Jelajahi Sumber

修改选择按钮

zhangweicheng 7 tahun lalu
induk
melakukan
57759c7268

+ 69 - 0
public/web/sheet/sheet_common.js

@@ -468,6 +468,75 @@ var sheetCommonObj = {
         };*/
         sheet.setCellType(row, col,this.getSelectButton(header.headerWidth),GC.Spread.Sheets.SheetArea.viewport);
     },
+    getCusButtonCellType:function (callback,readOnly=false) {
+        var ns = GC.Spread.Sheets;
+        function CusButtonCellType() {
+        }
+        CusButtonCellType.prototype = new ns.CellTypes.Text();
+        CusButtonCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
+
+            if(!readOnly){
+                if(options.sheet.getActiveRowIndex()==options.row&&options.sheet.getActiveColumnIndex()==options.col){
+                    var image = document.getElementById('f_btn'),imageMagin = 3;
+                    var imageHeight = 15;
+                    var imageWidth = 25;
+                    var imageX = x + w - imageWidth- imageMagin, imageY = y + h / 2 - imageHeight / 2;
+                    ctx.save();
+                    ctx.fillStyle = style.backColor;
+                    ctx.fillRect(x,y,w,h);
+                    ctx.drawImage(image, imageX, imageY,imageWidth,imageHeight);
+                    ctx.beginPath();
+                    ctx.arc(imageX+imageWidth/2,imageY+imageHeight/2,1,0,360,false);
+                    ctx.arc(imageX+imageWidth/2-4,imageY+imageHeight/2,1,0,360,false);
+                    ctx.arc(imageX+imageWidth/2+4,imageY+imageHeight/2,1,0,360,false);
+                    ctx.fillStyle="black";//填充颜色,默认是黑色
+                    ctx.fill();//画实心圆
+                    ctx.closePath();
+                    ctx.restore();
+                    //这里的左对齐的,当显示的字长度超过空白地方时,要改成右对齐
+                    if(style.hAlign == 0){
+                        w = w - imageWidth - imageMagin;
+                        if(value){
+                            let textWidth = ctx.measureText(value).width;
+                            let spaceWidth = w;
+                            if(spaceWidth<textWidth){
+                                style.hAlign = 2;
+                            }
+                        }
+                    }else if(style.hAlign == 2){//如果是右对齐的,往左边挪,给按钮留出空间
+                        x = x - imageWidth - imageMagin;
+                    }
+
+                }
+            }
+            GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
+        };
+        CusButtonCellType.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
+            };
+        };
+
+        CusButtonCellType.prototype.processMouseDown = function (hitinfo) {
+            if(hitinfo.sheet.getActiveRowIndex()==hitinfo.row&&hitinfo.sheet.getActiveColumnIndex()==hitinfo.col){
+                var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
+                var imageWidth = 25;
+                if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
+                    if(!readOnly){
+                        if(callback) callback(hitinfo)
+                    }
+                }
+            }
+        };
+        return new CusButtonCellType();
+    },
+
     getSelectButton(cellWidth=100){
 
         function moreButton() {

+ 0 - 1
web/building_saas/main/html/calc_program_manage.html

@@ -10,7 +10,6 @@
 
 <body>
     <div style="">
-        <img id="f_btn" src="/web/dest/css/img/feeRate_btn.jpg" alt="" style="display: none" />
     </div>
     <div class="toolsbar px-1" />
     <div class="container-fluid">

+ 9 - 42
web/building_saas/main/js/views/calc_base_view.js

@@ -355,18 +355,15 @@ let calcBaseView = {
         }
         CalcBaseCellType.prototype = new ns.CellTypes.Text();
         CalcBaseCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
-            //  if(value!=null){
-            // ctx.fillText(value,x+3+ctx.measureText(value).width,y+h-3);
-            // ctx.fillText(value,x+w-3,y+h-3);
-            GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
-            // }
             if(calcBaseView.editingCell && !projectReadOnly && calcBaseView.ifEdit(type, options.row)){
-                if(calcBaseView.editingCell.row==options.row&&calcBaseView.editingCell.col==options.col){
+                if(options.sheet.getActiveRowIndex()==options.row&&options.sheet.getActiveColumnIndex()==options.col){
                     var image = document.getElementById('f_btn'),imageMagin = 3;
-                    var imageHeight = h-2*imageMagin;
-                    var imageWidth = w*2/(type=='bills'?7:20);
+                    var imageHeight = 15;
+                    var imageWidth = 25;
                     var imageX = x + w - imageWidth- imageMagin, imageY = y + h / 2 - imageHeight / 2;
                     ctx.save();
+                    ctx.fillStyle = style.backColor;
+                    ctx.fillRect(x,y,w,h);
                     ctx.drawImage(image, imageX, imageY,imageWidth,imageHeight);
                     ctx.beginPath();
                     ctx.arc(imageX+imageWidth/2,imageY+imageHeight/2,1,0,360,false);
@@ -376,8 +373,10 @@ let calcBaseView = {
                     ctx.fill();//画实心圆
                     ctx.closePath();
                     ctx.restore();
+                    x = x - imageWidth - imageMagin;
                 }
             }
+            GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
         };
         CalcBaseCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
             return {
@@ -392,11 +391,9 @@ let calcBaseView = {
         };
         CalcBaseCellType.prototype.processMouseDown = function (hitinfo) {
             let me = calcBaseView;
-            if(me.editingCell && hitinfo.row==me.editingCell.row){
+            if(hitinfo.sheet.getActiveRowIndex()==hitinfo.row&&hitinfo.sheet.getActiveColumnIndex()==hitinfo.col){
                 var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
-                var imageMagin=3;
-                var imageHeight = hitinfo.cellRect.height-2*imageMagin;
-                var imageWidth = hitinfo.cellRect.width*2/7;
+                var imageWidth = 25;
                 if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
                     if(!projectReadOnly && me.ifEdit(type, hitinfo.row)){
                         hitinfo.sheet.setActiveCell(hitinfo.row, hitinfo.col);
@@ -409,39 +406,9 @@ let calcBaseView = {
                         $('#tabCalcBase').tab('show');
                         calcBaseView.initCalctor(type);
                     }
-                }else {//鼠标点击其它地方,消失
-                    hideButton(hitinfo);
                 }
             }
         };
-        CalcBaseCellType.prototype.processMouseEnter = function (hitinfo){
-            let me = calcBaseView;
-            me.pmLeave = false;
-            if(me.editingCell==null){
-                var showSelectBtn = true;
-                showSelectBtn=me.ifEdit(type, hitinfo.row);
-                if(showSelectBtn){
-                    me.editingCell={
-                        row:hitinfo.row,
-                        col:hitinfo.col
-                    };
-                    hitinfo.sheet.invalidateLayout();
-                    hitinfo.sheet.repaint();
-                }
-            }
-        };
-        CalcBaseCellType.prototype.processMouseLeave = function (hitinfo) {
-            hideButton(hitinfo);
-        };
-
-        function hideButton(hitinfo) {
-            if(!calcBaseView.pmLeave){
-                calcBaseView.editingCell=null;
-                hitinfo.sheet.invalidateLayout();
-                hitinfo.sheet.repaint();
-                calcBaseView.pmLeave = true;
-            }
-        }
         return new CalcBaseCellType();
     },
 };

+ 11 - 44
web/building_saas/main/js/views/project_view.js

@@ -1935,18 +1935,15 @@ var projectObj = {
         }
         CommonTotalFeeCellType.prototype = new ns.CellTypes.Text();
         CommonTotalFeeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
-            //  if(value!=null){
-            // ctx.fillText(value,x+3+ctx.measureText(value).width,y+h-3);
-            // ctx.fillText(value,x+w-3,y+h-3);
-            GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
-            // }
-            if(calcBaseView.editingCell && !projectReadOnly && calcBaseView.ifEdit(type, options.row)){
-                if(calcBaseView.editingCell.row==options.row&&calcBaseView.editingCell.col==options.col){
+            if(!projectReadOnly && calcBaseView.ifEdit(type, options.row)){
+                if(options.sheet.getActiveRowIndex()==options.row&&options.sheet.getActiveColumnIndex()==options.col){
                     var image = document.getElementById('f_btn'),imageMagin = 3;
-                    var imageHeight = h-2*imageMagin;
-                    var imageWidth = w*2/(type=='bills'?7:20);
+                    var imageHeight = 15;
+                    var imageWidth = 25;
                     var imageX = x + w - imageWidth- imageMagin, imageY = y + h / 2 - imageHeight / 2;
                     ctx.save();
+                    ctx.fillStyle = style.backColor;
+                    ctx.fillRect(x,y,w,h);
                     ctx.drawImage(image, imageX, imageY,imageWidth,imageHeight);
                     ctx.beginPath();
                     ctx.arc(imageX+imageWidth/2,imageY+imageHeight/2,1,0,360,false);
@@ -1956,8 +1953,10 @@ var projectObj = {
                     ctx.fill();//画实心圆
                     ctx.closePath();
                     ctx.restore();
+                    x = x - imageWidth - imageMagin;
                 }
             }
+            GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
         };
         CommonTotalFeeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
             return {
@@ -1972,57 +1971,25 @@ var projectObj = {
         };
         CommonTotalFeeCellType.prototype.processMouseDown = function (hitinfo) {
             let me = calcBaseView;
-            if(me.editingCell && hitinfo.row==me.editingCell.row){
+            if(hitinfo.sheet.getActiveRowIndex()==hitinfo.row&&hitinfo.sheet.getActiveColumnIndex()==hitinfo.col){
                 var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
-                var imageMagin=3;
-                var imageHeight = hitinfo.cellRect.height-2*imageMagin;
-                var imageWidth = hitinfo.cellRect.width*2/7;
+                var imageWidth = 25;
                 if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
                     if(!projectReadOnly && me.ifEdit(type, hitinfo.row)){
                         if(hitinfo.sheet.getParent() === projectObj.mainSpread){
                             let node = projectObj.project.mainTree.items[hitinfo.row] ? projectObj.project.mainTree.items[hitinfo.row] : null;
                             projectObj.mainController.setTreeSelected(node);
                         }
-                        //hitinfo.sheet.setActiveCell(hitinfo.row, hitinfo.col);
+                        hitinfo.sheet.setActiveCell(hitinfo.row, hitinfo.col);
                         calcBaseView.confirmBtn.attr('toggle', 'commonTotalFee');
                         changeCalcBaseFeeRate('commonTotalFee');
                         $('#tabCalcBase').tab('show');
                         calcBaseView.initCalctor(type);
                         feeRateObject.showSelectModal(hitinfo);
                     }
-                }else {//鼠标点击其它地方,消失
-                    hideButton(hitinfo);
                 }
             }
         };
-        CommonTotalFeeCellType.prototype.processMouseEnter = function (hitinfo){
-            let me = calcBaseView;
-            me.pmLeave = false;
-            if(me.editingCell==null){
-                var showSelectBtn = true;
-                showSelectBtn=me.ifEdit(type, hitinfo.row);
-                if(showSelectBtn){
-                    me.editingCell={
-                        row:hitinfo.row,
-                        col:hitinfo.col
-                    };
-                    hitinfo.sheet.invalidateLayout();
-                    hitinfo.sheet.repaint();
-                }
-            }
-        };
-        CommonTotalFeeCellType.prototype.processMouseLeave = function (hitinfo) {
-            hideButton(hitinfo);
-        };
-
-        function hideButton(hitinfo) {
-            if(!calcBaseView.pmLeave){
-                calcBaseView.editingCell=null;
-                hitinfo.sheet.invalidateLayout();
-                hitinfo.sheet.repaint();
-                calcBaseView.pmLeave = true;
-            }
-        }
         return new CommonTotalFeeCellType();
     },
     selectColAndFocus :function (newNode,field = 'code') {//选中单元格并设置焦点

+ 16 - 70
web/building_saas/main/js/views/quantity_edit_view.js

@@ -54,7 +54,7 @@ let quantityEditObj = {
         $("#quantityEXPValue").val(strartString+value+endString);
         setCursor($("#quantityEXPValue")[0],startIndex+value.length);//设置回光标位置
     },
-    getQuantityEditCellType:function () {
+    getQuantityEditCellType:function () {//这个需配合整个表的selection change事件,当change的时候会repaint,按钮会显示
         var ns = GC.Spread.Sheets;
         function QuantityEditCellType() {
             var init=false;
@@ -62,17 +62,15 @@ let quantityEditObj = {
         }
         QuantityEditCellType.prototype = new ns.CellTypes.Text();
         QuantityEditCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
-            // if(value!=null){
-            // ctx.fillText(value,x+3+ctx.measureText(value).width,y+h-3);
-            // }
-            GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
-            if(quantityEditObj.editingCell && !projectReadOnly){
-                if(quantityEditObj.editingCell.row==options.row&&quantityEditObj.editingCell.col==options.col){
+            if(!projectReadOnly){
+                if(options.sheet.getActiveRowIndex()==options.row&&options.sheet.getActiveColumnIndex()==options.col){
                     var image = document.getElementById('f_btn'),imageMagin = 3;
-                    var imageHeight = h-2*imageMagin;
-                    var imageWidth = w*2/7;
+                    var imageHeight = 15;
+                    var imageWidth = 25;
                     var imageX = x + w - imageWidth- imageMagin, imageY = y + h / 2 - imageHeight / 2;
                     ctx.save();
+                    ctx.fillStyle = style.backColor;
+                    ctx.fillRect(x,y,w,h);
                     ctx.drawImage(image, imageX, imageY,imageWidth,imageHeight);
                     ctx.beginPath();
                     ctx.arc(imageX+imageWidth/2,imageY+imageHeight/2,1,0,360,false);
@@ -82,9 +80,10 @@ let quantityEditObj = {
                     ctx.fill();//画实心圆
                     ctx.closePath();
                     ctx.restore();
+                    x = x - imageWidth - imageMagin;
                 }
             }
-
+            GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
         };
         QuantityEditCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
             return {
@@ -99,71 +98,18 @@ let quantityEditObj = {
         };
 
         //2018 -09 -26  修改工程量这个输入控件,删除悬浮提示注释,还原时通过git 历史
-
         QuantityEditCellType.prototype.processMouseDown = function (hitinfo) {
             let me=quantityEditObj;
-            /*if(isDoubleClick(this) == true && !projectReadOnly){//如果是双击,直接显示 2019-1-17 需求更改,取消双击弹出
-                me.showSelectModal(hitinfo);
-                return ;
-            }*/
-           if(me.editingCell && hitinfo.row==me.editingCell.row){
-               if(me.editingCell.isBtn == false){//是第一次点击,刷新显示按钮
-                   me.editingCell.isBtn = true;
-                   hitinfo.sheet.invalidateLayout();
-                   hitinfo.sheet.repaint();
-               }else {
-                   var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
-                   var imageMagin=3;
-                   var imageHeight = hitinfo.cellRect.height-2*imageMagin;
-                   var imageWidth = hitinfo.cellRect.width*2/7;
-                   if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
-                       if(!projectReadOnly){
-                           me.showSelectModal(hitinfo);
-                       }
-                   }/*else {//点击其它地方,按钮消失
-                    hideButton(hitinfo)
-                    }*/
-               }
-            }
-        };
-        QuantityEditCellType.prototype.processMouseEnter = function (hitinfo) {
-            var me=quantityEditObj;
-            me.pmLeave = false;
-            if(me.editingCell==null){
-                me.editingCell={
-                    row:hitinfo.row,
-                    col:hitinfo.col,
-                    isBtn :false//鼠标刚进入的时候按钮还是没显示的状态
+            if(hitinfo.sheet.getActiveRowIndex()==hitinfo.row&&hitinfo.sheet.getActiveColumnIndex()==hitinfo.col){
+                var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
+                var imageWidth = 25;
+                if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
+                    if(!projectReadOnly){
+                        me.showSelectModal(hitinfo);
+                    }
                 }
-               // hitinfo.sheet.invalidateLayout();
-                //hitinfo.sheet.repaint();
             }
         };
-        QuantityEditCellType.prototype.processMouseLeave = function (hitinfo) {
-            hideButton(hitinfo);
-        };
-
-        function hideButton(hitinfo) {
-            if(!quantityEditObj.pmLeave){//鼠标进入显示三个点按钮
-                quantityEditObj.editingCell=null;
-                hitinfo.sheet.invalidateLayout();
-                hitinfo.sheet.repaint();
-                quantityEditObj.pmLeave = true;
-            }
-        }
-
-        function isDoubleClick(quantityCell) {
-            let nowTime = +new Date();
-            if(quantityCell.clickTime !=0){
-                if(nowTime - quantityCell.clickTime < 280) {//判断为双击
-                    quantityCell.clickTime = 0;
-                    return true;
-                }
-            }
-            quantityCell.clickTime = nowTime;//计录点击时间
-            return false
-        }
-
         return new QuantityEditCellType();
     },
     showSelectModal:function (hitinfo) {

+ 4 - 2
web/building_saas/pm/js/pm_newMain.js

@@ -640,6 +640,9 @@ const projTreeObj = {
             }
         }
     },
+    cusButtonClick:async function(info){
+        projTreeObj.changeFileClick(null,info);
+    },
     onDragDropBlock : function (sender,args) {//拖动移动项目位置
         let selected = projTreeObj.tree.selected;
         let targetNode = projTreeObj.tree.items[args.toRow];
@@ -1123,8 +1126,7 @@ const projTreeObj = {
                     me.setCellValue({row: i, col: j}, nodes[i],sheet,setting);
                     let dataCode = headers[j].dataCode;
                     if(nodes[i].data.projType == "Tender" && (dataCode=="feeRateFile" || dataCode == "unitPriceFile")) {
-                        sheet.setCellType(i, j,sheetCommonObj.getSelectButton(headers[j].width),GC.Spread.Sheets.SheetArea.viewport);
-                        sheet.getCell(i, j,GC.Spread.Sheets.SheetArea.viewport).locked(false);
+                        sheet.setCellType(i, j,sheetCommonObj.getCusButtonCellType(me.cusButtonClick,false),GC.Spread.Sheets.SheetArea.viewport);
                     }
                     //sheet.setValue(i, j, nodes[i]['data'][dataCode]);
                 }

+ 1 - 0
web/common/html/header.html

@@ -1,3 +1,4 @@
+<img id="f_btn" src="/web/dest/css/img/feeRate_btn.jpg" alt="" style="display: none" />
 <nav class="navbar p-0 ">
     <% if(controller === 'boot' || controller === 'pm'){ %>
     <!--<a style="text-decoration: none" href="javascript:void(0);" class="header-logo">-->