app.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // app.js
  2. var projectMode = 0;//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. this.updateApp()
  16. wx.setStorageSync('islocation', false)
  17. var that = this;
  18. this.getLocation();
  19. },
  20. globalData: {
  21. userInfo: null,
  22. btnInfo: null,
  23. status: ['可下单', '服务中', '已满柜', '暂停服务'],
  24. baseAppUrl: projectMode == 2 ? 'https://hx.xishuashua.art/' : (projectMode == 1 ? 'https://wash.nanodreamtech.com/' : 'https://wash.nanodreamtech.com/'),
  25. location: "",
  26. islocation: true
  27. },
  28. api: api,
  29. getLocation(e) {
  30. var that = this;
  31. return new Promise((resolve, reject) => {
  32. wx.getLocation({
  33. success(res) {
  34. console.log('开启后台定位', res)
  35. console.log('location change', res)
  36. that.globalData.location = res;
  37. wx.setStorageSync('latitude', res.latitude)
  38. wx.setStorageSync('longitude', res.longitude)
  39. }, fail(res) {
  40. console.log('开启后台定位失败', res)
  41. that.globalData.islocation = false;
  42. wx.setStorageSync('islocation', true)
  43. wx.showLoading({
  44. title: '请授权获取地址。',
  45. })
  46. setTimeout(function () {
  47. wx.hideLoading();
  48. }, 2000)
  49. }
  50. })
  51. })
  52. },
  53. updateApp:function(){
  54. const updateManager = wx.getUpdateManager()
  55. updateManager.onCheckForUpdate(function (res) {
  56. // 请求完新版本信息的回调
  57. if (res.hasUpdate) {
  58. wx.showLoading({
  59. title:'更新下载中...',
  60. })
  61. }
  62. })
  63. updateManager.onUpdateReady(function () {
  64. wx.hideLoading();
  65. wx.showModal({
  66. title:'更新提示',
  67. content:'新版本已经准备好,是否重启应用?',
  68. success:function (res) {
  69. if (res.confirm) {
  70. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  71. updateManager.applyUpdate()
  72. }
  73. }
  74. })
  75. })
  76. updateManager.onUpdateFailed(function () {
  77. // 新的版本下载失败
  78. wx.hideLoading();
  79. wx.showToast({ title:'下载失败...', icon:"none" });
  80. })
  81. },
  82. })