From 0390f5ab4b062a9146cd7d92bdd91954a052e13d Mon Sep 17 00:00:00 2001 From: cloudroam <cloudroam> Date: 星期五, 22 十一月 2024 14:58:09 +0800 Subject: [PATCH] add: 区域配置 --- src/views/screen1/itm-map-plant-board.vue | 275 ++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 194 insertions(+), 81 deletions(-) diff --git a/src/views/screen1/itm-map-plant-board.vue b/src/views/screen1/itm-map-plant-board.vue index 702b3a5..b02feee 100644 --- a/src/views/screen1/itm-map-plant-board.vue +++ b/src/views/screen1/itm-map-plant-board.vue @@ -14,7 +14,7 @@ :scale-ratio="0.7" :style="{ - backgroundImage: `url(${imgSrc})`, + backgroundImage: `url(${item.imgSrc})`, backgroundSize: 'cover', backgroundPosition: 'center', backgroundRepeat: 'no-repeat', @@ -87,15 +87,22 @@ <li @click="handleDel()">删除</li> </ul> + <div> + <add-area-item ref="addAreaItem" :menuPositionx ="this.menuPosition.x" :menu-positiony="this.menuPosition.y" @update-area-list="getAreaItemList"></add-area-item> + </div> + </div> </template> <script> import A27 from '@/assets/screen/screen5/svgs3d/A27.svg' +import AddAreaItem from "@/components/add-area-item"; import { itmmapdata } from "./itm-map.js"; +import {addAreaItemInfo, deleteAreaModuleItem, getAreaItemData, updateAreaModuleItem} from "@/api/addareaitem"; export default { + components: {AddAreaItem}, props: { no: { type: Number, @@ -116,67 +123,68 @@ hLine: [], items:[ - { - x:300, - y:300, - w:200, - h:200, - t:'', - s:'', - n:'', - areacode:'', - t_c:'', - t_c_1:'', - tl:'', - stand:'', - imgSrc:A27, - }, - { - x:0, - y:0, - w:200, - h:200, - t:'测试一区', - s:'', - n:'', - areacode:'01', - t_c:'', - t_c_1:'', - tl:'', - stand:'', - imgSrc:A27, - }, - { - x:0, - y:0, - w:200, - h:200, - t:'测试一区', - s:'', - n:'', - areacode:'01', - t_c:'', - t_c_1:'', - tl:'', - stand:'', - imgSrc:A27, - }, - { - x:120, - y:120, - w:200, - h:200, - t:'测试二区', - s:'', - n:'', - areacode:'02', - t_c:'', - t_c_1:'', - tl:'', - stand:'', - imgSrc:A27, - }, + // { + // x:300, + // y:300, + // w:200, + // h:200, + // t:'', + // s:'', + // n:'', + // areacode:'', + // t_c:'', + // t_c_1:'', + // tl:'', + // stand:'', + // imgSrc:A27, + // }, + // { + // x:0, + // y:0, + // w:200, + // h:200, + // t:'测试一区', + // s:'', + // n:'', + // areacode:'01', + // t_c:'', + // t_c_1:'', + // tl:'', + // stand:'', + // imgSrc:A27, + // }, + // { + // x:0, + // y:0, + // w:200, + // h:200, + // t:'测试一区', + // s:'', + // n:'', + // areacode:'01', + // t_c:'', + // t_c_1:'', + // tl:'', + // stand:'', + // imgSrc:A27, + // }, + // { + // x:120, + // y:120, + // w:200, + // h:200, + // t:'测试二区', + // s:'', + // n:'', + // areacode:'02', + // t_c:'', + // t_c_1:'', + // tl:'', + // stand:'', + // imgSrc:A27, + // }, ], + adjustedItem: [], isElementMenuVisible: false, // 控制菜单显示 elementMenuPosition: { x: 0, y: 0 }, // 菜单位置 @@ -190,6 +198,8 @@ plantBoardFlag:false, // 是否画布局 hoveredItem:{}, + deleteItem:{}, + editItem:{}, areaVisible:false, areaPosition: { x: 0, y: 0 }, @@ -199,6 +209,7 @@ mounted() { document.addEventListener("click", this.hideMenu); + this.getAreaItemList(); }, beforeUnmount() { document.removeEventListener("click", this.hideMenu); @@ -240,18 +251,27 @@ this.y = y console.log(`x:${this.x},y:${this.y}`) }, - onDragStop: function (itemParam) { + onDragStop: async function (itemParam) { console.log("停止拖拽") console.log(`x:${this.x},y:${this.y}`) - console.log(itemParam) - itemParam.x = this.x - itemParam.y = this.y - - // TODO 需要更新元素操作 + console.log("itemParam", itemParam) + if(this.x !=itemParam.x && this.y !=itemParam.y && this.w !=itemParam.w && this.h !=itemParam.h){ + itemParam.x = this.x + itemParam.y = this.y + var dto = { + xVal: itemParam.x, + yVal: itemParam.y, + id: itemParam.id + }; + //更新元素操作 + const re = await updateAreaModuleItem(dto); + if (re.isSuccess) { + this.$message.success("更新成功"); + } + } }, - onResizeStop: function (itemParam) { - + onResizeStop: async function (itemParam) { console.log("停止resize") console.log(`x:${this.x},y:${this.y},width:${this.width},height:${this.height}`) console.log(itemParam) @@ -259,10 +279,17 @@ // itemParam.y=this.y itemParam.w = this.width itemParam.h = this.height - - // TODO 需要更新元素操作 - - + var dto = { + wVal: itemParam.w, + hVal: itemParam.h, + id: itemParam.id + }; + //更新元素操作 + const re = await updateAreaModuleItem(dto); + if (re.isSuccess) { + this.$message.success("更新成功"); + this.open = false; + } }, onActivated: function (itemParam) { @@ -300,6 +327,9 @@ event.stopPropagation(); // 阻止冒泡 this.elementMenuPosition = { x: item.x + item.w, y: item.y }; this.isElementMenuVisible = true; + console.log("item",item); + this.deleteItem = item; + this.editItem = item; // 点击其他地方时隐藏菜单 document.addEventListener("click", this.hideElementMenu); @@ -313,23 +343,106 @@ // 更新操作 handleUpdate() { - // TODO - alert(`You selected:handleUpdate`); + //编辑操作 this.hideElementMenu(); + console.log("this.editItem",this.editItem); + this.$refs.addAreaItem && this.$refs.addAreaItem.editConfig(this.editItem); + this.hideMenu(); }, // 删除操作 - handleDel() { - // TODO - alert(`You selected:handleDel`); + async handleDel() { + // 删除 + console.log("this.deleteItem",this.deleteItem); + const re = await deleteAreaModuleItem(this.deleteItem.id); + if (re.isSuccess) { + this.$message.success("删除成功"); + this.getAreaItemList(); + } this.hideElementMenu(); }, // 新增操作 handleAdd() { - // TODO - alert(`You selected:handleAdd`); - // this.hideElementMenu(); + this.$refs.addAreaItem && this.$refs.addAreaItem.openConfig(); this.hideMenu(); }, + // async getAreaItemList(){ + // debugger; + // const result = await getAreaItemData(); // 假设这是一个返回Promise的函数 + // this.adjustedItem = result.data; // 将解决后的数据赋值给itemData + // console.log(" adjustedItem", this.adjustedItem) + // let items = []; + // + // Object.keys(this.adjustedItem).forEach(key => { + // switch (key) { + // case 'xVal': + // items.x = this.adjustedItem[key]; + // break; + // case 'yVal': + // items.y = this.adjustedItem[key]; + // break; + // case 'areacode': + // items.areacode = this.adjustedItem[key]; + // break; + // case 'uRL': + // items.imgSrc = this.adjustedItem[key]; + // break; + // // 添加其他需要转换的键值对 + // default: + // // 如果不需要转换,直接赋值 + // // items[key] = this.adjustedItem[key]; + // } + // }); + // this.items = items; + // console.log(" this.items", this.items) + // }, + async getAreaItemList() { + const result = await getAreaItemData(); // 假设这是一个返回Promise的函数 + this.adjustedItem = result.data; // 将解决后的数据赋值给itemData + console.log(" adjustedItem", this.adjustedItem); + let items = []; + this.adjustedItem.forEach((item, index) => { + let newItem = {}; + if (item.xVal !== undefined) { + newItem.x = parseInt(item.xVal, 10); + } + if (item.yVal !== undefined) { + newItem.y = parseInt(item.yVal, 10); + } + if (item.areacode !== undefined) { + newItem.areacode = item.areacode; + } + if (item.url !== undefined) { + newItem.imgSrc = item.url; + } + if (item.id !== undefined) { + newItem.id = item.id; + } + if (item.wVal !== undefined) { + newItem.w = parseInt(item.wVal, 10); + } + if (item.hVal !== undefined) { + newItem.h = parseInt(item.hVal, 10); + } + if (item.tVal !== undefined) { + newItem.t = item.tVal; + } + newItem.areaBackGroudURL = item.areaBackGroudURL; + newItem.areaConfigNum = item.areaConfigNum; + newItem.moduleName = item.moduleName; + newItem.areaBackGroudName = item.areaBackGroudName; + newItem.s = ''; + newItem.n = ''; + newItem.t_c = ''; + newItem.t_c_1 = ''; + newItem.tl = ''; + newItem.stand = ''; + items.push(newItem); + }); + + this.items = items; + console.log(" this.items", this.items); + }, + evalA(string) { -- Gitblit v1.9.3