spreadjs_zh.min.js 6.0 KB

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