Browse Source

登陆问题

luck 2 years ago
parent
commit
a704dbf3b1

+ 12 - 0
app.js

@@ -20,6 +20,7 @@ App({
     var that = this;
 
     this.getLocation();
+ 
 
 
 
@@ -30,6 +31,7 @@ App({
         console.log(res)
       },
       fail: (res) => {
+        this.login();
       }
     })
 
@@ -44,6 +46,8 @@ App({
     status: ['可下单', '服务中', '已满柜', '暂停服务'],
     baseAppUrl: projectMode == 2 ? 'https://wash.nanodreamtech.com/' : (projectMode == 1 ? 'https://wash.nanodreamtech.com/' : 'http://127.0.0.1:8000/'),
     location: "",
+    token:"",
+    nid:0,
     islocation: true
   },
   api: api,
@@ -85,7 +89,12 @@ App({
   },
 
   login(lat = "", lng = "") {
+
     var that = this;
+    if(!lat || !lng){
+      lat=wx.getStorageSync('latitude')
+      lng=wx.getStorageSync('longitude')
+    }
     return new Promise((resolve, reject) => {
       console.log(3333333)
       wx.checkSession({
@@ -112,6 +121,9 @@ App({
                   }, 1000);
                 } else {
                   wx.hideLoading();
+                  that.globalData.token= res.message.token;
+                  that.globalData.nid= res.message.network_id;
+
                   wx.setStorageSync('token', res.message.token);
                   wx.setStorageSync('uid', res.message.user_id);
                   wx.setStorageSync('exp_time', res.message.exp_time);

+ 6 - 0
cloudfunction/publicLogin/config.json

@@ -0,0 +1,6 @@
+{
+  "permissions": {
+    "openapi": [
+    ]
+  }
+}

+ 15 - 0
cloudfunction/publicLogin/index.js

@@ -0,0 +1,15 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const wxContext = cloud.getWXContext()
+  return {
+    event,
+    openid: wxContext.OPENID,
+    appid: wxContext.APPID,
+    unionid: wxContext.UNIONID,
+  }
+}

+ 14 - 0
cloudfunction/publicLogin/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "publicLogin",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "wx-server-sdk": "~2.5.3"
+  }
+}

BIN
image/icon/icon_fanhui@2x.png


+ 22 - 6
pages/tabber/home/index.js

@@ -40,20 +40,36 @@ Page({
     onShow: function (options) {
         this.setData({
             islocation: wx.getStorageSync('islocation'),
-            status: app.globalData.status
+            status: app.globalData.status,
+           
         })
-        this.workDesc();
+        var nid =wx.getStorageSync('nid');
+        var token =wx.getStorageSync('token');
+            if(!nid || !token){
+                app.login().then(res => {
+                    console.log(res)
+                    this.setData({
+                        token: res.message.token,
+                        nid: res.message.network_id
+                    })
+                    this.workDesc(res.message.network_id);
+                })
+            
+            }else{
+                this.workDesc(nid);
+            }
+      
     },
     onReady: function () {
-
+        
     },
     //网点详情
-    workDesc: function () {
+    workDesc: function (nid="") {
         var that = this;
-        var nid = wx.getStorageSync('nid');
+            
         if (!nid) {
             that.setData({
-                worke: { 'title': '请选择网点', 'institution_id': 0, 'business_status': '不可下单', 'distance': 0 }
+                worke: { 'title': '请选择网点', 'institution_id': 0, 'business_status': 3, 'distance': 0 }
             })
             return false;
         }