Skip to content

Commit eb1fc03

Browse files
committed
chore: merge dev into master
2 parents 908025a + 422f9d4 commit eb1fc03

5 files changed

Lines changed: 60 additions & 26 deletions

File tree

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ VITE_API_URL = /api
1111
VITE_ADMIN_PROXY_PATH = http://localhost:9999
1212

1313
# 前端加密密钥
14-
VITE_PWD_ENC_KEY='pigpigpigpig0000'
14+
VITE_PWD_ENC_KEY='thanks,pig4cloud'
1515

1616
# OAUTH2 密码模式客户端信息
1717
VITE_OAUTH2_PASSWORD_CLIENT='pig:pig'

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"echarts": "5.6.0",
2626
"element-plus": "2.13.7",
2727
"js-base64": "3.7.8",
28-
"js-cookie": "3.0.7",
28+
"js-cookie": "3.0.8",
2929
"lodash": "4.18.1",
3030
"mitt": "3.0.1",
3131
"nprogress": "0.2.0",
@@ -35,7 +35,7 @@
3535
"sortablejs": "1.15.7",
3636
"splitpanes": "3.2.0",
3737
"v-calendar": "3.1.2",
38-
"vue": "3.5.34",
38+
"vue": "3.5.35",
3939
"vue-clipboard3": "2.0.0",
4040
"vue-echarts": "7.0.3",
4141
"vue-i18n": "9.2.2",
@@ -45,14 +45,14 @@
4545
},
4646
"devDependencies": {
4747
"@types/crypto-js": "4.2.2",
48-
"@types/node": "22.19.19",
48+
"@types/node": "22.19.20",
4949
"@types/nprogress": "0.2.3",
5050
"@types/sm-crypto": "0.3.4",
5151
"@types/sortablejs": "1.15.9",
5252
"@typescript-eslint/eslint-plugin": "5.53.0",
5353
"@typescript-eslint/parser": "5.53.0",
5454
"@vitejs/plugin-vue": "5.2.4",
55-
"@vue/compiler-sfc": "3.5.34",
55+
"@vue/compiler-sfc": "3.5.35",
5656
"autoprefixer": "10.4.27",
5757
"cross-env": "7.0.3",
5858
"daisyui": "3.9.4",

src/stores/userInfo.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Local, Session, STORAGE_KEYS } from '/@/utils/storage';
1+
import { Cookie, Local, Session, STORAGE_KEYS } from '/@/utils/storage';
22
import { getUserInfo, login, loginByMobile, loginBySocial, refreshTokenApi, SocialLoginEnum } from '/@/api/login/index';
33
import { useMessage } from '/@/hooks/message';
4-
import Cookies from 'js-cookie';
54

65
/**
76
* @function useUserInfo
@@ -148,13 +147,13 @@ export const useUserInfo = defineStore('userInfo', {
148147
* @function updateDeptInfo
149148
* @param {string} deptId - 部门ID
150149
*/
151-
updateDeptInfo(deptId: String) {
150+
updateDeptInfo(deptId: string) {
152151
this.userInfos.deptId = deptId;
153152

154153
// 保存部门信息到本地
155154
Session.set(STORAGE_KEYS.DEPT_ID, deptId);
156155
Local.set(STORAGE_KEYS.DEPT_ID, deptId);
157-
Cookies.set(STORAGE_KEYS.DEPT_ID, deptId);
156+
Cookie.set(STORAGE_KEYS.DEPT_ID, deptId);
158157
},
159158
},
160159
});

