From 52b9e8f3c84ec00fb4109cc682cc8548f9c45b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9A=93=E6=9C=88=E5=BD=92=E5=B0=98?= Date: Wed, 26 Feb 2025 17:13:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=94=80?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/login.ts | 5 ++ .../components/AccountSafe.vue | 11 +++- src/views/account-settings/utils/hooks.tsx | 50 +++++++++++++++++-- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/api/login.ts b/src/api/login.ts index f9620af..621a50f 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -156,3 +156,8 @@ export const postResetPasswordAPI = (data: ResetPasswordParams) => { data }); }; + +/**用户注销 */ +export const postUnbscribeAPI = () => { + return http.request("post", `/api/unsubscribe`); +}; diff --git a/src/views/account-settings/components/AccountSafe.vue b/src/views/account-settings/components/AccountSafe.vue index d3fedd4..a9db650 100644 --- a/src/views/account-settings/components/AccountSafe.vue +++ b/src/views/account-settings/components/AccountSafe.vue @@ -5,7 +5,8 @@ defineOptions({ name: "AccountSafe" }); -const { handleReset, handlePhone, handleEmail, userInfo } = useUserInfo(); +const { handleReset, handlePhone, handleEmail, userInfo, handleUnsubscribe } = + useUserInfo(); diff --git a/src/views/account-settings/utils/hooks.tsx b/src/views/account-settings/utils/hooks.tsx index 95391d9..79fce23 100644 --- a/src/views/account-settings/utils/hooks.tsx +++ b/src/views/account-settings/utils/hooks.tsx @@ -1,8 +1,14 @@ import { message } from "@/utils/message"; import { addDialog } from "@/components/ReDialog"; import { reactive, ref, onMounted, watch } from "vue"; -import { ElForm, ElFormItem, ElInput, ElProgress } from "element-plus"; -import { getUserInfoAPI } from "@/api/login"; +import { + ElForm, + ElFormItem, + ElInput, + ElMessageBox, + ElProgress +} from "element-plus"; +import { getUserInfoAPI, postUnbscribeAPI } from "@/api/login"; import { putUpdateEmailAPI, putUpdatePasswordAPI, @@ -12,6 +18,8 @@ import { isAllEmpty, isEmail, isPhone, storageLocal } from "@pureadmin/utils"; import { zxcvbn } from "@zxcvbn-ts/core"; import { setUserInfo, userInfoKey } from "@/utils/auth"; import type { UserInfo } from "types/system"; +import { transformI18n } from "@/plugins/i18n"; +import { useUserStoreHook } from "@/store/modules/user"; export const useUserInfo = () => { /** 密码正则(密码格式应为8-18位数字、字母、符号的任意两种组合) */ @@ -338,11 +346,47 @@ export const useUserInfo = () => { }); }; + /**注销账号 */ + const handleUnsubscribe = async () => { + ElMessageBox.confirm( + transformI18n("logout:cancellMessage"), + transformI18n("buttons:Cancell"), + { + confirmButtonText: transformI18n("buttons:Confirm"), + cancelButtonText: transformI18n("buttons:Cancel"), + type: "warning", + center: true + } + ) + .then(async () => { + const res = await postUnbscribeAPI(); + if (!res.success) { + useUserStoreHook().logOut(); + message(transformI18n("logout:cancellSuccess"), { + type: "success", + duration: 1000 + }); + } else { + message(transformI18n("logout:cancellFail"), { + type: "error", + duration: 1000 + }); + } + }) + .catch(() => { + message(transformI18n("logout:cancellCancel"), { + type: "info", + duration: 1000 + }); + }); + }; + return { userInfo, getUserInfo, handleReset, handlePhone, - handleEmail + handleEmail, + handleUnsubscribe }; };