perf: delete settings.ts use serverConfig.json

This commit is contained in:
xiaoxian521 2021-10-15 11:38:43 +08:00
parent cafc588e4c
commit e22e19552a
9 changed files with 46 additions and 35 deletions

View File

@ -43,5 +43,7 @@
"cSpell.userWords": ["sourcemap", "vite"], "cSpell.userWords": ["sourcemap", "vite"],
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll.eslint": true "source.fixAll.eslint": true
} },
"volar.tsPlugin": true,
"typescript.tsdk": "node_modules/typescript/lib"
} }

View File

@ -1,5 +1,8 @@
{ {
"Version": "2.0.0", "Version": "2.0.0",
"Title": "PureAdmin",
"FixedHeader": false,
"HiddenSideBar": false,
"KeepAlive": true, "KeepAlive": true,
"Locale": "zh", "Locale": "zh",
"Layout": "vertical-dark", "Layout": "vertical-dark",

View File

@ -6,7 +6,7 @@ const setConfig = (cfg?: unknown) => {
config = Object.assign(config, cfg); config = Object.assign(config, cfg);
}; };
const getConfig = (key?: string) => { const getConfig = (key?: string): ServerConfigs => {
if (typeof key === "string") { if (typeof key === "string") {
const arr = key.split("."); const arr = key.split(".");
if (arr && arr.length) { if (arr && arr.length) {

View File

@ -8,7 +8,6 @@ import {
getCurrentInstance getCurrentInstance
} from "vue"; } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import settings from "/@/settings";
import { emitter } from "/@/utils/mitt"; import { emitter } from "/@/utils/mitt";
import { templateRef } from "@vueuse/core"; import { templateRef } from "@vueuse/core";
import SidebarItem from "./sidebarItem.vue"; import SidebarItem from "./sidebarItem.vue";
@ -22,6 +21,10 @@ import { usePermissionStoreHook } from "/@/store/modules/permission";
const instance = const instance =
getCurrentInstance().appContext.config.globalProperties.$storage; getCurrentInstance().appContext.config.globalProperties.$storage;
const title =
getCurrentInstance().appContext.config.globalProperties.$config?.Title;
const menuRef = templateRef<ElRef | null>("menu", null); const menuRef = templateRef<ElRef | null>("menu", null);
const routeStore = usePermissionStoreHook(); const routeStore = usePermissionStoreHook();
const route = useRoute(); const route = useRoute();
@ -114,7 +117,7 @@ onMounted(() => {
<div class="horizontal-header"> <div class="horizontal-header">
<div class="horizontal-header-left" @click="backHome"> <div class="horizontal-header-left" @click="backHome">
<i class="fa fa-optin-monster"></i> <i class="fa fa-optin-monster"></i>
<h4>{{ settings.title }}</h4> <h4>{{ title }}</h4>
</div> </div>
<el-menu <el-menu
ref="menu" ref="menu"

View File

@ -1,9 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import settings from "/@/settings"; import { getCurrentInstance } from "vue";
const props = defineProps({ const props = defineProps({
collapse: Boolean collapse: Boolean
}); });
const title =
getCurrentInstance().appContext.config.globalProperties.$config?.Title;
</script> </script>
<template> <template>
@ -12,22 +14,22 @@ const props = defineProps({
<router-link <router-link
v-if="props.collapse" v-if="props.collapse"
key="props.collapse" key="props.collapse"
:title="settings.title" :title="title"
class="sidebar-logo-link" class="sidebar-logo-link"
to="/" to="/"
> >
<i class="fa fa-optin-monster"></i> <i class="fa fa-optin-monster"></i>
<h1 class="sidebar-title">{{ settings.title }}</h1> <h1 class="sidebar-title">{{ title }}</h1>
</router-link> </router-link>
<router-link <router-link
v-else v-else
key="expand" key="expand"
:title="settings.title" :title="title"
class="sidebar-logo-link" class="sidebar-logo-link"
to="/" to="/"
> >
<i class="fa fa-optin-monster"></i> <i class="fa fa-optin-monster"></i>
<h1 class="sidebar-title">{{ settings.title }}</h1> <h1 class="sidebar-title">{{ title }}</h1>
</router-link> </router-link>
</transition> </transition>
</div> </div>

View File

@ -38,7 +38,6 @@ import {
getCurrentInstance getCurrentInstance
} from "vue"; } from "vue";
import { setType } from "./types"; import { setType } from "./types";
import options from "/@/settings";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { emitter } from "/@/utils/mitt"; import { emitter } from "/@/utils/mitt";
import { toggleClass } from "/@/utils/operate"; import { toggleClass } from "/@/utils/operate";
@ -62,7 +61,9 @@ const { hiddenMainContainer } = useCssModule();
const instance = const instance =
getCurrentInstance().appContext.app.config.globalProperties.$storage; getCurrentInstance().appContext.app.config.globalProperties.$storage;
let containerHiddenSideBar = ref(options.hiddenSideBar); const hiddenSideBar = ref(
getCurrentInstance().appContext.config.globalProperties.$config?.HiddenSideBar
);
const set: setType = reactive({ const set: setType = reactive({
sidebar: computed(() => { sidebar: computed(() => {
@ -127,15 +128,15 @@ const $_resizeHandler = () => {
}; };
function onFullScreen() { function onFullScreen() {
if (unref(containerHiddenSideBar)) { if (unref(hiddenSideBar)) {
containerHiddenSideBar.value = false; hiddenSideBar.value = false;
toggleClass( toggleClass(
false, false,
hiddenMainContainer, hiddenMainContainer,
document.querySelector(".main-container") document.querySelector(".main-container")
); );
} else { } else {
containerHiddenSideBar.value = true; hiddenSideBar.value = true;
toggleClass( toggleClass(
true, true,
hiddenMainContainer, hiddenMainContainer,
@ -151,7 +152,7 @@ onMounted(() => {
handleClickOutside(true); handleClickOutside(true);
} }
toggleClass( toggleClass(
unref(containerHiddenSideBar), unref(hiddenSideBar),
hiddenMainContainer, hiddenMainContainer,
document.querySelector(".main-container") document.querySelector(".main-container")
); );
@ -173,20 +174,16 @@ onBeforeMount(() => {
class="drawer-bg" class="drawer-bg"
@click="handleClickOutside(false)" @click="handleClickOutside(false)"
/> />
<Vertical v-show="!containerHiddenSideBar && layout.includes('vertical')" /> <Vertical v-show="!hiddenSideBar && layout.includes('vertical')" />
<div class="main-container"> <div class="main-container">
<div :class="{ 'fixed-header': set.fixedHeader }"> <div :class="{ 'fixed-header': set.fixedHeader }">
<!-- 顶部导航栏 --> <!-- 顶部导航栏 -->
<navbar <navbar v-show="!hiddenSideBar && layout.includes('vertical')" />
v-show="!containerHiddenSideBar && layout.includes('vertical')"
/>
<!-- tabs标签页 --> <!-- tabs标签页 -->
<Horizontal <Horizontal v-show="!hiddenSideBar && layout.includes('horizontal')" />
v-show="!containerHiddenSideBar && layout.includes('horizontal')"
/>
<tag> <tag>
<span @click="onFullScreen"> <span @click="onFullScreen">
<fullScreen v-if="!containerHiddenSideBar" /> <fullScreen v-if="!hiddenSideBar" />
<exitScreen v-else /> <exitScreen v-else />
</span> </span>
</tag> </tag>

View File

@ -1,7 +0,0 @@
export default {
title: "PureAdmin",
fixedHeader: false,
hiddenSideBar: false
};

View File

@ -1,6 +1,6 @@
import defaultSettings from "../../settings";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { store } from "/@/store"; import { store } from "/@/store";
import { getConfig } from "/@/config";
interface SettingState { interface SettingState {
title: string; title: string;
@ -10,8 +10,8 @@ interface SettingState {
export const useSettingStore = defineStore({ export const useSettingStore = defineStore({
id: "pure-setting", id: "pure-setting",
state: (): SettingState => ({ state: (): SettingState => ({
title: defaultSettings.title, title: getConfig().Title,
fixedHeader: defaultSettings.fixedHeader fixedHeader: getConfig().FixedHeader
}), }),
getters: { getters: {
getTitle() { getTitle() {

13
types/global.d.ts vendored
View File

@ -84,10 +84,21 @@ declare global {
declare interface ServerConfigs { declare interface ServerConfigs {
Version?: string; Version?: string;
Title?: string;
FixedHeader?: boolean;
HiddenSideBar?: boolean;
KeepAlive?: boolean; KeepAlive?: boolean;
Locale?: string; Locale?: string;
Layout?: string; Layout?: string;
MapConfigure?: any; MapConfigure?: {
amapKey?: string;
baiduKey?: string;
options: {
resizeEnable?: boolean;
center?: number[];
zoom?: number;
};
};
} }
function parseInt(s: string | number, radix?: number): number; function parseInt(s: string | number, radix?: number): number;