index.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. import CryptoJS from 'crypto-js';
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. /// 旧密码
  13. oldpwd: '',
  14. /// 新密码
  15. newpwd: '',
  16. /// 确认新密码
  17. confirmpwd: ''
  18. },
  19. /**
  20. * 返回上层视图
  21. */
  22. backToParent() {
  23. /// 返回上层视图
  24. wx.navigateBack()
  25. },
  26. /**
  27. * 修改密码
  28. */
  29. doModifyPwd() {
  30. /// 合规性校验
  31. if (!this.check()) { return }
  32. /// showModel
  33. showModel(() => {
  34. /// showLoading
  35. showLoading(() => {
  36. const OldPwd = loginid()+this.data.oldpwd
  37. const NewPwd = loginid()+this.data.newpwd
  38. /// 参数信息
  39. const info = JSON.stringify({
  40. Header: protoHeader(FunCode.ModifyPwdReq),
  41. ModifyPwdType: 1,
  42. ModifyPwdID: loginid(),
  43. OldPwd: CryptoJS.SHA256(OldPwd).toString(),
  44. NewPwd: CryptoJS.SHA256(NewPwd).toString()
  45. })
  46. /// 发送请求
  47. sendMsgToMQ({
  48. data: {
  49. isEncrypted: isEncrypted(),
  50. funCodeReq: FunCode.ModifyPwdReq,
  51. funCodeRsp: FunCode.ModifyPwdRsp,
  52. data: encryptBody(info)
  53. },
  54. success: (res) => {
  55. /// 请求失败
  56. if (res.code ! = 0) {
  57. hideLoading(() => {}, res.msg)
  58. return
  59. }
  60. /// 解析对象
  61. const data = JSON.parse(res.data.data)
  62. if (data.RetCode != 0) {
  63. hideLoading(() => {}, getErrorMsg(data.RetCode))
  64. return
  65. }
  66. hideLoading(()=> {
  67. /// 系统登出响应
  68. this.onLoginOut()
  69. }, '修改成功', 'success')
  70. },
  71. fail: (emsg) => {
  72. hideLoading(() => {}, emsg)
  73. }
  74. })
  75. }, '修改中')
  76. }, '提示', '确定要修改密码吗?')
  77. },
  78. /**
  79. * 系统登出响应
  80. */
  81. onLoginOut() {
  82. /// loding....
  83. showLoading(()=>{
  84. /// 清楚所有的缓存数据
  85. wx.clearStorage()
  86. /// 登出
  87. setTimeout(function () {
  88. hideLoading(()=>{
  89. // on confirm
  90. wx.reLaunch({ url: '/pages/login/index' })
  91. }, '登出成功', 'success')
  92. }, 3000)
  93. }, '登出中....')
  94. },
  95. check(): boolean {
  96. /// 请输入原密码!
  97. if (this.data.oldpwd === '') {
  98. showToast('请输入原密码!')
  99. return false
  100. }
  101. /// 请输入新密码!
  102. if (this.data.newpwd === '') {
  103. showToast('请输入新密码!')
  104. return false
  105. }
  106. /// 请输入原密码!
  107. if (this.data.confirmpwd === '') {
  108. showToast('请再次确认新密码!')
  109. return false
  110. }
  111. /// 两次输入的密码不一样!
  112. if (this.data.confirmpwd != this.data.newpwd) {
  113. showToast('两次输入的密码不一样!')
  114. return false
  115. }
  116. return true
  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. })