WaterSupplyHome.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. <template>
  2. <div class="water-page home-page">
  3. <div class="page-heading">
  4. <div class="page-title">
  5. <span class="page-title-icon"><el-icon><HomeFilled /></el-icon></span>
  6. <div>
  7. <h2>供水首页工作台</h2>
  8. <span class="muted">面向值班态的一站式供水运行工作台,仅统计供水设施与供水监测设备</span>
  9. </div>
  10. </div>
  11. <div class="heading-actions">
  12. <el-button :icon="Refresh" :loading="loading" @click="loadAll">刷新</el-button>
  13. </div>
  14. </div>
  15. <el-alert v-if="loadError" class="load-error" type="error" show-icon :closable="false"
  16. title="部分数据加载失败" :description="loadError">
  17. <el-button size="small" type="primary" :loading="loading" @click="loadAll">重试</el-button>
  18. </el-alert>
  19. <!-- A 指挥台 -->
  20. <section class="home-section">
  21. <div class="metric-grid">
  22. <div v-for="card in homeKpis" :key="card.key" class="metric">
  23. <div class="metric-icon"><el-icon><component :is="kpiIcon(card.key)"/></el-icon></div>
  24. <div class="metric-body">
  25. <span>{{ card.label }}</span>
  26. <div class="metric-value">
  27. <strong :class="card.tone">{{ card.value }}</strong><small>{{ card.unit }}</small>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. <div class="workbench-grid">
  33. <el-card shadow="never" class="water-panel home-panel">
  34. <template #header>
  35. <div class="card-title">
  36. <el-icon><Bell /></el-icon><span>实时报警</span>
  37. <el-button link type="primary" class="panel-link" @click="goPage('/monitorAlarm/index')">前往报警管理</el-button>
  38. </div>
  39. </template>
  40. <div class="compact-list">
  41. <button v-for="item in alarmRows" :key="item.id || item.deviceCode" type="button"
  42. class="compact-item" @click="openRealtimeAlarm(item)">
  43. <span class="status-dot dot-alarm" />
  44. <span class="compact-main">
  45. <b>{{ item.deviceName }}</b>
  46. <small>{{ item.deviceCode }}</small>
  47. </span>
  48. <span class="compact-meta">
  49. <el-tag size="small" :type="item.displayStatusType">{{ item.displayStatusText }}</el-tag>
  50. <el-tag size="small" :type="levelType(item.alarmLevel)">{{ item.alarmLevelText }}</el-tag>
  51. <small>{{ item.alarmTime }}</small>
  52. </span>
  53. </button>
  54. <el-empty v-if="!alarmRows.length" description="当前无实时报警" :image-size="60" />
  55. </div>
  56. </el-card>
  57. <el-card shadow="never" class="water-panel home-panel map-panel">
  58. <template #header>
  59. <div class="card-title">
  60. <el-icon><MapLocation /></el-icon><span>全域态势</span>
  61. <div class="map-legend">
  62. <i class="legend-dot" :style="{ background: gisPointStatusColors.alarm }" />报警/异常
  63. <i class="legend-dot" :style="{ background: gisPointStatusColors.workOrder }" />工单/检修中
  64. <i class="legend-dot" :style="{ background: gisPointStatusColors.warning }" />预警/欠费
  65. <i class="legend-dot" :style="{ background: gisPointStatusColors.offline }" />离线
  66. <i class="legend-dot" :style="{ background: gisPointStatusColors.normal }" />正常
  67. </div>
  68. <div class="panel-links">
  69. <el-button link type="primary" class="panel-link" @click="goPage('/facility/gis')">设施</el-button>
  70. <el-button link type="primary" class="panel-link" @click="goPage('/device/gis')">设备</el-button>
  71. <el-button link type="primary" class="panel-link" @click="goPage('/monitorAlarm/map')">报警</el-button>
  72. </div>
  73. </div>
  74. </template>
  75. <div class="map-stage">
  76. <GisMapCanvas
  77. ref="overviewMapRef"
  78. :points="overviewMapPoints"
  79. :lines="overviewMapLines"
  80. cluster-label="供水点位"
  81. :center="overviewMapCenter"
  82. :zoom="overviewMapZoom"
  83. @point-click="openOverviewPoint"
  84. @line-click="openOverviewPoint"
  85. @map-click="overviewDetailOpen = false"
  86. @ready="handleOverviewMapReady"
  87. @error="overviewMapError = $event"
  88. />
  89. <el-alert v-if="overviewMapError" class="map-inline-alert" type="warning" show-icon :closable="false"
  90. :title="overviewMapError">
  91. <el-button link type="primary" @click="loadAll">重试</el-button>
  92. </el-alert>
  93. <el-empty v-else-if="overviewLoaded && !overviewMapPoints.length && !overviewMapLines.length"
  94. class="map-inline-empty" description="暂无可展示的全域点位" :image-size="70" />
  95. </div>
  96. <el-drawer v-model="overviewDetailOpen" title="点位详情" size="420px" direction="rtl"
  97. class="detail-drawer" append-to-body>
  98. <div v-if="overviewDetail" class="overview-detail">
  99. <section class="detail-hero">
  100. <h3>{{ overviewDetail.name }}</h3>
  101. <p>{{ overviewDetail.code }}</p>
  102. <div class="status-tags">
  103. <el-tag size="small" :type="gisStatusTagType(overviewDetail.statusKey)">
  104. {{ overviewDetail.statusText || gisStatusLabel(overviewDetail.statusKey) }}
  105. </el-tag>
  106. <el-tag v-if="overviewDetail.meta" size="small" type="info">{{ overviewDetail.meta }}</el-tag>
  107. </div>
  108. </section>
  109. <section class="detail-section">
  110. <h4>点位信息</h4>
  111. <dl>
  112. <dt>名称</dt><dd>{{ overviewDetail.name }}</dd>
  113. <dt>编码</dt><dd>{{ overviewDetail.code }}</dd>
  114. <dt>类别</dt><dd>{{ overviewKindLabel(overviewDetail.kind) }}</dd>
  115. <dt>状态</dt><dd>{{ overviewDetail.statusText || gisStatusLabel(overviewDetail.statusKey) }}</dd>
  116. <dt>类型 / 报警</dt><dd>{{ overviewDetail.meta }}</dd>
  117. <dt>经度</dt><dd>{{ overviewDetail.lng }}</dd>
  118. <dt>纬度</dt><dd>{{ overviewDetail.lat }}</dd>
  119. </dl>
  120. </section>
  121. </div>
  122. <el-empty v-else description="请点击地图点位查看详情" :image-size="70" />
  123. </el-drawer>
  124. </el-card>
  125. <el-card shadow="never" class="water-panel home-panel">
  126. <template #header>
  127. <div class="card-title">
  128. <el-icon><Tickets /></el-icon><span>工单进展</span>
  129. <el-button link type="primary" class="panel-link" @click="goPage('/device/maintain')">设备维修派单</el-button>
  130. </div>
  131. </template>
  132. <div class="compact-list">
  133. <button v-for="item in workOrderRows" :key="item.orderId || item.orderNo" type="button"
  134. class="compact-item" @click="goPage('/device/maintain', { keyword: item.orderNo })">
  135. <span class="status-dot" :class="dotByOrderType(item.orderStatusType)" />
  136. <span class="compact-main">
  137. <b>{{ item.orderNo }}</b>
  138. <small>{{ item.deviceName || item.deviceCode }}</small>
  139. </span>
  140. <span class="compact-meta">
  141. <el-tag size="small" :type="item.orderStatusType">{{ item.orderStatusText }}</el-tag>
  142. </span>
  143. </button>
  144. <el-empty v-if="!workOrderRows.length" description="当前暂无供水工单" :image-size="60" />
  145. </div>
  146. <div class="order-brief">
  147. <span>待处理 <b>{{ workOrderStat.pendingCount }}</b></span>
  148. <span>处理中 <b>{{ workOrderStat.processingCount }}</b></span>
  149. <span>待验收 <b>{{ workOrderStat.verifyingCount }}</b></span>
  150. <span>已完成 <b>{{ workOrderStat.finishedCount }}</b></span>
  151. </div>
  152. </el-card>
  153. </div>
  154. </section>
  155. <!-- B 异常待办 -->
  156. <section class="home-section">
  157. <div class="workbench-grid workbench-grid--equal">
  158. <el-card shadow="never" class="water-panel home-panel">
  159. <template #header>
  160. <div class="card-title">
  161. <el-icon><Warning /></el-icon><span>异常待办</span>
  162. <el-button link type="primary" class="panel-link" @click="goPage('/device/abnormal')">查看全部</el-button>
  163. </div>
  164. </template>
  165. <div class="compact-list">
  166. <button v-for="item in abnormalTodoRows" :key="item.equipmentId" type="button"
  167. class="compact-item" :class="{ active: selectedDevice && selectedDevice.equipmentId === item.equipmentId }"
  168. @click="selectAbnormal(item)">
  169. <span class="status-dot" :class="abnormalDot(item)" />
  170. <span class="compact-main">
  171. <b>{{ item.equipmentName || item.equipmentCode }}</b>
  172. <small>{{ item.equipmentCode }}</small>
  173. </span>
  174. <span class="compact-meta">
  175. <el-tag size="small" :type="abnormalType(item)">{{ item.abnormalReasonText || '设备异常' }}</el-tag>
  176. </span>
  177. </button>
  178. <el-empty v-if="!abnormalTodoRows.length" description="当前无异常设备待办" :image-size="60" />
  179. </div>
  180. </el-card>
  181. <el-card shadow="never" class="water-panel home-panel detail-panel">
  182. <template #header>
  183. <div class="card-title"><el-icon><Cpu /></el-icon><span>设备详情</span></div>
  184. </template>
  185. <div v-if="selectedDevice" class="device-summary">
  186. <div class="summary-top">
  187. <div class="summary-name">{{ selectedDevice.name }}</div>
  188. <div class="summary-tags">
  189. <el-tag size="small" :type="Number(selectedDevice.alarmStatus) === 1 ? 'danger' : 'success'">{{ selectedDevice.alarmStatusText }}</el-tag>
  190. <el-tag size="small" :type="Number(selectedDevice.onlineStatus) === 1 ? 'success' : 'info'">{{ selectedDevice.onlineStatusText }}</el-tag>
  191. <el-tag v-if="selectedDevice.relatedOrderNo && selectedDevice.relatedOrderNo !== '-'" size="small"
  192. :type="selectedDevice.workOrderStatusCode != null ? orderType(selectedDevice.workOrderStatusCode) : 'info'">
  193. {{ selectedDevice.workOrderStatusText }}
  194. </el-tag>
  195. </div>
  196. </div>
  197. <el-descriptions :column="1" border size="small">
  198. <el-descriptions-item label="设备编码">{{ selectedDevice.code }}</el-descriptions-item>
  199. <el-descriptions-item label="设备类型">{{ selectedDevice.typeName }}</el-descriptions-item>
  200. <el-descriptions-item label="所属区域">{{ selectedDevice.district || '-' }}</el-descriptions-item>
  201. <el-descriptions-item label="安装位置">{{ selectedDevice.location || '-' }}</el-descriptions-item>
  202. <el-descriptions-item label="报警等级">{{ selectedDevice.alarmLevelText }}</el-descriptions-item>
  203. <el-descriptions-item label="异常原因">{{ selectedDevice.abnormalReasonText || '-' }}</el-descriptions-item>
  204. <el-descriptions-item label="关联工单">
  205. <el-button v-if="selectedDevice.relatedOrderNo && selectedDevice.relatedOrderNo !== '-'" link type="primary"
  206. @click="goPage('/device/maintain', { keyword: selectedDevice.relatedOrderNo })">
  207. {{ selectedDevice.relatedOrderNo }}
  208. </el-button>
  209. <span v-else>-</span>
  210. </el-descriptions-item>
  211. </el-descriptions>
  212. </div>
  213. <el-empty v-else description="从左侧异常待办中选择设备" :image-size="70" />
  214. </el-card>
  215. <el-card shadow="never" class="water-panel home-panel">
  216. <template #header>
  217. <div class="card-title"><el-icon><Grid /></el-icon><span>快捷入口</span></div>
  218. </template>
  219. <div class="quick-grid">
  220. <button v-for="entry in quickEntries" :key="entry.key" type="button" class="quick-entry"
  221. @click="goPage(entry.suffix)">
  222. <el-icon><component :is="entryIcon(entry.key)"/></el-icon>
  223. <span>{{ entry.label }}</span>
  224. </button>
  225. </div>
  226. </el-card>
  227. </div>
  228. </section>
  229. <!-- C 数据总览 -->
  230. <section class="home-section">
  231. <div class="metric-grid">
  232. <div v-for="card in overviewCards" :key="card.key" class="metric">
  233. <div class="metric-icon"><el-icon><component :is="overviewIcon(card.key)"/></el-icon></div>
  234. <div class="metric-body">
  235. <span>{{ card.label }}</span>
  236. <div class="metric-value">
  237. <strong :class="card.tone">{{ card.value }}</strong><small>{{ card.unit }}</small>
  238. </div>
  239. </div>
  240. </div>
  241. </div>
  242. <div class="chart-grid">
  243. <el-card shadow="never" class="water-panel chart-card trend-card">
  244. <template #header>
  245. <div class="card-title">
  246. <el-icon><TrendCharts /></el-icon><span>报警趋势</span>
  247. <span class="muted">近 {{ trendDays }} 天 · 按四个报警等级分别统计</span>
  248. </div>
  249. </template>
  250. <div ref="trendChartRef" class="chart" />
  251. </el-card>
  252. <el-card shadow="never" class="water-panel chart-card">
  253. <template #header>
  254. <div class="card-title"><el-icon><PieChart /></el-icon><span>报警分类占比</span></div>
  255. </template>
  256. <div ref="warningPieRef" class="chart" />
  257. </el-card>
  258. <el-card shadow="never" class="water-panel chart-card">
  259. <template #header>
  260. <div class="card-title"><el-icon><DataAnalysis /></el-icon><span>设备分类占比</span></div>
  261. </template>
  262. <div ref="devicePieRef" class="chart" />
  263. </el-card>
  264. </div>
  265. </section>
  266. </div>
  267. </template>
  268. <script setup>
  269. import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
  270. import { useRouter } from 'vue-router'
  271. import * as echarts from 'echarts'
  272. import {
  273. Bell, BellFilled, Connection, Cpu, DataAnalysis, Finished, Grid, HomeFilled,
  274. MapLocation, OfficeBuilding, PieChart, Refresh, Tickets, TrendCharts,
  275. Warning, WarningFilled
  276. } from '@element-plus/icons-vue'
  277. import { getAlarmStats, getDeviceGisAllPoints,
  278. getWaterFacilityFeatures, getWaterFacilityOverview, listAlarmMapPoints,
  279. listRealtimeAlarms } from '@/api/pipeNetwork/waterSupply'
  280. import { getAlarmDashboard } from '@/api/alarm'
  281. import { getEquipmentStatusStatistics, listEquipment } from '@/api/pipeNetwork/pdeviceInform'
  282. import { listWorkOrder, workOrderStatusCount } from '@/api/pipeNetwork/ops/workOrder'
  283. import { normalizeGeoJson, normalizePage, unwrapResponse } from '@/utils/waterSupplyModel'
  284. import { normalizeDeviceGisPoints } from '@/utils/waterSupplyUiModel'
  285. import { gisPointStatusColors, gisPointStatusLabels, gisPointStatusTagTypes } from '@/utils/gisMapColors'
  286. import { buildFacilityMapModel } from '@/utils/waterFacilityGisModel'
  287. import GisMapCanvas from '@/components/GisMapCanvas.vue'
  288. import {
  289. HOME_QUICK_ENTRIES, WATER_DEVICE_ROOT_TYPE_ID, buildHomeGisOverview, buildHomeWorkOrderQuery,
  290. normalizeAbnormalTodoRows, normalizeAlarmOverviewCards, normalizeAlarmTrend, normalizeDeviceSummary,
  291. normalizeDeviceStatistics, normalizeHomeKpis, normalizePieRatio, normalizeRealtimeAlarmRows, realtimeAlarmJumpTarget,
  292. normalizeWorkOrderRows, normalizeWorkOrderStatusStat
  293. } from '@/utils/waterHomeModel'
  294. const router = useRouter()
  295. const loading = ref(true)
  296. const loadError = ref('')
  297. const trendDays = 7
  298. const quickEntries = HOME_QUICK_ENTRIES
  299. const facilityRows = ref([])
  300. const ledgerStats = ref({})
  301. const alarmStats = ref({})
  302. const alarmDashboard = ref({})
  303. const alarmRows = ref([])
  304. const workOrderRows = ref([])
  305. const workOrderStat = ref({})
  306. const abnormalTodoRows = ref([])
  307. const overviewMapPoints = ref([])
  308. const overviewMapLines = ref([])
  309. const overviewDeviceRaw = ref([])
  310. const overviewMapCenter = { lng: 110.3965, lat: 28.4638 }
  311. const overviewMapZoom = 15
  312. const overviewMapError = ref('')
  313. const overviewLoaded = ref(false)
  314. const overviewDetailOpen = ref(false)
  315. const overviewDetail = ref(null)
  316. const overviewMapRef = ref(null)
  317. const selectedDevice = ref(null)
  318. const homeKpis = ref([])
  319. const overviewCards = ref([])
  320. const trendData = ref({ dates: [], levels: [] })
  321. const warningRatio = ref([])
  322. const deviceRatio = ref([])
  323. const trendChartRef = ref(null)
  324. const warningPieRef = ref(null)
  325. const devicePieRef = ref(null)
  326. let trendChart = null
  327. let warningPie = null
  328. let devicePie = null
  329. const KPI_ICON = {
  330. facility: OfficeBuilding,
  331. device: Cpu,
  332. online: Connection,
  333. alarm: BellFilled
  334. }
  335. const OVERVIEW_ICON = {
  336. alarmTotal: BellFilled,
  337. alarmingDevice: WarningFilled,
  338. verifyingOrder: Tickets,
  339. onlineRate: TrendCharts
  340. }
  341. const ENTRY_ICON = {
  342. abnormal: WarningFilled,
  343. alarm: BellFilled,
  344. audit: Finished,
  345. map: MapLocation
  346. }
  347. function kpiIcon(key) { return KPI_ICON[key] || OfficeBuilding }
  348. function overviewIcon(key) { return OVERVIEW_ICON[key] || DataAnalysis }
  349. function entryIcon(key) { return ENTRY_ICON[key] || Grid }
  350. function levelType(level) {
  351. const meta = { 1: 'danger', 2: 'warning', 3: 'primary', 4: 'success' }
  352. return meta[Number(level)] || 'info'
  353. }
  354. function orderType(status) {
  355. const meta = {
  356. 0: 'danger', 1: 'warning', 2: 'primary', 3: 'warning',
  357. 4: 'primary', 5: 'success', 6: 'warning', 7: 'info'
  358. }
  359. return meta[Number(status)] || 'info'
  360. }
  361. function dotByOrderType(type) {
  362. const map = { danger: 'dot-danger', warning: 'dot-warning', primary: 'dot-primary', success: 'dot-success', info: 'dot-info' }
  363. return map[type] || 'dot-info'
  364. }
  365. function abnormalDot(row) {
  366. if (Number(row.alarmStatus) === 1) return 'dot-alarm'
  367. if (Number(row.onlineStatus) === 0) return 'dot-offline'
  368. return 'dot-warning'
  369. }
  370. function abnormalType(row) {
  371. if (Number(row.alarmStatus) === 1) return 'danger'
  372. if (Number(row.onlineStatus) === 0) return 'info'
  373. return 'warning'
  374. }
  375. async function settle(fn, fallback = null, onError = null) {
  376. try {
  377. return await fn()
  378. } catch (error) {
  379. console.warn('供水首页数据片段加载失败', error)
  380. // 失败上报必须在这里完成:本函数已吞掉异常并返回兜底值,
  381. // 调用侧再挂 .catch 永远不会触发,“部分数据加载失败”提示会变成死代码。
  382. onError?.()
  383. if (fallback !== null) return fallback
  384. throw error
  385. }
  386. }
  387. async function loadAll() {
  388. loading.value = true
  389. loadError.value = ''
  390. const problems = []
  391. const recordProblem = label => () => { problems.push(label) }
  392. const [overview, ledger, alarm, dashboard, realtime, abnormal, orderStat, orders, deviceGis] = await Promise.allSettled([
  393. settle(() => getWaterFacilityOverview(), [], recordProblem('设施概览')),
  394. settle(() => getEquipmentStatusStatistics(WATER_DEVICE_ROOT_TYPE_ID), {}, recordProblem('设备统计')),
  395. settle(() => getAlarmStats(), {}, recordProblem('报警统计')),
  396. settle(() => getAlarmDashboard({ rootTypeId: WATER_DEVICE_ROOT_TYPE_ID, days: trendDays }), {}, recordProblem('报警态势')),
  397. settle(() => listRealtimeAlarms(), [], recordProblem('实时报警')),
  398. // 异常待办 = 当前处于报警中的供水设备;设备状态由 equipment_status 维护
  399. settle(() => listEquipment({ pageNum: 1, pageSize: 50, rootTypeId: WATER_DEVICE_ROOT_TYPE_ID, alarmStatus: 1 }), { records: [], total: 0 }, recordProblem('异常待办')),
  400. settle(() => workOrderStatusCount(buildHomeWorkOrderQuery()), { total: 0, counts: [] }, recordProblem('工单统计')),
  401. settle(() => listWorkOrder(buildHomeWorkOrderQuery({ pageSize: 20 })), { records: [], total: 0 }, recordProblem('工单列表')),
  402. settle(() => getDeviceGisAllPoints(), { features: [] }, recordProblem('设备点位'))
  403. ])
  404. const overviewData = unwrapResponse(overview.value || [])
  405. facilityRows.value = Array.isArray(overviewData) ? overviewData : (overviewData?.facilityOverview || [])
  406. ledgerStats.value = normalizeDeviceStatistics(unwrapResponse(ledger.value || {}))
  407. alarmStats.value = unwrapResponse(alarm.value || {})
  408. alarmDashboard.value = unwrapResponse(dashboard.value || {})
  409. alarmRows.value = normalizeRealtimeAlarmRows(unwrapResponse(realtime.value || []), 20)
  410. const abnormalPage = normalizePage(abnormal.value || { records: [], total: 0 })
  411. abnormalTodoRows.value = normalizeAbnormalTodoRows(abnormalPage.records, 20)
  412. workOrderStat.value = normalizeWorkOrderStatusStat(unwrapResponse(orderStat.value || { total: 0, counts: [] }))
  413. const orderList = unwrapResponse(orders.value || { records: [] })
  414. workOrderRows.value = normalizeWorkOrderRows(orderList?.records || [], 20)
  415. const gisData = unwrapResponse(deviceGis.value || {})
  416. overviewDeviceRaw.value = Array.isArray(gisData) ? gisData : (gisData?.features || [])
  417. await loadOverviewMap(recordProblem)
  418. homeKpis.value = normalizeHomeKpis({ facilityRows: facilityRows.value, ledgerStats: ledgerStats.value, alarmStats: alarmStats.value })
  419. overviewCards.value = normalizeAlarmOverviewCards({
  420. dashboard: alarmDashboard.value,
  421. deviceStats: ledgerStats.value,
  422. workOrderStat: workOrderStat.value
  423. })
  424. trendData.value = normalizeAlarmTrend(alarmDashboard.value?.trend || [])
  425. warningRatio.value = normalizePieRatio(alarmDashboard.value?.warningTypeRatio || [], '未分类', 6)
  426. deviceRatio.value = normalizePieRatio(alarmDashboard.value?.deviceTypeRatio || [], '未分类', 6)
  427. if (problems.length) loadError.value = problems.join(';')
  428. loading.value = false
  429. await nextTick()
  430. renderCharts()
  431. }
  432. function selectAbnormal(row) {
  433. selectedDevice.value = normalizeDeviceSummary(row)
  434. }
  435. async function loadOverviewMap(recordProblem) {
  436. overviewMapError.value = ''
  437. const [facilityRes, alarmRes] = await Promise.all([
  438. settle(() => getWaterFacilityFeatures(), { features: [] }, recordProblem('设施GIS点位')),
  439. settle(() => listAlarmMapPoints(), [], recordProblem('报警点位'))
  440. ])
  441. const facilityModel = buildFacilityMapModel(normalizeGeoJson(facilityRes))
  442. const overviewModel = buildHomeGisOverview({
  443. facilityPoints: facilityModel.points,
  444. facilityLines: facilityModel.lines,
  445. devicePoints: normalizeDeviceGisPoints(overviewDeviceRaw.value),
  446. alarmPoints: (Array.isArray(alarmRes) ? alarmRes : [])
  447. })
  448. overviewMapPoints.value = overviewModel.points
  449. overviewMapLines.value = overviewModel.lines
  450. overviewLoaded.value = true
  451. await nextTick()
  452. overviewMapRef.value?.fitBounds()
  453. }
  454. function handleOverviewMapReady() {
  455. nextTick(() => overviewMapRef.value?.fitBounds())
  456. }
  457. function openOverviewPoint(point) {
  458. overviewDetail.value = point || null
  459. overviewDetailOpen.value = Boolean(point)
  460. }
  461. function openRealtimeAlarm(item) {
  462. const target = realtimeAlarmJumpTarget(item)
  463. goPage(target.path, target.query)
  464. }
  465. function resolveRoutePath(suffix) {
  466. const matched = router.getRoutes().find(item => item.path.endsWith(suffix))
  467. return matched ? matched.path : ''
  468. }
  469. function goPage(suffix, query = {}) {
  470. const path = resolveRoutePath(suffix)
  471. if (!path) {
  472. console.warn(`未找到供水入口路由: ${suffix}`)
  473. return
  474. }
  475. router.push({ path, query }).catch(() => {})
  476. }
  477. function gisStatusLabel(statusKey) {
  478. return gisPointStatusLabels[statusKey] || '正常'
  479. }
  480. function gisStatusTagType(statusKey) {
  481. return gisPointStatusTagTypes[statusKey] || 'success'
  482. }
  483. function overviewKindLabel(kind) {
  484. return { device: '监测设备', alarm: '报警', facility: '供水设施' }[kind] || '点位'
  485. }
  486. function renderCharts() {
  487. renderTrendChart()
  488. warningPie?.dispose()
  489. warningPie = renderPieChart(warningPieRef.value, warningRatio.value, '报警数')
  490. devicePie?.dispose()
  491. devicePie = renderPieChart(devicePieRef.value, deviceRatio.value, '设备数')
  492. }
  493. function renderTrendChart() {
  494. if (!trendChartRef.value) return
  495. trendChart?.dispose()
  496. trendChart = echarts.init(trendChartRef.value)
  497. const { dates, levels } = trendData.value
  498. const palette = ['#f56c6c', '#e6a23c', '#409eff', '#67c23a']
  499. trendChart.setOption({
  500. tooltip: { trigger: 'axis' },
  501. legend: { bottom: 0, icon: 'circle', itemWidth: 9, itemHeight: 9, textStyle: { color: '#475569' } },
  502. grid: { left: 34, right: 14, top: 18, bottom: 48, containLabel: true },
  503. xAxis: {
  504. type: 'category',
  505. data: dates,
  506. axisLine: { lineStyle: { color: '#cbd5e1' } },
  507. axisLabel: { color: '#64748b' }
  508. },
  509. yAxis: {
  510. type: 'value',
  511. minInterval: 1,
  512. splitLine: { lineStyle: { color: '#eef2f7' } },
  513. axisLabel: { color: '#64748b' }
  514. },
  515. color: palette,
  516. series: levels.map((level, index) => ({
  517. name: level.text || `级${index + 1}`,
  518. type: 'bar',
  519. stack: 'alarm',
  520. barWidth: 26,
  521. data: level.data,
  522. itemStyle: { borderRadius: index === levels.length - 1 ? [5, 5, 0, 0] : 0 }
  523. }))
  524. })
  525. }
  526. function renderPieChart(container, data, unit) {
  527. if (!container) return null
  528. const total = data.reduce((sum, item) => sum + item.count, 0)
  529. const chart = echarts.init(container)
  530. chart.setOption({
  531. tooltip: { trigger: 'item', formatter: `{b}:{c} ${unit}({d}%)` },
  532. legend: { bottom: 0, icon: 'circle', itemWidth: 9, itemHeight: 9, textStyle: { color: '#475569' } },
  533. title: {
  534. text: String(total),
  535. subtext: unit,
  536. left: 'center',
  537. top: '32%',
  538. textStyle: { color: '#1e293b', fontSize: 24, fontWeight: 700 },
  539. subtextStyle: { color: '#64748b', fontSize: 12 }
  540. },
  541. color: ['#2563eb', '#14b8a6', '#f59e0b', '#ef4444', '#8b5cf6', '#64748b'],
  542. series: [{
  543. type: 'pie',
  544. radius: ['48%', '68%'],
  545. center: ['50%', '43%'],
  546. data: data.map(item => ({ name: item.name, value: item.count })),
  547. label: { formatter: '{b}\n{d}%', color: '#475569', lineHeight: 17 },
  548. itemStyle: { borderColor: '#fff', borderWidth: 3, borderRadius: 8 },
  549. emphasis: { scaleSize: 7 }
  550. }]
  551. })
  552. return chart
  553. }
  554. function handleResize() {
  555. trendChart?.resize()
  556. warningPie?.resize()
  557. devicePie?.resize()
  558. }
  559. onMounted(async () => {
  560. await loadAll()
  561. window.addEventListener('resize', handleResize)
  562. })
  563. onBeforeUnmount(() => {
  564. window.removeEventListener('resize', handleResize)
  565. trendChart?.dispose()
  566. warningPie?.dispose()
  567. devicePie?.dispose()
  568. })
  569. </script>
  570. <style lang="scss">
  571. @use './waterSupplyPageTheme.scss';
  572. </style>
  573. <style scoped>
  574. .home-page {
  575. background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 45%, #eef2f7 100%);
  576. }
  577. .heading-actions {
  578. display: flex;
  579. align-items: center;
  580. gap: 10px;
  581. }
  582. .page-title-icon {
  583. display: grid;
  584. place-items: center;
  585. width: 42px;
  586. height: 42px;
  587. color: #fff;
  588. background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
  589. border-radius: 8px;
  590. box-shadow: 0 8px 16px rgba(37, 99, 235, 0.2);
  591. }
  592. .load-error {
  593. margin-bottom: 14px;
  594. }
  595. .home-section {
  596. margin-bottom: 20px;
  597. }
  598. .metric-grid {
  599. display: grid;
  600. grid-template-columns: repeat(4, minmax(0, 1fr));
  601. gap: 12px;
  602. margin-bottom: 14px;
  603. }
  604. .metric {
  605. display: flex;
  606. align-items: center;
  607. gap: 14px;
  608. min-width: 0;
  609. padding: 14px 16px;
  610. background: #fff;
  611. border: 1px solid #e1ebf3;
  612. border-radius: 8px;
  613. box-shadow: 0 6px 14px rgba(15, 23, 42, 0.04);
  614. }
  615. .metric-icon {
  616. position: static;
  617. flex: 0 0 42px;
  618. display: grid;
  619. place-items: center;
  620. width: 42px;
  621. height: 42px;
  622. color: #2563eb;
  623. background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%);
  624. border-radius: 8px;
  625. font-size: 22px;
  626. }
  627. .metric-body {
  628. min-width: 0;
  629. }
  630. .metric-body span {
  631. display: block;
  632. overflow: hidden;
  633. margin-bottom: 3px;
  634. color: #64748b;
  635. font-size: 13px;
  636. text-overflow: ellipsis;
  637. white-space: nowrap;
  638. }
  639. .metric-value {
  640. display: flex;
  641. align-items: baseline;
  642. gap: 5px;
  643. }
  644. .metric-value strong {
  645. color: #1e293b;
  646. font-size: 24px;
  647. line-height: 1.2;
  648. }
  649. .metric-value strong.danger { color: #dc2626; }
  650. .metric-value strong.warning { color: #d97706; }
  651. .metric-value small {
  652. color: #94a3b8;
  653. }
  654. .workbench-grid {
  655. display: grid;
  656. grid-template-columns: minmax(240px, 1fr) minmax(0, 3fr) minmax(240px, 1fr);
  657. gap: 12px;
  658. align-items: stretch;
  659. }
  660. .workbench-grid--equal {
  661. grid-template-columns: repeat(3, minmax(0, 1fr));
  662. }
  663. .home-panel {
  664. min-width: 0;
  665. border: 1px solid #e1ebf3;
  666. border-radius: 8px;
  667. box-shadow: 0 5px 16px rgba(28, 75, 110, 0.05);
  668. }
  669. .map-panel {
  670. display: flex;
  671. flex-direction: column;
  672. min-height: 0;
  673. }
  674. .map-panel :deep(.el-card__body) {
  675. display: flex;
  676. flex-direction: column;
  677. flex: 1;
  678. min-height: 0;
  679. }
  680. .home-panel :deep(.el-card__header) {
  681. padding: 12px 16px;
  682. border-bottom: 1px solid #e1ebf3;
  683. background: #fbfdff;
  684. }
  685. .home-panel :deep(.el-card__body) {
  686. padding: 12px 14px;
  687. }
  688. .card-title {
  689. display: flex;
  690. align-items: center;
  691. gap: 8px;
  692. color: #1e293b;
  693. font-weight: 600;
  694. }
  695. .card-title :deep(.el-icon) {
  696. color: #2563eb;
  697. font-size: 18px;
  698. }
  699. .card-title .muted {
  700. margin-left: auto;
  701. font-size: 12px;
  702. font-weight: 400;
  703. }
  704. .panel-link {
  705. margin-left: auto;
  706. }
  707. .panel-links {
  708. display: flex;
  709. align-items: center;
  710. gap: 2px;
  711. margin-left: auto;
  712. }
  713. .panel-links .panel-link {
  714. margin-left: 0;
  715. }
  716. .legend-dot {
  717. display: inline-block;
  718. width: 8px;
  719. height: 8px;
  720. border-radius: 50%;
  721. }
  722. .compact-list {
  723. display: flex;
  724. flex-direction: column;
  725. gap: 7px;
  726. min-height: 220px;
  727. max-height: 360px;
  728. overflow-y: auto;
  729. padding-right: 2px;
  730. }
  731. .compact-item {
  732. display: grid;
  733. grid-template-columns: 10px minmax(0, 1fr) auto;
  734. gap: 9px;
  735. align-items: center;
  736. width: 100%;
  737. padding: 9px 10px;
  738. text-align: left;
  739. background: #fff;
  740. border: 1px solid #eef2f7;
  741. border-radius: 8px;
  742. cursor: pointer;
  743. transition: all 0.15s ease;
  744. }
  745. .compact-item:hover {
  746. background: #f6fbff;
  747. border-color: #bfdbfe;
  748. }
  749. .compact-item.active {
  750. background: #eef6ff;
  751. border-color: #93c5fd;
  752. }
  753. .status-dot {
  754. width: 9px;
  755. height: 9px;
  756. border-radius: 50%;
  757. background: #94a3b8;
  758. }
  759. .dot-alarm { background: #dc2626; }
  760. .dot-offline { background: #94a3b8; }
  761. .dot-normal { background: #16a34a; }
  762. .dot-warning { background: #d97706; }
  763. .dot-danger { background: #dc2626; }
  764. .dot-primary { background: #2563eb; }
  765. .dot-success { background: #16a34a; }
  766. .dot-info { background: #94a3b8; }
  767. .dot-workorder { background: #2563eb; }
  768. .compact-main {
  769. display: block;
  770. min-width: 0;
  771. }
  772. .compact-main b,
  773. .compact-main small {
  774. display: block;
  775. overflow: hidden;
  776. text-overflow: ellipsis;
  777. white-space: nowrap;
  778. }
  779. .compact-main b {
  780. color: #1e293b;
  781. font-size: 13px;
  782. font-weight: 600;
  783. }
  784. .compact-main small {
  785. margin-top: 2px;
  786. color: #94a3b8;
  787. font-size: 12px;
  788. }
  789. .compact-meta {
  790. display: flex;
  791. flex-direction: column;
  792. align-items: flex-end;
  793. gap: 3px;
  794. min-width: 0;
  795. }
  796. .compact-meta small {
  797. color: #94a3b8;
  798. font-size: 11px;
  799. white-space: nowrap;
  800. }
  801. .map-stage {
  802. position: relative;
  803. flex: 1;
  804. min-height: 0;
  805. height: auto;
  806. overflow: hidden;
  807. border: 1px solid #e1ebf3;
  808. border-radius: 8px;
  809. background: #eef6ff;
  810. }
  811. .map-stage :deep(.gis-map-canvas) {
  812. width: 100%;
  813. height: 100%;
  814. min-height: 0;
  815. }
  816. .map-inline-alert {
  817. position: absolute;
  818. left: 16px;
  819. bottom: 16px;
  820. z-index: 3;
  821. width: 340px;
  822. }
  823. .map-inline-empty {
  824. position: absolute;
  825. left: 50%;
  826. top: 50%;
  827. z-index: 2;
  828. transform: translate(-50%, -50%);
  829. }
  830. .map-legend {
  831. display: flex;
  832. align-items: center;
  833. gap: 7px;
  834. margin-left: auto;
  835. color: #64748b;
  836. font-size: 12px;
  837. }
  838. .overview-detail {
  839. min-height: 240px;
  840. }
  841. .detail-hero h3,
  842. .detail-section h4 {
  843. margin: 0 0 8px;
  844. color: #1c4b78;
  845. }
  846. .detail-hero p {
  847. margin: 0 0 10px;
  848. color: #678197;
  849. font-size: 13px;
  850. }
  851. .status-tags {
  852. display: flex;
  853. flex-wrap: wrap;
  854. gap: 6px;
  855. }
  856. .detail-section {
  857. margin-top: 18px;
  858. padding-top: 12px;
  859. border-top: 1px solid #e5eef7;
  860. }
  861. .detail-section dl {
  862. display: grid;
  863. grid-template-columns: 92px minmax(0, 1fr);
  864. gap: 7px 10px;
  865. margin: 0;
  866. font-size: 13px;
  867. }
  868. .detail-section dt {
  869. color: #71889c;
  870. }
  871. .detail-section dd {
  872. margin: 0;
  873. color: #2b4c67;
  874. overflow-wrap: anywhere;
  875. }
  876. .order-brief {
  877. display: grid;
  878. grid-template-columns: repeat(4, minmax(0, 1fr));
  879. gap: 6px;
  880. margin-top: 10px;
  881. padding-top: 10px;
  882. border-top: 1px solid #eef2f7;
  883. }
  884. .order-brief span {
  885. color: #64748b;
  886. font-size: 12px;
  887. }
  888. .order-brief b {
  889. margin-left: 3px;
  890. color: #17324d;
  891. font-size: 14px;
  892. }
  893. .device-summary {
  894. display: flex;
  895. flex-direction: column;
  896. gap: 12px;
  897. }
  898. .detail-panel :deep(.el-card__body) {
  899. display: flex;
  900. flex-direction: column;
  901. }
  902. .detail-panel .device-summary {
  903. flex: 1;
  904. }
  905. .summary-top {
  906. display: flex;
  907. align-items: flex-start;
  908. justify-content: space-between;
  909. gap: 10px;
  910. flex-wrap: wrap;
  911. }
  912. .summary-name {
  913. color: #17324d;
  914. font-size: 16px;
  915. font-weight: 700;
  916. }
  917. .summary-tags {
  918. display: flex;
  919. flex-wrap: wrap;
  920. justify-content: flex-end;
  921. gap: 6px;
  922. }
  923. .detail-panel :deep(.el-descriptions__label) {
  924. width: 86px;
  925. color: #64748b;
  926. background: #f8fafc;
  927. white-space: nowrap;
  928. }
  929. .quick-grid {
  930. display: grid;
  931. grid-template-columns: repeat(2, minmax(0, 1fr));
  932. gap: 10px;
  933. }
  934. .quick-entry {
  935. display: flex;
  936. align-items: center;
  937. gap: 10px;
  938. min-width: 0;
  939. padding: 14px 12px;
  940. color: #1e293b;
  941. background: #fff;
  942. border: 1px solid #e1ebf3;
  943. border-radius: 8px;
  944. cursor: pointer;
  945. transition: all 0.15s ease;
  946. }
  947. .quick-entry:hover {
  948. background: #f6fbff;
  949. border-color: #bfdbfe;
  950. }
  951. .quick-entry :deep(.el-icon) {
  952. flex: 0 0 20px;
  953. color: #2563eb;
  954. font-size: 20px;
  955. }
  956. .quick-entry span {
  957. overflow: hidden;
  958. font-size: 13px;
  959. font-weight: 600;
  960. text-overflow: ellipsis;
  961. white-space: nowrap;
  962. }
  963. .chart-grid {
  964. display: grid;
  965. grid-template-columns: 1.5fr 1fr 1fr;
  966. gap: 12px;
  967. }
  968. .chart-card {
  969. border: 1px solid #e1ebf3;
  970. border-radius: 8px;
  971. box-shadow: 0 5px 16px rgba(28, 75, 110, 0.05);
  972. }
  973. .chart-card .chart {
  974. height: 260px;
  975. }
  976. .chart-card :deep(.el-card__header) {
  977. padding: 12px 16px;
  978. border-bottom: 1px solid #e1ebf3;
  979. background: #fbfdff;
  980. }
  981. .chart-card :deep(.el-card__body) {
  982. padding: 10px 12px;
  983. }
  984. @media (max-width: 1200px) {
  985. .metric-grid {
  986. grid-template-columns: repeat(2, minmax(0, 1fr));
  987. }
  988. .workbench-grid {
  989. grid-template-columns: 1fr;
  990. }
  991. .chart-grid {
  992. grid-template-columns: 1fr 1fr;
  993. }
  994. .trend-card {
  995. grid-column: 1 / -1;
  996. }
  997. }
  998. @media (max-width: 768px) {
  999. .page-heading,
  1000. .heading-actions {
  1001. align-items: stretch;
  1002. flex-direction: column;
  1003. }
  1004. .metric-grid,
  1005. .chart-grid {
  1006. grid-template-columns: 1fr;
  1007. }
  1008. .trend-card {
  1009. grid-column: auto;
  1010. }
  1011. .map-legend {
  1012. display: none;
  1013. }
  1014. .panel-links {
  1015. display: none;
  1016. }
  1017. .quick-grid {
  1018. grid-template-columns: 1fr;
  1019. }
  1020. }
  1021. </style>