guhongwei преди 3 години
родител
ревизия
bb4535bed3
променени са 3 файла, в които са добавени 48 реда и са изтрити 36 реда
  1. 26 0
      app.js
  2. 22 35
      pages/home/index.js
  3. 0 1
      utils/login.js

+ 26 - 0
app.js

@@ -8,6 +8,32 @@ App({
     const logs = wx.getStorageSync('logs') || []
     logs.unshift(Date.now())
     wx.setStorageSync('logs', logs)
+    wx.login({
+      success: res => {
+        const app = getApp()
+        const { code: js_code } = res
+        // 发送 res.code 到后台换取 openId, sessionKey, unionId
+        wx.request({
+          url: `${app.globalData.publicUrl}/api/st/system/weixin/appAuth?js_code=` + js_code,
+          method: "get",
+          header: {
+            'x-tenant': app.globalData.tenant
+          },
+          success: res => {
+            const { errcode, data } = res.data
+            if (errcode === 0) {
+              app.globalData.wxInfo = data;
+            }
+          },
+          error: err => {
+            wx.showToast({
+              title: err.msg,
+              icon: 'error'
+            })
+          }
+        })
+      }
+    })
     //获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度
     wx.getSystemInfo({
       success: (res) => {

+ 22 - 35
pages/home/index.js

@@ -11,35 +11,22 @@ Page({
     navbarData: {
       name: '节俭会'
     },
+    // 背景图片
     background: '',
-    tenant: '',
+
+    // 热量占比
     heat: 80,
+    heatColor: { '0%': '#E1FFFF', '25%': '#00FF7F', '50%': '#191970', '75%': '#ee0a24', '100%': '#ff0000', },
+    // 微信运动
     step: 0,
-    heatColor: {
-      '0%': '#E1FFFF',
-      '25%': '#00FF7F',
-      '50%': '#191970',
-      '75%': '#ee0a24',
-      '100%': '#ff0000',
-    },
-    thrList: [
-      {
-        name: '菜名',
-        num: 1,
-        reserve: '100'
-      },
-      {
-        name: '菜名',
-        num: 1,
-        reserve: '100'
-      },
-      {
-        name: '菜名',
-        num: 1,
-        reserve: '100'
-      },
-    ],
-    thrTitle: ''
+    // 用餐卡
+    // 餐类别
+    thrTitle: '',
+    // 站点信息
+    tenant: '',
+    // 餐列表
+    thrList: [],
+
   },
   // 查看本周菜谱
   reserveBtn: function () {
@@ -50,30 +37,29 @@ Page({
   // 报餐:1,余菜打包:2,卡路里计算:3
   twoBtn: function (e) {
     let type = e.currentTarget.dataset.smile
-    if (type == '1') {
+    if (type == '1') {//报餐
       wx.switchTab({
         url: '/pages/reserve/index',
       })
-    } else if (type == '2') {
+    } else if (type == '2') {//余菜打包
       wx.showToast({
         title: '暂未开通',
       })
-    } else {
+    } else {//卡路里计算
       wx.showToast({
         title: '暂未开通',
       })
-      // wx.redirectTo({
-      //   url: '/pages/calorie/index',
-      // })
     }
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    // 登录,获取用户openid,sessonkey
     app.toLogin().then(res => {
       this.getMealCard();
     });
+    // 获取背景图片,站点信息
     wx.request({
       url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
       method: "get",
@@ -91,12 +77,13 @@ Page({
         })
       }
     })
+    // 获取微信运动信息
     wx.getWeRunData({
       success: (res) => {
+        const app = getApp()
         const { encryptedData, iv } = res
         const session_key = app.globalData.wxInfo.session_key;
         const data = { encryptedData, iv, session_key }
-        // // 拿 encryptedData 到开发者后台解密开放数据
         wx.request({
           url: `${app.globalData.publicUrl}/api/st/system/weixin/decrypt`,
           method: "POST",
@@ -111,7 +98,6 @@ Page({
         })
       }
     })
-
   },
 
   /**
@@ -166,7 +152,7 @@ Page({
   onShareAppMessage: function () {
 
   },
-
+  // 获取用餐卡
   getMealCard() {
     const openid = app.globalData.wxInfo.openid;
     if (!openid) return;
@@ -197,6 +183,7 @@ Page({
       }
     })
   },
+  // 创建二维码
   initQrCode(id) {
     const url = `${app.globalData.publicUrl}/api/st/dining/order/useMeal/${id}?_tenant=${app.globalData.tenant}`;
     var qrcode = new QRCode(`myQrcode`, {

+ 0 - 1
utils/login.js

@@ -17,7 +17,6 @@ module.exports = {
               const { errcode, data } = res.data
               if (errcode === 0) {
                 app.globalData.wxInfo = data;
-                wx.setStorage({ key: "userInfo", data: null })
                 resolve(data);
               }
             },