psfqgl.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. <template>
  2. <div class="app-container">
  3. <!-- GIS 地图展示区 -->
  4. <div class="map-section" style="margin-bottom: 16px;">
  5. <div class="map-tabs">
  6. <div class="map-tab" :class="{ active: mapTab === 'all' }" @click="switchMapTab('all')">全部</div>
  7. <div class="map-tab" :class="{ active: mapTab === '雨水分区' }" @click="switchMapTab('雨水分区')">雨水分区</div>
  8. <div class="map-tab" :class="{ active: mapTab === '污水分区' }" @click="switchMapTab('污水分区')">污水分区</div>
  9. </div>
  10. <div id="psfqglMainMap" class="map-container" style="height: 350px;"></div>
  11. </div>
  12. <!-- 搜索区域 -->
  13. <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
  14. <el-form-item label="分区名称">
  15. <el-input v-model="queryParams.name" placeholder="请输入分区名称" clearable style="width: 200px"
  16. @keyup.enter="handleQuery" />
  17. </el-form-item>
  18. <el-form-item label="地点">
  19. <el-input v-model="queryParams.district" placeholder="请输入地点" clearable style="width: 200px"
  20. @keyup.enter="handleQuery" />
  21. </el-form-item>
  22. <el-form-item label="分区类型">
  23. <el-select v-model="queryParams.partitionType" placeholder="请选择分区类型" clearable style="width: 200px">
  24. <el-option label="雨水分区" value="雨水分区" />
  25. <el-option label="污水分区" value="污水分区" />
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  30. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  31. </el-form-item>
  32. </el-form>
  33. <!-- 操作按钮区域 -->
  34. <el-row :gutter="10" class="mb8">
  35. <el-col :span="1.5">
  36. <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button type="danger" plain icon="Delete" :disabled="selectedIds.length === 0"
  40. @click="handleBatchDelete">删除</el-button>
  41. </el-col>
  42. <right-toolbar v-model:showSearch="showSearch" @queryTable="loadData"></right-toolbar>
  43. </el-row>
  44. <!-- 数据表格 -->
  45. <el-table v-loading="loading" :data="filteredList" style="width: 100%" @selection-change="handleSelectionChange">
  46. <el-table-column type="selection" width="55" align="center" />
  47. <el-table-column label="分区名称" prop="name" min-width="160" />
  48. <el-table-column label="地点" prop="district" min-width="100" />
  49. <el-table-column label="分区类型" prop="partitionType" min-width="100" />
  50. <el-table-column label="数据时间" prop="time" min-width="120" />
  51. <el-table-column :label="`排水量(${DRAINAGE_UNIT})`" prop="drainage" min-width="120" align="right">
  52. <template #default="{ row }">
  53. <span>{{ formatVolume(row.drainage) }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column :label="`积水量(${WATERLOGGING_UNIT})`" prop="waterlogging" min-width="120" align="right">
  57. <template #default="{ row }">
  58. <span>{{ formatVolume(row.waterlogging) }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="积水等级" prop="level" min-width="110" align="center">
  62. <template #default="{ row }">
  63. <el-tag v-if="hasLevel(row.level)" :type="getLevelTagType(row.level)" effect="light" size="small">
  64. {{ getLevelLabel(row.level) }}
  65. </el-tag>
  66. <span v-else class="text-placeholder">--</span>
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="关联设备" min-width="160">
  70. <template #default="{ row }">
  71. {{ equipmentNameMap[row.id] || '' }}
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="操作" width="240" align="center">
  75. <template #default="{ row }">
  76. <el-button link type="primary" @click="handleView(row)">查看</el-button>
  77. <el-button link type="primary" @click="handleEdit(row)">修改</el-button>
  78. <el-button link type="primary" @click="handleBind(row)">关联设备</el-button>
  79. <el-button link type="danger" @click="handleDelete(row)">删除</el-button>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. <!-- 分页 -->
  84. <pagination v-show="total > 0" :total="total" v-model:page="pageNum" v-model:limit="pageSize"
  85. @pagination="loadData" />
  86. <!-- 查看详情对话框 -->
  87. <el-drawer v-model="dialogVisible" title="详情" size="700px" :before-close="handleClose" @opened="onDialogOpened" class="detail-drawer" direction="rtl">
  88. <div class="detail-info">
  89. <el-row :gutter="20">
  90. <el-col :span="12">
  91. <div class="info-item">
  92. <span class="info-label">分区名称:</span>
  93. <span class="info-value">{{ currentRow.name }}</span>
  94. </div>
  95. </el-col>
  96. <el-col :span="12">
  97. <div class="info-item">
  98. <span class="info-label">地点:</span>
  99. <span class="info-value">{{ currentRow.district }}</span>
  100. </div>
  101. </el-col>
  102. </el-row>
  103. <el-row :gutter="20">
  104. <el-col :span="12">
  105. <div class="info-item">
  106. <span class="info-label">数据时间:</span>
  107. <span class="info-value">{{ currentRow.time }}</span>
  108. </div>
  109. </el-col>
  110. <el-col :span="12">
  111. <div class="info-item">
  112. <span class="info-label">排水量:</span>
  113. <span class="info-value">{{ formatVolume(currentRow.drainage) }} {{ DRAINAGE_UNIT }}</span>
  114. </div>
  115. </el-col>
  116. </el-row>
  117. <el-row :gutter="20">
  118. <el-col :span="12">
  119. <div class="info-item">
  120. <span class="info-label">积水量:</span>
  121. <span class="info-value">{{ formatVolume(currentRow.waterlogging) }} {{ WATERLOGGING_UNIT }}</span>
  122. </div>
  123. </el-col>
  124. <el-col :span="12">
  125. <div class="info-item">
  126. <span class="info-label">积水等级:</span>
  127. <span class="info-value">
  128. <el-tag v-if="hasLevel(currentRow.level)" :type="getLevelTagType(currentRow.level)" effect="light" size="small">
  129. {{ getLevelLabel(currentRow.level) }}
  130. </el-tag>
  131. <span v-else class="text-placeholder">--</span>
  132. </span>
  133. </div>
  134. </el-col>
  135. </el-row>
  136. </div>
  137. <!-- 关联设备 -->
  138. <div v-if="viewEquipmentNames.length" class="detail-info" style="margin-top: 12px;">
  139. <el-row :gutter="20">
  140. <el-col :span="24">
  141. <div class="info-item">
  142. <span class="info-label">关联设备:</span>
  143. <span class="info-value">{{ viewEquipmentNames.join('、') }}</span>
  144. </div>
  145. </el-col>
  146. </el-row>
  147. </div>
  148. <!-- 地图区域 -->
  149. <div class="map-section">
  150. <div class="map-tabs">
  151. <div class="map-tab active">分区面预览</div>
  152. </div>
  153. <div id="psfqglViewMap" class="map-container"></div>
  154. </div>
  155. </el-drawer>
  156. <!-- 新增/修改对话框 -->
  157. <el-dialog v-model="editDialogVisible" :title="editDialogTitle" width="800px" :before-close="handleEditClose"
  158. @opened="onEditDialogOpened">
  159. <el-form ref="editFormRef" :model="editForm" :rules="editRules" label-width="100px">
  160. <el-row :gutter="20">
  161. <el-col :span="12">
  162. <el-form-item label="分区名称" prop="name">
  163. <el-input v-model="editForm.name" placeholder="请输入分区名称" />
  164. </el-form-item>
  165. </el-col>
  166. <el-col :span="12">
  167. <el-form-item label="地点" prop="district">
  168. <el-input v-model="editForm.district" placeholder="请输入地点" />
  169. </el-form-item>
  170. </el-col>
  171. </el-row>
  172. <el-row :gutter="20">
  173. <el-col :span="12">
  174. <el-form-item label="数据时间" prop="time">
  175. <el-date-picker v-model="editForm.time" type="date" placeholder="选择日期" value-format="YYYY-MM-DD"
  176. style="width: 100%" />
  177. </el-form-item>
  178. </el-col>
  179. <el-col :span="12">
  180. <el-form-item label="分区类型" prop="partitionType">
  181. <el-select v-model="editForm.partitionType" placeholder="请选择分区类型" style="width:100%"
  182. @change="handlePartitionTypeChange">
  183. <el-option label="雨水分区" value="雨水分区" />
  184. <el-option label="污水分区" value="污水分区" />
  185. </el-select>
  186. </el-form-item>
  187. </el-col>
  188. </el-row>
  189. <el-row :gutter="20">
  190. <el-col :span="12">
  191. <el-form-item :label="`排水量(${DRAINAGE_UNIT})`" prop="drainage">
  192. <el-input-number v-model="editForm.drainage" :precision="2" :min="0" style="width:100%"
  193. placeholder="请输入排水量" />
  194. </el-form-item>
  195. </el-col>
  196. <el-col :span="12">
  197. <el-form-item :label="`积水量(${WATERLOGGING_UNIT})`" prop="waterlogging">
  198. <el-input-number v-model="editForm.waterlogging" :precision="2" :min="0" style="width:100%"
  199. placeholder="请输入积水量" />
  200. </el-form-item>
  201. </el-col>
  202. </el-row>
  203. <el-row :gutter="20">
  204. <el-col :span="12">
  205. <el-form-item label="积水等级" prop="level">
  206. <el-select v-model="editForm.level" placeholder="请选择积水等级" clearable style="width:100%">
  207. <el-option v-for="item in levelOptions" :key="item.value" :label="item.label"
  208. :value="normalizeLevelValue(item.value)" />
  209. </el-select>
  210. </el-form-item>
  211. </el-col>
  212. </el-row>
  213. </el-form>
  214. <!-- 地图标点区域 -->
  215. <div class="map-section" style="margin-top: 16px;">
  216. <div class="map-tabs">
  217. <div class="map-tab active">分区面绘制</div>
  218. <div v-if="isPolygonPartition" class="map-tab-action" @click="togglePolygonDrawing">
  219. {{ isDrawingPolygon ? '完成绘制' : '开始绘制' }}
  220. </div>
  221. <div class="map-tab-action" @click="clearEditMarkers">清除边界</div>
  222. </div>
  223. <div id="psfqglEditMap" class="map-container" style="height: 350px;"></div>
  224. <div class="marker-count">
  225. {{ isPolygonPartition ? `已绘制 ${editPolygonPoints.length} 个点` : '请选择分区类型后绘制面' }}
  226. </div>
  227. </div>
  228. <template #footer>
  229. <el-button @click="handleEditClose">取 消</el-button>
  230. <el-button type="primary" @click="handleEditSubmit">确 定</el-button>
  231. </template>
  232. </el-dialog>
  233. <!-- 关联设备对话框 -->
  234. <el-dialog v-model="bindDialogVisible" title="关联设备" width="800px">
  235. <el-form :model="bindQueryParams" :inline="true" class="search-form">
  236. <el-form-item label="设备名称">
  237. <el-input v-model="bindQueryParams.equipmentName" placeholder="请输入设备名称" clearable style="width: 220px" />
  238. </el-form-item>
  239. <el-form-item>
  240. <el-button type="primary" @click="handleBindQuery">搜索</el-button>
  241. </el-form-item>
  242. </el-form>
  243. <el-table ref="bindTableRef" v-loading="bindLoading" :data="bindTableData" row-key="equipmentId" border
  244. style="width: 100%" height="400">
  245. <el-table-column label="选择" width="55" align="center">
  246. <template #default="{ row }">
  247. <el-checkbox :model-value="selectedEquipmentIds.includes(String(row.equipmentId))"
  248. :disabled="isEquipmentBound(row)" @change="toggleEquipment(row, $event)" />
  249. </template>
  250. </el-table-column>
  251. <el-table-column label="设备名称" prop="equipmentName" min-width="160" />
  252. <el-table-column label="设备编号" prop="equipmentCode" min-width="140" />
  253. <el-table-column label="设备类型" prop="equipmentTypeName" min-width="120" />
  254. <el-table-column label="关联状态" min-width="180">
  255. <template #default="{ row }">
  256. <span v-if="selectedEquipmentIds.includes(String(row.equipmentId))" style="color: #67c23a;">当前选择</span>
  257. <span v-else-if="boundEquipmentMap[String(row.equipmentId)]" style="color: #e6a23c;">
  258. 已关联:{{ boundEquipmentMap[String(row.equipmentId)] }}
  259. </span>
  260. <span v-else>未关联</span>
  261. </template>
  262. </el-table-column>
  263. </el-table>
  264. <pagination v-show="bindTotal > 0" v-model:page="bindPageNum" v-model:limit="bindPageSize" :total="bindTotal"
  265. @pagination="loadBindData" />
  266. <template #footer>
  267. <el-button @click="closeBindDialog">取 消</el-button>
  268. <el-button type="primary" @click="submitBind">确 定</el-button>
  269. </template>
  270. </el-dialog>
  271. </div>
  272. </template>
  273. <script setup name="Psfqgl">
  274. import { ref, computed, nextTick, onMounted } from 'vue'
  275. import { ElMessage, ElMessageBox } from 'element-plus'
  276. import { useDict } from '@/utils/dict'
  277. import locationIcon from '@/assets/images/location.png'
  278. import {
  279. getPartitionPage,
  280. addPartition,
  281. updatePartition,
  282. deletePartition,
  283. batchDeletePartition,
  284. getEquipmentPage,
  285. getEquipmentById,
  286. bindPartitionEquipment,
  287. getDrainageBoundEquipmentIds
  288. } from '@/api/drainage'
  289. // ==================== 量纲 + 积水等级字典 ====================
  290. // 排水量 / 积水量 单位:业务口径若调整,只改这两处,表单、列表、详情同步生效
  291. const DRAINAGE_UNIT = 'm³'
  292. const WATERLOGGING_UNIT = 'm³'
  293. // 积水等级字典(sys_dict_type = drainage_waterlogging_level)
  294. // 与易积水点 waterlogging_level 口径保持一致:0未积水 / 1轻度 / 2中度 / 3严重
  295. const { drainage_waterlogging_level: levelDict } = useDict('drainage_waterlogging_level')
  296. // 字典表未配置时用内置口径兜底,避免页面无选项
  297. const LEVEL_FALLBACK = [
  298. { label: '未积水', value: '0', elTagType: 'success' },
  299. { label: '轻度积水', value: '1', elTagType: 'primary' },
  300. { label: '中度积水', value: '2', elTagType: 'warning' },
  301. { label: '严重积水', value: '3', elTagType: 'danger' }
  302. ]
  303. const levelOptions = computed(() => {
  304. const list = levelDict.value
  305. return Array.isArray(list) && list.length ? list : LEVEL_FALLBACK
  306. })
  307. // 字典值统一成数字,保证 el-select 回显能与后端 Integer 字段匹配
  308. function normalizeLevelValue(value) {
  309. if (value === null || value === undefined || value === '') return value
  310. return Number.isNaN(Number(value)) ? value : Number(value)
  311. }
  312. function hasLevel(value) {
  313. return value !== null && value !== undefined && value !== ''
  314. }
  315. function findLevelOption(value) {
  316. const key = String(value)
  317. return levelOptions.value.find(item => String(item.value) === key)
  318. }
  319. function getLevelLabel(value) {
  320. const option = findLevelOption(value)
  321. return option ? option.label : '--'
  322. }
  323. // 标签配色由字典 list_class 决定;primary / 空值走默认主题色
  324. function getLevelTagType(value) {
  325. const option = findLevelOption(value)
  326. const type = option ? (option.elTagType || option.listClass) : ''
  327. return !type || type === 'primary' || type === 'default' ? '' : type
  328. }
  329. function formatVolume(value) {
  330. if (value === null || value === undefined || value === '') return '--'
  331. const num = Number(value)
  332. return Number.isFinite(num) ? num.toFixed(2) : String(value)
  333. }
  334. // 地图标记创建(用Label+img代替Marker)
  335. function createMapMarker(map, bPoint, name, bgColor) {
  336. const color = bgColor || '#409eff'
  337. const html = `<div style="text-align:center;cursor:pointer;">
  338. <div style="color:#fff;background:${color};border-radius:4px;padding:2px 6px;font-size:11px;white-space:nowrap;display:inline-block;margin-bottom:2px;">${name || ''}</div>
  339. <div><img src="${locationIcon}" style="width:28px;height:28px;display:block;margin:0 auto;"/></div>
  340. </div>`
  341. const label = new TdtMap.Label(html, {
  342. position: bPoint,
  343. offset: new TdtMap.Size(-30, -50)
  344. })
  345. label.setStyle({
  346. border: 'none',
  347. background: 'transparent',
  348. padding: '0'
  349. })
  350. map.addOverlay(label)
  351. return label
  352. }
  353. // ==================== 顶部地图 ====================
  354. let mainMapInstance = null
  355. const mainMapMarkers = ref([])
  356. const mapTab = ref('all')
  357. function parsePolygonPoints(value) {
  358. if (!value) return []
  359. try {
  360. const points = typeof value === 'string' ? JSON.parse(value) : value
  361. return Array.isArray(points)
  362. ? points.map(point => ({ lng: Number(point.lng), lat: Number(point.lat) }))
  363. .filter(point => Number.isFinite(point.lng) && Number.isFinite(point.lat))
  364. : []
  365. } catch (e) {
  366. return []
  367. }
  368. }
  369. function getPartitionCenter(item) {
  370. const points = parsePolygonPoints(item.points)
  371. if (points.length) {
  372. const lng = points.reduce((sum, point) => sum + point.lng, 0) / points.length
  373. const lat = points.reduce((sum, point) => sum + point.lat, 0) / points.length
  374. return { lng, lat }
  375. }
  376. return { lng: Number(item.longitude), lat: Number(item.latitude) }
  377. }
  378. function switchMapTab(tab) {
  379. mapTab.value = tab
  380. renderMainMapMarkers()
  381. }
  382. function initMainMap() {
  383. const container = document.getElementById('psfqglMainMap')
  384. if (!container) return
  385. try {
  386. mainMapInstance = new TdtMap.Map('psfqglMainMap')
  387. const centerPoint = new TdtMap.Point(110.393, 28.452)
  388. mainMapInstance.centerAndZoom(centerPoint, 12)
  389. mainMapInstance.enableScrollWheelZoom(true)
  390. renderMainMapMarkers()
  391. } catch (e) {
  392. console.error('顶部天地图初始化失败:', e)
  393. }
  394. }
  395. function renderMainMapMarkers() {
  396. if (!mainMapInstance) return
  397. // 清除旧标记
  398. mainMapMarkers.value.forEach(label => {
  399. mainMapInstance.removeOverlay(label)
  400. })
  401. mainMapMarkers.value = []
  402. const list = tableData.value.filter(item => parsePolygonPoints(item.points).length >= 3 || (item.longitude && item.latitude))
  403. const filtered = mapTab.value === 'all'
  404. ? list
  405. : list.filter(item => item.partitionType === mapTab.value)
  406. filtered.forEach(item => {
  407. const color = item.partitionType === '污水分区' ? '#e6a23c' : '#409eff'
  408. const points = parsePolygonPoints(item.points)
  409. if (points.length >= 3) {
  410. const polygon = new TdtMap.Polygon(points.map(point => new TdtMap.Point(point.lng, point.lat)), {
  411. strokeColor: color,
  412. fillColor: color,
  413. strokeWeight: 2,
  414. strokeOpacity: 0.8,
  415. fillOpacity: 0.25
  416. })
  417. mainMapInstance.addOverlay(polygon)
  418. mainMapMarkers.value.push(polygon)
  419. const center = getPartitionCenter(item)
  420. const label = createMapMarker(mainMapInstance, new TdtMap.Point(center.lng, center.lat), item.name, color)
  421. mainMapMarkers.value.push(label)
  422. } else {
  423. const bPoint = new TdtMap.Point(item.longitude, item.latitude)
  424. const label = createMapMarker(mainMapInstance, bPoint, item.name, color)
  425. mainMapMarkers.value.push(label)
  426. }
  427. })
  428. }
  429. // ==================== 搜索参数 ====================
  430. const showSearch = ref(true)
  431. const queryRef = ref()
  432. const queryParams = ref({
  433. name: '',
  434. district: '',
  435. partitionType: ''
  436. })
  437. // ==================== 表格数据 ====================
  438. const tableData = ref([])
  439. const total = ref(0)
  440. const pageNum = ref(1)
  441. const pageSize = ref(10)
  442. const loading = ref(false)
  443. // 加载分页数据
  444. async function loadData() {
  445. loading.value = true
  446. try {
  447. const res = await getPartitionPage(pageNum.value, pageSize.value, queryParams.value)
  448. // 兼容直接返回Page对象(无code包装)和AjaxResult包装两种格式
  449. const pageData = res.code !== undefined ? res.data : res
  450. tableData.value = pageData.records || []
  451. total.value = pageData.total || 0
  452. renderMainMapMarkers()
  453. // 解析关联设备名称
  454. resolveEquipmentNames()
  455. } catch (e) {
  456. console.error('加载排水分区数据失败', e)
  457. } finally {
  458. loading.value = false
  459. }
  460. }
  461. // 关联设备名称映射(分区ID -> 设备名称字符串)
  462. const equipmentNameMap = ref({})
  463. async function resolveEquipmentNames() {
  464. const map = {}
  465. for (const row of tableData.value) {
  466. if (row.equipmentId) {
  467. const ids = row.equipmentId.split(',')
  468. const names = []
  469. for (const id of ids) {
  470. try {
  471. const res = await getEquipmentById(id.trim())
  472. const data = res.code !== undefined ? res.data : res
  473. const info = data && data.equipmentInfo ? data.equipmentInfo : data
  474. if (info && info.equipmentName) names.push(info.equipmentName)
  475. } catch (e) { /* skip */ }
  476. }
  477. map[row.id] = names.join('、')
  478. }
  479. }
  480. equipmentNameMap.value = map
  481. }
  482. onMounted(() => {
  483. loadData()
  484. initMainMap()
  485. })
  486. // 多选
  487. const selectedIds = ref([])
  488. function handleSelectionChange(selection) {
  489. selectedIds.value = selection.map(item => item.id)
  490. }
  491. // 表格数据直接用 tableData(已是分页数据)
  492. const filteredList = computed(() => tableData.value)
  493. // 搜索
  494. function handleQuery() {
  495. pageNum.value = 1
  496. loadData()
  497. }
  498. // 重置搜索条件
  499. function resetQuery() {
  500. queryRef.value?.resetFields()
  501. queryParams.value.name = ''
  502. queryParams.value.district = ''
  503. queryParams.value.partitionType = ''
  504. pageNum.value = 1
  505. loadData()
  506. }
  507. // ==================== 查看详情对话框 ====================
  508. const dialogVisible = ref(false)
  509. const currentRow = ref({})
  510. let viewMapInstance = null
  511. const viewEquipmentNames = ref([])
  512. async function handleView(row) {
  513. currentRow.value = { ...row }
  514. dialogVisible.value = true
  515. // 解析关联设备名称
  516. viewEquipmentNames.value = []
  517. if (row.equipmentId) {
  518. const ids = row.equipmentId.split(',')
  519. const names = []
  520. for (const id of ids) {
  521. try {
  522. const res = await getEquipmentById(id.trim())
  523. const data = res.code !== undefined ? res.data : res
  524. const info = data && data.equipmentInfo ? data.equipmentInfo : data
  525. if (info && info.equipmentName) names.push(info.equipmentName)
  526. } catch (e) { /* skip */ }
  527. }
  528. viewEquipmentNames.value = names
  529. }
  530. }
  531. function handleClose() {
  532. dialogVisible.value = false
  533. if (viewMapInstance) {
  534. viewMapInstance = null
  535. }
  536. }
  537. function onDialogOpened() {
  538. setTimeout(() => {
  539. initViewMap()
  540. }, 300)
  541. }
  542. function initViewMap() {
  543. const container = document.getElementById('psfqglViewMap')
  544. if (!container) return
  545. try {
  546. viewMapInstance = new TdtMap.Map('psfqglViewMap')
  547. const center = getPartitionCenter(currentRow.value)
  548. const centerLng = center.lng || 110.393
  549. const centerLat = center.lat || 28.452
  550. const centerPoint = new TdtMap.Point(centerLng, centerLat)
  551. viewMapInstance.centerAndZoom(centerPoint, 15)
  552. viewMapInstance.enableScrollWheelZoom(true)
  553. const points = parsePolygonPoints(currentRow.value.points)
  554. if (points.length >= 3) {
  555. viewMapInstance.addOverlay(new TdtMap.Polygon(points.map(point => new TdtMap.Point(point.lng, point.lat)), {
  556. strokeColor: '#409eff', fillColor: '#409eff', strokeWeight: 2, fillOpacity: 0.25
  557. }))
  558. } else if (currentRow.value.longitude && currentRow.value.latitude) {
  559. createMapMarker(viewMapInstance, new TdtMap.Point(currentRow.value.longitude, currentRow.value.latitude), currentRow.value.name)
  560. }
  561. } catch (e) {
  562. console.error('天地图初始化失败:', e)
  563. }
  564. }
  565. // ==================== 新增/修改对话框 ====================
  566. const editDialogVisible = ref(false)
  567. const editDialogTitle = ref('新增排水分区')
  568. const editFormRef = ref(null)
  569. const isEditMode = ref(false)
  570. const editRowId = ref(null)
  571. const editForm = ref({
  572. name: '',
  573. district: '',
  574. partitionType: '',
  575. time: '',
  576. drainage: 0,
  577. waterlogging: 0,
  578. level: 0,
  579. longitude: null,
  580. latitude: null,
  581. points: ''
  582. })
  583. const editRules = {
  584. name: [{ required: true, message: '请输入分区名称', trigger: 'blur' }],
  585. time: [{ required: true, message: '请选择数据时间', trigger: 'change' }],
  586. level: [{ required: true, message: '请选择积水等级', trigger: 'change' }]
  587. }
  588. // 编辑弹窗地图相关
  589. let editMapInstance = null
  590. let editMarkerLabel = null
  591. let editPolygonOverlay = null
  592. const editPolygonPoints = ref([])
  593. const isDrawingPolygon = ref(false)
  594. const editPointOverlays = ref([])
  595. const polygonPartitionTypes = ['雨水分区', '污水分区']
  596. const isPolygonPartition = computed(() => polygonPartitionTypes.includes(editForm.value.partitionType))
  597. function handleAdd() {
  598. isEditMode.value = false
  599. editDialogTitle.value = '新增排水分区'
  600. editRowId.value = null
  601. editForm.value = {
  602. name: '',
  603. district: '',
  604. partitionType: '',
  605. time: '',
  606. drainage: 0,
  607. waterlogging: 0,
  608. level: 0,
  609. longitude: null,
  610. latitude: null,
  611. points: ''
  612. }
  613. editDialogVisible.value = true
  614. }
  615. function handleEdit(row) {
  616. isEditMode.value = true
  617. editDialogTitle.value = '修改排水分区'
  618. editRowId.value = row.id
  619. editForm.value = {
  620. name: row.name,
  621. district: row.district,
  622. partitionType: row.partitionType,
  623. time: row.time,
  624. drainage: row.drainage,
  625. waterlogging: row.waterlogging,
  626. level: hasLevel(row.level) ? normalizeLevelValue(row.level) : 0,
  627. longitude: row.longitude,
  628. latitude: row.latitude,
  629. points: row.points || ''
  630. }
  631. editDialogVisible.value = true
  632. }
  633. function handleEditClose() {
  634. editDialogVisible.value = false
  635. if (editMapInstance) {
  636. editMapInstance = null
  637. }
  638. editMarkerLabel = null
  639. editPolygonOverlay = null
  640. editPointOverlays.value = []
  641. editPolygonPoints.value = []
  642. isDrawingPolygon.value = false
  643. }
  644. function onEditDialogOpened() {
  645. setTimeout(() => {
  646. initEditMap()
  647. }, 300)
  648. }
  649. function initEditMap() {
  650. const container = document.getElementById('psfqglEditMap')
  651. if (!container) return
  652. try {
  653. editMapInstance = new TdtMap.Map('psfqglEditMap')
  654. const centerLng = editForm.value.longitude || 110.393
  655. const centerLat = editForm.value.latitude || 28.452
  656. const centerPoint = new TdtMap.Point(centerLng, centerLat)
  657. editMapInstance.centerAndZoom(centerPoint, 15)
  658. editMapInstance.enableScrollWheelZoom(true)
  659. editPolygonPoints.value = parsePolygonPoints(editForm.value.points)
  660. renderEditPolygon()
  661. editMapInstance.addEventListener('click', function (e) {
  662. if (!isDrawingPolygon.value || !isPolygonPartition.value) return
  663. const point = e.latLng || e.latlng
  664. if (!point) return
  665. editPolygonPoints.value.push({ lng: point.lng, lat: point.lat })
  666. renderEditPolygon()
  667. })
  668. } catch (e) {
  669. console.error('天地图初始化失败:', e)
  670. }
  671. }
  672. function clearEditMarkers() {
  673. if (editMapInstance && editPolygonOverlay) editMapInstance.removeOverlay(editPolygonOverlay)
  674. if (editMapInstance && editMarkerLabel) editMapInstance.removeOverlay(editMarkerLabel)
  675. if (editMapInstance) {
  676. editPointOverlays.value.forEach(overlay => editMapInstance.removeOverlay(overlay))
  677. }
  678. editPolygonOverlay = null
  679. editMarkerLabel = null
  680. editPointOverlays.value = []
  681. editPolygonPoints.value = []
  682. editForm.value.points = ''
  683. editForm.value.longitude = null
  684. editForm.value.latitude = null
  685. isDrawingPolygon.value = false
  686. }
  687. function handlePartitionTypeChange(type) {
  688. if (!polygonPartitionTypes.includes(type)) clearEditMarkers()
  689. }
  690. function renderEditPolygon() {
  691. if (!editMapInstance) return
  692. if (editPolygonOverlay) editMapInstance.removeOverlay(editPolygonOverlay)
  693. editPointOverlays.value.forEach(overlay => editMapInstance.removeOverlay(overlay))
  694. editPointOverlays.value = []
  695. editPolygonPoints.value.forEach(point => {
  696. const overlay = new TdtMap.Circle(new TdtMap.Point(point.lng, point.lat), 5, {
  697. strokeColor: '#ffffff',
  698. strokeWeight: 2,
  699. strokeOpacity: 1,
  700. fillColor: '#409eff',
  701. fillOpacity: 1
  702. })
  703. editMapInstance.addOverlay(overlay)
  704. editPointOverlays.value.push(overlay)
  705. })
  706. if (editPolygonPoints.value.length < 2) return
  707. const points = editPolygonPoints.value.map(point => new TdtMap.Point(point.lng, point.lat))
  708. const OverlayType = editPolygonPoints.value.length >= 3 ? TdtMap.Polygon : TdtMap.Polyline
  709. editPolygonOverlay = new OverlayType(points, {
  710. strokeColor: '#409eff',
  711. strokeWeight: 2,
  712. strokeOpacity: 0.9,
  713. fillColor: '#409eff',
  714. fillOpacity: 0.25
  715. })
  716. editMapInstance.addOverlay(editPolygonOverlay)
  717. }
  718. function togglePolygonDrawing() {
  719. if (!isPolygonPartition.value) return
  720. if (isDrawingPolygon.value && editPolygonPoints.value.length < 3) {
  721. ElMessage.warning('分区面至少需要绘制3个点')
  722. return
  723. }
  724. isDrawingPolygon.value = !isDrawingPolygon.value
  725. if (!isDrawingPolygon.value) finalizePolygon()
  726. }
  727. function finalizePolygon() {
  728. if (editPolygonPoints.value.length < 3) return false
  729. const points = editPolygonPoints.value.map(point => ({
  730. lng: Number(point.lng.toFixed(8)),
  731. lat: Number(point.lat.toFixed(8))
  732. }))
  733. editPolygonPoints.value = points
  734. editForm.value.points = JSON.stringify(points)
  735. editForm.value.longitude = points.reduce((sum, point) => sum + point.lng, 0) / points.length
  736. editForm.value.latitude = points.reduce((sum, point) => sum + point.lat, 0) / points.length
  737. renderEditPolygon()
  738. return true
  739. }
  740. function handleEditSubmit() {
  741. editFormRef.value.validate(async valid => {
  742. if (!valid) return
  743. if (isPolygonPartition.value) {
  744. if (isDrawingPolygon.value) finalizePolygon()
  745. if (editPolygonPoints.value.length < 3) {
  746. ElMessage.warning('分区面至少需要在地图上绘制3个点')
  747. return
  748. }
  749. }
  750. const formData = {
  751. ...editForm.value
  752. }
  753. try {
  754. if (isEditMode.value) {
  755. formData.id = editRowId.value
  756. const res = await updatePartition(formData)
  757. if (res.code === 0 || res.code === 200) {
  758. ElMessage.success('修改成功')
  759. } else {
  760. ElMessage.error(res.msg || '修改失败')
  761. return
  762. }
  763. } else {
  764. const res = await addPartition(formData)
  765. if (res.code === 0 || res.code === 200) {
  766. ElMessage.success('新增成功')
  767. } else {
  768. ElMessage.error(res.msg || '新增失败')
  769. return
  770. }
  771. }
  772. editDialogVisible.value = false
  773. if (editMapInstance) {
  774. editMapInstance = null
  775. }
  776. editMarkerLabel = null
  777. loadData()
  778. } catch (e) {
  779. console.error('提交失败', e)
  780. ElMessage.error('操作失败')
  781. }
  782. })
  783. }
  784. // ==================== 删除功能 ====================
  785. function handleDelete(row) {
  786. ElMessageBox.confirm(`确认删除监测点"${row.name}"吗?`, '提示', {
  787. confirmButtonText: '确定',
  788. cancelButtonText: '取消',
  789. type: 'warning'
  790. }).then(async () => {
  791. try {
  792. const res = await deletePartition(row.id)
  793. if (res.code === 0 || res.code === 200) {
  794. ElMessage.success('删除成功')
  795. loadData()
  796. } else {
  797. ElMessage.error(res.msg || '删除失败')
  798. }
  799. } catch (e) {
  800. ElMessage.error('删除失败')
  801. }
  802. }).catch(() => { })
  803. }
  804. function handleBatchDelete() {
  805. if (selectedIds.value.length === 0) return
  806. ElMessageBox.confirm(`确认删除选中的 ${selectedIds.value.length} 条数据吗?`, '提示', {
  807. confirmButtonText: '确定',
  808. cancelButtonText: '取消',
  809. type: 'warning'
  810. }).then(async () => {
  811. try {
  812. const res = await batchDeletePartition(selectedIds.value)
  813. if (res.code === 0 || res.code === 200) {
  814. selectedIds.value = []
  815. ElMessage.success('删除成功')
  816. loadData()
  817. } else {
  818. ElMessage.error(res.msg || '删除失败')
  819. }
  820. } catch (e) {
  821. ElMessage.error('删除失败')
  822. }
  823. }).catch(() => { })
  824. }
  825. // ==================== 关联设备 ====================
  826. const bindDialogVisible = ref(false)
  827. const currentPartitionId = ref(null)
  828. const bindTableRef = ref(null)
  829. const bindQueryParams = ref({ equipmentName: '', equipmentTypeId: 'drainage' })
  830. const bindTableData = ref([])
  831. const bindTotal = ref(0)
  832. const bindPageNum = ref(1)
  833. const bindPageSize = ref(10)
  834. const bindLoading = ref(false)
  835. const selectedEquipmentIds = ref([])
  836. const boundEquipmentMap = ref({})
  837. async function handleBind(row) {
  838. currentPartitionId.value = row.id
  839. bindDialogVisible.value = true
  840. bindPageNum.value = 1
  841. bindQueryParams.value.equipmentName = ''
  842. selectedEquipmentIds.value = row.equipmentId
  843. ? row.equipmentId.split(',').map(id => id.trim()).filter(Boolean)
  844. : []
  845. nextTick(() => {
  846. loadBindData()
  847. })
  848. }
  849. function handleBindQuery() {
  850. bindPageNum.value = 1
  851. loadBindData()
  852. }
  853. async function loadBindData() {
  854. bindLoading.value = true
  855. try {
  856. const [equipmentResult, boundResult] = await Promise.allSettled([
  857. getEquipmentPage(bindPageNum.value, bindPageSize.value, bindQueryParams.value),
  858. getDrainageBoundEquipmentIds('partition', currentPartitionId.value)
  859. ])
  860. if (equipmentResult.status === 'rejected') {
  861. throw equipmentResult.reason
  862. }
  863. const res = equipmentResult.value
  864. const pageData = res.code !== undefined ? res.data : res
  865. bindTableData.value = pageData.records || []
  866. bindTotal.value = pageData.total || 0
  867. if (boundResult.status === 'fulfilled') {
  868. const boundRes = boundResult.value
  869. const boundData = boundRes.code !== undefined ? boundRes.data : boundRes
  870. boundEquipmentMap.value = boundData && typeof boundData === 'object' ? boundData : {}
  871. } else {
  872. boundEquipmentMap.value = {}
  873. console.warn('加载设备关联状态失败,设备列表仍正常显示', boundResult.reason)
  874. }
  875. } catch (e) {
  876. bindTableData.value = []
  877. bindTotal.value = 0
  878. console.error('加载设备列表失败', e)
  879. } finally {
  880. bindLoading.value = false
  881. }
  882. }
  883. function closeBindDialog() {
  884. bindDialogVisible.value = false
  885. currentPartitionId.value = null
  886. selectedEquipmentIds.value = []
  887. boundEquipmentMap.value = {}
  888. }
  889. function isEquipmentBound(row) {
  890. const id = String(row.equipmentId)
  891. return Boolean(boundEquipmentMap.value[id]) && !selectedEquipmentIds.value.includes(id)
  892. }
  893. function toggleEquipment(row, checked) {
  894. const id = String(row.equipmentId)
  895. if (isEquipmentBound(row)) return
  896. const ids = new Set(selectedEquipmentIds.value)
  897. if (checked) ids.add(id)
  898. else ids.delete(id)
  899. selectedEquipmentIds.value = [...ids]
  900. }
  901. async function submitBind() {
  902. if (!selectedEquipmentIds.value.length) {
  903. ElMessage.warning('请选择要关联的设备')
  904. return
  905. }
  906. try {
  907. const res = await bindPartitionEquipment({
  908. partitionId: currentPartitionId.value,
  909. equipmentIds: selectedEquipmentIds.value
  910. })
  911. if (res.code === 0 || res.code === 200) {
  912. ElMessage.success('关联成功')
  913. closeBindDialog()
  914. loadData()
  915. } else {
  916. ElMessage.error(res.msg || '关联失败')
  917. }
  918. } catch (e) {
  919. console.error('关联设备失败', e)
  920. ElMessage.error('关联失败')
  921. }
  922. }
  923. </script>
  924. <style scoped>
  925. .app-container {
  926. padding: 20px;
  927. }
  928. .search-form {
  929. margin-bottom: 16px;
  930. }
  931. .toolbar {
  932. margin-bottom: 16px;
  933. }
  934. .detail-info {
  935. margin-bottom: 16px;
  936. }
  937. .info-item {
  938. display: flex;
  939. align-items: center;
  940. margin-bottom: 12px;
  941. line-height: 32px;
  942. }
  943. .info-label {
  944. color: #909399;
  945. font-size: 14px;
  946. white-space: nowrap;
  947. }
  948. .info-value {
  949. color: #303133;
  950. font-size: 14px;
  951. }
  952. .text-placeholder {
  953. color: #c0c4cc;
  954. }
  955. .map-section {
  956. border: 1px solid #e4e7ed;
  957. border-radius: 4px;
  958. overflow: hidden;
  959. }
  960. .map-tabs {
  961. display: flex;
  962. background: #f5f7fa;
  963. border-bottom: 1px solid #e4e7ed;
  964. }
  965. .map-tab {
  966. padding: 8px 24px;
  967. font-size: 14px;
  968. cursor: pointer;
  969. color: #606266;
  970. transition: all 0.3s;
  971. user-select: none;
  972. }
  973. .map-tab:hover {
  974. color: #409eff;
  975. }
  976. .map-tab.active {
  977. background: #409eff;
  978. color: #fff;
  979. }
  980. .map-tab-action {
  981. padding: 8px 24px;
  982. font-size: 14px;
  983. cursor: pointer;
  984. color: #f56c6c;
  985. transition: all 0.3s;
  986. user-select: none;
  987. margin-left: auto;
  988. }
  989. .map-tab-action:hover {
  990. color: #f78989;
  991. text-decoration: underline;
  992. }
  993. .map-container {
  994. width: 100%;
  995. height: 400px;
  996. }
  997. .marker-count {
  998. padding: 8px 16px;
  999. font-size: 13px;
  1000. color: #909399;
  1001. background: #f5f7fa;
  1002. border-top: 1px solid #e4e7ed;
  1003. }
  1004. </style>