From 5dd5771d6297e84cd209824637b38a67641036a4 Mon Sep 17 00:00:00 2001 From: Kven <2955163637@qq.com> Date: Fri, 17 Jan 2025 16:10:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(pagination):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E9=80=BB=E8=BE=91=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构 usePagination 钩子,使用 ref 替代直接操作对象属性 - 优化多个组件中的分页相关代码,使用新的 pagination 结构 - 在 bulletin-card 组件中添加空状态卡片样式 - 调整 message-edit 组件,增加消息类型选择功能 - 修改 bulletins 接口,统一字段命名 --- src/api/bulletins.ts | 2 +- src/hooks/pagination.ts | 22 +++++-- src/views/iot/device/index.vue | 10 +-- src/views/iot/product/index.vue | 12 ++-- src/views/notification/bulletin/index.vue | 10 +-- .../notice/components/message-edit.vue | 29 ++++++++- src/views/notification/notice/index.vue | 10 +-- .../bulletin-card/components/card-wrap.vue | 3 + src/views/user/bulletin-card/index.vue | 64 +++++++++++++++++-- src/views/user/bulletins/index.vue | 16 ++--- src/views/user/messages/index.vue | 20 ++---- 11 files changed, 132 insertions(+), 66 deletions(-) diff --git a/src/api/bulletins.ts b/src/api/bulletins.ts index 0a04211..5e24402 100644 --- a/src/api/bulletins.ts +++ b/src/api/bulletins.ts @@ -1,6 +1,7 @@ import axios from 'axios'; export interface BulletinsRecord { + id?: number; title?: string; state?: number[]; top?: boolean; @@ -13,7 +14,6 @@ export interface BulletinsRecord { } export interface BulletinsList extends BulletinsRecord{ - id?: number; remark: string; createBy: string; content: string; diff --git a/src/hooks/pagination.ts b/src/hooks/pagination.ts index 026b82f..27ffdf3 100644 --- a/src/hooks/pagination.ts +++ b/src/hooks/pagination.ts @@ -1,16 +1,24 @@ +import { ref } from 'vue'; export default function usePagination(initValue = false) { - const pagination: any = { + interface Pagination { + page: number; + size: number; + current: number; + total: number; + } + + const pagination = ref({ page: 1, size: 10, current: 1, total: 0, - }; - const setPagination = (value: any) => { - pagination.page = value.page; - pagination.size = value.size; - pagination.current = value.current; - pagination.total = value.total; + }); + const setPagination = (value: Pagination) => { + pagination.value.page = value.page; + pagination.value.size = value.size; + pagination.value.current = value.current; + pagination.value.total = value.total; }; return { pagination, diff --git a/src/views/iot/device/index.vue b/src/views/iot/device/index.vue index 9261385..254e20c 100644 --- a/src/views/iot/device/index.vue +++ b/src/views/iot/device/index.vue @@ -307,21 +307,21 @@ // 查询 const search = () => { fetchData({ - ...pagination, + ...pagination.value, ...formModel.value, } as unknown as DeviceRecord); }; // 分页发生改变 const onPageChange = (current: number) => { - pagination.page = current; - pagination.current = current; + pagination.value.page = current; + pagination.value.current = current; search(); }; // 数据条数改变 const onSizeChange = (Size: number) => { - pagination.size = Size; + pagination.value.size = Size; search(); }; @@ -338,7 +338,7 @@ params: {id} }).href; router.push(url); - }; + } // 删除 const handleDelete = async (id: number) => { diff --git a/src/views/iot/product/index.vue b/src/views/iot/product/index.vue index 3414fe2..0ba1724 100644 --- a/src/views/iot/product/index.vue +++ b/src/views/iot/product/index.vue @@ -317,21 +317,21 @@ // 查询 const search = () => { fetchData({ - ...pagination, + ...pagination.value, ...formModel.value, } as unknown as ProductRecord); }; // 分页发生改变 const onPageChange = (current: number) => { - pagination.page = current; - pagination.current = current; + pagination.value.page = current; + pagination.value.current = current; search(); }; // 数据条数改变 const onSizeChange = (Size: number) => { - pagination.size = Size; + pagination.value.size = Size; search(); }; @@ -348,7 +348,7 @@ params: {id} }).href; router.push(url); - }; + } // 打开物模型 function openTsl(id:number): void{ @@ -357,7 +357,7 @@ params: {id} }).href; router.push(url); - }; + } // 删除 const handleDelete = async (id: number) => { diff --git a/src/views/notification/bulletin/index.vue b/src/views/notification/bulletin/index.vue index cb428ff..33ff281 100644 --- a/src/views/notification/bulletin/index.vue +++ b/src/views/notification/bulletin/index.vue @@ -365,7 +365,7 @@ // 查询 const search = () => { fetchData({ - ...pagination, + ...pagination.value, ...formModel.value, } as unknown as BulletinsRecord); selectedIds.value = []; @@ -373,8 +373,8 @@ // 分页发生改变 const onPageChange = (current: number) => { - pagination.page = current; - pagination.current = current; + pagination.value.page = current; + pagination.value.current = current; search(); }; // 时间范围 @@ -387,7 +387,7 @@ // 数据条数改变 const onSizeChange = (Size: number) => { - pagination.size = Size; + pagination.value.size = Size; search(); }; @@ -421,7 +421,7 @@ params: {id} }).href; router.push(url); - }; + } // 发布公告 const publishBulletin = async (data:number[]) => { diff --git a/src/views/notification/notice/components/message-edit.vue b/src/views/notification/notice/components/message-edit.vue index 57bbfa5..5887cce 100644 --- a/src/views/notification/notice/components/message-edit.vue +++ b/src/views/notification/notice/components/message-edit.vue @@ -38,6 +38,20 @@ @click="queryDeptTree" /> + + + (); const formData = ref({ + sms: false, + email: false, ...props.prem, }); const messageStore = useMessageStore(); @@ -291,6 +305,16 @@ ]); const selectedDepartmentMembers: any = ref([]); const renderData = ref([]); + const messageType = computed(() => [ + { + label: '消息', + value: 'MESSAGE', + }, + { + label: '通知', + value: 'NOTICE', + }, + ]); // 获取部门树 const getDeptTree = async () => { const res = await getAllDeptTree(1); @@ -395,6 +419,7 @@ if (!valid) { // 新增 if (props.isCreate) { + formData.value.html = true; // formData.value.username = formData.value.email; const res = await messageStore.createMessage(formData.value); if (res.status === 200) { diff --git a/src/views/notification/notice/index.vue b/src/views/notification/notice/index.vue index ab2a9ad..43e3162 100644 --- a/src/views/notification/notice/index.vue +++ b/src/views/notification/notice/index.vue @@ -251,7 +251,7 @@ // 查询 const search = () => { fetchData({ - ...pagination, + ...pagination.value, ...formModel.value, } as unknown as MessageRecord); selectedIds.value = []; @@ -259,9 +259,7 @@ // 分页发生改变 const onPageChange = (current: number) => { - setPagination({ - current, - }); + pagination.value.current = current; search(); }; // 时间范围 @@ -274,9 +272,7 @@ // 数据条数改变 const onSizeChange = (size: number) => { - setPagination({ - size, - }) + pagination.value.size = size; search(); }; diff --git a/src/views/user/bulletin-card/components/card-wrap.vue b/src/views/user/bulletin-card/components/card-wrap.vue index c3b7271..73eb930 100644 --- a/src/views/user/bulletin-card/components/card-wrap.vue +++ b/src/views/user/bulletin-card/components/card-wrap.vue @@ -7,6 +7,9 @@ + +
+ + + + + +
+
{ fetchData({ - ...pagination, + ...pagination.value, ...formModel.value, } as unknown as BulletinsRecord); }; // 分页发生改变 const onPageChange = (current: number) => { - setPagination({ - current, - }) + pagination.value.current = current; search(); }; // 数据条数改变 const onSizeChange = (total: number) => { - pagination.total = total; + pagination.value.total = total; + console.log(pagination.value.total); search(); }; @@ -193,7 +212,7 @@ }; - \ No newline at end of file diff --git a/src/views/user/bulletins/index.vue b/src/views/user/bulletins/index.vue index 8482a10..e9af925 100644 --- a/src/views/user/bulletins/index.vue +++ b/src/views/user/bulletins/index.vue @@ -78,7 +78,6 @@ :style="highlightRow" style="margin-bottom: 40px" :filter-icon-align-left="alignLeft" - @change="handleSortChange" @page-change="onPageChange" >