HistoryTable.vue 16 KB

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