mirror of
https://github.com/MCSManager/MCSManager.git
synced 2024-12-03 07:20:16 +08:00
Feat: add update password
This commit is contained in:
parent
7d5960a558
commit
3af138d2fe
@ -2,22 +2,26 @@
|
|||||||
import { t } from "@/lang/i18n";
|
import { t } from "@/lang/i18n";
|
||||||
import { useAppStateStore } from "@/stores/useAppStateStore";
|
import { useAppStateStore } from "@/stores/useAppStateStore";
|
||||||
import { useAppToolsStore } from "@/stores/useAppToolsStore";
|
import { useAppToolsStore } from "@/stores/useAppToolsStore";
|
||||||
import { reactive, toRaw } from "vue";
|
import { reactive, ref } from "vue";
|
||||||
import { setUserApiKey } from "@/services/apis";
|
import { setUserApiKey, updatePassword } from "@/services/apis";
|
||||||
import { message } from "ant-design-vue";
|
import { message } from "ant-design-vue";
|
||||||
|
import type { FormInstance } from "ant-design-vue";
|
||||||
import CopyButton from "@/components/CopyButton.vue";
|
import CopyButton from "@/components/CopyButton.vue";
|
||||||
|
import { sleep } from "@/tools/commom";
|
||||||
const { state, updateUserInfo } = useAppStateStore();
|
const { state, updateUserInfo } = useAppStateStore();
|
||||||
const { state: tools } = useAppToolsStore();
|
const { state: tools } = useAppToolsStore();
|
||||||
|
|
||||||
const { execute, isLoading } = setUserApiKey();
|
const { execute, isLoading: setUserApiKeyLoading } = setUserApiKey();
|
||||||
|
const { execute: executeUpdatePassword, isLoading: updatePasswordLoading } = updatePassword();
|
||||||
|
|
||||||
const formState = reactive({
|
const formState = reactive({
|
||||||
resetPassword: false,
|
resetPassword: false,
|
||||||
oldPassword: "",
|
|
||||||
password1: "",
|
password1: "",
|
||||||
password2: ""
|
password2: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const formRef = ref<FormInstance>();
|
||||||
|
|
||||||
const handleGenerateApiKey = async (enable: boolean) => {
|
const handleGenerateApiKey = async (enable: boolean) => {
|
||||||
const res = await execute({
|
const res = await execute({
|
||||||
data: {
|
data: {
|
||||||
@ -31,9 +35,25 @@ const handleGenerateApiKey = async (enable: boolean) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChangePassword = () => {};
|
const handleChangePassword = async () => {
|
||||||
const onSubmit = () => {
|
formRef.value?.validateFields().then(async () => {
|
||||||
console.log("submit!", toRaw(formState));
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -46,7 +66,7 @@ const onSubmit = () => {
|
|||||||
@ok="tools.showUserInfoDialog = false"
|
@ok="tools.showUserInfoDialog = false"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<a-form :model="formState" layout="vertical">
|
<a-form ref="formRef" :model="formState" layout="vertical">
|
||||||
<a-row>
|
<a-row>
|
||||||
<a-col :span="12">
|
<a-col :span="12">
|
||||||
<a-form-item :label="t('用户名')">
|
<a-form-item :label="t('用户名')">
|
||||||
@ -87,12 +107,6 @@ const onSubmit = () => {
|
|||||||
重置
|
重置
|
||||||
</a-button>
|
</a-button>
|
||||||
<div v-if="formState.resetPassword">
|
<div v-if="formState.resetPassword">
|
||||||
<a-input
|
|
||||||
v-model:value="formState.oldPassword"
|
|
||||||
size="default"
|
|
||||||
class="mb-12"
|
|
||||||
:placeholder="t('请输入旧密码')"
|
|
||||||
/>
|
|
||||||
<a-input
|
<a-input
|
||||||
v-model:value="formState.password1"
|
v-model:value="formState.password1"
|
||||||
size="default"
|
size="default"
|
||||||
@ -106,7 +120,13 @@ const onSubmit = () => {
|
|||||||
:placeholder="t('请重复输入新密码')"
|
:placeholder="t('请重复输入新密码')"
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<a-button size="default" @click="handleChangePassword">确定</a-button>
|
<a-button
|
||||||
|
size="default"
|
||||||
|
:loading="updatePasswordLoading"
|
||||||
|
@click="handleChangePassword"
|
||||||
|
>
|
||||||
|
确定
|
||||||
|
</a-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
@ -128,7 +148,7 @@ const onSubmit = () => {
|
|||||||
<a-button
|
<a-button
|
||||||
class="mr-10"
|
class="mr-10"
|
||||||
size="default"
|
size="default"
|
||||||
:loading="isLoading"
|
:loading="setUserApiKeyLoading"
|
||||||
@click="handleGenerateApiKey(true)"
|
@click="handleGenerateApiKey(true)"
|
||||||
>
|
>
|
||||||
{{ t("生成") }}
|
{{ t("生成") }}
|
||||||
|
@ -81,4 +81,17 @@ export const setUserApiKey = useDefineApi<
|
|||||||
>({
|
>({
|
||||||
url: "/api/auth/api",
|
url: "/api/auth/api",
|
||||||
method: "PUT"
|
method: "PUT"
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更新密码
|
||||||
|
export const updatePassword = useDefineApi<
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
passWord: string;
|
||||||
|
};
|
||||||
|
},
|
||||||
|
boolean
|
||||||
|
>({
|
||||||
|
url: "/api/auth/update",
|
||||||
|
method: "PUT"
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user