index.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <a-card>
  3. <a-form ref="formRef" :model="formState" :rules="rules" layout="vertical">
  4. <a-form-item label="旧密码:" name="password" has-feedback>
  5. <a-input
  6. v-model:value="formState.password"
  7. placeholder="请输入原密码"
  8. type="password"
  9. allow-clear
  10. autocomplete="off"
  11. />
  12. </a-form-item>
  13. <a-form-item label="新密码:" name="newPassword" has-feedback>
  14. <a-input
  15. v-model:value="formState.newPassword"
  16. placeholder="请输入新密码"
  17. type="password"
  18. allow-clear
  19. autocomplete="off"
  20. />
  21. </a-form-item>
  22. </a-form>
  23. <a-button type="primary" :loading="submitLoading" @click="onSubmit">保存</a-button>
  24. </a-card>
  25. </template>
  26. <script setup name="updatePassword">
  27. import { required } from '@/utils/formRules'
  28. import userCenterApi from '@/api/sys/userCenterApi'
  29. const formRef = ref()
  30. // 表单数据
  31. const formState = ref({})
  32. const submitLoading = ref(false)
  33. // 默认要校验的
  34. const rules = {
  35. password: [required('请输入原密码')],
  36. checkPassword: [required('请再次输入原密码')],
  37. newPassword: [required('请输入新密码')]
  38. }
  39. // 提交数据
  40. const onSubmit = async () => {
  41. const values = await formRef.value.validateFields()
  42. submitLoading.value = true
  43. userCenterApi
  44. .userUpdatePassword(values)
  45. .then(() => {
  46. formRef.value.resetFields()
  47. visible.value = false
  48. })
  49. .finally(() => {
  50. submitLoading.value = false
  51. })
  52. }
  53. </script>