Explorar el Código

列设置,自动换行,悬浮提示

MaiXinRong hace 7 años
padre
commit
5c707bdf41

+ 90 - 1
public/web/sheet/sheet_data_helper.js

@@ -30,16 +30,36 @@ var __settingTemp = {
 };
 
 var SheetDataHelper = {
+    getObjPos: function (obj) {
+        let target = obj;
+        let pos = {x: obj.offsetLeft, y: obj.offsetTop};
+
+        target = obj.offsetParent;
+        while (target) {
+            pos.x += target.offsetLeft;
+            pos.y += target.offsetTop;
+            target = target.offsetParent;
+        }
+        return pos;
+    },
+    initSetting: function (obj, setting) {
+        setting.pos = this.getObjPos(obj);
+    },
     createNewSpread: function (obj) {
         var spread = new GC.Spread.Sheets.Workbook(obj, {sheetCount: 1});
         spread.options.tabStripVisible = false;
         spread.options.scrollbarMaxAlign = true;
         spread.options.cutCopyIndicatorVisible = false;
         spread.options.allowCopyPasteExcelStyle = false;
+        spread.options.allowUserDragDrop = false;
         spread.getActiveSheet().setRowCount(3);
         return spread;
     },
     loadSheetHeader: function (setting, sheet) {
+        if (setting.frozenCols) {
+            sheet.frozenColumnCount(setting.frozenCols);
+        }
+        sheet.setColumnCount(setting.cols.length);
         sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader);
         if (setting.headRowHeight) {
             setting.headRowHeight.forEach(function (rowHeight, index) {
@@ -82,12 +102,53 @@ var SheetDataHelper = {
         style.font = setting.data.font;
         style.hAlign = setting.data.hAlign;
         style.vAlign = setting.data.vAlign;
-        //style.wordWrap = setting.data.wordWrap;
+        style.wordWrap = setting.data.wordWrap;
         return style;
     },
     loadSheetData: function (setting, sheet, datas) {
         SheetDataHelper.protectdSheet(sheet);
 
+        let TipCellType = function () {};
+        TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
+        TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
+            return {
+                x: x,
+                y: y,
+                row: context.row,
+                col: context.col,
+                cellStyle: cellStyle,
+                cellRect: cellRect,
+                sheet: context.sheet,
+                sheetArea: context.sheetArea
+            };
+        };
+        TipCellType.prototype.processMouseEnter = function (hitinfo) {
+            let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
+            if (setting.pos && text && text !== '') {
+                if (!this._toolTipElement) {
+                    var div = document.createElement("div");
+                    $(div).css("position", "absolute")
+                        .css("border", "1px #C0C0C0 solid")
+                        .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
+                        .css("font", "9pt Arial")
+                        .css("background", "white")
+                        .css("padding", 5);
+
+                    this._toolTipElement = div;
+                }
+                $(this._toolTipElement).text(text).css("top", setting.pos.y + hitinfo.y + 15).css("left", setting.pos.x + hitinfo.x + 15);
+                $(this._toolTipElement).hide();
+                document.body.insertBefore(this._toolTipElement, null);
+                $(this._toolTipElement).show("fast");
+            }
+        };
+        TipCellType.prototype.processMouseLeave = function (hininfo) {
+            if (this._toolTipElement) {
+                document.body.removeChild(this._toolTipElement);
+                this._toolTipElement = null;
+            }
+        }
+
         sheet.suspendPaint();
         sheet.suspendEvent();
 
@@ -98,9 +159,37 @@ var SheetDataHelper = {
         sheet.setRowCount(datas.length + setting.emptyRows, GC.Spread.Sheets.SheetArea.viewport);
         setting.cols.forEach(function (colSetting, iCol) {       
             sheet.setStyle(-1, iCol, SheetDataHelper.getSheetCellStyle(colSetting));
+            if (colSetting.showHint) {
+                sheet.getRange(-1, iCol, -1, 1).cellType(new TipCellType());
+            }
             datas.forEach(function (data, iRow) {
                 var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
+                var getFieldText2 = function () {
+                    var fields = colSetting.data.field.split('.'), iField, value = data;
+                    for (iField = 0; iField < fields.length; iField++) {
+                        if (value[fields[iField]]) {
+                            value = value[fields[iField]];
+                        } else {
+                            return '';
+                        }
+                    }
+                    return value;
+                };
                 cell.value(data[colSetting.data.field]);
+                if (colSetting.data.getText) {
+                    cell.value(colSetting.data.getText(data));
+                } else {
+                    cell.value(getFieldText2());
+                }
+                if (colSetting.readOnly) {
+                    if (Object.prototype.toString.apply(colSetting.readOnly) === "[object Function]") {
+                        cell.locked(colSetting.readOnly(node));
+                    } else {
+                        cell.locked(true);
+                    }
+                } else {
+                    cell.locked(false);
+                }
             });
         });
 

+ 4 - 0
public/web/tree_sheet/tree_sheet_controller.js

@@ -118,6 +118,9 @@ var TREE_SHEET_CONTROLLER = {
         }
 
         controller.prototype.setTreeSelected = function (node) {
+            if (this.event.beforeTreeSelectedChange) {
+                this.event.beforeTreeSelectedChange(this.tree.selected);
+            }
             this.tree.selected = node;
             if (this.event.refreshBaseActn) {
                 this.event.refreshBaseActn(this.tree);
@@ -135,6 +138,7 @@ var TREE_SHEET_CONTROLLER = {
     },
     eventName: {
         refreshBaseActn: 'refreshBaseActn',
+        beforeTreeSelectedChange: 'beforeTreeSelectedChange',
         treeSelectedChanged: 'treeSelectedChanged',
         cellDoubleClick: 'cellDoubleClick'
     }

+ 90 - 1
public/web/tree_sheet/tree_sheet_helper.js

@@ -3,6 +3,26 @@
  */
 
 var TREE_SHEET_HELPER = {
+    getObjPos: function (obj) {
+        let target = obj;
+        let pos = {x: obj.offsetLeft, y: obj.offsetTop};
+
+        target = obj.offsetParent;
+        while (target) {
+            pos.x += target.offsetLeft;
+            pos.y += target.offsetTop;
+            target = target.offsetParent;
+        }
+        return pos;
+    },
+    /**
+     * 初始化setting,需要提示单元格text时,必须先初始化setting
+     * @param obj
+     * @param setting
+     */
+    initSetting: function (obj, setting) {
+        setting.pos = this.getObjPos(obj);
+    },
     createNewSpread: function (obj) {
         var spread = new GC.Spread.Sheets.Workbook(obj, {sheetCount: 1});
         spread.options.tabStripVisible = false;
@@ -21,9 +41,15 @@ var TREE_SHEET_HELPER = {
         style.hAlign = setting.data.hAlign;
         style.vAlign = setting.data.vAlign;
         style.wordWrap = setting.data.wordWrap;
+        if (setting.data.formatter) {
+            style.formatter = setting.data.formatter;
+        }
         return style;
     },
     loadSheetHeader: function (setting, sheet) {
+        if (setting.frozenCols) {
+            sheet.frozenColumnCount(setting.frozenCols);
+        }
         sheet.setColumnCount(setting.cols.length);
         sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader);
         setting.headRowHeight.forEach(function (rowHeight, index) {
@@ -112,7 +138,17 @@ var TREE_SHEET_HELPER = {
                 if (colSetting.data.cellType) {
                     cell.cellType(colSetting.data.cellType);
                 }
+                if (colSetting.readOnly) {
+                    if (Object.prototype.toString.apply(colSetting.readOnly) === "[object Function]") {
+                        cell.locked(colSetting.readOnly(node));
+                    } else {
+                        cell.locked(true);
+                    }
+                } else {
+                    cell.locked(false);
+                }
             });
+            sheet.autoFitRow(node.serialNo());
             if (recursive) {
                 TREE_SHEET_HELPER.refreshTreeNodeData(setting, sheet, node.children, recursive);
             }
@@ -127,6 +163,15 @@ var TREE_SHEET_HELPER = {
         };
         TreeNodeCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
         TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
+            console.log(style);
+            if (style.backColor) {
+                ctx.save();
+                ctx.fillStyle = style.backColor;
+                ctx.fillRect(x, y, w, h);
+                ctx.restore();
+            } else {
+                ctx.clearRect(x, y, w, h);
+            }
             // ������(x1, y1)���(��, ��), (x2, y2)�յ�(��, ��), ��ɫ
             var drawLine = function (canvas, x1, y1, x2, y2, color) {
                 ctx.save();
@@ -233,7 +278,7 @@ var TREE_SHEET_HELPER = {
                 cellRect: cellRect,
                 sheetArea: context.sheetArea
             };
-        }
+        };
         TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
             var offset = -1;
             var node = tree.items[hitinfo.row];
@@ -257,6 +302,47 @@ var TREE_SHEET_HELPER = {
             }
         };
 
+        let TipCellType = function () {};
+        TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
+        TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
+            return {
+                x: x,
+                y: y,
+                row: context.row,
+                col: context.col,
+                cellStyle: cellStyle,
+                cellRect: cellRect,
+                sheet: context.sheet,
+                sheetArea: context.sheetArea
+            };
+        };
+        TipCellType.prototype.processMouseEnter = function (hitinfo) {
+            let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
+            if (setting.pos && text && text !== '') {
+                if (!this._toolTipElement) {
+                    var div = document.createElement("div");
+                    $(div).css("position", "absolute")
+                        .css("border", "1px #C0C0C0 solid")
+                        .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
+                        .css("font", "9pt Arial")
+                        .css("background", "white")
+                        .css("padding", 5);
+
+                    this._toolTipElement = div;
+                }
+                $(this._toolTipElement).text(text).css("top", setting.pos.y + hitinfo.y + 15).css("left", setting.pos.x + hitinfo.x + 15);
+                $(this._toolTipElement).hide();
+                document.body.insertBefore(this._toolTipElement, null);
+                $(this._toolTipElement).show("fast");
+            }
+        };
+        TipCellType.prototype.processMouseLeave = function (hininfo) {
+            if (this._toolTipElement) {
+                document.body.removeChild(this._toolTipElement);
+                this._toolTipElement = null;
+            }
+        }
+
         TREE_SHEET_HELPER.protectdSheet(sheet);
         TREE_SHEET_HELPER.massOperationSheet(sheet, function () {
             sheet.rowOutlines.direction(GC.Spread.Sheets.Outlines.OutlineDirection.backward);
@@ -267,6 +353,9 @@ var TREE_SHEET_HELPER = {
             sheet.setRowCount(tree.count() + setting.emptyRows, GC.Spread.Sheets.SheetArea.viewport);
             setting.cols.forEach(function (colSetting, iCol) {
                 sheet.setStyle(-1, iCol, TREE_SHEET_HELPER.getSheetCellStyle(colSetting));
+                if (colSetting.showHint) {
+                    sheet.getRange(-1, iCol, -1, 1).cellType(new TipCellType());
+                }
             });
             sheet.getRange(-1, setting.treeCol, -1, 1).cellType(new TreeNodeCellType());
             TREE_SHEET_HELPER.refreshTreeNodeData(setting, sheet, tree.roots, true);

+ 26 - 5
web/users/js/col_setting.js

@@ -8,9 +8,10 @@ let ColSettingObj = {
     DEFAULT_DATA_STYLE: null,
     cellType: {
         getText: null,
-        readOnly: null
+        readOnly: null,
+        checkBox: null
     },
-    Rows: {data: 0, filedName: 0, getText: 1, width: 2, readOnly: 3},
+    Rows: {data: 0, filedName: 0, getText: 1, wordWrap: 2, width: 3, readOnly: 4, showHint: 5},
     columnValueChanged: function (e, info) {
         let that = ColSettingObj;
         info.colList.forEach(function (iCol) {
@@ -50,25 +51,31 @@ let ColSettingObj = {
 
         this.cellType.getText = new GC.Spread.Sheets.CellTypes.ComboBox();
         this.cellType.getText.items(['getText.type']);
+
+        this.cellType.checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
     },
     initSheet: function (sheet, setting) {
         sheet.setColumnCount(2, GC.Spread.Sheets.SheetArea.rowHeader);
         sheet.setColumnWidth(0, 80, GC.Spread.Sheets.SheetArea.rowHeader);
         sheet.setColumnWidth(1, 70, GC.Spread.Sheets.SheetArea.rowHeader);
-        sheet.setRowCount(setting.headRows + this.Rows.readOnly + 1);
+        sheet.setRowCount(setting.headRows + this.Rows.showHint + 1);
 
         sheet.setText(setting.headRows + this.Rows.data, 0, 'Data', GC.Spread.Sheets.SheetArea.rowHeader);
         sheet.setStyle(setting.headRows + this.Rows.data, -1, this.DEFAULT_DATA_STYLE);
-        sheet.addSpan(setting.headRows + this.Rows.data, 0, 2, 1, GC.Spread.Sheets.SheetArea.rowHeader);
+        sheet.addSpan(setting.headRows + this.Rows.data, 0, this.Rows.wordWrap + 1, 1, GC.Spread.Sheets.SheetArea.rowHeader);
 
         sheet.setText(setting.headRows + this.Rows.filedName, 1, 'FieldName', GC.Spread.Sheets.SheetArea.rowHeader);
         sheet.setText(setting.headRows + this.Rows.getText, 1, 'getText', GC.Spread.Sheets.SheetArea.rowHeader);
+        sheet.setText(setting.headRows + this.Rows.wordWrap, 1, 'wordWrap', GC.Spread.Sheets.SheetArea.rowHeader);
 
         sheet.setText(setting.headRows + this.Rows.width, 0, 'width', GC.Spread.Sheets.SheetArea.rowHeader);
         sheet.addSpan(setting.headRows + this.Rows.width, 0, 1, 2, GC.Spread.Sheets.SheetArea.rowHeader);
 
         sheet.setText(setting.headRows + this.Rows.readOnly, 0, 'ReadOnly', GC.Spread.Sheets.SheetArea.rowHeader);
         sheet.addSpan(setting.headRows + this.Rows.readOnly, 0, 1, 2, GC.Spread.Sheets.SheetArea.rowHeader);
+
+        sheet.setText(setting.headRows + this.Rows.showHint, 0, 'ShowHint', GC.Spread.Sheets.SheetArea.rowHeader);
+        sheet.addSpan(setting.headRows + this.Rows.showHint, 0, 1, 2, GC.Spread.Sheets.SheetArea.rowHeader);
     },
     initColSetting: function (setting) {
         this.DEFAULT_TITLE_STYLE = this.getCellStyle('Arial', GC.Spread.Sheets.HorizontalAlign.center, GC.Spread.Sheets.VerticalAlign.center);
@@ -124,12 +131,18 @@ let ColSettingObj = {
                 // getText
                 cell = sheet.getCell(this.colSetting.headRows + this.Rows.getText, iCol, GC.Spread.Sheets.SheetArea.viewport);
                 cell.cellType(this.cellType.getText).value(col.data.getText).hAlign(GC.Spread.Sheets.HorizontalAlign.right);
+                // wordWrap
+                cell = sheet.getCell(this.colSetting.headRows + this.Rows.wordWrap, iCol, GC.Spread.Sheets.SheetArea.viewport);
+                cell.cellType(this.cellType.checkBox).value(col.data.wordWrap).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
                 // 列宽
                 sheet.setColumnWidth(iCol, col.width);
                 sheet.setValue(this.colSetting.headRows + this.Rows.width, iCol, sheet.getColumnWidth(iCol), GC.Spread.Sheets.SheetArea.viewport);
                 // readonly
                 cell = sheet.getCell(this.colSetting.headRows + this.Rows.readOnly, iCol, GC.Spread.Sheets.SheetArea.viewport);
                 cell.cellType(this.cellType.readOnly).value(col.readOnly).hAlign(GC.Spread.Sheets.HorizontalAlign.right);
+                // showHint
+                cell = sheet.getCell(this.colSetting.headRows + this.Rows.showHint, iCol, GC.Spread.Sheets.SheetArea.viewport);
+                cell.cellType(this.cellType.checkBox).value(col.showHint).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
             }
         }
         let cell = colEditSpread.getActiveSheet().getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport);
@@ -141,9 +154,12 @@ let ColSettingObj = {
         let sheet = colEditSpread.getActiveSheet();
         sheet.setColumnCount(count);
         for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
+            sheet.getCell(this.colSetting.headRows + this.Rows.getText, iCol).cellType(this.cellType.getText).hAlign(GC.Spread.Sheets.HorizontalAlign.right);
+            sheet.getCell(this.colSetting.headRows + this.Rows.wordWrap, iCol).cellType(this.cellType.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
             sheet.setValue(this.colSetting.headRows + this.Rows.width, iCol, sheet.getColumnWidth(iCol), GC.Spread.Sheets.SheetArea.viewport);
-            sheet.getCell(this.colSetting.headRows + this.Rows.readOnly, iCol, GC.Spread.Sheets.SheetArea.viewport).cellType(this.cellType.readOnly);
+            sheet.getCell(this.colSetting.headRows + this.Rows.readOnly, iCol).cellType(this.cellType.readOnly).hAlign(GC.Spread.Sheets.HorizontalAlign.right);
             sheet.setValue(this.colSetting.headRows + this.Rows.readOnly, iCol, false, GC.Spread.Sheets.SheetArea.viewport);
+            sheet.getCell(this.colSetting.headRows + this.Rows.showHint, iCol).cellType(this.cellType.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
         }
     },
     setHeaderRowCount: function (count) {
@@ -199,6 +215,9 @@ let ColSettingObj = {
             let col = {};
             col.width = sheet.getColumnWidth(iCol);
             col.readOnly = sheet.getValue(setting.headRows + this.Rows.readOnly, iCol) || false;
+            if (sheet.getValue(setting.headRows + this.Rows.showHint, iCol)) {
+                col.showHint = sheet.getValue(setting.headRows + this.Rows.showHint, iCol) || false;
+            }
 
             col.head = {};
             col.head.titleNames = [];
@@ -240,6 +259,8 @@ let ColSettingObj = {
                 col.data.getText = cell.text();
             }
             setting.cols.push(col);
+            // wordWrap
+            col.data.wordWrap = sheet.getValue(setting.headRows + this.Rows.wordWrap, iCol) || false;
         }
         return setting;
     }