From 5039edd8820f66ae3efbd2687aacb04a90bf119d Mon Sep 17 00:00:00 2001 From: jiangjunhong <870160034@qq.com> Date: Fri, 25 Apr 2025 17:53:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=BF=E7=B4=A2=E7=AE=A1=E7=90=86=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E6=B7=BB=E5=8A=A0=E4=B8=8A=E4=B8=80=E4=B8=AA=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/auto-components.d.ts | 2 +- src/utils/crm.ts | 34 ++++++++++++++++++++++++++++++++++ src/views/crm/cule/index.vue | 31 ++++++++++++++----------------- 3 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 src/utils/crm.ts diff --git a/src/types/auto-components.d.ts b/src/types/auto-components.d.ts index d975f696..c330b42b 100644 --- a/src/types/auto-components.d.ts +++ b/src/types/auto-components.d.ts @@ -38,7 +38,7 @@ declare module 'vue' { CopyTaskNode: typeof import('./../components/SimpleProcessDesignerV2/src/nodes/CopyTaskNode.vue')['default'] CopyTaskNodeConfig: typeof import('./../components/SimpleProcessDesignerV2/src/nodes-config/CopyTaskNodeConfig.vue')['default'] CountTo: typeof import('./../components/CountTo/src/CountTo.vue')['default'] - Crm: typeof import('./../store/modules/crm.ts')['default'] + Crm: typeof import('./../utils/crm.ts')['default'] Crontab: typeof import('./../components/Crontab/src/Crontab.vue')['default'] Cropper: typeof import('./../components/Cropper/src/Cropper.vue')['default'] CropperAvatar: typeof import('./../components/Cropper/src/CropperAvatar.vue')['default'] diff --git a/src/utils/crm.ts b/src/utils/crm.ts new file mode 100644 index 00000000..954ce940 --- /dev/null +++ b/src/utils/crm.ts @@ -0,0 +1,34 @@ +interface HandlePrevNextOptions { + list: any[] + currentId: number + onUpdateIds: (params: { currentId: number; prevId: number; nextId: number }) => void +} + +/** + * 处理客户详情的上一条/下一条切换 + * @param type 切换类型:'prev' - 上一条 | 'next' - 下一条 + * @param options 配置选项 + * - list: 数据列表 + * - currentId: 当前查看的ID + * - onUpdateIds: ID更新后的回调函数 + */ +export const handlePrevNext = (type: 'prev' | 'next', options: HandlePrevNextOptions): void => { + const { list, currentId, onUpdateIds } = options + + // 找到当前记录在列表中的索引 + const currentIndex = list.findIndex(item => item.id === currentId) + + // 根据类型确定要切换到的索引 + const targetIndex = type === 'prev' ? currentIndex - 1 : currentIndex + 1 + + // 检查目标索引是否有效 + if (targetIndex >= 0 && targetIndex < list.length) { + const targetId = list[targetIndex].id + // 更新ID + onUpdateIds({ + currentId: targetId, + prevId: targetIndex > 0 ? list[targetIndex - 1].id : 0, + nextId: targetIndex < list.length - 1 ? list[targetIndex + 1].id : 0 + }) + } +} \ No newline at end of file diff --git a/src/views/crm/cule/index.vue b/src/views/crm/cule/index.vue index 287ea57d..1443971d 100644 --- a/src/views/crm/cule/index.vue +++ b/src/views/crm/cule/index.vue @@ -212,8 +212,8 @@ :customer-id="customerId" :prev-id="prevId" :next-id="nextId" - @prev="handlePrevNext('prev')" - @next="handlePrevNext('next')" + @prev="handlePrevNextClick('prev')" + @next="handlePrevNextClick('next')" /> @@ -226,6 +226,7 @@ \ No newline at end of file