HistoryTable.vue 14 KB

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