app.js 6.4 KB

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