changpwd.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="app-container common-list-page">
  3. <el-form
  4. ref="temp"
  5. :model="temp"
  6. :rules="rules"
  7. status-icon
  8. label-width="100px"
  9. >
  10. <el-form-item label="旧密码:" prop="oldpassword">
  11. <el-input v-model="temp.oldpassword" type="password" auto-complete="off" />
  12. </el-form-item>
  13. <el-form-item label="新密码:" prop="password">
  14. <el-input v-model="temp.password" placeholder="请输入8位以上密码,必须包含英文字母、数字和特殊字符" type="password" auto-complete="off" />
  15. </el-form-item>
  16. <el-form-item label="确认密码:" prop="password1">
  17. <el-input v-model="temp.password1" placeholder="请输入8位以上密码,必须包含英文字母、数字和特殊字符" type="password" auto-complete="off" />
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" @click.native.prevent="toAmend">确认修改</el-button>
  21. </el-form-item>
  22. </el-form>
  23. </div>
  24. </template>
  25. <script>
  26. import { ExecDataByConfig } from '@/api/common'
  27. export default {
  28. data() {
  29. var oldPass = (rule, value, callback) => {
  30. if (!value) {
  31. callback(new Error('请输入旧密码'))
  32. } else if (value.toString().length < 6 || value.toString().length > 18) {
  33. callback(new Error('密码长度为6-18位'))
  34. } else {
  35. callback()
  36. }
  37. }
  38. var validatePass = (rule, value, callback) => {
  39. const re = new RegExp(`^(?=.*[a-z])(?=.*\\d)(?=.*\\W)[^]{8,32}$`)
  40. if (value === '') {
  41. callback(new Error('请输入密码'))
  42. } else if (!re.test(value)) {
  43. callback(new Error('密码由8位以上数字,大小写字母,特殊字符组成'))
  44. } else {
  45. callback()
  46. }
  47. }
  48. var validatePass2 = (rule, value, callback) => {
  49. if (value === '') {
  50. callback(new Error('请再次输入密码'))
  51. } else if (value !== this.temp.password) {
  52. callback(new Error('两次输入密码不一致!'))
  53. } else {
  54. callback()
  55. }
  56. }
  57. return {
  58. resetForm: {
  59. // name: 'updatePwd',
  60. // returntype: 'Map',
  61. // parammaps: {
  62. // password: '',
  63. // username: this.$store.state.user.name
  64. // }
  65. },
  66. temp: {},
  67. rules: {
  68. oldpassword: [
  69. { required: true, validator: oldPass, trigger: 'blur' }
  70. ],
  71. password: [
  72. { required: true, validator: validatePass, trigger: 'blur' }
  73. ],
  74. password1: [
  75. { required: true, validator: validatePass2, trigger: 'blur' }
  76. ]
  77. }
  78. }
  79. },
  80. methods: {
  81. toAmend() {
  82. console.log(111)
  83. this.$refs['temp'].validate(valid => {
  84. if (valid) {
  85. this.resetForm.common = { 'returnmap': '0' }
  86. this.resetForm.data = []
  87. this.resetForm.data[0] = { 'name': 'checkPassword', 'type': 'v', 'parammaps': {
  88. 'id': this.$store.state.user.employeid,
  89. 'password': this.temp.oldpassword
  90. }}
  91. this.resetForm.data[1] = { 'name': 'updatePwd', 'type': 'e', 'parammaps': {
  92. 'password': this.temp.password,
  93. 'username': this.$store.state.user.name
  94. }}
  95. ExecDataByConfig(this.resetForm).then(response => {
  96. console.log('保存发送参数', this.resetForm)
  97. if (response.msg === 'fail') {
  98. this.$notify({
  99. title: '保存失败',
  100. message: response.data,
  101. type: 'warning',
  102. duration: 2000
  103. })
  104. } else {
  105. setTimeout(() => {
  106. this.logout() // 调用跳转到登陆页的方法
  107. }, 1000)
  108. this.$notify({
  109. title: '',
  110. message: '保存成功',
  111. type: 'success',
  112. duration: 2000
  113. })
  114. }
  115. })
  116. }
  117. })
  118. },
  119. // 这是修改成功后重新返回登陆页的方法,看个人需要自行调整
  120. async logout() {
  121. await this.$store.dispatch('user/logout')
  122. this.$router.push(`/login`)
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .el-form {
  129. width: 60%;
  130. margin: 50px auto 0;
  131. text-align: center;
  132. button {
  133. margin: 20px 0 0;
  134. }
  135. }
  136. </style>