HistoryTable.vue 14 KB

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