feat: 多模板支持,URL 查询参数 ?t= 切换不同邀请函配置
This commit is contained in:
39
js/script.js
39
js/script.js
@@ -45,7 +45,36 @@
|
||||
const guideV = document.getElementById('guideV');
|
||||
const gridLines = document.getElementById('gridLines');
|
||||
|
||||
let inputsConfig = null;
|
||||
var inputsConfig = null;
|
||||
var defaultBgUrl = './images/default-bg.jpg';
|
||||
|
||||
// 解析 URL 查询参数 ?t=模板名,选择对应模板
|
||||
(function resolveTemplate() {
|
||||
try {
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
var templateName = params.get('t') || (typeof CONFIG !== 'undefined' ? CONFIG.defaultTemplate : 'default');
|
||||
if (typeof CONFIG !== 'undefined' && CONFIG.templates && CONFIG.templates[templateName]) {
|
||||
var tmpl = CONFIG.templates[templateName];
|
||||
ACTIVE_TEMPLATE = tmpl;
|
||||
inputsConfig = tmpl.inputs || null;
|
||||
if (tmpl.bgImage) defaultBgUrl = tmpl.bgImage;
|
||||
} else if (typeof CONFIG !== 'undefined' && CONFIG.templates && CONFIG.templates[CONFIG.defaultTemplate]) {
|
||||
var tmpl = CONFIG.templates[CONFIG.defaultTemplate];
|
||||
ACTIVE_TEMPLATE = tmpl;
|
||||
inputsConfig = tmpl.inputs || null;
|
||||
if (tmpl.bgImage) defaultBgUrl = tmpl.bgImage;
|
||||
} else {
|
||||
// 兼容旧版 INPUTS_CONFIG / DEFAULT_BG_IMAGE
|
||||
if (typeof INPUTS_CONFIG !== 'undefined') inputsConfig = INPUTS_CONFIG.inputs;
|
||||
if (typeof DEFAULT_BG_IMAGE !== 'undefined') defaultBgUrl = DEFAULT_BG_IMAGE;
|
||||
}
|
||||
} catch (e) {
|
||||
if (typeof INPUTS_CONFIG !== 'undefined') inputsConfig = INPUTS_CONFIG.inputs;
|
||||
if (typeof DEFAULT_BG_IMAGE !== 'undefined') defaultBgUrl = DEFAULT_BG_IMAGE;
|
||||
}
|
||||
window._inputsConfig = inputsConfig;
|
||||
})();
|
||||
|
||||
let currentImage = null;
|
||||
let bgImageScale = 1;
|
||||
let bgImageOpacity = 1;
|
||||
@@ -266,8 +295,8 @@
|
||||
updateUndoRedoButtons();
|
||||
|
||||
// 从配置文件应用输入框初始参数
|
||||
if (typeof INPUTS_CONFIG !== 'undefined' && INPUTS_CONFIG && INPUTS_CONFIG.inputs) {
|
||||
INPUTS_CONFIG.inputs.forEach(function(cfg) {
|
||||
if (inputsConfig) {
|
||||
inputsConfig.forEach(function(cfg) {
|
||||
var el = document.getElementById(cfg.id);
|
||||
if (el) {
|
||||
el.style.left = cfg.left + 'px';
|
||||
@@ -808,9 +837,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 加载默认背景图(路径从 config.js 读取)
|
||||
// 加载默认背景图(路径从 config.js 根据 ?t= 参数读取)
|
||||
function loadDefaultBackground() {
|
||||
const defaultBgUrl = typeof DEFAULT_BG_IMAGE !== 'undefined' ? DEFAULT_BG_IMAGE : './images/default-bg.jpg';
|
||||
// defaultBgUrl 已在模板解析阶段确定
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
currentImage = img;
|
||||
|
||||
Reference in New Issue
Block a user