resetPwd.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar title="修改登录密码" />
  6. <view class="tips">
  7. 修改密码后,需重新登录应用
  8. </view>
  9. <view class="container">
  10. <view class="form">
  11. <view class="cell">
  12. <view class="cell-title">
  13. 原密码
  14. </view>
  15. <view class="cell-body">
  16. <input
  17. v-model="form.oldPassword"
  18. type="text"
  19. :maxlength="20"
  20. :password="!checkedStatus"
  21. placeholder="请输入原密码"
  22. placeholder-class="wk-placehoder placeholder"
  23. class="input-core">
  24. <!-- <text
  25. v-if="focusFlag.oldPassword && form.oldPassword"
  26. class="wk wk-close-fill"
  27. @click="handleClear('oldPassword')" /> -->
  28. </view>
  29. </view>
  30. <view class="cell">
  31. <view class="cell-title">
  32. 新密码
  33. </view>
  34. <view class="cell-body">
  35. <input
  36. v-model="form.newPassword"
  37. type="text"
  38. :maxlength="20"
  39. :password="!checkedStatus"
  40. placeholder="请输入新密码,由6-20位字母、数字组成"
  41. placeholder-class="wk-placehoder placeholder"
  42. class="input-core">
  43. </view>
  44. </view>
  45. <view class="cell">
  46. <view class="cell-title">
  47. 确认密码
  48. </view>
  49. <view class="cell-body">
  50. <input
  51. v-model="form.confirmPassword"
  52. type="text"
  53. :maxlength="20"
  54. :password="!checkedStatus"
  55. placeholder="请确认新密码"
  56. placeholder-class="wk-placehoder placeholder"
  57. class="input-core">
  58. </view>
  59. </view>
  60. <view class="checkbox-cell" @tap.stop="changeTaskStatus">
  61. <view
  62. :class="{over: checkedStatus}"
  63. class="checkbox">
  64. <span v-if="checkedStatus" class="icon wk wk-check" />
  65. </view>
  66. <text class="checkbox-label">
  67. 显示密码
  68. </text>
  69. </view>
  70. </view>
  71. <view class="submit" @click="handleSubmit">
  72. 确认修改
  73. </view>
  74. </view>
  75. </view>
  76. <uni-popup ref="popup" type="dialog">
  77. <uni-popup-dialog
  78. :content="dialogMsg"
  79. type="warning"
  80. @confirm="handleDialogConfirm" />
  81. </uni-popup>
  82. </view>
  83. </template>
  84. <script>
  85. import { UpdatePassword } from 'API/admin'
  86. import WkFieldInput from '@/components/wk-form/wk-field-input.vue'
  87. import { mapGetters } from 'vuex'
  88. export default {
  89. name: 'ResetPassword',
  90. data() {
  91. return {
  92. form: {
  93. oldPassword: null,
  94. newPassword: null,
  95. confirmPassword: null,
  96. },
  97. focusFlag: {
  98. oldPassword: false,
  99. newPassword: false,
  100. confirmPassword: false
  101. },
  102. dialogMsg: '',
  103. checkedStatus: false
  104. }
  105. },
  106. computed: {
  107. ...mapGetters({
  108. userInfo: 'user/userInfo'
  109. })
  110. },
  111. methods: {
  112. changeTaskStatus() {
  113. this.checkedStatus = !this.checkedStatus
  114. },
  115. changeFocusFlag(type, val = false) {
  116. this.$set(this.focusFlag, type, val)
  117. },
  118. handleClear(type) {
  119. console.log('handleClear', this.form)
  120. this.$set(this.form, type, '')
  121. this.$set(this.focusFlag, type, true)
  122. },
  123. handleSubmit() {
  124. if (!this.form.oldPassword) {
  125. this.$toast('原密码不能为空!')
  126. return
  127. }
  128. const pwdReg = /^(?=.*[a-zA-Z])(?=.*\d).{6,20}$/
  129. if (!pwdReg.test(this.form.newPassword)) {
  130. this.$toast('密码由6到20位数字、字母组成')
  131. return
  132. }
  133. if (this.form.newPassword !== this.form.confirmPassword) {
  134. this.$toast('两次密码不一致请重新输入!')
  135. return
  136. }
  137. this.dialogMsg = '您确定要修改登录密码吗?'
  138. this.$refs.popup.open()
  139. },
  140. handleDialogConfirm(next) {
  141. next()
  142. let params = {
  143. id: this.userInfo.userId,
  144. oldPwd: this.form.oldPassword,
  145. newPwd: this.form.newPassword,
  146. }
  147. UpdatePassword(params).then(() => {
  148. this.$toast('修改成功,即将跳转重新登录')
  149. setTimeout(() => {
  150. this.$Router.reLaunch('/pages/login/index')
  151. }, 3000)
  152. }).catch()
  153. }
  154. }
  155. }
  156. </script>
  157. <style scoped lang="scss">
  158. .placeholder {
  159. font-size: 24rpx;
  160. color: $light;
  161. }
  162. .main-container {
  163. flex: 1;
  164. .tips {
  165. width: 100%;
  166. height: 76rpx;
  167. line-height: 76rpx;
  168. font-size: $wk-font-sm;
  169. color: $gray;
  170. background-color: #EBEEF1;
  171. padding: 0 45rpx;
  172. }
  173. .container {
  174. flex: 1;
  175. background-color: white;
  176. .form {
  177. padding: 0 45rpx;
  178. margin-top: 15rpx;
  179. .cell {
  180. margin-bottom: 20rpx;
  181. .cell-title {
  182. width: 100%;
  183. font-size: $wk-font-base;
  184. margin-bottom: 15rpx;
  185. }
  186. .cell-body {
  187. position: relative;
  188. .input-core {
  189. width: 100%;
  190. height: 80rpx;
  191. font-size: 28rpx;
  192. border: 1rpx solid #D2D2D2;
  193. border-radius: 8rpx;
  194. padding: 0 28rpx;
  195. }
  196. .wk-close-fill {
  197. position: absolute;
  198. top: 50%;
  199. right: 18rpx;
  200. transform: translateY(-50%);
  201. color: $light;
  202. font-size: $wk-font-base;
  203. }
  204. }
  205. }
  206. .checkbox-cell {
  207. width: 180rpx;
  208. @include left;
  209. .checkbox {
  210. width: 32rpx;
  211. height: 32rpx;
  212. margin-right: 15rpx;
  213. border: 1rpx solid #ccc;
  214. border-radius: 6rpx;
  215. overflow: hidden;
  216. @include center;
  217. .icon {
  218. font-size: $wk-font-mini;
  219. line-height: 1;
  220. color: white;
  221. }
  222. &.over {
  223. background-color: $theme-color;
  224. border-color: $theme-color;
  225. }
  226. }
  227. .checkbox-label {
  228. font-size: $wk-font-base;
  229. }
  230. }
  231. }
  232. .submit {
  233. width: 650rpx;
  234. height: 85rpx;
  235. text-align: center;
  236. font-size: 34rpx;
  237. line-height: 85rpx;
  238. color: white;
  239. background-color: $theme-color;
  240. border-radius: 16rpx;
  241. margin: 110rpx auto 0;
  242. }
  243. }
  244. }
  245. </style>