+43
-24
@@ -518,6 +518,47 @@ function serializeCountdownRegions() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findCanvasSizeName(width, height) {
|
||||||
|
const size = canvasSizes.find((item) => item.width === width && item.height === height);
|
||||||
|
return size ? size.name : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyImportedCountdownCanvasSize(regionData) {
|
||||||
|
const sourceCanvas = regionData && (regionData.canvas || regionData.size);
|
||||||
|
if (!sourceCanvas || !canvas) return;
|
||||||
|
|
||||||
|
const width = Number(sourceCanvas.width || sourceCanvas.w);
|
||||||
|
const height = Number(sourceCanvas.height || sourceCanvas.h);
|
||||||
|
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) return;
|
||||||
|
if (canvas.width === width && canvas.height === height) return;
|
||||||
|
|
||||||
|
const canvasSizeSelect = document.getElementById('canvasSize');
|
||||||
|
const matchedName = findCanvasSizeName(width, height);
|
||||||
|
if (canvasSizeSelect && matchedName) canvasSizeSelect.value = matchedName;
|
||||||
|
canvas.width = width;
|
||||||
|
canvas.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyImportedCountdownTemplate(rawData) {
|
||||||
|
const importedState = rawData && typeof rawData === 'object' && rawData.countdown ? rawData.countdown : rawData;
|
||||||
|
const importedRegions = rawData && typeof rawData === 'object'
|
||||||
|
? (rawData.countdownRegions || rawData.regions || (importedState && importedState.regions))
|
||||||
|
: null;
|
||||||
|
|
||||||
|
countdownState = normalizeCountdownState(importedState);
|
||||||
|
if (!countdownState.single.date) countdownState.single.date = getTodayISODate();
|
||||||
|
|
||||||
|
applyImportedCountdownCanvasSize(importedRegions);
|
||||||
|
countdownManualRegions = normalizeCountdownRegions(importedRegions);
|
||||||
|
countdownDateRegion = normalizeCountdownDateRegion(importedRegions);
|
||||||
|
|
||||||
|
refreshCountdownTemplateUI();
|
||||||
|
applyCountdownTemplate();
|
||||||
|
renderCountdownRegions(countdownManualRegions || autoTemplateRegions());
|
||||||
|
saveCountdownState();
|
||||||
|
setActivePanelTab('countdown-template-panel');
|
||||||
|
}
|
||||||
|
|
||||||
function syncCountdownRegionInputs(index) {
|
function syncCountdownRegionInputs(index) {
|
||||||
const container = document.getElementById('countdown-region-items');
|
const container = document.getElementById('countdown-region-items');
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
@@ -1423,18 +1464,7 @@ function importCountdownTemplate(file) {
|
|||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
try {
|
try {
|
||||||
const rawData = JSON.parse(reader.result);
|
const rawData = JSON.parse(reader.result);
|
||||||
const importedState = rawData && typeof rawData === 'object' && rawData.countdown ? rawData.countdown : rawData;
|
applyImportedCountdownTemplate(rawData);
|
||||||
countdownState = normalizeCountdownState(importedState);
|
|
||||||
const importedRegions = rawData && typeof rawData === 'object'
|
|
||||||
? (rawData.countdownRegions || rawData.regions || (importedState && importedState.regions))
|
|
||||||
: null;
|
|
||||||
countdownManualRegions = normalizeCountdownRegions(importedRegions);
|
|
||||||
countdownDateRegion = normalizeCountdownDateRegion(importedRegions);
|
|
||||||
if (!countdownState.single.date) countdownState.single.date = getTodayISODate();
|
|
||||||
saveCountdownState();
|
|
||||||
refreshCountdownTemplateUI();
|
|
||||||
renderCountdownRegions(countdownManualRegions || autoTemplateRegions());
|
|
||||||
setActivePanelTab('countdown-template-panel');
|
|
||||||
addLog('Countdown 模板已导入。');
|
addLog('Countdown 模板已导入。');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -1473,18 +1503,7 @@ function importCountdownTemplate(file) {
|
|||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
try {
|
try {
|
||||||
const rawData = JSON.parse(reader.result);
|
const rawData = JSON.parse(reader.result);
|
||||||
const importedState = rawData && typeof rawData === 'object' && rawData.countdown ? rawData.countdown : rawData;
|
applyImportedCountdownTemplate(rawData);
|
||||||
countdownState = normalizeCountdownState(importedState);
|
|
||||||
const importedRegions = rawData && typeof rawData === 'object'
|
|
||||||
? (rawData.countdownRegions || rawData.regions || (importedState && importedState.regions))
|
|
||||||
: null;
|
|
||||||
countdownManualRegions = normalizeCountdownRegions(importedRegions);
|
|
||||||
countdownDateRegion = normalizeCountdownDateRegion(importedRegions);
|
|
||||||
if (!countdownState.single.date) countdownState.single.date = getTodayISODate();
|
|
||||||
saveCountdownState();
|
|
||||||
refreshCountdownTemplateUI();
|
|
||||||
renderCountdownRegions(countdownManualRegions || autoTemplateRegions());
|
|
||||||
setActivePanelTab('countdown-template-panel');
|
|
||||||
addLog('倒计时模板已导入。');
|
addLog('倒计时模板已导入。');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user