ruleTable.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <div class="search-table">
  3. <div class="search-area" v-if="config.type === 'C'">
  4. <div class="list-title">
  5. <span>联动规则列表</span>
  6. </div>
  7. <div class="search-btn" @click="handleAdd">
  8. <div class="btn-item">配置</div>
  9. </div>
  10. </div>
  11. <div v-if="config.type === 'D'" class="search-new">
  12. <div class="list-title">
  13. <span>联动日志</span>
  14. </div>
  15. <div class="time-picker-wrap">
  16. <div class="form-row">
  17. <label class="form-label">开始时间:</label>
  18. <a-date-picker
  19. v-model:value="filterForm.startDate"
  20. placeholder="请选择开始时间"
  21. class="date-picker"
  22. show-time
  23. format="YYYY-MM-DD HH:mm:ss"
  24. style="width: 300px !important"
  25. />
  26. </div>
  27. </div>
  28. <div class="time-select">
  29. <span class="span">快捷时间:</span>
  30. <div class="btn" :class="{ active: timeType === 1 }" @click="setTimeRange(1)">今日</div>
  31. <div class="btn" :class="{ active: timeType === 2 }" @click="setTimeRange(2)">近三天</div>
  32. <div class="btn" :class="{ active: timeType === 3 }" @click="setTimeRange(3)">近一月</div>
  33. <div class="search-btn" @click="confirmDetail">
  34. <div class="btn-item">详情</div>
  35. </div>
  36. </div>
  37. </div>
  38. <div class="content-area">
  39. <div class="table-container">
  40. <table class="warning-table">
  41. <colgroup>
  42. <col
  43. v-for="col in config.type === 'C' ? config.columns : filterDeviceColumns"
  44. :key="col.dataIndex || col.prop"
  45. :style="{ width: col.width }"
  46. />
  47. </colgroup>
  48. <thead class="table-header">
  49. <tr>
  50. <th v-for="col in config.type === 'C' ? config.columns : filterDeviceColumns" :key="col.dataIndex || col.prop">
  51. {{ col.title || col.name }}
  52. </th>
  53. </tr>
  54. </thead>
  55. <tbody class="table-body">
  56. <tr
  57. v-for="(row, index) in realTableData"
  58. :key="index"
  59. class="table-row"
  60. :class="config.type === 'C' ? { box_active: isCurrentSelectRow(row) } : ''"
  61. @click="config.type === 'C' ? handleRowClick(row) : ''"
  62. >
  63. <td v-for="col in config.type === 'C' ? config.columns : filterDeviceColumns" :key="col.dataIndex || col.prop" class="table-cell">
  64. <template v-if="config.type === 'C' && col.prop === 'operation'">
  65. <span class="text-look" @click="handleEditClick(row)">确认</span>
  66. </template>
  67. <template v-else>
  68. <span class="text-ellipsis" :title="getCellText(row, col)">
  69. {{ getCellText(row, col) }}
  70. </span>
  71. </template>
  72. </td>
  73. </tr>
  74. </tbody>
  75. </table>
  76. </div>
  77. </div>
  78. <DeviceModal
  79. @register="registerModal"
  80. :show-tab="true"
  81. @saveOrUpdate="saveOrUpdateHandler"
  82. :device-type="deviceType"
  83. :select-sys-alarm-id="currentSelectInfo.alarmId"
  84. :select-sys-id="currentSelectInfo.sysId"
  85. />
  86. </div>
  87. </template>
  88. <script setup lang="ts">
  89. import { ref, reactive, watch, onMounted, nextTick, computed } from 'vue';
  90. import dayjs, { Dayjs } from 'dayjs';
  91. import { message } from 'ant-design-vue';
  92. import DeviceModal from './deviceModal.vue';
  93. import { useModal } from '/@/components/Modal';
  94. import { getAlarmLogList } from '../../configurable.api';
  95. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  96. import { func } from 'vue-types';
  97. import { useLinkRuleStore } from '/@/store/modules/linkRule';
  98. const FIXED_STRTYPE = 'sys_openair_fire';
  99. const deviceType = ref('managesys');
  100. const isUpdate = ref(false);
  101. const instanceId = ref(`${Date.now()}_${Math.floor(Math.random() * 10000)}`);
  102. const [registerModal, { openModal, closeModal }] = useModal(instanceId.value);
  103. const linkRuleStore = useLinkRuleStore();
  104. const emit = defineEmits(['row-change']);
  105. const currentSelectInfo = ref({
  106. sysId: '',
  107. alarmId: '',
  108. });
  109. const alarmMap: Record<string, string> = {
  110. '102': '黄色预警',
  111. '103': '橙色预警',
  112. '104': '红色预警',
  113. };
  114. // 获取单元格文本内容
  115. const getCellText = (row: any, col: any) => {
  116. const field = col.dataIndex ?? col.prop;
  117. const val = row[field];
  118. if (field === 'alarmLevel' && alarmMap[val]) {
  119. return alarmMap[val];
  120. }
  121. return val ?? '-';
  122. };
  123. const deviceColumns = getTableHeaderColumns('alarm_history') as [];
  124. // 过滤日志只展示指定4列
  125. const filterDeviceColumns = computed(() => {
  126. const showKeys = ['devicename', 'wardescrip', 'starttime', 'warntime'];
  127. return deviceColumns.filter((item) => showKeys.includes(item.dataIndex));
  128. });
  129. const realTableData = computed(() => {
  130. return props.config.type === 'D' ? alarmList.value : tableList.value;
  131. });
  132. const props = defineProps<{
  133. config: {
  134. type: string;
  135. tableReadFrom: string;
  136. columns: {
  137. name: string;
  138. prop: string;
  139. width?: string;
  140. }[];
  141. };
  142. data: Record<string, any>;
  143. selectedRow?: any | null;
  144. }>();
  145. const handleEditClick = (row: any) => {};
  146. // C类型数据源
  147. const tableList = ref<any[]>([]);
  148. // D类型数据源
  149. const alarmList = ref<any[]>([]);
  150. const timeType = ref(3);
  151. const filterForm = reactive<{ startDate: Dayjs | null }>({
  152. startDate: null,
  153. });
  154. // 默认选中第一条(仅Type='C'时执行)
  155. const autoSelectFirstRow = async () => {
  156. await nextTick();
  157. if (props.config.type !== 'C') return;
  158. const list = realTableData.value;
  159. if (list.length > 0) {
  160. const firstRow = list[0];
  161. emit('row-change', firstRow);
  162. linkRuleStore.setSelectedRow(firstRow);
  163. currentSelectInfo.value.sysId = firstRow.sysId ?? '';
  164. currentSelectInfo.value.alarmId = firstRow.alarmId ?? '';
  165. } else {
  166. emit('row-change', null);
  167. linkRuleStore.clearSelectedRow();
  168. currentSelectInfo.value = { sysId: '', alarmId: '' };
  169. }
  170. };
  171. const isCurrentSelectRow = (row: any) => {
  172. if (!props.selectedRow) return false;
  173. return props.selectedRow === row;
  174. };
  175. const handleRowClick = (row: any) => {
  176. emit('row-change', row);
  177. linkRuleStore.setSelectedRow(row);
  178. currentSelectInfo.value.sysId = row.sysId ?? '';
  179. currentSelectInfo.value.alarmId = row.alarmId ?? '';
  180. };
  181. async function getAlarmHistory() {
  182. const res = await getAlarmLogList({
  183. column: 'createTime',
  184. deviceKind: null,
  185. isOk: false,
  186. pageNo: 1,
  187. pageSize: 100,
  188. startTime: filterForm.startDate?.format('YYYY-MM-DD HH:mm:ss'),
  189. systemType: 'ventS',
  190. });
  191. alarmList.value = res.records || [];
  192. }
  193. onMounted(() => {
  194. getAlarmHistory();
  195. autoSelectFirstRow();
  196. setTimeRange(3);
  197. });
  198. // 监听父组件传入数据,赋值给tableList(Type为C时生效)
  199. watch(
  200. () => props.data?.[props.config.tableReadFrom],
  201. (newArr) => {
  202. tableList.value = newArr || [];
  203. autoSelectFirstRow();
  204. },
  205. { deep: true, immediate: true }
  206. );
  207. async function handleAdd() {
  208. isUpdate.value = false;
  209. openModal(true, {});
  210. }
  211. const saveOrUpdateHandler = async () => {
  212. try {
  213. message.success(isUpdate.value ? '编辑成功' : '新增成功');
  214. closeModal();
  215. } catch (error) {
  216. message.error('保存失败,请联系管理员');
  217. }
  218. };
  219. const setTimeRange = (type: number) => {
  220. timeType.value = type;
  221. let start: Dayjs;
  222. switch (type) {
  223. case 1:
  224. start = dayjs().startOf('day');
  225. break;
  226. case 2:
  227. start = dayjs().subtract(3, 'day').startOf('day');
  228. break;
  229. case 3:
  230. start = dayjs().subtract(30, 'day').startOf('day');
  231. break;
  232. default:
  233. start = dayjs().startOf('day');
  234. }
  235. filterForm.startDate = start;
  236. getAlarmHistory();
  237. };
  238. // 跳转详情
  239. function confirmDetail() {
  240. window.open('/monitorChannel/device-monitor/warningHistory/home');
  241. }
  242. </script>
  243. <style lang="less" scoped>
  244. @import '/@/design/theme.less';
  245. .search-table {
  246. --image-box-bg: url('@/assets/images/home-container/configurable/hsq/2-5.png');
  247. --image-box-bg2: url('@/assets/images/home-container/configurable/hsq/2-24.png');
  248. position: relative;
  249. width: 100%;
  250. height: 100%;
  251. padding: 10px;
  252. box-sizing: border-box;
  253. }
  254. .list-title {
  255. width: 177px;
  256. height: 30px;
  257. line-height: 22px;
  258. color: #01fefc;
  259. font-weight: bolder;
  260. background: var(--image-box-bg) no-repeat;
  261. background-size: 80% 100%;
  262. margin-bottom: 5px;
  263. }
  264. .search-area {
  265. height: 42px;
  266. display: flex;
  267. justify-content: space-between;
  268. align-items: center;
  269. margin-bottom: 5px;
  270. }
  271. .search-btn {
  272. width: 85px;
  273. height: 30px;
  274. border: 1px solid #01fefc;
  275. border-radius: 4px;
  276. padding: 3px;
  277. cursor: pointer;
  278. }
  279. .search-new .time-picker-wrap {
  280. padding: 10px;
  281. .form-row {
  282. display: flex;
  283. align-items: center;
  284. margin-bottom: 8px;
  285. .form-label {
  286. width: 60px;
  287. font-size: 13px;
  288. color: #fff;
  289. flex-shrink: 0;
  290. }
  291. }
  292. }
  293. :deep(.zxm-picker) {
  294. border: 1px solid #3ae1ff !important;
  295. background-color: #104064 !important;
  296. }
  297. :deep(.zxm-picker-input > input) {
  298. color: #fff !important;
  299. }
  300. :deep(.zxm-picker-suffix) {
  301. color: #fff !important;
  302. }
  303. .time-select {
  304. display: flex;
  305. align-items: center;
  306. padding-left: 10px;
  307. margin-bottom: 8px;
  308. gap: 6px;
  309. white-space: nowrap;
  310. .span {
  311. color: #fff;
  312. font-size: 13px;
  313. }
  314. .btn {
  315. padding: 3px 8px;
  316. background: #114268;
  317. border: 1px solid transparent;
  318. border-radius: 4px;
  319. color: #fff;
  320. cursor: pointer;
  321. font-size: 13px;
  322. &.active {
  323. background-color: #185f8e;
  324. border-color: #2084c0;
  325. }
  326. }
  327. }
  328. .btn-item {
  329. display: flex;
  330. justify-content: center;
  331. align-items: center;
  332. width: 100%;
  333. height: 100%;
  334. background-color: rgba(32, 166, 169);
  335. }
  336. .content-area {
  337. height: 100%;
  338. }
  339. .table-container {
  340. width: 100%;
  341. height: 100%;
  342. overflow-y: auto;
  343. }
  344. .warning-table {
  345. width: 100%;
  346. table-layout: fixed;
  347. border-collapse: collapse;
  348. }
  349. .table-header tr {
  350. position: sticky;
  351. top: 0;
  352. z-index: 10;
  353. background: var(--image-box-bg2) no-repeat;
  354. background-size: 100% 100%;
  355. }
  356. .table-row {
  357. height: 36px;
  358. &:nth-child(odd) {
  359. background-color: #0e3455;
  360. }
  361. &:nth-child(even) {
  362. background-color: #114268;
  363. }
  364. &.box_active {
  365. box-shadow: 2px 0 0 0 #ffa024, inset 0 0 0 2px #ffa024;
  366. }
  367. }
  368. th,
  369. .table-cell {
  370. text-align: center;
  371. padding: 5px;
  372. font-size: 14px;
  373. box-sizing: border-box;
  374. vertical-align: middle;
  375. }
  376. th {
  377. font-weight: bold;
  378. color: #38e4ef;
  379. height: 30px;
  380. }
  381. .text-look {
  382. padding: 0 3px;
  383. margin: 0 2px;
  384. border-radius: 2px;
  385. background-color: #2484bc;
  386. cursor: pointer;
  387. }
  388. /* 文字省略样式 */
  389. .text-ellipsis {
  390. display: block;
  391. width: 100%;
  392. overflow: hidden;
  393. white-space: nowrap;
  394. text-overflow: ellipsis;
  395. }
  396. </style>