lsc 2 days ago
parent
commit
36d3300e46
1 changed files with 33 additions and 1 deletions
  1. 33 1
      js/Desktop/DeskTop.js

+ 33 - 1
js/Desktop/DeskTop.js

@@ -11507,8 +11507,40 @@ U.MD.D.I.getContents2 = function (cid, s, task, t, uid, type, iframe) {
                     } 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;
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    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 兼容早期意外结构,作为 elements
+                        // fallback
                         iframe.contentWindow.h.app.updateScene({ elements: text });
                     }
                 } else if (type == '4') {