Skip to content

Commit

Permalink
fixed error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Uyanide committed Jul 22, 2024
1 parent b08c74e commit 602ca72
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ <h1 class="title">光棱坦克工厂</h1>
callback(img);
}).catch((error) => {
console.error('图像加载失败:', error);
alert('无法加载图像, 请确保图像文件状态。');
alert('无法加载图像, 请确定文件类型和状态。');
loadImage(defaultSrc[currCanvasId]).then((img) => {
callback(img);
});
Expand Down Expand Up @@ -674,7 +674,7 @@ <h1 class="title">光棱坦克工厂</h1>
callback(img);
}).catch((error) => {
console.error('图像加载失败:', error);
alert('无法加载图像, 请确保剪贴板图像文件状态。');
alert('无法加载图像, 请确定剪贴板图像文件状态。');
loadImage(defaultSrc[currCanvasId]).then((img) => {
callback(img);
});
Expand All @@ -694,7 +694,7 @@ <h1 class="title">光棱坦克工厂</h1>
callback(img);
}).catch((error) => {
console.error('图像加载失败:', error);
alert('无法加载图像, 请确保拖动文件状态。');
alert('无法加载图像, 请确定拖动文件类型和状态。');
loadImage(defaultSrc[currCanvasId]).then((img) => {
callback(img);
});
Expand Down Expand Up @@ -749,6 +749,7 @@ <h1 class="title">光棱坦克工厂</h1>
decodeSetupEventListeners();
encodeRemoveEventListeners();
curPageId = 'decodePage';
currCanvasId = 0;
}
}

Expand Down Expand Up @@ -1054,6 +1055,7 @@ <h1 class="title">光棱坦克工厂</h1>

// 从文件加载里图
function encodeLoadInnerImageFile(event) {
currCanvasId = 1;
const file = event.target.files[0];
updateImageFromFile(file, (img) => {
mirage.updateInnerImage(img);
Expand All @@ -1062,25 +1064,26 @@ <h1 class="title">光棱坦克工厂</h1>

// 从文件加载表图
function encodeLoadCoverImageFile(event) {
currCanvasId = 2;
const file = event.target.files[0];
updateImageFromFile(file, (img) => {
mirage.updateCoverImage(img);
});
}

// 从剪贴板加载表图
// 从剪贴板加载表里图
var mouseX = 0;
function updateMousePosition(event) {
mouseX = event.clientX;
}

// 从剪贴板加载里图
function encodeLoadImageFromClipboard(event) {
if (mouseX < window.innerWidth / 2) {
currCanvasId = 1;
updateImageFromClipboard(event, (img) => {
mirage.updateInnerImage(img);
});
} else {
currCanvasId = 2;
updateImageFromClipboard(event, (img) => {
mirage.updateCoverImage(img);
});
Expand All @@ -1089,13 +1092,15 @@ <h1 class="title">光棱坦克工厂</h1>

// 从拖动加载里图
function encodeLoadInnerImageFromDrag(event) {
currCanvasId = 1;
dragDropLoadImage(event, (img) => {
mirage.updateInnerImage(img);
});
}

// 从拖动加载表图
function encodeLoadCoverImageFromDrag(event) {
currCanvasId = 2;
dragDropLoadImage(event, (img) => {
mirage.updateCoverImage(img);
});
Expand Down Expand Up @@ -1203,6 +1208,19 @@ <h1 class="title">光棱坦克工厂</h1>
isPng = document.getElementById('isPngCheckBox').checked;
}

// 保存图像
function encodeSaveImage() {
if (isPng) {
saveIamgeFromCanvas('outputCanvas');
} else {
const canvas = document.getElementById('outputCanvas');
const link = document.createElement('a');
link.href = canvas.toDataURL('image/jpeg', 1);
link.download = 'output.jpg';
link.click();
}
}

// 以当前结果跳转显形界面
function jumpToDecode() {
if (mirage.innerImg && mirage.coverImg) {
Expand All @@ -1225,19 +1243,6 @@ <h1 class="title">光棱坦克工厂</h1>
}
}

// 保存图像
function encodeSaveImage() {
if (isPng) {
saveIamgeFromCanvas('outputCanvas');
} else {
const canvas = document.getElementById('outputCanvas');
const link = document.createElement('a');
link.href = canvas.toDataURL('image/jpeg', 1);
link.download = 'output.jpg';
link.click();
}
}

// 设置事件监听器
function encodeSetUpEventListeners() {

Expand Down

0 comments on commit 602ca72

Please sign in to comment.