xushiting 2 роки тому
батько
коміт
78a99fdb2d

+ 2 - 2
src/views/draw-file/board/editCAD/Controls/UIControl.js

@@ -96,7 +96,7 @@ export default class UIControl{
                     const tag = floorplanService.getTag(item.vectorId)
                     tag.setValue(value)
                 }
-                else if(value == VectorType.Table){
+                else if(type == VectorType.Table){
                     const table = floorplanService.getTable(item.vectorId)
                     table.setValue(value)
                 }
@@ -219,7 +219,7 @@ export default class UIControl{
 
         let blobImg = this.base64ToBlob(imgData)
         return blobImg
-        
+
         // 加工image data,替换mime type
         //imgData = imgData.replace(this._fixType(type), 'image/octet-stream')
 

+ 40 - 4
src/views/draw-file/board/editCAD/Geometry/Table.js

@@ -93,10 +93,13 @@ export default class Table extends Geometry {
     setValue(value) {
         let maxCol = 0;
         let maxRow = 0;
-        let newCells = [];
         for(let i=0;i<value.length;++i){
             const item = value[i]
-            let cell = this.cells[item.rowIndex][item.colIndex]
+            if(!this.cells[item.rowIndex]){
+                this.cells[item.rowIndex] = [];
+            }
+            let cellId = this.cells[item.rowIndex][item.colIndex]
+            let cell = floorplanService.getCell(cellId)
             if(!cell){
                 cell = tableService.createCell(this.vectorId)
                 this.cells[item.rowIndex][item.colIndex] = cell.vectorId
@@ -107,7 +110,6 @@ export default class Table extends Geometry {
             cell.colIndex = item.colIndex
             cell.rowIndex = item.rowIndex
 
-            // newCells[item.rowIndex][item.colIndex]
 
             if(maxRow < item.rowIndex){
                 maxRow = item.rowIndex
@@ -118,6 +120,11 @@ export default class Table extends Geometry {
             }
         }
 
+        ++maxRow;
+        ++maxCol;
+        let width=0;
+        let height=0;
+
         //删除多余的
         for(let i=maxRow+1;i<this.cells.length;++i){
             for(let j=maxCol+1;j<this.cells[i].length;++j){
@@ -128,9 +135,38 @@ export default class Table extends Geometry {
             }
         }
 
-        this.cells = newCells;
         this.rowLen = this.cells.length;
         this.colLen = this.cells[0].length;
+
+        for(let i=0;i<maxRow;++i){
+            const cell = floorplanService.getCell(this.cells[i][0]);
+            height += cell.height
+        }
+
+        for(let i=0;i<maxCol;++i){
+            const cell = floorplanService.getCell(this.cells[0][i]);
+            width += cell.width
+        }
+
+        this.points[1] = {
+            x:this.points[0].x + width/coordinate.res,
+            y:this.points[0].y
+        }
+
+        this.points[2] = {
+            x:this.points[0].x + width/coordinate.res,
+            y:this.points[0].y - height/coordinate.res
+        }
+
+        this.points[3] = {
+            x:this.points[0].x ,
+            y:this.points[0].y - height/coordinate.res
+        }
+
+        this.center = {
+            x:(this.points[0].x + this.points[1].x)/2,
+            y:(this.points[0].y + this.points[2].y)/2
+        }
     }
 
     getCellPos(vectorId){

+ 8 - 18
src/views/draw-file/board/editCAD/Renderer/Draw.js

@@ -167,30 +167,16 @@ export default class Draw {
     }
 
     // 文字
-    drawText(position, txt, screenCoord, angle) {
+    drawText(position, txt, screenCoord) {
         this.context.save()
         this.setCanvasStyle(Style.Font)
-        if (coordinate.ratio == Constant.ratio) {
-            this.context.font = '36px Microsoft YaHei'
-        } else {
-            this.context.font = '12px Microsoft YaHei'
-        }
+        this.context.font = '12px Microsoft YaHei'
 
         let pt = { x: position.x, y: position.y }
         if (!screenCoord) {
             pt = coordinate.getScreenXY({ x: position.x, y: position.y })
         }
-
-        if (angle) {
-            this.context.translate(pt.x, pt.y)
-            this.context.rotate(angle)
-            //this.context.strokeText(txt, 0, 0)
-            this.context.fillText(txt, 0, 0)
-        } else {
-            //this.context.strokeText(txt, pt.x, pt.y)
-            this.context.fillText(txt, pt.x, pt.y)
-        }
-
+        this.context.fillText(txt, pt.x, pt.y)
         this.context.restore()
     }
 
@@ -305,6 +291,10 @@ export default class Draw {
         this.context.lineTo(0,geometry.height)
         this.context.closePath();
         this.context.stroke()
+
+        this.context.font = '24px Microsoft YaHei'
+        const fontWidth = this.context.measureText(geometry.value).width
+        this.context.fillText(geometry.value, geometry.width/2 - fontWidth/2, geometry.height/2-2)
         this.context.restore()
     }
 
@@ -830,7 +820,7 @@ export default class Draw {
         const selectItem = stateService.getSelectItem()
         const draggingItem = stateService.getDraggingItem()
         const focusItem = stateService.getFocusItem()
-        
+
         if (selectItem && selectItem.type == VectorType.Compass) {
             if (geometry.vectorId == selectItem.vectorId) {
                 this.context.strokeStyle = Style.Select.Compass.strokeStyle