Преглед изворни кода

添加主页和我的菜单

panxingxin пре 5 година
родитељ
комит
4efa781bdf

+ 7 - 11
api/request.js

@@ -29,7 +29,7 @@ fly.interceptors.request.use((request) => {
     console.log('nullHeaderToken()')
     return request;
   }
-  fly.lock()
+  // fly.lock()
   // 延迟发请求 等 getStorageSync 存储
   if(wx.getStorageSync('token')) {
      // 给所有请求添加自定义header
@@ -39,7 +39,7 @@ fly.interceptors.request.use((request) => {
        'X-Tag': 'flyio',
        'Authorization': `Bearer ${wx.getStorageSync('token')}`
      })
-     fly.unlock(); //解锁请求
+    //  fly.unlock(); //解锁请求
      return request;
   } else if (request.headers.Authorization) {
     // 给所有请求添加自定义header
@@ -48,7 +48,7 @@ fly.interceptors.request.use((request) => {
       'content-type': 'application/json',
       'X-Tag': 'flyio'
     })
-    fly.unlock(); //解锁请求
+    // fly.unlock(); //解锁请求
     return request;
   }
   //  else if(!wx.getStorageSync('token')&&app.getCurrentPages()=='pages/login/login') {
@@ -61,11 +61,7 @@ fly.interceptors.request.use((request) => {
   //   return request;
   // }
   else {
-    setTimeout(() => {
-      wx.redirectTo({
-        url: '../login/login'
-      });
-    }, 300)
+    console.log(app.getCurrentPages())
   }
 }, (error, promise) => {
   // Do something with request error
@@ -88,9 +84,9 @@ fly.interceptors.response.use(
     } else if (err.status === 401) {
       msg = '用户未登录'
       wx.clearStorageSync('token')
-      wx.redirectTo({
-        url: '../login/login'
-      });
+      // wx.navigateTo({
+      //   url: 'pages/me/me'
+      // });
     } else {
       if (err.response.data.message) {
         msg = err.response.data.message

+ 10 - 9
app.json

@@ -1,7 +1,8 @@
 {
   "pages": [
+    "pages/home/home",
     "pages/login/login",
-    "pages/index/index",
+    "pages/me/me",
     "pages/sample/index",
     "pages/sample/list",
     "pages/sample/detail",
@@ -12,15 +13,15 @@
   "tabBar": {
     "list": [
       {
-        "pagePath": "pages/sample/index",
-        "iconPath": "./resources/sample.png",
-        "selectedIconPath": "./resources/sample_selected.png",
-        "text": "样品单"
+        "pagePath": "pages/home/home",
+        "iconPath": "./resources/home.png",
+        "selectedIconPath": "./resources/home-selected.png",
+        "text": "主页"
       },{
-        "pagePath": "pages/contract/index",
-        "iconPath": "./resources/contract.png",
-        "selectedIconPath": "./resources/contract_selected.png",
-        "text": "采购合同"
+        "pagePath": "pages/me/me",
+        "iconPath": "./resources/me.png",
+        "selectedIconPath": "./resources/me-selected.png",
+        "text": "我的"
       }
     ]
   },

+ 4 - 0
menu/menu.js

@@ -0,0 +1,4 @@
+export const menuList = [
+  {name:'QA样品',url:'sample',icon:'../../resources/sample-selected.png'},
+  {name:'QA合同',url:'contract',icon:'../../resources/contract-selected.png'}
+]

+ 8 - 0
models/dataModel.js

@@ -49,6 +49,14 @@ export function getUserInfo() {
   })
 }
 
+// 获取菜单
+export function getMenu() {
+  return fly.request({
+    url: '/inventory/menu',
+    method: 'get'
+  })
+}
+
 // 获取样品单列表
 export function getSampleList(form) {
   return fly.request({

+ 1 - 0
pages/contract/detail.wxss

@@ -27,6 +27,7 @@ page{
 .detail-item .imageList image {
   height: 4rem;
   width: 4rem;
+  margin-right: 5px;
 }
 .detail-item .imageList text {
   font-size: 14px;

+ 56 - 0
pages/home/home.js

@@ -0,0 +1,56 @@
+//index.js
+import * as requestAPI from '../../models/dataModel'
+import { menuList } from '../../menu/menu'
+//获取应用实例
+const app = getApp()
+
+Page({
+  data: {
+    isLogin: false,
+    menuList: []
+  },
+  onLoad() {
+  },
+
+  onShow() {
+    if(wx.getStorageSync('token') && this.data.menuList.length===0) {
+      requestAPI.getMenu().then(res=>{
+        let tempList = []
+        if(res&&res.data&&res.data.data) {
+          for(let i of res.data.data) {
+            let filterList = menuList.filter(item => {
+              return item.name === i.name
+            })
+            tempList = tempList.concat(filterList)
+          }
+          this.setData({
+            menuList: tempList,
+            isLogin: true
+          })
+        }
+      })
+    }
+  },
+
+  getLink: function(event) {
+    console.log(event.currentTarget.dataset.item)
+    wx.navigateTo({
+      url: `/pages/${event.currentTarget.dataset.item.url}/index`,
+    })
+  }
+  //事件处理函数
+  // getmenu: function () {
+
+  //   wx.request({
+  //     url: 'http://192.168.20.53:9999/admin/menu/tree',
+  //     method: 'get',
+  //     header: {
+  //       'Authorization': 'Bearer ' + wx.getStorageSync('token')
+  //     },
+  //     success(r) {
+  //       console.log(r)
+  //       console.log(r)
+  //     }
+  //   })
+  // }
+})

+ 4 - 0
pages/home/home.json

@@ -0,0 +1,4 @@
+{
+  "usingComponents": {},
+  "navigationBarTitleText": "主页"
+}

+ 17 - 0
pages/home/home.wxml

@@ -0,0 +1,17 @@
+<view class="header">
+  <text>主页</text>
+</view>
+<view class="block">
+  <view class="title">基础菜单</view>
+  <view class="menu">
+    <view class="menu-item" wx:for="{{menuList}}" wx:key="index" data-item="{{item}}" bindtap="getLink">
+      <image mode="widthFix" src="{{item.icon}}"></image>
+      <text>{{item.name}}</text>
+    </view>
+    <text hidden="{{menuList.length!==0}}">暂无菜单</text>
+    <!-- <view class="menu-item" bindlongtap="getSample">
+      <image mode="widthFix" src="../../resources/contract.png"></image>
+      <text>采购合同</text>
+    </view> -->
+  </view>
+</view>

+ 51 - 0
pages/home/home.wxss

@@ -0,0 +1,51 @@
+page{
+  height: 100%;
+  background-color: #f8f8f8;
+}
+
+.block, .header{
+  background-color: #fff;
+  border-radius: 5px;
+  margin: 0.4rem;
+  padding: 1rem;
+}
+.block {
+  height: 10rem;
+}
+.header {
+  display: flex;
+  align-items: center;
+  height: 4rem
+}
+.header text {
+  font-size: 20px;
+}
+.block .wel {
+  font-size: 16px;
+}
+.block .title {
+  font-weight: bold;
+  border-bottom: 1px solid #eee;
+  padding-bottom: 1rem;
+}
+.menu {
+  display: flex;
+  padding-top: 1rem;
+}
+
+.menu .menu-item {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  width: 20%;
+  margin-right: 1rem;
+}
+
+.menu-item text {
+  font-family: Arial, Helvetica, sans-serif;
+  font-size: 14px;
+}
+
+.menu .menu-item image {
+  width: 2rem;
+}

+ 0 - 33
pages/index/index.js

@@ -1,33 +0,0 @@
-//index.js
-//获取应用实例
-const app = getApp()
-
-Page({
-  data: {
-    nbFrontColor: '#000',
-    nbBackgroundColor: '#fff'
-  },
-  onLoad() {
-    this.setData({
-      nbTitle: 'test',
-      nbLoading: false,
-      nbFrontColor: '#fff',
-      nbBackgroundColor: '#000'
-    })
-  },
-  //事件处理函数
-  // getmenu: function () {
-
-  //   wx.request({
-  //     url: 'http://192.168.20.53:9999/admin/menu/tree',
-  //     method: 'get',
-  //     header: {
-  //       'Authorization': 'Bearer ' + wx.getStorageSync('token')
-  //     },
-  //     success(r) {
-  //       console.log(r)
-  //       console.log(r)
-  //     }
-  //   })
-  // }
-})

+ 0 - 0
pages/index/index.wxml


+ 0 - 26
pages/index/index.wxss

@@ -1,26 +0,0 @@
-/**index.wxss**/
-.userinfo {
-  display: flex;
-  flex-direction: column;
-  align-items: center;
-}
-
-image {
-  width: 10rem;
-  height: 10rem;
-}
-
-.userinfo-avatar {
-  width: 128rpx;
-  height: 128rpx;
-  margin: 20rpx;
-  border-radius: 50%;
-}
-
-.userinfo-nickname {
-  color: #aaa;
-}
-
-.usermotto {
-  margin-top: 200px;
-}

+ 3 - 2
pages/login/login.js

@@ -15,7 +15,7 @@ Page({
     if(wx.getStorageSync('token')) {
       this.getIfExpired()
       wx.switchTab({
-        url: '/pages/sample/index',
+        url: '/pages/home/home',
       })
     }
   },
@@ -35,6 +35,7 @@ Page({
 
   // 登录 
   login: function () {
+    console.log('s')
     var self = this
     wx.login({
       success(wxres) {
@@ -47,7 +48,7 @@ Page({
             if (res.data.access_token) {
               wx.setStorageSync('token', res.data.access_token);
               wx.switchTab({
-                url: '/pages/sample/index',
+                url: '/pages/home/home',
               })
             }
           }

+ 29 - 0
pages/me/me.js

@@ -0,0 +1,29 @@
+// pages/me/me.js
+import * as requestAPI from '../../models/dataModel'
+Page({
+  data: {
+    isLogin: false,
+    userName: ''
+  },
+  onLoad: function (options) {
+  },
+
+  onShow() {
+    if(wx.getStorageSync('token') && !this.data.userName) {
+      requestAPI.getUserInfo().then(res => {
+        this.setData({
+          userName: res.data.data.sysUser.username,
+          isLogin: true
+        })
+      })
+    }
+  },
+
+  login() {
+    if(!this.data.isLogin) {
+      wx.navigateTo({
+        url: '/pages/login/login',
+      })
+    }
+  }
+})

pages/index/index.json → pages/me/me.json


+ 8 - 0
pages/me/me.wxml

@@ -0,0 +1,8 @@
+<view class="header">
+	<view class="title">登录信息</view>
+  <view class="info" bindtap="login">
+    <text hidden="{{!isLogin}}">欢迎用户{{userName}}登录</text>
+    <text hidden="{{isLogin}}">用户未登录</text>
+    <image src="../../resources/people.png" mode="widthFix"></image>
+  </view>
+</view>

+ 28 - 0
pages/me/me.wxss

@@ -0,0 +1,28 @@
+page{
+  height: 100%;
+  background-color: #f8f8f8;
+}
+
+.header{
+  background-color: #fff;
+  border-radius: 5px;
+  margin: 0.4rem;
+  padding: 1rem 2rem;
+}
+
+.header .title {
+  font-weight: bold;
+  border-bottom: 1px solid #eee;
+  padding-bottom: 1rem;
+}
+
+.header .info {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  padding-top: 1rem;
+}
+
+.header image {
+  width: 4rem;
+}

+ 1 - 0
pages/sample/detail.wxss

@@ -27,6 +27,7 @@ page{
 .detail-item .imageList image {
   height: 4rem;
   width: 4rem;
+  margin-right: 5px;
 }
 .detail-item .imageList text {
   font-size: 14px;

resources/contract_selected.png → resources/contract-selected.png


BIN
resources/home-selected.png


BIN
resources/home.png


BIN
resources/me-selected.png



BIN
resources/people.png


resources/sample_selected.png → resources/sample-selected.png