jsqc.vue 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  1. <template>
  2. <div class="jsqc-screen">
  3. <!-- ==================== 顶部标题栏 ==================== -->
  4. <div class="screen-header">
  5. <div class="header-left">
  6. <span class="header-time">{{ currentDateTime }}</span>
  7. </div>
  8. <div class="header-center">
  9. <h1 class="header-title">排水管网安全运行监测系统</h1>
  10. </div>
  11. <div class="header-right">
  12. </div>
  13. </div>
  14. <!-- ==================== 主体三栏布局 ==================== -->
  15. <div class="screen-body">
  16. <!-- ========== 左侧面板 ========== -->
  17. <div class="panel-left">
  18. <!-- 天气预报 -->
  19. <div class="panel-box">
  20. <div class="panel-title">
  21. <span class="title-icon">▶</span> 天气预报
  22. </div>
  23. <div class="weather-cards">
  24. <div class="weather-card" v-for="(w, i) in weatherList" :key="i">
  25. <div class="weather-date">{{ w.date }}</div>
  26. <div class="weather-icon">{{ getWeatherIcon(w.text) }}</div>
  27. <div class="weather-desc">{{ w.desc }}</div>
  28. <div class="weather-temp">{{ w.tempRange }}</div>
  29. <div class="weather-wind">{{ w.wind }}</div>
  30. </div>
  31. </div>
  32. </div>
  33. <!-- 监测点概况 -->
  34. <div class="panel-box">
  35. <div class="panel-title">
  36. <span class="title-icon">▶</span> 监测点概况
  37. </div>
  38. <div class="pie-chart-wrapper">
  39. <div id="jsqcPieChart" class="chart-area"></div>
  40. <div class="pie-legend">
  41. <div class="legend-item" v-for="(item, i) in pieData" :key="i">
  42. <span class="legend-dot" :style="{ background: item.color }"></span>
  43. <span class="legend-label">{{ item.name }}</span>
  44. <span class="legend-value">{{ item.value }}</span>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. <!-- 实时数据 -->
  50. <div class="panel-box">
  51. <div class="panel-title">
  52. <span class="title-icon">▶</span> 实时数据
  53. <span class="refresh-time">刷新: {{ refreshTime }}</span>
  54. </div>
  55. <div class="realtime-table-wrap">
  56. <table class="dark-table">
  57. <thead>
  58. <tr>
  59. <th>序号</th>
  60. <th>监测点</th>
  61. <th>时间</th>
  62. <th>积水量(cm)</th>
  63. <th>级别</th>
  64. </tr>
  65. </thead>
  66. <tbody>
  67. <tr v-for="(row, i) in realtimeData" :key="i">
  68. <td>{{ i + 1 }}</td>
  69. <td :title="row.name">{{ row.name }}</td>
  70. <td>{{ row.time }}</td>
  71. <td>{{ row.depth }}</td>
  72. <td>
  73. <span :class="'level-tag level-' + row.levelClass">{{ row.level }}</span>
  74. </td>
  75. </tr>
  76. </tbody>
  77. </table>
  78. </div>
  79. </div>
  80. </div>
  81. <!-- ========== 中间地图区域 ========== -->
  82. <div class="panel-center">
  83. <div id="jsqcMap" class="map-container"></div>
  84. </div>
  85. <!-- ========== 右侧面板 ========== -->
  86. <div class="panel-right">
  87. <!-- 积水统计 -->
  88. <div class="panel-box">
  89. <div class="panel-title">
  90. <span class="title-icon">▶</span> 积水统计
  91. </div>
  92. <div id="jsqcLineChart" class="chart-area-sm"></div>
  93. </div>
  94. </div>
  95. </div>
  96. <!-- 积水深度曲线弹窗 -->
  97. <div v-if="depthModalVisible" class="depth-modal" @click.self="closeDepthModal">
  98. <div class="depth-modal-content">
  99. <div class="depth-modal-header">
  100. <span class="depth-modal-title">{{ selectedPointName }} - 积水深度曲线</span>
  101. <span class="depth-modal-close" @click="closeDepthModal">×</span>
  102. </div>
  103. <div class="depth-modal-tabs">
  104. <div
  105. v-for="tab in depthTabs"
  106. :key="tab.value"
  107. class="depth-modal-tab"
  108. :class="{ active: currentDepthTab === tab.value }"
  109. @click="switchDepthTab(tab.value)"
  110. >{{ tab.label }}</div>
  111. </div>
  112. <div id="jsqcDepthChart" class="depth-chart-area"></div>
  113. </div>
  114. </div>
  115. </div>
  116. </template>
  117. <script setup name="Jsqc">
  118. import { ref, onMounted, onUnmounted, nextTick } from 'vue'
  119. import * as echarts from 'echarts'
  120. import { useRouter } from 'vue-router'
  121. import { ElMessage } from 'element-plus'
  122. import locationIcon from '@/assets/images/location.png'
  123. import { getWaterloggingPage } from '@/api/drainage'
  124. const router = useRouter()
  125. // ==================== 实时时间 ====================
  126. const currentDateTime = ref('')
  127. let timer = null
  128. function updateTime() {
  129. const now = new Date()
  130. const pad = n => String(n).padStart(2, '0')
  131. const weekDays = ['日', '一', '二', '三', '四', '五', '六']
  132. const dateStr = `${now.getFullYear()}/${pad(now.getMonth() + 1)}/${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())} 星期${weekDays[now.getDay()]}`
  133. currentDateTime.value = dateStr
  134. }
  135. // ==================== 刷新时间 ====================
  136. const refreshTime = ref('')
  137. function updateRefreshTime() {
  138. const now = new Date()
  139. const pad = n => String(n).padStart(2, '0')
  140. refreshTime.value = `${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`
  141. }
  142. // ==================== 天气数据 ====================
  143. const weatherList = ref([])
  144. // 百度地图 AK(与 index.html 中加载百度地图 SDK 使用同一个)
  145. const BAIDU_MAP_AK = 'mvSNSN4CPN6WJs2Xi6sQFNmWwCLRgU6T'
  146. // 天气文字 -> emoji 图标映射
  147. function getWeatherIcon(text) {
  148. if (!text) return '☀️'
  149. const t = String(text)
  150. if (t.includes('晴')) return '☀️'
  151. if (t.includes('多云')) return '⛅'
  152. if (t.includes('阴')) return '☁️'
  153. if (t.includes('雨') && t.includes('雪')) return '🌨️'
  154. if (t.includes('雪')) return '❄️'
  155. if (t.includes('雷')) return '⛈️'
  156. if (t.includes('雨')) return '🌧️'
  157. if (t.includes('雾') || t.includes('霾')) return '🌫️'
  158. return '☁️'
  159. }
  160. // 简易 JSONP 调用百度天气服务(服务端未开放 CORS,需用 JSONP)
  161. function jsonpRequest(url) {
  162. return new Promise((resolve, reject) => {
  163. const callbackName = 'jsqcWeatherCallback_' + Date.now()
  164. const script = document.createElement('script')
  165. script.src = url + (url.includes('?') ? '&' : '?') + 'callback=' + callbackName
  166. script.onerror = () => {
  167. document.head.removeChild(script)
  168. delete window[callbackName]
  169. reject(new Error('天气接口加载失败'))
  170. }
  171. window[callbackName] = (data) => {
  172. document.head.removeChild(script)
  173. delete window[callbackName]
  174. resolve(data)
  175. }
  176. document.head.appendChild(script)
  177. })
  178. }
  179. async function loadWeatherData() {
  180. try {
  181. const url = `/baidu-weather/weather/v1/?district_id=431222&data_type=all&ak=${BAIDU_MAP_AK}&output=json`
  182. const response = await fetch(url)
  183. const res = await response.json()
  184. if (res && (res.status === 0 || res.status === '0') && res.result && Array.isArray(res.result.forecasts)) {
  185. weatherList.value = res.result.forecasts.slice(0, 3).map(day => {
  186. const dateStr = day.date || ''
  187. const monthDay = dateStr.length >= 10 ? `${dateStr.slice(5, 7)}/${dateStr.slice(8, 10)}` : dateStr
  188. return {
  189. date: monthDay,
  190. text: day.text_day || day.text_night || '多云',
  191. desc: day.text_day || '多云',
  192. tempRange: `${day.low || '--'}°C ~ ${day.high || '--'}°C`,
  193. wind: `${day.wd_day || ''} ${day.wc_day || ''}`
  194. }
  195. })
  196. } else {
  197. console.warn('百度天气返回异常:', res)
  198. useMockWeather()
  199. }
  200. } catch (e) {
  201. console.error('加载天气数据失败:', e)
  202. useMockWeather()
  203. }
  204. }
  205. // 天气接口失败时使用模拟数据兜底
  206. function useMockWeather() {
  207. const now = new Date()
  208. const pad = n => String(n).padStart(2, '0')
  209. const formatDate = (offset) => {
  210. const d = new Date(now.getTime() + offset * 24 * 60 * 60 * 1000)
  211. return `${pad(d.getMonth() + 1)}/${pad(d.getDate())}`
  212. }
  213. weatherList.value = [
  214. { date: formatDate(0), text: '多云', desc: '多云', tempRange: '18°C ~ 26°C', wind: '东南风 2级' },
  215. { date: formatDate(1), text: '小雨', desc: '小雨', tempRange: '16°C ~ 23°C', wind: '东风 3级' },
  216. { date: formatDate(2), text: '阴', desc: '阴', tempRange: '15°C ~ 22°C', wind: '北风 2级' }
  217. ]
  218. }
  219. // ==================== 监测点概况 ====================
  220. const pieData = ref([
  221. { name: '未积水', value: 0, color: '#67c23a' },
  222. { name: '轻度积水', value: 0, color: '#409eff' },
  223. { name: '中度积水', value: 0, color: '#e6a23c' },
  224. { name: '严重积水', value: 0, color: '#f56c6c' }
  225. ])
  226. // ==================== 实时数据 ====================
  227. const realtimeData = ref([])
  228. // ==================== 地图监测点数据 ====================
  229. const mapPoints = ref([])
  230. // ==================== 积水等级映射 ====================
  231. // 后端 waterloggingLevel 约定:0=未积水,1=轻度,2=中度,3=严重
  232. function getWaterloggingLevelInfo(level) {
  233. const map = {
  234. 0: { label: '未积水', levelClass: 'none' },
  235. 1: { label: '轻度积水', levelClass: 'light' },
  236. 2: { label: '中度积水', levelClass: 'moderate' },
  237. 3: { label: '严重积水', levelClass: 'severe' }
  238. }
  239. return map[level] || map[Number(level)] || { label: '未积水', levelClass: 'none' }
  240. }
  241. // 安全解析 waterloggingPoints(后端返回 JSON 字符串,需转为数组使用)
  242. function parseWaterloggingPoints(raw) {
  243. if (!raw) return []
  244. if (Array.isArray(raw)) return raw
  245. if (typeof raw === 'string') {
  246. try {
  247. const parsed = JSON.parse(raw)
  248. return Array.isArray(parsed) ? parsed : []
  249. } catch (e) {
  250. console.warn('waterloggingPoints JSON 解析失败:', raw, e)
  251. return []
  252. }
  253. }
  254. return []
  255. }
  256. // ==================== API数据加载 ====================
  257. async function loadWaterloggingData() {
  258. try {
  259. const res = await getWaterloggingPage(1, 999)
  260. // 兼容直接返回 Page 对象(无 code 包装)和 AjaxResult 包装两种格式
  261. const pageData = res && res.code !== undefined ? res.data : res
  262. const list = Array.isArray(pageData.records) ? pageData.records : (Array.isArray(pageData) ? pageData : [])
  263. // 构建地图点位:展示每个易积水点的所有子点位
  264. const allMapPoints = []
  265. list.forEach(p => {
  266. const levelInfo = getWaterloggingLevelInfo(p.waterloggingLevel)
  267. const subPoints = parseWaterloggingPoints(p.waterloggingPoints)
  268. if (subPoints.length > 0) {
  269. subPoints.forEach(sp => {
  270. if (sp.lng && sp.lat) {
  271. allMapPoints.push({
  272. name: sp.name || p.pointName || '未命名',
  273. lng: Number(sp.lng),
  274. lat: Number(sp.lat),
  275. depth: sp.depth ?? p.waterVolume ?? 0,
  276. level: levelInfo.label,
  277. levelClass: levelInfo.levelClass,
  278. parentId: p.id,
  279. parentName: p.pointName
  280. })
  281. }
  282. })
  283. } else if (p.longitude && p.latitude) {
  284. // 兼容无子点位的旧数据:使用主点坐标
  285. allMapPoints.push({
  286. name: p.pointName || '未命名',
  287. lng: Number(p.longitude),
  288. lat: Number(p.latitude),
  289. depth: p.waterVolume ?? 0,
  290. level: levelInfo.label,
  291. levelClass: levelInfo.levelClass,
  292. parentId: p.id,
  293. parentName: p.pointName
  294. })
  295. }
  296. })
  297. mapPoints.value = allMapPoints
  298. // 构建实时数据表(按子点位展开)
  299. const pad = n => String(n).padStart(2, '0')
  300. const now = new Date()
  301. const timeStr = `${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`
  302. realtimeData.value = allMapPoints.map((p, idx) => ({
  303. name: p.name,
  304. time: timeStr,
  305. depth: p.depth,
  306. level: p.level,
  307. levelClass: p.levelClass
  308. })).slice(0, 50)
  309. // 更新 pieData 统计(按 waterloggingLevel 统计各等级数量)
  310. const levelCount = { 0: 0, 1: 0, 2: 0, 3: 0 }
  311. list.forEach(p => {
  312. const key = Number(p.waterloggingLevel ?? 0)
  313. if (levelCount[key] !== undefined) levelCount[key]++
  314. else levelCount[0]++
  315. })
  316. pieData.value = [
  317. { name: '未积水', value: levelCount[0], color: '#67c23a' },
  318. { name: '轻度积水', value: levelCount[1], color: '#409eff' },
  319. { name: '中度积水', value: levelCount[2], color: '#e6a23c' },
  320. { name: '严重积水', value: levelCount[3], color: '#f56c6c' }
  321. ]
  322. } catch (e) {
  323. console.error('加载易积水点数据失败:', e)
  324. ElMessage.error('加载易积水点数据失败')
  325. }
  326. }
  327. // ==================== 导航方法 ====================
  328. function goBack() {
  329. router.push('/')
  330. }
  331. function goAdmin() {
  332. router.push('/')
  333. }
  334. // ==================== 地图初始化 ====================
  335. let mapInstance = null
  336. function initMap() {
  337. const container = document.getElementById('jsqcMap')
  338. if (!container || typeof BMapGL === 'undefined') {
  339. console.warn('BMapGL 未加载或容器不存在')
  340. return
  341. }
  342. try {
  343. mapInstance = new BMapGL.Map('jsqcMap')
  344. mapInstance.enableScrollWheelZoom(true)
  345. // 添加标记点
  346. mapPoints.value.forEach(point => {
  347. addMapMarker(point)
  348. })
  349. // 根据所有点位自适应视野
  350. if (mapPoints.value.length > 0) {
  351. const viewPoints = mapPoints.value.map(p => new BMapGL.Point(p.lng, p.lat))
  352. mapInstance.setViewport(viewPoints)
  353. // 确保缩放级别不低于14,避免地图显示太小
  354. if (mapInstance.getZoom() < 14) {
  355. mapInstance.setZoom(14)
  356. }
  357. } else {
  358. mapInstance.centerAndZoom(new BMapGL.Point(110.393, 28.452), 14)
  359. }
  360. } catch (e) {
  361. console.error('百度地图初始化失败:', e)
  362. }
  363. }
  364. function addMapMarker(point) {
  365. const levelColor = {
  366. '未积水': '#67c23a',
  367. '轻度积水': '#409eff',
  368. '中度积水': '#e6a23c',
  369. '严重积水': '#f56c6c'
  370. }
  371. const color = levelColor[point.level] || '#409eff'
  372. const bPoint = new BMapGL.Point(point.lng, point.lat)
  373. const html = `<div style="text-align:center;cursor:pointer;">
  374. <div style="color:#fff;background:${color};border-radius:4px;padding:2px 6px;font-size:11px;white-space:nowrap;display:inline-block;margin-bottom:2px;">${point.name}</div>
  375. <div style="color:#fff;font-size:10px;background:rgba(0,0,0,0.6);border-radius:3px;padding:1px 4px;margin-bottom:2px;">水位:${point.depth}cm ${point.level}</div>
  376. <div><img src="${locationIcon}" style="width:24px;height:24px;display:block;margin:0 auto;"/></div>
  377. </div>`
  378. const label = new BMapGL.Label(html, {
  379. position: bPoint,
  380. offset: new BMapGL.Size(-30, -55)
  381. })
  382. label.setStyle({
  383. border: 'none',
  384. background: 'transparent',
  385. padding: '0'
  386. })
  387. mapInstance.addOverlay(label)
  388. // 点击标记打开积水深度曲线弹窗
  389. label.addEventListener('click', function () {
  390. openDepthModal(point)
  391. })
  392. }
  393. // ==================== ECharts 图表 ====================
  394. let pieChart = null
  395. let lineChart = null
  396. function initPieChart() {
  397. const dom = document.getElementById('jsqcPieChart')
  398. if (!dom) return
  399. pieChart = echarts.init(dom)
  400. const total = pieData.value.reduce((s, d) => s + d.value, 0)
  401. pieChart.setOption({
  402. tooltip: { trigger: 'item', formatter: '{b}: {c} ({d}%)' },
  403. legend: { show: false },
  404. graphic: [{
  405. type: 'text',
  406. left: 'center',
  407. top: '38%',
  408. style: { text: '积水点个数', fill: '#a0cfff', fontSize: 12, textAlign: 'center' }
  409. }, {
  410. type: 'text',
  411. left: 'center',
  412. top: '52%',
  413. style: { text: String(total), fill: '#fff', fontSize: 22, fontWeight: 'bold', textAlign: 'center' }
  414. }],
  415. series: [{
  416. type: 'pie',
  417. radius: ['45%', '70%'],
  418. center: ['50%', '50%'],
  419. label: { show: false },
  420. labelLine: { show: false },
  421. data: pieData.value.map(d => ({ name: d.name, value: d.value, itemStyle: { color: d.color } })),
  422. emphasis: { scale: true, scaleSize: 5 }
  423. }]
  424. })
  425. }
  426. async function initLineChart() {
  427. // 统计最近6个月积水事件数
  428. const dom = document.getElementById('jsqcLineChart')
  429. if (!dom) return
  430. lineChart = echarts.init(dom)
  431. try {
  432. const res = await getWaterloggingPage(1, 9999)
  433. const pageData = res && res.code !== undefined ? res.data : res
  434. const list = Array.isArray(pageData.records) ? pageData.records : (Array.isArray(pageData) ? pageData : [])
  435. const now = new Date()
  436. const xData = []
  437. const yData = []
  438. for (let i = 5; i >= 0; i--) {
  439. const d = new Date(now.getFullYear(), now.getMonth() - i, 1)
  440. const month = d.getMonth() + 1
  441. const year = d.getFullYear()
  442. xData.push(`${month}月`)
  443. const count = list.filter(item => {
  444. const t = item.time || item.dataTime || item.updateTime || item.createTime || ''
  445. if (!t) return false
  446. const itemDate = new Date(t)
  447. return itemDate.getFullYear() === year && itemDate.getMonth() + 1 === month
  448. }).length
  449. yData.push(count)
  450. }
  451. lineChart.setOption({
  452. tooltip: { trigger: 'axis' },
  453. grid: { left: 40, right: 10, top: 10, bottom: 25 },
  454. xAxis: {
  455. type: 'category',
  456. data: xData,
  457. axisLabel: { color: '#7ec8e3', fontSize: 10 },
  458. axisLine: { lineStyle: { color: '#1a3a5c' } }
  459. },
  460. yAxis: {
  461. type: 'value',
  462. name: '次',
  463. nameTextStyle: { color: '#7ec8e3', fontSize: 10 },
  464. axisLabel: { color: '#7ec8e3', fontSize: 10 },
  465. splitLine: { lineStyle: { color: '#1a3a5c' } },
  466. axisLine: { show: false }
  467. },
  468. series: [{
  469. type: 'bar',
  470. data: yData,
  471. barWidth: 12,
  472. itemStyle: {
  473. color: '#00e5ff',
  474. borderRadius: [2, 2, 0, 0]
  475. }
  476. }]
  477. })
  478. } catch (e) {
  479. console.error('积水统计加载失败:', e)
  480. }
  481. }
  482. // ==================== 积水深度曲线弹窗 ====================
  483. const depthModalVisible = ref(false)
  484. const selectedPointName = ref('')
  485. const currentDepthTab = ref('24h')
  486. const depthTabs = [
  487. { label: '24小时', value: '24h' },
  488. { label: '7天', value: '7d' },
  489. { label: '15天', value: '15d' },
  490. { label: '30天', value: '30d' }
  491. ]
  492. let depthChart = null
  493. function openDepthModal(point) {
  494. selectedPointName.value = point.name
  495. currentDepthTab.value = '24h'
  496. depthModalVisible.value = true
  497. nextTick(() => {
  498. initDepthChart()
  499. })
  500. }
  501. function closeDepthModal() {
  502. depthModalVisible.value = false
  503. if (depthChart) {
  504. depthChart.dispose()
  505. depthChart = null
  506. }
  507. }
  508. function switchDepthTab(tab) {
  509. currentDepthTab.value = tab
  510. initDepthChart()
  511. }
  512. function generateDepthData(tab) {
  513. let labels = []
  514. let values = []
  515. const now = new Date()
  516. const pad = n => String(n).padStart(2, '0')
  517. if (tab === '24h') {
  518. for (let i = 0; i < 24; i++) {
  519. labels.push(`${pad(i)}:00`)
  520. const base = i < 8 || i > 20 ? Math.random() * 3 : Math.random() * 15 + 5
  521. values.push(Math.round(base * 10) / 10)
  522. }
  523. } else {
  524. const count = tab === '7d' ? 7 : tab === '15d' ? 15 : 30
  525. for (let i = count - 1; i >= 0; i--) {
  526. const d = new Date(now.getTime() - i * 24 * 60 * 60 * 1000)
  527. labels.push(`${pad(d.getMonth() + 1)}-${pad(d.getDate())}`)
  528. values.push(Math.round((Math.random() * 20 + Math.random() * 5) * 10) / 10)
  529. }
  530. }
  531. return { labels, values }
  532. }
  533. function initDepthChart() {
  534. const dom = document.getElementById('jsqcDepthChart')
  535. if (!dom) return
  536. if (depthChart) depthChart.dispose()
  537. depthChart = echarts.init(dom)
  538. const { labels, values } = generateDepthData(currentDepthTab.value)
  539. depthChart.setOption({
  540. tooltip: { trigger: 'axis' },
  541. grid: { left: 50, right: 20, top: 20, bottom: 30 },
  542. xAxis: {
  543. type: 'category',
  544. data: labels,
  545. axisLabel: { color: '#7ec8e3', fontSize: 10 },
  546. axisLine: { lineStyle: { color: '#1a3a5c' } }
  547. },
  548. yAxis: {
  549. type: 'value',
  550. name: 'cm',
  551. nameTextStyle: { color: '#7ec8e3', fontSize: 11 },
  552. axisLabel: { color: '#7ec8e3', fontSize: 10 },
  553. splitLine: { lineStyle: { color: '#1a3a5c' } },
  554. axisLine: { show: false }
  555. },
  556. series: [{
  557. type: 'line',
  558. data: values,
  559. smooth: true,
  560. symbol: 'circle',
  561. symbolSize: 6,
  562. lineStyle: { color: '#409eff', width: 2 },
  563. itemStyle: { color: '#409eff' },
  564. areaStyle: {
  565. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  566. { offset: 0, color: 'rgba(64, 158, 255, 0.4)' },
  567. { offset: 1, color: 'rgba(64, 158, 255, 0.05)' }
  568. ])
  569. }
  570. }]
  571. })
  572. }
  573. // ==================== 生命周期 ====================
  574. onMounted(async () => {
  575. updateTime()
  576. timer = setInterval(() => {
  577. updateTime()
  578. updateRefreshTime()
  579. }, 1000)
  580. updateRefreshTime()
  581. // 先加载后端数据,再初始化地图和图表
  582. await Promise.all([
  583. loadWaterloggingData(),
  584. loadWeatherData()
  585. ])
  586. // 延迟初始化确保 DOM 渲染完成
  587. setTimeout(() => {
  588. initMap()
  589. initPieChart()
  590. initLineChart()
  591. }, 300)
  592. })
  593. onUnmounted(() => {
  594. if (timer) clearInterval(timer)
  595. if (pieChart) pieChart.dispose()
  596. if (lineChart) lineChart.dispose()
  597. if (depthChart) depthChart.dispose()
  598. if (mapInstance) mapInstance = null
  599. })
  600. // 监听窗口大小变化,重绘图表
  601. window.addEventListener('resize', () => {
  602. if (pieChart) pieChart.resize()
  603. if (lineChart) lineChart.resize()
  604. if (depthChart) depthChart.resize()
  605. })
  606. </script>
  607. <style scoped>
  608. /* ==================== 全局暗色大屏 ==================== */
  609. .jsqc-screen {
  610. width: 100%;
  611. height: 100vh;
  612. background: #0a1929;
  613. color: #fff;
  614. font-family: 'Microsoft YaHei', sans-serif;
  615. overflow: hidden;
  616. display: flex;
  617. flex-direction: column;
  618. }
  619. /* ==================== 顶部标题栏 ==================== */
  620. .screen-header {
  621. height: 64px;
  622. background: linear-gradient(180deg, #0d2137 0%, #0a1929 100%);
  623. border-bottom: 1px solid rgba(64, 158, 255, 0.3);
  624. display: flex;
  625. align-items: center;
  626. justify-content: space-between;
  627. padding: 0 24px;
  628. flex-shrink: 0;
  629. position: relative;
  630. }
  631. .screen-header::after {
  632. content: '';
  633. position: absolute;
  634. bottom: 0;
  635. left: 10%;
  636. right: 10%;
  637. height: 1px;
  638. background: linear-gradient(90deg, transparent, #409eff, transparent);
  639. }
  640. .header-left {
  641. flex: 1;
  642. text-align: left;
  643. }
  644. .header-time {
  645. font-size: 15px;
  646. color: #a0cfff;
  647. letter-spacing: 1px;
  648. }
  649. .header-center {
  650. flex: 2;
  651. text-align: center;
  652. }
  653. .header-title {
  654. font-size: 26px;
  655. font-weight: 700;
  656. margin: 0;
  657. letter-spacing: 4px;
  658. background: linear-gradient(180deg, #fff 0%, #7ec8e3 100%);
  659. -webkit-background-clip: text;
  660. -webkit-text-fill-color: transparent;
  661. text-shadow: none;
  662. }
  663. .header-right {
  664. flex: 1;
  665. text-align: right;
  666. display: flex;
  667. justify-content: flex-end;
  668. gap: 10px;
  669. }
  670. .header-btn {
  671. background: rgba(64, 158, 255, 0.15);
  672. border: 1px solid rgba(64, 158, 255, 0.4);
  673. color: #a0cfff;
  674. padding: 6px 16px;
  675. border-radius: 4px;
  676. font-size: 13px;
  677. cursor: pointer;
  678. transition: all 0.3s;
  679. }
  680. .header-btn:hover {
  681. background: rgba(64, 158, 255, 0.3);
  682. border-color: #409eff;
  683. color: #fff;
  684. }
  685. /* ==================== 主体三栏 ==================== */
  686. .screen-body {
  687. flex: 1;
  688. display: flex;
  689. padding: 12px;
  690. gap: 12px;
  691. min-height: 0;
  692. }
  693. .panel-left,
  694. .panel-right {
  695. width: 22%;
  696. min-width: 260px;
  697. display: flex;
  698. flex-direction: column;
  699. gap: 12px;
  700. min-height: 0;
  701. }
  702. .panel-center {
  703. flex: 1;
  704. display: flex;
  705. flex-direction: column;
  706. min-height: 0;
  707. position: relative;
  708. }
  709. /* ==================== 面板盒子 ==================== */
  710. .panel-box {
  711. background: rgba(6, 30, 65, 0.8);
  712. border: 1px solid rgba(64, 158, 255, 0.2);
  713. border-radius: 6px;
  714. padding: 12px;
  715. display: flex;
  716. flex-direction: column;
  717. flex: 1;
  718. min-height: 0;
  719. overflow: hidden;
  720. }
  721. .panel-title {
  722. font-size: 14px;
  723. font-weight: 600;
  724. color: #7ec8e3;
  725. margin-bottom: 10px;
  726. display: flex;
  727. align-items: center;
  728. gap: 4px;
  729. flex-shrink: 0;
  730. }
  731. .title-icon {
  732. color: #409eff;
  733. font-size: 10px;
  734. }
  735. .refresh-time {
  736. margin-left: auto;
  737. font-size: 11px;
  738. color: #607080;
  739. font-weight: 400;
  740. }
  741. /* ==================== 天气预报 ==================== */
  742. .weather-cards {
  743. display: flex;
  744. gap: 8px;
  745. flex-shrink: 0;
  746. }
  747. .weather-card {
  748. flex: 1;
  749. background: rgba(20, 60, 110, 0.5);
  750. border: 1px solid rgba(64, 158, 255, 0.15);
  751. border-radius: 6px;
  752. padding: 10px 8px;
  753. text-align: center;
  754. }
  755. .weather-date {
  756. font-size: 12px;
  757. color: #a0cfff;
  758. margin-bottom: 4px;
  759. }
  760. .weather-icon {
  761. font-size: 24px;
  762. margin: 4px 0;
  763. }
  764. .weather-desc {
  765. font-size: 12px;
  766. color: #d0e8ff;
  767. margin-bottom: 2px;
  768. }
  769. .weather-temp {
  770. font-size: 11px;
  771. color: #7ec8e3;
  772. }
  773. .weather-wind {
  774. font-size: 10px;
  775. color: #607080;
  776. margin-top: 2px;
  777. }
  778. /* ==================== 监测点概况 ==================== */
  779. .pie-chart-wrapper {
  780. flex: 1;
  781. display: flex;
  782. align-items: center;
  783. min-height: 0;
  784. }
  785. .chart-area {
  786. width: 55%;
  787. height: 100%;
  788. min-height: 120px;
  789. }
  790. .pie-legend {
  791. width: 45%;
  792. display: flex;
  793. flex-direction: column;
  794. gap: 8px;
  795. }
  796. .legend-item {
  797. display: flex;
  798. align-items: center;
  799. gap: 6px;
  800. font-size: 12px;
  801. }
  802. .legend-dot {
  803. width: 10px;
  804. height: 10px;
  805. border-radius: 2px;
  806. flex-shrink: 0;
  807. }
  808. .legend-label {
  809. color: #a0cfff;
  810. flex: 1;
  811. }
  812. .legend-value {
  813. color: #fff;
  814. font-weight: 600;
  815. }
  816. /* ==================== 实时数据表格 ==================== */
  817. .realtime-table-wrap {
  818. flex: 1;
  819. overflow-y: auto;
  820. min-height: 0;
  821. }
  822. .dark-table {
  823. width: 100%;
  824. border-collapse: collapse;
  825. font-size: 12px;
  826. }
  827. .dark-table th {
  828. background: rgba(20, 60, 110, 0.6);
  829. color: #7ec8e3;
  830. padding: 7px 6px;
  831. text-align: center;
  832. border-bottom: 1px solid rgba(64, 158, 255, 0.2);
  833. font-weight: 500;
  834. white-space: nowrap;
  835. }
  836. .dark-table td {
  837. padding: 6px;
  838. text-align: center;
  839. color: #d0e8ff;
  840. border-bottom: 1px solid rgba(64, 158, 255, 0.08);
  841. white-space: nowrap;
  842. overflow: hidden;
  843. text-overflow: ellipsis;
  844. max-width: 80px;
  845. }
  846. .dark-table tbody tr:nth-child(odd) {
  847. background: rgba(10, 25, 50, 0.4);
  848. }
  849. .dark-table tbody tr:nth-child(even) {
  850. background: rgba(20, 40, 70, 0.3);
  851. }
  852. .dark-table tbody tr:hover {
  853. background: rgba(64, 158, 255, 0.1);
  854. }
  855. .level-tag {
  856. padding: 1px 6px;
  857. border-radius: 3px;
  858. font-size: 11px;
  859. }
  860. .level-none {
  861. color: #67c23a;
  862. background: rgba(103, 194, 58, 0.15);
  863. }
  864. .level-light {
  865. color: #409eff;
  866. background: rgba(64, 158, 255, 0.15);
  867. }
  868. .level-moderate {
  869. color: #e6a23c;
  870. background: rgba(230, 162, 60, 0.15);
  871. }
  872. .level-severe {
  873. color: #f56c6c;
  874. background: rgba(245, 108, 108, 0.15);
  875. }
  876. /* ==================== 中间地图 ==================== */
  877. .map-container {
  878. flex: 1;
  879. border-radius: 6px;
  880. overflow: hidden;
  881. border: 1px solid rgba(64, 158, 255, 0.2);
  882. min-height: 0;
  883. }
  884. .map-tabs {
  885. display: flex;
  886. gap: 0;
  887. background: rgba(6, 30, 65, 0.9);
  888. border: 1px solid rgba(64, 158, 255, 0.2);
  889. border-radius: 6px;
  890. margin-top: 8px;
  891. flex-shrink: 0;
  892. overflow: hidden;
  893. }
  894. .map-tab {
  895. flex: 1;
  896. text-align: center;
  897. padding: 8px 4px;
  898. font-size: 12px;
  899. color: #a0cfff;
  900. cursor: pointer;
  901. transition: all 0.3s;
  902. border-right: 1px solid rgba(64, 158, 255, 0.1);
  903. }
  904. .map-tab:last-child {
  905. border-right: none;
  906. }
  907. .map-tab.active {
  908. background: rgba(64, 158, 255, 0.25);
  909. color: #fff;
  910. font-weight: 600;
  911. }
  912. .map-tab:hover {
  913. background: rgba(64, 158, 255, 0.15);
  914. }
  915. .chart-area-sm {
  916. width: 100%;
  917. flex: 1;
  918. min-height: 130px;
  919. }
  920. /* ==================== 滚动条样式 ==================== */
  921. ::-webkit-scrollbar {
  922. width: 4px;
  923. }
  924. ::-webkit-scrollbar-track {
  925. background: rgba(10, 25, 50, 0.3);
  926. }
  927. ::-webkit-scrollbar-thumb {
  928. background: rgba(64, 158, 255, 0.3);
  929. border-radius: 2px;
  930. }
  931. ::-webkit-scrollbar-thumb:hover {
  932. background: rgba(64, 158, 255, 0.5);
  933. }
  934. /* ==================== 积水深度曲线弹窗 ==================== */
  935. .depth-modal {
  936. position: fixed;
  937. top: 0;
  938. left: 0;
  939. right: 0;
  940. bottom: 0;
  941. background: rgba(0, 0, 0, 0.7);
  942. display: flex;
  943. align-items: center;
  944. justify-content: center;
  945. z-index: 1000;
  946. }
  947. .depth-modal-content {
  948. width: 720px;
  949. max-width: 90vw;
  950. background: rgba(6, 30, 65, 0.95);
  951. border: 1px solid rgba(64, 158, 255, 0.4);
  952. border-radius: 8px;
  953. padding: 16px;
  954. box-shadow: 0 0 20px rgba(64, 158, 255, 0.2);
  955. }
  956. .depth-modal-header {
  957. display: flex;
  958. align-items: center;
  959. justify-content: space-between;
  960. margin-bottom: 12px;
  961. }
  962. .depth-modal-title {
  963. font-size: 15px;
  964. font-weight: 600;
  965. color: #7ec8e3;
  966. }
  967. .depth-modal-close {
  968. font-size: 22px;
  969. color: #a0cfff;
  970. cursor: pointer;
  971. line-height: 1;
  972. }
  973. .depth-modal-close:hover {
  974. color: #fff;
  975. }
  976. .depth-modal-tabs {
  977. display: flex;
  978. gap: 8px;
  979. margin-bottom: 12px;
  980. }
  981. .depth-modal-tab {
  982. flex: 1;
  983. text-align: center;
  984. padding: 6px 4px;
  985. font-size: 12px;
  986. color: #a0cfff;
  987. background: rgba(10, 25, 50, 0.6);
  988. border: 1px solid rgba(64, 158, 255, 0.2);
  989. border-radius: 4px;
  990. cursor: pointer;
  991. transition: all 0.3s;
  992. }
  993. .depth-modal-tab.active {
  994. background: rgba(64, 158, 255, 0.3);
  995. color: #fff;
  996. border-color: rgba(64, 158, 255, 0.6);
  997. }
  998. .depth-modal-tab:hover {
  999. background: rgba(64, 158, 255, 0.2);
  1000. }
  1001. .depth-chart-area {
  1002. width: 100%;
  1003. height: 320px;
  1004. }
  1005. </style>