luck 2 năm trước cách đây
mục cha
commit
2b5a6dde2e
3 tập tin đã thay đổi với 96 bổ sung75 xóa
  1. 75 73
      app.js
  2. 20 1
      pages/tabber/home/index.js
  3. 1 1
      pages/tabber/home/index.wxml

+ 75 - 73
app.js

@@ -1,9 +1,9 @@
 // app.js
-var projectMode=0;//0代表开发模式(本地环境),1代表测试模式(线上测试环境),2代表线上模式(正式运行环境)
-var info=wx.getSystemInfoSync();
-if(info.platform!="devtools"&&projectMode==0){projectMode=1}
+var projectMode = 2;//0代表开发模式(本地环境),1代表测试模式(线上测试环境),2代表线上模式(正式运行环境)
+var info = wx.getSystemInfoSync();
+if (info.platform != "devtools" && projectMode == 0) { projectMode = 1 }
 var envVersion = `${__wxConfig.envVersion}`;//develop	开发版,trial	体验版,release	正式版
-if(envVersion=='release'){projectMode=2}
+if (envVersion == 'release') { projectMode = 2 }
 import api from './utils/api'
 App({
   onLaunch() {
@@ -11,108 +11,110 @@ App({
     const logs = wx.getStorageSync('logs') || []
     logs.unshift(Date.now())
     wx.setStorageSync('logs', logs)
-    var that=this;
+    var that = this;
 
     this.getLocation();
 
     // 登录
 
     wx.checkSession({
-      success: res=> {
+      success: res => {
         console.log(res)
       },
-      fail:(res)=>{
+      fail: (res) => {
       }
     })
-  
+
 
     this.globalData.btnInfo = wx.getMenuButtonBoundingClientRect()
-    console.log(this.globalData.btnInfo,'按钮信息');
-    
+    console.log(this.globalData.btnInfo, '按钮信息');
+
   },
   globalData: {
     userInfo: null,
-    btnInfo:null,
-    baseAppUrl: projectMode==2 ? 'https://bank.nanodreamtech.com/':(projectMode==1 ?'https://bank.nanodreamtech.com/':'http://127.0.0.1:8000/'),
-    location:""
+    btnInfo: null,
+    baseAppUrl: projectMode == 2 ? 'https://wash.nanodreamtech.com/' : (projectMode == 1 ? 'https://wash.nanodreamtech.com/' : 'http://127.0.0.1:8000/'),
+    location: {'latitude':123,'longitude':321}
   },
-  api:api,
+  api: api,
+
+  getLocation(e) {
+    var that = this;
 
-  getLocation(e){
-    var that=this;
     wx.startLocationUpdateBackground({
-        success(res) {
-          console.log('开启后台定位', res)
-          wx.onLocationChange(function(res) {
-            console.log('location change', res)
-            that.globalData.location=res;
+      success(res) {
+        console.log('开启后台定位', res)
+        wx.onLocationChange(function (ress) {
+         wx.setStorageSync('latitude', ress.latitude)
+         wx.setStorageSync('latitude', ress.longitude)
+          that.globalData.location = ress;
+          that.login(that.globalData.location.latitude,  that.globalData.location.longitude).then(function (res) {
+            if (res.code != 200) {
 
+            }
 
-   
-            that.login(res.latitude,res.longitude).then(function(res){
-              if(res.code!=200){
-                
-              }
+
+          }, function (err) {
+
+          })
 
 
-            },function(err){
+        })
+      },
+      fail(res) {
+        console.log('开启后台定位失败', res)
+      }
+    })
+  },
 
-            })
+  login(lat = "", lng = "") {
+    var that = this;
+    return new Promise((resolve, reject) => {
 
+      wx.checkSession({
+        success: (res) => {
 
-          })
         },
-        fail(res) {
-          console.log('开启后台定位失败', res)
+        fail: (res) => {
+      
+          wx.login({
+            success: res => {
+              // 发送 res.code 到后台换取 openId, sessionKey, unionId
+              that.api.useApi(that.globalData.baseAppUrl + "api/login", {
+                code: res.code,
+                lat: lat,
+                lng: lng,
+                appid: wx.getAppBaseInfo().host.appId
+              }, "post").then(function (res) {
+                wx.showLoading({
+                  title: '登录中',
+                })
+                console.log(res);
+                if (res.code != 200) {
+                  setTimeout(function () {
+                    that.login(lat, lng);
+                  }, 1000);
+                } else {
+                  wx.hideLoading();
+                  wx.setStorageSync('token', res.message.token);
+                  wx.setStorageSync('uid', res.message.user_id);
+                  wx.setStorageSync('nid', res.message.network_id);//当前网点选择id
+                  resolve(res);
+                }
+
+              }).catch(function (err) {
+                console.log(222);
+              })
+            }
+          })
         }
+
       })
-},
 
-  login(lat="",lng=""){
-    var that=this;
-   return new Promise((resolve,reject)=>{
 
-    wx.checkSession({
-      success: (res) => {
 
-      },
-      fail:(res)=>{
-        wx.login({
-          success: res => {
-            // 发送 res.code 到后台换取 openId, sessionKey, unionId
-            that.api.useApi(that.globalData.baseAppUrl+"api/login",{
-              code:res.code,
-              lat:lat,
-              lng:lng,
-              appid:wx.getAppBaseInfo().host.appId
-            },"post").then(function(res){
-              wx.showLoading({
-                title: '登录中',
-              })
-              if(res.code!=200){
-                setTimeout(function(){
-                  that.login(lat,lng);
-                },1000);
-              }else{
-                wx.hideLoading();
-                resolve(res);
-              }
-          
-    
-            
-            }).catch(function(err){
-              console.log(222);
-            })
-          }
-        })
-      }
 
     })
-
-
-
-   
-   })
   }
 
 })

+ 20 - 1
pages/tabber/home/index.js

@@ -29,6 +29,7 @@ Page({
         current: 3,
         btnInfo: app.globalData.btnInfo,
         topShow: true,
+        address:[]
     },
 
     /**
@@ -38,8 +39,26 @@ Page({
         // api.getBanner().then(res=>{
         //     console.log(res);
         // })
+        var that=this;
+        app.api.useApi(app.globalData.baseAppUrl + "api", {
+            lat: wx.getStorageSync('latitude'),
+            lng: wx.getStorageSync('longitude'),
+          }, "get").then(function (res) {
+            if (res.code != 200) {
+                wx.showLoading({
+                    title: '网点加载失败'+res.status,
+                  })
+            } else {
+             that.setData({
+                 address:res.message.data.data[0]
+             })
+            }
 
-    
+            wx.hideLoading();
+
+          }).catch(function (err) {
+            console.log(222);
+          })
 
     
 

+ 1 - 1
pages/tabber/home/index.wxml

@@ -11,7 +11,7 @@
         <view class="le flex ju-b">
             <image src="/image/home/pic.png" class="pic"></image>
             <view class="content">
-                <view class="tit">创星汇科技园B栋1号柜</view>
+                <view class="tit">{{address.name}}</view>
                 <view class="message">离您最近|距离40米</view>
                 <view class="tags">可下单</view>
             </view>