HistoryTable.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <div class="history-table" v-if="loading">
  3. <BasicTable ref="historyTable" @register="registerTable" :data-source="dataSource" :columns="historyColumns">
  4. <template #form-submitBefore>
  5. <a-button type="primary" preIcon="ant-design:search-outlined" @click="getDataSource">查询</a-button>
  6. <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXlsFn">导出</a-button>
  7. </template>
  8. </BasicTable>
  9. </div>
  10. </template>
  11. <script lang="ts" setup>
  12. //ts语法
  13. import { watchEffect, ref, watch, defineExpose, inject, nextTick, onMounted, computed } from 'vue';
  14. import { subStationList } from '../safetyList.api';
  15. import { historyColumns } from '../historyLsit.data';
  16. import { FormSchema } from '/@/components/Form/index';
  17. import { BasicTable } from '/@/components/Table';
  18. import { useListPage } from '/@/hooks/system/useListPage';
  19. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  20. import { useMethods } from '/@/hooks/system/useMethods';
  21. import { defHttp } from '/@/utils/http/axios';
  22. import dayjs from 'dayjs';
  23. import { getAutoScrollContainer } from '/@/utils/common/compUtils';
  24. const props = defineProps({
  25. columnsType: {
  26. type: String,
  27. },
  28. columns: {
  29. type: Array,
  30. // required: true,
  31. default: () => [],
  32. },
  33. historyColumns: {
  34. type: Array,
  35. default: () => [],
  36. },
  37. stationId: {
  38. type: String,
  39. },
  40. scroll: {
  41. type: Object,
  42. default: { y: 0 },
  43. },
  44. formSchemas: {
  45. type: Array<FormSchema>,
  46. default: () => [],
  47. },
  48. });
  49. const postExportXlsUrl = '/safety/ventanalySubStation/export158StatusLog';
  50. //获取分站数据
  51. const getDeviceListApi = (params) => defHttp.get({ url: '/safety/ventanalySubStation/alllist', params });
  52. const historyTable = ref();
  53. const loading = ref(false);
  54. const dataSource = ref([]);
  55. const emit = defineEmits(['change']);
  56. const historyType = ref('');
  57. const deviceKide = ref('');
  58. const columns = ref([]);
  59. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({});
  60. const statusMap = new Map([
  61. ['1', '连接成功'],
  62. ['0', '连接失败'],
  63. ]);
  64. loading.value = true;
  65. watch(
  66. () => {
  67. return props.columnsType;
  68. },
  69. async (newVal) => {
  70. debugger;
  71. if (!newVal) return;
  72. deviceKide.value = newVal;
  73. if (historyTable.value) {
  74. getForm().resetFields();
  75. // getForm().updateSchema();
  76. // getForm();
  77. }
  78. dataSource.value = [];
  79. nextTick(() => {
  80. getDataSource();
  81. });
  82. if (historyTable.value) reload();
  83. },
  84. {
  85. immediate: true,
  86. }
  87. );
  88. watch(
  89. () => props.scroll.y,
  90. (newVal) => {
  91. if (newVal) {
  92. tableScroll.value = { y: newVal - 100 };
  93. } else {
  94. tableScroll.value = {};
  95. }
  96. }
  97. );
  98. watch(
  99. () => props.stationId,
  100. async () => {
  101. await getForm().setFieldsValue({});
  102. }
  103. );
  104. function resetFormParam() {
  105. const formData = getForm().getFieldsValue();
  106. const pagination = getPaginationRef();
  107. formData['pageNo'] = pagination['current'];
  108. formData['pageSize'] = pagination['pageSize'];
  109. const params = {
  110. pageNo: pagination['current'],
  111. pageSize: pagination['pageSize'],
  112. createTime_begin: formData['starttime_begin'],
  113. createTime_end: formData['starttime_end'],
  114. stationId: props.stationId,
  115. status: formData['status'],
  116. };
  117. return params;
  118. }
  119. async function getDataSource() {
  120. dataSource.value = [];
  121. setLoading(true);
  122. const params = await resetFormParam();
  123. const result = await defHttp.post({ url: '/safety/ventanalySubStation/get158StatusLog', params: params });
  124. // if (result['datalist']['records'].length > 0) {
  125. // dataSource.value = result['datalist']['records'].map((item: any) => {
  126. // return Object.assign(item, item['readData']);
  127. // });
  128. // } else {
  129. dataSource.value = result['records'];
  130. // }
  131. // return result;
  132. setLoading(false);
  133. }
  134. //导出
  135. // function onExportXlsFn() {
  136. // // const params = resetFormParam();
  137. // // // 判断时间间隔和查询时间区间,数据量下载大时进行提示
  138. // // return onExportXlsPost(params);
  139. // }
  140. //导入导出方法
  141. function onExportXlsFn() {
  142. const { handleExportXlsPost } = useMethods();
  143. const params = resetFormParam();
  144. handleExportXlsPost('历史数据', postExportXlsUrl, params);
  145. }
  146. // 列表页面公共参数、方法
  147. const { tableContext, onExportXlsPost } = useListPage({
  148. tableProps: {
  149. // api: list,
  150. columns: props.historyColumns ? props.historyColumns : (props.historyColumns as any[]),
  151. canResize: true,
  152. showTableSetting: false,
  153. showActionColumn: false,
  154. bordered: false,
  155. size: 'small',
  156. scroll: tableScroll,
  157. showIndexColumn: true,
  158. tableLayout: 'auto',
  159. formConfig: {
  160. labelAlign: 'left',
  161. showAdvancedButton: false,
  162. showSubmitButton: false,
  163. showResetButton: false,
  164. baseColProps: {
  165. xs: 24,
  166. sm: 24,
  167. md: 24,
  168. lg: 9,
  169. xl: 7,
  170. xxl: 4,
  171. },
  172. schemas:
  173. props.formSchemas.length > 0
  174. ? props.formSchemas
  175. : [
  176. {
  177. field: 'starttime_begin',
  178. label: '开始时间',
  179. component: 'DatePicker',
  180. defaultValue: dayjs().startOf('date'),
  181. required: true,
  182. componentProps: {
  183. showTime: true,
  184. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  185. getPopupContainer: getAutoScrollContainer,
  186. },
  187. colProps: {
  188. span: 6,
  189. },
  190. },
  191. {
  192. field: 'starttime_end',
  193. label: '结束时间',
  194. component: 'DatePicker',
  195. defaultValue: dayjs(),
  196. required: true,
  197. componentProps: {
  198. showTime: true,
  199. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  200. getPopupContainer: getAutoScrollContainer,
  201. },
  202. colProps: {
  203. span: 6,
  204. },
  205. },
  206. {
  207. label: '连接状态',
  208. field: 'status',
  209. component: 'Select',
  210. defaultValue: '1',
  211. componentProps: () => {
  212. return {
  213. options: [
  214. { label: '连接成功', value: 1 },
  215. { label: '连接失败', value: 0 },
  216. ],
  217. };
  218. },
  219. colProps: {
  220. span: 6,
  221. },
  222. },
  223. ],
  224. },
  225. // fetchSetting: {
  226. pagination: {
  227. current: 1,
  228. pageSize: 20,
  229. pageSizeOptions: ['10', '30', '50', '100'],
  230. showQuickJumper: false,
  231. },
  232. beforeFetch() {
  233. const newParams = { ...resetFormParam() };
  234. // debugger;
  235. return newParams;
  236. },
  237. },
  238. exportConfig: {
  239. name: '历史列表',
  240. url: postExportXlsUrl,
  241. },
  242. });
  243. //注册table数据
  244. const [registerTable, { reload, setLoading, getForm, setColumns, getPaginationRef, setPagination }] = tableContext;
  245. watchEffect(() => {
  246. if (historyTable.value && dataSource) {
  247. const data = dataSource.value || [];
  248. emit('change', data);
  249. }
  250. });
  251. onMounted(async () => {
  252. if (props.stationId) {
  253. nextTick(async () => {
  254. await getDataSource();
  255. });
  256. }
  257. });
  258. defineExpose({ setLoading });
  259. </script>
  260. <style scoped lang="less">
  261. @import '/@/design/vent/color.less';
  262. :deep(.@{ventSpace}-table-body) {
  263. height: auto !important;
  264. }
  265. :deep(.zxm-picker) {
  266. height: 30px !important;
  267. }
  268. .history-table {
  269. width: 100%;
  270. :deep(.jeecg-basic-table-form-container) {
  271. .@{ventSpace}-form {
  272. padding: 0 !important;
  273. border: none !important;
  274. margin-bottom: 0 !important;
  275. .@{ventSpace}-picker,
  276. .@{ventSpace}-select-selector {
  277. width: 100% !important;
  278. height: 100%;
  279. background: #00000017;
  280. border: 1px solid #b7b7b7;
  281. input,
  282. .@{ventSpace}-select-selection-item,
  283. .@{ventSpace}-picker-suffix {
  284. color: #fff;
  285. }
  286. .@{ventSpace}-select-selection-placeholder {
  287. color: #ffffffaa;
  288. }
  289. .@{ventSpace}-zxm-select-selection-item {
  290. color: #00000017 !important;
  291. }
  292. }
  293. }
  294. .@{ventSpace}-table-title {
  295. min-height: 0 !important;
  296. }
  297. }
  298. .pagination-box {
  299. display: flex;
  300. justify-content: flex-end;
  301. align-items: center;
  302. .page-num {
  303. border: 1px solid #0090d8;
  304. padding: 4px 8px;
  305. margin-right: 5px;
  306. color: #0090d8;
  307. }
  308. .btn {
  309. margin-right: 10px;
  310. }
  311. }
  312. }
  313. </style>