Browse Source

开发新登录

sunxf 2 years ago
parent
commit
e7f512b232

+ 4 - 0
api/user.js

@@ -5,8 +5,12 @@ import {
 module.exports = {
     // 用户登录
     userLogin: data => request('/user/register', 'post', data),
+    // 获取用户session_key和open_id
+    getUserSO: data => request('/user/openId', 'get', data),
     //获取用户信息
     getUserInfo: data => request('/v3/user/my', 'get', data),
+    // 设置用户信息
+    setUserInfo: data => request('/user', 'post', data),
     //获取是否vip及过期时间
     getVipInfo: data => request('/auth', 'get', data),
     //获取自己朗读的作品

+ 2 - 4
app.js

@@ -19,7 +19,7 @@ App({
         })
     },
     async onLaunch(options) {
-        wx.login({
+        /* wx.login({
             success(res) {
                 if (res.code) {
                     console.log(res.code);
@@ -32,7 +32,7 @@ App({
                     })
                 }
             }
-        })
+        }) */
         // 判断设备是否为 iPhone X
         this.checkIsIPhoneX()
         options.referrerInfo.extraData && (this.globalData.upgradeHide = options.referrerInfo.extraData.upgrade)
@@ -51,8 +51,6 @@ App({
         wx.getSystemInfo({
             success: function (res) {
                 // 根据 model 进行判断
-                console.log(res)
-                console.log(res.system.search('iOS'))
                 if (res.model.search('iPhone X') != -1) {
                     self.globalData.isIPX = true
                 }

+ 1 - 2
app.json

@@ -1,8 +1,8 @@
 {
     "pages": [
+        "pages/index/index",
         "pages/my/index",
         "pages/userWorks/index",
-        "pages/index/index",
         "pages/login/login",
         "pages/reading/reading",
         "pages/social/works/works",
@@ -25,7 +25,6 @@
         "pages/vipPage/vip/vip",
         "pages/vipPage/vipCode/vipCode",
         "pages/vipPage/wechat/wechat",
-        "pages/grade/grade",
         "pages/activity/index/index",
         "pages/activity/rule/rule",
         "pages/activity/strategy/strategy",

+ 75 - 0
component/setGrade/index.js

@@ -0,0 +1,75 @@
+import {
+    setUserInfo,
+    userLogin,
+    getUserSO
+} from '~/api/user'
+Component({
+    /**
+     * 组件的属性列表
+     */
+    properties: {
+
+    },
+
+    /**
+     * 组件的初始数据
+     */
+    data: {
+        code: ''
+    },
+
+    /**
+     * 组件的方法列表
+     */
+    methods: {
+        selectGrade({
+            target
+        }) {
+            let code = target.dataset.code
+            if (!code) {
+                return
+            }
+            this.setData({
+                code
+            })
+            console.log(code);
+        },
+        setUserInfo() {
+
+        },
+        getUserProfile(e) {
+            wx.login({
+                success: async (res) => {
+                    if (res.code) {
+                        let so = await getUserSO({
+                            code: res.code
+                        })
+                        console.log(so);
+                    } else {
+                        console.log('获取用户登录态失败!' + res.errMsg)
+                    }
+                }
+            })
+            // wx.getUserProfile({
+            //     desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+            //     success: async (userProfile) => {
+            //         console.log(userProfile);
+            //         /* 
+            //             shareUid
+            //         */
+            //         let {
+            //             encryptedData,
+            //             sessionKey,
+            //             iv,
+            //         } = userProfile
+            //         let res = await userLogin({
+            //             encryptedData,
+            //             sessionKey,
+            //             iv,
+            //         })
+            //         console.log(res);
+            //     }
+            // })
+        },
+    }
+})

+ 5 - 0
component/setGrade/index.json

@@ -0,0 +1,5 @@
+{
+    "component": true,
+    "usingComponents": {},
+    "styleIsolation": "apply-shared"
+}

+ 59 - 0
component/setGrade/index.less

@@ -0,0 +1,59 @@
+.gradeContainer {
+    width: 100%;
+    height: 100%;
+    background: rgba(0, 0, 0, .7);
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    position: fixed;
+    top: 0;
+    left: 0;
+    z-index: 9999;
+
+    .gradeBox {
+        width: 530rpx;
+        padding: 33rpx 40rpx 50rpx;
+        border-radius: 20rpx;
+        background-color: white;
+
+        .title {
+            text-align: center;
+            font-size: 40rpx;
+            font-weight: bold;
+        }
+
+        .content {
+            margin-top: 65rpx;
+            display: flex;
+            justify-content: space-between;
+            align-items: center;
+
+            .grade {
+                padding: 14rpx 64rpx;
+                border-radius: 50rpx;
+                font-size: 36rpx;
+                color: #333;
+                background-color: #E4E4E4;
+            }
+
+            .check {
+                color: white;
+                background-color: #1CCC69;
+            }
+        }
+
+        .submitBox {
+            text-align: center;
+
+            .submit {
+                margin-top: 60rpx;
+                padding: 16rpx 118rpx;
+                display: inline-block;
+                background-color: #F7991B;
+                color: white;
+                font-size: 42rpx;
+                border-radius: 50rpx;
+            }
+        }
+    }
+}

+ 19 - 0
component/setGrade/index.wxml

@@ -0,0 +1,19 @@
+<view class="gradeContainer" catchtouchmove='true'>
+    <view class="gradeBox" bindtap="selectGrade">
+        <view class="title">年级选择</view>
+        <view class="content">
+            <view class="grade {{code=='PRESCHOOL'?'check':''}}" data-code="PRESCHOOL">学前班</view>
+            <view class="grade {{code=='PRIMARY_FIRST_GRADE'?'check':''}}" data-code="PRIMARY_FIRST_GRADE">一年级</view>
+        </view>
+        <view class="content">
+            <view class="grade {{code=='PRIMARY_SECOND_GRADE'?'check':''}}" data-code="PRIMARY_SECOND_GRADE">二年级</view>
+            <view class="grade {{code=='PRIMARY_THREE_GRADE'?'check':''}}" data-code="PRIMARY_THREE_GRADE">三年级</view>
+        </view>
+        <view class="content">
+            <view class="grade {{code=='PRIMARY_SENIOR_GRADE'?'check':''}}" data-code="PRIMARY_SENIOR_GRADE">四年级</view>
+        </view>
+        <view class="submitBox">
+            <button class="resetBtn submit" bindtap="getUserProfile">登录</button>
+        </view>
+    </view>
+</view>

+ 52 - 0
component/setGrade/index.wxss

@@ -0,0 +1,52 @@
+.gradeContainer {
+  width: 100%;
+  height: 100%;
+  background: rgba(0, 0, 0, 0.7);
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  position: fixed;
+  top: 0;
+  left: 0;
+  z-index: 9999;
+}
+.gradeContainer .gradeBox {
+  width: 530rpx;
+  padding: 33rpx 40rpx 50rpx;
+  border-radius: 20rpx;
+  background-color: white;
+}
+.gradeContainer .gradeBox .title {
+  text-align: center;
+  font-size: 40rpx;
+  font-weight: bold;
+}
+.gradeContainer .gradeBox .content {
+  margin-top: 65rpx;
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+}
+.gradeContainer .gradeBox .content .grade {
+  padding: 14rpx 64rpx;
+  border-radius: 50rpx;
+  font-size: 36rpx;
+  color: #333;
+  background-color: #E4E4E4;
+}
+.gradeContainer .gradeBox .content .check {
+  color: white;
+  background-color: #1CCC69;
+}
+.gradeContainer .gradeBox .submitBox {
+  text-align: center;
+}
+.gradeContainer .gradeBox .submitBox .submit {
+  margin-top: 60rpx;
+  padding: 16rpx 118rpx;
+  display: inline-block;
+  background-color: #F7991B;
+  color: white;
+  font-size: 42rpx;
+  border-radius: 50rpx;
+}

+ 0 - 89
pages/grade/grade.js

@@ -1,89 +0,0 @@
-// pages/grade/grade.js
-Page({
-
-  /**
-   * 页面的初始数据
-   */
-  data: {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad: function (options) {
-
-  },
-    // 修改年级
-    changeGrade: function (e) {
-      const grade = e.target.dataset.code;
-      wx.setStorageSync('grade', grade)
-      this.setData({
-        grade: grade
-      })
-  
-      let gradeText = '一年级';
-      switch (e.target.dataset.code) {
-        case '0':
-          gradeText = '学前班';
-          break;
-        case '1':
-          gradeText = '一年级';
-          break;
-        case '2':
-          gradeText = '二年级';
-          break;
-        case '3':
-          gradeText = '三年级';
-          break;
-      }
-    },
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady: function () {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow: function () {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide: function () {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload: function () {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh: function () {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom: function () {
-
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage: function () {
-
-  }
-})

+ 0 - 3
pages/grade/grade.json

@@ -1,3 +0,0 @@
-{
-  "usingComponents": {}
-}

+ 0 - 22
pages/grade/grade.wxml

@@ -1,22 +0,0 @@
-<!--pages/grade/grade.wxml-->
-<view class="change_grade">
-  <view class="change_brage_wrapper">
-    <text class="title">分龄选择</text>
-    <view class="change_row">
-      <view class="change_item" bindtap="changeGrade" data-code="0">
-        学前班
-      </view>
-      <view class="change_item" bindtap="changeGrade" data-code="1">
-        一年级
-      </view>
-    </view>
-     <view class="change_row">
-      <view class="change_item" bindtap="changeGrade" data-code="2">
-        二年级
-      </view>
-      <view class="change_item" bindtap="changeGrade" data-code="3">
-        三年级
-      </view>
-    </view>
-  </view>
-</view>

+ 0 - 1
pages/grade/grade.wxss

@@ -1 +0,0 @@
-/* pages/grade/grade.wxss */

+ 3 - 3
pages/index/index.js

@@ -918,8 +918,8 @@ Page({
     // 修改年级
     changeGrade: function (e) {
         const grade = e.target.dataset.code;
-
-        wx.setStorageSync('grade', grade)
+        console.log(grade);
+      /*   wx.setStorageSync('grade', grade)
         this.setData({
             isGradeShow: false,
             grade
@@ -952,7 +952,7 @@ Page({
             this.setData({
                 hide: !this.data.hide
             })
-        }, grade);
+        }, grade); */
     },
 
     getFollowData: function () {

+ 4 - 3
pages/index/index.json

@@ -7,10 +7,11 @@
         "Comment": "../../component/comment/comment",
         "StatusBar": "../../component/statusBar/statusBar",
         "shareDialog": "/component/share/share",
-        "flowerBox": "/component/flowerBox/flowerBox"
+        "flowerBox": "/component/flowerBox/flowerBox",
+        "setGrade": "/component/setGrade/index"
     },
     "enablePullDownRefresh": true,
     "window": {
         "onReachBottomDistance": 50
-      }
-  }
+    }
+}

+ 3 - 2
pages/index/index.wxml

@@ -1,7 +1,8 @@
 <!-- index.wxml -->
 <!-- <StatusBar receiveData="{{statusbarobj}}" grade="{{grade}}" bindgradeTap="gradeTap" /> -->
 <mp-navigation-bar title="UI组件库"></mp-navigation-bar>
-<view class="change_grade" wx:if="{{isGradeShow}}">
+<setGrade wx:if="{{isGradeShow}}"></setGrade>
+<!-- <view class="change_grade" wx:if="{{isGradeShow}}">
     <view class="change_brage_wrapper">
         <text class="title">分龄选择</text>
         <view class="change_row">
@@ -17,7 +18,7 @@
             <view class="change_item change_item_blank" data-code="PRESCHOOL"></view>
         </view>
     </view>
-</view>
+</view> -->
 <view class="container">
     <!-- 引入组件 -->
     <import src="/component/my/my.wxml" />