feat: 添加注销功能

This commit is contained in:
2025-02-25 18:19:19 +08:00
parent 06a4b57686
commit 47c00b1227
5 changed files with 71 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
title: System Title title: System Title
buttons:AccountSettings: Account buttons:AccountSettings: Account
buttons:LoginOut: LoginOut buttons:LoginOut: LoginOut
buttons:Cancell: Cancell Account
buttons:Login: Login buttons:Login: Login
buttons:OpenSystemSet: Open System Configs buttons:OpenSystemSet: Open System Configs
buttons:Reload: Reload buttons:Reload: Reload
@@ -172,6 +173,10 @@ logout:message: Whether to exit the system?
logout:success: Logout Success logout:success: Logout Success
logout:fail: Logout Fail logout:fail: Logout Fail
logout:cancel: Logout Cancel logout:cancel: Logout Cancel
logout:cancellMessage: Would you like to deactivate your account?
logout:cancellSuccess: Deletion successful
logout:cancellFail: Failed to cancell
logout:cancellCancel: cancell Cancel
user:buttons:addRole: Add User Role user:buttons:addRole: Add User Role
user:buttons:deleteRole: Delete User Role user:buttons:deleteRole: Delete User Role
user:buttons:updateRole: Update User Role user:buttons:updateRole: Update User Role

View File

@@ -1,6 +1,7 @@
title: 系统标题 title: 系统标题
buttons:AccountSettings: 账户设置 buttons:AccountSettings: 账户设置
buttons:LoginOut: 退出系统 buttons:LoginOut: 退出系统
buttons:Cancell: 注销账号
buttons:Login: 登录 buttons:Login: 登录
buttons:OpenSystemSet: 打开系统配置 buttons:OpenSystemSet: 打开系统配置
buttons:Reload: 重新加载 buttons:Reload: 重新加载
@@ -172,6 +173,10 @@ logout:message: 是否退出当前系统?
logout:success: 退出成功 logout:success: 退出成功
logout:fail: 退出失败 logout:fail: 退出失败
logout:cancel: 退出取消 logout:cancel: 退出取消
logout:cancellMessage: 是否注销账号?
logout:cancellSuccess: 注销成功
logout:cancellFail: 注销失败
logout:cancellCancel: 注销取消
user:buttons:addRole: 添加用户角色 user:buttons:addRole: 添加用户角色
user:buttons:deleteRole: 删除用户角色 user:buttons:deleteRole: 删除用户角色
user:buttons:updateRole: 更新用户角色 user:buttons:updateRole: 更新用户角色

View File

@@ -156,3 +156,8 @@ export const postResetPasswordAPI = (data: ResetPasswordParams) => {
data data
}); });
}; };
/**用户注销 */
export const postUnbscribeAPI = () => {
return http.request<null>("post", `/api/unsubscribe`);
};

View File

@@ -5,7 +5,8 @@ defineOptions({
name: "AccountSafe" name: "AccountSafe"
}); });
const { handleReset, handlePhone, handleEmail, userInfo } = useUserInfo(); const { handleReset, handlePhone, handleEmail, userInfo, handleUnsubscribe } =
useUserInfo();
</script> </script>
<template> <template>
@@ -57,6 +58,14 @@ const { handleReset, handlePhone, handleEmail, userInfo } = useUserInfo();
> >
</div> </div>
<el-divider /> <el-divider />
<div class="flex items-center">
<div class="flex-1">
<p>注销账号</p>
<el-text class="mx-1" type="info" />
</div>
<el-button type="danger" text @click="handleUnsubscribe">注销</el-button>
</div>
<el-divider />
</div> </div>
</template> </template>

View File

@@ -1,8 +1,14 @@
import { message } from "@/utils/message"; import { message } from "@/utils/message";
import { addDialog } from "@/components/ReDialog"; import { addDialog } from "@/components/ReDialog";
import { reactive, ref, onMounted, watch } from "vue"; import { reactive, ref, onMounted, watch } from "vue";
import { ElForm, ElFormItem, ElInput, ElProgress } from "element-plus"; import {
import { getUserInfoAPI } from "@/api/login"; ElForm,
ElFormItem,
ElInput,
ElMessageBox,
ElProgress
} from "element-plus";
import { getUserInfoAPI, postUnbscribeAPI } from "@/api/login";
import { import {
putUpdateEmailAPI, putUpdateEmailAPI,
putUpdatePasswordAPI, putUpdatePasswordAPI,
@@ -12,6 +18,8 @@ import { isAllEmpty, isEmail, isPhone, storageLocal } from "@pureadmin/utils";
import { zxcvbn } from "@zxcvbn-ts/core"; import { zxcvbn } from "@zxcvbn-ts/core";
import { setUserInfo, userInfoKey } from "@/utils/auth"; import { setUserInfo, userInfoKey } from "@/utils/auth";
import type { UserInfo } from "types/system"; import type { UserInfo } from "types/system";
import { transformI18n } from "@/plugins/i18n";
import { useUserStoreHook } from "@/store/modules/user";
export const useUserInfo = () => { export const useUserInfo = () => {
/** 密码正则密码格式应为8-18位数字、字母、符号的任意两种组合 */ /** 密码正则密码格式应为8-18位数字、字母、符号的任意两种组合 */
@@ -337,12 +345,46 @@ 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 { return {
userInfo, userInfo,
getUserInfo, getUserInfo,
handleReset, handleReset,
handlePhone, handlePhone,
handleEmail handleEmail,
handleUnsubscribe
}; };
}; };