modPassword.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div>
  3. <el-dialog title="修改密码" :visible.sync="dialog" width="450px" :close-on-click-modal="false" top="50px">
  4. <el-form ref="form" :model="form" :rules="formRules" label-width="80px" class="bind-phone">
  5. <el-form-item label="旧密码:" label-width="150px" prop="old_password" :rules="formRules.password">
  6. <el-input v-model="form.old_password" placeholder="请输入旧密码"> </el-input>
  7. </el-form-item>
  8. <el-form-item label="新密码:" label-width="150px" prop="new_password" :rules="formRules.password">
  9. <el-input placeholder="请输入新密码" @keyup.enter.native="handleSubmit" v-model="form.new_password"></el-input>
  10. </el-form-item>
  11. </el-form>
  12. <div slot="footer" class="dialog-footer text-center">
  13. <el-button @click="dialog = false">取 消</el-button>
  14. <el-button type="danger" @click="handleSubmit">确 定</el-button>
  15. </div>
  16. </el-dialog>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. value: {
  23. type: Boolean,
  24. default: true
  25. }
  26. },
  27. data() {
  28. return {
  29. dialog: !!this.value,
  30. form: {
  31. old_password: '',
  32. new_password: ''
  33. }
  34. }
  35. },
  36. methods: {
  37. async handleSubmit() {
  38. this.$refs.form.validate(async valid => {
  39. if (valid) {
  40. const data = await this.$fetch('/user/set_me_password', this.form)
  41. if (data.code == 200) {
  42. await this.$store.dispatch('user/logout')
  43. this.$router.push(`/login`)
  44. }
  45. } else {
  46. console.log('error submit!!')
  47. return false
  48. }
  49. })
  50. }
  51. },
  52. watch: {
  53. dialog(val) {
  54. if (!val) this.$emit('input', val)
  55. }
  56. }
  57. }
  58. </script>
  59. <style lang="scss" scoped>
  60. .top-tip {
  61. margin-top: -20px;
  62. margin-bottom: 20px;
  63. }
  64. </style>