HistoryTable.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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" style="margin-right: 20px">查询</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 historyTable = ref();
  52. const loading = ref(false);
  53. const dataSource = ref([]);
  54. const emit = defineEmits(['change']);
  55. const deviceKide = ref('');
  56. const columns = ref([]);
  57. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({});
  58. loading.value = true;
  59. watch(
  60. () => {
  61. return props.columnsType;
  62. },
  63. async (newVal) => {
  64. if (!newVal) return;
  65. deviceKide.value = newVal;
  66. if (historyTable.value) {
  67. getForm().resetFields();
  68. // getForm().updateSchema();
  69. // getForm();
  70. }
  71. dataSource.value = [];
  72. nextTick(() => {
  73. getDataSource();
  74. });
  75. if (historyTable.value) reload();
  76. },
  77. {
  78. immediate: true,
  79. }
  80. );
  81. watch(
  82. () => props.scroll.y,
  83. (newVal) => {
  84. if (newVal) {
  85. tableScroll.value = { y: newVal - 100 };
  86. } else {
  87. tableScroll.value = {};
  88. }
  89. }
  90. );
  91. watch(
  92. () => props.stationId,
  93. async () => {
  94. await getForm().setFieldsValue({});
  95. }
  96. );
  97. function resetFormParam() {
  98. const formData = getForm().getFieldsValue();
  99. const pagination = getPaginationRef();
  100. formData['pageNo'] = pagination['current'];
  101. formData['pageSize'] = pagination['pageSize'];
  102. const params = {
  103. pageNo: pagination['current'],
  104. pageSize: pagination['pageSize'],
  105. createTime_begin: formData['starttime_begin'],
  106. createTime_end: formData['starttime_end'],
  107. stationId: props.stationId,
  108. status: formData['status'],
  109. };
  110. return params;
  111. }
  112. async function getDataSource() {
  113. dataSource.value = [];
  114. setLoading(true);
  115. const params = await resetFormParam();
  116. const res = await defHttp.post(
  117. { url: '/safety/ventanalySubStation/get158StatusLog', params: params },
  118. { joinParamsToUrl: true, isTransformResponse: false }
  119. );
  120. console.log(res.result['records']);
  121. if (res.result['records'].length > 0) {
  122. dataSource.value = res.result['records'];
  123. setLoading(false);
  124. } else {
  125. dataSource.value = [];
  126. setLoading(false);
  127. }
  128. }
  129. //导入导出方法
  130. function onExportXlsFn() {
  131. const { exportXlsPost0 } = useMethods();
  132. const params = resetFormParam();
  133. exportXlsPost0('历史数据', postExportXlsUrl, params);
  134. }
  135. // 列表页面公共参数、方法
  136. const { tableContext } = useListPage({
  137. tableProps: {
  138. // api: list,
  139. columns: props.historyColumns ? props.historyColumns : (props.historyColumns as any[]),
  140. canResize: true,
  141. showTableSetting: false,
  142. showActionColumn: false,
  143. bordered: false,
  144. size: 'small',
  145. scroll: tableScroll,
  146. showIndexColumn: true,
  147. tableLayout: 'auto',
  148. formConfig: {
  149. labelAlign: 'left',
  150. showAdvancedButton: false,
  151. showSubmitButton: false,
  152. showResetButton: false,
  153. baseColProps: {
  154. xs: 24,
  155. sm: 24,
  156. md: 24,
  157. lg: 9,
  158. xl: 7,
  159. xxl: 4,
  160. },
  161. schemas:
  162. props.formSchemas.length > 0
  163. ? props.formSchemas
  164. : [
  165. {
  166. field: 'starttime_begin',
  167. label: '开始时间',
  168. component: 'DatePicker',
  169. defaultValue: dayjs().startOf('date'),
  170. required: true,
  171. componentProps: {
  172. showTime: true,
  173. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  174. getPopupContainer: getAutoScrollContainer,
  175. },
  176. colProps: {
  177. span: 8,
  178. },
  179. },
  180. {
  181. field: 'starttime_end',
  182. label: '结束时间',
  183. component: 'DatePicker',
  184. defaultValue: dayjs(),
  185. required: true,
  186. componentProps: {
  187. showTime: true,
  188. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  189. getPopupContainer: getAutoScrollContainer,
  190. },
  191. colProps: {
  192. span: 8,
  193. },
  194. },
  195. {
  196. label: '连接状态',
  197. field: 'status',
  198. component: 'Select',
  199. defaultValue: 1,
  200. componentProps: {
  201. options: [
  202. { label: '连接成功', value: 1 },
  203. { label: '连接失败', value: 0 },
  204. ],
  205. },
  206. colProps: {
  207. span: 8,
  208. },
  209. },
  210. ],
  211. },
  212. // fetchSetting: {
  213. pagination: {
  214. current: 1,
  215. pageSize: 20,
  216. pageSizeOptions: ['10', '30', '50', '100'],
  217. showQuickJumper: false,
  218. },
  219. beforeFetch() {
  220. const newParams = { ...resetFormParam() };
  221. // debugger;
  222. return newParams;
  223. },
  224. },
  225. exportConfig: {
  226. name: '历史列表',
  227. url: postExportXlsUrl,
  228. },
  229. });
  230. //注册table数据
  231. const [registerTable, { reload, setLoading, getForm, setColumns, getPaginationRef, setPagination }] = tableContext;
  232. watchEffect(() => {
  233. if (historyTable.value && dataSource) {
  234. const data = dataSource.value || [];
  235. emit('change', data);
  236. }
  237. });
  238. onMounted(async () => {
  239. if (props.stationId) {
  240. nextTick(async () => {
  241. await getDataSource();
  242. });
  243. }
  244. });
  245. defineExpose({ setLoading });
  246. </script>
  247. <style scoped lang="less">
  248. @import '/@/design/theme.less';
  249. :deep(.@{ventSpace}-table-body) {
  250. height: auto !important;
  251. }
  252. :deep(.zxm-picker) {
  253. height: 30px !important;
  254. }
  255. .history-table {
  256. width: 100%;
  257. :deep(.jeecg-basic-table-form-container) {
  258. .@{ventSpace}-form {
  259. padding: 0 !important;
  260. border: none !important;
  261. margin-bottom: 0 !important;
  262. .@{ventSpace}-picker,
  263. .@{ventSpace}-select-selector {
  264. width: 100% !important;
  265. height: 100%;
  266. background: #00000017;
  267. border: 1px solid #b7b7b7;
  268. input,
  269. .@{ventSpace}-select-selection-item,
  270. .@{ventSpace}-picker-suffix {
  271. color: #fff;
  272. }
  273. .@{ventSpace}-select-selection-placeholder {
  274. color: #ffffffaa;
  275. }
  276. .@{ventSpace}-zxm-select-selection-item {
  277. color: #00000017 !important;
  278. }
  279. }
  280. }
  281. .@{ventSpace}-table-title {
  282. min-height: 0 !important;
  283. }
  284. }
  285. .pagination-box {
  286. display: flex;
  287. justify-content: flex-end;
  288. align-items: center;
  289. .page-num {
  290. border: 1px solid #0090d8;
  291. padding: 4px 8px;
  292. margin-right: 5px;
  293. color: #0090d8;
  294. }
  295. .btn {
  296. margin-right: 10px;
  297. }
  298. }
  299. }
  300. </style>
  301. <style lang="less" scoped>
  302. :deep(.zxm-picker-dropdown) {
  303. top: 50px !important;
  304. left: 5px !important;
  305. }
  306. </style>