9c536c9cd8c6fb1fecccc3aa081c48c72187d619.svn-base 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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" type="password" auto-complete="off" />
  15. </el-form-item>
  16. <el-form-item label="确认密码:" prop="password1">
  17. <el-input v-model="temp.password1" 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. import Cookies from 'js-cookie'
  28. export default {
  29. data() {
  30. var oldPass = (rule, value, callback) => {
  31. if (!value) {
  32. callback(new Error('请输入旧密码'))
  33. } else if (value.toString().length < 6 || value.toString().length > 18) {
  34. callback(new Error('密码长度为6-18位'))
  35. } else {
  36. callback()
  37. }
  38. }
  39. var validatePass = (rule, value, callback) => {
  40. console.log(value)
  41. if (!value) {
  42. callback(new Error('请输入新密码'))
  43. } else if (value.toString().length < 6 || value.toString().length > 18) {
  44. callback(new Error('密码长度为6-18位'))
  45. } else {
  46. callback()
  47. }
  48. }
  49. var validatePass2 = (rule, value, callback) => {
  50. if (value === '') {
  51. callback(new Error('请再次输入密码'))
  52. } else if (value !== this.temp.password) {
  53. callback(new Error('两次输入密码不一致!'))
  54. } else {
  55. callback()
  56. }
  57. }
  58. return {
  59. resetForm: {
  60. // name: 'updatePwd',
  61. // returntype: 'Map',
  62. // parammaps: {
  63. // password: '',
  64. // username: this.$store.state.user.name
  65. // }
  66. },
  67. temp: {},
  68. rules: {
  69. oldpassword: [
  70. { required: true, validator: oldPass, trigger: 'blur' }
  71. ],
  72. password: [
  73. { required: true, validator: validatePass, trigger: 'blur' }
  74. ],
  75. password1: [
  76. { required: true, validator: validatePass2, trigger: 'blur' }
  77. ]
  78. }
  79. }
  80. },
  81. methods: {
  82. toAmend() {
  83. console.log(111)
  84. this.$refs['temp'].validate(valid => {
  85. if (valid) {
  86. this.resetForm.common = { 'returnmap': '0' }
  87. this.resetForm.data = []
  88. this.resetForm.data[0] = { 'name': 'checkPassword', 'type': 'v', 'parammaps': {
  89. 'id': Cookies.get('employeid'),
  90. 'password': this.temp.oldpassword
  91. }}
  92. this.resetForm.data[1] = { 'name': 'updatePwd', 'type': 'e', 'parammaps': {
  93. 'password': this.temp.password,
  94. 'username': Cookies.get('name')
  95. }}
  96. ExecDataByConfig(this.resetForm).then(response => {
  97. console.log('保存发送参数', this.resetForm)
  98. if (response.msg === 'fail') {
  99. this.$notify({
  100. title: '保存失败',
  101. message: response.data,
  102. type: 'warning',
  103. duration: 2000
  104. })
  105. } else {
  106. setTimeout(() => {
  107. this.logout() // 调用跳转到登陆页的方法
  108. }, 1000)
  109. this.$notify({
  110. title: '',
  111. message: '保存成功',
  112. type: 'success',
  113. duration: 2000
  114. })
  115. }
  116. })
  117. }
  118. })
  119. // this.resetForm.parammaps.password = this.temp.password
  120. // this.resetForm.parammaps.username = this.$store.state.user.name
  121. // PostDataByName(this.resetForm).then(response => {
  122. // if (response.msg === 'fail') {
  123. // this.$notify({
  124. // title: '失败',
  125. // message: '修改失败',
  126. // type: 'danger',
  127. // duration: 2000
  128. // })
  129. // } else {
  130. // setTimeout(() => {
  131. // this.logout() // 调用跳转到登陆页的方法
  132. // }, 1000)
  133. // this.$notify({
  134. // title: '成功',
  135. // message: '修改成功',
  136. // type: 'success',
  137. // duration: 2000
  138. // })
  139. // }
  140. // console.log(response)
  141. // })
  142. // }
  143. // })
  144. },
  145. // 这是修改成功后重新返回登陆页的方法,看个人需要自行调整
  146. async logout() {
  147. await this.$store.dispatch('user/logout')
  148. this.$router.push(`/login`)
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .el-form {
  155. width: 60%;
  156. margin: 50px auto 0;
  157. text-align: center;
  158. button {
  159. margin: 20px 0 0;
  160. }
  161. }
  162. </style>