app.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. wx.navigateTo({
  47. url: '/pages/FirstBangDing/FirstBangDing',
  48. })
  49. _this.globalData.waterCompanys=resData.waterCompany;
  50. if (!resData.swUserManagementVos || resData.swUserManagementVos.length == 0) {
  51. wx.navigateTo({
  52. url: '/pages/FirstBangDing/FirstBangDing',
  53. })
  54. } else {
  55. // _this.globalData.userBindInfo = groupArr
  56. }
  57. } else {
  58. utils.simleInfo('登录失败,请稍后再试')
  59. }
  60. },
  61. fail: error => {
  62. wx.hideLoading()
  63. utils.simleInfo('登录失败,请稍后再试')
  64. }
  65. })
  66. }else{
  67. utils.simleInfo('登录失败,请稍后再试')
  68. }
  69. }
  70. })
  71. },
  72. globalData: {
  73. // 当前用户信息
  74. userWxInfo: null,
  75. // 系统中存在的水务公司
  76. waterCompanys: [],
  77. // 小程序启动时带的参数
  78. launchPara: null,
  79. // 系统接口地址
  80. interfaceUrls: {
  81. loginUrl: baseIp+ '/wechat/login', // 登录+获取绑定列表
  82. accoundBind: baseIp+ '/wechat/account/bind', // 账号绑定
  83. },
  84. // 统一管理图片路径
  85. images: {
  86. logo: '/static_file/logo.png',
  87. background: '/static_file/background.png',
  88. card: '/static_file/card.png',
  89. tabBar: {
  90. home: '/static_file/homepage.png',
  91. homeActive: '/static_file/homepageCheck.png',
  92. profile: '/static_file/personalCenter.png',
  93. profileActive: '/static_file/personalCenterCheck.png',
  94. tzd: '/static_file/tzd.png',
  95. phone: '/static_file/phone.png',
  96. yl: '/static_file/yl.png',
  97. jcsfcjtzd:'/static_file/jcsfcjtzd.jpg'
  98. }
  99. }
  100. }
  101. })