MarkChangeProfile.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <a-modal
  3. title="修改个人信息"
  4. v-model:visible="visible"
  5. :confirm-loading="confirmLoading"
  6. @ok="handleOk"
  7. @cancel="handleCancel"
  8. :zIndex="2000"
  9. >
  10. <a-form labelAlign="right" :labelCol="{ span: 4 }">
  11. <a-form-item class="tw-mb-2" :required="true" label="姓名">
  12. <a-input
  13. @keydown.stop="() => {}"
  14. v-model:value="user.name"
  15. placeholder="姓名"
  16. />
  17. </a-form-item>
  18. <a-form-item class="tw-mb-2" label="新密码">
  19. <a-input
  20. @keydown.stop="() => {}"
  21. type="password"
  22. v-model:value="user.password"
  23. placeholder="输入新密码"
  24. />
  25. </a-form-item>
  26. <a-form-item class="tw-mb-2" label="确认新密码">
  27. <a-input
  28. @keydown.stop="() => {}"
  29. type="password"
  30. v-model:value="user.confirmPassword"
  31. placeholder="再次输入新密码"
  32. />
  33. </a-form-item>
  34. </a-form>
  35. </a-modal>
  36. </template>
  37. <script lang="ts">
  38. import { changeUserInfo, doLogout } from "@/api/markPage";
  39. import { message } from "ant-design-vue";
  40. import { ref, defineComponent, reactive, watchEffect } from "vue";
  41. import { store } from "./store";
  42. interface User {
  43. name: string;
  44. password: string;
  45. confirmPassword: string;
  46. }
  47. export default defineComponent({
  48. name: "MarkChangeProfile",
  49. setup() {
  50. const user = reactive<User>({
  51. name: "",
  52. password: "",
  53. confirmPassword: "",
  54. });
  55. watchEffect(() => {
  56. user.name = store.setting.userName;
  57. });
  58. const visible = ref<boolean>(false);
  59. const confirmLoading = ref<boolean>(false);
  60. const showModal = () => {
  61. visible.value = true;
  62. };
  63. const handleOk = () => {
  64. if (user.name.length === 0 || user.name.length >= 30) {
  65. message.error({ content: "姓名长度必须在1到30之间" });
  66. return;
  67. }
  68. if (user.password.length !== 0 || user.confirmPassword.length !== 0) {
  69. if (user.password.length === 0 || user.password.length >= 16) {
  70. message.error({ content: "密码长度必须在1到16之间" });
  71. return;
  72. }
  73. if (user.password !== user.confirmPassword) {
  74. message.error({ content: "两次输入的密码不一致" });
  75. return;
  76. }
  77. }
  78. confirmLoading.value = true;
  79. changeUserInfo(user.name, user.password)
  80. .then(() => doLogout())
  81. .finally(() => {
  82. visible.value = false;
  83. confirmLoading.value = false;
  84. });
  85. };
  86. const handleCancel = () => {
  87. user.name = store.setting.userName;
  88. user.password = "";
  89. user.confirmPassword = "";
  90. };
  91. return {
  92. user,
  93. visible,
  94. confirmLoading,
  95. showModal,
  96. handleOk,
  97. handleCancel,
  98. };
  99. },
  100. });
  101. </script>