Skip to content

Commit 660720d

Browse files
committed
refactor!: 将 token 存储方式从 cookie 改为 localStorage 并移除 js-cookie 依赖
1 parent 88ea7f3 commit 660720d

File tree

13 files changed

+80
-285
lines changed

13 files changed

+80
-285
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"axios": "1.13.2",
2020
"dayjs": "1.11.19",
2121
"element-plus": "2.13.1",
22-
"js-cookie": "3.0.5",
2322
"lodash-es": "4.17.22",
2423
"mitt": "3.0.1",
2524
"normalize.css": "8.0.1",
@@ -34,7 +33,6 @@
3433
},
3534
"devDependencies": {
3635
"@antfu/eslint-config": "7.0.1",
37-
"@types/js-cookie": "3.0.6",
3836
"@types/lodash-es": "4.17.12",
3937
"@types/node": "25.0.9",
4038
"@types/nprogress": "0.2.3",

pnpm-lock.yaml

Lines changed: 57 additions & 258 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/composables/useTheme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getActiveThemeName, setActiveThemeName } from "@@/utils/cache/local-storage"
21
import { setCssVar } from "@@/utils/css"
2+
import { getActiveThemeName, setActiveThemeName } from "@@/utils/local-storage"
33

44
const DEFAULT_THEME_NAME = "normal"
55

src/common/utils/cache/cookies.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ import type { LayoutsConfig } from "@/layouts/config"
66
import type { TagView } from "@/pinia/stores/tags-view"
77
import { CacheKey } from "@@/constants/cache-key"
88

9+
// #region Token
10+
export function getToken() {
11+
return localStorage.getItem(CacheKey.TOKEN)
12+
}
13+
14+
export function setToken(token: string) {
15+
localStorage.setItem(CacheKey.TOKEN, token)
16+
}
17+
18+
export function removeToken() {
19+
localStorage.removeItem(CacheKey.TOKEN)
20+
}
21+
// #endregion
22+
923
// #region 系统布局配置
1024
export function getLayoutsConfig() {
1125
const json = localStorage.getItem(CacheKey.CONFIG_LAYOUT)

src/http/axios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { AxiosInstance, AxiosRequestConfig } from "axios"
2-
import { getToken } from "@@/utils/cache/cookies"
2+
import { getToken } from "@@/utils/local-storage"
33
import axios from "axios"
44
import { get, merge } from "lodash-es"
55
import { useUserStore } from "@/pinia/stores/user"

src/layouts/components/Settings/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts" setup>
22
import { useLayoutMode } from "@@/composables/useLayoutMode"
3-
import { removeLayoutsConfig } from "@@/utils/cache/local-storage"
3+
import { removeLayoutsConfig } from "@@/utils/local-storage"
44
import { Refresh } from "@element-plus/icons-vue"
55
import { useSettingsStore } from "@/pinia/stores/settings"
66
import SelectLayoutMode from "./SelectLayoutMode.vue"

src/layouts/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LayoutModeEnum } from "@@/constants/app-key"
2-
import { getLayoutsConfig } from "@@/utils/cache/local-storage"
2+
import { getLayoutsConfig } from "@@/utils/local-storage"
33

44
/** 项目配置类型 */
55
export interface LayoutsConfig {

src/pinia/stores/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DeviceEnum, SIDEBAR_CLOSED, SIDEBAR_OPENED } from "@@/constants/app-key"
2-
import { getSidebarStatus, setSidebarStatus } from "@@/utils/cache/local-storage"
2+
import { getSidebarStatus, setSidebarStatus } from "@@/utils/local-storage"
33
import { pinia } from "@/pinia"
44

55
interface Sidebar {

src/pinia/stores/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Ref } from "vue"
22
import type { LayoutsConfig } from "@/layouts/config"
3-
import { setLayoutsConfig } from "@@/utils/cache/local-storage"
3+
import { setLayoutsConfig } from "@@/utils/local-storage"
44
import { layoutsConfig } from "@/layouts/config"
55
import { pinia } from "@/pinia"
66

0 commit comments

Comments
 (0)