|
|
@@ -229,6 +229,77 @@ var sheetCommonObj = {
|
|
|
sheet.setStyle(row, -1, setting.getStyle(data[row]));
|
|
|
}
|
|
|
},
|
|
|
+ showTreeData:function (sheet,setting,data) {
|
|
|
+ let ch = GC.Spread.Sheets.SheetArea.viewport;
|
|
|
+ let parentMap=_.groupBy(data, 'ParentID');
|
|
|
+ let visibleMap = {};
|
|
|
+ let styleRow=[];
|
|
|
+ let treeCol = setting.treeCol?setting.treeCol:0;
|
|
|
+ sheet.suspendPaint();
|
|
|
+ sheet.suspendEvent();
|
|
|
+ for (let col = 0; col < setting.header.length; col++) {
|
|
|
+ let hAlign = "left", vAlign = "center";
|
|
|
+ if (setting.header[col].hAlign) {
|
|
|
+ hAlign = setting.header[col].hAlign;
|
|
|
+ } else if (setting.header[col].dataType !== "String"){
|
|
|
+ hAlign = "right";
|
|
|
+ }
|
|
|
+ vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
|
|
|
+ sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
|
|
|
+ if (setting.header[col].formatter) {
|
|
|
+ sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ }
|
|
|
+ if(setting.header[col].cellType === "comboBox"){
|
|
|
+ this.setComboBox(-1,col,sheet,setting.header[col].options,setting.header[col].editorValueType,setting.header[col].editable,setting.header[col].maxDropDownItems);
|
|
|
+ }
|
|
|
+ for (let row = 0; row < data.length; row++) {
|
|
|
+ if(data[row].cellType === 'comboBox'){
|
|
|
+ let options = data[row].options ? data[row].options.split("@") : [];
|
|
|
+ this.setComboBox(row,col,sheet,options);
|
|
|
+ }else if(data[row].cellType === 'String'){//默认设置字符输入,避免出现输入10:01变成日期的情况
|
|
|
+ sheet.setFormatter(row, col,"@", GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ }
|
|
|
+ let val = data[row][setting.header[col].dataCode];
|
|
|
+ if(val&&setting.header[col].dataType === "Number"){
|
|
|
+ if(setting.header[col].hasOwnProperty('decimalField')){
|
|
|
+ let decimal = getDecimal(setting.header[col].decimalField);
|
|
|
+ val =scMathUtil.roundToString(val,decimal);
|
|
|
+ sheet.setFormatter(-1, col,getFormatter(decimal), GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ }else {
|
|
|
+ val =scMathUtil.roundToString(val,2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(val!=null && setting.header[col].cellType == "checkBox"){
|
|
|
+ this.setCheckBoxCell(row,col,sheet,val);
|
|
|
+ }
|
|
|
+ sheet.setValue(row, col, val, ch);
|
|
|
+ if(col==treeCol){
|
|
|
+ let treeType = sheetCommonObj.getTreeNodeCellType(data,row,parentMap,treeCol);
|
|
|
+ sheet.getCell(row, col).cellType(treeType);
|
|
|
+ visibleMap[data[row].ID] = treeType.collapsed;
|
|
|
+ this.setRowVisible(data,row,visibleMap,sheet);
|
|
|
+ }
|
|
|
+ if(data[row].bgColour) styleRow.push(row)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(let r of styleRow){
|
|
|
+ this.setRowStyle(r,sheet,data[r].bgColour);
|
|
|
+ }
|
|
|
+ this.lockCells(sheet,setting);
|
|
|
+ sheet.resumeEvent();
|
|
|
+ sheet.resumePaint();
|
|
|
+ },
|
|
|
+ setRowVisible:function (data,row,visibleMap,sheet) {
|
|
|
+ sheet.getRange(row , -1, 1, -1).visible(getVisible(data[row].ParentID));//显示或隐藏
|
|
|
+ function getVisible(ParentID) {
|
|
|
+ if(visibleMap[ParentID]) return false //如果父节点是缩起的,那就隐藏本身。
|
|
|
+ if(visibleMap[ParentID] == false){//如果父节点不是缩起的,要再往父节点找看
|
|
|
+ let pnode = _.find(data,{'ID':ParentID});
|
|
|
+ if(pnode) return getVisible(pnode.ParentID);//如果有父节点,递归调用
|
|
|
+ return true;//没有,返回显示
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
checkData: function (col, setting, value) {
|
|
|
let result = true;
|
|
|
let validator = setting.header[col].validator !== undefined ? setting.header[col].validator : null;
|
|
|
@@ -398,81 +469,7 @@ var sheetCommonObj = {
|
|
|
sheet.showRow(showRow, GC.Spread.Sheets.VerticalPosition.top);
|
|
|
|
|
|
},
|
|
|
- setSelectButton(row, col, sheet, header) {
|
|
|
- /* let getSelectButton = function (cellWidth=100) {
|
|
|
- function moreButton() {
|
|
|
-
|
|
|
- }
|
|
|
- moreButton.prototype = new GC.Spread.Sheets.CellTypes.Button();
|
|
|
- moreButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
|
|
|
- GC.Spread.Sheets.CellTypes.Button.prototype.paint.call(this, ctx, value, x, y, w, h, style, options);
|
|
|
- let buttonW = cellWidth/5;
|
|
|
- let endX = x+w-2;
|
|
|
- if(value){
|
|
|
- let textWidth = ctx.measureText(value).width;
|
|
|
- let spaceWidth = cellWidth - buttonW;
|
|
|
- let textEndX = x+2+textWidth;
|
|
|
- if(spaceWidth<textWidth){
|
|
|
- for(let i = value.length-1;i>1;i--){
|
|
|
- let newValue = value.substr(0,i);
|
|
|
- let newTestWidth = ctx.measureText(newValue).width;
|
|
|
- if(spaceWidth>newTestWidth){
|
|
|
- value = newValue;
|
|
|
- textEndX = x+2+newTestWidth;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ctx.fillText(value,textEndX,y+h-5);
|
|
|
- }
|
|
|
-
|
|
|
- //画三个点
|
|
|
- ctx.save();
|
|
|
- ctx.beginPath();
|
|
|
- ctx.arc(endX-buttonW/2,y+h/2,1,0,360,false);
|
|
|
- ctx.arc(endX-buttonW/2-4,y+h/2,1,0,360,false);
|
|
|
- ctx.arc(endX-buttonW/2+4,y+h/2,1,0,360,false);
|
|
|
- ctx.fillStyle="black";//填充颜色,默认是黑色
|
|
|
- ctx.fill();//画实心圆
|
|
|
- ctx.closePath();
|
|
|
- ctx.restore();
|
|
|
- };
|
|
|
-
|
|
|
- moreButton.prototype.processMouseLeave= function (hitinfo) {
|
|
|
- let newCell = new selectButton();
|
|
|
- hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, newCell, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
- hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(false);
|
|
|
- };
|
|
|
-
|
|
|
- function selectButton() {
|
|
|
- }
|
|
|
-
|
|
|
- selectButton.prototype = new GC.Spread.Sheets.CellTypes.Text();
|
|
|
-
|
|
|
- selectButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
|
|
|
- GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this,arguments);
|
|
|
- };
|
|
|
- selectButton.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
|
|
|
- return {
|
|
|
- x: x,
|
|
|
- y: y,
|
|
|
- row: context.row,
|
|
|
- col: context.col,
|
|
|
- cellStyle: cellStyle,
|
|
|
- cellRect: cellRect,
|
|
|
- sheetArea: context.sheetArea
|
|
|
- };
|
|
|
- };
|
|
|
- selectButton.prototype.processMouseDown = function (hitinfo){
|
|
|
- if(hitinfo.sheet.getCell(hitinfo.row,hitinfo.col).locked()!=true){
|
|
|
- let b1 = new moreButton();
|
|
|
- b1.marginLeft(cellWidth*4/5);
|
|
|
- hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, b1, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
- hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(true);
|
|
|
- }
|
|
|
- };
|
|
|
- return new selectButton();
|
|
|
- };*/
|
|
|
+ setSelectButton(row, col, sheet, header) {
|
|
|
sheet.setCellType(row, col, this.getSelectButton(header.headerWidth), GC.Spread.Sheets.SheetArea.viewport);
|
|
|
},
|
|
|
getSelectButton(cellWidth = 100) {
|
|
|
@@ -773,7 +770,7 @@ var sheetCommonObj = {
|
|
|
}
|
|
|
return new getTipsCombo();
|
|
|
},
|
|
|
- getTreeNodeCellType: function (datas, row, parentMap) {// 2018-09-26 不用spreadjs默认的树结构,自定义控件
|
|
|
+ getTreeNodeCellType: function (datas, row, parentMap,treeCol) {// 2018-09-26 不用spreadjs默认的树结构,自定义控件
|
|
|
var ns = GC.Spread.Sheets;
|
|
|
let rectW = 10;
|
|
|
let rectH = 10;
|
|
|
@@ -867,7 +864,8 @@ var sheetCommonObj = {
|
|
|
let parent = getParent(item.ParentID, datas);
|
|
|
if (!parent) return true;
|
|
|
let p_row = datas.indexOf(parent);
|
|
|
- let visible = !sheet.getCellType(p_row, 0).collapsed;
|
|
|
+ treeCol = treeCol?treeCol:0;
|
|
|
+ let visible = !sheet.getCellType(p_row, treeCol).collapsed;
|
|
|
if (visible == true) { //如果是显示的,则要再往父节点的父节点检查,只要有一个节点是隐藏的,则都是隐藏
|
|
|
return getVisible(parent);
|
|
|
} else {
|
|
|
@@ -883,7 +881,7 @@ var sheetCommonObj = {
|
|
|
return new TreeNodeCellType()
|
|
|
|
|
|
function getTreeLevel(item, data) {
|
|
|
- if (item.ParentID) {
|
|
|
+ if (item.ParentID && item.ParentID!=-1) {
|
|
|
let pitem = _.find(data, { 'ID': item.ParentID });
|
|
|
return getTreeLevel(pitem, data) + 1;
|
|
|
} else {
|