HistoryTable.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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: 'Select',
  320. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  321. required: true,
  322. componentProps: {
  323. showSearch: true,
  324. filterOption: (input: string, option: any) => {
  325. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  326. },
  327. options: deviceOptions,
  328. onChange: (e, option) => {
  329. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind']))
  330. historyType.value = option['strtype'] || option['devicekind'];
  331. if (option['strtype']) deviceTypeStr.value = option['strtype'];
  332. stationType.value = option['stationtype'];
  333. nextTick(async () => {
  334. await getDataSource();
  335. });
  336. },
  337. },
  338. colProps: {
  339. span: 4,
  340. },
  341. },
  342. {
  343. label: '间隔时间',
  344. field: 'skip',
  345. component: 'Select',
  346. defaultValue: '8',
  347. componentProps: {
  348. options: [
  349. {
  350. label: '1秒',
  351. value: '1',
  352. },
  353. {
  354. label: '5秒',
  355. value: '2',
  356. },
  357. {
  358. label: '10秒',
  359. value: '3',
  360. },
  361. {
  362. label: '30秒',
  363. value: '4',
  364. },
  365. {
  366. label: '1分钟',
  367. value: '5',
  368. },
  369. {
  370. label: '10分钟',
  371. value: '6',
  372. },
  373. {
  374. label: '30分钟',
  375. value: '7',
  376. },
  377. {
  378. label: '1小时',
  379. value: '8',
  380. },
  381. ],
  382. },
  383. colProps: {
  384. span: 4,
  385. },
  386. },
  387. ],
  388. // fieldMapToTime: [['tickectDate', ['ttime_begin', 'ttime_end'], '']],
  389. },
  390. // fetchSetting: {
  391. // listField: 'datalist',
  392. // totalField: 'datalist.total',
  393. // },
  394. pagination: {
  395. current: 1,
  396. pageSize: 10,
  397. pageSizeOptions: ['10', '30', '50', '100'],
  398. showQuickJumper: false,
  399. },
  400. // beforeFetch(params) {
  401. // params.strtype = deviceTypeStr.value
  402. // ? deviceTypeStr.value
  403. // : deviceOptions.value[0]['strtype']
  404. // ? deviceOptions.value[0]['strtype']
  405. // : props.deviceType + '*';
  406. // if (props.sysId) {
  407. // params.sysId = props.sysId;
  408. // }
  409. // return params;
  410. // },
  411. // afterFetch(result) {
  412. // const resultItems = result['records'];
  413. // resultItems.map((item) => {
  414. // Object.assign(item, item['readData']);
  415. // });
  416. // console.log('result---------------->', result);
  417. // return resultItems;
  418. // },
  419. },
  420. exportConfig: {
  421. name: '历史列表',
  422. url: getExportXlsUrl(),
  423. },
  424. });
  425. //注册table数据
  426. const [registerTable, { reload, setLoading, getForm, setColumns, getPaginationRef, setPagination }] = tableContext;
  427. watchEffect(() => {
  428. if (historyTable.value && dataSource) {
  429. const data = dataSource.value || [];
  430. emit('change', data);
  431. }
  432. });
  433. onMounted(async () => {
  434. await getDeviceList();
  435. if (deviceOptions.value[0]) {
  436. stationType.value = deviceOptions.value[0]['stationtype'];
  437. historyType.value = deviceOptions.value[0]['strtype'] || deviceOptions.value[0]['devicekind'];
  438. nextTick(async () => {
  439. await getDataSource();
  440. });
  441. }
  442. watch([() => getPaginationRef()['current'], () => getPaginationRef()['pageSize']], async () => {
  443. if (deviceOptions.value[0]) {
  444. if (deviceOptions.value[0]) {
  445. await getDataSource();
  446. }
  447. }
  448. });
  449. });
  450. defineExpose({ setLoading });
  451. </script>
  452. <style scoped lang="less">
  453. @import '/@/design/vent/color.less';
  454. :deep(.@{ventSpace}-table-body) {
  455. height: auto !important;
  456. }
  457. :deep(.zxm-picker) {
  458. height: 30px !important;
  459. }
  460. .history-table {
  461. width: 100%;
  462. :deep(.jeecg-basic-table-form-container) {
  463. .@{ventSpace}-form {
  464. padding: 0 !important;
  465. border: none !important;
  466. margin-bottom: 0 !important;
  467. .@{ventSpace}-picker,
  468. .@{ventSpace}-select-selector {
  469. width: 100% !important;
  470. height: 100%;
  471. background: #00000017;
  472. border: 1px solid #b7b7b7;
  473. input,
  474. .@{ventSpace}-select-selection-item,
  475. .@{ventSpace}-picker-suffix {
  476. color: #fff;
  477. }
  478. .@{ventSpace}-select-selection-placeholder {
  479. color: #ffffffaa;
  480. }
  481. }
  482. }
  483. .@{ventSpace}-table-title {
  484. min-height: 0 !important;
  485. }
  486. }
  487. .pagination-box {
  488. display: flex;
  489. justify-content: flex-end;
  490. align-items: center;
  491. .page-num {
  492. border: 1px solid #0090d8;
  493. padding: 4px 8px;
  494. margin-right: 5px;
  495. color: #0090d8;
  496. }
  497. .btn {
  498. margin-right: 10px;
  499. }
  500. }
  501. }
  502. // :deep(.zxm-select-selector){
  503. // height: 42px !important;
  504. // }
  505. </style>