From fc2d905e92d8cbba0f4f5a950f71ff8c22b5a3fb Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Mon, 9 Oct 2023 18:58:09 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=85=8D=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=8A=9F=E8=83=BD=EF=BC=8C=E7=94=A8=E6=88=B7=E5=8F=AF?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=85=8D=E7=99=BB=E5=BD=95=E7=9A=84=E5=A4=A9?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/en.yaml | 4 ++-- locales/zh-CN.yaml | 4 ++-- src/store/modules/types.ts | 1 + src/store/modules/user.ts | 12 +++++++++--- src/utils/auth.ts | 5 +++-- src/views/login/index.vue | 17 +++++++++++++++++ 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/locales/en.yaml b/locales/en.yaml index 6f3982aaa..cf9858c04 100644 --- a/locales/en.yaml +++ b/locales/en.yaml @@ -116,8 +116,8 @@ login: username: Username password: Password verifyCode: VerifyCode - remember: No need to login for 7 days - rememberInfo: After checking and logging in, you will automatically log in to the system without entering your username and password within 7 days + remember: days no need to login + 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 forget: Forget Password? login: Login diff --git a/locales/zh-CN.yaml b/locales/zh-CN.yaml index f7da8017b..a04e3539e 100644 --- a/locales/zh-CN.yaml +++ b/locales/zh-CN.yaml @@ -116,8 +116,8 @@ login: username: 账号 password: 密码 verifyCode: 验证码 - remember: 7天内免登录 - rememberInfo: 勾选并登录后,7天内无需输入用户名和密码会自动登入系统 + remember: 天内免登录 + rememberInfo: 勾选并登录后,规定天数内无需输入用户名和密码会自动登入系统 sure: 确认密码 forget: 忘记密码? login: 登录 diff --git a/src/store/modules/types.ts b/src/store/modules/types.ts index 352e3732a..1ae906310 100644 --- a/src/store/modules/types.ts +++ b/src/store/modules/types.ts @@ -42,4 +42,5 @@ export type userType = { verifyCode?: string; currentPage?: number; isRemembered?: boolean; + loginDay?: number; }; diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 7b39e1fcd..770411a1e 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -20,8 +20,10 @@ export const useUserStore = defineStore({ verifyCode: "", // 判断登录页面显示哪个组件(0:登录(默认)、1:手机登录、2:二维码登录、3:注册、4:忘记密码) currentPage: 0, - // 是否勾选了7天内免登录 - isRemembered: false + // 是否勾选了登录页的免登录 + isRemembered: false, + // 登录页的免登录存储几天,默认7天 + loginDay: 7 }), actions: { /** 存储用户名 */ @@ -40,10 +42,14 @@ export const useUserStore = defineStore({ SET_CURRENTPAGE(value: number) { this.currentPage = value; }, - /** 存储是否勾选了7天内免登录 */ + /** 存储是否勾选了登录页的免登录 */ SET_ISREMEMBERED(bool: boolean) { this.isRemembered = bool; }, + /** 设置登录页的免登录存储几天 */ + SET_LOGINDAY(value: number) { + this.loginDay = Number(value); + }, /** 登入 */ async loginByUsername(data) { return new Promise((resolve, reject) => { diff --git a/src/utils/auth.ts b/src/utils/auth.ts index 14774651d..ccefcf2b4 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -42,6 +42,7 @@ export function getToken(): DataInfo { export function setToken(data: DataInfo) { let expires = 0; const { accessToken, refreshToken } = data; + const { isRemembered, loginDay } = useUserStoreHook(); expires = new Date(data.expires).getTime(); // 如果后端直接设置时间戳,将此处代码改为expires = data.expires,然后把上面的DataInfo改成DataInfo即可 const cookieString = JSON.stringify({ accessToken, expires }); @@ -54,9 +55,9 @@ export function setToken(data: DataInfo) { Cookies.set( multipleTabsKey, "true", - useUserStoreHook().isRemembered + isRemembered ? { - expires: 7 + expires: loginDay } : {} ); diff --git a/src/views/login/index.vue b/src/views/login/index.vue index ee81bb75f..be9072326 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -44,6 +44,7 @@ defineOptions({ }); const imgCode = ref(""); +const loginDay = ref(7); const router = useRouter(); const loading = ref(false); const checked = ref(false); @@ -111,6 +112,9 @@ watch(imgCode, value => { watch(checked, bool => { useUserStoreHook().SET_ISREMEMBERED(bool); }); +watch(loginDay, value => { + useUserStoreHook().SET_LOGINDAY(value); +});