mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-07 17:07:19 +08:00
perf: 增加全局配置本地加载的控制
This commit is contained in:
parent
13e7a13e9d
commit
36143438f6
@ -38,6 +38,7 @@ const pathResolve = (dir = ".", metaUrl = import.meta.url) => {
|
|||||||
/** 设置别名 */
|
/** 设置别名 */
|
||||||
const alias: Record<string, string> = {
|
const alias: Record<string, string> = {
|
||||||
"@": pathResolve("../src"),
|
"@": pathResolve("../src"),
|
||||||
|
"@public": pathResolve("../public"),
|
||||||
"@build": pathResolve()
|
"@build": pathResolve()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import type { App } from "vue";
|
import type { App } from "vue";
|
||||||
|
import platformConfig from "@public/platform-config.json";
|
||||||
|
|
||||||
let config: object = {};
|
let config: object = {};
|
||||||
const { VITE_PUBLIC_PATH } = import.meta.env;
|
const { VITE_PUBLIC_PATH } = import.meta.env;
|
||||||
@ -27,13 +28,12 @@ const getConfig = (key?: string): PlatformConfigs => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** 获取项目动态全局配置 */
|
/** 获取项目动态全局配置 */
|
||||||
export const getPlatformConfig = async (app: App): Promise<undefined> => {
|
export const getPlatformConfig = async (
|
||||||
|
app: App,
|
||||||
|
local = false
|
||||||
|
): Promise<undefined> => {
|
||||||
app.config.globalProperties.$config = getConfig();
|
app.config.globalProperties.$config = getConfig();
|
||||||
return axios({
|
const fn = ({ data: config }) => {
|
||||||
method: "get",
|
|
||||||
url: `${VITE_PUBLIC_PATH}platform-config.json`
|
|
||||||
})
|
|
||||||
.then(({ data: config }) => {
|
|
||||||
let $config = app.config.globalProperties.$config;
|
let $config = app.config.globalProperties.$config;
|
||||||
// 自动注入系统配置
|
// 自动注入系统配置
|
||||||
if (app && $config && typeof config === "object") {
|
if (app && $config && typeof config === "object") {
|
||||||
@ -43,10 +43,19 @@ export const getPlatformConfig = async (app: App): Promise<undefined> => {
|
|||||||
setConfig($config);
|
setConfig($config);
|
||||||
}
|
}
|
||||||
return $config;
|
return $config;
|
||||||
|
};
|
||||||
|
if (local) {
|
||||||
|
return Promise.resolve({ data: platformConfig }).then(fn);
|
||||||
|
} else {
|
||||||
|
return axios({
|
||||||
|
method: "get",
|
||||||
|
url: `${VITE_PUBLIC_PATH}platform-config.json`
|
||||||
})
|
})
|
||||||
|
.then(fn)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
throw "请在public文件夹下添加platform-config.json配置文件";
|
throw "请在public文件夹下添加platform-config.json配置文件";
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 本地响应式存储的命名空间 */
|
/** 本地响应式存储的命名空间 */
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
"@/*": [
|
"@/*": [
|
||||||
"src/*"
|
"src/*"
|
||||||
],
|
],
|
||||||
|
"@public/*": [
|
||||||
|
"public/*"
|
||||||
|
],
|
||||||
"@build/*": [
|
"@build/*": [
|
||||||
"build/*"
|
"build/*"
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user