app.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // app.js
  2. var projectMode = 1;//0代表开发模式(本地环境),1代表测试模式(线上测试环境),2代表线上模式(正式运行环境)
  3. var info = wx.getSystemInfoSync();
  4. if (info.platform != "devtools" && projectMode == 0) { projectMode = 1 }
  5. var envVersion = `${__wxConfig.envVersion}`;//develop 开发版,trial 体验版,release 正式版
  6. if (envVersion == 'release') { projectMode = 2 }
  7. import api from './utils/api'
  8. App({
  9. onLaunch() {
  10. //云开发
  11. // wx.cloud.init({
  12. // traceUser: true,
  13. // })
  14. this.updateApp()
  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://wash.nanodreamtech.com/' : '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. updateApp:function(){
  53. const updateManager = wx.getUpdateManager()
  54. updateManager.onCheckForUpdate(function (res) {
  55. // 请求完新版本信息的回调
  56. if (res.hasUpdate) {
  57. wx.showLoading({
  58. title:'更新下载中...',
  59. })
  60. }
  61. })
  62. updateManager.onUpdateReady(function () {
  63. wx.hideLoading();
  64. wx.showModal({
  65. title:'更新提示',
  66. content:'新版本已经准备好,是否重启应用?',
  67. success:function (res) {
  68. if (res.confirm) {
  69. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  70. updateManager.applyUpdate()
  71. }
  72. }
  73. })
  74. })
  75. updateManager.onUpdateFailed(function () {
  76. // 新的版本下载失败
  77. wx.hideLoading();
  78. wx.showToast({ title:'下载失败...', icon:"none" });
  79. })
  80. },
  81. })