|
@@ -10,6 +10,7 @@
|
|
|
*/
|
|
|
|
|
|
const NewMergePeg = function (setting) {
|
|
|
+ let siHandle;
|
|
|
const spread = SpreadJsObj.createNewSpread($('#mp-spread')[0]);
|
|
|
const sheet = spread.getActiveSheet();
|
|
|
const spreadSetting = {
|
|
@@ -115,13 +116,15 @@ const NewMergePeg = function (setting) {
|
|
|
spreadObj.mergePeg(row);
|
|
|
},
|
|
|
editEnded: function (e, info) {
|
|
|
- if (info.col === spCol || info.col === epCol) {
|
|
|
- if (info.editingText.length > 10) {
|
|
|
- info.sheet.setText(info.row, info.col, info.editingText.substring(0, 10));
|
|
|
- }
|
|
|
- } else if (info.col === posCol) {
|
|
|
- if (info.editingText.length > 50) {
|
|
|
- info.sheet.setText(info.row, info.col, info.editingText.substring(0, 50));
|
|
|
+ if (info.editingText) {
|
|
|
+ if (info.col === spCol || info.col === epCol) {
|
|
|
+ if (info.editingText.length > 10) {
|
|
|
+ info.sheet.setText(info.row, info.col, info.editingText.substring(0, 10));
|
|
|
+ }
|
|
|
+ } else if (info.col === posCol) {
|
|
|
+ if (info.editingText.length > 50) {
|
|
|
+ info.sheet.setText(info.row, info.col, info.editingText.substring(0, 50));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
spreadObj.mergePeg(info.row);
|
|
@@ -138,13 +141,52 @@ const NewMergePeg = function (setting) {
|
|
|
rows.push(iRow);
|
|
|
}
|
|
|
spreadObj.mergePeg(rows);
|
|
|
- }
|
|
|
+ },
|
|
|
+ checkEmptyRow: function () {
|
|
|
+ let nonEmptyRow = -1, count = sheet.getRowCount();
|
|
|
+ for (let iRow = count - 1; iRow >= 0; iRow--) {
|
|
|
+ const sp = sheet.getText(iRow, spCol);
|
|
|
+ const ep = sheet.getText(iRow, epCol);
|
|
|
+ const p = sheet.getText(iRow, posCol);
|
|
|
+ if (sp !== '' || ep !== '' || p !== '') {
|
|
|
+ nonEmptyRow = iRow;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (nonEmptyRow >= 0 && count - nonEmptyRow <= 3) {
|
|
|
+ sheet.addRows(nonEmptyRow + 1, 4 + nonEmptyRow - count);
|
|
|
+ }
|
|
|
+ },
|
|
|
};
|
|
|
spread.bind(spreadNS.Events.EditStarting, spreadObj.editStarting);
|
|
|
spread.bind(spreadNS.Events.ClipboardPasted, spreadObj.clipboardPasted);
|
|
|
spread.bind(spreadNS.Events.EditEnded, spreadObj.editEnded);
|
|
|
SpreadJsObj.addDeleteBind(spread, spreadObj.deletePress);
|
|
|
SpreadJsObj.addCutEvents(spread, spreadObj.cut);
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#mp-spread',
|
|
|
+ build: function ($trigger, e) {
|
|
|
+ const target = SpreadJsObj.safeRightClickSelection($trigger, e, spread);
|
|
|
+ return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
|
|
|
+ },
|
|
|
+ items: {
|
|
|
+ 'create': {
|
|
|
+ name: '新增行',
|
|
|
+ icon: 'fa-sign-in',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ sheet.addRows(sheet.getRowCount(), 1);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'delete': {
|
|
|
+ name: '删除行',
|
|
|
+ icon: 'fa-remove',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ sheet.deleteRows(sel.row, sel.rowCount);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
// 勾选位置
|
|
|
$('#mp-with-pos').click(() => {spreadObj.mergePeg();});
|
|
@@ -171,11 +213,13 @@ const NewMergePeg = function (setting) {
|
|
|
if (setting.callback) {
|
|
|
setting.callback(spreadObj.getPegs());
|
|
|
}
|
|
|
+ clearInterval(siHandle);
|
|
|
$('#merge-peg').modal('hide');
|
|
|
});
|
|
|
|
|
|
const showModal = function () {
|
|
|
$('#merge-peg').modal('show');
|
|
|
+ siHandle = setInterval(spreadObj.checkEmptyRow, 500);
|
|
|
};
|
|
|
return {show: showModal};
|
|
|
};
|