MarkChangeProfile.vue 2.7 KB

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