Web 端数据交互与 design2 布局修复
统一门户 JSON 契约:新增 GET /templates/{id},模板/云文件/保存/打开走虚拟 key;
layer 保存弹层替代 prompt,本地 .soon 已登录后台 POST 登记;修复保存静默失败与 design2 全宽布局。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,7 +6,9 @@ $("#object_attribute").css("height", "470px");
|
||||
$("#obj_list").css("height", document.body.clientHeight - 520);
|
||||
$(".obj_list").css("height", $("#obj_list").height() - 32);
|
||||
|
||||
$(".main").show();
|
||||
var mainEl = document.querySelector('.layui-fluid.main');
|
||||
if (mainEl) mainEl.style.display = 'flex';
|
||||
else $(".main").show();
|
||||
$(".canvas_box").css("height", document.body.clientHeight - 100);
|
||||
zoom = $(".canvas_bg_img").width() / 2787
|
||||
$("#canvas1").attr("width", $(".canvas_box").width() / zoom);
|
||||
@@ -259,7 +261,7 @@ if (typeof ipcRenderer !== 'undefined' && ipcRenderer) {
|
||||
applySysLan(window.platformBridge.getLocale());
|
||||
}
|
||||
function onCloseConfirm() {
|
||||
layer.confirm('<font style="color:black">' + language_str("whetherSave") + '</font>', {
|
||||
layer.confirm(language_str("whetherSave"), {
|
||||
btn: [language_str("save"), language_str("noSave"), language_str("cancel")]
|
||||
, btn3: function (index, layero) {}
|
||||
}, function (index, layero) {
|
||||
@@ -418,28 +420,14 @@ function addBackground() {
|
||||
recordObjs2.push(JSON.stringify(objs2));
|
||||
recordJson2.push(canvas2.toJSON(TO_JSON_PROPERTIES));
|
||||
|
||||
let file = GetFile().get('file');
|
||||
if (!file && typeof sessionStorage !== 'undefined') {
|
||||
try {
|
||||
file = sessionStorage.getItem('soondesign_open_file');
|
||||
if (file) {
|
||||
sessionStorage.removeItem('soondesign_open_file');
|
||||
sessionStorage.removeItem('soondesign_open_type');
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
var file = typeof window.soonResolveOpenFileKey === 'function'
|
||||
? window.soonResolveOpenFileKey(GetFile)
|
||||
: (GetFile().get('file') || '');
|
||||
if (file && file != 'empty') {
|
||||
if (file.indexOf('soondesign_file:') === 0 && typeof sessionStorage !== 'undefined') {
|
||||
try {
|
||||
var metaRaw = sessionStorage.getItem('soondesign_open_meta');
|
||||
if (metaRaw) {
|
||||
window._soonFileMeta = JSON.parse(metaRaw);
|
||||
sessionStorage.removeItem('soondesign_open_meta');
|
||||
}
|
||||
} catch (e) {}
|
||||
if (typeof window.soonConsumeOpenMeta === 'function') {
|
||||
window.soonConsumeOpenMeta(file);
|
||||
}
|
||||
var p = window.openFile(file)
|
||||
if (p && p.then) p.then(function() {}, function() {})
|
||||
window.openFile(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -401,6 +401,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, //点击遮罩关闭
|
||||
@@ -1097,8 +1098,14 @@ 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.f || !j.f.objects || !Array.isArray(j.f.objects) || j.f.objects.length === 0) return;
|
||||
if (!j || !background_image) {
|
||||
if (typeof window.soonReportOpenLoadError === 'function') window.soonReportOpenLoadError('模板/文件加载失败');
|
||||
return;
|
||||
}
|
||||
if (!j.f || !j.f.objects || !Array.isArray(j.f.objects) || j.f.objects.length === 0) {
|
||||
if (typeof window.soonReportOpenLoadError === 'function') window.soonReportOpenLoadError('模板/文件加载失败');
|
||||
return;
|
||||
}
|
||||
if (!j.b || !j.b.objects || !Array.isArray(j.b.objects) || j.b.objects.length === 0) {
|
||||
j.b = { version: '4.6.0', objects: [], hoverCursor: 'move' };
|
||||
}
|
||||
@@ -1173,12 +1180,14 @@ window.openFile = function open(file, jAlready) {
|
||||
var j2 = canvas2.toJSON(props);
|
||||
recordJson2.push(j2);
|
||||
}, 0);
|
||||
if (typeof window.soonTryConsumeCloudImport === 'function') window.soonTryConsumeCloudImport(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (arguments.length >= 2 && jAlready) {
|
||||
doOpenWithJson(jAlready);
|
||||
openAs.name = file;
|
||||
if (typeof window.soonTryConsumeCloudImport === 'function') window.soonTryConsumeCloudImport(file);
|
||||
return;
|
||||
}
|
||||
if (window.platformBridge && window.platformBridge.readJsonFile) {
|
||||
@@ -1186,8 +1195,12 @@ window.openFile = function open(file, jAlready) {
|
||||
if (j) {
|
||||
doOpenWithJson(j);
|
||||
openAs.name = file;
|
||||
} else if (typeof window.soonReportOpenLoadError === 'function') {
|
||||
window.soonReportOpenLoadError('模板/文件加载失败');
|
||||
}
|
||||
}).catch(function() {});
|
||||
}).catch(function () {
|
||||
if (typeof window.soonReportOpenLoadError === 'function') window.soonReportOpenLoadError('模板/文件加载失败');
|
||||
});
|
||||
}
|
||||
try {
|
||||
var fs = typeof require !== 'undefined' ? require('fs') : null;
|
||||
@@ -1252,6 +1265,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();
|
||||
}
|
||||
@@ -1260,6 +1276,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 = [];
|
||||
@@ -1311,7 +1336,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;
|
||||
@@ -1322,7 +1347,7 @@ function saveAs(op1, callback) {
|
||||
saveHistory();
|
||||
if (callback && typeof callback === 'function') callback();
|
||||
}
|
||||
}).catch(function(err) {});
|
||||
}).catch(reportSaveError);
|
||||
}
|
||||
|
||||
function save(op1, callback) {
|
||||
@@ -1365,7 +1390,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;
|
||||
@@ -1394,7 +1419,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;
|
||||
@@ -1405,7 +1430,7 @@ function save(op1, callback) {
|
||||
saveHistory();
|
||||
if (callback && typeof callback === 'function') callback();
|
||||
}
|
||||
}).catch(function(err) {});
|
||||
}).catch(reportSaveError);
|
||||
}
|
||||
|
||||
window.saveHistory = function saveHistory() {
|
||||
|
||||
@@ -1345,7 +1345,7 @@ $("#open").click(function () {
|
||||
OpenDialog();
|
||||
return;
|
||||
}
|
||||
layer.confirm('<font style="color:black">' + language_str("whetherSave") + '</font>', function (index) {//confirm 是否保存当前文件�?
|
||||
layer.confirm(language_str("whetherSave"), function (index) {//confirm 是否保存当前文件�?
|
||||
if (typeof window.output === 'function') {
|
||||
window.output(OpenDialog);
|
||||
}
|
||||
@@ -1375,18 +1375,14 @@ $("#open").click(function () {
|
||||
}
|
||||
}
|
||||
function importAndOpen(j, fileName) {
|
||||
var tok = typeof window.soonGetAccessToken === 'function'
|
||||
? window.soonGetAccessToken()
|
||||
: (localStorage.getItem('soon_access') || '');
|
||||
if (!tok && typeof window.soonPutSoonSession === 'function') {
|
||||
if (typeof window.soonPutSoonSession === 'function') {
|
||||
var localKey = window.soonPutSoonSession(j, fileName || 'design.soon');
|
||||
if (localKey) openWithKey(localKey, j);
|
||||
return;
|
||||
if (!localKey) return;
|
||||
if (typeof window.soonScheduleCloudImport === 'function') {
|
||||
window.soonScheduleCloudImport(localKey, fileName || 'design.soon');
|
||||
}
|
||||
openWithKey(localKey, j);
|
||||
}
|
||||
if (!window.platformBridge || !window.platformBridge.importSoonFile) return;
|
||||
window.platformBridge.importSoonFile(fileName || 'design.soon', j).then(function(res) {
|
||||
if (res && res.fileKey) openWithKey(res.fileKey, j);
|
||||
}).catch(function () {});
|
||||
}
|
||||
if (file && file.text) {
|
||||
file.text().then(function(t) {
|
||||
@@ -1445,7 +1441,7 @@ $("#new").click(function () {
|
||||
else if (window.platformBridge) window.platformBridge.openFirstPage();
|
||||
return;
|
||||
}
|
||||
layer.confirm('<font style="color:black">' + language_str("whetherSave") + '</font>', function (index) {//confirm 是否保存当前文件�?
|
||||
layer.confirm(language_str("whetherSave"), function (index) {//confirm 是否保存当前文件�?
|
||||
if (typeof window.output === 'function') {
|
||||
window.output(function() { if (ipcRenderer) ipcRenderer.send('open-first-page'); else if (window.platformBridge) window.platformBridge.openFirstPage(); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user