login.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // pages/login/login.ts
  2. import {login, loginQuery} from '../../services/api/account/index'
  3. import { appConfig } from '../../config/index'
  4. import { getDivisions, loginid, taAccounts } from '../../services/utils'
  5. import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. /// 底部安全区域
  12. safeBottom: getApp().globalData.safeBottom,
  13. /// 姓名
  14. username: '110000000001',
  15. /// 密码
  16. pwd: 'BgAAAPir1cgH1bw5xgrywoXpw8l/s5auAXn8MA==',
  17. /// 版本号
  18. version: appConfig.version,
  19. /// 是否loding
  20. isLoding: false,
  21. },
  22. /**
  23. * 合规性校验
  24. */
  25. check(): boolean {
  26. /// 请输入用户名
  27. if (this.data.username.length == 0) {
  28. Toast('请输入用户名!')
  29. return false
  30. }
  31. /// 请输入密码并且大于6位数!
  32. if (this.data.pwd.length < 6) {
  33. Toast('请输入密码并且大于6位数!')
  34. return false
  35. }
  36. return true
  37. },
  38. /**
  39. * 用户登录请求方法
  40. */
  41. onLogin() {
  42. /// 合规性校验
  43. if (!this.check()) return
  44. /// loding.....
  45. this.setData({ isLoding: true })
  46. /// loding......
  47. wx.showLoading({title: '登录中.....'})
  48. /// 进行账户登录
  49. login({
  50. data: {
  51. userName: this.data.username,
  52. password: this.data.pwd,
  53. clientType: 5
  54. },
  55. enableAuthorization: false,
  56. success: (res) => {
  57. /// 登录失败
  58. if (res.code != 0) {
  59. Toast('登录查询失败,原因:'+res.msg)
  60. return
  61. }
  62. /// 存储token以及loginId、userId
  63. wx.setStorageSync('Authorization', res.data.token)
  64. wx.setStorageSync('LoginID', res.data.loginId)
  65. wx.setStorageSync('UserId', res.data.userId)
  66. /// 获取地区区域信息
  67. getDivisions()
  68. /// 获取资金账户信息
  69. taAccounts()
  70. /// 登录查询
  71. this.loginQuery()
  72. },
  73. fail: (emsg) => {
  74. Toast('登录查询失败,原因:'+emsg)
  75. },
  76. complete: () => {
  77. /// 清除Toast
  78. wx.hideLoading()
  79. /// isLoding
  80. this.setData({ isLoding: false })
  81. }
  82. })
  83. },
  84. /// 登录查询
  85. loginQuery() {
  86. /// showLoading
  87. Toast.loading({ message: '数据查询中.....' })
  88. /// 发送查询请求
  89. loginQuery({
  90. data: { loginID: loginid() },
  91. success: (res) => {
  92. /// 数据存储
  93. wx.setStorageSync('LoginQuery', res.data)
  94. /// 存储市场ID
  95. wx.setStorageSync('MarketID', res.data.markets[0].marketid)
  96. /// 登录失败
  97. if (res.code != 200) {
  98. Toast.fail({message: '登录查询失败,原因:'+res.msg})
  99. return
  100. }
  101. /// showToast
  102. Toast.success({ message: '登录成功' })
  103. /// 跳转到首页
  104. wx.reLaunch({ url: '/pages/home/home' })
  105. },
  106. fail: (emsg) => {
  107. /// showToast
  108. Toast.fail({message: '登录查询失败,原因:'+emsg})
  109. },
  110. complete: () => {
  111. /// hideLoading
  112. Toast.clear()
  113. /// isLoding
  114. this.setData({ isLoding: false })
  115. }
  116. })
  117. },
  118. /**
  119. * 生命周期函数--监听页面加载
  120. */
  121. onLoad() {
  122. },
  123. /**
  124. * 生命周期函数--监听页面初次渲染完成
  125. */
  126. onReady() {
  127. },
  128. /**
  129. * 生命周期函数--监听页面显示
  130. */
  131. onShow() {
  132. },
  133. /**
  134. * 生命周期函数--监听页面隐藏
  135. */
  136. onHide() {
  137. },
  138. /**
  139. * 生命周期函数--监听页面卸载
  140. */
  141. onUnload() {
  142. },
  143. /**
  144. * 页面相关事件处理函数--监听用户下拉动作
  145. */
  146. onPullDownRefresh() {
  147. },
  148. /**
  149. * 页面上拉触底事件的处理函数
  150. */
  151. onReachBottom() {
  152. },
  153. /**
  154. * 用户点击右上角分享
  155. */
  156. onShareAppMessage() {
  157. }
  158. })