Merge pull request #7 from 6get-xiaofan/main

Fix: serverConfig.json fetching behavior across nested routes
This commit is contained in:
valarchie 2024-02-23 11:27:06 +08:00 committed by GitHub
commit 33103b61f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 3 deletions

View File

@ -1,8 +1,8 @@
import { App } from "vue";
import axios from "axios";
import { configConver } from "@/utils/rootConver";
let config: object = {};
const { VITE_PUBLIC_PATH } = import.meta.env;
const setConfig = (cfg?: unknown) => {
config = Object.assign(config, cfg);
@ -31,7 +31,7 @@ export const getServerConfig = async (app: App): Promise<undefined> => {
app.config.globalProperties.$config = getConfig();
return axios({
method: "get",
url: `${VITE_PUBLIC_PATH}serverConfig.json`
url: `${configConver()}serverConfig.json`
})
.then(({ data: config }) => {
let $config = app.config.globalProperties.$config;

View File

@ -158,7 +158,12 @@ router.beforeEach((to: ToRouteType, _from, next) => {
getTopMenu(true);
// query、params模式路由传参数的标签页不在此处处理
if (route && route.meta?.title) {
if (isAllEmpty(route.parentId) && route.meta?.backstage) {
if (
isAllEmpty(route.parentId) &&
route.meta?.backstage &&
route.children &&
route.children.length > 0
) {
// 此处为动态顶级路由(目录)
const { path, name, meta } = route.children[0];
useMultiTagsStoreHook().handleTags("push", {

22
src/utils/rootConver.ts Normal file
View File

@ -0,0 +1,22 @@
const { VITE_PUBLIC_PATH } = import.meta.env;
export const configConver = () => {
if (VITE_PUBLIC_PATH === "./") {
return window.location.origin + "/";
}
return window.location.origin + processPath(VITE_PUBLIC_PATH);
};
function processPath(str: string): string {
if (str.startsWith("./")) {
str = str.substring(1);
} else if (!str.startsWith("/")) {
str = "/" + str;
}
if (!str.endsWith("/")) {
str += "/";
}
return str;
}