115 lines
3.2 KiB
JavaScript
115 lines
3.2 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
// 显示错误页面
|
|
function showErrorPage(message) {
|
|
const appContainer = document.getElementById('app');
|
|
if (appContainer) {
|
|
// 添加样式
|
|
const style = document.createElement('style');
|
|
style.textContent = `
|
|
* {
|
|
padding: 0;
|
|
margin: 0;
|
|
}
|
|
body {
|
|
background: #fff;
|
|
overflow: hidden;
|
|
}
|
|
.icon {
|
|
width: 50px;
|
|
height: 50px;
|
|
background: url('https://oss.yqbmb.com/card/v1/warn.png') no-repeat;
|
|
margin: 100px auto 10px;
|
|
background-position: center;
|
|
background-size: 100%;
|
|
}
|
|
.error {
|
|
text-align: center;
|
|
font-size: 17px;
|
|
font-weight: bold;
|
|
padding: 15px 0;
|
|
}
|
|
`;
|
|
document.head.appendChild(style);
|
|
|
|
appContainer.innerHTML = `<div class="icon"></div><p class="error">${message}</p>`;
|
|
}
|
|
}
|
|
|
|
// 动态加载CSS文件
|
|
function loadCSS(href) {
|
|
return new Promise((resolve, reject) => {
|
|
const link = document.createElement('link');
|
|
link.rel = 'stylesheet';
|
|
link.type = 'text/css';
|
|
link.href = href;
|
|
link.onload = resolve;
|
|
link.onerror = reject;
|
|
document.head.appendChild(link);
|
|
});
|
|
}
|
|
|
|
// 动态加载JS文件
|
|
function loadJS(src) {
|
|
return new Promise((resolve, reject) => {
|
|
const script = document.createElement('script');
|
|
script.src = src;
|
|
script.onload = resolve;
|
|
script.onerror = reject;
|
|
document.body.appendChild(script);
|
|
});
|
|
}
|
|
|
|
// 初始化函数
|
|
async function init() {
|
|
try {
|
|
const url = `https://oss.yqbmb.com/card/v1/config.json`;
|
|
|
|
|
|
// 从API获取配置
|
|
const response = await fetch(url, {
|
|
method: 'GET',
|
|
cache: 'no-cache',
|
|
});
|
|
const result = await response.json();
|
|
|
|
if (!result.success) {
|
|
showErrorPage(result.message || '链接配置获取失败');
|
|
return;
|
|
}
|
|
|
|
// 检查微信外链状态
|
|
if (result.data) {
|
|
const wechatLink = result.data;
|
|
|
|
// 检查链接是否停用 (后端返回 Boolean 类型, true 表示审核拒绝/停用)
|
|
if (wechatLink.isForbid === true) {
|
|
showErrorPage('链接已停用');
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
// 将配置数据存储到全局变量,供后续脚本使用
|
|
window.LANDING_CONFIG = result.data;
|
|
// 保存原始目标链接到全局变量
|
|
// window.ORIGINAL_TARGET_URL = result.data.originalTargetUrl;
|
|
|
|
// 根据landingType动态加载对应的资源
|
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
await loadCSS('landpage.css?v=' + timestamp);
|
|
await loadJS('landpage.js?v=' + timestamp);
|
|
} catch (error) {
|
|
showErrorPage('链接配置加载失败');
|
|
}
|
|
}
|
|
|
|
// 页面加载完成后初始化
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
})();
|