index.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. setTimeout(function () {
  86. hideLoading(()=>{
  87. // on confirm
  88. wx.reLaunch({ url: '/pages/login/index' })
  89. }, '登出成功', 'success')
  90. }, 3000)
  91. }, '登出中....')
  92. },
  93. check(): boolean {
  94. /// 请输入原密码!
  95. if (this.data.oldpwd === '') {
  96. showToast('请输入原密码!')
  97. return false
  98. }
  99. /// 请输入新密码!
  100. if (this.data.newpwd === '') {
  101. showToast('请输入新密码!')
  102. return false
  103. }
  104. /// 请输入原密码!
  105. if (this.data.confirmpwd === '') {
  106. showToast('请再次确认新密码!')
  107. return false
  108. }
  109. /// 两次输入的密码不一样!
  110. if (this.data.confirmpwd != this.data.newpwd) {
  111. showToast('两次输入的密码不一样!')
  112. return false
  113. }
  114. return true
  115. },
  116. /**
  117. * 生命周期函数--监听页面加载
  118. */
  119. onLoad() {
  120. },
  121. /**
  122. * 生命周期函数--监听页面初次渲染完成
  123. */
  124. onReady() {
  125. },
  126. /**
  127. * 生命周期函数--监听页面显示
  128. */
  129. onShow() {
  130. },
  131. /**
  132. * 生命周期函数--监听页面隐藏
  133. */
  134. onHide() {
  135. },
  136. /**
  137. * 生命周期函数--监听页面卸载
  138. */
  139. onUnload() {
  140. },
  141. /**
  142. * 页面相关事件处理函数--监听用户下拉动作
  143. */
  144. onPullDownRefresh() {
  145. },
  146. /**
  147. * 页面上拉触底事件的处理函数
  148. */
  149. onReachBottom() {
  150. },
  151. /**
  152. * 用户点击右上角分享
  153. */
  154. onShareAppMessage() {
  155. }
  156. })