app.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // app.js
  2. const {
  3. checkUserWhiteListId
  4. } = require('./utils/api/api')
  5. const versionConfig = require("./version.js")
  6. App({
  7. data: {
  8. /***
  9. * 用户信息
  10. */
  11. //用户基础信息-常客
  12. userInfo: null,
  13. //用户基础信息-访客
  14. visitorUserInfo: null,
  15. //用户额外信息-访客
  16. visitorExtraInfo: null,
  17. /***
  18. * 账号信息
  19. */
  20. //账号信息-常客
  21. adminInfo: null,
  22. //账号信息-访客
  23. visitorAdminInfo: null,
  24. //账号信息-临时
  25. temporaryAdminInfo: null,
  26. /***
  27. * 配置项
  28. */
  29. //何种扫码方式 0->普通码 1->常客码
  30. type: 0,
  31. //中英文
  32. language: 'ch',
  33. /**
  34. * 其他业务数据
  35. */
  36. //换取小程序用户信息的密钥
  37. wxCode: null,
  38. //二维码信息
  39. qrcodeInfo: null,
  40. //人脸识别任务 id
  41. faceTaskId: null,
  42. //定时器
  43. timer: null,
  44. /**
  45. * 渲染基础数据
  46. */
  47. //右上角胶囊位置
  48. statusBarCont: {},
  49. //(过审专用,禁止删除)- start
  50. fake: true,
  51. myAppointment: null,
  52. //(过审专用,禁止删除)- end
  53. },
  54. onLaunch() {
  55. //版本检查
  56. this.checkVersion()
  57. //缓存值赋值
  58. this.getStorage()
  59. //提前获取 wxCode
  60. this.getWxCode()
  61. //获取胶囊按钮位置信息
  62. this.getMenuButtonInfo()
  63. //检测缓存中的常客是否有效(存在)
  64. this.checkAdminInfoOfUser()
  65. },
  66. //版本判断
  67. checkVersion() {
  68. const oldVersion = wx.getStorageSync('version') || null;
  69. //若当前无缓存
  70. let infoList = wx.getStorageInfoSync()
  71. if(infoList.keys.length <= 0) {
  72. //缓存当前版本
  73. wx.setStorageSync('version', versionConfig.version)
  74. return;
  75. }
  76. //当前无版本号或大版本更新
  77. if (!oldVersion || Number(versionConfig.version.split('.')[0]) > Number(oldVersion.split('.')[0])) {
  78. let infoList = wx.getStorageInfoSync()
  79. infoList.keys.forEach(item => {
  80. wx.removeStorageSync(item)
  81. });
  82. wx.showModal({
  83. content: '小程序已升级到2.0.10,请重新认证后使用',
  84. complete: (res) => {}
  85. })
  86. }
  87. //缓存当前版本
  88. wx.setStorageSync('version', versionConfig.version)
  89. },
  90. //缓存值赋值
  91. getStorage() {
  92. this.data.userInfo = wx.getStorageSync('userInfo') || null
  93. this.data.visitorUserInfo = wx.getStorageSync('visitorUserInfo') || null
  94. this.data.visitorExtraInfo = wx.getStorageSync('visitorExtraInfo') || null
  95. this.data.adminInfo = wx.getStorageSync('adminInfo') || null
  96. this.data.visitorAdminInfo = wx.getStorageSync('visitorAdminInfo') || null
  97. this.data.language = wx.getStorageSync('language') || 'ch'
  98. },
  99. //提前获取 wxCode
  100. getWxCode() {
  101. wx.login({
  102. success: res => {
  103. this.data.wxCode = res.code;
  104. }
  105. })
  106. },
  107. //获取胶囊按钮位置信息
  108. getMenuButtonInfo() {
  109. wx.getSystemInfo({
  110. success: e => {
  111. this.data.statusBarCont.StatusBar = e.statusBarHeight;
  112. let capsule = wx.getMenuButtonBoundingClientRect();
  113. if (capsule) {
  114. this.data.statusBarCont.Custom = capsule;
  115. this.data.statusBarCont.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;;
  116. } else {
  117. this.data.statusBarCont.CustomBar = e.statusBarHeight + 50;
  118. }
  119. }
  120. });
  121. },
  122. //检测缓存中的常客是否有效(存在)
  123. checkAdminInfoOfUser() {
  124. if (this.data.adminInfo) {
  125. checkUserWhiteListId(this.data.adminInfo.userWhitelistId).then(res => {
  126. if (!res.data) {
  127. wx.removeStorageSync('adminInfo');
  128. this.data.adminInfo = null;
  129. }
  130. })
  131. }
  132. },
  133. globalData: {}
  134. })