From 3af138d2fede5981e89ea363ffca027d2daa08b1 Mon Sep 17 00:00:00 2001 From: Lazy <2211717435@qq.com> Date: Thu, 31 Aug 2023 01:04:51 +0800 Subject: [PATCH] Feat: add update password --- frontend/src/components/MyselfInfoDialog.vue | 52 ++++++++++++++------ frontend/src/services/apis/index.ts | 13 +++++ 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/MyselfInfoDialog.vue b/frontend/src/components/MyselfInfoDialog.vue index 66b147a3..770f7563 100644 --- a/frontend/src/components/MyselfInfoDialog.vue +++ b/frontend/src/components/MyselfInfoDialog.vue @@ -2,22 +2,26 @@ import { t } from "@/lang/i18n"; import { useAppStateStore } from "@/stores/useAppStateStore"; import { useAppToolsStore } from "@/stores/useAppToolsStore"; -import { reactive, toRaw } from "vue"; -import { setUserApiKey } from "@/services/apis"; +import { reactive, ref } from "vue"; +import { setUserApiKey, updatePassword } from "@/services/apis"; import { message } from "ant-design-vue"; +import type { FormInstance } from "ant-design-vue"; import CopyButton from "@/components/CopyButton.vue"; +import { sleep } from "@/tools/commom"; const { state, updateUserInfo } = useAppStateStore(); const { state: tools } = useAppToolsStore(); -const { execute, isLoading } = setUserApiKey(); +const { execute, isLoading: setUserApiKeyLoading } = setUserApiKey(); +const { execute: executeUpdatePassword, isLoading: updatePasswordLoading } = updatePassword(); const formState = reactive({ resetPassword: false, - oldPassword: "", password1: "", password2: "" }); +const formRef = ref(); + const handleGenerateApiKey = async (enable: boolean) => { const res = await execute({ data: { @@ -31,9 +35,25 @@ const handleGenerateApiKey = async (enable: boolean) => { } }; -const handleChangePassword = () => {}; -const onSubmit = () => { - console.log("submit!", toRaw(formState)); +const handleChangePassword = async () => { + formRef.value?.validateFields().then(async () => { + if (formState.password1 !== formState.password2) + return message.error(t("两次输入的密码不一致")); + if (formState.password1.length < 6 || formState.password1.length > 36) + return message.error(t("密码长度不能小于6位")); + try { + await executeUpdatePassword({ + data: { + passWord: formState.password1 + } + }); + await sleep(1000); + updateUserInfo(); + return message.success(t("更新成功")); + } catch (error: any) { + return message.error(error.response.data.data); + } + }); }; @@ -46,7 +66,7 @@ const onSubmit = () => { @ok="tools.showUserInfoDialog = false" >
- + @@ -87,12 +107,6 @@ const onSubmit = () => { 重置
- { :placeholder="t('请重复输入新密码')" />
- 确定 + + 确定 +
@@ -128,7 +148,7 @@ const onSubmit = () => { {{ t("生成") }} diff --git a/frontend/src/services/apis/index.ts b/frontend/src/services/apis/index.ts index 18b6c866..30ca2cd4 100644 --- a/frontend/src/services/apis/index.ts +++ b/frontend/src/services/apis/index.ts @@ -81,4 +81,17 @@ export const setUserApiKey = useDefineApi< >({ url: "/api/auth/api", method: "PUT" +}); + +// 更新密码 +export const updatePassword = useDefineApi< + { + data: { + passWord: string; + }; + }, + boolean +>({ + url: "/api/auth/update", + method: "PUT" }); \ No newline at end of file