app.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // app.js
  2. const api = require('./api/index')
  3. App({
  4. onLaunch() {
  5. wx.setStorageSync('showDialog', true)
  6. // 展示本地存储能力
  7. const logs = wx.getStorageSync('logs') || []
  8. logs.unshift(Date.now())
  9. wx.setStorageSync('logs', logs)
  10. //获取顶部navBar的信息
  11. const that = this;
  12. // 获取系统信息
  13. const systemInfo = wx.getSystemInfoSync();
  14. // 胶囊按钮位置信息
  15. const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
  16. that.globalData.windowWidth = systemInfo.windowWidth
  17. that.globalData.windowHeight = systemInfo.windowHeight
  18. // 导航栏高度 = 状态栏高度 + 44
  19. that.globalData.navBarHeight = systemInfo.statusBarHeight + 44;
  20. that.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
  21. that.globalData.menuTop = menuButtonInfo.top;
  22. that.globalData.menuHeight = menuButtonInfo.height;
  23. that.globalData.menuWidth = menuButtonInfo.width;
  24. wx.setStorageSync('height', that.globalData.navBarHeight)
  25. this.getPersonRights()
  26. this.checkVersion()
  27. //静态图片地址
  28. var Path = {
  29. develop: {
  30. localImagePath:'',
  31. imghttp:'https://www.xsip.cn/fileManager/downloadFile?fileId='
  32. }, // 开发环境地址
  33. trial: {
  34. localImagePath:'.',
  35. imghttp:'https://www.xsip.cn/fileManager/downloadFile?fileId='
  36. }, // 测试环境地址
  37. release:{
  38. localImagePath:'.',
  39. imghttp:'https://www.xsip.cn/fileManager/downloadFile?fileId='
  40. }, // 生产环境地址
  41. }
  42. const accountInfo = wx.getAccountInfoSync();
  43. const envVersion = accountInfo.miniProgram.envVersion;
  44. that.globalData.localImagePath = Path[envVersion].localImagePath;
  45. that.globalData.imghttp = Path[envVersion].imghttp;
  46. that.globalData.version = accountInfo.miniProgram.version;
  47. },
  48. globalData: {
  49. userInfo: null,
  50. navBarHeight: 0, // 导航栏高度
  51. menuRight: 0, // 胶囊距右方间距(方保持左、右间距一致)
  52. menuTop: 0, // 胶囊距顶部间距
  53. menuHeight: 0, // 胶囊高度(自定义内容可与胶囊高度保证一致)
  54. menuWidth:0,
  55. windowHeight:0,
  56. windowWidth:0,
  57. phone:'0755-82839168',
  58. localImagePath:'',//发布是'.',本地开发是''
  59. imghttp:'https://www.xsip.cn/fileManager/downloadFile?fileId=',
  60. version:''
  61. },
  62. getPersonRights(){
  63. api.getPersonRights({},false).then(res=>{
  64. if(res.code == 200){
  65. var data = JSON.stringify(res.data.data)
  66. wx.setStorageSync('vip', data)
  67. }
  68. })
  69. },
  70. checkVersion(){
  71. const updateManager = wx.getUpdateManager()
  72. updateManager.onCheckForUpdate(function (res) {
  73. // 请求完新版本信息的回调
  74. if (res.hasUpdate) {
  75. // 有新版本
  76. updateManager.onUpdateReady(function () {
  77. wx.showModal({
  78. title: '更新提示',
  79. content: '新版本已经准备好,是否立即重启应用?',
  80. success: function (res) {
  81. if (res.confirm) {
  82. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  83. updateManager.applyUpdate()
  84. }
  85. }
  86. })
  87. })
  88. updateManager.onUpdateFailed(function () {
  89. // 新版本下载失败
  90. wx.showModal({
  91. title: '更新提示',
  92. content: '新版本下载失败,请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索打开呦~',
  93. })
  94. })
  95. }
  96. })
  97. }
  98. })