1 |
- const SpreadJsObj={createNewSpread:function(e){const t=new GC.Spread.Sheets.Workbook(e,{sheetCount:1});return t.options.tabStripVisible=!1,t.options.scrollbarMaxAlign=!0,t.options.cutCopyIndicatorVisible=!1,t.options.allowCopyPasteExcelStyle=!1,t.options.allowUserDragDrop=!1,t.getActiveSheet().setRowCount(3),t},protectedSheet:function(e){e.options.protectionOptions={allowSelectLockedCells:!0,allowSelectUnlockedCells:!0,allowResizeRows:!0,allowResizeColumns:!0},e.options.isProtected=!0},beginMassOperationSheet:function(e){e.suspendPaint(),e.suspendEvent()},endMassOperationSheet:function(e){e.resumeEvent(),e.resumePaint()},massOperationSheet:function(e,t){e.suspendPaint(),e.suspendEvent(),t(),e.resumeEvent(),e.resumePaint()},getObjPos:function(e){let t=e,n={x:e.offsetLeft,y:e.offsetTop};for(t=e.offsetParent;t;)n.x+=t.offsetLeft,n.y+=t.offsetTop,t=t.offsetParent;return n},getHitTest:function(e,t,n){var o=e.offset(),l=t.pageX-o.left,i=t.pageY-o.top;return n.hitTest(l,i)},getTargetSelection:function(e,t){return t.hitTestType===GC.Spread.Sheets.SheetArea.colHeader?e.getRange(-1,t.col,e.getRowCount(),1):t.hitTestType===GC.Spread.Sheets.SheetArea.rowHeader?e.getRange(t.row,-1,1,e.getColumnCount()):t.hitTestType===GC.Spread.Sheets.SheetArea.viewport?e.getRange(t.row,t.col,1,1):t.hitTestType===GC.Spread.Sheets.SheetArea.corner?e.getRange(-1,-1,e.getRowCount(),e.getColumnCount()):void 0},getCellInSelections:function(e,t,n){const o=e.length;let l;for(var i=0;i<o;i++)if((l=e[i]).contains(t,n))return l;return null},checkTargetInSelection:function(e,t){for(var n=e.length,o=0;o<n;o++)if(e[o].containsRange(t))return!0;return!1},safeRightClickSelection:function(e,t,n){const o=n.getActiveSheet(),l=o.getSelections(),i=this.getHitTest(e,t,o),r=this.getTargetSelection(o,i);return this.checkTargetInSelection(l,r)||o.setSelection(r.row,r.col,r.rowCount,r.colCount),i},addDeleteBind:function(e,t){e.commandManager().register("deleteEvent",function(){t(e.getActiveSheet())}),e.commandManager().setShortcutKey("null",GC.Spread.Commands.Key.del,!1,!1,!1,!1),e.commandManager().setShortcutKey("deleteEvent",GC.Spread.Commands.Key.del,!1,!1,!1,!1)},initSheetHeader:function(e){e.zh_setting&&this.massOperationSheet(e,function(){e.setColumnCount(e.zh_setting.cols.length);for(const t in e.zh_setting.cols){const n=e.zh_setting.cols[t];e.getCell(0,t,GC.Spread.Sheets.SheetArea.colHeader).text(n.title),e.setColumnWidth(t,n.width)}e.rowOutlines.direction(GC.Spread.Sheets.Outlines.OutlineDirection.backward),e.showRowOutline(!1),e.zh_setting.defaultRowHeight&&(e.defaults.rowHeight=e.zh_setting.defaultRowHeight,e.defaults.colHeaderRowHeight=e.zh_setting.defaultRowHeight)})},initSheet:function(e,t){e.zh_setting=t,this.initSheetHeader(e),e.extendCellType={}},reLoadSheetData:function(e){this.protectedSheet(e),this.massOperationSheet(e,function(){const t="tree"===e.zh_dataType?e.zh_tree.nodes:e.zh_data,n=t.length+e.zh_setting.emptyRows;e.setRowCount(n,GC.Spread.Sheets.SheetArea.viewport),e.getRange(t.length,-1,e.zh_setting.emptyRows,-1).locked("tree"===e.zh_dataType),t.forEach(function(t,n){e.zh_setting.cols.forEach(function(o,l){const i=e.getCell(n,l);""!==o.field&&t[o.field]?i.value(t[o.field]).locked(o.readOnly||!1).vAlign(o.vAlign).hAlign(o.hAlign):i.locked(o.readOnly||!1)})}),e.zh_setting.cols.forEach(function(t,n){t.cellType&&("tree"===t.cellType?(e.extendCellType.tree||(e.extendCellType.tree=SpreadJsExtendCellType.getTreeNodeCellType()),e.getRange(-1,n,-1,1).cellType(e.extendCellType.tree)):"tip"===t.cellType&&(e.extendCellType.tip||(e.extendCellType.tip=SpreadJsExtendCellType.getTipCellType()),e.getRange(-1,n,-1,1).cellType(e.extendCellType.tip)))})})},reLoadRowData:function(e,t,n){this.massOperationSheet(e,function(){const o="tree"===e.zh_dataType?e.zh_tree.nodes:e.zh_data;e.clear(t,-1,n,-1,GC.Spread.Sheets.SheetArea.viewport,GC.Spread.Sheets.StorageType.data);for(let l=t;l<t+n;l++){const t=o[l];t&&e.zh_setting.cols.forEach(function(n,o){const i=e.getCell(l,o);""!==n.field&&t[n.field]?i.value(t[n.field]).locked(n.readOnly||!1):i.locked(n.readOnly||!1)})}e.zh_setting.cols.forEach(function(o,l){o.cellType&&("tree"===o.cellType?(e.extendCellType.tree||(e.extendCellType.tree=SpreadJsExtendCellType.getTreeNodeCellType()),e.getRange(t,l,n,1).cellType(e.extendCellType.tree)):"tip"===o.cellType&&(e.extendCellType.tip||(e.extendCellType.tip=SpreadJsExtendCellType.getTipCellType()),e.getRange(t,l,n,1).cellType(e.extendCellType.tip)))})})},reLoadRowsData:function(e,t){this.massOperationSheet(e,function(){const n="tree"===e.zh_dataType?e.zh_tree.nodes:e.zh_data;for(const o of t){e.clear(o,-1,1,-1,GC.Spread.Sheets.SheetArea.viewport,GC.Spread.Sheets.StorageType.data);const t=n[o];e.zh_setting.cols.forEach(function(n,l){const i=e.getCell(o,l);""!==n.field&&t[n.field]?i.value(t[n.field]).locked(n.readOnly||!1):i.locked(n.readOnly||!1),n.cellType&&("tree"===n.cellType?(e.extendCellType.tree||(e.extendCellType.tree=SpreadJsExtendCellType.getTreeNodeCellType()),e.getRange(o,l,1,1).cellType(e.extendCellType.tree)):"tip"===n.cellType&&(e.extendCellType.tip||(e.extendCellType.tip=SpreadJsExtendCellType.getTipCellType()),e.getRange(o,l,1,1).cellType(e.extendCellType.tip)))})}})},loadSheetData:function(e,t,n){e.zh_dataType=t,"tree"===t?e.zh_tree=n:e.zh_data=n,this.reLoadSheetData(e)},getFilterCopyHTML:function(e){const t=e.getSelections()[0],n=[];n.push("<table>");for(let o=t.row,l=t.row+t.rowCount;o<l;o++){if(!e.getCell(o,-1).visible())continue;const l=[];l.push("<tr>");for(let n=t.col,i=t.col+t.colCount;n<i;n++){const t=e.getText(o,n);l.push("<td>"+t+"</td>")}l.push("</tr>"),n.push(l.join(""))}return n.push("</table>"),n.join("")},getFilterCopyText:function(e){const t=[],n=e.getSelections()[0];for(let o=n.row,l=n.row+n.rowCount;o<l;o++){if(!e.getCell(o,-1).visible())continue;const l=[];for(let t=n.col,i=n.col+n.colCount;t<i;t++){const n=e.getText(o,t);l.push(n)}t.push(l.join("\t"))}return t.join("\n")}};
|