changpwd.vue 5.5 KB

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