app.js 3.2 KB

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