resetPwd.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <el-form ref="form" :model="pwd" :rules="rules" label-width="80px">
  3. <el-form-item label="旧密码" prop="oldPassword">
  4. <el-input v-model="pwd.oldPassword" placeholder="请输入旧密码" type="password" show-password/>
  5. </el-form-item>
  6. <el-form-item label="新密码" prop="newPassword">
  7. <el-input v-model="pwd.newPassword" placeholder="请输入新密码" type="password" show-password/>
  8. </el-form-item>
  9. <el-form-item label="确认密码" prop="confirmPassword">
  10. <el-input v-model="pwd.confirmPassword" placeholder="请确认新密码" type="password" show-password/>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" size="mini" @click="submit">保存</el-button>
  14. <el-button type="danger" size="mini" @click="close">关闭</el-button>
  15. </el-form-item>
  16. </el-form>
  17. </template>
  18. <script>
  19. import { mapGetters } from 'vuex'
  20. import {doEncrypt, doDecryptStr,doSign,doVerifySignature,userinfoEncrypt,userinfoDecrypt} from '@/utils/smutil'
  21. import { debounce } from 'lodash'
  22. export default {
  23. // computed: {
  24. // ...mapGetters([
  25. // 'userinfo'
  26. // ])
  27. // },
  28. data() {
  29. const equalToPassword = (rule, value, callback) => {
  30. if (this.pwd.newPassword !== value) {
  31. callback(new Error("新密码两次输入的密码不一致"));
  32. } else {
  33. callback();
  34. }
  35. };
  36. return {
  37. user: {},
  38. pwd: {
  39. oldPassword: undefined,
  40. newPassword: undefined,
  41. confirmPassword: undefined
  42. },
  43. // 表单校验
  44. rules: {
  45. oldPassword: [
  46. { required: true, message: "旧密码不能为空", trigger: "blur" }
  47. ],
  48. newPassword: [
  49. { required: true, message: "新密码不能为空", trigger: "blur" },
  50. { min: 8, max: 20, message: "长度在 8 到 20 个字符", trigger: "blur" }
  51. ],
  52. confirmPassword: [
  53. { required: true, message: "确认密码不能为空", trigger: "blur" },
  54. { required: true, validator: equalToPassword, trigger: "blur" }
  55. ]
  56. },
  57. //字母连续规则
  58. strReg : /(a(?=b)|b(?=c)|c(?=d)|d(?=e)|e(?=f)|f(?=g)|g(?=h)|h(?=i)|i(?=j)|j(?=k)|k(?=l)|l(?=m)|m(?=n)|n(?=o)|o(?=p)|p(?=q)|q(?=r)|r(?=s)|s(?=t)|t(?=u)|u(?=v)|v(?=w)|w(?=x)|x(?=y)|y(?=z)|z(?=a)){3}[a-z]/i,
  59. strResverReg : /(a(?=z)|z(?=y)|y(?=x)|x(?=w)|w(?=v)|v(?=u)|u(?=t)|t(?=s)|s(?=r)|r(?=q)|q(?=p)|p(?=o)|o(?=n)|n(?=m)|m(?=l)|l(?=k)|k(?=j)|j(?=i)|i(?=h)|h(?=g)|g(?=f)|f(?=e)|e(?=d)|d(?=c)|c(?=b)|b(?=a)){3}[a-z]/i,
  60. //数字连续规则
  61. numReg : /(0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)|9(?=0)){3}\d/,
  62. numResverReg : /(0(?=9)|9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){3}\d/,
  63. //键盘字母横向连续规则
  64. keyboardHorizontalReg : /(q(?=w)|w(?=e)|e(?=r)|r(?=t)|t(?=y)|y(?=u)|u(?=i)|i(?=o)|o(?=p)|p(?=q)|a(?=s)|s(?=d)|d(?=f)|f(?=g)|g(?=h)|h(?=j)|j(?=k)|k(?=l)|l(?=a)|z(?=x)|x(?=c)|c(?=v)|v(?=b)|b(?=n)|n(?=m)|m(?=z)){3}[a-z]/i,
  65. keyboardHorizontalResverReg : /(p(?=o)|o(?=i)|i(?=u)|u(?=y)|y(?=t)|t(?=r)|r(?=e)|e(?=w)|w(?=q)|q(?=p)|l(?=k)|k(?=j)|j(?=h)|h(?=g)|g(?=f)|f(?=d)|d(?=s)|s(?=a)|a(?=l)|m(?=n)|n(?=b)|b(?=v)|v(?=c)|c(?=x)|x(?=z)|z(?=m)){3}[a-z]/i,
  66. //多个相同字母、数字规则
  67. sameReg : /([0-9a-zA-Z])\1{3}/,
  68. keyboardSlopeArr : ["1qaz", "2wsx", "3edc", "4rfv", "5tgb", "6yhn", "7ujm", "8ik,", "9ol.", "0p;/", "/;p0", ".lo9", ",ki8", "mju7", "nhy6", "bgt5", "vfr4", "cde3", "xsw2", "zaq1", "4esz", "5rdx", "6tfc", "7ygv", "8uhb", "9ijn", "0okm", "-pl,", "=[;.", ".;[=", ",lp-", "mko0", "nji9", "bhu8", "vgy7", "cft6", "xdr5", "zse4"],
  69. keyboardSlopeShiftArr : ["!qaz", "@wsx", "#edc","$rfv", "%tgb", "^yhn", "&ujm", "*ik<", "(ol>", ")p:?", "?:p)", ">lo(", "<ki*", "mju&", "nhy^", "bgt%", "vfr$", "cde#", "xsw@", "zaq!", "$esz", "%rdx", "^tfc", "&ygv", "*uhb", "(ijn", ")okm", "_pl<", "+{:>", ">:{+", "<lp_", "mko)", "nji(", "bhu*", "vgy&", "cft^", "xdr%", "zse$"],
  70. lastReg: /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,20}$/
  71. };
  72. },
  73. methods: {
  74. // 表单重置
  75. pwdReset() {
  76. this.pwd={
  77. oldPassword: undefined,
  78. newPassword: undefined,
  79. confirmPassword: undefined
  80. }
  81. },
  82. submit:debounce(function(){
  83. this.$refs["form"].validate(valid => {
  84. if (valid) {
  85. // 密码验证规则
  86. if (this.sameReg.test(this.pwd.newPassword)) {
  87. this.$message.error('密码不能含有连续4位相同的数字或字母')
  88. return
  89. } else if (this.strResverReg.test(this.pwd.newPassword.toLowerCase())) {
  90. this.$message.error('密码不能含有4位连续的字母')
  91. return
  92. } else if (this.strReg.test(this.pwd.newPassword.toLowerCase())) {
  93. this.$message.error('密码不能含有4位连续的字母')
  94. return
  95. } else if (this.numReg.test(this.pwd.newPassword)) {
  96. this.$message.error('密码不能含有4位连续的数字')
  97. return
  98. } else if (this.numResverReg.test(this.pwd.newPassword)) {
  99. this.$message.error('密码不能含有4位连续的数字')
  100. return
  101. } else if (this.keyboardHorizontalReg.test(this.pwd.newPassword)) {
  102. this.$message.error('密码不能含有4位横向连续的字母')
  103. return
  104. } else if (this.keyboardHorizontalResverReg.test(this.pwd.newPassword)) {
  105. this.$message.error('密码不能含有4位横向连续的字母')
  106. return
  107. } else if (this.keyboardSlopeArr.some(v => this.pwd.newPassword.toLowerCase().indexOf(v) > -1)) {
  108. this.$message.error('密码不能含有4位键盘斜向连续的字符')
  109. return
  110. } else if (this.keyboardSlopeShiftArr.some(v => this.pwd.newPassword.toLowerCase().indexOf(v) > -1)) {
  111. this.$message.error('密码不能含有4位键盘斜向连续的字符')
  112. return
  113. } else if (!this.lastReg.test(this.pwd.newPassword)) {
  114. this.$message.error('密码不满足8~20位大写字母、小写字母、数字、特殊字符三种以上的组合')
  115. return
  116. }
  117. // 用户信息解密
  118. let decryptUserInfo = userinfoDecrypt(sessionStorage.getItem('userinfo'))
  119. this.user = JSON.parse(decryptUserInfo).sysUser
  120. const param = {
  121. id: this.user.id,
  122. oldPassword: this.pwd.oldPassword,
  123. newPassword: this.pwd.newPassword,
  124. confirmPassword: this.pwd.confirmPassword
  125. }
  126. this.$axios.post('/sysUserController/updatePassword', param).then((res) => {
  127. if (res.code==0){
  128. this.$message.success('密码修改成功')
  129. this.pwdReset()
  130. }
  131. if (res.code==1){
  132. this.$message.error(res.data)
  133. }
  134. }).catch((error) => {
  135. // this.$message.error(error)
  136. })
  137. }
  138. });
  139. },1000),
  140. close() {
  141. this.$tab.closePage();
  142. }
  143. }
  144. };
  145. </script>