app.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //app.js
  2. var businessT = require('tool/business-tool.js')
  3. var sysT = require('tool/sys-tool.js')
  4. var publicData = require('constant/data.js')
  5. var key = require('constant/key.js')
  6. const updateManager = wx.getUpdateManager()
  7. App({
  8. //根据跳转小程序appID获取对应名称
  9. getflowAPP: function (flow_id) {
  10. switch (flow_id) {
  11. case "wx4882c703815c5602": {
  12. this.globalData.flow_name = "比心单身";
  13. break
  14. }
  15. case "wxdb674acb1231c231": {
  16. this.globalData.flow_name = "趣健步";
  17. break
  18. }
  19. case "wx6664983624b1a9aa": {
  20. this.globalData.flow_name = "开心小视频";
  21. break
  22. }
  23. case "wx361bc43be556242b": {
  24. this.globalData.flow_name = "车行易";
  25. break
  26. }
  27. case "wxffbb41ec9b99a969": {
  28. this.globalData.flow_name = "房天下";
  29. break
  30. }
  31. case "wxf4b1c4ee0bc63893": {
  32. this.globalData.flow_name = "医启查";
  33. break
  34. }
  35. case "wxe5bf8b2a2fe172ff": {
  36. this.globalData.flow_name = "职友集";
  37. break
  38. }
  39. case "wx7ab08191e61478c5": {
  40. this.globalData.flow_name = "般若商城";
  41. break
  42. }
  43. case "wxc18bff57483f5644": {
  44. this.globalData.flow_name = "查查信用";
  45. break
  46. }
  47. case "wxeb95a70a8c8bbb6c": {
  48. this.globalData.flow_name = "土巴兔";
  49. break
  50. }
  51. case "wxcb0ec6ae8c422c3b": {
  52. this.globalData.flow_name = "养老金计算器";
  53. break
  54. }
  55. case "wx482c4fd36243ba7b": {
  56. this.globalData.flow_name = "退休养老金计算器";
  57. break
  58. }
  59. case "wx7379ad24baaaf660": {
  60. this.globalData.flow_name = "个人所得税计算器新版";
  61. break
  62. }
  63. case "wx9c2770b744d95f66": {
  64. this.globalData.flow_name = "个人所得税计算2019新版";
  65. break
  66. }
  67. case "wx53e95e68996dbb50": {
  68. this.globalData.flow_name = "上海税后工资计算器";
  69. break
  70. }
  71. case "wx6eed53ca3059904b": {
  72. this.globalData.flow_name = "北京税后工资计算器";
  73. break
  74. }
  75. default:
  76. this.globalData.flow_id = "其他小程序ID"
  77. this.globalData.flow_name = "其他小程序名称";
  78. }
  79. },
  80. onLaunch: function (options) {
  81. sysT.adaptor()
  82. businessT.debugLog(sysT.isLongScreen())
  83. businessT.debugLog(sysT.suffixOfClass())
  84. this.judgeVersion()
  85. this.getUpdateReady()
  86. this.getNetworkStatus()
  87. this.handleData()
  88. },
  89. onShow:function(e){
  90. //console.log(e)
  91. this.globalData.scene = e.scene
  92. if (e.scene == 1037){
  93. this.globalData.flow_id = e.referrerInfo.appId
  94. this.getflowAPP(e.referrerInfo.appId)
  95. }else{
  96. this.globalData.flow_id = 1000
  97. this.globalData.flow_name = "其他渠道来源"
  98. }
  99. },
  100. handleData: function () {
  101. //购买城市
  102. var d
  103. try {
  104. d = wx.getStorageSync(key.StorageKey.purchaseCity)
  105. } catch (e) {
  106. }
  107. if (!d) {
  108. d = {
  109. p: [{ name: '广东', id: 1000 }, { name: '北京市', id: 1100 }, { name: '上海市', id: 1200 }],
  110. 1000: [{ name: '广州', id: 1001 }, { name: '深圳', id: 1014 }],
  111. 1100: [{ name: '北京', id: 1101 }],
  112. 1200: [{ name: '上海', id: 1201 }]
  113. }
  114. }
  115. publicData.purchaseCity = d
  116. wx.setStorageSync(key.StorageKey.purchaseCity, d)
  117. businessT.debugLog(d)
  118. },
  119. getUpdateReady: function () {
  120. updateManager.onUpdateReady(function () {
  121. wx.showModal({
  122. title: '更新提示',
  123. content: '新版本已经准备好,是否重启应用?',
  124. showCancel: false,
  125. success: function (res) {
  126. if (res.confirm) {
  127. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  128. updateManager.applyUpdate()
  129. }
  130. }
  131. })
  132. })
  133. },
  134. getNetworkStatus: function () {
  135. var that = this
  136. wx.getNetworkType({
  137. success: function (res) {
  138. // 返回网络类型, 有效值:
  139. // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  140. that.networkStatus.type = res.networkType
  141. if (that.networkStatus.type == 'none') {
  142. that.networkStatus.connected = false
  143. } else {
  144. that.networkStatus.connected = true
  145. }
  146. businessT.debugLog(that.networkStatus)
  147. }
  148. })
  149. wx.onNetworkStatusChange(function(res){
  150. that.networkStatus.type = res.networkType
  151. that.networkStatus.connected = res.isConnected
  152. businessT.debugLog(that.networkStatus)
  153. })
  154. },
  155. judgeVersion: function () {
  156. var version = wx.getStorageSync(key.StorageKey.localVersion)
  157. if (!version) {
  158. wx.removeStorageSync(key.StorageKey.userCode)
  159. wx.removeStorageSync(key.StorageKey.user)
  160. wx.removeStorageSync(key.StorageKey.userPhone)
  161. } else if (version < this.localVersion) {
  162. } else {
  163. }
  164. wx.setStorageSync(key.StorageKey.localVersion, this.localVersion)
  165. },
  166. initRedDotArray: function () {
  167. this.redDotArray = ['0', '0', '0', '0', '0']
  168. this.tabRedDot = '0'
  169. },
  170. tabRedDot: '0',
  171. redDotArray: ['0', '0', '0', '0', '0'],
  172. bankCardTips:{},
  173. loginStatus: {
  174. key: '',
  175. isLogin: false
  176. },
  177. networkStatus: {
  178. type: 'none',
  179. connected: false
  180. },
  181. purchase: {
  182. // normalPurchaseDataArray: [],
  183. // supplementaryPurchaseDataArray: [],
  184. purchaseDataArray: [],
  185. purchaseData: null,
  186. order: null
  187. },
  188. globalData: {
  189. scene: null,//进入小程序场景
  190. flow_id: 1000,//从其他平台跳转过来的appID
  191. flow_name: '其他渠道来源',//从其他平台跳转过来的平台名称
  192. customerList: [],
  193. userInfo: {
  194. uid: '',
  195. phone: ''
  196. }
  197. },
  198. localVersion: 1,
  199. })