app.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. cancelPay: baseIp + host + '/wechat/wechat/payment/cancel/' //用户表取消付款
  60. }
  61. // 微信静态文件预览方式 使用二开服务的使用次方法
  62. this.globalData.weChatImgPreviewUrl = baseIp + "8020/wechat/";
  63. // 平台
  64. this.globalData.imgPreviewUrl = baseIp + "9000/common/sys/sysfile/preview/";
  65. logs.unshift(Date.now())
  66. wx.setStorageSync('logs', logs)
  67. // 登录
  68. wx.login({
  69. success: res => {
  70. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  71. if (res.code) {
  72. const _this = this
  73. // 登录
  74. wx.showLoading({
  75. title: '登陆中...',
  76. mask: true,
  77. });
  78. wx.request({
  79. method: 'POST',
  80. url: _this.globalData.interfaceUrls.loginUrl,
  81. data: {
  82. wxCode: res.code,
  83. dsKey: options.query.deskey
  84. },
  85. success(res) {
  86. wx.hideLoading()
  87. if (!res.data.code || res.data.code != "200") {
  88. utils.simleInfoWithBack('登录失败,请稍后再试')
  89. return
  90. }
  91. _this.globalData.launchPara = options.query.deskey;
  92. const resData = res.data.data
  93. if (resData) {
  94. _this.globalData.userWxInfo = {
  95. openid: resData.openid,
  96. session_key: resData.session_key,
  97. token: resData.token,
  98. // 当前用户所关联的户号信息
  99. bindAccountInfo: resData.swUserManagementVos,
  100. // 当前用户所对应的水务公司
  101. currentDsKey: ""
  102. }
  103. if (resData.swUserManagementVos.length != 0) {
  104. _this.globalData.currentAccountInfo = (resData.swUserManagementVos || [])[0];
  105. _this.globalData.userWxInfo.currentDsKey = (resData.swUserManagementVos || [])[0].dsKey;
  106. };
  107. // _this.baseIp.waterCompanys=resData.waterCompany;
  108. if (resData.swUserManagementVos.length == 0) {
  109. _this.globalData.refresh = 0;
  110. wx.navigateTo({
  111. url: '/pages/FirstBangDing/FirstBangDing',
  112. })
  113. } else {
  114. _this.globalData.refresh = 1;
  115. wx.switchTab({
  116. url: '/pages/homepage/homepage',
  117. success: function () {
  118. var page = getCurrentPages().pop();
  119. if (page == undefined || page == null) return;
  120. page.onLoad(); //重新刷新页面
  121. }
  122. })
  123. }
  124. } else {
  125. utils.simleInfo('登录失败,请稍后再试')
  126. }
  127. },
  128. fail: error => {
  129. wx.hideLoading()
  130. utils.simleInfo('登录失败,请稍后再试')
  131. }
  132. })
  133. } else {
  134. utils.simleInfo('登录失败,请稍后再试')
  135. }
  136. }
  137. })
  138. },
  139. globalData: {
  140. nickName: "",
  141. avatarUrl: "",
  142. // 当前用户信息
  143. userWxInfo: {},
  144. // 系统中存在的水务公司
  145. waterCompanys: [],
  146. // 小程序启动时带的参数
  147. launchPara: null,
  148. // 当前用户所选择的账户信息
  149. currentAccountInfo: null,
  150. // 是否刷新主页数据
  151. refresh: 0,
  152. baseIp: "",
  153. // 系统接口地址
  154. interfaceUrls: {
  155. },
  156. // 微信静态文件预览方式 使用二开服务的使用次方法
  157. weChatImgPreviewUrl: "",
  158. // 平台
  159. imgPreviewUrl: "",
  160. // 统一管理图片路径
  161. images: {
  162. logo: '/static_file/logo.png',
  163. background: '/static_file/background.png',
  164. card: '/static_file/card.png',
  165. tabBar: {
  166. home: '/static_file/homepage.png',
  167. homeActive: '/static_file/homepageCheck.png',
  168. profile: '/static_file/personalCenter.png',
  169. profileActive: '/static_file/personalCenterCheck.png',
  170. tzd: '/static_file/tzd.png',
  171. phone: '/static_file/phone.png',
  172. yl: '/static_file/yl.png',
  173. jcsfcjtzd: '/static_file/jcsfcjtzd.jpg'
  174. }
  175. },
  176. // 用户通知公告
  177. notices: []
  178. }
  179. })