feat: 添加注销功能
This commit is contained in:
parent
39ed03386d
commit
52b9e8f3c8
@ -156,3 +156,8 @@ export const postResetPasswordAPI = (data: ResetPasswordParams) => {
|
|||||||
data
|
data
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**用户注销 */
|
||||||
|
export const postUnbscribeAPI = () => {
|
||||||
|
return http.request<null>("post", `/api/unsubscribe`);
|
||||||
|
};
|
||||||
|
@ -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>
|
||||||
|
|
||||||
|
@ -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位数字、字母、符号的任意两种组合) */
|
||||||
@ -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 {
|
return {
|
||||||
userInfo,
|
userInfo,
|
||||||
getUserInfo,
|
getUserInfo,
|
||||||
handleReset,
|
handleReset,
|
||||||
handlePhone,
|
handlePhone,
|
||||||
handleEmail
|
handleEmail,
|
||||||
|
handleUnsubscribe
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user