119 lines
3.1 KiB
JavaScript
119 lines
3.1 KiB
JavaScript
// config.js
|
|
window.ENV = {
|
|
// 开发环境配置
|
|
development: {
|
|
API_BASE_URL: 'http://47.108.24.205:9100',
|
|
// API_BASE_URL: 'http://192.168.10.119:9100',
|
|
// 后端租户标识,会作为 header tenantId 发送;后面更换租户只改这里。
|
|
TENANT_ID: '531923',
|
|
// TENANT_ID: '000000',
|
|
CLIENT_ID: '209ef407810e3856f40870a9f0e769d7',
|
|
DEBUG: true,
|
|
APP_NAME: 'Lottery App Dev'
|
|
},
|
|
// 生产环境配置
|
|
production: {
|
|
API_BASE_URL: 'https://api-3d.3dyjs.cn',
|
|
// 后端租户标识,会作为 header tenantId 发送;后面更换租户只改这里。
|
|
TENANT_ID: '531923',
|
|
CLIENT_ID: '209ef407810e3856f40870a9f0e769d7',
|
|
DEBUG: false,
|
|
APP_NAME: 'Lottery App'
|
|
}
|
|
};
|
|
|
|
// 根据域名自动判断环境
|
|
window.CURRENT_ENV = (function () {
|
|
if (location.hostname === 'localhost' || location.hostname === '127.0.0.1' || location.port !== '') {
|
|
return 'development';
|
|
} else {
|
|
return 'production';
|
|
}
|
|
})();
|
|
|
|
// 获取当前环境配置
|
|
window.CURRENT_CONFIG = window.ENV[window.CURRENT_ENV];
|
|
|
|
window.NavigationUtil = (function (window, document) {
|
|
const blockedProtocols = /^(?:javascript|data|vbscript|mailto|tel):/i;
|
|
|
|
function shouldOpenInNewTab(anchor) {
|
|
const href = (anchor.getAttribute('href') || '').trim();
|
|
|
|
return href && href !== '#' && !href.startsWith('#') &&
|
|
!anchor.hasAttribute('download') && !blockedProtocols.test(href);
|
|
}
|
|
|
|
function prepareAnchor(anchor) {
|
|
if (!anchor || anchor.tagName !== 'A' || !shouldOpenInNewTab(anchor)) {
|
|
return;
|
|
}
|
|
|
|
if (anchor.target !== '_blank') {
|
|
anchor.target = '_blank';
|
|
}
|
|
|
|
const relTokens = (anchor.getAttribute('rel') || '').split(/\s+/).filter(Boolean);
|
|
|
|
if (!relTokens.includes('noopener')) {
|
|
anchor.setAttribute('rel', [...relTokens, 'noopener'].join(' '));
|
|
}
|
|
}
|
|
|
|
function prepareAnchors(root) {
|
|
if (root.nodeType === 1 && root.matches('a[href]')) {
|
|
prepareAnchor(root);
|
|
}
|
|
|
|
root.querySelectorAll('a[href]').forEach(prepareAnchor);
|
|
}
|
|
|
|
function installLinkTargeting() {
|
|
prepareAnchors(document);
|
|
|
|
new MutationObserver((mutations) => {
|
|
mutations.forEach((mutation) => {
|
|
if (mutation.type === 'attributes') {
|
|
prepareAnchor(mutation.target);
|
|
return;
|
|
}
|
|
|
|
mutation.addedNodes.forEach((node) => {
|
|
if (node.nodeType === 1) {
|
|
prepareAnchors(node);
|
|
}
|
|
});
|
|
});
|
|
}).observe(document.documentElement, {
|
|
subtree: true,
|
|
childList: true,
|
|
attributes: true,
|
|
attributeFilter: ['href', 'target', 'download']
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', installLinkTargeting, { once: true });
|
|
} else {
|
|
installLinkTargeting();
|
|
}
|
|
|
|
return {
|
|
open(url) {
|
|
const destination = String(url || '').trim();
|
|
|
|
if (!destination) {
|
|
return null;
|
|
}
|
|
|
|
const openedWindow = window.open(destination, '_blank', 'noopener');
|
|
|
|
if (openedWindow) {
|
|
openedWindow.opener = null;
|
|
}
|
|
|
|
return openedWindow;
|
|
}
|
|
};
|
|
})(window, document);
|