mirror of
https://gitee.com/yiming_chang/vue-pure-admin.git
synced 2024-12-03 11:49:21 +08:00
perf: 优化免登录功能,用户可选择免登录的天数
This commit is contained in:
parent
7e7b6fee7a
commit
fc2d905e92
@ -116,8 +116,8 @@ login:
|
|||||||
username: Username
|
username: Username
|
||||||
password: Password
|
password: Password
|
||||||
verifyCode: VerifyCode
|
verifyCode: VerifyCode
|
||||||
remember: No need to login for 7 days
|
remember: days no need to login
|
||||||
rememberInfo: After checking and logging in, you will automatically log in to the system without entering your username and password within 7 days
|
rememberInfo: After checking and logging in, will automatically log in to the system without entering your username and password within the specified number of days.
|
||||||
sure: Sure Password
|
sure: Sure Password
|
||||||
forget: Forget Password?
|
forget: Forget Password?
|
||||||
login: Login
|
login: Login
|
||||||
|
@ -116,8 +116,8 @@ login:
|
|||||||
username: 账号
|
username: 账号
|
||||||
password: 密码
|
password: 密码
|
||||||
verifyCode: 验证码
|
verifyCode: 验证码
|
||||||
remember: 7天内免登录
|
remember: 天内免登录
|
||||||
rememberInfo: 勾选并登录后,7天内无需输入用户名和密码会自动登入系统
|
rememberInfo: 勾选并登录后,规定天数内无需输入用户名和密码会自动登入系统
|
||||||
sure: 确认密码
|
sure: 确认密码
|
||||||
forget: 忘记密码?
|
forget: 忘记密码?
|
||||||
login: 登录
|
login: 登录
|
||||||
|
@ -42,4 +42,5 @@ export type userType = {
|
|||||||
verifyCode?: string;
|
verifyCode?: string;
|
||||||
currentPage?: number;
|
currentPage?: number;
|
||||||
isRemembered?: boolean;
|
isRemembered?: boolean;
|
||||||
|
loginDay?: number;
|
||||||
};
|
};
|
||||||
|
@ -20,8 +20,10 @@ export const useUserStore = defineStore({
|
|||||||
verifyCode: "",
|
verifyCode: "",
|
||||||
// 判断登录页面显示哪个组件(0:登录(默认)、1:手机登录、2:二维码登录、3:注册、4:忘记密码)
|
// 判断登录页面显示哪个组件(0:登录(默认)、1:手机登录、2:二维码登录、3:注册、4:忘记密码)
|
||||||
currentPage: 0,
|
currentPage: 0,
|
||||||
// 是否勾选了7天内免登录
|
// 是否勾选了登录页的免登录
|
||||||
isRemembered: false
|
isRemembered: false,
|
||||||
|
// 登录页的免登录存储几天,默认7天
|
||||||
|
loginDay: 7
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
/** 存储用户名 */
|
/** 存储用户名 */
|
||||||
@ -40,10 +42,14 @@ export const useUserStore = defineStore({
|
|||||||
SET_CURRENTPAGE(value: number) {
|
SET_CURRENTPAGE(value: number) {
|
||||||
this.currentPage = value;
|
this.currentPage = value;
|
||||||
},
|
},
|
||||||
/** 存储是否勾选了7天内免登录 */
|
/** 存储是否勾选了登录页的免登录 */
|
||||||
SET_ISREMEMBERED(bool: boolean) {
|
SET_ISREMEMBERED(bool: boolean) {
|
||||||
this.isRemembered = bool;
|
this.isRemembered = bool;
|
||||||
},
|
},
|
||||||
|
/** 设置登录页的免登录存储几天 */
|
||||||
|
SET_LOGINDAY(value: number) {
|
||||||
|
this.loginDay = Number(value);
|
||||||
|
},
|
||||||
/** 登入 */
|
/** 登入 */
|
||||||
async loginByUsername(data) {
|
async loginByUsername(data) {
|
||||||
return new Promise<UserResult>((resolve, reject) => {
|
return new Promise<UserResult>((resolve, reject) => {
|
||||||
|
@ -42,6 +42,7 @@ export function getToken(): DataInfo<number> {
|
|||||||
export function setToken(data: DataInfo<Date>) {
|
export function setToken(data: DataInfo<Date>) {
|
||||||
let expires = 0;
|
let expires = 0;
|
||||||
const { accessToken, refreshToken } = data;
|
const { accessToken, refreshToken } = data;
|
||||||
|
const { isRemembered, loginDay } = useUserStoreHook();
|
||||||
expires = new Date(data.expires).getTime(); // 如果后端直接设置时间戳,将此处代码改为expires = data.expires,然后把上面的DataInfo<Date>改成DataInfo<number>即可
|
expires = new Date(data.expires).getTime(); // 如果后端直接设置时间戳,将此处代码改为expires = data.expires,然后把上面的DataInfo<Date>改成DataInfo<number>即可
|
||||||
const cookieString = JSON.stringify({ accessToken, expires });
|
const cookieString = JSON.stringify({ accessToken, expires });
|
||||||
|
|
||||||
@ -54,9 +55,9 @@ export function setToken(data: DataInfo<Date>) {
|
|||||||
Cookies.set(
|
Cookies.set(
|
||||||
multipleTabsKey,
|
multipleTabsKey,
|
||||||
"true",
|
"true",
|
||||||
useUserStoreHook().isRemembered
|
isRemembered
|
||||||
? {
|
? {
|
||||||
expires: 7
|
expires: loginDay
|
||||||
}
|
}
|
||||||
: {}
|
: {}
|
||||||
);
|
);
|
||||||
|
@ -44,6 +44,7 @@ defineOptions({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const imgCode = ref("");
|
const imgCode = ref("");
|
||||||
|
const loginDay = ref(7);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const checked = ref(false);
|
const checked = ref(false);
|
||||||
@ -111,6 +112,9 @@ watch(imgCode, value => {
|
|||||||
watch(checked, bool => {
|
watch(checked, bool => {
|
||||||
useUserStoreHook().SET_ISREMEMBERED(bool);
|
useUserStoreHook().SET_ISREMEMBERED(bool);
|
||||||
});
|
});
|
||||||
|
watch(loginDay, value => {
|
||||||
|
useUserStoreHook().SET_LOGINDAY(value);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -230,6 +234,19 @@ watch(checked, bool => {
|
|||||||
<div class="w-full h-[20px] flex justify-between items-center">
|
<div class="w-full h-[20px] flex justify-between items-center">
|
||||||
<el-checkbox v-model="checked">
|
<el-checkbox v-model="checked">
|
||||||
<span class="flex">
|
<span class="flex">
|
||||||
|
<select
|
||||||
|
v-model="loginDay"
|
||||||
|
:style="{
|
||||||
|
width: loginDay < 10 ? '10px' : '16px',
|
||||||
|
outline: 'none',
|
||||||
|
background: 'none',
|
||||||
|
appearance: 'none'
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<option value="1">1</option>
|
||||||
|
<option value="7">7</option>
|
||||||
|
<option value="30">30</option>
|
||||||
|
</select>
|
||||||
{{ t("login.remember") }}
|
{{ t("login.remember") }}
|
||||||
<el-tooltip
|
<el-tooltip
|
||||||
effect="dark"
|
effect="dark"
|
||||||
|
Loading…
Reference in New Issue
Block a user