| | |
| | | <template> |
| | | <el-dialog v-model="visible" class="ztzf-page-map-view-dialog" :show-close="false" :close-on-click-modal="false" |
| | | destroy-on-close @closed="handleClosed"> |
| | | <el-dialog |
| | | v-model="visible" |
| | | class="ztzf-page-map-view-dialog" |
| | | :show-close="false" |
| | | :close-on-click-modal="false" |
| | | destroy-on-close |
| | | @closed="handleClosed" |
| | | > |
| | | <div class="dialog-container"> |
| | | <div class="left-container"> |
| | | <div class="leftMap ztzf-cesium" id="detectionRangeMap"></div> |
| | |
| | | <div class="val">{{ formData.deviceModel || '-' }}</div> |
| | | </el-col> |
| | | <el-col :span="24"> |
| | | <div class="label">覆盖范围</div> |
| | | <div class="label">覆盖范围(m)</div> |
| | | <div class="val">{{ formatRange(formData.effectiveRangeKm) }}</div> |
| | | </el-col> |
| | | </el-row> |
| | | </div> |
| | | |
| | | <el-form v-else ref="formRef" class="dialog-form" :model="formData" :rules="rules" label-width="96px"> |
| | | <el-form v-else ref="formRef" class="dialog-form" :model="formData" :rules="rules" label-width="110px"> |
| | | <el-form-item label="侦测设备" prop="deviceId"> |
| | | <el-select class="ztzf-data-cockpit-select" popper-class="ztzf-data-cockpit-select-popper" |
| | | v-model="formData.deviceId" placeholder="请选择" clearable @change="handleDeviceChange"> |
| | | <el-option v-for="item in deviceOptions" :key="item.value" :label="item.label" |
| | | :value="item.value" /> |
| | | <el-select |
| | | class="ztzf-data-cockpit-select" |
| | | popper-class="ztzf-data-cockpit-select-popper" |
| | | v-model="formData.deviceId" |
| | | placeholder="请选择" |
| | | clearable |
| | | @change="handleDeviceChange" |
| | | > |
| | | <el-option v-for="item in deviceOptions" :key="item.value" :label="item.label" :value="item.value" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="设备类型" prop="deviceType"> |
| | | <el-select class="ztzf-data-cockpit-select" popper-class="ztzf-data-cockpit-select-popper" |
| | | v-model="formData.deviceType" placeholder="请选择" clearable> |
| | | <el-option v-for="item in dictObj.deviceType" :key="item.dictKey" :label="item.dictValue" |
| | | :value="item.dictKey" /> |
| | | <el-select |
| | | class="ztzf-data-cockpit-select" |
| | | popper-class="ztzf-data-cockpit-select-popper" |
| | | v-model="formData.deviceType" |
| | | placeholder="请选择" |
| | | clearable |
| | | > |
| | | <el-option |
| | | v-for="item in dictObj.deviceType" |
| | | :key="item.dictKey" |
| | | :label="item.dictValue" |
| | | :value="item.dictKey" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="设备位置" prop="deployLocation"> |
| | | <el-input class="ztzf-data-cockpit-search-input" v-model="formData.deployLocation" |
| | | placeholder="请选择位置"> |
| | | <el-input |
| | | class="ztzf-data-cockpit-search-input" |
| | | v-model="formData.deployLocation" |
| | | disabled |
| | | placeholder="请选择位置" |
| | | > |
| | | <template #suffix> |
| | | <span class="suffix-action">地图选点</span> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="设备编号" prop="deviceSn"> |
| | | <el-input class="ztzf-data-cockpit-search-input" v-model="formData.deviceSn" placeholder="请输入" |
| | | clearable /> |
| | | <el-input |
| | | class="ztzf-data-cockpit-search-input" |
| | | v-model="formData.deviceSn" |
| | | placeholder="请输入" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="设备型号" prop="deviceModel"> |
| | | <el-input class="ztzf-data-cockpit-search-input" v-model="formData.deviceModel" |
| | | placeholder="请输入" clearable /> |
| | | <el-input |
| | | class="ztzf-data-cockpit-search-input" |
| | | v-model="formData.deviceModel" |
| | | placeholder="请输入" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="覆盖范围" prop="effectiveRangeKm"> |
| | | <el-input-number class="ztzf-data-cockpit-search-input" v-model="formData.effectiveRangeKm" :min="0" :precision="2" :controls="false" |
| | | placeholder="请输入" /> |
| | | <el-form-item label="覆盖范围(m)" prop="effectiveRangeKm"> |
| | | <el-input-number |
| | | class="ztzf-data-cockpit-search-input" |
| | | v-model="formData.effectiveRangeKm" |
| | | :min="0" |
| | | :precision="2" |
| | | :controls="false" |
| | | placeholder="请输入" |
| | | /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div class="footer"> |
| | | <el-button color="#2B2B4C" @click="handleCancel">{{ dialogReadonly ? '关闭' : '取消' }}</el-button> |
| | | <el-button color="#284FE3" v-if="!dialogReadonly" type="primary" :loading="submitting" |
| | | :disabled="submitting" @click="handleSubmit"> |
| | | <el-button |
| | | color="#284FE3" |
| | | v-if="!dialogReadonly" |
| | | type="primary" |
| | | :loading="submitting" |
| | | :disabled="submitting" |
| | | @click="handleSubmit" |
| | | > |
| | | 保存 |
| | | </el-button> |
| | | </div> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { computed, inject, nextTick, ref } from 'vue' |
| | | import { computed, inject, nextTick, ref, watch } from 'vue' |
| | | import { ElMessage } from 'element-plus' |
| | | import { |
| | | detectionRangeDetailApi, |
| | |
| | | } from '@/api/detectionCountermeasure/detectionRange' |
| | | import { PublicCesium } from '@/utils/cesium/publicCesium' |
| | | import * as Cesium from 'cesium' |
| | | import deviceZcImg from '@/assets/images/dataCockpit/device-zc.svg' |
| | | |
| | | const initForm = () => ({ |
| | | deviceId: '', // 侦测设备ID |
| | |
| | | const emit = defineEmits(['success']) |
| | | const formRef = ref(null) // 表单实例 |
| | | const formData = ref(initForm()) // 表单数据 |
| | | const visible = ref(false) // 弹框显隐 |
| | | const visible = defineModel() // 弹框显隐 |
| | | const dialogMode = ref('add') // 弹框模式 |
| | | const submitting = ref(false) // 提交中 |
| | | const deviceOptions = ref([]) |
| | | const dialogReadonly = computed(() => dialogMode.value === 'view') |
| | | let viewer |
| | | let redPointEntity |
| | | let rangeCircleEntity |
| | | const formTitle = computed(() => { |
| | | if (dialogMode.value === 'edit') { |
| | | return '编辑侦测范围' |
| | |
| | | effectiveRangeKm: [{ required: true, message: '请输入覆盖范围', trigger: ['blur', 'change'] }], |
| | | } |
| | | |
| | | function handleDeviceChange (value) { |
| | | function handleDeviceChange(value) { |
| | | const target = deviceOptions.value.find(item => item.value === value) |
| | | const raw = target?.raw |
| | | if (!raw) return |
| | |
| | | raw.deployLocation ?? raw.address ?? raw.location ?? raw.deployAddress ?? formData.value.deployLocation |
| | | } |
| | | |
| | | function getDeviceTypeLabel (value) { |
| | | function getDeviceTypeLabel(value) { |
| | | const list = dictObj?.deviceType ?? [] |
| | | const target = list.find(item => item.dictKey === value) |
| | | return target?.dictValue ?? value ?? '-' |
| | | } |
| | | |
| | | function formatRange (value) { |
| | | function formatRange(value) { |
| | | if (value == null || value === '') return '-' |
| | | return `${value}km` |
| | | return `${value}` |
| | | } |
| | | |
| | | // 关闭弹框 |
| | | function handleCancel () { |
| | | function handleCancel() { |
| | | visible.value = false |
| | | } |
| | | |
| | | // 提交新增/编辑 |
| | | async function handleSubmit () { |
| | | async function handleSubmit() { |
| | | const isValid = await formRef.value?.validate().catch(() => false) |
| | | if (!isValid) return |
| | | submitting.value = true |
| | |
| | | } |
| | | |
| | | // 加载详情 |
| | | async function loadDetail (id) { |
| | | async function loadDetail(id) { |
| | | if (!id) return null |
| | | const res = await detectionRangeDetailApi({ id }) |
| | | return res?.data?.data ?? null |
| | | } |
| | | |
| | | async function loadDeviceOptions () { |
| | | async function loadDeviceOptions() { |
| | | const res = await detectionRangePageApi({ |
| | | current: 1, |
| | | size: 200, |
| | |
| | | } |
| | | |
| | | // 关闭后重置 |
| | | function handleClosed () { |
| | | function handleClosed() { |
| | | formData.value = initForm() |
| | | clearRangeCircle() |
| | | viewer = null |
| | | redPointEntity = null |
| | | rangeCircleEntity = null |
| | | } |
| | | |
| | | function setMapPoint (longitude, latitude) { |
| | | function setMapPoint(longitude, latitude) { |
| | | if (!viewer || longitude == null || latitude == null) return |
| | | if (!redPointEntity) { |
| | | redPointEntity = viewer.entities.add({ |
| | | position: Cesium.Cartesian3.fromDegrees(longitude, latitude), |
| | | point: { |
| | | color: Cesium.Color.RED, |
| | | pixelSize: 10, |
| | | billboard: { |
| | | image: deviceZcImg, // 这里替换为你的图片路径或变量 deviceZcImg |
| | | width: 30, // 可选:设置图片宽度 |
| | | height: 42, // 可选:设置图片高度 |
| | | verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // 设置图片底部对齐坐标点 |
| | | }, |
| | | label: { |
| | | text: `${longitude.toFixed(6)}, ${latitude.toFixed(6)}`, |
| | | font: '14px', |
| | | font: '16px', |
| | | fillColor: Cesium.Color.WHITE, |
| | | backgroundColor: Cesium.Color.BLACK.withAlpha(0.45), |
| | | backgroundPadding: new Cesium.Cartesian2(5, 5), |
| | | pixelOffset: new Cesium.Cartesian2(0, -20), |
| | | showBackground: true, |
| | | style: Cesium.LabelStyle.FILL_AND_OUTLINE, |
| | | horizontalOrigin: Cesium.HorizontalOrigin.CENTER, |
| | | verticalOrigin: Cesium.VerticalOrigin.CENTER, |
| | | outlineWidth: 1, |
| | | outlineColor: Cesium.Color.WHITE, |
| | | pixelOffset: new Cesium.Cartesian2(0, -60), |
| | | eyeOffset: new Cesium.Cartesian3(0, 0, -20), |
| | | }, |
| | | }) |
| | |
| | | redPointEntity.position = Cesium.Cartesian3.fromDegrees(longitude, latitude) |
| | | redPointEntity.label.text = `${longitude.toFixed(6)}, ${latitude.toFixed(6)}` |
| | | } |
| | | updateRangeCircle(longitude, latitude, formData.value.effectiveRangeKm) |
| | | } |
| | | |
| | | function initMap () { |
| | | function parseDeployLocation(value) { |
| | | if (!value) return null |
| | | const [longitude, latitude] = value.split(',').map(item => Number(item.trim())) |
| | | if (Number.isNaN(longitude) || Number.isNaN(latitude)) return null |
| | | return { longitude, latitude } |
| | | } |
| | | |
| | | function clearRangeCircle() { |
| | | if (viewer && rangeCircleEntity) { |
| | | viewer.entities.remove(rangeCircleEntity) |
| | | } |
| | | } |
| | | |
| | | function updateRangeCircle(longitude, latitude, range) { |
| | | if (!viewer || longitude == null || latitude == null) return |
| | | const rangeMeters = Number(range) |
| | | if (!Number.isFinite(rangeMeters) || rangeMeters <= 0) { |
| | | clearRangeCircle() |
| | | rangeCircleEntity = null |
| | | return |
| | | } |
| | | const position = Cesium.Cartesian3.fromDegrees(longitude, latitude) |
| | | if (!rangeCircleEntity) { |
| | | rangeCircleEntity = viewer.entities.add({ |
| | | position, |
| | | ellipse: { |
| | | semiMajorAxis: rangeMeters, |
| | | semiMinorAxis: rangeMeters, |
| | | material: Cesium.Color.fromCssColorString('#6b9ca8').withAlpha(0.6), |
| | | outline: true, |
| | | outlineColor: Cesium.Color.fromCssColorString('#6b9ca8').withAlpha(0.6), |
| | | heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, |
| | | }, |
| | | }) |
| | | return |
| | | } |
| | | rangeCircleEntity.position = position |
| | | rangeCircleEntity.ellipse.semiMajorAxis = rangeMeters |
| | | rangeCircleEntity.ellipse.semiMinorAxis = rangeMeters |
| | | } |
| | | |
| | | function initMap() { |
| | | if (viewer) return |
| | | const publicCesiumInstance = new PublicCesium({ |
| | | dom: 'detectionRangeMap', |
| | |
| | | viewer = publicCesiumInstance.getViewer() |
| | | } |
| | | |
| | | function handleMapClick (click) { |
| | | function handleMapClick(click) { |
| | | const pos = click.position |
| | | const cartesian3 = viewer.camera.pickEllipsoid(pos, viewer.scene.globe.ellipsoid) |
| | | if (!cartesian3) return |
| | |
| | | } |
| | | |
| | | // 打开弹框 |
| | | async function open ({ mode, row } = {}) { |
| | | async function open({ mode, row } = {}) { |
| | | dialogMode.value = mode || 'add' |
| | | visible.value = true |
| | | await nextTick() |
| | | initMap() |
| | | if (dialogMode.value === 'add') { |
| | |
| | | const detail = await loadDetail(row?.id) |
| | | formData.value = detail ?? row |
| | | } |
| | | formData.value.deployLocation = `${formData.value.longitude}, ${formData.value.latitude}` |
| | | formData.value.deviceId = formData.value.id ?? formData.value.deviceId |
| | | await loadDeviceOptions() |
| | | const currentName = formData.value.deviceName |
| | |
| | | } |
| | | const location = formData.value.deployLocation |
| | | if (location) { |
| | | const [longitude, latitude] = location.split(',').map(item => Number(item.trim())) |
| | | if (!Number.isNaN(longitude) && !Number.isNaN(latitude)) { |
| | | setMapPoint(longitude, latitude) |
| | | const parsed = parseDeployLocation(location) |
| | | if (parsed) { |
| | | setMapPoint(parsed.longitude, parsed.latitude) |
| | | viewer.flyTo(redPointEntity, { duration: 0 }) |
| | | } |
| | | } |
| | | } |
| | | |
| | | defineExpose({ open }) |
| | | |
| | | watch( |
| | | () => formData.value.effectiveRangeKm, |
| | | value => { |
| | | const parsed = parseDeployLocation(formData.value.deployLocation) |
| | | if (!parsed) return |
| | | updateRangeCircle(parsed.longitude, parsed.latitude, value) |
| | | } |
| | | ) |
| | | </script> |
| | | |
| | | <style scoped lang="scss"></style> |