haojianlong 5 роки тому
батько
коміт
a686ce5744

+ 1 - 1
saga-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.7",
+    "version": "1.0.8",
     "description": "上格云建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 1 - 1
saga-web-big/src/factories/SItemFactory.ts

@@ -104,7 +104,7 @@ export class SItemFactory {
      * @param   data    图片数据
      * */
     createImage(data: ImageData): SImageItem {
-        return new SImageItem(null, data);
+        return new SImageItem(null);
     } // Function createImage()
 
     /**

+ 33 - 20
saga-web-big/src/items/SImageItem.ts

@@ -10,37 +10,50 @@ import { SPainter, SRect } from "@saga-web/draw/lib";
  */
 export class SImageItem extends SObjectItem {
     /** 标志宽度 */
-    private width: number = 20;
+    _width: number = 20;
+    get width(): number {
+        return this._width;
+    }
+    set width(v: number) {
+        this._width = v;
+        this.update();
+    }
     /** 标志高度 */
-    private height: number = 20;
+    _height: number = 20;
+    get height(): number {
+        return this._height;
+    }
+    set height(v: number) {
+        this._height = v;
+        this.update();
+    }
     /** 图片地址    */
-    url: string = "";
+    _url: string = "";
+    get url(): string {
+        return this._url;
+    }
+    set url(v: string) {
+        this._url = v;
+        this.Img = new Image();
+        this.Img.src = v;
+        this.Img.onload = (): void => {
+            // @ts-ignore
+            this.width = this.Img.width;
+            // @ts-ignore
+            this.height = this.Img.height;
+            this.update();
+        };
+    }
     /** 图片dom */
     Img: CanvasImageSource | undefined;
-    /** 图片item所有数据  */
-    private data: ImageData;
 
     /**
      * 构造函数
      *
      *  @param parent    指向父对象
-     *  @param data      图片数据
      * */
-    constructor(parent: SGraphyItem | null, data: ImageData) {
+    constructor(parent: SGraphyItem | null) {
         super(parent);
-        this.data = data;
-        if (data.Url) {
-            this.Img = new Image();
-            this.url = data.Url;
-            this.Img.src = this.url;
-            this.Img.onload = (): void => {
-                // @ts-ignore
-                this.width = data.Width ? data.Width : this.Img.width;
-                // @ts-ignore
-                this.height = data.Height ? data.Height : this.Img.height;
-                this.update();
-            };
-        }
         this.isTransform = false;
     }
 

+ 63 - 3
saga-web-big/src/items/SLineItem.ts

@@ -1,6 +1,7 @@
 import { SGraphyItem } from "@saga-web/graphy/lib";
 import { SLine, SPainter, SPoint } from "@saga-web/draw/lib";
 import { SMouseEvent } from "@saga-web/base";
+import { SMathUtil } from "../utils/SMathUtil";
 
 /**
  * 直线item
@@ -12,6 +13,42 @@ export class SLineItem extends SGraphyItem {
     p1: SPoint | undefined;
     /** 线段终止点   */
     p2: SPoint | undefined;
+    /** 是否完成绘制  */
+    private isFinish: boolean = true;
+    /** 拖动灵敏度   */
+    dis: number = 5;
+
+    /**
+     * 构造函数
+     *
+     * @param   parent  父级
+     * @param   line    线段
+     * */
+    constructor(parent: SGraphyItem | null, line: SLine);
+
+    /**
+     * 构造函数
+     *
+     * @param   parent  父级
+     * @param   point   线段起点
+     * */
+    constructor(parent: SGraphyItem | null, point: SPoint);
+
+    /**
+     * 构造函数
+     *
+     * @param   parent  父级
+     * @param   l       线段or线段起点
+     * */
+    constructor(parent: SGraphyItem | null, l: SPoint | SLine) {
+        super(parent);
+        if (l instanceof SPoint) {
+            this.p1 = l;
+        } else {
+            this.p1 = l.p1;
+            this.p2 = l.p2;
+        }
+    }
 
     /**
      * 鼠标按下事件
@@ -30,7 +67,17 @@ export class SLineItem extends SGraphyItem {
      * @return  是否处理事件
      * */
     onMouseMove(event: SMouseEvent): boolean {
-        return false;
+        if (this.isFinish) {
+            if (!this.p2) {
+                this.p2 = new SPoint(event.x, event.y);
+            } else {
+                this.p2.x = event.x;
+                this.p2.y = event.y;
+            }
+            return true;
+        } else {
+            return super.onMouseMove(event);
+        }
     } // Function onMouseMove()
 
     /**
@@ -40,7 +87,12 @@ export class SLineItem extends SGraphyItem {
      * @return  是否处理事件
      * */
     onMouseUp(event: SMouseEvent): boolean {
-        return false;
+        if (!this.isFinish) {
+            this.isFinish = true;
+            return true;
+        } else {
+            return super.onMouseUp(event);
+        }
     } // Function onMouseUp()
 
     /**
@@ -51,7 +103,15 @@ export class SLineItem extends SGraphyItem {
      * @return  true-是
      */
     contains(x: number, y: number): boolean {
-
+        if (this.p1 instanceof SPoint && this.p2 instanceof SPoint) {
+            let p = new SPoint(x, y);
+            if (
+                SMathUtil.pointToLine(p, new SLine(this.p1, this.p2)).MinDis <
+                this.dis
+            ) {
+                return true;
+            }
+        }
         return false;
     } // Function contains()
 

+ 2 - 2
saga-web-big/src/items/floor/SColumnItem.ts

@@ -1,8 +1,8 @@
 import { Column } from "../../types/floor/Column";
 import { SGraphyItem } from "@saga-web/graphy/lib";
 import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
-import { ItemOrder } from "../../config/ItemOrder";
-import { ItemColor } from "../../config/ItemColor";
+import { ItemOrder } from "../..";
+import { ItemColor } from "../..";
 
 /**
  * 柱子item

+ 1 - 1
saga-web-draw/src/SPainter.ts

@@ -600,7 +600,7 @@ export class SPainter extends SObject {
      */
     drawPolygon(points: SPoint[]): void {
         this.engine.drawPolygon(points);
-    } // Functin drawPolygon()
+    } // Function drawPolygon()
 
     /**
      * 绘制路径