index.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import { FunCode } from "../../../constants/enum/funcode"
  2. import { sendMsgToMQ } from "../../../services/api/common/index"
  3. import { getErrorMsg, isEncrypted, loginid, protoHeader } from "../../../services/utils"
  4. import { hideLoading, showLoading, showModel, showToast } from "../../../utils/message/index"
  5. import { encryptBody } from "../../../utils/websocket/crypto"
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. /// 旧密码
  12. oldpwd: '',
  13. /// 新密码
  14. newpwd: '',
  15. /// 确认新密码
  16. confirmpwd: ''
  17. },
  18. /**
  19. * 返回上层视图
  20. */
  21. backToParent() {
  22. /// 返回上层视图
  23. wx.navigateBack()
  24. },
  25. /**
  26. * 修改密码
  27. */
  28. doModifyPwd() {
  29. /// 合规性校验
  30. if (!this.check()) {
  31. return
  32. }
  33. // /// showModel
  34. // showModel(() => {
  35. // /// showLoading
  36. // showLoading(() => {
  37. /// 参数信息
  38. const info = JSON.stringify({
  39. Header: protoHeader(FunCode.ModifyPwdReq),
  40. ModifyPwdType: 1,
  41. ModifyPwdID: loginid(),
  42. OldPwd: encryptBody(this.data.oldpwd, true),
  43. NewPwd: encryptBody(this.data.newpwd, true)
  44. })
  45. /// 发送请求
  46. sendMsgToMQ({
  47. data: {
  48. isEncrypted: isEncrypted(),
  49. funCodeReq: FunCode.ModifyPwdReq,
  50. funCodeRsp: FunCode.ModifyPwdRsp,
  51. data: encryptBody(info)
  52. },
  53. success: (res) => {
  54. /// 请求失败
  55. if (res.code ! = 0) {
  56. hideLoading(() => {}, res.msg, 'error')
  57. return
  58. }
  59. /// 解析对象
  60. const data = JSON.parse(res.data.data)
  61. if (data.RetCode != 0) {
  62. hideLoading(() => {}, getErrorMsg(data.RetCode), 'error')
  63. return
  64. }
  65. hideLoading(()=> {
  66. /// 系统登出响应
  67. this.onLoginOut()
  68. }, '修改成功', 'success')
  69. },
  70. fail: (emsg) => {
  71. hideLoading(() => {}, emsg, 'error')
  72. }
  73. })
  74. // }, '修改中')
  75. // }, '提示', '确定要修改密码吗?')
  76. },
  77. /**
  78. * 系统登出响应
  79. */
  80. onLoginOut() {
  81. /// 清楚所有的缓存数据
  82. wx.clearStorage()
  83. /// loding....
  84. showLoading(()=>{
  85. /// 登出
  86. setTimeout(function () {
  87. hideLoading(()=>{
  88. // on confirm
  89. wx.reLaunch({ url: '/pages/login/index' })
  90. }, '登出成功', 'success')
  91. }, 3000)
  92. }, '登出中....')
  93. },
  94. check(): boolean {
  95. /// 请输入原密码!
  96. if (this.data.oldpwd === '') {
  97. showToast('请输入原密码!')
  98. return false
  99. }
  100. /// 请输入新密码!
  101. if (this.data.newpwd === '') {
  102. showToast('请输入新密码!')
  103. return false
  104. }
  105. /// 请输入原密码!
  106. if (this.data.confirmpwd === '') {
  107. showToast('请再次确认新密码!')
  108. return false
  109. }
  110. /// 两次输入的密码不一样!
  111. if (this.data.confirmpwd != this.data.newpwd) {
  112. showToast('两次输入的密码不一样!')
  113. return false
  114. }
  115. return true
  116. },
  117. /**
  118. * 生命周期函数--监听页面加载
  119. */
  120. onLoad() {
  121. },
  122. /**
  123. * 生命周期函数--监听页面初次渲染完成
  124. */
  125. onReady() {
  126. },
  127. /**
  128. * 生命周期函数--监听页面显示
  129. */
  130. onShow() {
  131. },
  132. /**
  133. * 生命周期函数--监听页面隐藏
  134. */
  135. onHide() {
  136. },
  137. /**
  138. * 生命周期函数--监听页面卸载
  139. */
  140. onUnload() {
  141. },
  142. /**
  143. * 页面相关事件处理函数--监听用户下拉动作
  144. */
  145. onPullDownRefresh() {
  146. },
  147. /**
  148. * 页面上拉触底事件的处理函数
  149. */
  150. onReachBottom() {
  151. },
  152. /**
  153. * 用户点击右上角分享
  154. */
  155. onShareAppMessage() {
  156. }
  157. })