Skip to content

Commit

Permalink
feat: 抽离默认配置选项
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Oct 8, 2021
1 parent 13749c7 commit fc5cec5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 45 deletions.
13 changes: 6 additions & 7 deletions public/serverConfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
2 changes: 1 addition & 1 deletion src/layout/components/appMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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[] => {
Expand Down
40 changes: 3 additions & 37 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
// 导入公共样式
Expand All @@ -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();
Expand Down
38 changes: 38 additions & 0 deletions src/utils/storage/responsive.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
});
};
8 changes: 8 additions & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fc5cec5

Please sign in to comment.