Files
admin-govern/src/views/govern/manage/gplot/popupEdit.vue

176 lines
5.7 KiB
Vue
Raw Normal View History

2024-01-17 14:22:34 +08:00
<template>
2024-01-26 13:43:54 +08:00
<el-dialog class="cn-operate-dialog" v-model="dialogVisible" title="编辑拓扑图信息">
<el-form :label-width="140">
<el-form-item label="拓扑图:" style="height: auto !important">
<div class="gplot-content">
<VueDraggableResizable
class-name-draggable="gplot-content-item"
class-name-active="gplot-content-item-active"
:active="editorIndex == index"
:resizable="false"
:parent="true"
:x="item.left"
:y="item.top"
:w="item.width"
:h="item.height"
@dragStart="editorIndex = index"
@dragging="resize"
v-for="(item, index) in pointList"
:key="index"
:isResizable="false"
>
<div
class="text"
style="line-height: 20px; white-space: nowrap"
:style="{ color: item.name === '监测点' ? 'red' : 'black' }"
>
{{ item.name }}
</div>
</VueDraggableResizable>
<img
:src="imgUrl"
class="gplot-content"
style="border: 1px solid #dcdfe6; position: unset; user-select: none"
draggable="false"
/>
2024-01-17 15:52:51 +08:00
<div>注意监测点不要移出圈</div>
</div>
</el-form-item>
2024-01-26 13:43:54 +08:00
<el-form-item label="监测点位置:" v-if="editorIndex > -1">
<div style="display: flex">
2024-01-17 15:52:51 +08:00
<el-select
2024-01-26 13:43:54 +08:00
v-model="pointList[editorIndex].position"
placeholder="请选择"
style="flex: 1"
@change="positionChange"
2024-01-17 15:52:51 +08:00
>
<el-option
2024-01-26 13:43:54 +08:00
v-for="item in linePosition"
:key="item.id"
:label="item.name"
:value="item.id"
2024-01-17 15:52:51 +08:00
></el-option>
</el-select>
2024-01-26 13:43:54 +08:00
<el-button class="ml20" type="danger" @click="deletePoint" icon="el-icon-Delete">删除</el-button>
2024-01-17 15:52:51 +08:00
</div>
</el-form-item>
2024-01-26 13:43:54 +08:00
<el-form-item label=" ">
<el-button type="primary" @click="addPoint">添加监测点</el-button>
2024-01-17 15:52:51 +08:00
</el-form-item>
</el-form>
2024-01-17 14:22:34 +08:00
<template #footer>
2024-01-26 13:43:54 +08:00
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submit">确认</el-button>
2024-01-17 14:22:34 +08:00
</span>
</template>
</el-dialog>
</template>
2024-01-26 13:43:54 +08:00
<script lang="ts" setup>
2024-01-17 14:22:34 +08:00
import { ref, inject } from 'vue'
import { reactive } from 'vue'
import TableStore from '@/utils/tableStore'
2024-01-17 15:52:51 +08:00
import { useDictData } from '@/stores/dictData'
import { fullUrl } from '@/utils/common'
2024-01-26 13:43:54 +08:00
import VueDraggableResizable from 'vue-draggable-resizable'
import { ElMessage } from 'element-plus'
import { addLineTemplate } from '@/api/cs-device-boot/lineTemplate'
2024-01-17 15:52:51 +08:00
defineOptions({
2024-01-26 13:43:54 +08:00
name: 'govern/manage/gplot/popupEdit'
2024-01-17 14:22:34 +08:00
})
2024-01-17 15:52:51 +08:00
const tableStore = inject('tableStore') as TableStore
const editorIndex = ref(-1)
2024-01-26 13:43:54 +08:00
const pointList = ref<any[]>([])
2024-01-17 15:52:51 +08:00
const topoId = ref()
const imgUrl = ref('')
const linePosition = useDictData().getBasicData('Line_Position')
2024-01-17 14:22:34 +08:00
const dialogVisible = ref(false)
2024-01-26 13:43:54 +08:00
const open = (data: anyObj) => {
pointList.value = data.csLineTopologyTemplateVOList.map((item: any) => {
return {
name: linePosition.find(item2 => {
return item2.id == item.linePostion
})?.name,
position: item.linePostion,
width: 'auto',
height: 20,
top: item.lng,
left: item.lat
}
})
2024-01-17 15:52:51 +08:00
topoId.value = data.id
imgUrl.value = fullUrl(data.filePath)
2024-01-17 14:22:34 +08:00
dialogVisible.value = true
}
2024-01-26 13:43:54 +08:00
const positionChange = (e: string) => {
pointList.value[editorIndex.value].name = linePosition.find((item: any) => {
return item.id == e
})?.name
2024-01-17 15:52:51 +08:00
}
2024-01-26 13:43:54 +08:00
const resize = (left: number, top: number) => {
const dom = pointList.value[editorIndex.value]
dom.left = left
dom.top = top
2024-01-17 15:52:51 +08:00
}
const addPoint = () => {
2024-01-26 13:43:54 +08:00
pointList.value.push({
name: '监测点',
position: '',
width: 'auto',
height: 20,
top: 100,
left: 100
})
editorIndex.value = pointList.value.length - 1
2024-01-17 15:52:51 +08:00
}
const deletePoint = () => {
2024-01-26 13:43:54 +08:00
pointList.value.splice(editorIndex.value, 1)
editorIndex.value = -1
2024-01-17 15:52:51 +08:00
}
2024-01-17 14:22:34 +08:00
const submit = async () => {
2024-01-26 13:43:54 +08:00
let allSelect = pointList.value.some(item => item.position === '')
if (allSelect) {
ElMessage.warning('请完善所有监测点位置')
return
}
let arr = pointList.value.map(item => {
return {
linePostion: item.position,
lat: item.left,
lng: item.top,
topoId: topoId.value
}
})
addLineTemplate(arr).then(res => {
ElMessage.success('保存成功')
tableStore.index()
dialogVisible.value = false
})
2024-01-17 14:22:34 +08:00
}
defineExpose({ open })
</script>
2024-01-17 15:52:51 +08:00
2024-01-26 13:43:54 +08:00
<style lang="scss">
@import 'vue-draggable-resizable/style.css';
2024-01-17 15:52:51 +08:00
.gplot-content {
2024-01-26 13:43:54 +08:00
position: relative;
2024-01-17 15:52:51 +08:00
width: 375px;
object-fit: cover;
2024-01-26 13:43:54 +08:00
overflow: hidden;
.gplot-content-item {
border-color: transparent;
cursor: move;
&-active {
border-color: red;
}
}
2024-01-17 15:52:51 +08:00
}
</style>