zs 1 سال پیش
والد
کامیت
3c605a18c5

+ 3 - 3
pages/index/index.js

@@ -28,8 +28,8 @@ Page({
         const that = this;
         wx.showLoading({ title: '加载中', mask: true })
         await that.searchConfig()
-        // 监听用户是否登录
-        await that.watchLogin();
+        // 获取Openid
+        await that.searchOpenid();
         wx.hideLoading()
     },
     async searchConfig() {
@@ -45,7 +45,7 @@ Page({
         }
     },
     // 监听用户是否登录
-    watchLogin: async function () {
+    searchOpenid: async function () {
         wx.login({
             success: async (arr) => {
                 const { code: js_code } = arr;

+ 2 - 2
pagesCommon/login/index.js

@@ -32,9 +32,9 @@ Page({
             const res = await app.$api('user/login', 'POST', params);
             if (res.errcode === 0) {
                 app.globalData.userInfo = res.data;//存用户信息到app.js
-                wx.setStorage({ key: "token", data: res.data })// 存用户信息到storage,以便之后判断用户是否登录
+                wx.setStorage({ key: "user", data: res.data })// 存用户信息到storage,以便之后判断用户是否登录
                 wx.showToast({ title: `账号登录成功`, icon: 'success', duration: 2000 }) //登录成功提示
-                wx.redirectTo({ url: '/pagesHome/home/index' })
+                wx.navigateBack({ delta: 1 });
             } else wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 })
         }
     },

+ 7 - 8
pagesHome/home/index.js

@@ -78,6 +78,12 @@ Page({
      * 生命周期函数--监听页面加载
      */
     async onLoad(options) {
+
+    },
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    async onShow() {
         const that = this;
         wx.showLoading({ title: '加载中', mask: true })
         await that.searchUser()
@@ -88,7 +94,7 @@ Page({
     async searchUser() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
             },
@@ -125,13 +131,6 @@ Page({
 
     },
 
-    /**
-     * 生命周期函数--监听页面显示
-     */
-    onShow() {
-
-    },
-
     /**
      * 生命周期函数--监听页面隐藏
      */

+ 8 - 8
pagesMatch/apply/index.js

@@ -34,16 +34,23 @@ Page({
     async onLoad(options) {
         const that = this;
         that.setData({ id: options.id });
+    },
+    /**
+    * 生命周期函数--监听页面显示
+    */
+    async onShow() {
+        const that = this;
         wx.showLoading({ title: '加载中', mask: true })
         await that.searchUser()
         await that.searchOther()
         await that.search()
         wx.hideLoading()
     },
+
     async searchUser() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
             }, fail(err) {
@@ -78,13 +85,6 @@ Page({
 
     },
 
-    /**
-     * 生命周期函数--监听页面显示
-     */
-    onShow() {
-
-    },
-
     /**
      * 生命周期函数--监听页面隐藏
      */

+ 1 - 1
pagesMatch/enroll/index.js

@@ -120,7 +120,7 @@ Page({
     search() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
                 if (that.data.id) {

+ 7 - 8
pagesMatch/home/index.js

@@ -98,6 +98,12 @@ Page({
      * 生命周期函数--监听页面加载
      */
     async onLoad(options) {
+        
+    },
+      /**
+     * 生命周期函数--监听页面显示
+     */
+    async onShow() {
         const that = this;
         wx.showLoading({ title: '加载中', mask: true })
         await that.searchUser()
@@ -108,7 +114,7 @@ Page({
     async searchUser() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
             },
@@ -148,13 +154,6 @@ Page({
 
     },
 
-    /**
-     * 生命周期函数--监听页面显示
-     */
-    onShow() {
-
-    },
-
     /**
      * 生命周期函数--监听页面隐藏
      */

+ 1 - 1
pagesMy/basic/index.js

@@ -96,7 +96,7 @@ Page({
     search() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 let form = {}
                 let aee = await app.$api(`user/${res.data._id}`, 'GET', {})

+ 1 - 1
pagesMy/course/index.js

@@ -78,7 +78,7 @@ Page({
     async searchUser() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
             },

+ 1 - 1
pagesMy/course/index.wxml

@@ -15,7 +15,7 @@
                     {{item.match_time}}
                     <text class="color{{item.status}}">({{item.status_name}})</text>
                 </view>
-                <view class="button">
+                <view class="button"> 
                     <button wx:if="{{item.status=='1'&&user.type=='1'}}" class="btn" type="primary" size="mini" data-item="{{item}}" bindtap="toUpload">
                         上传比分
                     </button>

+ 22 - 22
pagesMy/home/index.js

@@ -31,7 +31,7 @@ Page({
                     success(res) {
                         if (res.confirm) {
                             wx.removeStorage({
-                                key: 'token',
+                                key: 'user',
                                 success(res) {
                                     return wx.redirectTo({ url: '/pagesHome/home/index' })
                                 }
@@ -45,25 +45,25 @@ Page({
             wx.navigateTo({ url: '/pagesCommon/login/index' })
         }
     },
+    // 去登录
+    toLogin() {
+        wx.navigateTo({ url: '/pagesCommon/login/index' })
+    },
     // 获取头像
     async toAvatarUrl(e) {
         const that = this;
         const { avatarUrl } = e.detail
-        if (that.data.user._id) {
-            let res = await app.$apifile('files/ball/users/upload', null, avatarUrl)
-            res = JSON.parse(res);
-            if (res.errcode == '0') {
-                let icon = [{ id: res.id, name: res.name, uri: res.uri, url: `${app.globalData.fileserverUrl}` + res.uri }]
-                let arr = await app.$api(`user/${that.data.user._id}`, 'POST', { icon: icon });
-                if (arr.errcode == '0') {
-                    wx.showToast({ title: `头像上传成功`, icon: 'success' });
-                    that.search()
-                } else {
-                    wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
-                }
+        let res = await app.$apifile('files/ball/users/upload', null, avatarUrl)
+        res = JSON.parse(res);
+        if (res.errcode == '0') {
+            let icon = [{ id: res.id, name: res.name, uri: res.uri, url: `${app.globalData.fileserverUrl}` + res.uri }]
+            let arr = await app.$api(`user/${that.data.user._id}`, 'POST', { icon: icon });
+            if (arr.errcode == '0') {
+                wx.showToast({ title: `头像上传成功`, icon: 'success' });
+                that.search()
+            } else {
+                wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
             }
-        } else {
-            wx.navigateTo({ url: '/pagesCommon/login/index' })
         }
     },
     // 过滤字典表
@@ -80,6 +80,12 @@ Page({
      * 生命周期函数--监听页面加载
      */
     async onLoad(options) {
+
+    },
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    async onShow() {
         const that = this;
         wx.showLoading({ title: '加载中', mask: true })
         await that.searchConfig();
@@ -114,7 +120,7 @@ Page({
     async search() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 let arr = await app.$api(`user/${res.data._id}`, 'GET', {})
                 if (arr.errcode == '0') {
@@ -144,12 +150,6 @@ Page({
 
     },
 
-    /**
-     * 生命周期函数--监听页面显示
-     */
-    onShow() {
-
-    },
 
     /**
      * 生命周期函数--监听页面隐藏

+ 6 - 1
pagesMy/home/index.wxml

@@ -1,11 +1,16 @@
 <home-frame bind:toPath="toPath">
     <view class='main'>
         <!--头像名称-->
-        <view class="one">
+        <view class="one" wx:if="{{user._id}}">
             <button class="button" open-type="chooseAvatar" bind:chooseavatar="toAvatarUrl">
                 <image class="image" src="{{avatarUrl||logo}}"></image>
             </button>
         </view>
+        <view class="one" wx:else>
+            <view class="button" bindtap="toLogin">
+                <image class="image" src="{{avatarUrl||logo}}"></image>
+            </view>
+        </view>
         <view class="two">
             <view class="two_1">
                 <view class="text"> {{user.name||'暂无姓名'}} </view>

+ 1 - 1
pagesMy/home/index.wxss

@@ -3,7 +3,7 @@
 
 .main .one {
     display: flex;
-    justify-content: space-between;
+    justify-content: center;
     background-color: var(--rgb40E);
     padding-top: 50rpx;
     padding-bottom: 100rpx;

+ 1 - 1
pagesMy/match/index.js

@@ -100,7 +100,7 @@ Page({
     async searchUser() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
             },

+ 1 - 1
pagesMy/ranking/index.js

@@ -26,7 +26,7 @@ Page({
     async searchUser() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
             },

+ 1 - 1
pagesMy/score/index.js

@@ -108,7 +108,7 @@ Page({
     search() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 let form = {}
                 let aee = await app.$api(`course/${that.data.id}`, 'GET', {})

+ 1 - 1
pagesMy/team/index.js

@@ -99,7 +99,7 @@ Page({
     async searchUser() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
             },

+ 1 - 1
pagesMy/teamCreate/index.js

@@ -127,7 +127,7 @@ Page({
     search() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 if (that.data.id) {
                     let res = await app.$api(`team/${that.data.id}`, 'GET', {})

+ 2 - 2
pagesMy/update/index.js

@@ -29,7 +29,7 @@ Page({
                 else wx.showToast({ title: `未登录无法修改密码`, icon: 'none' });
                 if (res.errcode == '0') {
                     wx.removeStorage({
-                        key: 'token',
+                        key: 'user',
                         success(res) {
                             wx.showToast({ title: `修改密码成功`, icon: 'success' });
                             wx.redirectTo({ url: '/pagesHome/home/index' })
@@ -60,7 +60,7 @@ Page({
     search() {
         const that = this;
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 let form = {}
                 let aee = await app.$api(`user/${res.data._id}`, 'GET', {})

+ 1 - 1
pagesTeam/apply/index.js

@@ -100,7 +100,7 @@ Page({
             }
         })
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
             },

+ 8 - 7
pagesTeam/home/index.js

@@ -40,6 +40,12 @@ Page({
      * 生命周期函数--监听页面加载
      */
     async onLoad(options) {
+      
+    },
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    async onShow() {
         const that = this;
         wx.showLoading({ title: '加载中', mask: true })
         await that.searchConfig()
@@ -47,6 +53,7 @@ Page({
         await that.search()
         wx.hideLoading()
     },
+
     async searchConfig() {
         const that = this;
         wx.getStorage({
@@ -63,7 +70,7 @@ Page({
             }
         })
         wx.getStorage({
-            key: 'token',
+            key: 'user',
             async success(res) {
                 that.setData({ user: res.data })
             },
@@ -133,12 +140,6 @@ Page({
 
     },
 
-    /**
-     * 生命周期函数--监听页面显示
-     */
-    onShow() {
-
-    },
 
     /**
      * 生命周期函数--监听页面隐藏