-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstores.ts
More file actions
35 lines (32 loc) · 1022 Bytes
/
Copy pathstores.ts
File metadata and controls
35 lines (32 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { assets } from './instance/config'//导入状态配置
import { getAssetIdForPath } from './router'//导入路由控制
/**
* 应用配置 - 默认使用第一个配置
*/
export let appConfig = { ...assets[1] };
/**
* 根据资产ID更新应用配置
* @param assetId 资产ID
*/
export function updateAppConfig(assetId: number): void {
if (assets[assetId]) {
//更新appConfig
appConfig = { ...assets[assetId] };
}
}
// 在初始化路由之前,先根据URL参数设置配置
export function initializeConfigFromUrl() {
// 从URL参数中获取资产ID
const urlParams = new URLSearchParams(window.location.search);
const assetIdParam = urlParams.get('assetId');
if (assetIdParam) {
// 如果URL中有资产ID参数,使用该参数
const assetId = parseInt(assetIdParam, 10);
updateAppConfig(assetId);
} else {
// 根据路径确定资产
const path = window.location.pathname;
const assetId = getAssetIdForPath(path);
updateAppConfig(assetId);
}
}