src/utils/storage.ts

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ export const STORAGE_KEYS = {
1212

1313
const LOCAL_STORAGE_KEY_PREFIX = `${__NEXT_NAME__}${__VERSION__}:`;
1414

15+
/**
16+
* js-cookie 统一包装
17+
* @description 全局 Cookie 读写统一走此对象,业务代码不直接 import 'js-cookie',
18+
* 便于后续统一调整 Cookie 属性(path、expires、secure 等)
19+
*/
20+
export const Cookie = {
21+
// 写入 Cookie,options 透传 js-cookie 的属性配置
22+
set(key: string, val: string, options?: object) {
23+
Cookies.set(key, val, options);
24+
},
25+
// 读取 Cookie,不存在时返回 undefined
26+
get(key: string): string | undefined {
27+
return Cookies.get(key);
28+
},
29+
// 移除 Cookie
30+
remove(key: string) {
31+
Cookies.remove(key);
32+
},
33+
};
34+
1535
/**
1636
* 判断 key 是否需要同步写入 Cookie
1737
* @description token、refresh_token、deptId 在写入 sessionStorage 的同时也需要写入 Cookie,
@@ -22,6 +42,17 @@ function isCookieBackedSessionKey(key: string) {
2242
return key === STORAGE_KEYS.TOKEN || key === STORAGE_KEYS.REFRESH_TOKEN || key === STORAGE_KEYS.DEPT_ID;
2343
}
2444

45+
/**
46+
* 为存储键统一追加应用前缀,localStorage 与 sessionStorage 共用
47+
* @description 已带前缀的 key 原样返回,避免重复拼接
48+
*/
49+
function setStorageKey(key: string) {
50+
if (key.startsWith(LOCAL_STORAGE_KEY_PREFIX)) {
51+
return key;
52+
}
53+
return `${LOCAL_STORAGE_KEY_PREFIX}${key}`;
54+
}
55+
2556
/**
2657
* 安全读取并解析 sessionStorage 中的 JSON 值
2758
* @description Session.get 和 cookie-backed key 的兜底逻辑共用此函数,
@@ -49,7 +80,7 @@ function getSessionStorageValue(key: string) {
4980
export const Local = {
5081
// 查看 v2.4.3版本更新日志
5182
setKey(key: string) {
52-
return `${LOCAL_STORAGE_KEY_PREFIX}${key}`;
83+
return setStorageKey(key);
5384
},
5485
// 设置永久缓存
5586
set<T>(key: string, val: T) {
@@ -86,39 +117,43 @@ export const Local = {
86117
* @method clear 移除全部临时缓存
87118
*/
88119
export const Session = {
120+
// 与 Local 保持一致的键名前缀规则;Cookie 键保持原名,供网关和请求拦截器按原名读取
121+
setKey(key: string) {
122+
return setStorageKey(key);
123+
},
89124
// 设置临时缓存
90125
set(key: string, val: any) {
91126
if (val === undefined || val === null) {
92127
return;
93128
}
94129
if (isCookieBackedSessionKey(key)) {
95-
Cookies.set(key, val);
130+
Cookie.set(key, val);
96131
}
97-
window.sessionStorage.setItem(key, JSON.stringify(val));
132+
window.sessionStorage.setItem(Session.setKey(key), JSON.stringify(val));
98133
},
99134
// 获取临时缓存
100135
get(key: string) {
101-
if (isCookieBackedSessionKey(key)) return Cookies.get(key) || getSessionStorageValue(key);
102-
return getSessionStorageValue(key);
136+
if (isCookieBackedSessionKey(key)) return Cookie.get(key) || getSessionStorageValue(Session.setKey(key));
137+
return getSessionStorageValue(Session.setKey(key));
103138
},
104139
// 移除临时缓存
105140
remove(key: string) {
106-
if (isCookieBackedSessionKey(key)) Cookies.remove(key);
107-
window.sessionStorage.removeItem(key);
141+
if (isCookieBackedSessionKey(key)) Cookie.remove(key);
142+
window.sessionStorage.removeItem(Session.setKey(key));
108143
},
109144
// 移除全部临时缓存
110-
clear() {
111-
Cookies.remove(STORAGE_KEYS.TOKEN);
112-
Cookies.remove(STORAGE_KEYS.REFRESH_TOKEN);
113-
Cookies.remove(STORAGE_KEYS.DEPT_ID);
114-
window.sessionStorage.clear();
115-
},
145+
clear() {
146+
Cookie.remove(STORAGE_KEYS.TOKEN);
147+
Cookie.remove(STORAGE_KEYS.REFRESH_TOKEN);
148+
Cookie.remove(STORAGE_KEYS.DEPT_ID);
149+
window.sessionStorage.clear();
150+
},
116151
// 获取当前存储的 token
117152
getToken() {
118153
return this.get(STORAGE_KEYS.TOKEN);
119154
},
120-
// 获取当前的部门
121-
getDeptId() {
155+
// 获取当前的部门
156+
getDeptId() {
122157
return Local.get(STORAGE_KEYS.DEPT_ID) ? Local.get(STORAGE_KEYS.DEPT_ID) : '';
123158
},
124159
};

src/views/login/component/social.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
</template>
6969

7070
<script setup lang="ts" name="loginSocial">
71-
import Cookies from 'js-cookie';
71+
import { Cookie, STORAGE_KEYS } from '/@/utils/storage';
7272
import other from '/@/utils/other';
7373
import { getLoginAppList } from '/@/api/admin/social';
7474
import { useMessage } from '/@/hooks/message';
@@ -167,7 +167,7 @@ const { pause, resume } = useIntervalFn(
167167
// 检查弹出窗口是否已关闭
168168
if (winOpen.value && winOpen.value.closed) {
169169
cleanup();
170-
if (Cookies.get('token')) {
170+
if (Cookie.get(STORAGE_KEYS.TOKEN)) {
171171
emit('signInSuccess');
172172
}
173173
}

0 commit comments

Comments
 (0)