updatePassword.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div class="updatePass">
  3. <el-form ref="form" :model="form" :rules="rules">
  4. <el-row>
  5. <el-col style="padding-bottom: 10px">
  6. <el-card shadow="hover" style="padding: 20px">
  7. <el-row v-if="info" style="height: 40px">
  8. <el-col :span="24" class="tc f-normal"><span>{{ info }}</span></el-col>
  9. </el-row>
  10. <el-row>
  11. <el-col :span="4" class="col-txt"><span>原密码</span></el-col>
  12. <el-col :span="18" class="col-input">
  13. <el-form-item prop="oldPwd">
  14. <el-input v-model="form.oldPwd" type="password" />
  15. </el-form-item>
  16. </el-col>
  17. </el-row>
  18. <el-row>
  19. <el-col :span="4" class="col-txt"><span>新密码</span></el-col>
  20. <el-col :span="18" class="col-input">
  21. <el-form-item prop="newPwd">
  22. <el-input v-model="form.newPwd" type="password" />
  23. </el-form-item>
  24. </el-col>
  25. </el-row>
  26. <el-row>
  27. <el-col :span="4" class="col-txt"><span>再次输入</span></el-col>
  28. <el-col :span="18" class="col-input">
  29. <el-form-item prop="newPwdConfirm">
  30. <el-input v-model="form.newPwdConfirm" type="password" />
  31. </el-form-item>
  32. </el-col>
  33. </el-row>
  34. </el-card>
  35. </el-col>
  36. </el-row>
  37. </el-form>
  38. <div class="el-dialog__footer">
  39. <el-button @click="closeUpdate">取 消</el-button>
  40. <el-button type="primary" @click="passwordUpdate()">确 定</el-button>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. /* common function */
  46. import channel from '@/static/utils/channel'
  47. import { isPassword } from '../../static/utils/validate'
  48. export default {
  49. props: {
  50. info: {
  51. type: String,
  52. default: ''
  53. }
  54. },
  55. data() {
  56. return {
  57. // 密码修改
  58. form: {
  59. oldPwd: '',
  60. newPwd: '',
  61. newPwdConfirm: ''
  62. },
  63. rules: {
  64. oldPwd: [
  65. { required: true, message: '请输入原密码', trigger: 'blur' },
  66. {
  67. validator: (rule, value, callback) => {
  68. if (value === '') {
  69. callback(new Error('请输入原密码'))
  70. } else if (this.$md5(this.$md5(value)) !== this.$common.currUser().password) {
  71. callback(new Error('原密码不正确'))
  72. } else {
  73. callback()
  74. }
  75. },
  76. trigger: 'blur'
  77. }
  78. ],
  79. newPwd: [
  80. { required: true, trigger: 'blur', validator: isPassword }
  81. ],
  82. newPwdConfirm: [
  83. { required: true, message: '确认密码', trigger: 'blur' },
  84. {
  85. validator: (rule, value, callback) => {
  86. if (value === '') {
  87. callback(new Error('请再次输入密码'))
  88. } else if (value !== this.form.newPwd) {
  89. callback(new Error('两次输入密码不一致'))
  90. } else {
  91. callback()
  92. }
  93. },
  94. trigger: 'blur'
  95. }
  96. ]
  97. }
  98. }
  99. },
  100. mounted() {
  101. },
  102. methods: {
  103. passwordUpdate: function() {
  104. const _this = this
  105. this.$refs.form.validate(valid => {
  106. if (valid) {
  107. const doing = this.$notify({
  108. title: '正在修改,请稍等',
  109. type: 'warning'
  110. })
  111. const postData = {
  112. password: _this.$md5(_this.form.newPwd),
  113. id: _this.$common.currUser().id
  114. }
  115. const userType = _this.$common.currUserType()
  116. //console.log('userType:', userType)
  117. channel.globeRequest(
  118. userType === '2' ? 'BizUserController' : 'UserController',
  119. 'editPwd',
  120. postData,
  121. 'Update Pwd'
  122. ).then((res) => {
  123. doing.close()
  124. _this.$notify({
  125. title: '修改成功,请重新登录',
  126. type: 'info'
  127. })
  128. _this.logout()
  129. _this.closeUpdate()
  130. }).catch((err, x) => {
  131. doing.close()
  132. _this.$alert(err)
  133. })
  134. } else {
  135. //console.log('error submit!!')
  136. return false
  137. }
  138. })
  139. },
  140. closeUpdate: function() {
  141. this.form.oldPwd = ''
  142. this.form.newPwd = ''
  143. this.form.newPwdConfirm = ''
  144. this.$emit('closeUpdate')
  145. },
  146. async logout() {
  147. await this.$store.dispatch('user/logout')
  148. const userType = this.$common.currUserType()
  149. if (userType === '2') {
  150. this.$router.push(`/bizLogin`)
  151. } else {
  152. this.$router.push(`/login`)
  153. }
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. .updatePass{
  160. .col-txt{
  161. font-size: 0.8vw;
  162. }
  163. .el-button{
  164. font-size: 0.8vw;
  165. padding: 0.6vw 1.1vw;
  166. border-radius: 0.3vw;
  167. }
  168. }
  169. </style>