HistoryTable.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. }
  207. async function getDataSource() {
  208. dataSource.value = [];
  209. setLoading(true);
  210. const stationTypeStr = stationType.value;
  211. const formData = getForm().getFieldsValue();
  212. const pagination = getPaginationRef();
  213. formData['pageNo'] = pagination['current'];
  214. formData['pageSize'] = pagination['pageSize'];
  215. formData['column'] = 'createTime';
  216. if (stationTypeStr !== 'redis') {
  217. formData['strtype'] = deviceTypeStr.value
  218. ? deviceTypeStr.value
  219. : deviceOptions.value[0]['strtype']
  220. ? deviceOptions.value[0]['strtype']
  221. : props.deviceType + '*';
  222. if (props.sysId) {
  223. formData['sysId'] = props.sysId;
  224. }
  225. const result = await defHttp.get({ url: '/safety/ventanalyMonitorData/listdays', params: formData });
  226. setPagination({ total: Math.abs(result['datalist']['total']) || 0 });
  227. if (result['datalist']['records'].length > 0) {
  228. dataSource.value = result['datalist']['records'].map((item: any) => {
  229. return Object.assign(item, item['readData']);
  230. });
  231. } else {
  232. dataSource.value = [];
  233. }
  234. } else {
  235. const params = {
  236. pageNum: pagination['current'],
  237. pageSize: pagination['pageSize'],
  238. column: pagination['createTime'],
  239. startTime: formData['ttime_begin'],
  240. endTime: formData['ttime_end'],
  241. deviceId: formData['gdeviceid'],
  242. strtype: props.deviceType + '*',
  243. sysId: props.sysId,
  244. interval: intervalMap.get(formData['skip']) ? intervalMap.get(formData['skip']) : '1h',
  245. isEmployee: props.deviceType.startsWith('vehicle') ? false : true,
  246. };
  247. const result = await defHttp.post({ url: '/ventanaly-device/history/getHistoryData', params: params });
  248. setPagination({ total: Math.abs(result['total']) || 0 });
  249. dataSource.value = result['records'] || [];
  250. }
  251. setLoading(false);
  252. }
  253. // 列表页面公共参数、方法
  254. const { tableContext, onExportXls } = useListPage({
  255. tableProps: {
  256. // api: list,
  257. columns: props.columnsType ? columns : (props.columns as any[]),
  258. canResize: true,
  259. showTableSetting: false,
  260. showActionColumn: false,
  261. bordered: false,
  262. size: 'small',
  263. scroll: tableScroll,
  264. showIndexColumn: true,
  265. tableLayout: 'auto',
  266. formConfig: {
  267. labelAlign: 'left',
  268. showAdvancedButton: false,
  269. showSubmitButton: false,
  270. showResetButton: false,
  271. baseColProps: {
  272. xs: 24,
  273. sm: 24,
  274. md: 24,
  275. lg: 9,
  276. xl: 7,
  277. xxl: 4,
  278. },
  279. schemas:
  280. props.formSchemas.length > 0
  281. ? props.formSchemas
  282. : [
  283. {
  284. field: 'ttime_begin',
  285. label: '开始时间',
  286. component: 'DatePicker',
  287. defaultValue: dayjs().startOf('date'),
  288. required: true,
  289. componentProps: {
  290. showTime: true,
  291. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  292. getPopupContainer: getAutoScrollContainer,
  293. },
  294. colProps: {
  295. span: 4,
  296. },
  297. },
  298. {
  299. field: 'ttime_end',
  300. label: '结束时间',
  301. component: 'DatePicker',
  302. defaultValue: dayjs(),
  303. required: true,
  304. componentProps: {
  305. showTime: true,
  306. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  307. getPopupContainer: getAutoScrollContainer,
  308. },
  309. colProps: {
  310. span: 4,
  311. },
  312. },
  313. {
  314. label: '查询设备',
  315. field: 'gdeviceid',
  316. component: 'Select',
  317. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  318. required: true,
  319. componentProps: {
  320. showSearch: true,
  321. filterOption: (input: string, option: any) => {
  322. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  323. },
  324. options: deviceOptions,
  325. onChange: (e, option) => {
  326. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind']))
  327. historyType.value = option['strtype'] || option['devicekind'];
  328. if (option['strtype']) deviceTypeStr.value = option['strtype'];
  329. stationType.value = option['stationtype'];
  330. nextTick(async () => {
  331. await getDataSource();
  332. });
  333. },
  334. },
  335. colProps: {
  336. span: 4,
  337. },
  338. },
  339. {
  340. label: '间隔时间',
  341. field: 'skip',
  342. component: 'Select',
  343. defaultValue: '8',
  344. componentProps: {
  345. options: [
  346. {
  347. label: '1秒',
  348. value: '1',
  349. },
  350. {
  351. label: '5秒',
  352. value: '2',
  353. },
  354. {
  355. label: '10秒',
  356. value: '3',
  357. },
  358. {
  359. label: '30秒',
  360. value: '4',
  361. },
  362. {
  363. label: '1分钟',
  364. value: '5',
  365. },
  366. {
  367. label: '10分钟',
  368. value: '6',
  369. },
  370. {
  371. label: '30分钟',
  372. value: '7',
  373. },
  374. {
  375. label: '1小时',
  376. value: '8',
  377. },
  378. ],
  379. },
  380. colProps: {
  381. span: 4,
  382. },
  383. },
  384. ],
  385. // fieldMapToTime: [['tickectDate', ['ttime_begin', 'ttime_end'], '']],
  386. },
  387. // fetchSetting: {
  388. // listField: 'datalist',
  389. // totalField: 'datalist.total',
  390. // },
  391. pagination: {
  392. current: 1,
  393. pageSize: 10,
  394. pageSizeOptions: ['10', '30', '50', '100'],
  395. showQuickJumper: false,
  396. },
  397. // beforeFetch(params) {
  398. // params.strtype = deviceTypeStr.value
  399. // ? deviceTypeStr.value
  400. // : deviceOptions.value[0]['strtype']
  401. // ? deviceOptions.value[0]['strtype']
  402. // : props.deviceType + '*';
  403. // if (props.sysId) {
  404. // params.sysId = props.sysId;
  405. // }
  406. // return params;
  407. // },
  408. // afterFetch(result) {
  409. // const resultItems = result['records'];
  410. // resultItems.map((item) => {
  411. // Object.assign(item, item['readData']);
  412. // });
  413. // console.log('result---------------->', result);
  414. // return resultItems;
  415. // },
  416. },
  417. exportConfig: {
  418. name: '历史列表',
  419. url: getExportXlsUrl(),
  420. },
  421. });
  422. //注册table数据
  423. const [registerTable, { reload, setLoading, getForm, setColumns, getPaginationRef, setPagination }] = tableContext;
  424. watchEffect(() => {
  425. if (historyTable.value && dataSource) {
  426. const data = dataSource.value || [];
  427. emit('change', data);
  428. }
  429. });
  430. onMounted(async () => {
  431. await getDeviceList();
  432. if (deviceOptions.value[0]) {
  433. stationType.value = deviceOptions.value[0]['stationtype'];
  434. historyType.value = deviceOptions.value[0]['strtype'] || deviceOptions.value[0]['devicekind'];
  435. nextTick(async () => {
  436. await getDataSource();
  437. });
  438. }
  439. watch([() => getPaginationRef()['current'], () => getPaginationRef()['pageSize']], async () => {
  440. if (deviceOptions.value[0]) {
  441. if (deviceOptions.value[0]) {
  442. await getDataSource();
  443. }
  444. }
  445. });
  446. });
  447. defineExpose({ setLoading });
  448. </script>
  449. <style scoped lang="less">
  450. @import '/@/design/vent/color.less';
  451. :deep(.@{ventSpace}-table-body) {
  452. height: auto !important;
  453. }
  454. :deep(.zxm-picker) {
  455. height: 30px !important;
  456. }
  457. .history-table {
  458. width: 100%;
  459. :deep(.jeecg-basic-table-form-container) {
  460. .@{ventSpace}-form {
  461. padding: 0 !important;
  462. border: none !important;
  463. margin-bottom: 0 !important;
  464. .@{ventSpace}-picker,
  465. .@{ventSpace}-select-selector {
  466. width: 100% !important;
  467. height: 100%;
  468. background: #00000017;
  469. border: 1px solid #b7b7b7;
  470. input,
  471. .@{ventSpace}-select-selection-item,
  472. .@{ventSpace}-picker-suffix {
  473. color: #fff;
  474. }
  475. .@{ventSpace}-select-selection-placeholder {
  476. color: #ffffffaa;
  477. }
  478. }
  479. }
  480. .@{ventSpace}-table-title {
  481. min-height: 0 !important;
  482. }
  483. }
  484. .pagination-box {
  485. display: flex;
  486. justify-content: flex-end;
  487. align-items: center;
  488. .page-num {
  489. border: 1px solid #0090d8;
  490. padding: 4px 8px;
  491. margin-right: 5px;
  492. color: #0090d8;
  493. }
  494. .btn {
  495. margin-right: 10px;
  496. }
  497. }
  498. }
  499. // :deep(.zxm-select-selector){
  500. // height: 42px !important;
  501. // }
  502. </style>