Browse Source

添加自定义图片同步方法的功能

master
LiuQiao 5 years ago
parent
commit
5b00ea2cce
  1. 1
      src/config.js
  2. 21
      src/controllers/imageUpdateCtrl.js
  3. 30
      src/controllers/server.js
  4. 2
      src/core.js

1
src/config.js

@ -66,4 +66,5 @@ export default {
showstatisticBarConfig:{}, //自定义计数栏 showstatisticBarConfig:{}, //自定义计数栏
cellRightClickConfig:{}, //自定义单元格右键菜单 cellRightClickConfig:{}, //自定义单元格右键菜单
sheetRightClickConfig:{}, //自定义底部sheet页右击菜单 sheetRightClickConfig:{}, //自定义底部sheet页右击菜单
imageUpdateMethodConfig:{}, //自定义图片同步方式
} }

21
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
}

30
src/controllers/server.js

@ -18,6 +18,8 @@ import { collaborativeEditBox } from './select'
import locale from '../locale/locale'; import locale from '../locale/locale';
import dayjs from "dayjs"; import dayjs from "dayjs";
import json from '../global/json'; import json from '../global/json';
import luckysheetConfigsetting from './luckysheetConfigsetting';
import {customImageUpdate} from './imageUpdateCtrl';
const server = { const server = {
gridKey: null, gridKey: null,
@ -141,11 +143,31 @@ const server = {
// d.s = params.s; // 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){ if (_this.websocket != null) {
_this.websocket.send(msg); _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, websocket: null,

2
src/core.js

@ -140,6 +140,8 @@ luckysheet.create = function (setting) {
luckysheetConfigsetting.initShowsheetbarConfig = false; luckysheetConfigsetting.initShowsheetbarConfig = false;
luckysheetConfigsetting.imageUpdateMethodConfig = extendsetting.imageUpdateMethodConfig;
if (Store.lang === 'zh') flatpickr.localize(Mandarin.zh); if (Store.lang === 'zh') flatpickr.localize(Mandarin.zh);
// Store the currently used plugins for monitoring asynchronous loading // Store the currently used plugins for monitoring asynchronous loading

Loading…
Cancel
Save