diff --git a/public/serverConfig.json b/public/serverConfig.json index e1e30f1e37..c2d672a76e 100644 --- a/public/serverConfig.json +++ b/public/serverConfig.json @@ -1,16 +1,15 @@ { - "version": "1.0.0", - "keepAlive": true, + "Version": "2.0.0", + "KeepAlive": true, + "Locale": "zh", + "Layout": "vertical-dark", "MapConfigure": { "amapKey": "97b3248d1553172e81f168cf94ea667e", "baiduKey": "wTHbkkEweiFqZLKunMIjcrb2RcqNXkhc", "options": { "resizeEnable": true, - "center": [ - 113.6401, - 34.72468 - ], + "center": [113.6401, 34.72468], "zoom": 12 } } -} \ No newline at end of file +} diff --git a/src/layout/components/appMain.vue b/src/layout/components/appMain.vue index 5685aee9fd..9e506c792e 100644 --- a/src/layout/components/appMain.vue +++ b/src/layout/components/appMain.vue @@ -3,7 +3,7 @@ import { ref, unref, computed, getCurrentInstance } from "vue"; import { useSettingStoreHook } from "/@/store/modules/settings"; const keepAlive: Boolean = ref( - getCurrentInstance().appContext.config.globalProperties.$config?.keepAlive + getCurrentInstance().appContext.config.globalProperties.$config?.KeepAlive ); const getCachedPageList = computed((): string[] => { diff --git a/src/main.ts b/src/main.ts index fc9de9f952..e90af529fc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import { createApp, Directive } from "vue"; import { usI18n } from "../src/plugins/i18n"; import { useTable } from "../src/plugins/vxe-table"; import { useElementPlus } from "../src/plugins/element-plus"; +import { injectResponsiveStorage } from "/@/utils/storage/responsive"; import "animate.css"; // 导入公共样式 @@ -17,49 +18,14 @@ import "v-contextmenu/dist/themes/default.css"; const app = createApp(App); -// 响应式storage -import Storage from "responsive-storage"; -// @ts-ignore -app.use(Storage, { - // 默认显示首页tag - routesInStorage: { - type: Array, - default: Storage.getData(undefined, "routesInStorage") ?? [ - { - path: "/welcome", - parentPath: "/", - meta: { - title: "message.hshome", - icon: "el-icon-s-home", - showLink: true, - savedPosition: false - } - } - ] - }, - // 国际化 默认中文zh - locale: { - type: Object, - default: Storage.getData(undefined, "locale") ?? { - locale: "zh" - } - }, - // layout模式以及主题 - layout: { - type: Object, - default: Storage.getData(undefined, "layout") ?? { - layout: "vertical-dark" - } - } -}); - // 自定义指令 import * as directives from "/@/directives"; Object.keys(directives).forEach(key => { app.directive(key, (directives as { [key: string]: Directive })[key]); }); -getServerConfig(app).then(async () => { +getServerConfig(app).then(async config => { + injectResponsiveStorage(app, config); setupStore(app); app.use(router).use(useElementPlus).use(useTable).use(usI18n); await router.isReady(); diff --git a/src/utils/storage/responsive.ts b/src/utils/storage/responsive.ts new file mode 100644 index 0000000000..d3682341e8 --- /dev/null +++ b/src/utils/storage/responsive.ts @@ -0,0 +1,38 @@ +// 响应式storage +import { App } from "vue"; +import Storage from "responsive-storage"; + +export const injectResponsiveStorage = (app: App, config: ServerConfigs) => { + app.use(Storage, { + // 默认显示首页tag + routesInStorage: { + type: Array, + default: Storage.getData(undefined, "routesInStorage") ?? [ + { + path: "/welcome", + parentPath: "/", + meta: { + title: "message.hshome", + icon: "el-icon-s-home", + showLink: true, + savedPosition: false + } + } + ] + }, + // 国际化 默认中文zh + locale: { + type: Object, + default: Storage.getData(undefined, "locale") ?? { + locale: config.Locale + } + }, + // layout模式以及主题 + layout: { + type: Object, + default: Storage.getData(undefined, "layout") ?? { + layout: config.Layout + } + } + }); +}; diff --git a/types/global.d.ts b/types/global.d.ts index 95e997cd72..a357c59fe7 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -82,6 +82,14 @@ declare global { VITE_GENERATE_UI: string; } + declare interface ServerConfigs { + Version?: string; + KeepAlive?: boolean; + Locale?: string; + Layout?: string; + MapConfigure?: any; + } + function parseInt(s: string | number, radix?: number): number; function parseFloat(string: string | number): number;