guhongwei 3 years ago
parent
commit
daecf0ed9c
9 changed files with 69 additions and 30 deletions
  1. 10 1
      app.js
  2. 2 1
      app.json
  3. 27 3
      custom-tab-bar/index.js
  4. 1 1
      pages/home/index.js
  5. 10 5
      pages/login/index.js
  6. 3 3
      pages/login/index.wxml
  7. 5 6
      pages/my/index.js
  8. 2 2
      pages/my/index.wxml
  9. 9 8
      pages/reserve/index.js

+ 10 - 1
app.js

@@ -19,7 +19,8 @@ App({
           success: res => {
             const { errcode, data } = res.data
             if (errcode === 0) {
-              this.globalData.userInfo = data;
+              this.globalData.wxInfo = data;
+              wx.setStorage({ key: "userInfo", data: null })
             }
           },
           error: err => {
@@ -40,11 +41,19 @@ App({
     })
   },
   globalData: {
+    // 微信用户基本信息
     userInfo: {},
+    // 微信用户openid,sessionKey
+    wxInfo: {},
+    // 头部高度
     height: 0,
+    // 手机页面高度
     windowHeight: 0,
+    // 请求接口
     publicUrl: 'http://192.168.1.19:9901',
+    // 图片请求接口
     fileUrl: "http://broadcast.waityou24.cn",
+    // 站点标识
     tenant: "test"
   }
 })

+ 2 - 1
app.json

@@ -2,6 +2,7 @@
   "pages": [
     "pages/home/index",
     "pages/login/index",
+   
     "pages/food/index",
     "pages/calorie/index",
     "pages/reserve/index",
@@ -84,4 +85,4 @@
     "navigationStyle": "custom"
   },
   "sitemapLocation": "sitemap.json"
-}
+}

+ 27 - 3
custom-tab-bar/index.js

@@ -1,3 +1,4 @@
+const app = getApp()
 Component({
   data: {
     selected: '',
@@ -32,9 +33,32 @@ Component({
   },
   methods: {
     switchTab(e) {
-      const data = e.currentTarget.dataset
-      const url = data.path
-      wx.switchTab({ url })
+      const { index, path } = e.currentTarget.dataset;
+      var sessionUser;
+      wx.getStorage({
+        key: 'userInfo',
+        success(res) {
+          sessionUser = res.data;
+        }
+      })
+      if (index == 3) {
+        if (sessionUser) {
+          app.globalData.userInfo = sessionUser;
+          wx.switchTab({ url: path })
+        } else {
+          wx.getUserProfile({
+            desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+            success: (res) => {
+              wx.setStorage({ key: "userInfo", data: res.userInfo })
+              app.globalData.userInfo = res.userInfo;
+              wx.switchTab({ url: path })
+            }
+          })
+        }
+      } else {
+        wx.switchTab({ url: path })
+      }
+      // wx.switchTab({ url })
       // wx.reLaunch({ url })
       // this.setData({
       //   selected: data.index

+ 1 - 1
pages/home/index.js

@@ -66,7 +66,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    console.log(app.globalData.userInfo);
+    console.log(app.globalData.wxInfo);
   },
 
   /**

+ 10 - 5
pages/login/index.js

@@ -17,8 +17,8 @@ Page({
   },
   initValidate() {
     const rules = {
-      phone: { required: true, tel: true },
-      password: { required: true, },
+      phone: { required: false, tel: true },
+      password: { required: false, },
     }
     // 验证字段的提示信息,若不传则调用默认的信息
     const messages = {
@@ -38,12 +38,17 @@ Page({
       })
       return false
     } else {
-      console.log(params);
       wx.switchTab({
         url: '/pages/home/index',
       })
-      // wx.redirectTo({
-      //   url: '/pages/home/index'
+      // wx.getUserProfile({
+      //   desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+      //   success: (res) => {
+      //     app.globalData.userInfo = res
+      //     wx.switchTab({
+      //       url: '/pages/home/index',
+      //     })
+      //   }
       // })
     }
   },

+ 3 - 3
pages/login/index.wxml

@@ -4,16 +4,16 @@
   </view>
   <view class="two">
     <form bindsubmit="formSubmit">
-      <view class='content'>
+      <!-- <view class='content'>
         <view class='input'>
           <input type='number' name="phone" value="{{form.phone}}" maxlength="11" placeholder='请输入账号'></input>
         </view>
         <view class='input'>
           <input type='text' name="password" value="{{form.password}}" placeholder='请输入密码' password></input>
         </view>
-      </view>
+      </view> -->
       <view class="save">
-        <button form-type="submit" size="small">登录</button>
+        <button form-type="submit" size="small">微信授权登录</button>
       </view>
     </form>
   </view>

+ 5 - 6
pages/my/index.js

@@ -11,10 +11,7 @@ Page({
     navbarData: {
       name: '我的'
     },
-    userInfo: {
-      url: '/image/home/image1.jpg',
-      name: '顾红伟'
-    }
+    userInfo: {}
   },
   // 跳转页面
   routeBtn: function (e) {
@@ -24,7 +21,7 @@ Page({
         url: `/pages/history/index?openid=${app.globalData.userInfo.openid}`
       })
     } else if (type == '2') {
-      app.globalData.userInfo = null
+      app.globalData.userInfo = {}
       wx.redirectTo({
         url: '/pages/login/index'
       })
@@ -34,7 +31,9 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    let data = app.globalData.userInfo;
+    console.log(data);
+    if (data) this.setData({ userInfo: data })
   },
 
   /**

+ 2 - 2
pages/my/index.wxml

@@ -2,11 +2,11 @@
 <view class="main" style="padding-top:{{height}}px;height:{{windowHeight-height}}px">
   <view class="one">
     <view class="left">
-      <image src="{{userInfo.url}}"></image>
+      <image src="{{userInfo.avatarUrl}}"></image>
     </view>
     <view class="right">
       <view class="name">
-        {{userInfo.name}}
+        {{userInfo.nickName}}
       </view>
     </view>
   </view>

+ 9 - 8
pages/reserve/index.js

@@ -140,11 +140,9 @@ Page({
   },
   // 提交
   onSubmit: function () {
-    console.log(this.data.form);
-    console.log(app.globalData.userInfo)
     const data = JSON.parse(JSON.stringify(this.data.form))
-    if (app.globalData.userInfo.openid) data.openid =app.globalData.userInfo.openid;
-    if (this.data.today) data.date = this.data.today
+    if (app.globalData.wxInfo) data.openid = app.globalData.wxInfo.openid;
+    if (this.data.today) data.date = this.data.today;
     wx.request({
       url: `${app.globalData.publicUrl}/api/st/dining/order`,
       method: "post",
@@ -153,7 +151,12 @@ Page({
       },
       data,
       success: res => {
-        console.log(res)
+        if (res.errcode == 0) {
+          wx.showToast({
+            title: '完成点餐',
+          })
+        }
+
       },
       error: err => {
         wx.showToast({
@@ -162,9 +165,7 @@ Page({
         })
       }
     })
-    wx.showToast({
-      title: '完成点餐',
-    })
+
   },
   /**
    * 生命周期函数--监听页面加载