HistoryTable.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <div class="history-table" v-if="loading">
  3. <BasicTable ref="historyTable" @register="registerTable" :data-source="dataSource">
  4. <template #bodyCell="{ column, record }">
  5. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == '0' ? 'green' : 'red'">{{
  6. record.warnFlag == '0' ? '正常' : '报警'
  7. }}</a-tag>
  8. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == '0' ? '#f00' : 'green'">{{
  9. record.netStatus == '0' ? '断开' : '连接'
  10. }}</a-tag>
  11. <slot name="filterCell" v-bind="{ column, record }"></slot>
  12. </template>
  13. <template #form-submitBefore>
  14. <a-button type="primary" preIcon="ant-design:search-outlined" @click="getDataSource">查询</a-button>
  15. </template>
  16. </BasicTable>
  17. </div>
  18. </template>
  19. <script lang="ts" setup>
  20. //ts语法
  21. import { watchEffect, ref, watch, defineExpose, inject, nextTick } from 'vue';
  22. import { FormSchema } from '/@/components/Form/index';
  23. import { BasicTable } from '/@/components/Table';
  24. import { useListPage } from '/@/hooks/system/useListPage';
  25. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  26. import { defHttp } from '/@/utils/http/axios';
  27. import dayjs from 'dayjs';
  28. import { getAutoScrollContainer } from '/@/utils/common/compUtils';
  29. import { onMounted } from 'vue';
  30. import { safetyDeviceList } from './safety.api';
  31. const globalConfig = inject('globalConfig');
  32. const props = defineProps({
  33. columnsType: {
  34. type: String,
  35. },
  36. columns: {
  37. type: Array,
  38. // required: true,
  39. default: () => [],
  40. },
  41. deviceType: {
  42. type: String,
  43. required: true,
  44. },
  45. deviceListApi: {
  46. type: Function,
  47. },
  48. deviceArr: {
  49. type: Array,
  50. // required: true,
  51. default: () => [],
  52. },
  53. designScope: {
  54. type: String,
  55. },
  56. sysId: {
  57. type: String,
  58. },
  59. deviceId: {
  60. type: String,
  61. },
  62. scroll: {
  63. type: Object,
  64. default: { y: 0 },
  65. },
  66. formSchemas: {
  67. type: Array<FormSchema>,
  68. default: () => [],
  69. },
  70. });
  71. const getDeviceListApi = (params) => defHttp.post({ url: '/monitor/device', params });
  72. const historyTable = ref();
  73. const loading = ref(false);
  74. const stationType = ref('plc1');
  75. const dataSource = ref([]);
  76. const dataTypeName = ref('');
  77. const intervalMap = new Map([
  78. ['1', '1s'],
  79. ['2', '5s'],
  80. ['3', '10s'],
  81. ['4', '30s'],
  82. ['5', '1m'],
  83. ['6', '10m'],
  84. ['7', '30m'],
  85. ['8', '1h'],
  86. ]);
  87. const getExportXlsUrl = () => {
  88. if (stationType.value !== 'redis') {
  89. return '/safety/ventanalyMonitorData/exportXls';
  90. } else {
  91. return '/monitor/history/getHistoryData/exportXls';
  92. }
  93. };
  94. const emit = defineEmits(['change']);
  95. const historyType = ref('');
  96. const columns = ref([]);
  97. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({});
  98. let deviceOptions = ref([]);
  99. const deviceTypeStr = ref('');
  100. loading.value = true;
  101. watch(
  102. () => {
  103. return props.columnsType;
  104. },
  105. async (newVal) => {
  106. if (!newVal) return;
  107. if (historyTable.value) getForm().resetFields();
  108. await getDeviceList();
  109. dataSource.value = [];
  110. const column = getTableHeaderColumns(newVal.includes('_history') ? newVal : newVal + '_history');
  111. if (column && column.length < 1) {
  112. const arr = newVal.split('_');
  113. console.log('历史记录列表表头------------>', arr[0] + '_monitor');
  114. columns.value = getTableHeaderColumns(arr[0] + '_history');
  115. } else {
  116. columns.value = column;
  117. }
  118. await getDataSource();
  119. if (historyTable.value) reload();
  120. },
  121. {
  122. immediate: true,
  123. }
  124. );
  125. watch(historyType, (type) => {
  126. if (!type) return;
  127. // if (historyTable.value) getForm().resetFields()
  128. const column = getTableHeaderColumns(type.includes('_history') ? type : type + '_history');
  129. if (column && column.length < 1) {
  130. const arr = type.split('_');
  131. columns.value = getTableHeaderColumns(arr[0] + '_history');
  132. } else {
  133. columns.value = column;
  134. }
  135. setColumns(columns.value);
  136. });
  137. watch(
  138. () => props.scroll.y,
  139. (newVal) => {
  140. if (newVal) {
  141. tableScroll.value = { y: newVal - 100 };
  142. } else {
  143. tableScroll.value = {};
  144. }
  145. }
  146. );
  147. watch(
  148. () => props.deviceId,
  149. async () => {
  150. await getForm().setFieldsValue({});
  151. await getDeviceList();
  152. }
  153. );
  154. async function getDeviceList() {
  155. let result;
  156. const res = await getDeviceListApi({ devicetype: props.deviceType, filterParams: { dataTypeName: dataTypeName.value }, pageSize: 10000 });
  157. if (res['records'] && res['records'].length > 0) {
  158. result = res['records'];
  159. } else if (res['msgTxt'] && res['msgTxt'][0] && res['msgTxt'][0]['datalist']) {
  160. result = res['msgTxt'][0]['datalist'];
  161. }
  162. if (result && result.length > 0) {
  163. deviceOptions.value = [];
  164. deviceOptions.value = result.map((item, index) => {
  165. return {
  166. label: item['strinstallpos'],
  167. value: item['id'] || item['deviceID'],
  168. strtype: item['strtype'] || item['deviceType'],
  169. strinstallpos: item['strinstallpos'],
  170. devicekind: item['devicekind'],
  171. stationtype: item['stationtype'],
  172. };
  173. });
  174. stationType.value = deviceOptions.value[0]['stationtype'];
  175. } else {
  176. deviceOptions.value = [];
  177. stationType.value = '';
  178. }
  179. await getForm().setFieldsValue({ gdeviceid: props.deviceId ? props.deviceId : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '' });
  180. }
  181. async function getDataSource() {
  182. dataSource.value = [];
  183. setLoading(true);
  184. const stationTypeStr = stationType.value;
  185. const formData = getForm().getFieldsValue();
  186. const pagination = getPaginationRef();
  187. formData['pageNo'] = pagination['current'];
  188. formData['pageSize'] = pagination['pageSize'];
  189. formData['column'] = 'createTime';
  190. if (stationTypeStr !== 'redis') {
  191. formData['strtype'] = deviceTypeStr.value
  192. ? deviceTypeStr.value
  193. : deviceOptions.value[0]['strtype']
  194. ? deviceOptions.value[0]['strtype']
  195. : props.deviceType + '*';
  196. if (props.sysId) {
  197. formData['sysId'] = props.sysId;
  198. }
  199. const result = await defHttp.get({ url: '/safety/ventanalyMonitorData/listdays', params: formData });
  200. setPagination({ total: Math.abs(result['datalist']['total']) || 0 });
  201. if (result['datalist']['records'].length > 0) {
  202. dataSource.value = result['datalist']['records'].map((item: any) => {
  203. return Object.assign(item, item['readData']);
  204. });
  205. } else {
  206. dataSource.value = [];
  207. }
  208. } else {
  209. const params = {
  210. pageNum: pagination['current'],
  211. pageSize: pagination['pageSize'],
  212. column: pagination['createTime'],
  213. startTime: formData['ttime_begin'],
  214. endTime: formData['ttime_end'],
  215. deviceId: formData['gdeviceid'],
  216. strtype: props.deviceType + '*',
  217. sysId: props.sysId,
  218. interval: intervalMap.get(formData['skip']) ? intervalMap.get(formData['skip']) : '1h',
  219. isEmployee: props.deviceType.startsWith('vehicle') ? false : true,
  220. };
  221. const result = await defHttp.post({ url: '/monitor/history/getHistoryData', params: params });
  222. setPagination({ total: Math.abs(result['total']) || 0 });
  223. dataSource.value = result['records'] || [];
  224. }
  225. setLoading(false);
  226. }
  227. // 列表页面公共参数、方法
  228. const { tableContext, onExportXls } = useListPage({
  229. tableProps: {
  230. // api: list,
  231. columns: props.columnsType ? columns : (props.columns as any[]),
  232. canResize: true,
  233. showTableSetting: false,
  234. showActionColumn: false,
  235. bordered: false,
  236. size: 'small',
  237. scroll: tableScroll,
  238. showIndexColumn: true,
  239. tableLayout: 'auto',
  240. formConfig: {
  241. labelAlign: 'left',
  242. showAdvancedButton: false,
  243. showSubmitButton: false,
  244. showResetButton: false,
  245. baseColProps: {
  246. xs: 24,
  247. sm: 24,
  248. md: 24,
  249. lg: 9,
  250. xl: 7,
  251. xxl: 4,
  252. },
  253. schemas: [
  254. {
  255. field: 'ttime_begin',
  256. label: '开始时间',
  257. component: 'DatePicker',
  258. defaultValue: dayjs().startOf('date'),
  259. required: true,
  260. componentProps: {
  261. showTime: true,
  262. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  263. getPopupContainer: getAutoScrollContainer,
  264. },
  265. colProps: {
  266. span: 4,
  267. },
  268. },
  269. {
  270. field: 'ttime_end',
  271. label: '结束时间',
  272. component: 'DatePicker',
  273. defaultValue: dayjs(),
  274. required: true,
  275. componentProps: {
  276. showTime: true,
  277. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  278. getPopupContainer: getAutoScrollContainer,
  279. },
  280. colProps: {
  281. span: 4,
  282. },
  283. },
  284. {
  285. label: '设备类型',
  286. field: 'dataTypeName',
  287. component: 'ApiSelect',
  288. componentProps: {
  289. api: safetyDeviceList.bind(null, { devicetype: 'safetymonitor', code: 'dataTypeName' }),
  290. labelField: 'name',
  291. valueField: 'code',
  292. onChange: async (e, option) => {
  293. console.log('1111', e, option);
  294. dataTypeName.value = e;
  295. await getDeviceList();
  296. },
  297. },
  298. colProps: {
  299. span: 4,
  300. },
  301. },
  302. {
  303. label: '查询设备',
  304. field: 'gdeviceid',
  305. component: 'Select',
  306. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  307. required: true,
  308. componentProps: {
  309. showSearch: true,
  310. filterOption: (input: string, option: any) => {
  311. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  312. },
  313. options: deviceOptions,
  314. onChange: (e, option) => {
  315. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind']))
  316. historyType.value = option['strtype'] || option['devicekind'];
  317. if (option['strtype']) deviceTypeStr.value = option['strtype'];
  318. stationType.value = option['stationtype'];
  319. nextTick(async () => {
  320. await getDataSource();
  321. });
  322. },
  323. },
  324. colProps: {
  325. span: 4,
  326. },
  327. },
  328. {
  329. label: '间隔时间',
  330. field: 'skip',
  331. component: 'Select',
  332. defaultValue: '8',
  333. componentProps: {
  334. options: [
  335. {
  336. label: '1秒',
  337. value: '1',
  338. },
  339. {
  340. label: '5秒',
  341. value: '2',
  342. },
  343. {
  344. label: '10秒',
  345. value: '3',
  346. },
  347. {
  348. label: '30秒',
  349. value: '4',
  350. },
  351. {
  352. label: '1分钟',
  353. value: '5',
  354. },
  355. {
  356. label: '10分钟',
  357. value: '6',
  358. },
  359. {
  360. label: '30分钟',
  361. value: '7',
  362. },
  363. {
  364. label: '1小时',
  365. value: '8',
  366. },
  367. ],
  368. },
  369. colProps: {
  370. span: 4,
  371. },
  372. },
  373. ],
  374. },
  375. pagination: {
  376. current: 1,
  377. pageSize: 10,
  378. pageSizeOptions: ['10', '30', '50', '100'],
  379. showQuickJumper: false,
  380. },
  381. },
  382. exportConfig: {
  383. name: '历史列表',
  384. url: getExportXlsUrl(),
  385. },
  386. });
  387. //注册table数据
  388. const [registerTable, { reload, setLoading, getForm, setColumns, getPaginationRef, setPagination }] = tableContext;
  389. watchEffect(() => {
  390. if (historyTable.value && dataSource) {
  391. const data = dataSource.value || [];
  392. emit('change', data);
  393. }
  394. });
  395. onMounted(async () => {
  396. await getDeviceList();
  397. if (deviceOptions.value[0]) {
  398. stationType.value = deviceOptions.value[0]['stationtype'];
  399. historyType.value = deviceOptions.value[0]['strtype'] || deviceOptions.value[0]['devicekind'];
  400. nextTick(async () => {
  401. await getDataSource();
  402. });
  403. }
  404. watch([() => getPaginationRef()['current'], () => getPaginationRef()['pageSize']], async () => {
  405. if (deviceOptions.value[0]) {
  406. if (deviceOptions.value[0]) {
  407. await getDataSource();
  408. }
  409. }
  410. });
  411. });
  412. defineExpose({ setLoading });
  413. </script>
  414. <style scoped lang="less">
  415. @import '/@/design/theme.less';
  416. :deep(.@{ventSpace}-table-body) {
  417. height: auto !important;
  418. }
  419. :deep(.zxm-picker) {
  420. height: 30px !important;
  421. }
  422. .history-table {
  423. width: 100%;
  424. :deep(.jeecg-basic-table-form-container) {
  425. .@{ventSpace}-form {
  426. padding: 0 !important;
  427. border: none !important;
  428. margin-bottom: 0 !important;
  429. .@{ventSpace}-picker,
  430. .@{ventSpace}-select-selector {
  431. width: 100% !important;
  432. height: 100%;
  433. background: #00000017;
  434. border: 1px solid #b7b7b7;
  435. input,
  436. .@{ventSpace}-select-selection-item,
  437. .@{ventSpace}-picker-suffix {
  438. color: #fff;
  439. }
  440. .@{ventSpace}-select-selection-placeholder {
  441. color: #ffffffaa;
  442. }
  443. }
  444. }
  445. .@{ventSpace}-table-title {
  446. min-height: 0 !important;
  447. }
  448. }
  449. .pagination-box {
  450. display: flex;
  451. justify-content: flex-end;
  452. align-items: center;
  453. .page-num {
  454. border: 1px solid #0090d8;
  455. padding: 4px 8px;
  456. margin-right: 5px;
  457. color: #0090d8;
  458. }
  459. .btn {
  460. margin-right: 10px;
  461. }
  462. }
  463. }
  464. // :deep(.zxm-select-selector){
  465. // height: 42px !important;
  466. // }
  467. </style>