123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- import { SObjectItem, SImageItem, SGraphItem, STextItem } from "@saga-web/graph/lib";
- import { ItemOrder } from "@saga-web/big/lib";
- import { SColor, SPainter, SRect } from "@saga-web/draw/lib";
- import { SMouseEvent } from "@saga-web/base/lib";
- import { EquipmentData } from "../types/EquipmentData";
- import { uuid } from '@/components/mapClass/until';
- import { cloneDeep } from 'lodash'
- enum StatusType {
-
- Normal,
-
- Edit
- }
- export class SEquipmentTextItem extends SObjectItem {
- _textArr: STextItem[] = [];
-
- _epData: EquipmentData | any = {};
-
- _name: string = '';
- get textArr(): STextItem[] {
- return this._textArr
- }
- set textArr(v) {
- this._textArr = v
- this.update();
- }
-
- get epData(): EquipmentData {
- return this._epData;
- }
- set epData(v: EquipmentData) {
- this._epData = v;
- this.update();
- }
- _info: any[] = []
-
- get info(): [] {
-
- return this._info
- }
-
- set info(data) {
-
- let { index, Name, FontSize, Color } = data
-
- if (this.epData && index < this.epData.InfoList.length) {
-
-
- }
-
- this.textArr[index + 1].text = Name
- this.textArr[index + 1].font.size = FontSize
- this.textArr[index + 1].color = Color
-
- this.epData.InfoList[index].Name = Name
- this.epData.InfoList[index].FontSize = FontSize
- this.epData.InfoList[index].Color = Color
- this.update();
- }
-
- constructor(parent: SGraphItem | null, epData: EquipmentData) {
- super(parent);
-
-
- this.epData = cloneDeep(epData)
- this.moveable = true;
- this.id = epData.ID;
- this.zOrder = ItemOrder.textOrder;
- this.textArr = [];
-
-
- this.loadEquipment(epData);
- }
-
- loadEquipment(epData: EquipmentData): void {
-
- this.x = epData.Pos.X;
- this.y = epData.Pos.Y;
-
- this.name = epData.Name
- let nameItem = new STextItem(this);
-
- nameItem.backgroundColor = SColor.Transparent;
- nameItem.font.size = 14;
- nameItem.text = epData.Name;
-
- nameItem.moveTo(10, epData.Size.Height + 7);
- this.textArr.push(nameItem);
-
- let { InfoList } = epData;
- InfoList.map(({ Name, X, Y, Width, Height, FontSize, Background, Color, TextAlign }) => {
- let textItem = new STextItem(this);
- textItem.backgroundColor = new SColor(Background);
- textItem.width = Width;
- textItem.height = Height;
- textItem.text = Name;
- textItem.font.size = FontSize;
- textItem.color = new SColor(Color);
- textItem.pos.x = X;
- textItem.pos.y = Y;
- this.textArr.push(textItem);
- });
- }
-
- boundingRect(): SRect {
-
-
- }
-
- toData(): EquipmentData {
-
- this.epData.Name = this.name;
- this.epData.Pos.X = this.x;
- this.epData.Pos.Y = this.y;
- this.epData.Size.Width = this.width;
- this.epData.Size.Height = this.height;
-
-
- this.epData.InfoList.map((item, index, arr) => {
- arr[index].X = this.textArr[index + 1].pos.x;
- arr[index].Y = this.textArr[index + 1].pos.y;
- arr[index].Name = this.textArr[index + 1].text;
- });
- this.epData.GraphElementType = 'Equipment'
-
- this.epData.Type = 'equipment'
- return this.epData;
- }
-
- addEquipmentInfo() {
- let { InfoList } = this.epData;
- let textItem = new STextItem(this);
- let Name, X, Y, Width, Height, FontSize, Background, Color, TextAlign
- if (InfoList.length) {
- let info = InfoList[InfoList.length - 1]
- Background = info.Background
- X = info.X
- Y = info.Y + 20
- Width = info.Width
- Height = info.Height
- FontSize = info.FontSize
- Background = info.Background
- Color = info.Color
- TextAlign = info.TextAlign
- Name = info.Name
-
- } else {
-
- Background = '#ffffff'
- X = this.img.width + 10
- Y = this.img.height / 2 - 6
- Width = 100
- Height = 25
- FontSize = 14
- Background = '#ffffff'
- Color = '#000000'
- TextAlign = 'center'
- Name = '请输入'
- }
-
- textItem.backgroundColor = new SColor(Background);
- textItem.width = Width;
- textItem.height = Height;
- textItem.text = '请输入';
- textItem.font.size = FontSize;
- textItem.color = new SColor(Color);
- textItem.pos.x = X;
- textItem.pos.y = Y;
- this.textArr.push(textItem);
- InfoList.push({
- Code: uuid(),
- Name: '请输入',
- X,
- Y,
- Width,
- Height,
- FontSize,
- Background,
- TextAlign,
- Color,
- })
- this.update()
- }
-
- deleteEquipmentInfo() {
- this.epData.InfoList.pop()
- if (this.textArr.length) {
- this.textArr[this.textArr.length - 1].text = '';
- this.textArr[this.textArr.length - 1].width = 0;
- this.textArr[this.textArr.length - 1].height = 0;
- this.textArr[this.textArr.length - 1].backgroundColor = SColor.Transparent;
- this.textArr.pop()
- }
- this.update()
- }
-
- onDraw(painter: SPainter): void {
- painter.pen.lineWidth = painter.toPx(1);
- painter.pen.color = SColor.Black;
- painter.brush.color = SColor.Transparent;
- if (this.equipmentStatus === StatusType.Edit) {
- painter.drawRect(this.boundingRect());
- this.textArr.map(item => item.moveable = true)
- } else {
- this.textArr.map(item => item.moveable = false)
- }
- }
- }
|