浏览代码

Merge branch 'beta'

lsc 1 月之前
父节点
当前提交
685e3b5e3a
共有 8 个文件被更改,包括 423 次插入7 次删除
  1. 1 0
      admin.html
  2. 1 0
      ai.html
  3. 1 0
      iframe.html
  4. 1 0
      index.html
  5. 2 2
      js/Controls/Basic.js
  6. 0 0
      js/Controls/Basic.min.js
  7. 416 5
      js/Desktop/DeskTop.js
  8. 1 0
      liyuan.html

+ 1 - 0
admin.html

@@ -344,6 +344,7 @@
         <script src="./js/Text/Text.js" type="text/javascript"></script>
         <!--轮训服务-->
         <script src="./js/Office/Poll.js" type="text/javascript"></script>
+        <script src="./js/Common/aws-sdk-2.235.1.min.js" type="text/javascript"></script>
     </div>
 </body>
 

+ 1 - 0
ai.html

@@ -334,6 +334,7 @@
         <script src="./js/Office/Poll.js" type="text/javascript"></script>
 
 
+        <script src="./js/Common/aws-sdk-2.235.1.min.js" type="text/javascript"></script>
     </div>
 </body>
 

+ 1 - 0
iframe.html

@@ -344,6 +344,7 @@
         <script src="./js/Text/Text.js" type="text/javascript"></script>
         <!--轮训服务-->
         <script src="./js/Office/Poll.js" type="text/javascript"></script>
+        <script src="./js/Common/aws-sdk-2.235.1.min.js" type="text/javascript"></script>
     </div>
 </body>
 

+ 1 - 0
index.html

@@ -344,6 +344,7 @@
         <script src="./js/Text/Text.js" type="text/javascript"></script>
         <!--轮训服务-->
         <script src="./js/Office/Poll.js" type="text/javascript"></script>
+        <script src="./js/Common/aws-sdk-2.235.1.min.js" type="text/javascript"></script>
     </div>
 </body>
 

+ 2 - 2
js/Controls/Basic.js

