mirror of
https://github.com/un-pany/v3-admin-vite.git
synced 2025-04-21 03:19:19 +08:00
refactor: cache & constant
This commit is contained in:
parent
e2f4bb1533
commit
a6cf96f373
10
src/constant/cacheKeys.ts
Normal file
10
src/constant/cacheKeys.ts
Normal file
@ -0,0 +1,10 @@
|
||||
const SYSTEM_NAME = "v3-admin-vite"
|
||||
|
||||
/** 缓存数据时用到的 Keys */
|
||||
class CacheKeys {
|
||||
static TOKEN = `${SYSTEM_NAME}-token-key`
|
||||
static SIDEBAR_STATUS = `${SYSTEM_NAME}-sidebar-status-key`
|
||||
static ACTIVE_THEME_NAME = `${SYSTEM_NAME}-active-theme-name-key`
|
||||
}
|
||||
|
||||
export default CacheKeys
|
@ -1,7 +0,0 @@
|
||||
class Keys {
|
||||
static sidebarStatus = "v3-admin-vite-sidebar-status-key"
|
||||
static token = "v3-admin-vite-token-key"
|
||||
static activeThemeName = "v3-admin-vite-active-theme-name-key"
|
||||
}
|
||||
|
||||
export default Keys
|
@ -71,6 +71,22 @@ export const constantRoutes: Array<RouteRecordRaw> = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/table",
|
||||
component: Layout,
|
||||
redirect: "/table/index",
|
||||
children: [
|
||||
{
|
||||
path: "index",
|
||||
component: () => import("@/views/table/index.vue"),
|
||||
name: "Table",
|
||||
meta: {
|
||||
title: "表格",
|
||||
icon: "table"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/menu",
|
||||
component: Layout,
|
||||
|
@ -4,7 +4,7 @@ import { useUserStoreHook } from "@/store/modules/user"
|
||||
import { usePermissionStoreHook } from "@/store/modules/permission"
|
||||
import { ElMessage } from "element-plus"
|
||||
import { whiteList } from "@/config/white-list"
|
||||
import { getToken } from "@/utils/cookies"
|
||||
import { getToken } from "@/utils/cache/cookies"
|
||||
import asyncRouteSettings from "@/config/async-route"
|
||||
import NProgress from "nprogress"
|
||||
import "nprogress/nprogress.css"
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { defineStore } from "pinia"
|
||||
import { getSidebarStatus, getActiveThemeName, setSidebarStatus, setActiveThemeName } from "@/utils/cookies"
|
||||
import { getSidebarStatus, getActiveThemeName, setSidebarStatus, setActiveThemeName } from "@/utils/cache/localStorage"
|
||||
import themeList from "@/config/theme"
|
||||
|
||||
export enum DeviceType {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import store from "@/store"
|
||||
import { defineStore } from "pinia"
|
||||
import { usePermissionStore } from "./permission"
|
||||
import { getToken, removeToken, setToken } from "@/utils/cookies"
|
||||
import { getToken, removeToken, setToken } from "@/utils/cache/cookies"
|
||||
import router, { resetRouter } from "@/router"
|
||||
import { login, getUserInfo } from "@/api/login"
|
||||
import { RouteRecordRaw } from "vue-router"
|
||||
|
8
src/utils/cache/cookies.ts
vendored
Normal file
8
src/utils/cache/cookies.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/** 统一处理 Cookie */
|
||||
|
||||
import CacheKeys from "@/constant/cacheKeys"
|
||||
import Cookies from "js-cookie"
|
||||
|
||||
export const getToken = () => Cookies.get(CacheKeys.TOKEN)
|
||||
export const setToken = (token: string) => Cookies.set(CacheKeys.TOKEN, token)
|
||||
export const removeToken = () => Cookies.remove(CacheKeys.TOKEN)
|
9
src/utils/cache/localStorage.ts
vendored
Normal file
9
src/utils/cache/localStorage.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/** 统一处理 localStorage */
|
||||
|
||||
import CacheKeys from "@/constant/cacheKeys"
|
||||
|
||||
export const getSidebarStatus = () => localStorage.getItem(CacheKeys.SIDEBAR_STATUS)
|
||||
export const setSidebarStatus = (sidebarStatus: string) => localStorage.setItem(CacheKeys.SIDEBAR_STATUS, sidebarStatus)
|
||||
|
||||
export const getActiveThemeName = () => localStorage.getItem(CacheKeys.ACTIVE_THEME_NAME)
|
||||
export const setActiveThemeName = (themeName: string) => localStorage.setItem(CacheKeys.ACTIVE_THEME_NAME, themeName)
|
@ -1,16 +0,0 @@
|
||||
/** 统一处理 Cookie */
|
||||
|
||||
import Keys from "@/constant/key"
|
||||
import Cookies from "js-cookie"
|
||||
|
||||
export const getSidebarStatus = () => Cookies.get(Keys.sidebarStatus)
|
||||
export const setSidebarStatus = (sidebarStatus: string) => Cookies.set(Keys.sidebarStatus, sidebarStatus)
|
||||
|
||||
export const getToken = () => Cookies.get(Keys.token)
|
||||
export const setToken = (token: string) => Cookies.set(Keys.token, token)
|
||||
export const removeToken = () => Cookies.remove(Keys.token)
|
||||
|
||||
export const getActiveThemeName = () => Cookies.get(Keys.activeThemeName)
|
||||
export const setActiveThemeName = (themeName: string) => {
|
||||
Cookies.set(Keys.activeThemeName, themeName)
|
||||
}
|
@ -2,7 +2,7 @@ import axios, { AxiosInstance, AxiosRequestConfig } from "axios"
|
||||
import { useUserStoreHook } from "@/store/modules/user"
|
||||
import { ElMessage } from "element-plus"
|
||||
import { get } from "lodash-es"
|
||||
import { getToken } from "@/utils/cookies"
|
||||
import { getToken } from "@/utils/cache/cookies"
|
||||
|
||||
/** 创建请求实例 */
|
||||
function createService() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user