app.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. 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://hx.xishuashua.art/' : '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. })