lsyjgl.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <div class="app-container lsyjgl-page">
  3. <!-- ==================== 搜索区域 ==================== -->
  4. <div class="search-panel">
  5. <div class="search-form">
  6. <div class="form-item">
  7. <span class="form-label">预警名称:</span>
  8. <el-input v-model="filters.equipmentName" placeholder="请输入" clearable style="width:200px" />
  9. </div>
  10. <div class="form-item">
  11. <span class="form-label">预警级别:</span>
  12. <el-select v-model="filters.warningLevel" placeholder="请选择" clearable style="width:160px">
  13. <el-option label="严重" :value="1" />
  14. <el-option label="重要" :value="2" />
  15. <el-option label="一般" :value="3" />
  16. </el-select>
  17. </div>
  18. <div class="form-item">
  19. <span class="form-label">处理状态:</span>
  20. <el-select v-model="filters.status" placeholder="请选择" clearable style="width:160px">
  21. <el-option label="已处置" value="HANDLED" />
  22. <el-option label="已解除" value="CLOSED" />
  23. </el-select>
  24. </div>
  25. <el-button type="primary" @click="handleSearch">搜索</el-button>
  26. <el-button @click="handleClear">清除</el-button>
  27. </div>
  28. </div>
  29. <!-- ==================== 数据表格 ==================== -->
  30. <div class="table-panel">
  31. <el-table :data="tableData" border style="width:100%" v-loading="loading">
  32. <el-table-column prop="warningNo" label="预警编号" min-width="140" />
  33. <el-table-column prop="equipmentName" label="预警名称" min-width="140" show-overflow-tooltip />
  34. <el-table-column prop="warningLevel" label="预警级别" width="90" align="center">
  35. <template #default="{ row }">
  36. <el-tag :type="levelTagType(row.warningLevel)" size="small">{{ levelText(row.warningLevel) }}</el-tag>
  37. </template>
  38. </el-table-column>
  39. <el-table-column prop="deviceCode" label="预警类型" width="110" align="center">
  40. <template #default="{ row }">
  41. {{ equipmentTypeMap.get(String(row.deviceCode)) || row.deviceCode || row.warningType || '-' }}
  42. </template>
  43. </el-table-column>
  44. <el-table-column prop="warningSpecial" label="预警专项" width="110" align="center" show-overflow-tooltip />
  45. <el-table-column prop="location" label="位置" min-width="180" show-overflow-tooltip />
  46. <el-table-column prop="createTime" label="预警时间" width="160" />
  47. <el-table-column prop="status" label="处理状态" width="90" align="center">
  48. <template #default="{ row }">
  49. <el-tag :type="statusTagType(row.status)" size="small">{{ statusText(row.status) }}</el-tag>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="操作" width="140" fixed="right">
  53. <template #default="{ row }">
  54. <el-button link type="primary" @click="handleView(row)">查看</el-button>
  55. <el-button link type="danger" @click="handleDelete(row)">删除</el-button>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <el-pagination
  60. v-model:current-page="pageNum"
  61. v-model:page-size="pageSize"
  62. :page-sizes="[10, 20, 50, 100]"
  63. :total="total"
  64. layout="total, sizes, prev, pager, next, jumper"
  65. style="margin-top: 16px; justify-content: flex-end"
  66. @size-change="loadData"
  67. @current-change="loadData"
  68. />
  69. </div>
  70. <!-- ==================== 查看详情弹窗 ==================== -->
  71. <el-drawer
  72. v-model="dialogVisible"
  73. title="历史预警详情"
  74. size="680px"
  75. :close-on-click-modal="false"
  76. class="detail-drawer" direction="rtl">
  77. <div class="detail-body" v-if="currentDetail">
  78. <!-- 右侧信息 -->
  79. <div class="detail-info">
  80. <div class="info-code">预警编号:{{ currentDetail.warningNo }}</div>
  81. <div class="info-grid">
  82. <div class="info-row">
  83. <div class="info-item">
  84. <span class="info-label">预警名称:</span>
  85. <span class="info-value">{{ currentDetail.equipmentName }}</span>
  86. </div>
  87. <div class="info-item">
  88. <span class="info-label">预警级别:</span>
  89. <span class="info-value">
  90. <el-tag :type="levelTagType(currentDetail.warningLevel)" size="small">{{ levelText(currentDetail.warningLevel) }}</el-tag>
  91. </span>
  92. </div>
  93. </div>
  94. <div class="info-row">
  95. <div class="info-item">
  96. <span class="info-label">预警类型:</span>
  97. <span class="info-value">{{ equipmentTypeMap.get(String(currentDetail.deviceCode)) || currentDetail.deviceCode || currentDetail.warningType || '-' }}</span>
  98. </div>
  99. <div class="info-item">
  100. <span class="info-label">预警专项:</span>
  101. <span class="info-value">{{ currentDetail.warningSpecial || '-' }}</span>
  102. </div>
  103. </div>
  104. <div class="info-row">
  105. <div class="info-item">
  106. <span class="info-label">预警时间:</span>
  107. <span class="info-value">{{ currentDetail.createTime }}</span>
  108. </div>
  109. <div class="info-item">
  110. <span class="info-label">发布人:</span>
  111. <span class="info-value">{{ currentDetail.publisher || '-' }}</span>
  112. </div>
  113. </div>
  114. <div class="info-row">
  115. <div class="info-item">
  116. <span class="info-label">处理状态:</span>
  117. <span class="info-value">
  118. <el-tag :type="statusTagType(currentDetail.status)" size="small">{{ statusText(currentDetail.status) }}</el-tag>
  119. </span>
  120. </div>
  121. <div class="info-item">
  122. <span class="info-label">发布时间:</span>
  123. <span class="info-value">{{ currentDetail.publishTime || '-' }}</span>
  124. </div>
  125. </div>
  126. <div class="info-row single">
  127. <div class="info-item">
  128. <span class="info-label">位置:</span>
  129. <span class="info-value desc-text">{{ currentDetail.location }}</span>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. <template #footer>
  136. <el-button @click="dialogVisible = false">关闭</el-button>
  137. </template>
  138. </el-drawer>
  139. </div>
  140. </template>
  141. <script setup name="Lsyjgl">
  142. import { ref, reactive, onMounted } from 'vue'
  143. import { ElMessage, ElMessageBox } from 'element-plus'
  144. import { getWarningHistoryPage, deleteWarning, getEquipmentTypeList } from '@/api/drainage'
  145. // ==================== 设备类型映射 ====================
  146. const equipmentTypeMap = ref(new Map())
  147. async function loadEquipmentTypes() {
  148. try {
  149. const res = await getEquipmentTypeList('2')
  150. const list = res.code !== undefined ? res.data : res
  151. const map = new Map()
  152. if (Array.isArray(list)) {
  153. list.forEach(item => {
  154. if (item.id !== undefined && item.id !== null) map.set(String(item.id), item.typeName)
  155. })
  156. }
  157. equipmentTypeMap.value = map
  158. } catch (error) {
  159. console.error('加载设备类型列表失败', error)
  160. }
  161. }
  162. // ==================== 等级/状态工具方法 ====================
  163. function levelText(level) {
  164. const map = { 1: '严重', 2: '重要', 3: '一般' }
  165. return map[level] || '-'
  166. }
  167. function levelTagType(level) {
  168. const map = { 1: 'danger', 2: 'warning', 3: '' }
  169. return map[level] || 'info'
  170. }
  171. function statusText(status) {
  172. const map = { DRAFT: '草稿', PENDING: '待办', PROCESSING: '处置中', RELEASED: '已发布', HANDLED: '已处置', CLOSED: '已解除' }
  173. return map[status] ?? '-'
  174. }
  175. function statusTagType(status) {
  176. const map = { DRAFT: 'info', PENDING: 'warning', PROCESSING: 'warning', RELEASED: 'success', HANDLED: 'success', CLOSED: '' }
  177. return map[status] || 'info'
  178. }
  179. // ==================== 表格数据 ====================
  180. const tableData = ref([])
  181. const total = ref(0)
  182. const loading = ref(false)
  183. const pageNum = ref(1)
  184. const pageSize = ref(10)
  185. // ==================== 搜索筛选 ====================
  186. const filters = reactive({
  187. equipmentName: '',
  188. warningLevel: '',
  189. status: ''
  190. })
  191. // ==================== 数据加载 ====================
  192. async function loadData() {
  193. loading.value = true
  194. try {
  195. // 历史页由后端按历史状态(HANDLED/CLOSED)限定;不再写死
  196. // 旧的数字类型和 HANDLED 状态,避免过滤掉实际历史记录。
  197. const params = {
  198. historyOnly: true,
  199. equipmentType: 'drainage'
  200. }
  201. if (filters.equipmentName) params.equipmentName = filters.equipmentName
  202. if (filters.warningLevel) params.warningLevel = filters.warningLevel
  203. if (filters.status !== '' && filters.status !== null) params.status = filters.status
  204. const res = await getWarningHistoryPage(pageNum.value, pageSize.value, params)
  205. const pageData = res.code !== undefined ? res.data : res
  206. tableData.value = pageData.records || []
  207. total.value = pageData.total || 0
  208. } catch (error) {
  209. console.error('加载历史预警列表失败', error)
  210. ElMessage.error('加载历史预警列表失败')
  211. } finally {
  212. loading.value = false
  213. }
  214. }
  215. function handleSearch() {
  216. pageNum.value = 1
  217. loadData()
  218. }
  219. function handleClear() {
  220. filters.equipmentName = ''
  221. filters.warningLevel = ''
  222. filters.status = ''
  223. pageNum.value = 1
  224. loadData()
  225. }
  226. // ==================== 操作:删除 ====================
  227. async function handleDelete(row) {
  228. try {
  229. await ElMessageBox.confirm('确认删除该预警?删除后不可恢复。', '提示', { type: 'warning' })
  230. await deleteWarning(row.id)
  231. ElMessage.success('删除成功')
  232. loadData()
  233. } catch (error) {
  234. if (error !== 'cancel') console.error('删除预警失败', error)
  235. }
  236. }
  237. // ==================== 查看详情弹窗 ====================
  238. const dialogVisible = ref(false)
  239. const currentDetail = ref(null)
  240. function handleView(row) {
  241. currentDetail.value = { ...row }
  242. dialogVisible.value = true
  243. }
  244. onMounted(async () => {
  245. await loadEquipmentTypes()
  246. loadData()
  247. })
  248. </script>
  249. <style scoped>
  250. .lsyjgl-page {
  251. background: #fff;
  252. min-height: 100%;
  253. padding: 16px;
  254. }
  255. /* 搜索区 */
  256. .search-panel {
  257. background: #fff;
  258. border: 1px solid #e4e7ed;
  259. border-radius: 4px;
  260. padding: 16px 20px;
  261. margin-bottom: 16px;
  262. }
  263. .search-form {
  264. display: flex;
  265. align-items: center;
  266. flex-wrap: wrap;
  267. gap: 12px;
  268. }
  269. .form-item {
  270. display: flex;
  271. align-items: center;
  272. }
  273. .form-label {
  274. font-size: 14px;
  275. color: #606266;
  276. white-space: nowrap;
  277. margin-right: 4px;
  278. }
  279. /* 表格区 */
  280. .table-panel {
  281. background: #fff;
  282. border-radius: 4px;
  283. }
  284. /* 所属类型标签 */
  285. .type-tag {
  286. font-weight: 500;
  287. font-size: 13px;
  288. }
  289. .type-pipe {
  290. color: #409eff;
  291. }
  292. .type-point {
  293. color: #67c23a;
  294. }
  295. .type-well {
  296. color: #e6a23c;
  297. }
  298. /* 详情弹窗 */
  299. .detail-body {
  300. display: flex;
  301. gap: 24px;
  302. padding: 8px 4px;
  303. }
  304. /* 左侧图片占位 */
  305. .detail-img {
  306. flex-shrink: 0;
  307. width: 150px;
  308. height: 150px;
  309. background: #d9ecff;
  310. border: 2px solid #b3d8ff;
  311. border-radius: 4px;
  312. display: flex;
  313. align-items: center;
  314. justify-content: center;
  315. }
  316. .img-placeholder-icon {
  317. font-size: 64px;
  318. color: #409eff;
  319. opacity: 0.7;
  320. }
  321. /* 右侧详情信息 */
  322. .detail-info {
  323. flex: 1;
  324. display: flex;
  325. flex-direction: column;
  326. gap: 10px;
  327. }
  328. .info-code {
  329. font-size: 15px;
  330. font-weight: 600;
  331. color: #303133;
  332. padding-bottom: 6px;
  333. border-bottom: 1px solid #f0f0f0;
  334. }
  335. .info-grid {
  336. display: flex;
  337. flex-direction: column;
  338. gap: 8px;
  339. }
  340. .info-row {
  341. display: flex;
  342. gap: 16px;
  343. }
  344. .info-row.single {
  345. display: block;
  346. }
  347. .info-item {
  348. flex: 1;
  349. display: flex;
  350. align-items: baseline;
  351. font-size: 14px;
  352. }
  353. .info-label {
  354. color: #909399;
  355. white-space: nowrap;
  356. min-width: 64px;
  357. }
  358. .info-value {
  359. color: #303133;
  360. }
  361. .desc-text {
  362. color: #606266;
  363. line-height: 1.6;
  364. word-break: break-all;
  365. }
  366. </style>