app.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. },
  47. globalData: {
  48. userInfo: null,
  49. navBarHeight: 0, // 导航栏高度
  50. menuRight: 0, // 胶囊距右方间距(方保持左、右间距一致)
  51. menuTop: 0, // 胶囊距顶部间距
  52. menuHeight: 0, // 胶囊高度(自定义内容可与胶囊高度保证一致)
  53. menuWidth:0,
  54. windowHeight:0,
  55. windowWidth:0,
  56. phone:'0755-82839168',
  57. localImagePath:'',//发布是'.',本地开发是''
  58. imghttp:'https://www.xsip.cn/fileManager/downloadFile?fileId='
  59. },
  60. getPersonRights(){
  61. api.getPersonRights({},false).then(res=>{
  62. if(res.code == 200){
  63. var data = JSON.stringify(res.data.data)
  64. wx.setStorageSync('vip', data)
  65. }
  66. })
  67. },
  68. checkVersion(){
  69. const updateManager = wx.getUpdateManager()
  70. updateManager.onCheckForUpdate(function (res) {
  71. // 请求完新版本信息的回调
  72. if (res.hasUpdate) {
  73. // 有新版本
  74. updateManager.onUpdateReady(function () {
  75. wx.showModal({
  76. title: '更新提示',
  77. content: '新版本已经准备好,是否立即重启应用?',
  78. success: function (res) {
  79. if (res.confirm) {
  80. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  81. updateManager.applyUpdate()
  82. }
  83. }
  84. })
  85. })
  86. updateManager.onUpdateFailed(function () {
  87. // 新版本下载失败
  88. wx.showModal({
  89. title: '更新提示',
  90. content: '新版本下载失败,请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索打开呦~',
  91. })
  92. })
  93. }
  94. })
  95. }
  96. })