Ver código fonte

登陆问题

luck 2 anos atrás
pai
commit
a704dbf3b1

+ 12 - 0
app.js

@@ -20,6 +20,7 @@ App({
     var that = this;
     var that = this;
 
 
     this.getLocation();
     this.getLocation();
+ 
 
 
 
 
 
 
@@ -30,6 +31,7 @@ App({
         console.log(res)
         console.log(res)
       },
       },
       fail: (res) => {
       fail: (res) => {
+        this.login();
       }
       }
     })
     })
 
 
@@ -44,6 +46,8 @@ App({
     status: ['可下单', '服务中', '已满柜', '暂停服务'],
     status: ['可下单', '服务中', '已满柜', '暂停服务'],
     baseAppUrl: projectMode == 2 ? 'https://wash.nanodreamtech.com/' : (projectMode == 1 ? 'https://wash.nanodreamtech.com/' : 'http://127.0.0.1:8000/'),
     baseAppUrl: projectMode == 2 ? 'https://wash.nanodreamtech.com/' : (projectMode == 1 ? 'https://wash.nanodreamtech.com/' : 'http://127.0.0.1:8000/'),
     location: "",
     location: "",
+    token:"",
+    nid:0,
     islocation: true
     islocation: true
   },
   },
   api: api,
   api: api,
@@ -85,7 +89,12 @@ App({
   },
   },
 
 
   login(lat = "", lng = "") {
   login(lat = "", lng = "") {
+
     var that = this;
     var that = this;
+    if(!lat || !lng){
+      lat=wx.getStorageSync('latitude')
+      lng=wx.getStorageSync('longitude')
+    }
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
       console.log(3333333)
       console.log(3333333)
       wx.checkSession({
       wx.checkSession({
@@ -112,6 +121,9 @@ App({
                   }, 1000);
                   }, 1000);
                 } else {
                 } else {
                   wx.hideLoading();
                   wx.hideLoading();
+                  that.globalData.token= res.message.token;
+                  that.globalData.nid= res.message.network_id;
+
                   wx.setStorageSync('token', res.message.token);
                   wx.setStorageSync('token', res.message.token);
                   wx.setStorageSync('uid', res.message.user_id);
                   wx.setStorageSync('uid', res.message.user_id);
                   wx.setStorageSync('exp_time', res.message.exp_time);
                   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) {
     onShow: function (options) {
         this.setData({
         this.setData({
             islocation: wx.getStorageSync('islocation'),
             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 () {
     onReady: function () {
-
+        
     },
     },
     //网点详情
     //网点详情
-    workDesc: function () {
+    workDesc: function (nid="") {
         var that = this;
         var that = this;
-        var nid = wx.getStorageSync('nid');
+            
         if (!nid) {
         if (!nid) {
             that.setData({
             that.setData({
-                worke: { 'title': '请选择网点', 'institution_id': 0, 'business_status': '不可下单', 'distance': 0 }
+                worke: { 'title': '请选择网点', 'institution_id': 0, 'business_status': 3, 'distance': 0 }
             })
             })
             return false;
             return false;
         }
         }