|
@@ -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
|
|
|
+ files = _iframe.contentWindow.h.app.files
|
|
|
+ U.MD.D.I.downloadFile2(_cid, _stage, _task, _tool, _userid, type, 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)
|
|
@@ -11607,7 +11668,7 @@ U.MD.D.I.setContents = function (cid, s, task, t, uid, type, text, loading, span
|
|
|
|
|
|
U.MD.D.I.downloadFile = function (cid, s, task, t, uid, type, text, loading, span, files) {
|
|
|
// 遍历 files,上传后只把 dataURL 变成链接,其它结构不变
|
|
|
- let _fileArray = Object.keys(files);
|
|
|
+ let _fileArray = Object.keys(files);
|
|
|
if (!_fileArray.length) {
|
|
|
let text_str = JSON.stringify({
|
|
|
elements: text,
|
|
@@ -11712,9 +11773,155 @@ U.MD.D.I.downloadFile = function (cid, s, task, t, uid, type, text, loading, spa
|
|
|
files: files
|
|
|
});
|
|
|
U.MD.D.I.setContents(cid, s, task, t, uid, type, text_str, loading, span);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+U.MD.D.I.downloadFile2 = function (cid, s, task, t, uid, type, text, loading, span, files, _iframe, str) {
|
|
|
+ // 优化:常量抽离、合并相同代码、结构简化
|
|
|
+ const BUCKET = "ccrb";
|
|
|
+ const REGION = "cn-northwest-1";
|
|
|
+ const ACCESS_KEY_ID = "AKIATLPEDU37QV5CHLMH";
|
|
|
+ const SECRET_ACCESS_KEY = "Q2SQw37HfolS7yeaR1Ndpy9Jl4E2YZKUuuy2muZR";
|
|
|
+
|
|
|
+ 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}',
|
|
|
+ '${s}',
|
|
|
+ '${task}',
|
|
|
+ '${t}',
|
|
|
+ '${str}_loadLi_Jie${cid}${s}${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) {
|