app.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-06-23 22:15:11
  4. * @LastEditTime: 2021-06-24 21:01:33
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \Mina_B_T\miniprogram\app.ts
  8. */
  9. // app.ts
  10. App<IAppOption>({
  11. globalData: {
  12. captchaTicketExpire: null,
  13. captchaResult: null,
  14. phone_zz: /1[0-9]{10}/,
  15. webview: null,
  16. version: '1.2.5',
  17. platformId: 1
  18. },
  19. /**
  20. * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
  21. */
  22. onLaunch() {
  23. const systemInfo = wx.getSystemInfoSync()
  24. console.log('微信版本=>',systemInfo.version,'小程序版本=>',systemInfo.SDKVersion)
  25. if (!wx.getStorageSync('hasClear')) {
  26. wx.clearStorage({
  27. success: () => {
  28. wx.setStorageSync('hasClear', true)
  29. },
  30. })
  31. }
  32. },
  33. /**
  34. * 当小程序启动,或从后台进入前台显示,会触发 onShow
  35. */
  36. onShow(options: any) {
  37. if (!this.globalData.captchaTicketExpire) this.globalData.captchaTicketExpire = {};
  38. if (options.referrerInfo.appId === 'wx5a3a7366fd07e119') {
  39. const result = options.referrerInfo.extraData;
  40. if (result.ret === 0) {
  41. const ticket = result.ticket;
  42. if (!this.globalData.captchaTicketExpire[ticket]) {
  43. this.globalData.captchaResult = result;
  44. this.globalData.captchaTicketExpire[ticket] = true;
  45. }
  46. }
  47. }
  48. if (wx.getUpdateManager) {
  49. const updateManager = wx.getUpdateManager();
  50. updateManager.onCheckForUpdate(res => {
  51. if (res.hasUpdate) {
  52. updateManager.onUpdateReady(() => {
  53. wx.showModal({
  54. title: '更新提示',
  55. content: '新版本上线了,请点击确定按钮更新!',
  56. showCancel: false,
  57. success: res => {
  58. if (res.confirm) {
  59. updateManager.applyUpdate()
  60. }
  61. }
  62. })
  63. })
  64. updateManager.onUpdateFailed(() => {
  65. wx.showModal({
  66. title: '更新提示',
  67. content: '新版本已上线,请删除当前小程序,重新搜索进入',
  68. showCancel: false,
  69. })
  70. })
  71. }
  72. })
  73. }
  74. },
  75. /**
  76. * 当小程序从前台进入后台,会触发 onHide
  77. */
  78. onHide() {
  79. },
  80. /**
  81. * 当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
  82. */
  83. onError(msg) {
  84. console.error(msg)
  85. },
  86. })