浏览代码

Spread悬浮提示

MaiXinRong 7 年之前
父节点
当前提交
1f861908fb

+ 59 - 0
public/web/sheet/sheet_data_helper.js

@@ -30,6 +30,21 @@ 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;
@@ -88,6 +103,47 @@ var SheetDataHelper = {
     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,6 +154,9 @@ 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 () {

+ 66 - 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;
@@ -10,6 +30,7 @@ var TREE_SHEET_HELPER = {
         spread.options.cutCopyIndicatorVisible = false;
         spread.options.allowCopyPasteExcelStyle = false;
         spread.options.allowUserDragDrop = false;
+        spread.options.
         spread.getActiveSheet().setRowCount(3);
         return spread;
     },
@@ -249,7 +270,7 @@ var TREE_SHEET_HELPER = {
                 cellRect: cellRect,
                 sheetArea: context.sheetArea
             };
-        }
+        };
         TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
             var offset = -1;
             var node = tree.items[hitinfo.row];
@@ -273,6 +294,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);
@@ -283,6 +345,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);

+ 1 - 0
test/tmp_data/bills_grid_setting.js

@@ -74,6 +74,7 @@ var BillsGridSetting ={
         {
             "width":200,
             "readOnly":false,
+            "showHint": true,
             "head":{
                 "titleNames":[
                     "项目名称"

+ 1 - 0
web/building_saas/main/js/views/project_view.js

@@ -86,6 +86,7 @@ var projectObj = {
         this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
         this.project.loadDatas(function (err) {
             if (!err) {
+                TREE_SHEET_HELPER.initSetting($('#billsSpread')[0], BillsGridSetting);
                 BillsGridSetting.cols.forEach(function (col) {
                     col.data.splitFields = col.data.field.split('.');
                     if (col.data.getText && Object.prototype.toString.apply(col.data.getText) === "[object String]") {

+ 3 - 0
web/building_saas/main/js/views/std_bills_lib.js

@@ -47,6 +47,8 @@ var billsLibObj = {
         }
     },
     loadStdBills: function (stdBillsLibID) {
+        TREE_SHEET_HELPER.initSetting($('#stdBillsSpread')[0], billsLibObj.stdBillsTreeSetting);
+
         var that = this;
         var stdBillsJobData, stdBillsFeatureData, stdBills;
         var stdBillsTree  = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
@@ -239,6 +241,7 @@ var billsLibObj = {
         }, {
             "width":100,
             "readOnly": true,
+            "showHint": true,
             "head":{
                 "titleNames":["工程量计算规则"],
                 "spanCols":[1],