app.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // app.js
  2. var projectMode = 1;//0代表开发模式(本地环境),1代表测试模式(线上测试环境),2代表线上模式(正式运行环境)
  3. var info = wx.getSystemInfoSync();
  4. console.log(info);
  5. if (info.platform != "devtools" && projectMode == 0) { projectMode = 1 }
  6. var envVersion = `${__wxConfig.envVersion}`;//develop 开发版,trial 体验版,release 正式版
  7. if (envVersion == 'release') { projectMode = 2 }
  8. import api from './utils/api'
  9. App({
  10. onLaunch() {
  11. //云开发
  12. // wx.cloud.init({
  13. // traceUser: true,
  14. // })
  15. wx.setStorageSync('islocation', false)
  16. var that = this;
  17. this.getLocation();
  18. },
  19. globalData: {
  20. userInfo: null,
  21. btnInfo: null,
  22. status: ['可下单', '服务中', '已满柜', '暂停服务'],
  23. baseAppUrl: projectMode == 2 ? 'https://hx.xishuashua.art/' : (projectMode == 1 ? 'https://hx.xishuashua.art/' : 'https://wash.nanodreamtech.com/'),
  24. location: "",
  25. islocation: true
  26. },
  27. api: api,
  28. getLocation(e) {
  29. var that = this;
  30. return new Promise((resolve, reject) => {
  31. wx.getLocation({
  32. success(res) {
  33. console.log('开启后台定位', res)
  34. console.log('location change', res)
  35. that.globalData.location = res;
  36. wx.setStorageSync('latitude', res.latitude)
  37. wx.setStorageSync('longitude', res.longitude)
  38. }, fail(res) {
  39. console.log('开启后台定位失败', res)
  40. that.globalData.islocation = false;
  41. wx.setStorageSync('islocation', true)
  42. wx.showLoading({
  43. title: '请授权获取地址。',
  44. })
  45. setTimeout(function () {
  46. wx.hideLoading();
  47. }, 2000)
  48. }
  49. })
  50. })
  51. },
  52. })