updatePassword.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. validator: (rule, value, callback) => {
  83. if (value.length < 8) {
  84. callback(new Error('密码不可小于8位'))
  85. } else {
  86. callback()
  87. }
  88. },
  89. trigger: 'blur'
  90. }
  91. ],
  92. newPwdConfirm: [
  93. { required: true, message: '确认密码', trigger: 'blur' },
  94. {
  95. validator: (rule, value, callback) => {
  96. if (value === '') {
  97. callback(new Error('请再次输入密码'))
  98. } else if (value !== this.form.newPwd) {
  99. callback(new Error('两次输入密码不一致'))
  100. } else {
  101. callback()
  102. }
  103. },
  104. trigger: 'blur'
  105. }
  106. ]
  107. }
  108. }
  109. },
  110. mounted() {
  111. },
  112. methods: {
  113. passwordUpdate: function() {
  114. const _this = this
  115. this.$refs.form.validate(valid => {
  116. if (valid) {
  117. const doing = this.$notify({
  118. title: '正在修改,请稍等',
  119. type: 'warning'
  120. })
  121. const postData = {
  122. password: _this.$md5(_this.form.newPwd),
  123. id: _this.$common.currUser().id
  124. }
  125. const userType = _this.$common.currUserType()
  126. //console.log('userType:', userType)
  127. channel.globeRequest(
  128. userType === '2' ? 'BizUserController' : 'UserController',
  129. 'editPwd',
  130. postData,
  131. 'Update Pwd'
  132. ).then((res) => {
  133. doing.close()
  134. _this.$notify({
  135. title: '修改成功,请重新登录',
  136. type: 'info'
  137. })
  138. _this.logout()
  139. _this.closeUpdate()
  140. }).catch((err, x) => {
  141. doing.close()
  142. _this.$alert(err)
  143. })
  144. } else {
  145. //console.log('error submit!!')
  146. return false
  147. }
  148. })
  149. },
  150. closeUpdate: function() {
  151. this.form.oldPwd = ''
  152. this.form.newPwd = ''
  153. this.form.newPwdConfirm = ''
  154. this.$emit('closeUpdate')
  155. },
  156. async logout() {
  157. await this.$store.dispatch('user/logout')
  158. const userType = this.$common.currUserType()
  159. if (userType === '2') {
  160. this.$router.push(`/bizLogin`)
  161. } else {
  162. this.$router.push(`/login`)
  163. }
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. .updatePass{
  170. .col-txt{
  171. font-size: 0.8vw;
  172. }
  173. .el-button{
  174. font-size: 0.8vw;
  175. padding: 0.6vw 1.1vw;
  176. border-radius: 0.3vw;
  177. }
  178. }
  179. </style>