|
@@ -1,6 +1,6 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div class="mapdata">
|
|
<div class="mapdata">
|
|
|
- <div id="container" ref="container" style="width: 1600px"></div>
|
|
|
|
|
|
|
+ <div id="container" ref="container" ></div>
|
|
|
<div class="left">
|
|
<div class="left">
|
|
|
<div
|
|
<div
|
|
|
class="bottombtn"
|
|
class="bottombtn"
|
|
@@ -24,14 +24,6 @@
|
|
|
>保存
|
|
>保存
|
|
|
</el-button>
|
|
</el-button>
|
|
|
|
|
|
|
|
- <el-button
|
|
|
|
|
- v-no-more-click
|
|
|
|
|
- @click="reset"
|
|
|
|
|
- type="primary"
|
|
|
|
|
- icon="el-icon-setting"
|
|
|
|
|
- style="align-self: flex-end;margin-top: 10px"
|
|
|
|
|
- >重置
|
|
|
|
|
- </el-button>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -42,13 +34,7 @@
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
import Konva from 'konva'
|
|
import Konva from 'konva'
|
|
|
-import {
|
|
|
|
|
- selectLotoMapById,
|
|
|
|
|
- selectIsLotoSwitchMapById,
|
|
|
|
|
- updateIsLotoSwitchMap,
|
|
|
|
|
- updatePointsBindingSwitchMap
|
|
|
|
|
-} from '@/api/mes/switchmanagement/switchmanagement'
|
|
|
|
|
-import { getIsIsolationPointPage } from '@/api/mes/spm/segregationPoint'
|
|
|
|
|
|
|
+import { getIsMotorListByLotoId, updateIsMotorMove } from '@/api/mes/motor/index'
|
|
|
import { getIsMapPointPage, selectIsMapPointById, updateMapPointList } from '@/api/system/mappoint'
|
|
import { getIsMapPointPage, selectIsMapPointById, updateMapPointList } from '@/api/system/mappoint'
|
|
|
import { selectIsMapById } from '@/api/system/mapconfig'
|
|
import { selectIsMapById } from '@/api/system/mapconfig'
|
|
|
|
|
|
|
@@ -60,21 +46,9 @@ export default {
|
|
|
layer: null,
|
|
layer: null,
|
|
|
selectedStates: [], // 用于存储每个元素的选中状态
|
|
selectedStates: [], // 用于存储每个元素的选中状态
|
|
|
selectedText: [], // 用于存储未选中的元素文本
|
|
selectedText: [], // 用于存储未选中的元素文本
|
|
|
- rects: [], // 白色rect合集
|
|
|
|
|
- texts: [], // 白色text合集
|
|
|
|
|
- redrects: [], // 红色rect合集
|
|
|
|
|
- redtexts: [], // 白色text合集
|
|
|
|
|
value: '',
|
|
value: '',
|
|
|
form: {}, //拿到单个数据
|
|
form: {}, //拿到单个数据
|
|
|
- originData: null, //原始数据
|
|
|
|
|
- filterData: null, //用来过滤掉已经渲染出来的隔离点
|
|
|
|
|
- leftPoints: [], //绑定的但未指定位置的集合
|
|
|
|
|
- orgLeftPoints: [], //原始左边数据
|
|
|
|
|
- rightPoints: [], //解绑的数据集合
|
|
|
|
|
- orgRightPoints: [], //原始右边数据
|
|
|
|
|
groups: [], //组移动数据
|
|
groups: [], //组移动数据
|
|
|
- bindingPointIds: [], //存放从未绑定中放入物资柜的数据 id集合
|
|
|
|
|
- unbindPointIds: [], //解绑的数据接口参数 id集合
|
|
|
|
|
isSave: true,
|
|
isSave: true,
|
|
|
isInitialized: false, // 添加初始化标志
|
|
isInitialized: false, // 添加初始化标志
|
|
|
imageUrl: '',//获取底图
|
|
imageUrl: '',//获取底图
|
|
@@ -83,227 +57,55 @@ export default {
|
|
|
x: '',//底图横坐标
|
|
x: '',//底图横坐标
|
|
|
y: '',//底图纵坐标
|
|
y: '',//底图纵坐标
|
|
|
mapId: null,//地图Id
|
|
mapId: null,//地图Id
|
|
|
- mapType: 3,//地图类型
|
|
|
|
|
|
|
+ mapType: 4,//地图类型
|
|
|
pointList: null,//接口给的所有点位数据
|
|
pointList: null,//接口给的所有点位数据
|
|
|
- bindingPoints: [],//给地图点位界面更新的绑定隔离点
|
|
|
|
|
movePoints: [],//给地图点位界面更新位置
|
|
movePoints: [],//给地图点位界面更新位置
|
|
|
- unbindingPoints: []//给地图点位界面更新解绑数据
|
|
|
|
|
-
|
|
|
|
|
|
|
+ lotoId: null,
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- // watch: {
|
|
|
|
|
- // bindingPointIds(newVal, oldVal) {
|
|
|
|
|
- // if (newVal) {
|
|
|
|
|
- // this.isSave = false;
|
|
|
|
|
- // }
|
|
|
|
|
- // },
|
|
|
|
|
- // unbindPointIds(newVal, oldVal) {
|
|
|
|
|
- // if (newVal) {
|
|
|
|
|
- // this.isSave = false;
|
|
|
|
|
- // }
|
|
|
|
|
- // },
|
|
|
|
|
- // // value: {
|
|
|
|
|
- // // handler(newVal, oldVal) {
|
|
|
|
|
- // // if (this.isInitialized && newVal) {
|
|
|
|
|
- // // // 只有在初始化后才监听 value 变化
|
|
|
|
|
- // // const parsedValue = JSON.parse(newVal);
|
|
|
|
|
- // // console.log(parsedValue, "deep watch for value");
|
|
|
|
|
- // // this.isSave = false;
|
|
|
|
|
- // // }
|
|
|
|
|
- // // },
|
|
|
|
|
- // // deep: true,
|
|
|
|
|
- // // },
|
|
|
|
|
- // },
|
|
|
|
|
|
|
|
|
|
created() {
|
|
created() {
|
|
|
- // this.getIsIsolationPointPage()
|
|
|
|
|
this.isInitialized = true
|
|
this.isInitialized = true
|
|
|
},
|
|
},
|
|
|
- beforeRouteEnter(to, from, next) {
|
|
|
|
|
- next((vm) => {
|
|
|
|
|
- // vm.getIsIsolationPointPage()
|
|
|
|
|
- vm.addPointsToRightPointsBox()
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
|
|
+
|
|
|
mounted() {
|
|
mounted() {
|
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
|
this.getInfo()
|
|
this.getInfo()
|
|
|
- this.getIsIsolationPointPage()
|
|
|
|
|
- this.addPointsToRightPointsBox()
|
|
|
|
|
})
|
|
})
|
|
|
- console.log(this.$route.query.switchMapId, 'switchMapId')
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
methods: {
|
|
|
getInfo() {
|
|
getInfo() {
|
|
|
- const switchMapId = this.$route.query.switchMapId
|
|
|
|
|
- selectIsLotoSwitchMapById(switchMapId).then((response) => {
|
|
|
|
|
- console.log(response, '作业区域信息')
|
|
|
|
|
- this.form = response.data
|
|
|
|
|
- this.mapId = response.data.mapId
|
|
|
|
|
-
|
|
|
|
|
- // 获取不同底图 如地图或者柜子
|
|
|
|
|
- selectIsMapById(response.data.mapId).then((response) => {
|
|
|
|
|
- console.log(response, '获取底图')
|
|
|
|
|
- if (response.data) {
|
|
|
|
|
- try {
|
|
|
|
|
- this.value = JSON.stringify(response.data.pointList, null, 4)
|
|
|
|
|
-
|
|
|
|
|
- this.originData = this.value
|
|
|
|
|
- } catch (err) {
|
|
|
|
|
- console.error(err)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- this.imageUrl = response.data.imageUrl
|
|
|
|
|
- this.width = response.data.width
|
|
|
|
|
- this.height = response.data.height
|
|
|
|
|
- this.x = response.data.x
|
|
|
|
|
- this.y = response.data.y
|
|
|
|
|
- this.pointList = response.data.pointList|| []
|
|
|
|
|
-
|
|
|
|
|
- const data = {
|
|
|
|
|
- current: 1,
|
|
|
|
|
- size: -1,
|
|
|
|
|
- switchMapId: this.$route.query.switchMapId
|
|
|
|
|
- }
|
|
|
|
|
- console.log('调用getIsIsolationPointPage之前')
|
|
|
|
|
- getIsIsolationPointPage(data).then((res) => {
|
|
|
|
|
- const allPoints = res.data.records || []; // 所有可绑定点
|
|
|
|
|
- const placedPointIds = new Set((this.pointList || []).map(p => String(p.entityId)));
|
|
|
|
|
-
|
|
|
|
|
- // 过滤:只留下还没有指定位置的点
|
|
|
|
|
- const unplacedPoints = allPoints.filter(item => !placedPointIds.has(item.pointId));
|
|
|
|
|
-
|
|
|
|
|
- console.log(allPoints, '所有点');
|
|
|
|
|
- console.log(this.pointList, '已绑定并有位置的点');
|
|
|
|
|
- console.log(unplacedPoints, '未绑定位置的点(需要放左上角0,0)');
|
|
|
|
|
-
|
|
|
|
|
- // 左侧需要显示的数据
|
|
|
|
|
- this.leftPoints = unplacedPoints.map((item) => {
|
|
|
|
|
- return {
|
|
|
|
|
- pointId: item.pointId,
|
|
|
|
|
- entityId: item.pointId,
|
|
|
|
|
- entityName: item.pointName,
|
|
|
|
|
- pointName: item.pointName,
|
|
|
|
|
- remark: item.remark,
|
|
|
|
|
- prePointId: item.prePointId,
|
|
|
|
|
- pointType: item.pointType,
|
|
|
|
|
- pointTypeName: item.pointTypeName,
|
|
|
|
|
- powerType: item.powerType,
|
|
|
|
|
- powerTypeName: item.powerTypeName,
|
|
|
|
|
- pointIcon: item.pointIcon,
|
|
|
|
|
- status: false,
|
|
|
|
|
- pointPicture: item.pointPicture,
|
|
|
|
|
- mapImg: null,
|
|
|
|
|
- mapId: this.form.mapId,
|
|
|
|
|
- mapType: this.mapType,
|
|
|
|
|
- mapName: '你好4',
|
|
|
|
|
- x: 0,
|
|
|
|
|
- y: 0
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 调用你已有的渲染逻辑
|
|
|
|
|
- this.addPointsToLeftPointsBox(this.leftPoints)
|
|
|
|
|
-
|
|
|
|
|
- // 保存完整数据
|
|
|
|
|
- this.orgLeftPoints = res.data.records.map((item) => {
|
|
|
|
|
- return {
|
|
|
|
|
- pointId: item.pointId,
|
|
|
|
|
- entityId: item.pointId,
|
|
|
|
|
- entityName: item.pointName,
|
|
|
|
|
- pointName: item.pointName,
|
|
|
|
|
- remark: item.remark,
|
|
|
|
|
- prePointId: item.prePointId,
|
|
|
|
|
- pointType: item.pointType,
|
|
|
|
|
- pointTypeName: item.pointTypeName,
|
|
|
|
|
- powerType: item.powerType,
|
|
|
|
|
- powerTypeName: item.powerTypeName,
|
|
|
|
|
- pointIcon: item.pointIcon,
|
|
|
|
|
- status: false,
|
|
|
|
|
- pointPicture: item.pointPicture,
|
|
|
|
|
- mapImg: null,
|
|
|
|
|
- mapId: this.form.mapId,
|
|
|
|
|
- mapType: this.form.mapType
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- this.initKonva()
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ this.lotoId = this.$route.query.lotoId
|
|
|
|
|
+ const motorMapId = this.$route.query.motorMapId
|
|
|
|
|
+ this.mapId = motorMapId
|
|
|
|
|
+ const lotoId = this.$route.query.lotoId
|
|
|
|
|
+
|
|
|
|
|
+ const mapPromise = selectIsMapById(motorMapId).then((response) => {
|
|
|
|
|
+ console.log(response, '获取底图')
|
|
|
|
|
+ this.imageUrl = response.data.imageUrl
|
|
|
|
|
+ this.width = response.data.width
|
|
|
|
|
+ this.height = response.data.height
|
|
|
|
|
+ this.x = response.data.x
|
|
|
|
|
+ this.y = response.data.y
|
|
|
})
|
|
})
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
- // 获取未绑定的所有隔离点
|
|
|
|
|
- getIsIsolationPointPage() {
|
|
|
|
|
|
|
+ const pointPromise = getIsMotorListByLotoId({ lotoId }).then((response) => {
|
|
|
|
|
+ console.log(response, '查询电机对应的锁定站的点位列表')
|
|
|
|
|
+ this.pointList = response.data || []
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- // 拿到解绑的隔离点数据
|
|
|
|
|
- const data1 = {
|
|
|
|
|
- current: 1,
|
|
|
|
|
- size: -1,
|
|
|
|
|
- switchMapId: 0
|
|
|
|
|
- }
|
|
|
|
|
- getIsIsolationPointPage(data1).then((res) => {
|
|
|
|
|
- this.rightPoints = res.data.records.map((item) => {
|
|
|
|
|
- return {
|
|
|
|
|
- entityId: item.pointId,
|
|
|
|
|
- entityName: item.pointName,
|
|
|
|
|
- pointId: item.pointId,
|
|
|
|
|
- pointName: item.pointName,
|
|
|
|
|
- remark: item.remark,
|
|
|
|
|
- prePointId: item.prePointId,
|
|
|
|
|
- pointType: item.pointType,
|
|
|
|
|
- pointTypeName: item.pointTypeName,
|
|
|
|
|
- powerType: item.powerType,
|
|
|
|
|
- powerTypeName: item.powerTypeName,
|
|
|
|
|
- pointIcon: item.pointIcon,
|
|
|
|
|
- status: false,
|
|
|
|
|
- pointPicture: item.pointPicture,
|
|
|
|
|
- mapImg: null,
|
|
|
|
|
- mapId: this.form.mapId,
|
|
|
|
|
- mapType: this.form.mapType
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- this.orgRightPoints = res.data.records.map((item) => {
|
|
|
|
|
- return {
|
|
|
|
|
- entityId: item.pointId,
|
|
|
|
|
- entityName: item.pointName,
|
|
|
|
|
- pointId: item.pointId,
|
|
|
|
|
- pointName: item.pointName,
|
|
|
|
|
- remark: item.remark,
|
|
|
|
|
- prePointId: item.prePointId,
|
|
|
|
|
- pointType: item.pointType,
|
|
|
|
|
- pointTypeName: item.pointTypeName,
|
|
|
|
|
- powerType: item.powerType,
|
|
|
|
|
- powerTypeName: item.powerTypeName,
|
|
|
|
|
- pointIcon: item.pointIcon,
|
|
|
|
|
- status: false,
|
|
|
|
|
- pointPicture: item.pointPicture,
|
|
|
|
|
- mapImg: null,
|
|
|
|
|
- mapId: this.form.mapId,
|
|
|
|
|
- mapType: this.form.mapType
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ Promise.all([mapPromise, pointPromise]).then(() => {
|
|
|
|
|
+ // 数据准备好以后再渲染
|
|
|
|
|
+ this.initKonva()
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- // 重置
|
|
|
|
|
- reset() {
|
|
|
|
|
- this.value = this.originData
|
|
|
|
|
- // 清空并重新赋值
|
|
|
|
|
- this.rightPoints = JSON.parse(JSON.stringify(this.orgRightPoints)) // 深拷贝
|
|
|
|
|
- this.leftPoints = JSON.parse(JSON.stringify(this.orgLeftPoints)) // 深拷贝
|
|
|
|
|
- this.initKonva() // 重新初始化 Konva
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
close() {
|
|
close() {
|
|
|
- // this.$router.push('/mes/dv/lotoStation')
|
|
|
|
|
-
|
|
|
|
|
- setTimeout(()=>{
|
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
this.getInfo()
|
|
this.getInfo()
|
|
|
- this.getIsIsolationPointPage()
|
|
|
|
|
this.initKonva()
|
|
this.initKonva()
|
|
|
- this.addPointsToRightPointsBox()
|
|
|
|
|
- },1000)
|
|
|
|
|
|
|
+ }, 1000)
|
|
|
},
|
|
},
|
|
|
save() {
|
|
save() {
|
|
|
this.$confirm('请确认是否保存修改内容', '提示', {
|
|
this.$confirm('请确认是否保存修改内容', '提示', {
|
|
@@ -312,78 +114,29 @@ export default {
|
|
|
type: 'warning'
|
|
type: 'warning'
|
|
|
})
|
|
})
|
|
|
.then(() => {
|
|
.then(() => {
|
|
|
- // 校验 this.value 是否为有效的 JSON
|
|
|
|
|
- if (this.isJson(this.value)) {
|
|
|
|
|
- const mapData =
|
|
|
|
|
- typeof this.value === 'string'
|
|
|
|
|
- ? this.value
|
|
|
|
|
- : JSON.stringify(this.value)
|
|
|
|
|
- const formData = {
|
|
|
|
|
- ...this.form,
|
|
|
|
|
- map: mapData
|
|
|
|
|
- }
|
|
|
|
|
- console.log(formData, 'map')
|
|
|
|
|
-
|
|
|
|
|
- updateIsLotoSwitchMap(formData).then((response) => {
|
|
|
|
|
- console.log(response, '修改车间区域地图')
|
|
|
|
|
- this.$message({
|
|
|
|
|
- type: 'success',
|
|
|
|
|
- message: '保存成功!'
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ let dataMap = {
|
|
|
|
|
+ moveList: this.movePoints
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(dataMap, '先拿到数据看看再说')
|
|
|
|
|
+ updateIsMotorMove(dataMap).then((res) => {
|
|
|
|
|
+ console.log(res, '拿到的新绑定数据')
|
|
|
|
|
+ this.movePoints = []
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
|
|
+ this.close()
|
|
|
|
|
|
|
|
- let dataMap = {
|
|
|
|
|
- bindingPoints: this.bindingPoints,
|
|
|
|
|
- movePoints: this.movePoints,
|
|
|
|
|
- unbindingPoints: this.unbindingPoints
|
|
|
|
|
- }
|
|
|
|
|
- console.log(dataMap, '先拿到数据看看再说')
|
|
|
|
|
- updateMapPointList(dataMap).then((res) => {
|
|
|
|
|
- console.log(res, '拿到的新绑定数据')
|
|
|
|
|
- this.bindingPoints = []
|
|
|
|
|
- this.unbindingPoints=[]
|
|
|
|
|
- })
|
|
|
|
|
- const data = {
|
|
|
|
|
- bindingPointIds: this.bindingPointIds,
|
|
|
|
|
- switchMapId: this.$route.query.switchMapId,
|
|
|
|
|
- unbindPointIds: this.unbindPointIds
|
|
|
|
|
- }
|
|
|
|
|
- console.log(data, '解绑与绑定数据参数')
|
|
|
|
|
- updatePointsBindingSwitchMap(data).then((res) => {
|
|
|
|
|
- console.log(res, '解绑接口返回值')
|
|
|
|
|
- this.bindingPointIds = []
|
|
|
|
|
- this.unbindPointIds = []
|
|
|
|
|
- })
|
|
|
|
|
- this.close()
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$message({
|
|
|
|
|
- type: 'error',
|
|
|
|
|
- message: '地图数据格式不正确,请输入有效的 JSON 格式!'
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
})
|
|
})
|
|
|
.catch(() => {
|
|
.catch(() => {
|
|
|
// 取消操作
|
|
// 取消操作
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- // 校验字符串是否为有效的 JSON
|
|
|
|
|
- isJson(str) {
|
|
|
|
|
- try {
|
|
|
|
|
- JSON.parse(str)
|
|
|
|
|
- return true
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
initKonva() {
|
|
initKonva() {
|
|
|
-
|
|
|
|
|
// 创建舞台
|
|
// 创建舞台
|
|
|
this.stage = new Konva.Stage({
|
|
this.stage = new Konva.Stage({
|
|
|
container: this.$refs.container, // 容器元素
|
|
container: this.$refs.container, // 容器元素
|
|
|
- width: 1600,
|
|
|
|
|
- height: 860
|
|
|
|
|
|
|
+ width: 1700,
|
|
|
|
|
+ height: 860,
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// 创建图层
|
|
// 创建图层
|
|
@@ -400,6 +153,7 @@ export default {
|
|
|
draggable: false
|
|
draggable: false
|
|
|
}
|
|
}
|
|
|
bgImage.src = this.imageUrl
|
|
bgImage.src = this.imageUrl
|
|
|
|
|
+
|
|
|
bgImage.onload = () => {
|
|
bgImage.onload = () => {
|
|
|
const knovaImage = new Konva.Image({
|
|
const knovaImage = new Konva.Image({
|
|
|
...imageConfig,
|
|
...imageConfig,
|
|
@@ -407,32 +161,6 @@ export default {
|
|
|
})
|
|
})
|
|
|
this.layer.add(knovaImage)
|
|
this.layer.add(knovaImage)
|
|
|
|
|
|
|
|
- // 创建背景图并添加到图层
|
|
|
|
|
- // 创建所有隔离点父盒子 放置于网格线上
|
|
|
|
|
- const rightPointsBox = new Konva.Rect({
|
|
|
|
|
- x: 1100,
|
|
|
|
|
- y: 15,
|
|
|
|
|
- width: 200,
|
|
|
|
|
- height: 800,
|
|
|
|
|
- cornerRadius: 5,
|
|
|
|
|
- stroke: 'black',
|
|
|
|
|
- strokeWidth: 2,
|
|
|
|
|
- fill: 'white'
|
|
|
|
|
- })
|
|
|
|
|
- const rightnoLoto = new Konva.Text({
|
|
|
|
|
- x: 1110, // 调整位置以适应网格
|
|
|
|
|
- y: 20, // 调整位置以适应网格
|
|
|
|
|
- text: '未绑定开关分布的点位数据',
|
|
|
|
|
- fontSize: 15,
|
|
|
|
|
- fill: 'black'
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- this.layer.add(rightPointsBox)
|
|
|
|
|
- this.layer.add(rightnoLoto)
|
|
|
|
|
-
|
|
|
|
|
- // 将隔离点添加到 rightPointsBox
|
|
|
|
|
- this.addPointsToRightPointsBox(rightPointsBox)
|
|
|
|
|
-
|
|
|
|
|
// 渲染数据
|
|
// 渲染数据
|
|
|
const imageSrc = require('@/assets/images/localSetIcon.jpg') // 图片路径
|
|
const imageSrc = require('@/assets/images/localSetIcon.jpg') // 图片路径
|
|
|
this.renderGrid(imageSrc, 6, 3, 450, 100, 120, 100, 50, 50, 60, 25)
|
|
this.renderGrid(imageSrc, 6, 3, 450, 100, 120, 100, 50, 50, 60, 25)
|
|
@@ -448,7 +176,7 @@ export default {
|
|
|
|
|
|
|
|
// 绘制无限网格
|
|
// 绘制无限网格
|
|
|
drawGrid(cellWidth, cellHeight, gridColor) {
|
|
drawGrid(cellWidth, cellHeight, gridColor) {
|
|
|
- const width = 1600
|
|
|
|
|
|
|
+ const width = 1700
|
|
|
const height = 860
|
|
const height = 860
|
|
|
|
|
|
|
|
// 绘制竖线
|
|
// 绘制竖线
|
|
@@ -489,582 +217,89 @@ export default {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
// 绘制柜内所有点
|
|
// 绘制柜内所有点
|
|
|
- renderGrid(imageSrc) {
|
|
|
|
|
- this.selectedStates = []
|
|
|
|
|
- this.rects = []
|
|
|
|
|
- this.texts = []
|
|
|
|
|
|
|
+ renderGrid() {
|
|
|
this.bgrects = {}
|
|
this.bgrects = {}
|
|
|
- this.redrects = []
|
|
|
|
|
- this.redtexts = []
|
|
|
|
|
this.selectedText = []
|
|
this.selectedText = []
|
|
|
-
|
|
|
|
|
- this.rightPoints = []
|
|
|
|
|
- this.leftPoints = []
|
|
|
|
|
- this.bindingPointIds = []
|
|
|
|
|
- this.unbindPointIds = []
|
|
|
|
|
this.movePoints = []
|
|
this.movePoints = []
|
|
|
|
|
|
|
|
const positions = this.pointList.map(item => ({
|
|
const positions = this.pointList.map(item => ({
|
|
|
- row: item.x,
|
|
|
|
|
- col: item.y,
|
|
|
|
|
- id: item.id,
|
|
|
|
|
- pointId: item.entityId,
|
|
|
|
|
- pointName: item.entityName,
|
|
|
|
|
- entityId: item.entityId,
|
|
|
|
|
- entityName: item.entityName,
|
|
|
|
|
- mapId: item.mapId,
|
|
|
|
|
- mapType: parseInt(item.mapType),
|
|
|
|
|
- x: item.x,
|
|
|
|
|
- y: item.y,
|
|
|
|
|
- remark: item.remark,
|
|
|
|
|
- pointIcon: item.pointIcon,
|
|
|
|
|
- pointPicture: item.pointPicture
|
|
|
|
|
|
|
+ entityId: item.motorId,
|
|
|
|
|
+ entityName: item.motorName,
|
|
|
|
|
+ pointId: item.pointId,
|
|
|
|
|
+ mapPointId: item.mapPointId,
|
|
|
|
|
+ // 如果 x / y 为空则默认放置到 0,0
|
|
|
|
|
+ x: item.x != null ? item.x : 0,
|
|
|
|
|
+ y: item.y != null ? item.y : 0
|
|
|
}))
|
|
}))
|
|
|
- console.log(positions,'positions')
|
|
|
|
|
|
|
+
|
|
|
|
|
+ console.log(positions, 'positions')
|
|
|
|
|
|
|
|
positions.forEach(pos => {
|
|
positions.forEach(pos => {
|
|
|
const x = pos.x * 50
|
|
const x = pos.x * 50
|
|
|
const y = pos.y * 50
|
|
const y = pos.y * 50
|
|
|
const labelText = pos.entityName
|
|
const labelText = pos.entityName
|
|
|
|
|
|
|
|
- const point = new Image()
|
|
|
|
|
- point.src = pos.pointIcon
|
|
|
|
|
-
|
|
|
|
|
- point.onload = () => {
|
|
|
|
|
- const group = new Konva.Group({
|
|
|
|
|
- x: x,
|
|
|
|
|
- y: y,
|
|
|
|
|
- draggable: true
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- const bgrect = new Konva.Rect({ x: -1, y: -5, width: 50, height: 78, cornerRadius: 5, stroke: 'white', strokeWidth: 2, fill: 'white' })
|
|
|
|
|
- const rect = new Konva.Rect({ x: 1, y: -1, width: 45, height: 70, cornerRadius: 5, stroke: 'red', strokeWidth: 2, fill: 'white' })
|
|
|
|
|
- const knovaImage = new Konva.Image({ x: 1, y: 0, image: point, width: 45, height: 45 })
|
|
|
|
|
- const text = new Konva.Text({ x: 8, y: 50, fontSize: 17, text: labelText, fontFamily: 'Calibri', fill: 'red' })
|
|
|
|
|
-
|
|
|
|
|
- group.add(bgrect)
|
|
|
|
|
- group.add(rect)
|
|
|
|
|
- group.add(knovaImage)
|
|
|
|
|
- group.add(text)
|
|
|
|
|
- this.layer.add(group)
|
|
|
|
|
-
|
|
|
|
|
- group.on('dragend', () => {
|
|
|
|
|
- const groupPos = group.getAbsolutePosition();
|
|
|
|
|
-
|
|
|
|
|
- const rightBoxBounds = { x: 1100, y: 15, width: 200, height: 800 };
|
|
|
|
|
- const cabinetBounds = { x: 0, y: 0, width: 1200, height: 860 };
|
|
|
|
|
-
|
|
|
|
|
- const isInRightBox =
|
|
|
|
|
- groupPos.x >= rightBoxBounds.x &&
|
|
|
|
|
- groupPos.x <= rightBoxBounds.x + rightBoxBounds.width &&
|
|
|
|
|
- groupPos.y >= rightBoxBounds.y &&
|
|
|
|
|
- groupPos.y <= rightBoxBounds.y + rightBoxBounds.height;
|
|
|
|
|
-
|
|
|
|
|
- const isInCabinet =
|
|
|
|
|
- groupPos.x >= cabinetBounds.x &&
|
|
|
|
|
- groupPos.x <= cabinetBounds.x + cabinetBounds.width &&
|
|
|
|
|
- groupPos.y >= cabinetBounds.y &&
|
|
|
|
|
- groupPos.y <= cabinetBounds.y + cabinetBounds.height;
|
|
|
|
|
-
|
|
|
|
|
- // 判断点的来源
|
|
|
|
|
- let pointData = positions.find(p => p.entityName === labelText);
|
|
|
|
|
- let fromRight = false;
|
|
|
|
|
- if (!pointData) {
|
|
|
|
|
- const rightIndex = this.rightPoints.findIndex(p => p.entityName === labelText);
|
|
|
|
|
- if (rightIndex !== -1) {
|
|
|
|
|
- pointData = this.rightPoints.splice(rightIndex, 1)[0];
|
|
|
|
|
- fromRight = true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (!pointData) return;
|
|
|
|
|
-
|
|
|
|
|
- const newRow = Math.max(0, Math.min(Math.round(groupPos.x / 50), Math.floor(1200 / 50) - 1));
|
|
|
|
|
- const newCol = Math.max(0, Math.min(Math.round(groupPos.y / 50), Math.floor(860 / 50) - 1));
|
|
|
|
|
-
|
|
|
|
|
- const updatedPoint = {
|
|
|
|
|
- ...pointData,
|
|
|
|
|
- row: newRow,
|
|
|
|
|
- col: newCol,
|
|
|
|
|
- x: newRow,
|
|
|
|
|
- y: newCol,
|
|
|
|
|
- mapId: this.mapId,
|
|
|
|
|
- mapType: this.mapType
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- // ====================== 数据处理 ======================
|
|
|
|
|
- if (fromRight && isInCabinet) {
|
|
|
|
|
- // 右侧盒子 → 左侧画布
|
|
|
|
|
- this.rightPoints = this.rightPoints.filter(p => p.entityId !== updatedPoint.entityId);
|
|
|
|
|
-
|
|
|
|
|
- // 加入 bindingPoints
|
|
|
|
|
- if (!this.bindingPoints.some(p => p.entityId === updatedPoint.entityId)) {
|
|
|
|
|
- this.bindingPoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 加入 movePoints
|
|
|
|
|
- const existIdx = this.movePoints.findIndex(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
- if (existIdx !== -1) {
|
|
|
|
|
- this.movePoints.splice(existIdx, 1, updatedPoint);
|
|
|
|
|
- } else {
|
|
|
|
|
- this.movePoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 加入左侧画布
|
|
|
|
|
- if (!this.leftPoints.some(p => p.entityName === updatedPoint.entityName)) {
|
|
|
|
|
- this.leftPoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
- } else if (!fromRight && isInRightBox) {
|
|
|
|
|
- // 左侧画布 → 右侧盒子
|
|
|
|
|
- this.leftPoints = this.leftPoints.filter(p => p.entityId !== updatedPoint.entityId);
|
|
|
|
|
-
|
|
|
|
|
- // 加入 unbindingPoints
|
|
|
|
|
- if (!this.unbindingPoints.some(p => p.entityId === updatedPoint.entityId)) {
|
|
|
|
|
- this.unbindingPoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
- if (!this.unbindPointIds.includes(updatedPoint.pointId)) this.unbindPointIds.push(updatedPoint.pointId);
|
|
|
|
|
- // 加入右侧盒子
|
|
|
|
|
- if (!this.rightPoints.some(p => p.entityName === updatedPoint.entityName)) {
|
|
|
|
|
- this.rightPoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
- } else if (isInCabinet) {
|
|
|
|
|
- // 左侧画布内部移动
|
|
|
|
|
- const existIdx = this.movePoints.findIndex(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
- if (existIdx !== -1) {
|
|
|
|
|
- this.movePoints.splice(existIdx, 1, updatedPoint);
|
|
|
|
|
- } else {
|
|
|
|
|
- this.movePoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- // 右侧盒子内部移动:不处理数据
|
|
|
|
|
-
|
|
|
|
|
- // 更新 positions 数组
|
|
|
|
|
- const posIndex = positions.findIndex(p => p.entityName === updatedPoint.entityName);
|
|
|
|
|
- if (posIndex !== -1) {
|
|
|
|
|
- positions[posIndex] = updatedPoint;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.updatePointInJson(updatedPoint, groupPos);
|
|
|
|
|
-
|
|
|
|
|
- this.rightPoints = this.rightPoints.filter(Boolean);
|
|
|
|
|
- this.leftPoints = this.leftPoints.filter(Boolean);
|
|
|
|
|
-
|
|
|
|
|
- this.layer.draw();
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- // 左侧的列表 现在左侧列表通过地图点位接口获取pointList里直接有左侧的数据 不用再去隔离点管理接口拿数据
|
|
|
|
|
- addPointsToLeftPointsBox(filterData) {
|
|
|
|
|
- // 获取接口返回的 leftPoints 数据
|
|
|
|
|
- const pointsData = filterData
|
|
|
|
|
-
|
|
|
|
|
- let row = 1 // 当前行
|
|
|
|
|
- let col = 1 // 当前列
|
|
|
|
|
-
|
|
|
|
|
- // 遍历 pointsData 并根据是否存在于 this.value 中来决定位置
|
|
|
|
|
- pointsData.forEach((point) => {
|
|
|
|
|
- const existingPoint = JSON.parse(this.value).find(
|
|
|
|
|
- (item) => item.pointId == point.pointId
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- // 如果该点在 this.value 中,使用它的原始位置
|
|
|
|
|
- if (existingPoint) {
|
|
|
|
|
- point.row = existingPoint.row
|
|
|
|
|
- point.col = existingPoint.col
|
|
|
|
|
- } else {
|
|
|
|
|
- // 否则,按顺序从 (0, 0) 位置开始,每行三个点
|
|
|
|
|
- point.row = 0
|
|
|
|
|
- point.col = 0
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- // 渲染该点
|
|
|
|
|
- this.renderPoint(point)
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- // 渲染每个点
|
|
|
|
|
- // 渲染每个点
|
|
|
|
|
- renderPoint(point) {
|
|
|
|
|
- const x = point.col * 50; // 每个单元格宽度为50
|
|
|
|
|
- const y = point.row * 50; // 每个单元格高度为50
|
|
|
|
|
- const labelText = point.pointName;
|
|
|
|
|
-
|
|
|
|
|
- const pointImage = new Image();
|
|
|
|
|
- pointImage.src = point.pointIcon;
|
|
|
|
|
-
|
|
|
|
|
- pointImage.onload = () => {
|
|
|
|
|
const group = new Konva.Group({
|
|
const group = new Konva.Group({
|
|
|
- x,
|
|
|
|
|
- y,
|
|
|
|
|
|
|
+ x: x,
|
|
|
|
|
+ y: y,
|
|
|
draggable: true
|
|
draggable: true
|
|
|
- });
|
|
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- // 背景矩形
|
|
|
|
|
- const bgrect = new Konva.Rect({
|
|
|
|
|
- x: -6,
|
|
|
|
|
- y: -5,
|
|
|
|
|
- width: 62,
|
|
|
|
|
- height: 80,
|
|
|
|
|
- cornerRadius: 5,
|
|
|
|
|
|
|
+ // 用圆来展示点位
|
|
|
|
|
+ const circle = new Konva.Circle({
|
|
|
|
|
+ x: 15,
|
|
|
|
|
+ y: 15,
|
|
|
|
|
+ radius: 15,
|
|
|
|
|
+ fill: 'green',
|
|
|
stroke: 'white',
|
|
stroke: 'white',
|
|
|
- strokeWidth: 2,
|
|
|
|
|
- fill: 'white'
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 普通矩形
|
|
|
|
|
- const rect = new Konva.Rect({
|
|
|
|
|
- x: 0,
|
|
|
|
|
- y: -1,
|
|
|
|
|
- width: 50,
|
|
|
|
|
- height: 72,
|
|
|
|
|
- cornerRadius: 5,
|
|
|
|
|
- stroke: 'red',
|
|
|
|
|
- strokeWidth: 2,
|
|
|
|
|
- fill: 'white'
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ strokeWidth: 2
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- // 图片
|
|
|
|
|
- const knovaImage = new Konva.Image({
|
|
|
|
|
|
|
+ const text = new Konva.Text({
|
|
|
x: 0,
|
|
x: 0,
|
|
|
y: 0,
|
|
y: 0,
|
|
|
- image: pointImage,
|
|
|
|
|
- width: 50,
|
|
|
|
|
- height: 50
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 文字
|
|
|
|
|
- const text = new Konva.Text({
|
|
|
|
|
- x: 8,
|
|
|
|
|
- y: 50,
|
|
|
|
|
- fontSize: 17,
|
|
|
|
|
|
|
+ width: 30,
|
|
|
|
|
+ height: 30,
|
|
|
text: labelText,
|
|
text: labelText,
|
|
|
|
|
+ fontSize: 12,
|
|
|
fontFamily: 'Calibri',
|
|
fontFamily: 'Calibri',
|
|
|
- fill: 'red'
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- group.add(bgrect, rect, knovaImage, text);
|
|
|
|
|
- this.layer.add(group);
|
|
|
|
|
|
|
+ fill: 'white',
|
|
|
|
|
+ align: 'center',
|
|
|
|
|
+ verticalAlign: 'middle'
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- // 右侧盒子范围
|
|
|
|
|
- const rightBoxBounds = { x: 1100, y: 15, width: 200, height: 800 };
|
|
|
|
|
|
|
+ group.add(circle)
|
|
|
|
|
+ group.add(text)
|
|
|
|
|
+ this.layer.add(group)
|
|
|
|
|
|
|
|
|
|
+ // 监听拖动结束
|
|
|
group.on('dragend', () => {
|
|
group.on('dragend', () => {
|
|
|
- const groupPos = group.getAbsolutePosition();
|
|
|
|
|
- const rightBoxBounds = { x: 1100, y: 15, width: 200, height: 800 };
|
|
|
|
|
- const isInRightBox =
|
|
|
|
|
- groupPos.x >= rightBoxBounds.x &&
|
|
|
|
|
- groupPos.x <= rightBoxBounds.x + rightBoxBounds.width &&
|
|
|
|
|
- groupPos.y >= rightBoxBounds.y &&
|
|
|
|
|
- groupPos.y <= rightBoxBounds.y + rightBoxBounds.height;
|
|
|
|
|
|
|
+ const groupPos = group.getAbsolutePosition()
|
|
|
|
|
|
|
|
- const newRow = Math.max(0, Math.round(groupPos.x / 50));
|
|
|
|
|
- const newCol = Math.max(0, Math.round(groupPos.y / 50));
|
|
|
|
|
|
|
+ const newRow = Math.max(0, Math.round(groupPos.x / 50))
|
|
|
|
|
+ const newCol = Math.max(0, Math.round(groupPos.y / 50))
|
|
|
|
|
|
|
|
const updatedPoint = {
|
|
const updatedPoint = {
|
|
|
- ...point,
|
|
|
|
|
- row: newRow,
|
|
|
|
|
- col: newCol,
|
|
|
|
|
|
|
+ ...pos,
|
|
|
x: newRow,
|
|
x: newRow,
|
|
|
y: newCol,
|
|
y: newCol,
|
|
|
mapId: this.mapId,
|
|
mapId: this.mapId,
|
|
|
- mapType: this.mapType,
|
|
|
|
|
- entityId: point.pointId,
|
|
|
|
|
- entityName: point.pointName
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const fromRight = this.rightPoints.some(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
- const fromLeft = this.leftPoints.some(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
-
|
|
|
|
|
- // ===== 数据处理 =====
|
|
|
|
|
- if (fromRight && !isInRightBox) {
|
|
|
|
|
- // 右 → 左画布
|
|
|
|
|
- this.rightPoints = this.rightPoints.filter(p => p.pointId !== updatedPoint.pointId);
|
|
|
|
|
-
|
|
|
|
|
- if (!this.leftPoints.some(p => p.pointId === updatedPoint.pointId)) {
|
|
|
|
|
- this.leftPoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
- if (!this.bindingPoints.some(p => p.pointId === updatedPoint.pointId)) {
|
|
|
|
|
- this.bindingPoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const existIdx = this.movePoints.findIndex(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
- if (existIdx !== -1) this.movePoints.splice(existIdx, 1, updatedPoint);
|
|
|
|
|
- else this.movePoints.push(updatedPoint);
|
|
|
|
|
-
|
|
|
|
|
- } else if (fromLeft && isInRightBox) {
|
|
|
|
|
- // 左 → 右盒子
|
|
|
|
|
- this.leftPoints = this.leftPoints.filter(p => p.pointId !== updatedPoint.pointId);
|
|
|
|
|
-
|
|
|
|
|
- if (!this.rightPoints.some(p => p.pointId === updatedPoint.pointId)) {
|
|
|
|
|
- this.rightPoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
- if (!this.unbindingPoints.some(p => p.pointId === updatedPoint.pointId)) {
|
|
|
|
|
- this.unbindingPoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
- if (!this.unbindPointIds.some(p => p.pointId === updatedPoint.pointId)) {
|
|
|
|
|
- this.unbindPointIds.push(updatedPoint.entityId);
|
|
|
|
|
- }
|
|
|
|
|
- } else if (fromLeft && !isInRightBox) {
|
|
|
|
|
- // 左内部移动
|
|
|
|
|
- const existIdx = this.movePoints.findIndex(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
- if (existIdx !== -1) this.movePoints.splice(existIdx, 1, updatedPoint);
|
|
|
|
|
- else this.movePoints.push(updatedPoint);
|
|
|
|
|
|
|
+ mapType: this.mapType
|
|
|
}
|
|
}
|
|
|
- // 右盒子内部移动:不操作
|
|
|
|
|
-
|
|
|
|
|
- // 更新 JSON
|
|
|
|
|
- let positions = JSON.parse(this.value || '[]');
|
|
|
|
|
- const posIndex = positions.findIndex(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
- if (posIndex !== -1) positions[posIndex] = updatedPoint;
|
|
|
|
|
- else positions.push(updatedPoint);
|
|
|
|
|
- this.value = JSON.stringify(positions, null, 4);
|
|
|
|
|
-
|
|
|
|
|
- this.layer.draw();
|
|
|
|
|
-
|
|
|
|
|
- console.log('bindingPoints:', this.bindingPoints);
|
|
|
|
|
- console.log('movePoints:', this.movePoints);
|
|
|
|
|
- console.log('unbindingPoints:', this.unbindingPoints);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.layer.draw();
|
|
|
|
|
- };
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- // 从 json 删除对应的点
|
|
|
|
|
- removePointFromJson(point) {
|
|
|
|
|
- // 更新 leftPoints 和 rightPoints
|
|
|
|
|
- this.rightPoints.push(point)
|
|
|
|
|
- this.unbindPointIds.push(point.pointId) // 给接口传递需要解绑的数据Id
|
|
|
|
|
-
|
|
|
|
|
- // 删除 JSON 中对应的点
|
|
|
|
|
- const updatedData = JSON.parse(this.value).filter(
|
|
|
|
|
- (item) => item.pointId !== point.pointId
|
|
|
|
|
- )
|
|
|
|
|
- this.value = JSON.stringify(updatedData, null, 4)
|
|
|
|
|
-
|
|
|
|
|
- // console.log('Updated value after removal:', this.value)
|
|
|
|
|
- console.log('removePointFromJson', updatedData)
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- // 更新 JSON 中对应点的位置
|
|
|
|
|
- updatePointInJson(point, groupPos) {
|
|
|
|
|
- // 计算新的位置
|
|
|
|
|
- const newCol = Math.round(groupPos.x / 50)
|
|
|
|
|
- const newRow = Math.round(groupPos.y / 50)
|
|
|
|
|
-
|
|
|
|
|
- // 更新 positions 数组中的点位
|
|
|
|
|
- const updatedPosition = {
|
|
|
|
|
- row: newRow,
|
|
|
|
|
- col: newCol,
|
|
|
|
|
- x: newRow,
|
|
|
|
|
- y: newCol,
|
|
|
|
|
- pointId: point.pointId,
|
|
|
|
|
- pointName: point.pointName,
|
|
|
|
|
- entityId: point.pointId,
|
|
|
|
|
- entityName: point.pointName,
|
|
|
|
|
- remark: point.remark,
|
|
|
|
|
- prePointId: point.prePointId,
|
|
|
|
|
- pointType: point.pointType,
|
|
|
|
|
- pointTypeName: point.pointTypeName,
|
|
|
|
|
- powerType: point.powerType,
|
|
|
|
|
- powerTypeName: point.powerTypeName,
|
|
|
|
|
- state: point.state,
|
|
|
|
|
- pointIcon: point.pointIcon,
|
|
|
|
|
- pointPicture: point.pointPicture,
|
|
|
|
|
- mapImg: point.mapImg,
|
|
|
|
|
- mapId: this.mapId,
|
|
|
|
|
- mapType: this.mapType,
|
|
|
|
|
- mapName: '你好5'
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- let positions = JSON.parse(this.value)
|
|
|
|
|
- const index = positions.findIndex(
|
|
|
|
|
- (item) => item.pointId === point.pointId
|
|
|
|
|
- )
|
|
|
|
|
- if (index !== -1) {
|
|
|
|
|
- // positions[index] = updatedPosition;
|
|
|
|
|
- // this.value = JSON.stringify(positions, null, 4);
|
|
|
|
|
- const updatedPositionCopy = JSON.parse(JSON.stringify(updatedPosition))
|
|
|
|
|
- positions[index] = updatedPositionCopy
|
|
|
|
|
-
|
|
|
|
|
- console.log(updatedPositionCopy, positions[index], 'updatedPosition-1')
|
|
|
|
|
- this.value = JSON.stringify(positions, null, 4)
|
|
|
|
|
- } else {
|
|
|
|
|
- // 如果点位不在 this.value 中,则重新插入
|
|
|
|
|
- positions.push(updatedPosition)
|
|
|
|
|
- this.value = JSON.stringify(positions, null, 4)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // console.log('Updated value after update:', this.value)
|
|
|
|
|
- },
|
|
|
|
|
- // 解绑隔离点函数
|
|
|
|
|
- addPointsToRightPointsBox(rightPointsBox) {
|
|
|
|
|
- if (!this.rightPoints || this.rightPoints.length === 0) return;
|
|
|
|
|
-
|
|
|
|
|
- const boxWidth = rightPointsBox.width();
|
|
|
|
|
- const boxHeight = rightPointsBox.height();
|
|
|
|
|
- const boxX = rightPointsBox.x();
|
|
|
|
|
- const boxY = rightPointsBox.y();
|
|
|
|
|
- const padding = 10;
|
|
|
|
|
- const pointWidth = 50;
|
|
|
|
|
- const pointHeight = 70;
|
|
|
|
|
-
|
|
|
|
|
- let currentX = boxX + padding;
|
|
|
|
|
- let currentY = boxY + padding;
|
|
|
|
|
-
|
|
|
|
|
- const rightBoxBounds = { x: 1100, y: 15, width: 200, height: 800 };
|
|
|
|
|
- const cabinetBounds = { x: 330, y: 10, width: 500, height: 790 };
|
|
|
|
|
-
|
|
|
|
|
- this.rightPoints.forEach((point) => {
|
|
|
|
|
- const initialLocation = 'right';
|
|
|
|
|
-
|
|
|
|
|
- const pointData = {
|
|
|
|
|
- ...point,
|
|
|
|
|
- entityId: point.entityId || point.pointId,
|
|
|
|
|
- entityName: point.entityName || point.pointName,
|
|
|
|
|
- mapId: point.mapId || this.mapId,
|
|
|
|
|
- mapType: point.mapType || this.mapType
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const group = new Konva.Group({
|
|
|
|
|
- x: currentX,
|
|
|
|
|
- y: currentY + 14,
|
|
|
|
|
- draggable: true
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 红色边框
|
|
|
|
|
- const borderRect = new Konva.Rect({
|
|
|
|
|
- x: 0,
|
|
|
|
|
- y: 0,
|
|
|
|
|
- width: pointWidth,
|
|
|
|
|
- height: pointHeight,
|
|
|
|
|
- cornerRadius: 5,
|
|
|
|
|
- stroke: 'red',
|
|
|
|
|
- strokeWidth: 2,
|
|
|
|
|
- fill: 'white'
|
|
|
|
|
- });
|
|
|
|
|
- group.add(borderRect);
|
|
|
|
|
-
|
|
|
|
|
- // 图片
|
|
|
|
|
- const image = new Image();
|
|
|
|
|
- image.src = point.pointIcon;
|
|
|
|
|
- image.onload = () => {
|
|
|
|
|
- const knovaImage = new Konva.Image({
|
|
|
|
|
- x: 1,
|
|
|
|
|
- y: 5,
|
|
|
|
|
- image: image,
|
|
|
|
|
- width: 50,
|
|
|
|
|
- height: 50
|
|
|
|
|
- });
|
|
|
|
|
- group.add(knovaImage);
|
|
|
|
|
-
|
|
|
|
|
- // 文字
|
|
|
|
|
- const pointText = new Konva.Text({
|
|
|
|
|
- x: 12,
|
|
|
|
|
- y: 53,
|
|
|
|
|
- text: point.pointName,
|
|
|
|
|
- fontSize: 12,
|
|
|
|
|
- fill: 'red'
|
|
|
|
|
- });
|
|
|
|
|
- group.add(pointText);
|
|
|
|
|
-
|
|
|
|
|
- this.layer.add(group);
|
|
|
|
|
- this.groups[point.pointName] = group;
|
|
|
|
|
-
|
|
|
|
|
- // 拖拽移动
|
|
|
|
|
- group.on('dragmove', () => {
|
|
|
|
|
- const pos = group.getAbsolutePosition();
|
|
|
|
|
- group.x(pos.x);
|
|
|
|
|
- group.y(pos.y);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 拖拽结束
|
|
|
|
|
- group.on('dragend', () => {
|
|
|
|
|
- const gridX = 50;
|
|
|
|
|
- const gridY = 50;
|
|
|
|
|
-
|
|
|
|
|
- const snappedX = Math.round(group.x() / gridX) * gridX;
|
|
|
|
|
- const snappedY = Math.round(group.y() / gridY) * gridY;
|
|
|
|
|
- group.x(snappedX);
|
|
|
|
|
- group.y(snappedY);
|
|
|
|
|
-
|
|
|
|
|
- const row = Math.floor(snappedY / gridY);
|
|
|
|
|
- const col = Math.floor(snappedX / gridX);
|
|
|
|
|
-
|
|
|
|
|
- const updatedPoint = { ...pointData, row, col, x: col, y: row };
|
|
|
|
|
-
|
|
|
|
|
- const inRightBox =
|
|
|
|
|
- snappedX >= rightBoxBounds.x &&
|
|
|
|
|
- snappedX <= rightBoxBounds.x + rightBoxBounds.width &&
|
|
|
|
|
- snappedY >= rightBoxBounds.y &&
|
|
|
|
|
- snappedY <= rightBoxBounds.y + rightBoxBounds.height;
|
|
|
|
|
-
|
|
|
|
|
- const inCabinet =
|
|
|
|
|
- snappedX >= cabinetBounds.x &&
|
|
|
|
|
- snappedX <= cabinetBounds.x + cabinetBounds.width &&
|
|
|
|
|
- snappedY >= cabinetBounds.y &&
|
|
|
|
|
- snappedY <= cabinetBounds.y + cabinetBounds.height;
|
|
|
|
|
-
|
|
|
|
|
- // ===== 数据处理 =====
|
|
|
|
|
- if (initialLocation === 'right' && inCabinet) {
|
|
|
|
|
- // 右 → 左
|
|
|
|
|
- this.rightPoints = this.rightPoints.filter(p => p.pointId !== point.pointId);
|
|
|
|
|
- if (!this.leftPoints.some(p => p.pointId === updatedPoint.pointId)) this.leftPoints.push(updatedPoint);
|
|
|
|
|
- if (!this.bindingPoints.some(p => p.pointId === updatedPoint.pointId)) this.bindingPoints.push(updatedPoint);
|
|
|
|
|
- if (!this.bindingPointIds) this.bindingPointIds = [];
|
|
|
|
|
- if (!this.bindingPointIds.includes(updatedPoint.pointId)) this.bindingPointIds.push(updatedPoint.pointId);
|
|
|
|
|
-
|
|
|
|
|
- const existIdx = this.movePoints.findIndex(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
- if (existIdx !== -1) this.movePoints.splice(existIdx, 1, updatedPoint);
|
|
|
|
|
- else this.movePoints.push(updatedPoint);
|
|
|
|
|
-
|
|
|
|
|
- } else if (initialLocation === 'left' && inRightBox) {
|
|
|
|
|
- // 左 → 右盒子
|
|
|
|
|
- this.leftPoints = this.leftPoints.filter(p => p.pointId !== point.pointId);
|
|
|
|
|
- if (!this.rightPoints.some(p => p.pointId === updatedPoint.pointId)) this.rightPoints.push(updatedPoint);
|
|
|
|
|
- if (!this.unbindingPoints.some(p => p.pointId === updatedPoint.pointId)) this.unbindingPoints.push(updatedPoint);
|
|
|
|
|
- if (!this.unbindPointIds) this.unbindPointIds = [];
|
|
|
|
|
- if (!this.unbindPointIds.includes(updatedPoint.pointId)) this.unbindPointIds.push(updatedPoint.pointId);
|
|
|
|
|
-
|
|
|
|
|
- } else if (initialLocation === 'left' && inCabinet) {
|
|
|
|
|
- // 左内部移动
|
|
|
|
|
- const existIdx = this.movePoints.findIndex(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
- if (existIdx !== -1) this.movePoints.splice(existIdx, 1, updatedPoint);
|
|
|
|
|
- else this.movePoints.push(updatedPoint);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 更新 JSON
|
|
|
|
|
- let valueArray = [];
|
|
|
|
|
- try { valueArray = JSON.parse(this.value || '[]'); } catch (e) { valueArray = []; }
|
|
|
|
|
- const valIdx = valueArray.findIndex(p => p.pointId === updatedPoint.pointId);
|
|
|
|
|
- if (valIdx !== -1) valueArray[valIdx] = updatedPoint;
|
|
|
|
|
- else valueArray.push(updatedPoint);
|
|
|
|
|
- this.value = JSON.stringify(valueArray, null, 4);
|
|
|
|
|
-
|
|
|
|
|
- this.layer.draw();
|
|
|
|
|
-
|
|
|
|
|
- console.log('bindingPoints:', this.bindingPoints);
|
|
|
|
|
- console.log('bindingPointIds:', this.bindingPointIds);
|
|
|
|
|
- console.log('movePoints:', this.movePoints);
|
|
|
|
|
- console.log('unbindingPoints:', this.unbindingPoints);
|
|
|
|
|
- console.log('unbindPointIds:', this.unbindPointIds);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // 更新 movePoints,如果存在就替换
|
|
|
|
|
+ const existIdx = this.movePoints.findIndex(p => p.pointId === updatedPoint.pointId)
|
|
|
|
|
+ if (existIdx !== -1) {
|
|
|
|
|
+ this.movePoints.splice(existIdx, 1, updatedPoint)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.movePoints.push(updatedPoint)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- this.layer.draw();
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ console.log(this.movePoints, '更新后的 movePoints')
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- // 更新下一个隔离点位置
|
|
|
|
|
- currentX += pointWidth + padding;
|
|
|
|
|
- if (currentX + pointWidth > boxX + boxWidth) {
|
|
|
|
|
- currentX = boxX + padding;
|
|
|
|
|
- currentY += pointHeight + padding;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ this.layer.draw()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|