mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-06 16:37:18 +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> = {
|
||||
"@": pathResolve("../src"),
|
||||
"@public": pathResolve("../public"),
|
||||
"@build": pathResolve()
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import axios from "axios";
|
||||
import type { App } from "vue";
|
||||
import platformConfig from "@public/platform-config.json";
|
||||
|
||||
let config: object = {};
|
||||
const { VITE_PUBLIC_PATH } = import.meta.env;
|
||||
@ -27,26 +28,34 @@ 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();
|
||||
return axios({
|
||||
method: "get",
|
||||
url: `${VITE_PUBLIC_PATH}platform-config.json`
|
||||
})
|
||||
.then(({ data: config }) => {
|
||||
let $config = app.config.globalProperties.$config;
|
||||
// 自动注入系统配置
|
||||
if (app && $config && typeof config === "object") {
|
||||
$config = Object.assign($config, config);
|
||||
app.config.globalProperties.$config = $config;
|
||||
// 设置全局配置
|
||||
setConfig($config);
|
||||
}
|
||||
return $config;
|
||||
const fn = ({ data: config }) => {
|
||||
let $config = app.config.globalProperties.$config;
|
||||
// 自动注入系统配置
|
||||
if (app && $config && typeof config === "object") {
|
||||
$config = Object.assign($config, config);
|
||||
app.config.globalProperties.$config = $config;
|
||||
// 设置全局配置
|
||||
setConfig($config);
|
||||
}
|
||||
return $config;
|
||||
};
|
||||
if (local) {
|
||||
return Promise.resolve({ data: platformConfig }).then(fn);
|
||||
} else {
|
||||
return axios({
|
||||
method: "get",
|
||||
url: `${VITE_PUBLIC_PATH}platform-config.json`
|
||||
})
|
||||
.catch(() => {
|
||||
throw "请在public文件夹下添加platform-config.json配置文件";
|
||||
});
|
||||
.then(fn)
|
||||
.catch(() => {
|
||||
throw "请在public文件夹下添加platform-config.json配置文件";
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/** 本地响应式存储的命名空间 */
|
||||
|
@ -25,6 +25,9 @@
|
||||
"@/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@public/*": [
|
||||
"public/*"
|
||||
],
|
||||
"@build/*": [
|
||||
"build/*"
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user