Files

84 lines
2.3 KiB
JavaScript

(function (root, factory) {
// 根配置负责运行环境、接口基础地址与全站跳转入口。
if (typeof module === 'object' && module.exports) {
module.exports = factory;
return;
}
root.GenealogyConfig = factory(root);
})(typeof globalThis !== 'undefined' ? globalThis : window, function (root) {
'use strict';
var CLIENT_ID = 'ced7e5f0498645c6ec642dcf450b036f';
var TENANT_ID = '000000';
var TOKEN_KEY = 'genealogy_auth_token';
var BLOCKED_NAVIGATION_PROTOCOL = /^(?:javascript|data|vbscript):/i;
function createNavigationUtil() {
return {
open: function (url) {
var targetUrl = String(url || '').trim();
if (!targetUrl || BLOCKED_NAVIGATION_PROTOCOL.test(targetUrl) || typeof root.open !== 'function') {
return null;
}
var openedWindow = root.open(targetUrl, '_blank', 'noopener');
if (openedWindow) openedWindow.opener = null;
return openedWindow;
},
replace: function (url) {
var targetUrl = String(url || '').trim();
if (!targetUrl || BLOCKED_NAVIGATION_PROTOCOL.test(targetUrl)) return;
if (root.location && typeof root.location.replace === 'function') {
root.location.replace(targetUrl);
}
}
};
}
// 这里只维护运行环境和后端基础地址,具体接口路径统一放在 ApiClient 中。
var ENVIRONMENTS = {
development: {
apiBaseUrl: 'https://backend-api.ddxcjp.cn/'
},
production: {
apiBaseUrl: 'https://backend-api.ddxcjp.cn/'
}
};
function getEnvironment() {
var location = root.location || {};
var hostname = location.hostname || '';
if (hostname === 'localhost' || hostname === '127.0.0.1' || location.port) {
return 'development';
}
return 'production';
}
function getApiBaseUrl() {
return ENVIRONMENTS[getEnvironment()].apiBaseUrl;
}
function getConfig() {
return {
environment: getEnvironment(),
apiBaseUrl: getApiBaseUrl(),
clientId: CLIENT_ID,
tenantId: TENANT_ID,
tokenKey: TOKEN_KEY
};
}
root.NavigationUtil = root.NavigationUtil || createNavigationUtil();
return {
getEnvironment: getEnvironment,
getApiBaseUrl: getApiBaseUrl,
getConfig: getConfig
};
});