index.ts 4.1 KB

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