wzg 1 yıl önce
ebeveyn
işleme
6de80eab8f
3 değiştirilmiş dosya ile 79 ekleme ve 98 silme
  1. 24 29
      miniprogram/app.js
  2. 22 27
      miniprogram/pages/index/index.js
  3. 33 42
      miniprogram/utils/wxUtils.js

+ 24 - 29
miniprogram/app.js

@@ -1,56 +1,51 @@
-import {
-  wxSetSessionKey
-} from "./utils/wxUtils"
+import { wxSetSessionKey } from "./utils/wxUtils";
 App({
   onLaunch: function () {
-    const updateManager = wx.getUpdateManager()
+    const updateManager = wx.getUpdateManager();
 
     updateManager.onCheckForUpdate(function (res) {
       // 请求完新版本信息的回调
-    })
+    });
 
     updateManager.onUpdateReady(function () {
       wx.showModal({
-        title: '更新提示',
-        content: '新版本已经准备好,是否重启应用?',
+        title: "更新提示",
+        content: "新版本已经准备好,是否重启应用?",
         success: function (res) {
           if (res.confirm) {
             // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
-            updateManager.applyUpdate()
+            updateManager.applyUpdate();
           }
-        }
-      })
-    })
+        },
+      });
+    });
 
     updateManager.onUpdateFailed(function () {
       // 新版本下载失败
-    })
-
+    });
 
     wx.cloud.init({
-      traceUser: true
-    })
-    this.globalData = {}
+      traceUser: true,
+    });
+    this.globalData = {};
   },
   onShow() {
-    this.checkEnvVersion()
+    this.checkEnvVersion();
   },
   checkEnvVersion() {
-    let v = wx.getAccountInfoSync()
-    let appVersion = wx.getStorageSync('appVersion')
-    let {
-      envVersion
-    } = v.miniProgram
+    let v = wx.getAccountInfoSync();
+    let appVersion = wx.getStorageSync("appVersion");
+    let { envVersion } = v.miniProgram;
     if (appVersion != envVersion) {
       wx.clearStorage({
         success: (res) => {
-          wx.setStorageSync('appVersion', envVersion)
+          wx.setStorageSync("appVersion", envVersion);
           wx.redirectTo({
-            url: '/pages/index/index',
-          })
+            url: "/pages/index/index",
+          });
         },
-      })
+      });
     }
-    wxSetSessionKey()
-  }
-})
+    wxSetSessionKey();
+  },
+});

+ 22 - 27
miniprogram/pages/index/index.js

@@ -1,62 +1,57 @@
 // pages/index/index.js
-import {
-  postApi
-} from "../../apis/api"
+import { postApi } from "../../apis/api";
 Page({
-
   /**
    * 页面的初始数据
    */
   data: {
-    loginStatus: false
+    loginStatus: false,
   },
 
   async login() {
-    if (!wx.getStorageSync('openId')) return
+    if (!wx.getStorageSync("openId")) return;
     let res1 = await postApi("/user/wx/openId/login", {
-      openId: wx.getStorageSync('openId')
-    })
+      openId: wx.getStorageSync("openId"),
+    });
 
     if (res1.data.status == 0) {
       let data = {
         ...res1.data.result.userInfo,
         ...res1.data.result.shipInfo,
-      }
+      };
       Object.keys(data).forEach(function (key) {
-        wx.setStorageSync(key, data[key])
-      })
+        wx.setStorageSync(key, data[key]);
+      });
     }
 
     wx.switchTab({
-      url: '/pages/takePhoto/takePhoto',
-    })
-
-
+      url: "/pages/takePhoto/takePhoto",
+    });
   },
   onLoad: function (options) {
-    if (wx.getStorageSync('userId') && wx.getStorageSync('shipName')) {
+    if (wx.getStorageSync("userId") && wx.getStorageSync("shipName")) {
       this.setData({
-        loginStatus: true
-      })
+        loginStatus: true,
+      });
     }
   },
 
   onShow() {
-    let v = wx.getAccountInfoSync()
+    let v = wx.getAccountInfoSync();
 
     if (v.miniProgram.envVersion != "release") {
       wx.showToast({
-        title: `当前环境:${v.miniProgram.envVersion=="develop"?'开发版':'体验版'}`,
-        icon: 'none',
-        duration: 1000
-      })
+        title: `当前环境:${
+          v.miniProgram.envVersion == "develop" ? "开发版" : "体验版"
+        }`,
+        icon: "none",
+        duration: 1000,
+      });
     }
   },
 
   /**
    * 用户点击右上角分享
    */
-  onShareAppMessage: function () {
-
-  }
-})
+  onShareAppMessage: function () {},
+});

+ 33 - 42
miniprogram/utils/wxUtils.js

@@ -1,69 +1,60 @@
-import cloudApi from "../apis/cloudApi"
-import {
-  postApi
-} from "../apis/api"
+import cloudApi from "../apis/cloudApi";
+import { postApi } from "../apis/api";
 
 function wxSetSessionKey() {
   return new Promise((resolve, reject) => {
     wx.login({
-      success: async res => {
-        let {
-          data
-        } = await postApi('/wx/getOpenId', {
-          code: res.code
-        })
-        let {
-          result: openId
-        } = data
-        wx.setStorageSync('openId', openId)
+      success: async (res) => {
+        let { data } = await postApi("/wx/getOpenId", {
+          code: res.code,
+        });
+        let { result: openId } = data;
+        wx.setStorageSync("openId", openId);
         resolve({
-          openId
-        })
-      }
-    })
-  })
-
+          openId,
+        });
+      },
+    });
+  });
 }
 
 function getUserProfile() {
   return new Promise((resolve, reject) => {
     wx.getUserProfile({
       desc: "'用于完善用户信息",
-      success: e => {
-        let {
-          userInfo
-        } = e
+      success: (e) => {
+        let { userInfo } = e;
         resolve({
           status: 0,
-          userInfo
-        })
+          userInfo,
+        });
       },
-      fail: e => {
+      fail: (e) => {
         resolve({
           errMsg: e.errMsg,
-          status: 1
-        })
-      }
-    })
-  })
+          status: 1,
+        });
+      },
+    });
+  });
 }
 
 function subMsg() {
   return new Promise((resolve, reject) => {
     wx.requestSubscribeMessage({
-      tmplIds: ['q1joCPFWjhAxSJtrZ30QFi_aA9LVva4PQZmBcxZIPhU'],
-      success: res => {
-        console.log(res)
+      tmplIds: ["q1joCPFWjhAxSJtrZ30QFi_aA9LVva4PQZmBcxZIPhU"],
+      success: (res) => {
+        console.log(res);
+      },
+      complete: (e) => {
+        console.log(e);
       },
-      complete: e => {
-        console.log(e)
-      }
-    })
-  })
+    });
+  });
 }
 
 module.exports = {
   wxSetSessionKey,
   getUserProfile,
-  subMsg
-}
+  subMsg,
+};