Web 端数据交互与 design2 布局修复
统一门户 JSON 契约:新增 GET /templates/{id},模板/云文件/保存/打开走虚拟 key;
layer 保存弹层替代 prompt,本地 .soon 已登录后台 POST 登记;修复保存静默失败与 design2 全宽布局。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -333,6 +333,7 @@ window.display_func = function display_func(img1, img2, img3) {
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
skin: 'soon-layer',
|
||||
area: [w, h],
|
||||
title: language_str('display'), //不显示标题栏"预览"
|
||||
shadeClose: true, //点击遮罩关闭
|
||||
@@ -1087,6 +1088,9 @@ function cloudSaveSuccessLabel(res, fallback) {
|
||||
|
||||
function onCloudWriteDone(res, fallback, callback) {
|
||||
applyCloudWriteResult(res, fallback);
|
||||
if (res && res.fileKey && typeof window.soonClearPendingImport === 'function') {
|
||||
window.soonClearPendingImport();
|
||||
}
|
||||
layer.msg(language_str('saveSucc') + cloudSaveSuccessLabel(res, fallback));
|
||||
if (callback && typeof callback === 'function') callback();
|
||||
}
|
||||
@@ -1095,6 +1099,15 @@ function guardWebSave() {
|
||||
return typeof window.soonGuardCloudSave === 'function' ? window.soonGuardCloudSave() : true;
|
||||
}
|
||||
|
||||
function reportSaveError(err) {
|
||||
if (err && err.status) return;
|
||||
if (typeof window.soonShowApiError === 'function') {
|
||||
window.soonShowApiError({ status: err && err.status, message: (err && err.message) || '保存失败' });
|
||||
} else if (typeof window.soonToast === 'function') {
|
||||
window.soonToast('保存失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function saveAs(op1, callback) {
|
||||
// 临时移除辅助线,保存后再恢复
|
||||
let guideLines1 = []
|
||||
@@ -1143,7 +1156,7 @@ function saveAs(op1, callback) {
|
||||
if (window.platformBridge && window.platformBridge.writeFile) {
|
||||
window.platformBridge.writeFile(fp, content).then(function (res) {
|
||||
onCloudWriteDone(res, fp, callback);
|
||||
}).catch(function () {});
|
||||
}).catch(reportSaveError);
|
||||
return;
|
||||
}
|
||||
var fs = typeof require !== 'undefined' ? require('fs') : null;
|
||||
@@ -1155,7 +1168,7 @@ function saveAs(op1, callback) {
|
||||
if (callback && typeof callback === 'function') callback();
|
||||
}
|
||||
})
|
||||
.catch(function(err) {});
|
||||
.catch(reportSaveError);
|
||||
}
|
||||
|
||||
function save(op1, callback) {
|
||||
@@ -1198,7 +1211,7 @@ function save(op1, callback) {
|
||||
if (window.platformBridge && window.platformBridge.writeFile) {
|
||||
window.platformBridge.writeFile(openAs.name, content).then(function (res) {
|
||||
onCloudWriteDone(res, openAs.name, callback);
|
||||
}).catch(function () {});
|
||||
}).catch(reportSaveError);
|
||||
return;
|
||||
}
|
||||
var fs = typeof require !== 'undefined' ? require('fs') : null;
|
||||
@@ -1222,7 +1235,7 @@ function save(op1, callback) {
|
||||
if (window.platformBridge && window.platformBridge.writeFile) {
|
||||
window.platformBridge.writeFile(fp, content).then(function (res) {
|
||||
onCloudWriteDone(res, fp, callback);
|
||||
}).catch(function () {});
|
||||
}).catch(reportSaveError);
|
||||
return;
|
||||
}
|
||||
var fs = typeof require !== 'undefined' ? require('fs') : null;
|
||||
@@ -1234,7 +1247,7 @@ function save(op1, callback) {
|
||||
if (callback && typeof callback === 'function') callback();
|
||||
}
|
||||
})
|
||||
.catch(function(err) {});
|
||||
.catch(reportSaveError);
|
||||
}
|
||||
|
||||
window.saveHistory = function saveHistory() {
|
||||
@@ -1287,7 +1300,10 @@ window.openFile = function open(file, jAlready) {
|
||||
if (!file) return;
|
||||
if (typeof window.soonBindFileMeta === 'function') window.soonBindFileMeta(file);
|
||||
function doOpenWithJson(j) {
|
||||
if (!j || !background_image) return;
|
||||
if (!j || !background_image) {
|
||||
if (typeof window.soonReportOpenLoadError === 'function') window.soonReportOpenLoadError('模板/文件加载失败');
|
||||
return;
|
||||
}
|
||||
openAs.name = file;
|
||||
var left = background_image.left
|
||||
let top = background_image.top
|
||||
@@ -1438,6 +1454,7 @@ window.openFile = function open(file, jAlready) {
|
||||
recordJson = recordJson2
|
||||
step = step2
|
||||
}
|
||||
if (typeof window.soonTryConsumeCloudImport === 'function') window.soonTryConsumeCloudImport(file);
|
||||
}
|
||||
|
||||
canvas1.loadFromJSON(j.f, function () {
|
||||
@@ -1482,7 +1499,11 @@ window.openFile = function open(file, jAlready) {
|
||||
if (j) {
|
||||
doOpenWithJson(j);
|
||||
openAs.name = file;
|
||||
} else if (typeof window.soonReportOpenLoadError === 'function') {
|
||||
window.soonReportOpenLoadError('模板/文件加载失败');
|
||||
}
|
||||
}).catch(function () {
|
||||
if (typeof window.soonReportOpenLoadError === 'function') window.soonReportOpenLoadError('模板/文件加载失败');
|
||||
});
|
||||
}
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user