移动端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

155 lines
4.7 KiB

  1. <template>
  2. <div>
  3. <van-nav-bar
  4. title="密码修改"
  5. left-arrow
  6. @click-left="$router.back(-1)"
  7. />
  8. <van-cell-group style="width: 96%;margin:2%;border-radius: 6px;overflow: hidden;padding-top: 10px;padding-bottom: 10px;box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);">
  9. <van-field type="password" v-model="user.oldPassword" placeholder="" @input="clearError" >
  10. <template #left-icon>
  11. <van-image
  12. height="20"
  13. width="16"
  14. src="../../../static/images/onlineHome/lock.png"></van-image>
  15. </template>
  16. <template #label>
  17. <H4 style="margin-left: 5px">原密码</H4>
  18. </template>
  19. </van-field>
  20. <van-field type="password" :error-message="validate.newPassword" v-model="user.newPassword" placeholder="" @input="clearError" @blur="validate_newPassword">
  21. <template #left-icon>
  22. <van-image
  23. height="20"
  24. width="16"
  25. src="../../../static/images/onlineHome/lock.png"></van-image>
  26. </template>
  27. <template #label>
  28. <H4 style="margin-left: 5px">新密码</H4>
  29. </template>
  30. </van-field>
  31. <van-field type="password" v-model="user.confirmPassword" placeholder="" @input="clearError">
  32. <template #left-icon>
  33. <van-image
  34. height="20"
  35. width="16"
  36. src="../../../static/images/onlineHome/lock.png"></van-image>
  37. </template>
  38. <template #label>
  39. <H4 style="margin-left: 5px">确认密码</H4>
  40. </template>
  41. </van-field>
  42. </van-cell-group>
  43. <van-row style="text-align: center;margin-top: 40px">
  44. <van-button color="#1D6FE9" style="border-radius: 6px;width: 90%;margin: 0 auto" @click="submit">完成</van-button>
  45. </van-row>
  46. </div>
  47. </template>
  48. <script>
  49. import onlineHomeIndex from "../onlineHomeIndex";
  50. import {updateUserPwd} from "../../api/onlineHome/my";
  51. import {REGEXP} from "@/utils/global";
  52. import {Notify} from "vant";
  53. export default {
  54. components: {
  55. onlineHomeIndex
  56. },
  57. name: "password",
  58. data() {
  59. return {
  60. user: {
  61. oldPassword: undefined,
  62. newPassword: undefined,
  63. confirmPassword: undefined
  64. },
  65. validate: {
  66. newPassword: '',
  67. },
  68. };
  69. },
  70. methods: {
  71. submit() {
  72. if(!this.validate_newPassword())
  73. return;
  74. console.log(this.user)
  75. if(this.user.confirmPassword
  76. !=this.user.newPassword){
  77. this.$toast({
  78. icon: 'error', // 找到自己需要的图标
  79. message: '两次密码不同,请重新输入',
  80. duration:"1000",
  81. onClose:() => {
  82. if(0)
  83. {
  84. this.user.oldPassword=""
  85. this.user.newPassword=""
  86. this.user.confirmPassword=""
  87. }
  88. return false;
  89. }
  90. })
  91. }else{
  92. if(!this.validatePassword(this.user.newPassword))
  93. return;
  94. updateUserPwd(this.user.oldPassword, this.user.newPassword).then(
  95. response => {
  96. let _this =this
  97. this.$toast({
  98. icon: 'success', // 找到自己需要的图标
  99. message: '修改成功',
  100. duration:"1000",
  101. onClose:function(){
  102. _this.$router.back(-1);
  103. }
  104. })
  105. }
  106. );
  107. }
  108. },
  109. validatePassword(what) {
  110. if(!(REGEXP.PASSWORD.test(what)))
  111. {
  112. Notify.clear();
  113. Notify({ type: 'danger', message: '密码至少8个字符,必须包括字母、数字、特殊符号!' });
  114. return false;
  115. }
  116. return true;
  117. },
  118. validate_newPassword() {
  119. let password = this.user.newPassword;
  120. if(!password)
  121. {
  122. this.validate.newPassword = '';
  123. return false;
  124. }
  125. if(password.length < 8)
  126. {
  127. this.validate.newPassword = '密码长度至少8位';
  128. return false;
  129. }
  130. if(password.length > 20)
  131. {
  132. this.validate.newPassword = '密码长度不能超过20位';
  133. return false;
  134. }
  135. if(!(REGEXP.PASSWORD.test(password)))
  136. {
  137. this.validate.newPassword = '密码必须包括字母、数字、特殊符号!';
  138. return false;
  139. }
  140. this.validate.newPassword = '';
  141. return true;
  142. },
  143. clearError() {
  144. this.validate.newPassword = '';
  145. },
  146. }
  147. }
  148. </script>
  149. <style scoped>
  150. </style>