Showing
1 changed file
with
36 additions
and
138 deletions
1 | 1 | <script setup lang="ts"> |
2 | - import { Button, List, Space, Tooltip } from 'ant-design-vue'; | |
3 | - import { PageWrapper } from '/@/components/Page'; | |
4 | - import { BasicForm, useForm } from '/@/components/Form'; | |
2 | + import { Button } from 'ant-design-vue'; | |
5 | 3 | import { PermissionEnum, formSchemas } from './config'; |
6 | 4 | import { TaskCard } from './components/TaskCard'; |
7 | 5 | import { getTaskCenterList } from '/@/api/task'; |
8 | - import { ref, unref } from 'vue'; | |
9 | - import { onMounted } from 'vue'; | |
10 | 6 | import { DetailModal } from './components/DetailModal'; |
11 | 7 | import { useModal } from '/@/components/Modal'; |
12 | 8 | import { TaskRecordType } from '/@/api/task/model'; |
13 | - import { reactive } from 'vue'; | |
14 | - import { ReloadOutlined } from '@ant-design/icons-vue'; | |
15 | 9 | import { DataActionModeEnum } from '/@/enums/toolEnum'; |
16 | 10 | import { Authority } from '/@/components/Authority'; |
17 | - import { getBoundingClientRect } from '/@/utils/domUtils'; | |
18 | 11 | import { RunTaskModal } from './components/RunTaskModal'; |
19 | 12 | import { DetailDrawer } from './components/DetailDrawer'; |
20 | 13 | import { useDrawer } from '/@/components/Drawer'; |
14 | + import { BasicCardList, useCardList } from '/@/components/CardList'; | |
21 | 15 | |
22 | 16 | const [registerModal, { openModal }] = useModal(); |
23 | 17 | const [registerDrawer, { openDrawer }] = useDrawer(); |
24 | 18 | const [registerRunTaskModal, { openModal: openRunTaskModal }] = useModal(); |
25 | 19 | |
26 | - const [registerForm, { getFieldsValue }] = useForm({ | |
27 | - schemas: formSchemas, | |
28 | - baseColProps: { span: 8 }, | |
29 | - compact: true, | |
30 | - showAdvancedButton: true, | |
31 | - labelWidth: 100, | |
32 | - submitFunc: async () => { | |
33 | - getDataSource(); | |
20 | + const [registerCardList, { reload }] = useCardList({ | |
21 | + title: '任务列表', | |
22 | + api: getTaskCenterList, | |
23 | + baseLayout: { col: 4, row: 4 }, | |
24 | + useSearchForm: true, | |
25 | + formConfig: { | |
26 | + schemas: formSchemas, | |
27 | + labelWidth: 100, | |
28 | + baseColProps: { span: 8 }, | |
34 | 29 | }, |
35 | - resetFunc: async () => { | |
36 | - getDataSource({}); | |
30 | + beforeFetch: async (params: Recordable) => { | |
31 | + return { ...params }; | |
37 | 32 | }, |
38 | 33 | }); |
39 | 34 | |
40 | - const paginationChange = (page: number, pageSize: number) => { | |
41 | - pagination.current = page - 1 * pageSize > pagination.total ? 1 : page; | |
42 | - pagination.pageSize = pageSize; | |
43 | - getDataSource(); | |
44 | - }; | |
45 | - | |
46 | - const pagination = reactive({ | |
47 | - current: 1, | |
48 | - total: 0, | |
49 | - pageSize: 10, | |
50 | - size: 'small', | |
51 | - showSizeChanger: false, | |
52 | - showTotal: (total: number) => `共 ${total} 条数据`, | |
53 | - onChange: paginationChange, | |
54 | - onShowSizeChange: paginationChange, | |
55 | - }); | |
56 | - | |
57 | - const dataSource = ref<TaskRecordType[]>([]); | |
58 | - const loading = ref(false); | |
59 | - const getDataSource = async (params?: Recordable) => { | |
60 | - try { | |
61 | - loading.value = true; | |
62 | - params = params || getFieldsValue(); | |
63 | - const { items, total } = await getTaskCenterList({ | |
64 | - page: pagination.current, | |
65 | - pageSize: pagination.pageSize, | |
66 | - ...params, | |
67 | - }); | |
68 | - dataSource.value = items; | |
69 | - pagination.total = total; | |
70 | - } catch (error) { | |
71 | - throw error; | |
72 | - } finally { | |
73 | - loading.value = false; | |
74 | - } | |
75 | - }; | |
76 | - | |
77 | 35 | const handleEdit = (record: TaskRecordType) => { |
78 | 36 | openModal(true, { |
79 | 37 | record, |
... | ... | @@ -88,95 +46,35 @@ |
88 | 46 | const handleDetail = (record: TaskRecordType) => { |
89 | 47 | openDrawer(true, { mode: DataActionModeEnum.READ, record } as ModalParamsType); |
90 | 48 | }; |
91 | - | |
92 | - const reload = () => getDataSource(); | |
93 | - | |
94 | - const listElRef = ref<Nullable<ComponentElRef>>(null); | |
95 | - | |
96 | - const setListHeight = () => { | |
97 | - const clientHeight = document.documentElement.clientHeight; | |
98 | - const rect = getBoundingClientRect(unref(listElRef)!.$el!) as DOMRect; | |
99 | - // margin-top 24 height 24 | |
100 | - const paginationHeight = 24 + 24 + 8; | |
101 | - // list pading top 8 maring-top 8 extra slot 56 | |
102 | - const listContainerMarginBottom = 8 + 8 + 72; | |
103 | - const listContainerHeight = | |
104 | - clientHeight - rect.top - paginationHeight - listContainerMarginBottom; | |
105 | - const listContainerEl = (unref(listElRef)!.$el as HTMLElement).querySelector( | |
106 | - '.ant-spin-container' | |
107 | - ) as HTMLElement; | |
108 | - listContainerEl && | |
109 | - (listContainerEl.style.height = listContainerHeight + 'px') && | |
110 | - (listContainerEl.style.overflowY = 'auto') && | |
111 | - (listContainerEl.style.overflowX = 'hidden'); | |
112 | - }; | |
113 | - | |
114 | - onMounted(() => { | |
115 | - setListHeight(); | |
116 | - getDataSource(); | |
117 | - }); | |
118 | 49 | </script> |
119 | 50 | |
120 | 51 | <template> |
121 | - <PageWrapper class="task-center-container"> | |
122 | - <section | |
123 | - class="bg-light-50 flex p-4 justify-between items-center dark:text-gray-300 dark:bg-dark-900" | |
124 | - > | |
125 | - <div class="text-2xl">任务中心</div> | |
126 | - <Authority :value="PermissionEnum.CREATE"> | |
127 | - <Button | |
128 | - type="primary" | |
129 | - @click="openModal(true, { mode: DataActionModeEnum.CREATE } as ModalParamsType)" | |
130 | - > | |
131 | - 创建任务 | |
132 | - </Button> | |
133 | - </Authority> | |
134 | - </section> | |
135 | - <section | |
136 | - class="form-container bg-light-50 px-4 pt-4 mt-4 x dark:text-gray-300 dark:bg-dark-900" | |
137 | - > | |
138 | - <BasicForm @register="registerForm" /> | |
139 | - </section> | |
140 | - <section class="bg-light-50 mt-4 p-4 dark:text-gray-300 dark:bg-dark-900"> | |
141 | - <List | |
142 | - ref="listElRef" | |
143 | - :dataSource="dataSource" | |
144 | - :pagination="pagination" | |
145 | - :grid="{ gutter: 16, xs: 1, sm: 1, md: 2, lg: 3, xl: 3, xxl: 4, column: 4 }" | |
146 | - :loading="loading" | |
147 | - > | |
148 | - <template #header> | |
149 | - <section class="flex justify-between gap-4 min-h-12 items-center"> | |
150 | - <div> | |
151 | - <span class="text-lg font-medium">任务列表</span> | |
152 | - </div> | |
153 | - <Space> | |
154 | - <!-- <CardLayoutButton v-model:value="colNumber" :max="4" :min="1" @change="reload" /> --> | |
155 | - <Tooltip v-if="dataSource.length" title="刷新"> | |
156 | - <Button type="primary" @click="getDataSource"> | |
157 | - <ReloadOutlined :spin="loading" /> | |
158 | - </Button> | |
159 | - </Tooltip> | |
160 | - </Space> | |
161 | - </section> | |
162 | - </template> | |
163 | - <template #renderItem="{ item }"> | |
164 | - <List.Item :key="item.id"> | |
165 | - <TaskCard | |
166 | - :record="item" | |
167 | - :reload="reload" | |
168 | - @runTask="handleRunTask" | |
169 | - @detail="handleDetail" | |
170 | - @edit="handleEdit" | |
171 | - /> | |
172 | - </List.Item> | |
173 | - </template> | |
174 | - </List> | |
175 | - </section> | |
52 | + <section> | |
53 | + <BasicCardList class="flex-auto w-full" @register="registerCardList"> | |
54 | + <template #toolbar> | |
55 | + <Authority :value="PermissionEnum.CREATE"> | |
56 | + <Button | |
57 | + type="primary" | |
58 | + @click="openModal(true, { mode: DataActionModeEnum.CREATE } as ModalParamsType)" | |
59 | + > | |
60 | + 创建任务 | |
61 | + </Button> | |
62 | + </Authority> | |
63 | + </template> | |
64 | + <template #renderItem="{ item }"> | |
65 | + <TaskCard | |
66 | + :record="item" | |
67 | + :reload="reload" | |
68 | + @runTask="handleRunTask" | |
69 | + @detail="handleDetail" | |
70 | + @edit="handleEdit" | |
71 | + /> | |
72 | + </template> | |
73 | + </BasicCardList> | |
176 | 74 | <DetailDrawer @register="registerDrawer" /> |
177 | 75 | <DetailModal @register="registerModal" :reload="reload" /> |
178 | 76 | <RunTaskModal :reload="reload" @register="registerRunTaskModal" /> |
179 | - </PageWrapper> | |
77 | + </section> | |
180 | 78 | </template> |
181 | 79 | |
182 | 80 | <style lang="less" scoped> | ... | ... |