guhongwei 2 rokov pred
rodič
commit
dcf451e305
4 zmenil súbory, kde vykonal 16 pridanie a 13 odobranie
  1. 1 0
      app.json
  2. 11 10
      pages/my/index.js
  3. 1 1
      pages/my/index.wxml
  4. 3 2
      utils/dict.js

+ 1 - 0
app.json

@@ -1,5 +1,6 @@
 {
     "pages": [
+
         "pages/index/index",
         "pages/register/index",
         "pages/home/index",

+ 11 - 10
pages/my/index.js

@@ -7,9 +7,7 @@ Page({
      */
     data: {
         frameStyle: { useTop: true, name: '我的', leftArrow: false, useBar: true },
-        user: {
-
-        },
+        user: {},
         btnList: [],
     },
     // 跳转菜单
@@ -31,19 +29,22 @@ Page({
         const that = this;
         that.watchLogin();
     },
-
-    watchLogin: function () {
+    watchLogin: async function () {
         const that = this;
         wx.getStorage({
             key: 'user',
             success: async (res) => {
-                console.log('已登陆');
+                const arr = await app.$get(`/newCourt/api/user/${res.data.openid}`);
+                if (arr.errcode == '0') {
+                    let user = arr.data;
+                    that.setData({ user: user });
+                    let btn = myBtn.filter((i) => i.type.includes(user.type));
+                    that.setData({ btnList: btn })
+
+                } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
             },
             fail: async (res) => {
-                console.log('未登陆');
-                let user = { icon: '/image/icon.jpg', name: '顾红伟', phone: '12345678901', type: '1' }
-                that.setData({ user: user })
-                console.log(user);
+                wx.redirectTo({ url: '/pages/index/index' });
             },
         });
     },

+ 1 - 1
pages/my/index.wxml

@@ -5,7 +5,7 @@
             <view class="one_2">
                 <view class="l">
                     <view class="l_1">
-                        <image class="icon" src="{{user.icon}}"></image>
+                        <image class="icon" src="{{user.icon&&user.icon.length>0?user.icon[0].url:''}}"></image>
                     </view>
                     <view class="l_2">
                         <view class="info textOver">{{user.name}}</view>

+ 3 - 2
utils/dict.js

@@ -16,9 +16,10 @@ export const match_status = [
     { label: '5', value: '比赛结束' },
 ]
 // 我的页面,功能按钮
+// -1:管理员,0:普通用户,1:裁判用户
 export const myBtn = [
-    { title: '我的赛事', route: 'usermymatch' },
-    { title: '账号设置', route: 'setting' }
+    { title: '我的赛事', route: 'usermymatch', type: '0' },
+    { title: '账号设置', route: 'setting', type: '-1|0' }
 ]
 
 export const gender = [