|
@@ -11495,53 +11495,60 @@ U.MD.D.I.getContents2 = function (cid, s, task, t, uid, type, iframe) {
|
|
|
iframe.contentWindow.editor.minder.importData('json', JSON.parse(xmlhttp.response)[0][0].text)
|
|
|
} else if (type == '3') {
|
|
|
let text = JSON.parse(JSON.parse(xmlhttp.response)[0][0].text)
|
|
|
+ // 如果是数组或含有 elements 并且 elements 是数组
|
|
|
+ let updateSceneData;
|
|
|
if ((Array.isArray(text)) || (text && Array.isArray(text.elements))) {
|
|
|
- // 如果是数组或含有 elements 并且 elements 是数组
|
|
|
if (Array.isArray(text)) {
|
|
|
// 兼容原有结构:仅为数组时
|
|
|
- iframe.contentWindow.h.app.updateScene({ elements: text });
|
|
|
+ updateSceneData = { elements: text };
|
|
|
} else {
|
|
|
// 有 elements 和可能的 files 字段时,直接传递整个对象
|
|
|
- iframe.contentWindow.h.app.updateScene(text);
|
|
|
+ updateSceneData = { ...text };
|
|
|
}
|
|
|
} else if (text && (text.elements || text.files)) {
|
|
|
- // 有 elements 和 files 字段的 json对象
|
|
|
- iframe.contentWindow.h.app.updateScene(text);
|
|
|
- let text = JSON.parse(JSON.parse(xmlhttp.response)[0][0].text);
|
|
|
-
|
|
|
- // 新增:转换files中dataURL为dataimg(如果是链接),files为json对象
|
|
|
- function convertFilesDataURLToDataImg(obj) {
|
|
|
- if (obj && obj.files && typeof obj.files === 'object' && !Array.isArray(obj.files)) {
|
|
|
- for (const key in obj.files) {
|
|
|
- if (obj.files.hasOwnProperty(key)) {
|
|
|
- const file = obj.files[key];
|
|
|
- if (
|
|
|
- file.dataURL &&
|
|
|
- typeof file.dataURL === "string" &&
|
|
|
- /^https?:\/\//i.test(file.dataURL)
|
|
|
- ) {
|
|
|
- // 这里只能做标记,实际应异步转换链接为dataimg
|
|
|
- // file.dataURL = await fetchImageAsDataURL(file.dataURL)
|
|
|
- // 暂时加上一个标志表示需要转换
|
|
|
- file.dataURL_isRemote = true;
|
|
|
- }
|
|
|
- }
|
|
|
+ updateSceneData = { ...text };
|
|
|
+ } else {
|
|
|
+ // fallback 兼容早期意外结构,作为 elements
|
|
|
+ updateSceneData = { elements: text };
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查 files 字段,若为 jsonObject 且含有 dataURL,将 dataURL 网络地址转为 base64
|
|
|
+ if (updateSceneData && updateSceneData.files && typeof updateSceneData.files === 'object' && !Array.isArray(updateSceneData.files)) {
|
|
|
+ const files = updateSceneData.files;
|
|
|
+ const fileKeys = Object.keys(files);
|
|
|
+ let promises = [];
|
|
|
+ let needConvert = false;
|
|
|
+ fileKeys.forEach(key => {
|
|
|
+ let file = files[key];
|
|
|
+ if (file && file.dataURL && typeof file.dataURL === 'string' && file.dataURL.startsWith('http')) {
|
|
|
+ // 是网络地址,需转换
|
|
|
+ needConvert = true;
|
|
|
+ let p = fetch(file.dataURL)
|
|
|
+ .then(res => res.blob())
|
|
|
+ .then(blob => {
|
|
|
+ return new Promise(resolve => {
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.onloadend = function () {
|
|
|
+ // data:[mime];base64,...
|
|
|
+ const base64 = reader.result;
|
|
|
+ file.dataURL = base64;
|
|
|
+ resolve();
|
|
|
+ };
|
|
|
+ reader.readAsDataURL(blob);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ promises.push(p);
|
|
|
}
|
|
|
+ });
|
|
|
+ if (needConvert && promises.length > 0) {
|
|
|
+ Promise.all(promises).then(() => {
|
|
|
+ iframe.contentWindow.h.app.updateScene(updateSceneData);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ iframe.contentWindow.h.app.updateScene(updateSceneData);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if (Array.isArray(text)) {
|
|
|
- // 仅为数组
|
|
|
- iframe.contentWindow.h.app.updateScene({ elements: text });
|
|
|
- } else if (text && (text.elements || text.files)) {
|
|
|
- // json对象结构,处理files字段
|
|
|
- convertFilesDataURLToDataImg(text);
|
|
|
- iframe.contentWindow.h.app.updateScene(text);
|
|
|
- } else if (text && Array.isArray(text.elements)) {
|
|
|
- iframe.contentWindow.h.app.updateScene(text);
|
|
|
} else {
|
|
|
- // fallback
|
|
|
- iframe.contentWindow.h.app.updateScene({ elements: text });
|
|
|
+ iframe.contentWindow.h.app.updateScene(updateSceneData);
|
|
|
}
|
|
|
} else if (type == '4') {
|
|
|
iframe.contentWindow.loadingXml(JSON.parse(xmlhttp.response)[0][0].text)
|
|
@@ -11563,7 +11570,6 @@ U.MD.D.I.getContents2 = function (cid, s, task, t, uid, type, iframe) {
|
|
|
xmlhttp.send();
|
|
|
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
U.MD.D.I.setContents = function (cid, s, task, t, uid, type, text, loading, span) {
|
|
|
var xmlhttp;
|