diff --git a/src/config.js b/src/config.js index 9e11d07..f4372c8 100644 --- a/src/config.js +++ b/src/config.js @@ -66,4 +66,5 @@ export default { showstatisticBarConfig:{}, //自定义计数栏 cellRightClickConfig:{}, //自定义单元格右键菜单 sheetRightClickConfig:{}, //自定义底部sheet页右击菜单 + imageUpdateMethodConfig:{}, //自定义图片同步方式 } \ No newline at end of file diff --git a/src/controllers/imageUpdateCtrl.js b/src/controllers/imageUpdateCtrl.js new file mode 100644 index 0000000..fc76264 --- /dev/null +++ b/src/controllers/imageUpdateCtrl.js @@ -0,0 +1,21 @@ +// 自定义图片的更新方法例如: customImageUpdate("POST", "http://127.0.0.1:8000/luckysheetimageprocess/", d) +function customImageUpdate(method, url, obj) { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest() || new ActiveXObject("Microsoft.XMLHTTP"); + xhr.open(method, url); + xhr.send(JSON.stringify(obj)); // 发送 POST/GET 数据 + xhr.onreadystatechange = function () { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + resolve(xhr.responseText); + } else { + reject("error"); + } + } + }; + }); +} + +export { + customImageUpdate +} \ No newline at end of file diff --git a/src/controllers/server.js b/src/controllers/server.js index f7cd526..f3edcf7 100644 --- a/src/controllers/server.js +++ b/src/controllers/server.js @@ -18,6 +18,8 @@ import { collaborativeEditBox } from './select' import locale from '../locale/locale'; import dayjs from "dayjs"; import json from '../global/json'; +import luckysheetConfigsetting from './luckysheetConfigsetting'; +import {customImageUpdate} from './imageUpdateCtrl'; const server = { gridKey: null, @@ -141,11 +143,31 @@ const server = { // d.s = params.s; } - let msg = pako.gzip(encodeURIComponent(JSON.stringify(d)), { to: "string" }); + // TODO 配置自定义方式同步图片 + const customImageUpdateMethodConfig = luckysheetConfigsetting.imageUpdateMethodConfig + if (JSON.stringify(customImageUpdateMethodConfig) !== "{}") { + if ("images" != d.k) { + let msg = pako.gzip(encodeURIComponent(JSON.stringify(d)), {to: "string"}); - if(_this.websocket!=null){ - _this.websocket.send(msg); - } + if (_this.websocket != null) { + _this.websocket.send(msg); + } + } else { + customImageUpdate(customImageUpdateMethodConfig.method, customImageUpdateMethodConfig.url, d) + .then((data) => { + console.log(data); + }) + .catch((err) => { + console.log(err); + }); + + } + } else { + let msg = pako.gzip(encodeURIComponent(JSON.stringify(d)), {to: "string"}); + if (_this.websocket != null) { + _this.websocket.send(msg); + } + } }, websocket: null, diff --git a/src/core.js b/src/core.js index 57c5a0f..0966ab8 100644 --- a/src/core.js +++ b/src/core.js @@ -140,6 +140,8 @@ luckysheet.create = function (setting) { luckysheetConfigsetting.initShowsheetbarConfig = false; + luckysheetConfigsetting.imageUpdateMethodConfig = extendsetting.imageUpdateMethodConfig; + if (Store.lang === 'zh') flatpickr.localize(Mandarin.zh); // Store the currently used plugins for monitoring asynchronous loading