| | |
| | | <template> |
| | | <el-dialog class="command-page-view-dialog" v-model="visible" :title="titleEnum[dialogMode]" |
| | | :close-on-click-modal="false"> |
| | | <el-dialog |
| | | class="command-page-view-dialog" |
| | | v-model="visible" |
| | | :title="titleEnum[dialogMode]" |
| | | :close-on-click-modal="false" |
| | | > |
| | | <div class="detail-container" v-if="readonly"> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | |
| | | <div class="val">{{ formData.contactPerson }}</div> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <div class="label">位置</div> |
| | | <div class="val">{{ formData.address }}</div> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <div class="label">联系方式</div> |
| | | <div class="val">{{ formData.contactPhone }}</div> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <div class="label">位置</div> |
| | | <div class="val">{{ formData.address }}</div> |
| | | </el-col> |
| | | </el-row> |
| | | </div> |
| | | <el-form class="dialog-form" v-else ref="formRef" :model="formData" :rules="rules" :disabled="readonly" |
| | | label-width="100px"> |
| | | <el-form |
| | | class="dialog-form" |
| | | v-else |
| | | ref="formRef" |
| | | :model="formData" |
| | | :rules="rules" |
| | | :disabled="readonly" |
| | | label-width="100px" |
| | | > |
| | | <el-row> |
| | | <el-col :span="24"> |
| | | <el-form-item label="派出所名称" prop="stationName"> |
| | | <el-input class="command-input" v-model="formData.stationName" maxlength="50" |
| | | placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="24"> |
| | | <el-form-item label="位置" prop="longitude"> |
| | | <el-button class="address-btn" @click="selectLocation"> |
| | | {{ formData.longitude }}, {{ formData.latitude }}, {{ formData.address }} |
| | | </el-button> |
| | | <el-input |
| | | class="command-input" |
| | | v-model="formData.stationName" |
| | | maxlength="50" |
| | | placeholder="请输入" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="联系人" prop="contactPerson"> |
| | | <el-input class="command-input" v-model="formData.contactPerson" maxlength="50" |
| | | placeholder="请输入" clearable /> |
| | | <el-input |
| | | class="command-input" |
| | | v-model="formData.contactPerson" |
| | | maxlength="50" |
| | | placeholder="请输入" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="联系方式" prop="contactPhone"> |
| | | <el-input class="command-input" v-model="formData.contactPhone" maxlength="50" |
| | | placeholder="请输入" clearable /> |
| | | <el-input |
| | | class="command-input" |
| | | v-model="formData.contactPhone" |
| | | maxlength="50" |
| | | placeholder="请输入" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="24"> |
| | | <el-form-item label="位置" prop="longitude"> |
| | | <div class="location-container"> |
| | | <div class="location-info" v-if="formData.longitude && formData.latitude"> |
| | | 经度: {{ formData.longitude }}, 纬度: {{ formData.latitude }} |
| | | <span v-if="formData.address">, {{ formData.address }}</span> |
| | | </div> |
| | | <div class="location-info" v-else>请在地图上点击选择位置</div> |
| | | <div class="inline-map-container"> |
| | | <CommonCesiumMap |
| | | ref="inlineMapRef" |
| | | class="inline-map command-cesium" |
| | | :active="visible && !readonly" |
| | | :flat-mode="false" |
| | | :terrain="true" |
| | | :layer-mode="4" |
| | | :boundary="false" |
| | | /> |
| | | </div> |
| | | </div> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | </el-form> |
| | | <template #footer> |
| | | <el-button v-if="dialogMode != 'view'" color="#2B2B4C" @click="handleCancel">{{ readonly ? '关闭' : '取消' }}</el-button> |
| | | <el-button color="#284FE3" v-if="!readonly" type="primary" :loading="submitting" :disabled="submitting" |
| | | @click="handleSubmit"> |
| | | <el-button v-if="dialogMode != 'view'" color="#2B2B4C" @click="handleCancel"> |
| | | {{ readonly ? '关闭' : '取消' }} |
| | | </el-button> |
| | | <el-button |
| | | color="#284FE3" |
| | | v-if="!readonly" |
| | | type="primary" |
| | | :loading="submitting" |
| | | :disabled="submitting" |
| | | @click="handleSubmit" |
| | | > |
| | | 确定 |
| | | </el-button> |
| | | </template> |
| | | </el-dialog> |
| | | |
| | | <el-dialog class="command-page-map-view-dialog" v-model="visible1" :show-close="false" |
| | | :close-on-click-modal="false" destroy-on-close @closed="positionClosed"> |
| | | <div class="dialog-container"> |
| | | <div class="left-container"> |
| | | <CommonCesiumMap |
| | | ref="mapRef" |
| | | class="leftMap command-cesium" |
| | | :active="visible1" |
| | | :flat-mode="false" |
| | | :terrain="true" |
| | | :layer-mode="4" |
| | | :boundary="false" |
| | | /> |
| | | </div> |
| | | </div> |
| | | |
| | | <template #footer> |
| | | <el-button color="#2B2B4C" @click="handleMapCancel">取消</el-button> |
| | | <el-button color="#284FE3" type="primary" @click="handleMapConfirm">确定</el-button> |
| | | </template> |
| | | </el-dialog> |
| | | </template> |
| | | |
| | | <script setup> |
| | |
| | | contactPerson: '', // 联系人 |
| | | contactPhone: '', // 联系方式 |
| | | stationName: '', // 派出所名称 |
| | | longitude: 0, |
| | | latitude: 0, |
| | | longitude: null, |
| | | latitude: null, |
| | | }) |
| | | |
| | | const emit = defineEmits(['success']) |
| | | const formRef = ref(null) // 表单实例 |
| | | const formData = ref(initForm()) // 表单数据 |
| | | const visible = defineModel() // 弹框显隐 |
| | | const visible1 = ref(false) // 弹框显隐 |
| | | const dialogMode = ref('add') // 弹框模式 |
| | | const submitting = ref(false) // 提交中 |
| | | const readonly = computed(() => dialogMode.value === 'view') |
| | | const titleEnum = ref({ edit: '编辑', view: '查看', add: '新增' }) |
| | | const tempLocation = ref({ longitude: null, latitude: null }) |
| | | const mapRef = ref(null) |
| | | const inlineMapRef = ref(null) // 内嵌地图引用 |
| | | const route = useRoute() |
| | | |
| | | const rules = { |
| | |
| | | stationName: fieldRules(true, 50), |
| | | contactPerson: fieldRules(true, 50), |
| | | contactPhone: fieldRules(true, 50), |
| | | longitude: fieldRules(true), |
| | | } |
| | | |
| | | // 关闭弹框 |
| | | 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 () { |
| | | async function loadDetail() { |
| | | if (!formData.value.id) return |
| | | const res = await fwPoliceStationDetailApi({ id: formData.value.id }) |
| | | formData.value = res?.data?.data ?? {} |
| | | } |
| | | |
| | | function LeftClickEvent (click) { |
| | | let viewer |
| | | let redPointEntity |
| | | let leftClickBound = false |
| | | const labelParams = { |
| | | font: '16px', |
| | | fillColor: Cesium.Color.WHITE, // 文字颜色:白色 |
| | | backgroundColor: Cesium.Color.BLACK, //背景颜色 |
| | | 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, |
| | | heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, |
| | | } |
| | | |
| | | function LeftClickEvent(click) { |
| | | const pos = click.position // Cartesian2 屏幕坐标 |
| | | // 屏幕坐标 -> 椭球面坐标(不考虑地形/模型) |
| | | const cartesian3 = viewer.camera.pickEllipsoid(pos, viewer.scene.globe.ellipsoid) |
| | |
| | | const carto = Cesium.Cartographic.fromCartesian(cartesian3) |
| | | const longitude = Cesium.Math.toDegrees(carto.longitude) |
| | | const latitude = Cesium.Math.toDegrees(carto.latitude) |
| | | tempLocation.value = { longitude, latitude } |
| | | // 直接更新 formData |
| | | formData.value.longitude = _.round(longitude, 6) |
| | | formData.value.latitude = _.round(latitude, 6) |
| | | getLocationName(longitude, latitude) |
| | | |
| | | // 添加红点(全局仅保留一个)并渲染经纬度标签 |
| | | if (!redPointEntity) { |
| | | redPointEntity = viewer.entities.add({ |
| | |
| | | point: { |
| | | color: Cesium.Color.RED, |
| | | pixelSize: 10, |
| | | heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, |
| | | }, |
| | | label: { |
| | | text: `${longitude.toFixed(6)}, ${latitude.toFixed(6)}`, |
| | | font: '14px', |
| | | fillColor: Cesium.Color.WHITE, // 文字颜色:白色 |
| | | backgroundColor: Cesium.Color.BLACK.withAlpha(0.6), //背景颜色 |
| | | 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, |
| | | eyeOffset: new Cesium.Cartesian3(0, 0, -20), // 负值更靠近相机(显示在前) |
| | | ...labelParams |
| | | }, |
| | | }) |
| | | } else { |
| | |
| | | } |
| | | } |
| | | |
| | | function positionClosed () { |
| | | redPointEntity = null |
| | | } |
| | | |
| | | let viewer |
| | | let redPointEntity |
| | | let leftClickBound = false |
| | | function setMapPoint (longitude, latitude) { |
| | | function setMapPoint(longitude, latitude) { |
| | | if (!viewer || longitude == null || latitude == null) return |
| | | if (!redPointEntity) { |
| | | redPointEntity = viewer.entities.add({ |
| | |
| | | point: { |
| | | color: Cesium.Color.RED, |
| | | pixelSize: 10, |
| | | heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, |
| | | }, |
| | | label: { |
| | | text: `${longitude.toFixed(6)}, ${latitude.toFixed(6)}`, |
| | | font: '14px', |
| | | fillColor: Cesium.Color.WHITE, |
| | | backgroundColor: Cesium.Color.BLACK.withAlpha(0.6), |
| | | 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, |
| | | eyeOffset: new Cesium.Cartesian3(0, 0, -20), |
| | | ...labelParams |
| | | }, |
| | | }) |
| | | } else { |
| | |
| | | } |
| | | } |
| | | |
| | | function formatCoord (value) { |
| | | function formatCoord(value) { |
| | | if (value == null || value === '') return '-' |
| | | return _.round(Number(value), 6) |
| | | } |
| | | |
| | | async function selectLocation () { |
| | | visible1.value = true |
| | | // 初始化内嵌地图 |
| | | async function initInlineMap() { |
| | | await nextTick() |
| | | const map = mapRef.value?.getMap() |
| | | const map = inlineMapRef.value?.getMap() |
| | | viewer = map?.viewer || null |
| | | if (viewer && !leftClickBound) { |
| | | map.publicCesium?.addLeftClickEvent?.(null, LeftClickEvent) |
| | | leftClickBound = true |
| | | } |
| | | if (formData.value.longitude != null && formData.value.latitude != null) { |
| | | tempLocation.value = { longitude: formData.value.longitude, latitude: formData.value.latitude } |
| | | setMapPoint(formData.value.longitude, formData.value.latitude) |
| | | } |
| | | } |
| | | |
| | | function handleMapCancel () { |
| | | tempLocation.value = { longitude: null, latitude: null } |
| | | visible1.value = false |
| | | } |
| | | |
| | | async function getLocationName () { |
| | | async function getLocationName(longitude, latitude) { |
| | | const tk = import.meta.env.VITE_APP_TDT_TOKEN |
| | | const { latitude, longitude } = tempLocation.value |
| | | const http = axios.create({ withCredentials: false }) |
| | | const res = await http({ |
| | | url: `https://api.tianditu.gov.cn/geocoder?postStr={'lon':${longitude},'lat':${latitude},'ver':1}&tk=${tk}`, |
| | |
| | | formData.value.address = res.data.result.formatted_address |
| | | } |
| | | |
| | | function handleMapConfirm () { |
| | | if (tempLocation.value.longitude != null && tempLocation.value.latitude != null) { |
| | | formData.value.longitude = _.round(tempLocation.value.longitude, 6) |
| | | formData.value.latitude = _.round(tempLocation.value.latitude, 6) |
| | | getLocationName() |
| | | } |
| | | visible1.value = false |
| | | } |
| | | |
| | | // 打开弹框 |
| | | async function open ({ mode, row } = {}) { |
| | | async function open({ mode, row } = {}) { |
| | | dialogMode.value = mode || 'add' |
| | | formData.value = dialogMode.value === 'add' ? initForm() : row |
| | | dialogMode.value !== 'add' && (await loadDetail()) |
| | | redPointEntity = null |
| | | leftClickBound = false |
| | | if (dialogMode.value !== 'add') { |
| | | await loadDetail() |
| | | } |
| | | // 延迟初始化地图,确保 DOM 渲染完成 |
| | | setTimeout(() => { |
| | | initInlineMap() |
| | | }, 500) |
| | | } |
| | | |
| | | defineExpose({ open }) |
| | | </script> |
| | | <style scoped lang="scss"> |
| | | .location-container { |
| | | width: 100%; |
| | | } |
| | | |
| | | .location-info { |
| | | margin-bottom: 8px; |
| | | color: #fff; |
| | | font-size: 14px; |
| | | } |
| | | |
| | | .inline-map-container { |
| | | width: 100%; |
| | | height: 300px; |
| | | border-radius: 4px; |
| | | overflow: hidden; |
| | | border: 1px solid rgba(255, 255, 255, 0.1); |
| | | } |
| | | |
| | | .inline-map { |
| | | width: 100%; |
| | | height: 100%; |
| | | } |
| | | </style> |