// app.js var projectMode = 1;//0代表开发模式(本地环境),1代表测试模式(线上测r试环境),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 } import api from './utils/api' App({ onLaunch() { //云开发 wx.cloud.init({ traceUser: true, }) wx.setStorageSync('islocation', false) const logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) var that = this; this.getLocation(); // 登录 wx.checkSession({ success: res => { if(!wx.getStorageSync('token')){ this.login(); } }, fail: (res) => { this.login(); } }) this.globalData.btnInfo = wx.getMenuButtonBoundingClientRect() console.log(this.globalData.btnInfo, '按钮信息'); }, globalData: { userInfo: null, btnInfo: null, status: ['可下单', '服务中', '已满柜', '暂停服务'], baseAppUrl: projectMode == 2 ? 'https://hx.xishuashua.art/' : (projectMode == 1 ? 'https://hx.xishuashua.art/' : 'http://wash.nanodreamtech.com/'), location: "", token:"", nid:0, islocation: true, logisticsStatus:['用户未存衣','用户已存衣', '送洗途中', '工厂已签收','管家送回中', '管家已存衣', '用户已取衣'], systeminfo:"" }, api: api, getLocation(e) { var that = this; this.globalData.headerBtnPosi = wx.getMenuButtonBoundingClientRect() wx.getSystemInfo({ // iphonex底部适配 success: res => { that.globalData.systeminfo = res } }) wx.getLocation({ success(res) { console.log('开启后台定位', res) console.log('location change', res) that.globalData.location = res; wx.setStorageSync('latitude', res.latitude) wx.setStorageSync('longitude', res.longitude) wx.checkSession({ success: res => { }, fail: (res) => { that.login(res.latitude, res.longitude).then(function (res) { }) } }) },fail(res) { console.log('开启后台定位失败', res) that.globalData.islocation = false; wx.setStorageSync('islocation', true) wx.showLoading({ title: '请授权获取地址。', }) setTimeout(function () { wx.hideLoading(); }, 2000) } }) }, 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({ // success: (res) => { // console.log(444444) // }, // fail: (res) => { wx.login({ success: res => { console.log(res) // 发送 res.code 到后台换取 openId, sessionKey, unionId that.api.useApi(that.globalData.baseAppUrl + "api/login", { code: res.code, lat: lat, lng: lng, appid: wx.getAccountInfoSync().miniProgram.appId }, "post").then(function (res) { wx.showLoading({ title: '登录中', }) if (res.code != 200) { setTimeout(function () { that.login(lat, lng); }, 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); wx.setStorageSync('seisson_key', res.message.session_key); wx.setStorageSync('phone', res.message.phone); wx.setStorageSync('is_online', res.is_online); wx.setStorageSync('nid', res.message.network_id);//当前网点选择id resolve(res); } }).catch(function (err) { console.log(222); }) } }) // } //}) }) }, getQueryVariable(url,name){ var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i'); var r = url.substr(1).match(reg); if (r != null) { return r[2]; } return null; } })