HistoryTable.vue 16 KB

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