LinkRuleTable.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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. <RuleTableModal
  87. @register="register"
  88. @update="onSubmit"
  89. :destroy-on-close="true"
  90. @success="handleModalSuccess"
  91. :form-schemas="workFaceWarningSchemas"
  92. />
  93. </div>
  94. </template>
  95. <script setup lang="ts">
  96. import { ref, reactive, watch, onMounted, nextTick, computed } from 'vue';
  97. import dayjs, { Dayjs } from 'dayjs';
  98. import { message } from 'ant-design-vue';
  99. import DeviceModal from './deviceModal.vue';
  100. import { useModal } from '/@/components/Modal';
  101. import { getAlarmLogList } from '../hsqHome.api.js';
  102. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  103. import { func } from 'vue-types';
  104. import { useLinkRuleStore } from '/@/store/modules/linkRule';
  105. import RuleTableModal from '../../../deviceManager/comment/warningTabel/RuleTableModal.vue';
  106. import { FormSchema } from '/@/components/Table';
  107. import { warningLogEdit, warningLogList } from '../../../deviceManager/comment/warningTabel/warning.api';
  108. import { workFaceWarningFormSchemas } from '../../../deviceManager/comment/warningTabel/warning.data';
  109. const FIXED_STRTYPE = 'sys_openair_fire';
  110. const deviceType = ref('managesys');
  111. const isUpdate = ref(false);
  112. const instanceId = ref(`${Date.now()}_${Math.floor(Math.random() * 10000)}`);
  113. const [registerModal, { openModal, closeModal }] = useModal(instanceId.value);
  114. const linkRuleStore = useLinkRuleStore();
  115. const emit = defineEmits(['row-change', 'table-refresh']);
  116. const currentSelectInfo = ref({
  117. sysId: '',
  118. alarmId: '',
  119. });
  120. const alarmMap: Record<string, string> = {
  121. '102': '黄色预警',
  122. '103': '橙色预警',
  123. '104': '红色预警',
  124. };
  125. // 获取单元格文本内容
  126. const getCellText = (row: any, col: any) => {
  127. const field = col.dataIndex ?? col.prop;
  128. const val = row[field];
  129. if (field === 'alarmLevel' && alarmMap[val]) {
  130. return alarmMap[val];
  131. }
  132. return val ?? '-';
  133. };
  134. const deviceColumns = getTableHeaderColumns('alarm_history') as [];
  135. // 过滤日志只展示指定4列
  136. const filterDeviceColumns = computed(() => {
  137. const showKeys = ['devicename', 'wardescrip', 'starttime', 'warntime'];
  138. return deviceColumns.filter((item) => showKeys.includes(item.dataIndex));
  139. });
  140. const realTableData = computed(() => {
  141. return props.config.type === 'D' ? alarmList.value : tableList.value;
  142. });
  143. const props = defineProps<{
  144. config: {
  145. type: string;
  146. tableReadFrom: string;
  147. columns: {
  148. name: string;
  149. prop: string;
  150. width?: string;
  151. }[];
  152. };
  153. data: Record<string, any>;
  154. selectedRow?: any | null;
  155. }>();
  156. const handleEditClick = (row: any) => {
  157. openModalRule(true, {
  158. isUpdate: true,
  159. record: row,
  160. });
  161. };
  162. // 弹窗保存成功触发
  163. const handleModalSuccess = () => {
  164. emit('table-refresh');
  165. };
  166. const workFaceWarningSchemas: FormSchema[] = [
  167. ...workFaceWarningFormSchemas,
  168. {
  169. label: '关联条目',
  170. field: 'relatedEntries',
  171. component: 'ApiSelect',
  172. componentProps: {
  173. labelField: 'alarmName',
  174. valueField: 'id',
  175. resultField: 'records',
  176. api: warningLogList.bind(null, { sysId: currentSelectInfo.value.sysId }),
  177. },
  178. },
  179. {
  180. label: '预警后自动控制',
  181. field: 'isAutoControl',
  182. component: 'RadioGroup',
  183. componentProps: {
  184. //options里面由一个一个的radio组成,支持disabled
  185. options: [
  186. { label: '是', value: true },
  187. { label: '否', value: false },
  188. ],
  189. },
  190. },
  191. {
  192. label: '解除后自动复位',
  193. field: 'isAutoReset',
  194. component: 'RadioGroup',
  195. componentProps: {
  196. //options里面由一个一个的radio组成,支持disabled
  197. options: [
  198. { label: '是', value: true },
  199. { label: '否', value: false },
  200. ],
  201. },
  202. },
  203. ];
  204. const [register, { openModal: openModalRule, closeModal: closeModalRule }] = useModal();
  205. async function onSubmit(flag, values) {
  206. await warningLogEdit(values);
  207. closeModalRule();
  208. // 通知外层刷新表格
  209. handleModalSuccess();
  210. }
  211. // C类型数据源
  212. const tableList = ref<any[]>([]);
  213. // D类型数据源
  214. const alarmList = ref<any[]>([]);
  215. const timeType = ref(3);
  216. const filterForm = reactive<{ startDate: Dayjs | null }>({
  217. startDate: null,
  218. });
  219. // 默认选中第一条(仅Type='C'时执行)
  220. const autoSelectFirstRow = async () => {
  221. await nextTick();
  222. if (props.config.type !== 'C') return;
  223. const list = realTableData.value;
  224. if (list.length > 0) {
  225. const firstRow = list[0];
  226. emit('row-change', firstRow);
  227. linkRuleStore.setSelectedRow(firstRow);
  228. currentSelectInfo.value.sysId = firstRow.sysId ?? '';
  229. currentSelectInfo.value.alarmId = firstRow.alarmId ?? '';
  230. } else {
  231. emit('row-change', null);
  232. linkRuleStore.clearSelectedRow();
  233. currentSelectInfo.value = { sysId: '', alarmId: '' };
  234. }
  235. };
  236. const isCurrentSelectRow = (row: any) => {
  237. if (!props.selectedRow) return false;
  238. return props.selectedRow === row;
  239. };
  240. const handleRowClick = (row: any) => {
  241. emit('row-change', row);
  242. linkRuleStore.setSelectedRow(row);
  243. currentSelectInfo.value.sysId = row.sysId ?? '';
  244. currentSelectInfo.value.alarmId = row.alarmId ?? '';
  245. };
  246. async function getAlarmHistory() {
  247. const res = await getAlarmLogList({
  248. column: 'createTime',
  249. deviceKind: null,
  250. isOk: false,
  251. pageNo: 1,
  252. pageSize: 100,
  253. startTime: filterForm.startDate?.format('YYYY-MM-DD HH:mm:ss'),
  254. systemType: 'ventS',
  255. });
  256. alarmList.value = res.records || [];
  257. }
  258. onMounted(() => {
  259. getAlarmHistory();
  260. autoSelectFirstRow();
  261. setTimeRange(3);
  262. });
  263. // 监听父组件传入数据,赋值给tableList(Type为C时生效)
  264. watch(
  265. () => props.data,
  266. (newData) => {
  267. const list = newData?.[props.config.tableReadFrom];
  268. tableList.value = list || [];
  269. autoSelectFirstRow();
  270. },
  271. { deep: true, immediate: true }
  272. );
  273. async function handleAdd() {
  274. isUpdate.value = false;
  275. openModal(true, {});
  276. }
  277. const saveOrUpdateHandler = async () => {
  278. try {
  279. message.success(isUpdate.value ? '编辑成功' : '新增成功');
  280. closeModal();
  281. } catch (error) {
  282. message.error('保存失败,请联系管理员');
  283. }
  284. };
  285. const setTimeRange = (type: number) => {
  286. timeType.value = type;
  287. let start: Dayjs;
  288. switch (type) {
  289. case 1:
  290. start = dayjs().startOf('day');
  291. break;
  292. case 2:
  293. start = dayjs().subtract(3, 'day').startOf('day');
  294. break;
  295. case 3:
  296. start = dayjs().subtract(30, 'day').startOf('day');
  297. break;
  298. default:
  299. start = dayjs().startOf('day');
  300. }
  301. filterForm.startDate = start;
  302. getAlarmHistory();
  303. };
  304. // 跳转详情
  305. function confirmDetail() {
  306. window.open('/monitorChannel/device-monitor/warningHistory/home');
  307. }
  308. </script>
  309. <style lang="less" scoped>
  310. @import '/@/design/theme.less';
  311. .search-table {
  312. --image-box-bg: url('@/assets/images/home-container/configurable/hsq/2-5.png');
  313. --image-box-bg2: url('@/assets/images/home-container/configurable/hsq/2-24.png');
  314. position: relative;
  315. width: 100%;
  316. height: 100%;
  317. padding: 10px;
  318. box-sizing: border-box;
  319. }
  320. .list-title {
  321. width: 177px;
  322. height: 30px;
  323. line-height: 22px;
  324. color: #01fefc;
  325. font-weight: bolder;
  326. background: var(--image-box-bg) no-repeat;
  327. background-size: 80% 100%;
  328. margin-bottom: 5px;
  329. }
  330. .search-area {
  331. height: 42px;
  332. display: flex;
  333. justify-content: space-between;
  334. align-items: center;
  335. margin-bottom: 5px;
  336. }
  337. .search-btn {
  338. width: 85px;
  339. height: 30px;
  340. border: 1px solid #01fefc;
  341. border-radius: 4px;
  342. padding: 3px;
  343. cursor: pointer;
  344. }
  345. .search-new .time-picker-wrap {
  346. padding: 10px;
  347. .form-row {
  348. display: flex;
  349. align-items: center;
  350. margin-bottom: 8px;
  351. .form-label {
  352. width: 60px;
  353. font-size: 13px;
  354. color: #fff;
  355. flex-shrink: 0;
  356. }
  357. }
  358. }
  359. :deep(.zxm-picker) {
  360. border: 1px solid #3ae1ff !important;
  361. background-color: #104064 !important;
  362. }
  363. :deep(.zxm-picker-input > input) {
  364. color: #fff !important;
  365. }
  366. :deep(.zxm-picker-suffix) {
  367. color: #fff !important;
  368. }
  369. .time-select {
  370. display: flex;
  371. align-items: center;
  372. padding-left: 10px;
  373. margin-bottom: 8px;
  374. gap: 6px;
  375. white-space: nowrap;
  376. .span {
  377. color: #fff;
  378. font-size: 13px;
  379. }
  380. .btn {
  381. padding: 3px 8px;
  382. background: #114268;
  383. border: 1px solid transparent;
  384. border-radius: 4px;
  385. color: #fff;
  386. cursor: pointer;
  387. font-size: 13px;
  388. &.active {
  389. background-color: #185f8e;
  390. border-color: #2084c0;
  391. }
  392. }
  393. }
  394. .btn-item {
  395. display: flex;
  396. justify-content: center;
  397. align-items: center;
  398. width: 100%;
  399. height: 100%;
  400. background-color: rgba(32, 166, 169);
  401. }
  402. .content-area {
  403. height: 100%;
  404. }
  405. .table-container {
  406. width: 100%;
  407. height: 100%;
  408. overflow-y: auto;
  409. }
  410. .warning-table {
  411. width: 100%;
  412. table-layout: fixed;
  413. border-collapse: collapse;
  414. }
  415. .table-header tr {
  416. position: sticky;
  417. top: 0;
  418. z-index: 10;
  419. background: var(--image-box-bg2) no-repeat;
  420. background-size: 100% 100%;
  421. }
  422. .table-row {
  423. height: 36px;
  424. &:nth-child(odd) {
  425. background-color: #0e3455;
  426. }
  427. &:nth-child(even) {
  428. background-color: #114268;
  429. }
  430. &.box_active {
  431. box-shadow: 2px 0 0 0 #ffa024, inset 0 0 0 2px #ffa024;
  432. }
  433. }
  434. th,
  435. .table-cell {
  436. text-align: center;
  437. padding: 5px;
  438. font-size: 14px;
  439. box-sizing: border-box;
  440. vertical-align: middle;
  441. }
  442. th {
  443. font-weight: bold;
  444. color: #38e4ef;
  445. height: 30px;
  446. }
  447. .text-look {
  448. padding: 0 3px;
  449. margin: 0 2px;
  450. border-radius: 2px;
  451. background-color: #2484bc;
  452. cursor: pointer;
  453. }
  454. /* 文字省略样式 */
  455. .text-ellipsis {
  456. display: block;
  457. width: 100%;
  458. overflow: hidden;
  459. white-space: nowrap;
  460. text-overflow: ellipsis;
  461. }
  462. </style>