mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-06 00:18:51 +08:00
feat: 将本地响应式存储的命名空间提升到全局配置中
This commit is contained in:
parent
dc0ad8523c
commit
2024c4e5fe
@ -19,6 +19,7 @@
|
|||||||
"MenuArrowIconNoTransition": true,
|
"MenuArrowIconNoTransition": true,
|
||||||
"CachingAsyncRoutes": false,
|
"CachingAsyncRoutes": false,
|
||||||
"TooltipEffect": "light",
|
"TooltipEffect": "light",
|
||||||
|
"ResponsiveStorageNameSpace": "responsive-",
|
||||||
"MapConfigure": {
|
"MapConfigure": {
|
||||||
"amapKey": "97b3248d1553172e81f168cf94ea667e",
|
"amapKey": "97b3248d1553172e81f168cf94ea667e",
|
||||||
"options": {
|
"options": {
|
||||||
|
@ -49,4 +49,7 @@ export const getServerConfig = async (app: App): Promise<undefined> => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export { getConfig, setConfig };
|
/** 本地响应式存储的命名空间 */
|
||||||
|
const responsiveStorageNameSpace = () => getConfig().ResponsiveStorageNameSpace;
|
||||||
|
|
||||||
|
export { getConfig, setConfig, responsiveStorageNameSpace };
|
||||||
|
@ -6,14 +6,16 @@ import SidebarItem from "./sidebarItem.vue";
|
|||||||
import leftCollapse from "./leftCollapse.vue";
|
import leftCollapse from "./leftCollapse.vue";
|
||||||
import { useNav } from "@/layout/hooks/useNav";
|
import { useNav } from "@/layout/hooks/useNav";
|
||||||
import { storageLocal } from "@pureadmin/utils";
|
import { storageLocal } from "@pureadmin/utils";
|
||||||
|
import { responsiveStorageNameSpace } from "@/config";
|
||||||
import { ref, computed, watch, onBeforeMount } from "vue";
|
import { ref, computed, watch, onBeforeMount } from "vue";
|
||||||
import { findRouteByPath, getParentPaths } from "@/router/utils";
|
import { findRouteByPath, getParentPaths } from "@/router/utils";
|
||||||
import { usePermissionStoreHook } from "@/store/modules/permission";
|
import { usePermissionStoreHook } from "@/store/modules/permission";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const showLogo = ref(
|
const showLogo = ref(
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-configure")?.showLogo ??
|
storageLocal().getItem<StorageConfigs>(
|
||||||
true
|
`${responsiveStorageNameSpace()}configure`
|
||||||
|
)?.showLogo ?? true
|
||||||
);
|
);
|
||||||
|
|
||||||
const { routers, device, pureApp, isCollapse, menuSelect, toggleSideBar } =
|
const { routers, device, pureApp, isCollapse, menuSelect, toggleSideBar } =
|
||||||
|
@ -12,6 +12,7 @@ import { tagsViewsType } from "../types";
|
|||||||
import { useEventListener } from "@vueuse/core";
|
import { useEventListener } from "@vueuse/core";
|
||||||
import { useRoute, useRouter } from "vue-router";
|
import { useRoute, useRouter } from "vue-router";
|
||||||
import { transformI18n, $t } from "@/plugins/i18n";
|
import { transformI18n, $t } from "@/plugins/i18n";
|
||||||
|
import { responsiveStorageNameSpace } from "@/config";
|
||||||
import { useSettingStoreHook } from "@/store/modules/settings";
|
import { useSettingStoreHook } from "@/store/modules/settings";
|
||||||
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
|
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
|
||||||
import {
|
import {
|
||||||
@ -46,13 +47,16 @@ export function useTags() {
|
|||||||
|
|
||||||
/** 显示模式,默认灵动模式 */
|
/** 显示模式,默认灵动模式 */
|
||||||
const showModel = ref(
|
const showModel = ref(
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-configure")?.showModel ||
|
storageLocal().getItem<StorageConfigs>(
|
||||||
"smart"
|
`${responsiveStorageNameSpace()}configure`
|
||||||
|
)?.showModel || "smart"
|
||||||
);
|
);
|
||||||
/** 是否隐藏标签页,默认显示 */
|
/** 是否隐藏标签页,默认显示 */
|
||||||
const showTags =
|
const showTags =
|
||||||
ref(
|
ref(
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-configure").hideTabs
|
storageLocal().getItem<StorageConfigs>(
|
||||||
|
`${responsiveStorageNameSpace()}configure`
|
||||||
|
).hideTabs
|
||||||
) ?? ref("false");
|
) ?? ref("false");
|
||||||
const multiTags: any = computed(() => {
|
const multiTags: any = computed(() => {
|
||||||
return useMultiTagsStoreHook().multiTags;
|
return useMultiTagsStoreHook().multiTags;
|
||||||
@ -201,10 +205,13 @@ export function useTags() {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (!showModel.value) {
|
if (!showModel.value) {
|
||||||
const configure = storageLocal().getItem<StorageConfigs>(
|
const configure = storageLocal().getItem<StorageConfigs>(
|
||||||
"responsive-configure"
|
`${responsiveStorageNameSpace()}configure`
|
||||||
);
|
);
|
||||||
configure.showModel = "card";
|
configure.showModel = "card";
|
||||||
storageLocal().setItem("responsive-configure", configure);
|
storageLocal().setItem(
|
||||||
|
`${responsiveStorageNameSpace()}configure`,
|
||||||
|
configure
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import { App, WritableComputedRef } from "vue";
|
import { App, WritableComputedRef } from "vue";
|
||||||
import { storageLocal } from "@pureadmin/utils";
|
import { storageLocal } from "@pureadmin/utils";
|
||||||
import { type I18n, createI18n } from "vue-i18n";
|
import { type I18n, createI18n } from "vue-i18n";
|
||||||
|
import { responsiveStorageNameSpace } from "@/config";
|
||||||
|
|
||||||
// element-plus国际化
|
// element-plus国际化
|
||||||
import enLocale from "element-plus/lib/locale/lang/en";
|
import enLocale from "element-plus/lib/locale/lang/en";
|
||||||
@ -63,7 +64,9 @@ export const $t = (key: string) => key;
|
|||||||
export const i18n: I18n = createI18n({
|
export const i18n: I18n = createI18n({
|
||||||
legacy: false,
|
legacy: false,
|
||||||
locale:
|
locale:
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-locale")?.locale ?? "zh",
|
storageLocal().getItem<StorageConfigs>(
|
||||||
|
`${responsiveStorageNameSpace()}locale`
|
||||||
|
)?.locale ?? "zh",
|
||||||
fallbackLocale: "en",
|
fallbackLocale: "en",
|
||||||
messages: localesConfigs
|
messages: localesConfigs
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { store } from "@/store";
|
import { store } from "@/store";
|
||||||
import { appType } from "./types";
|
import { appType } from "./types";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { getConfig } from "@/config";
|
import { getConfig, responsiveStorageNameSpace } from "@/config";
|
||||||
import { deviceDetection, storageLocal } from "@pureadmin/utils";
|
import { deviceDetection, storageLocal } from "@pureadmin/utils";
|
||||||
|
|
||||||
export const useAppStore = defineStore({
|
export const useAppStore = defineStore({
|
||||||
@ -9,15 +9,17 @@ export const useAppStore = defineStore({
|
|||||||
state: (): appType => ({
|
state: (): appType => ({
|
||||||
sidebar: {
|
sidebar: {
|
||||||
opened:
|
opened:
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-layout")
|
storageLocal().getItem<StorageConfigs>(
|
||||||
?.sidebarStatus ?? getConfig().SidebarStatus,
|
`${responsiveStorageNameSpace()}layout`
|
||||||
|
)?.sidebarStatus ?? getConfig().SidebarStatus,
|
||||||
withoutAnimation: false,
|
withoutAnimation: false,
|
||||||
isClickCollapse: false
|
isClickCollapse: false
|
||||||
},
|
},
|
||||||
// 这里的layout用于监听容器拖拉后恢复对应的导航模式
|
// 这里的layout用于监听容器拖拉后恢复对应的导航模式
|
||||||
layout:
|
layout:
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-layout")?.layout ??
|
storageLocal().getItem<StorageConfigs>(
|
||||||
getConfig().Layout,
|
`${responsiveStorageNameSpace()}layout`
|
||||||
|
)?.layout ?? getConfig().Layout,
|
||||||
device: deviceDetection() ? "mobile" : "desktop",
|
device: deviceDetection() ? "mobile" : "desktop",
|
||||||
// 作用于 src/views/components/draggable/index.vue 页面,当离开页面并不会销毁 new Swap(),sortablejs 官网也没有提供任何销毁的 api
|
// 作用于 src/views/components/draggable/index.vue 页面,当离开页面并不会销毁 new Swap(),sortablejs 官网也没有提供任何销毁的 api
|
||||||
sortSwap: false
|
sortSwap: false
|
||||||
@ -32,8 +34,9 @@ export const useAppStore = defineStore({
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
TOGGLE_SIDEBAR(opened?: boolean, resize?: string) {
|
TOGGLE_SIDEBAR(opened?: boolean, resize?: string) {
|
||||||
const layout =
|
const layout = storageLocal().getItem<StorageConfigs>(
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-layout");
|
`${responsiveStorageNameSpace()}layout`
|
||||||
|
);
|
||||||
if (opened && resize) {
|
if (opened && resize) {
|
||||||
this.sidebar.withoutAnimation = true;
|
this.sidebar.withoutAnimation = true;
|
||||||
this.sidebar.opened = true;
|
this.sidebar.opened = true;
|
||||||
@ -48,7 +51,7 @@ export const useAppStore = defineStore({
|
|||||||
this.sidebar.isClickCollapse = !this.sidebar.opened;
|
this.sidebar.isClickCollapse = !this.sidebar.opened;
|
||||||
layout.sidebarStatus = this.sidebar.opened;
|
layout.sidebarStatus = this.sidebar.opened;
|
||||||
}
|
}
|
||||||
storageLocal().setItem("responsive-layout", layout);
|
storageLocal().setItem(`${responsiveStorageNameSpace()}layout`, layout);
|
||||||
},
|
},
|
||||||
async toggleSideBar(opened?: boolean, resize?: string) {
|
async toggleSideBar(opened?: boolean, resize?: string) {
|
||||||
await this.TOGGLE_SIDEBAR(opened, resize);
|
await this.TOGGLE_SIDEBAR(opened, resize);
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
import { store } from "@/store";
|
import { store } from "@/store";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { getConfig } from "@/config";
|
|
||||||
import { storageLocal } from "@pureadmin/utils";
|
import { storageLocal } from "@pureadmin/utils";
|
||||||
|
import { getConfig, responsiveStorageNameSpace } from "@/config";
|
||||||
|
|
||||||
export const useEpThemeStore = defineStore({
|
export const useEpThemeStore = defineStore({
|
||||||
id: "pure-epTheme",
|
id: "pure-epTheme",
|
||||||
state: () => ({
|
state: () => ({
|
||||||
epThemeColor:
|
epThemeColor:
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-layout")
|
storageLocal().getItem<StorageConfigs>(
|
||||||
?.epThemeColor ?? getConfig().EpThemeColor,
|
`${responsiveStorageNameSpace()}layout`
|
||||||
|
)?.epThemeColor ?? getConfig().EpThemeColor,
|
||||||
epTheme:
|
epTheme:
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-layout")?.theme ??
|
storageLocal().getItem<StorageConfigs>(
|
||||||
getConfig().Theme
|
`${responsiveStorageNameSpace()}layout`
|
||||||
|
)?.theme ?? getConfig().Theme
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
getEpThemeColor(state) {
|
getEpThemeColor(state) {
|
||||||
@ -30,13 +32,14 @@ export const useEpThemeStore = defineStore({
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
setEpThemeColor(newColor: string): void {
|
setEpThemeColor(newColor: string): void {
|
||||||
const layout =
|
const layout = storageLocal().getItem<StorageConfigs>(
|
||||||
storageLocal().getItem<StorageConfigs>("responsive-layout");
|
`${responsiveStorageNameSpace()}layout`
|
||||||
|
);
|
||||||
this.epTheme = layout?.theme;
|
this.epTheme = layout?.theme;
|
||||||
this.epThemeColor = newColor;
|
this.epThemeColor = newColor;
|
||||||
if (!layout) return;
|
if (!layout) return;
|
||||||
layout.epThemeColor = newColor;
|
layout.epThemeColor = newColor;
|
||||||
storageLocal().setItem("responsive-layout", layout);
|
storageLocal().setItem(`${responsiveStorageNameSpace()}layout`, layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,18 +2,22 @@ import { defineStore } from "pinia";
|
|||||||
import { store } from "@/store";
|
import { store } from "@/store";
|
||||||
import { routerArrays } from "@/layout/types";
|
import { routerArrays } from "@/layout/types";
|
||||||
import { multiType, positionType } from "./types";
|
import { multiType, positionType } from "./types";
|
||||||
|
import { responsiveStorageNameSpace } from "@/config";
|
||||||
import { isEqual, isBoolean, isUrl, storageLocal } from "@pureadmin/utils";
|
import { isEqual, isBoolean, isUrl, storageLocal } from "@pureadmin/utils";
|
||||||
|
|
||||||
export const useMultiTagsStore = defineStore({
|
export const useMultiTagsStore = defineStore({
|
||||||
id: "pure-multiTags",
|
id: "pure-multiTags",
|
||||||
state: () => ({
|
state: () => ({
|
||||||
// 存储标签页信息(路由信息)
|
// 存储标签页信息(路由信息)
|
||||||
multiTags: storageLocal().getItem<StorageConfigs>("responsive-configure")
|
multiTags: storageLocal().getItem<StorageConfigs>(
|
||||||
?.multiTagsCache
|
`${responsiveStorageNameSpace()}configure`
|
||||||
? storageLocal().getItem<StorageConfigs>("responsive-tags")
|
)?.multiTagsCache
|
||||||
|
? storageLocal().getItem<StorageConfigs>(
|
||||||
|
`${responsiveStorageNameSpace()}tags`
|
||||||
|
)
|
||||||
: [...routerArrays],
|
: [...routerArrays],
|
||||||
multiTagsCache: storageLocal().getItem<StorageConfigs>(
|
multiTagsCache: storageLocal().getItem<StorageConfigs>(
|
||||||
"responsive-configure"
|
`${responsiveStorageNameSpace()}configure`
|
||||||
)?.multiTagsCache
|
)?.multiTagsCache
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
@ -25,14 +29,20 @@ export const useMultiTagsStore = defineStore({
|
|||||||
multiTagsCacheChange(multiTagsCache: boolean) {
|
multiTagsCacheChange(multiTagsCache: boolean) {
|
||||||
this.multiTagsCache = multiTagsCache;
|
this.multiTagsCache = multiTagsCache;
|
||||||
if (multiTagsCache) {
|
if (multiTagsCache) {
|
||||||
storageLocal().setItem("responsive-tags", this.multiTags);
|
storageLocal().setItem(
|
||||||
|
`${responsiveStorageNameSpace()}tags`,
|
||||||
|
this.multiTags
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
storageLocal().removeItem("responsive-tags");
|
storageLocal().removeItem(`${responsiveStorageNameSpace()}tags`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tagsCache(multiTags) {
|
tagsCache(multiTags) {
|
||||||
this.getMultiTagsCache &&
|
this.getMultiTagsCache &&
|
||||||
storageLocal().setItem("responsive-tags", multiTags);
|
storageLocal().setItem(
|
||||||
|
`${responsiveStorageNameSpace()}tags`,
|
||||||
|
multiTags
|
||||||
|
);
|
||||||
},
|
},
|
||||||
handleTags<T>(
|
handleTags<T>(
|
||||||
mode: string,
|
mode: string,
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
import { App } from "vue";
|
import { App } from "vue";
|
||||||
import Storage from "responsive-storage";
|
import Storage from "responsive-storage";
|
||||||
import { routerArrays } from "@/layout/types";
|
import { routerArrays } from "@/layout/types";
|
||||||
|
import { responsiveStorageNameSpace } from "@/config";
|
||||||
const nameSpace = "responsive-";
|
|
||||||
|
|
||||||
export const injectResponsiveStorage = (app: App, config: ServerConfigs) => {
|
export const injectResponsiveStorage = (app: App, config: ServerConfigs) => {
|
||||||
|
const nameSpace = responsiveStorageNameSpace();
|
||||||
const configObj = Object.assign(
|
const configObj = Object.assign(
|
||||||
{
|
{
|
||||||
// 国际化 默认中文zh
|
// 国际化 默认中文zh
|
||||||
|
1
types/global.d.ts
vendored
1
types/global.d.ts
vendored
@ -97,6 +97,7 @@ declare global {
|
|||||||
MenuArrowIconNoTransition?: boolean;
|
MenuArrowIconNoTransition?: boolean;
|
||||||
CachingAsyncRoutes?: boolean;
|
CachingAsyncRoutes?: boolean;
|
||||||
TooltipEffect?: Effect;
|
TooltipEffect?: Effect;
|
||||||
|
ResponsiveStorageNameSpace?: string;
|
||||||
MapConfigure?: {
|
MapConfigure?: {
|
||||||
amapKey?: string;
|
amapKey?: string;
|
||||||
options: {
|
options: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user