@@ -1907,7 +1907,7 @@ U.UF.UI.form.prototype = {
                 _mousedown = _formattr.onmousedown;
                 _formattr.onresize = U.UF.C.apply(this, function () { //当窗体大小发生变化的处理
                     this.size(); //大小变化处理
-                    if (_resizefun) {
+                    if (_resizefun && typeof _resizefun == "function") {
                         _resizefun(); //大小变化回调
                     }
                 });
@@ -1965,7 +1965,7 @@ U.UF.UI.form.prototype = {
                 this.header = _headel; //设置中间的全局变量
             }
             //创建中间
-            _contentel = $$("div", { "style": { "cssText": "width: 100%; position: relative;" } });
+            _contentel = $$("div", { "style": { "cssText": "width: 100%; position: relative; overflow:hidden" } });
             //中间的内容
             _contentattr.usbody = "true";
             //窗体头部属性统一设置

文件差异内容过多而无法显示
+ 0 - 0
js/Controls/Basic.min.js


+ 416 - 5
js/Desktop/DeskTop.js

@@ -8984,7 +8984,11 @@ U.MD.D.I.openApplicationJie = function (str, cid, stage, task, tool) {
         _jie.onclick = async () => {
             let text = ''
             if (aTool == 1) {
-                text = JSON.stringify(_iframe.contentWindow.h.app.scene.elements)
+                // text = JSON.stringify(_iframe.contentWindow.h.app.scene.elements)
+                text = _iframe.contentWindow.h.app.scene.elements
+                let files = _iframe.contentWindow.h.app.files
+                U.MD.D.I.downloadFile2(_cid, _stage, _task, _tool, _userid, text, _loading, _lspan, files, _iframe, str)
+                return
             } else if (aTool == 6) {
                 text = _iframe.contentWindow.$("#U_MD_O_H_wordEditor")[0].innerHTML.escapeQuotes()
             } else if (aTool == 3) {
@@ -10465,7 +10469,64 @@ U.MD.D.I.getContent = function (cid, s, task, t, uid, type, iframe) {
                 if (type == '2') {
                     iframe.contentWindow.editor.minder.importData('json', JSON.parse(xmlhttp.response)[0][0].text)
                 } else if (type == '3') {
-                    iframe.contentWindow.h.app.updateScene({ elements: JSON.parse(JSON.parse(xmlhttp.response)[0][0].text) })
+                    // iframe.contentWindow.h.app.updateScene({ elements: JSON.parse(JSON.parse(xmlhttp.response)[0][0].text) })
+                    let text = JSON.parse(JSON.parse(xmlhttp.response)[0][0].text)
+                    // 如果是数组或含有 elements 并且 elements 是数组
+                    let updateSceneData;
+                    if ((Array.isArray(text)) || (text && Array.isArray(text.elements))) {
+                        if (Array.isArray(text)) {
+                            // 兼容原有结构:仅为数组时
+                            updateSceneData = { elements: text };
+                        } else {
+                            // 有 elements 和可能的 files 字段时,直接传递整个对象
+                            updateSceneData = { ...text };
+                        }
+                    } else if (text && (text.elements || text.files)) {
+                        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);
+                                iframe.contentWindow.h.app.files = { ...iframe.contentWindow.h.app.files, ...updateSceneData.files };
+                            });
+                        } else {
+                            iframe.contentWindow.h.app.updateScene(updateSceneData);
+                        }
+                    } else {
+                        iframe.contentWindow.h.app.updateScene(updateSceneData);
+                    }
                 }
             } else {
                 U.MD.D.I.getContents2(cid, s, task, t, uid, type, iframe)
@@ -11416,9 +11477,11 @@ U.MD.D.I.openApplicationYu = function (str, cid, stage, task, tool) {
         }
         _jie.onclick = async () => {
             let text = ''
+            let files = ''
             let type = '2'
             if (aTool == 1) {
-                text = JSON.stringify(_iframe.contentWindow.h.app.scene.elements)
+                text = _iframe.contentWindow.h.app.scene.elements
+                files = _iframe.contentWindow.h.app.files
                 type = '3'
             } else if (aTool == 6) {
                 text = _iframe.contentWindow.$("#U_MD_O_H_wordEditor")[0].innerHTML.escapeQuotes()
@@ -11435,7 +11498,11 @@ U.MD.D.I.openApplicationYu = function (str, cid, stage, task, tool) {
             }
             _loading.style.display = 'flex'
 
-            U.MD.D.I.setContents(_cid, _stage, _task, _tool, _userid, type, text, _loading, _lspan)
+            if(aTool == 1){
+                U.MD.D.I.downloadFile(_cid, _stage, _task, _tool, _userid, type, text, _loading, _lspan, files)
+            }else {
+                U.MD.D.I.setContents(_cid, _stage, _task, _tool, _userid, type, text, _loading, _lspan)
+            }
         }
     }
 
@@ -11488,7 +11555,63 @@ U.MD.D.I.getContents2 = function (cid, s, task, t, uid, type, iframe) {
                 if (type == '2') {
                     iframe.contentWindow.editor.minder.importData('json', JSON.parse(xmlhttp.response)[0][0].text)
                 } else if (type == '3') {
-                    iframe.contentWindow.h.app.updateScene({ elements: JSON.parse(JSON.parse(xmlhttp.response)[0][0].text) })
+                    let text = JSON.parse(JSON.parse(xmlhttp.response)[0][0].text)
+                    // 如果是数组或含有 elements 并且 elements 是数组
+                    let updateSceneData;
+                    if ((Array.isArray(text)) || (text && Array.isArray(text.elements))) {
+                        if (Array.isArray(text)) {
+                            // 兼容原有结构:仅为数组时
+                            updateSceneData = { elements: text };
+                        } else {
+                            // 有 elements 和可能的 files 字段时,直接传递整个对象
+                            updateSceneData = { ...text };
+                        }
+                    } else if (text && (text.elements || text.files)) {
+                        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);
+                                iframe.contentWindow.h.app.files = { ...iframe.contentWindow.h.app.files, ...updateSceneData.files };
+                            });
+                        } else {
+                            iframe.contentWindow.h.app.updateScene(updateSceneData);
+                        }
+                    } else {
+                        iframe.contentWindow.h.app.updateScene(updateSceneData);
+                    }
                 } else if (type == '4') {
                     iframe.contentWindow.loadingXml(JSON.parse(xmlhttp.response)[0][0].text)
                 } else if (type == '5') {
@@ -11543,6 +11666,294 @@ U.MD.D.I.setContents = function (cid, s, task, t, uid, type, text, loading, span
     // 设置请求体,使用url-encoded格式的数据
 }
 
+U.MD.D.I.downloadFile = function (cid, s, task, t, uid, type, text, loading, span, files) {
+    // 遍历 files,上传后只把 dataURL 变成链接,其它结构不变
+   let _fileArray = Object.keys(files);
+    if (!_fileArray.length) {
+        let text_str = JSON.stringify({
+            elements: text,
+            files: []
+        });
+        U.MD.D.I.setContents(cid, s, task, t, uid, type, text_str, loading, span);
+        return;
+    }
+    var credentials = {
+        accessKeyId: "AKIATLPEDU37QV5CHLMH",
+        secretAccessKey: "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",
+    };
+    window.AWS.config.update(credentials);
+    window.AWS.config.region = "cn-northwest-1";
+    var bucket = new window.AWS.S3({
+        params: { Bucket: "ccrb" }
+    });
+
+    let uploadedCount = 0;
+    let total = _fileArray.length;
+    _fileArray.forEach(function (key, idx) {
+        let fileObj = files[key];
+        if (!fileObj || !fileObj.dataURL) {
+            // 没有内容就直接加计数
+            uploadedCount++;
+            if (uploadedCount === total) finalizeUpload();
+            return;
+        }
+        // 如果 dataURL 已经是链接(http, https, //, oss, cloud, cocorobo)就不上传
+        if (
+            typeof fileObj.dataURL === "string" &&
+            (
+                /^https?:\/\//.test(fileObj.dataURL) ||
+                /^\/\//.test(fileObj.dataURL) ||
+                fileObj.dataURL.startsWith('oss://') ||
+                fileObj.dataURL.startsWith('cloud://') ||
+                fileObj.dataURL.indexOf('.cocorobo.cn/') > -1
+            )
+        ) {
+            // 已经是链接,不上传,直接计数
+            uploadedCount++;
+            if (uploadedCount === total) finalizeUpload();
+            return;
+        }
+        // 是 base64 字符串转 File
+        if (typeof fileObj.dataURL === "string") {
+            let filename = fileObj.name || ('file_' + key);
+            fileObj.dataURL = dataURLtoFile_shishi(fileObj.dataURL, filename);
+        }
+        let file = fileObj.dataURL;
+        if (file) {
+            // fileObj 结构类似:
+            // {
+            //   name: "file_3344aa4c0fa552dc01cb2fe5edb6e4eb3aed9e39",
+            //   size: 12034,
+            //   type: "image/jpeg",
+            //   webkitRelativePath: "",
+            //   dataURL: File对象
+            // }
+            let ext = (fileObj.name && fileObj.name.lastIndexOf('.') !== -1)
+                ? fileObj.name.substring(fileObj.name.lastIndexOf('.') + 1)
+                : (file.type ? file.type.split('/')[1] : 'png');
+            let basename = (fileObj.name && fileObj.name.lastIndexOf('.') !== -1)
+                ? fileObj.name.substring(0, fileObj.name.lastIndexOf('.'))
+                : (fileObj.name || ('file_' + key));
+            var params = {
+                Key: basename + '_' + new Date().getTime() + "." + ext,
+                ContentType: fileObj.type || file.type || 'application/octet-stream',
+                Body: file,
+                "Access-Control-Allow-Credentials": "*",
+                ACL: "public-read",
+            };
+            var options = {
+                partSize: 2048 * 1024 * 1024,
+                queueSize: 2,
+                leavePartsOnError: true,
+            };
+            bucket.upload(params, options)
+                .on("httpUploadProgress", function (evt) {
+                    // 进度处理
+                })
+                .send(function (err, data) {
+                    if (data) {
+                        // 只将 dataURL 字段替换为链接,其它原样不动
+                        files[key].dataURL = data.Location;
+                    }
+                    // 上传出错仍然整体结构
+                    uploadedCount++;
+                    if (uploadedCount === total) finalizeUpload();
+                });
+        } else {
+            uploadedCount++;
+            if (uploadedCount === total) finalizeUpload();
+        }
+    });
+
+    function finalizeUpload() {
+        // 最终打包时,files结构不变,只是dataURL变为链接
+        // let fileList = _fileArray.map(key => files[key]);
+        let text_str = JSON.stringify({
+            elements: text,
+            files: files
+        });
+        U.MD.D.I.setContents(cid, s, task, t, uid, type, text_str, loading, span);
+    } 
+}
+
+U.MD.D.I.downloadFile2 = function (cid, stage, task, t, uid, text, loading, span, files, _iframe, str) {
+    // 优化:常量抽离、合并相同代码、结构简化
+    const BUCKET = "ccrb";
+    const REGION = "cn-northwest-1";
+    const ACCESS_KEY_ID = "AKIATLPEDU37QV5CHLMH";
+    const SECRET_ACCESS_KEY = "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";
+
+    function injectScreenshotScript(text_str) {
+        // 注入屏幕截图脚本到iframe
+        loading.style.display = 'flex';
+        const doc = _iframe.contentWindow.document;
+        var s = doc.createElement("script");
+        s.type = "text/javascript";
+        // 优化脚本内容拼接
+        s.innerHTML = `
+            var _js = document.createElement("script");
+            _js.type="text/javascript";
+            _js.charset="UTF-8";
+            _js.src="https://cloud.cocorobo.cn/js/Common/html2canvas.min.js";
+            _js.onload = function(){
+                var imgs = document.getElementsByTagName("img");
+                for(var i = 0; i < imgs.length; i++) { imgs[i].crossOrigin = "anonymous"; }
+                html2canvas(document.body, {
+                    allowTaint: true,
+                    useCORS: true,
+                    height: document.body.scrollHeight,
+                    windowHeight: document.body.scrollHeight
+                }).then(canvas => {
+                    var base64Url = canvas.toDataURL("image/png");
+                    var file = dataURLtoFile_shishi(base64Url, "截图");
+                    beforeUpload_shishi(
+                        file,
+                        '${uid}',
+                        '${cid}',
+                        '${stage}',
+                        '${task}',
+                        '${t}',
+                        '${str}_loadLi_Jie${cid}${stage}${task}${t}${uid}',
+                        '1',
+                        \`${text_str}\`
+                    );
+                });
+            };
+            document.head.appendChild(_js);
+        `;
+        doc.head.appendChild(s);
+    }
+
+    let _fileArray = Object.keys(files);
+
+    if (!_fileArray.length) {
+        const text_str = JSON.stringify({ elements: text, files: [] });
+        console.log(loading);
+        injectScreenshotScript(text_str);
+        return;
+    }
+
+    // AWS 配置初始化(只做一次)
+    if (!window.AWS?.S3?.__ccrbInitialized) {
+        window.AWS.config.update({
+            accessKeyId: ACCESS_KEY_ID,
+            secretAccessKey: SECRET_ACCESS_KEY
+        });
+        window.AWS.config.region = REGION;
+        window.AWS.S3.__ccrbInitialized = true;
+    }
+
+    const bucket = new window.AWS.S3({ params: { Bucket: BUCKET } });
+
+    let uploadedCount = 0;
+    const total = _fileArray.length;
+
+    function isFileUrl(url) {
+        return typeof url === "string" && (
+            /^https?:\/\//.test(url) ||
+            /^\/\//.test(url) ||
+            url.startsWith('oss://') ||
+            url.startsWith('cloud://') ||
+            url.indexOf('.cocorobo.cn/') > -1
+        );
+    }
+
+    function finalizeUpload() {
+        // 优化:只注入脚本,不重复提交
+        const text_str = JSON.stringify({ elements: text, files });
+        console.log(loading);
+        injectScreenshotScript(text_str);
+    }
+
+    _fileArray.forEach(function (key) {
+        const fileObj = files[key];
+        if (!fileObj || !fileObj.dataURL) {
+            uploadedCount++;
+            if (uploadedCount === total) finalizeUpload();
+            return;
+        }
+        if (isFileUrl(fileObj.dataURL)) {
+            uploadedCount++;
+            if (uploadedCount === total) finalizeUpload();
+            return;
+        }
+        // base64字符串转 File
+        if (typeof fileObj.dataURL === "string") {
+            const filename = fileObj.name || ('file_' + key);
+            fileObj.dataURL = dataURLtoFile_shishi(fileObj.dataURL, filename);
+        }
+        const file = fileObj.dataURL;
+        if (!file) {
+            uploadedCount++;
+            if (uploadedCount === total) finalizeUpload();
+            return;
+        }
+
+        const ext = (fileObj.name && fileObj.name.lastIndexOf('.') !== -1)
+            ? fileObj.name.substring(fileObj.name.lastIndexOf('.') + 1)
+            : (file.type ? file.type.split('/')[1] : 'png');
+        const basename = (fileObj.name && fileObj.name.lastIndexOf('.') !== -1)
+            ? fileObj.name.substring(0, fileObj.name.lastIndexOf('.'))
+            : (fileObj.name || ('file_' + key));
+        const params = {
+            Key: `${basename}_${Date.now()}.${ext}`,
+            ContentType: fileObj.type || file.type || 'application/octet-stream',
+            Body: file,
+            "Access-Control-Allow-Credentials": "*",
+            ACL: "public-read"
+        };
+        const options = {
+            partSize: 2048 * 1024 * 1024,
+            queueSize: 2,
+            leavePartsOnError: true
+        };
+        bucket.upload(params, options)
+            .on("httpUploadProgress", function (evt) {
+                // 进度处理可自定义
+            })
+            .send(function (err, data) {
+                if (data) {
+                    files[key].dataURL = data.Location;
+                }
+                uploadedCount++;
+                if (uploadedCount === total) finalizeUpload();
+            });
+    });
+}
+
+
+function dataURLtoFile_shishi(dataurl, filename) {
+    try {
+        if (typeof dataurl !== "string" || dataurl.indexOf(',') === -1) {
+            throw new Error("Invalid dataurl");
+        }
+        let arr = dataurl.split(","),
+            mimeMatch = arr[0].match(/:(.*?);/);
+        if (!mimeMatch) {
+            throw new Error("Mime type not found in dataurl");
+        }
+        let mime = mimeMatch[1];
+        let bstr = atob(arr[1]);
+        let n = bstr.length;
+        let u8arr = new Uint8Array(n);
+        for (let i = 0; i < n; i++) {
+            u8arr[i] = bstr.charCodeAt(i);
+        }
+        // Check for File constructor compatibility
+        if (typeof File === "function") {
+            return new File([u8arr], filename, { type: mime });
+        } else {
+            // fallback for very old browsers
+            let blob = new Blob([u8arr], { type: mime });
+            blob.name = filename;
+            return blob;
+        }
+    } catch(e) {
+        console.error("dataURLtoFile_shishi error:", e, dataurl, filename);
+        // 返回null,调用方自行判断
+        return null;
+    }
+}
 
 U.MD.D.I.openApplicationUpload = function (str, cid, stage, task, tool) {
     var _taskbar, //_taskbar 作为任务栏显示的元素,包含图标和名字

+ 1 - 0
liyuan.html

@@ -344,6 +344,7 @@
         <script src="./js/Text/Text.js" type="text/javascript"></script>
         <!--轮训服务-->
         <script src="./js/Office/Poll.js" type="text/javascript"></script>
+        <script src="./js/Common/aws-sdk-2.235.1.min.js" type="text/javascript"></script>
     </div>
 </body>
 

部分文件因为文件数量过多而无法显示