app.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // app.js
  2. const utils = require('/utils/util.js')
  3. const baseIp= "http://localhost:9747"
  4. // 图片预览地址
  5. App({
  6. onLaunch(options) {
  7. // 展示本地存储能力
  8. const logs = wx.getStorageSync('logs') || []
  9. logs.unshift(Date.now())
  10. wx.setStorageSync('logs', logs)
  11. // 登录
  12. wx.login({
  13. success: res => {
  14. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  15. if(res.code){
  16. const _this = this
  17. // 登录
  18. wx.showLoading({
  19. title: '登陆中...',
  20. mask: true,
  21. });
  22. wx.request({
  23. method: 'POST',
  24. url: _this.globalData.interfaceUrls.loginUrl,
  25. data: {
  26. wxCode: res.code,
  27. dsKey: options.query.deskey
  28. },
  29. success(res) {
  30. debugger
  31. wx.hideLoading()
  32. if (!res.data.code || res.data.code!= "200") {
  33. utils.simleInfoWithBack('登录失败,请稍后再试')
  34. return
  35. }
  36. _this.globalData.launchPara=options.query.deskey;
  37. const resData = res.data.data
  38. if (resData) {
  39. _this.globalData.userWxInfo = {
  40. openid: resData.openid,
  41. session_key: resData.session_key,
  42. token: resData.token,
  43. // 当前用户所关联的户号信息
  44. bindAccountInfo: resData.swUserManagementVos,
  45. // 当前用户所对应的水务公司
  46. currentDsKey:""
  47. }
  48. if(resData.swUserManagementVos.length!=0){
  49. _this.globalData.currentAccountInfo=(resData.swUserManagementVos||[])[0]
  50. };
  51. _this.globalData.waterCompanys=resData.waterCompany;
  52. if (resData.swUserManagementVos.length == 0) {
  53. _this.globalData.refresh=0;
  54. wx.navigateTo({
  55. url: '/pages/FirstBangDing/FirstBangDing',
  56. })
  57. } else {
  58. _this.globalData.refresh=1;
  59. wx.switchTab({
  60. url: '/pages/homepage/homepage',
  61. success:function () {
  62. var page = getCurrentPages().pop();
  63. if (page == undefined || page == null) return;
  64. page.onLoad(); //重新刷新页面
  65. }
  66. })
  67. }
  68. } else {
  69. utils.simleInfo('登录失败,请稍后再试')
  70. }
  71. },
  72. fail: error => {
  73. wx.hideLoading()
  74. utils.simleInfo('登录失败,请稍后再试')
  75. }
  76. })
  77. }else{
  78. utils.simleInfo('登录失败,请稍后再试')
  79. }
  80. }
  81. })
  82. },
  83. globalData: {
  84. // 当前用户信息
  85. userWxInfo: {},
  86. // 系统中存在的水务公司
  87. waterCompanys: [],
  88. // 小程序启动时带的参数
  89. launchPara: null,
  90. // 当前用户所选择的户号信息
  91. currentAccountInfo:null,
  92. // 是否刷新主页数据
  93. refresh:0,
  94. // 系统接口地址
  95. interfaceUrls: {
  96. loginUrl: baseIp+ '/wechat/login', // 登录+获取绑定列表
  97. accoundBind: baseIp+ '/wechat/account/bind', // 账号绑定
  98. homePageInfo: baseIp+ '/wechat/account/info/', // 首页获取用水量等信息
  99. billList: baseIp+ '/wechat/bill/list', // 首页获取用水量等信息
  100. },
  101. imgPreviewUrl: "http://192.168.0.215:9000/common/sys/sysfile/preview?fileId=",
  102. // 统一管理图片路径
  103. images: {
  104. logo: '/static_file/logo.png',
  105. background: '/static_file/background.png',
  106. card: '/static_file/card.png',
  107. tabBar: {
  108. home: '/static_file/homepage.png',
  109. homeActive: '/static_file/homepageCheck.png',
  110. profile: '/static_file/personalCenter.png',
  111. profileActive: '/static_file/personalCenterCheck.png',
  112. tzd: '/static_file/tzd.png',
  113. phone: '/static_file/phone.png',
  114. yl: '/static_file/yl.png',
  115. jcsfcjtzd:'/static_file/jcsfcjtzd.jpg'
  116. }
  117. }
  118. }
  119. })