Commit 6000cf9a7a752b643e1036eeefba346096f3b3f9
1 parent
39cb4bc2
'修改首页顶部数据和ui,新增消息批量删除的功能,封装useBatchDelete批量删除的hook'
Showing
5 changed files
with
135 additions
and
84 deletions
src/hooks/web/useBatchDelete.ts
0 → 100644
1 | +import { ref, computed } from 'vue'; | |
2 | +import { useMessage } from '/@/hooks/web/useMessage'; | |
3 | +/** | |
4 | + * | |
5 | + * @param deleteFn 要删除的API接口方法 | |
6 | + * @param handleSuccess 刷新表格的方法 | |
7 | + * @returns { | |
8 | + * hasBatchDelete: 是否可以删除 | |
9 | + * selectionOptions 表格复选框配置项 | |
10 | + * handleDeleteOrBatchDelete 删除方法,适用单一删除和批量删除。参数为null为批量删除 | |
11 | + * } | |
12 | + * | |
13 | + */ | |
14 | +export interface selectionOptions { | |
15 | + rowKey: string; | |
16 | + clickToRowSelect: boolean; | |
17 | + rowSelection: { | |
18 | + onChange: (selectedRowKeys: string[]) => void; | |
19 | + type: 'radio' | 'checkbox'; | |
20 | + }; | |
21 | +} | |
22 | +export const useBatchDelete = ( | |
23 | + deleteFn: (deleteIds: string[]) => Promise<void>, | |
24 | + handleSuccess: () => void | |
25 | +) => { | |
26 | + const { createMessage } = useMessage(); | |
27 | + const selectedRowIds = ref<string[]>([]); | |
28 | + const hasBatchDelete = computed(() => selectedRowIds.value.length <= 0); | |
29 | + // 复选框事件 | |
30 | + const onSelectRowChange = (selectedRowKeys: string[]) => { | |
31 | + selectedRowIds.value = selectedRowKeys; | |
32 | + }; | |
33 | + const handleDeleteOrBatchDelete = async (record: Recordable | null) => { | |
34 | + if (record) { | |
35 | + try { | |
36 | + await deleteFn([record.id]); | |
37 | + createMessage.success('删除联系人成功'); | |
38 | + handleSuccess(); | |
39 | + } catch (e) { | |
40 | + createMessage.error('删除失败'); | |
41 | + } | |
42 | + } else { | |
43 | + try { | |
44 | + await deleteFn(selectedRowIds.value); | |
45 | + createMessage.success('批量删除联系人成功'); | |
46 | + selectedRowIds.value = []; | |
47 | + handleSuccess(); | |
48 | + } catch (e) { | |
49 | + createMessage.info('删除失败'); | |
50 | + } | |
51 | + } | |
52 | + }; | |
53 | + const selectionOptions: selectionOptions = { | |
54 | + rowKey: 'id', | |
55 | + clickToRowSelect: false, | |
56 | + rowSelection: { | |
57 | + onChange: onSelectRowChange, | |
58 | + type: 'checkbox', | |
59 | + }, | |
60 | + }; | |
61 | + return { hasBatchDelete, selectionOptions, handleDeleteOrBatchDelete }; | |
62 | +}; | ... | ... |
... | ... | @@ -45,6 +45,9 @@ |
45 | 45 | </div> |
46 | 46 | <div class="flex-auto"> |
47 | 47 | <div class="flex justify-between" style="align-items: center"> |
48 | + <div v-if="!isAdmin(role)" style="font-size: 1.625rem; color: #333">{{ | |
49 | + growCardList?.alarmInfo?.sumCount | |
50 | + }}</div> | |
48 | 51 | <div style="font-size: 1.625rem; color: #333">{{ |
49 | 52 | growCardList?.tenantInfo?.sumCount |
50 | 53 | }}</div> |
... | ... | @@ -53,7 +56,10 @@ |
53 | 56 | <div> {{ !isAdmin(role) ? `${currentMonth}月告警数(条)` : '租户总量(个)' }}</div> |
54 | 57 | </div> |
55 | 58 | </div> |
56 | - <div class="ml-2 pt-4" style="border-top: 2px solid #f0f2f5"> | |
59 | + <div v-if="!isAdmin(role)" class="ml-2 pt-4" style="border-top: 2px solid #f0f2f5"> | |
60 | + 今日新增 {{ growCardList?.alarmInfo?.todayAdd }}</div | |
61 | + > | |
62 | + <div v-else class="ml-2 pt-4" style="border-top: 2px solid #f0f2f5"> | |
57 | 63 | 今日新增 {{ growCardList?.tenantInfo?.todayAdd }}</div |
58 | 64 | > |
59 | 65 | </Card> |
... | ... | @@ -66,27 +72,40 @@ |
66 | 72 | style="width: 5rem; height: 5rem" |
67 | 73 | /><img v-else src="/src/assets/images/kf.png" style="width: 5rem; height: 5rem" /> |
68 | 74 | </div> |
69 | - <div style="display: flex; align-items: center"> | |
70 | - <div v-if="!isAdmin(role)"> | |
71 | - <div> | |
75 | + <div v-if="!isAdmin(role)" style="display: flex; align-items: center"> | |
76 | + <div> | |
77 | + <div class="flex" style="align-items: center"> | |
72 | 78 | {{ `${currentMonth}月数据点(条)` }} |
73 | - <span>{{ growCardList?.messageInfo?.dataPointsCount }}</span> | |
79 | + <span style="font-size: 1.625rem; color: #333"> | |
80 | + {{ growCardList?.messageInfo?.dataPointsCount }}</span | |
81 | + > | |
74 | 82 | </div> |
75 | - <div> | |
83 | + <div class="flex" style="align-items: center"> | |
76 | 84 | {{ `${currentMonth}月消息量(条)` }} |
77 | - <span>{{ growCardList?.messageInfo?.messageCount }}</span> | |
85 | + <span style="font-size: 1.625rem; color: #333"> | |
86 | + {{ growCardList?.messageInfo?.messageCount }}</span | |
87 | + > | |
78 | 88 | </div> |
79 | 89 | </div> |
80 | - <div v-else>客户总量(个)</div> | |
81 | 90 | </div> |
82 | - </div> | |
83 | - <div class="ml-2 pt-4" style="border-top: 2px solid #f0f2f5"> | |
84 | - <div> | |
85 | - 今日新增 | |
86 | - <span class="ml-8">数据点 ({{ growCardList?.messageInfo?.todayDataPointsAdd }})</span> | |
87 | - <span class="ml-8">消息量 ({{ growCardList?.messageInfo?.todayMessageAdd }})</span> | |
91 | + <div class="flex-auto" v-else> | |
92 | + <div class="flex justify-between" style="align-items: center"> | |
93 | + <div style="font-size: 1.625rem; color: #333">{{ | |
94 | + growCardList?.customerInfo?.sumCount | |
95 | + }}</div> | |
96 | + <img src="/src/assets/images/tip.png" style="width: 1.4rem; height: 1.4rem" /> | |
97 | + </div> | |
98 | + <div>客户总量(个)</div> | |
88 | 99 | </div> |
89 | 100 | </div> |
101 | + <div v-if="!isAdmin(role)" class="ml-2 pt-4" style="border-top: 2px solid #f0f2f5"> | |
102 | + 今日新增 | |
103 | + <span class="ml-8">数据点 ({{ growCardList?.messageInfo?.todayDataPointsAdd }})</span> | |
104 | + <span class="ml-8">消息量 ({{ growCardList?.messageInfo?.todayMessageAdd }})</span> | |
105 | + </div> | |
106 | + <div v-else class="ml-2 pt-4" style="border-top: 2px solid #f0f2f5"> | |
107 | + 今日新增 {{ growCardList?.customerInfo?.todayAdd }}</div | |
108 | + > | |
90 | 109 | </Card> |
91 | 110 | </div> |
92 | 111 | </template> | ... | ... |
src/views/message/records/data.ts
renamed from
src/views/message/records/data.tsx
... | ... | @@ -15,37 +15,3 @@ export const achieveList: TabItem[] = [ |
15 | 15 | component: 'EmailLog', |
16 | 16 | }, |
17 | 17 | ]; |
18 | - | |
19 | -export const actions: any[] = [ | |
20 | - { icon: 'clarity:star-line', text: '156', color: '#018ffb' }, | |
21 | - { icon: 'bx:bxs-like', text: '156', color: '#459ae8' }, | |
22 | - { icon: 'bx:bxs-message-dots', text: '2', color: '#42d27d' }, | |
23 | -]; | |
24 | - | |
25 | -export const articleList = (() => { | |
26 | - const result: any[] = []; | |
27 | - for (let i = 0; i < 4; i++) { | |
28 | - result.push({ | |
29 | - title: 'Vben Admin', | |
30 | - description: ['Vben', '设计语言', 'Typescript'], | |
31 | - content: '基于Vue Next, TypeScript, Ant Design实现的一套完整的企业级后台管理系统。', | |
32 | - time: '2020-11-14 11:20', | |
33 | - }); | |
34 | - } | |
35 | - return result; | |
36 | -})(); | |
37 | - | |
38 | -export const applicationList = (() => { | |
39 | - const result: any[] = []; | |
40 | - for (let i = 0; i < 8; i++) { | |
41 | - result.push({ | |
42 | - title: 'Vben Admin', | |
43 | - icon: 'emojione-monotone:letter-a', | |
44 | - color: '#1890ff', | |
45 | - active: '100', | |
46 | - new: '1,799', | |
47 | - download: 'bx:bx-download', | |
48 | - }); | |
49 | - } | |
50 | - return result; | |
51 | -})(); | ... | ... |
... | ... | @@ -3,6 +3,14 @@ |
3 | 3 | <BasicTable @register="registerTable"> |
4 | 4 | <template #toolbar> |
5 | 5 | <a-button type="primary" @click="handleCreate"> 导出 </a-button> |
6 | + <a-button | |
7 | + type="primary" | |
8 | + color="error" | |
9 | + @click="handleDeleteOrBatchDelete(null)" | |
10 | + :disabled="hasBatchDelete" | |
11 | + > | |
12 | + 批量删除 | |
13 | + </a-button> | |
6 | 14 | </template> |
7 | 15 | <template #action="{ record }"> |
8 | 16 | <TableAction |
... | ... | @@ -18,7 +26,7 @@ |
18 | 26 | color: 'error', |
19 | 27 | popConfirm: { |
20 | 28 | title: '是否确认删除', |
21 | - confirm: handleDelete.bind(null, record), | |
29 | + confirm: handleDeleteOrBatchDelete.bind(null, record), | |
22 | 30 | }, |
23 | 31 | }, |
24 | 32 | ]" |
... | ... | @@ -33,16 +41,19 @@ |
33 | 41 | import { BasicTable, useTable, TableAction } from '/@/components/Table'; |
34 | 42 | import { useDrawerInner } from '/@/components/Drawer'; |
35 | 43 | import { columns, searchFormSchema } from './email.data'; |
36 | - import { useMessage } from '/@/hooks/web/useMessage'; | |
37 | 44 | import { mailLogPage, deleteMailLog } from '/@/api/message/records'; |
38 | 45 | import { useModal } from '/@/components/Modal'; |
39 | 46 | import EmailDetail from '/@/views/message/records/item/EmailDetail.vue'; |
47 | + import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; | |
40 | 48 | export default defineComponent({ |
41 | 49 | name: 'EmailLog', |
42 | 50 | components: { EmailDetail, BasicTable, TableAction }, |
43 | 51 | setup() { |
44 | 52 | const [registerModal, { openModal }] = useModal(); |
45 | - const { createMessage } = useMessage(); | |
53 | + const { hasBatchDelete, selectionOptions, handleDeleteOrBatchDelete } = useBatchDelete( | |
54 | + deleteMailLog, | |
55 | + handleSuccess | |
56 | + ); | |
46 | 57 | const [register] = useDrawerInner(() => {}); |
47 | 58 | const [registerTable, { reload }] = useTable({ |
48 | 59 | title: '邮件发送列表', |
... | ... | @@ -64,7 +75,7 @@ |
64 | 75 | slots: { customRender: 'action' }, |
65 | 76 | fixed: 'right', |
66 | 77 | }, |
67 | - immediate: true, | |
78 | + ...selectionOptions, | |
68 | 79 | }); |
69 | 80 | |
70 | 81 | function handleCreate() {} |
... | ... | @@ -75,14 +86,6 @@ |
75 | 86 | }); |
76 | 87 | } |
77 | 88 | |
78 | - function handleDelete(record: Recordable) { | |
79 | - let ids = [record.id]; | |
80 | - deleteMailLog(ids).then((result) => { | |
81 | - createMessage.success(result.message); | |
82 | - handleSuccess(); | |
83 | - }); | |
84 | - } | |
85 | - | |
86 | 89 | function handleSuccess() { |
87 | 90 | reload(); |
88 | 91 | } |
... | ... | @@ -92,7 +95,8 @@ |
92 | 95 | registerTable, |
93 | 96 | registerModal, |
94 | 97 | handleCreate, |
95 | - handleDelete, | |
98 | + hasBatchDelete, | |
99 | + handleDeleteOrBatchDelete, | |
96 | 100 | handleModal, |
97 | 101 | handleSuccess, |
98 | 102 | }; | ... | ... |
... | ... | @@ -2,7 +2,15 @@ |
2 | 2 | <div style="background-color: #f0f2f5"> |
3 | 3 | <BasicTable @register="registerTable"> |
4 | 4 | <template #toolbar> |
5 | - <a-button type="primary" @click="handleCreate"> 导出 </a-button> | |
5 | + <a-button type="primary" @click="handleExport"> 导出 </a-button> | |
6 | + <a-button | |
7 | + type="primary" | |
8 | + color="error" | |
9 | + @click="handleDeleteOrBatchDelete(null)" | |
10 | + :disabled="hasBatchDelete" | |
11 | + > | |
12 | + 批量删除 | |
13 | + </a-button> | |
6 | 14 | </template> |
7 | 15 | <template #action="{ record }"> |
8 | 16 | <TableAction |
... | ... | @@ -18,7 +26,7 @@ |
18 | 26 | color: 'error', |
19 | 27 | popConfirm: { |
20 | 28 | title: '是否确认删除', |
21 | - confirm: handleDelete.bind(null, record), | |
29 | + confirm: handleDeleteOrBatchDelete.bind(null, record), | |
22 | 30 | }, |
23 | 31 | }, |
24 | 32 | ]" |
... | ... | @@ -29,21 +37,22 @@ |
29 | 37 | </template> |
30 | 38 | <script lang="ts"> |
31 | 39 | import { defineComponent, h } from 'vue'; |
32 | - | |
33 | 40 | import { BasicTable, useTable, TableAction } from '/@/components/Table'; |
34 | - import { useDrawerInner } from '/@/components/Drawer'; | |
35 | 41 | import { columns, searchFormSchema } from './sms.data'; |
36 | 42 | import { Modal } from 'ant-design-vue'; |
37 | - import { useMessage } from '/@/hooks/web/useMessage'; | |
38 | 43 | import { smsLogPage, deleteSmsLog } from '/@/api/message/records'; |
39 | 44 | import { JsonPreview } from '/@/components/CodeEditor'; |
45 | + import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; | |
40 | 46 | |
41 | 47 | export default defineComponent({ |
42 | 48 | name: 'SmsLog', |
43 | 49 | components: { BasicTable, TableAction }, |
44 | 50 | setup() { |
45 | - const { createMessage } = useMessage(); | |
46 | - const [register] = useDrawerInner(() => {}); | |
51 | + // 批量删除的hooks | |
52 | + const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete( | |
53 | + deleteSmsLog, | |
54 | + handleSuccess | |
55 | + ); | |
47 | 56 | const [registerTable, { reload }] = useTable({ |
48 | 57 | title: '短信发送列表', |
49 | 58 | api: smsLogPage, |
... | ... | @@ -64,10 +73,8 @@ |
64 | 73 | slots: { customRender: 'action' }, |
65 | 74 | fixed: 'right', |
66 | 75 | }, |
76 | + ...selectionOptions, | |
67 | 77 | }); |
68 | - | |
69 | - function handleCreate() {} | |
70 | - | |
71 | 78 | function handleQuery(record: Recordable) { |
72 | 79 | Modal.info({ |
73 | 80 | title: '当前配置', |
... | ... | @@ -75,26 +82,19 @@ |
75 | 82 | content: h(JsonPreview, { data: JSON.parse(JSON.stringify(record.templateParam)) }), |
76 | 83 | }); |
77 | 84 | } |
78 | - | |
79 | - function handleDelete(record: Recordable) { | |
80 | - let ids = [record.id]; | |
81 | - deleteSmsLog(ids).then((result) => { | |
82 | - createMessage.success(result.message); | |
83 | - handleSuccess(); | |
84 | - }); | |
85 | - } | |
86 | - | |
85 | + // 导出 TODO:待做 | |
86 | + const handleExport = () => {}; | |
87 | + // 刷新表格 | |
87 | 88 | function handleSuccess() { |
88 | 89 | reload(); |
89 | 90 | } |
90 | 91 | |
91 | 92 | return { |
92 | - register, | |
93 | + hasBatchDelete, | |
93 | 94 | registerTable, |
94 | - handleCreate, | |
95 | - handleDelete, | |
96 | - handleSuccess, | |
95 | + handleExport, | |
97 | 96 | handleQuery, |
97 | + handleDeleteOrBatchDelete, | |
98 | 98 | }; |
99 | 99 | }, |
100 | 100 | }); | ... | ... |