app.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // app.js
  2. const utils = require('/utils/util.js')
  3. // 图片预览地址
  4. const ipConfig = {
  5. develop: "http://192.168.0.215:", //开发地址
  6. trial: "http://61.177.40.178:", // 体验地址
  7. release: "https://www.izilaishui.com:", //上线地址
  8. }
  9. const hostConfig = {
  10. develop: "9000/wechat", //开发地址
  11. trial: "8000/wechat", // 体验地址
  12. release: "9000/wechat", //上线地址
  13. }
  14. App({
  15. onLaunch(options) {
  16. const updateManager = wx.getUpdateManager();
  17. updateManager.onCheckForUpdate(function(res) {
  18. // 请求完新版本信息的回调
  19. console.log(res.hasUpdate);
  20. });
  21. updateManager.onUpdateReady(function() {
  22. wx.showModal({
  23. title: "更新提示",
  24. content: "新版本已经准备好,是否重启应用?",
  25. success: function(res) {
  26. if (res.confirm) {
  27. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  28. updateManager.applyUpdate();
  29. }
  30. },
  31. });
  32. });
  33. updateManager.onUpdateFailed(function() {});
  34. const ACCOUNT_INFO = wx.getAccountInfoSync();
  35. const ENV_VERSION = ACCOUNT_INFO.miniProgram.envVersion;
  36. const baseIp = ipConfig[ENV_VERSION || develop];
  37. const host = hostConfig[ENV_VERSION || develop];
  38. const logs = wx.getStorageSync('logs') || []
  39. this.globalData.interfaceUrls = {
  40. loginUrl: baseIp + host + '/wechat/login', // 登录+获取绑定列表
  41. accountBind: baseIp + host + '/wechat/account/bind', // 账号绑定
  42. homePageInfo: baseIp + host + '/wechat/account/info/', // 首页获取用水量等信息
  43. billList: baseIp + host + '/wechat/bill/list', // 首页获取用水量等信息
  44. accountList: baseIp + host + '/wechat/account/list', // 首页获取用水量等信息
  45. accountUnbind: baseIp + host + '/wechat/account/unbind', // 户号解绑方法
  46. setDefaultAccount: baseIp + host + '/wechat/account/setDefaultAccount', // 设置默认户号
  47. repairRegistration: baseIp + host + '/wechat/registration/repair',//报修登记
  48. feedback: baseIp + host + '/wechat/registration/feedback',//投诉建议
  49. mineRepair: baseIp + host + '/wechat/mine/repair',//报修登记
  50. mineFeedback: baseIp + host + '/wechat/mine/feedback',//投诉建议
  51. paymentList: baseIp + host + '/wechat/payment/record',//缴费记录信息
  52. pendingBill: baseIp + host + '/wechat/bill/pending/',//代缴费用
  53. prepayOrder: baseIp + host + '/wechat/payment/prepayOrder/',//获取缴费的订单信息
  54. createPaymentRecord: baseIp + host + '/wechat/payment/record/create',//获取缴费的订单信息
  55. updateRadstateStatus: baseIp + host + '/wechat/account/readStatus',//修改已读状态
  56. updateRadstateStatusAll: baseIp + host + '/wechat/account/readStatusAll',//全部消息已读
  57. waterList: baseIp + host + '/water/list',//从主库获取全部水站信息
  58. getHuMing: baseIp + host + '/wechat/account/getHuMing'//根据户号、水站获取户名
  59. }
  60. // 微信静态文件预览方式 使用二开服务的使用次方法
  61. this.globalData.weChatImgPreviewUrl = baseIp + "8020/wechat/";
  62. // 平台
  63. this.globalData.imgPreviewUrl = baseIp + "9000/common/sys/sysfile/preview/";
  64. logs.unshift(Date.now())
  65. wx.setStorageSync('logs', logs)
  66. // 登录
  67. wx.login({
  68. success: res => {
  69. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  70. if (res.code) {
  71. const _this = this
  72. // 登录
  73. wx.showLoading({
  74. title: '登陆中...',
  75. mask: true,
  76. });
  77. wx.request({
  78. method: 'POST',
  79. url: _this.globalData.interfaceUrls.loginUrl,
  80. data: {
  81. wxCode: res.code,
  82. dsKey: options.query.deskey
  83. },
  84. success(res) {
  85. wx.hideLoading()
  86. if (!res.data.code || res.data.code != "200") {
  87. utils.simleInfoWithBack('登录失败,请稍后再试')
  88. return
  89. }
  90. _this.globalData.launchPara = options.query.deskey;
  91. const resData = res.data.data
  92. if (resData) {
  93. _this.globalData.userWxInfo = {
  94. openid: resData.openid,
  95. session_key: resData.session_key,
  96. token: resData.token,
  97. // 当前用户所关联的户号信息
  98. bindAccountInfo: resData.swUserManagementVos,
  99. // 当前用户所对应的水务公司
  100. currentDsKey: ""
  101. }
  102. if (resData.swUserManagementVos.length != 0) {
  103. _this.globalData.currentAccountInfo = (resData.swUserManagementVos || [])[0];
  104. _this.globalData.userWxInfo.currentDsKey = (resData.swUserManagementVos || [])[0].dsKey;
  105. };
  106. // _this.baseIp.waterCompanys=resData.waterCompany;
  107. if (resData.swUserManagementVos.length == 0) {
  108. _this.globalData.refresh = 0;
  109. wx.navigateTo({
  110. url: '/pages/FirstBangDing/FirstBangDing',
  111. })
  112. } else {
  113. _this.globalData.refresh = 1;
  114. wx.switchTab({
  115. url: '/pages/homepage/homepage',
  116. success: function () {
  117. var page = getCurrentPages().pop();
  118. if (page == undefined || page == null) return;
  119. page.onLoad(); //重新刷新页面
  120. }
  121. })
  122. }
  123. } else {
  124. utils.simleInfo('登录失败,请稍后再试')
  125. }
  126. },
  127. fail: error => {
  128. wx.hideLoading()
  129. utils.simleInfo('登录失败,请稍后再试')
  130. }
  131. })
  132. } else {
  133. utils.simleInfo('登录失败,请稍后再试')
  134. }
  135. }
  136. })
  137. },
  138. globalData: {
  139. nickName: "",
  140. avatarUrl: "",
  141. // 当前用户信息
  142. userWxInfo: {},
  143. // 系统中存在的水务公司
  144. waterCompanys: [],
  145. // 小程序启动时带的参数
  146. launchPara: null,
  147. // 当前用户所选择的账户信息
  148. currentAccountInfo: null,
  149. // 是否刷新主页数据
  150. refresh: 0,
  151. baseIp: "",
  152. // 系统接口地址
  153. interfaceUrls: {
  154. },
  155. // 微信静态文件预览方式 使用二开服务的使用次方法
  156. weChatImgPreviewUrl: "",
  157. // 平台
  158. imgPreviewUrl: "",
  159. // 统一管理图片路径
  160. images: {
  161. logo: '/static_file/logo.png',
  162. background: '/static_file/background.png',
  163. card: '/static_file/card.png',
  164. tabBar: {
  165. home: '/static_file/homepage.png',
  166. homeActive: '/static_file/homepageCheck.png',
  167. profile: '/static_file/personalCenter.png',
  168. profileActive: '/static_file/personalCenterCheck.png',
  169. tzd: '/static_file/tzd.png',
  170. phone: '/static_file/phone.png',
  171. yl: '/static_file/yl.png',
  172. jcsfcjtzd: '/static_file/jcsfcjtzd.jpg'
  173. }
  174. },
  175. // 用户通知公告
  176. notices: []
  177. }
  178. })