From 28bbc32efb52fb10d51d2eb15304a01d1e202349 Mon Sep 17 00:00:00 2001 From: luozhun <2025254074@qq.com> Date: Fri, 15 Nov 2024 16:31:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(superManagement):=20=E6=8F=90=E5=8F=96?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=8D=95=E5=85=83=E6=A0=BC=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 ckProjectDetail 和 deductedDetail 函数中的合并单元格计算逻辑提取到单独的函数 calculationMergeSpan 中- 在 assessmentRecord/index.tsx 中添加 calculationMergeSpan 函数实现合并单元格计算 - 通过提取公共逻辑,提高代码复用性和可维护性 --- .../police/assessmentCriteria/index.ts | 31 +-------- .../police/assessmentRecord/index.tsx | 65 ++++++++++--------- 2 files changed, 36 insertions(+), 60 deletions(-) diff --git a/superManagement/src/views/unitManage/police/assessmentCriteria/index.ts b/superManagement/src/views/unitManage/police/assessmentCriteria/index.ts index e5813a9..8b1bd57 100644 --- a/superManagement/src/views/unitManage/police/assessmentCriteria/index.ts +++ b/superManagement/src/views/unitManage/police/assessmentCriteria/index.ts @@ -7,6 +7,7 @@ import {deleteDataModal, submitSimpleFormModal} from "@/components/tsx/ModalPro. import api from "@/axios"; import {message} from "ant-design-vue"; import {dictSelectNodes} from "@/config/dict.ts"; +import {calculationMergeSpan} from "@/views/unitManage/police/assessmentRecord"; export const saveOrUpdateCkProject = (params: SaveOrUpdateCkProjectParams = { name: '', @@ -62,35 +63,7 @@ export const deleteCkProjectById = (name: string, ckProjectId: string, callback: export const ckProjectDetail = async (ckProjectId: string): Promise => { const {data} = await api.get('/assessmentCriteria/ckProjectDetail', {ckProjectId}) - - const groupRowSpan: Record = {} - const itemRowSpan: Record = {} - - data.forEach((item, index) => { - //如果第一次没有值 - if (item.ckGroupId) { - if (!groupRowSpan[item.ckGroupId]) { - groupRowSpan[item.ckGroupId] = {count: 1, firstIndex: index} - } else { - groupRowSpan[item.ckGroupId].count++; - data[index].groupRowSpan = 0 - } - } - - if (item.ckItemId) { - if (!itemRowSpan[item.ckItemId]) { - itemRowSpan[item.ckItemId] = {count: 1, firstIndex: index} - } else { - itemRowSpan[item.ckItemId].count++; - data[index].itemRowSpan = 0 - } - } - }) - - Object.values(groupRowSpan).forEach(({count, firstIndex}) => data[firstIndex].groupRowSpan = count) - - Object.values(itemRowSpan).forEach(({count, firstIndex}) => data[firstIndex].itemRowSpan = count) - + calculationMergeSpan(data) return data } diff --git a/superManagement/src/views/unitManage/police/assessmentRecord/index.tsx b/superManagement/src/views/unitManage/police/assessmentRecord/index.tsx index 0a62bbe..029dcc4 100644 --- a/superManagement/src/views/unitManage/police/assessmentRecord/index.tsx +++ b/superManagement/src/views/unitManage/police/assessmentRecord/index.tsx @@ -5,37 +5,8 @@ import {Modal, Table} from "ant-design-vue"; export const deductedDetail = async (assessmentRecord: AssessmentRecordPagerVo) => { const {data} = await api.get('/assessmentRecord/deductedDetail', {assessmentRecordId: assessmentRecord.snowFlakeId}) - const groupRowSpan: Record = {} - const itemRowSpan: Record = {} - data.forEach((item, index) => { - //如果第一次没有值 - if (item.ckGroupId) { - if (!groupRowSpan[item.ckGroupId]) { - groupRowSpan[item.ckGroupId] = {count: 1, firstIndex: index} - } else { - groupRowSpan[item.ckGroupId].count++; - data[index].groupRowSpan = 0 - } - } - - if (item.ckItemId) { - if (!itemRowSpan[item.ckItemId]) { - itemRowSpan[item.ckItemId] = {count: 1, firstIndex: index} - } else { - itemRowSpan[item.ckItemId].count++; - data[index].itemRowSpan = 0 - } - } - }) - - Object.values(groupRowSpan).forEach(({count, firstIndex}) => { - data[firstIndex].groupRowSpan = count; - }) - - Object.values(itemRowSpan).forEach(({count, firstIndex}) => { - data[firstIndex].itemRowSpan = count; - }) + calculationMergeSpan(data) const ckProjectDetailTableColumns: ColumnsType = [ { @@ -99,5 +70,37 @@ export const deductedDetail = async (assessmentRecord: AssessmentRecordPagerVo) > }) - +} + +/** + * 计算合并数值 + * @param data + */ +export const calculationMergeSpan = (data: Record[]) => { + const groupRowSpan: Record = {} + const itemRowSpan: Record = {} + + data.forEach((item, index) => { + //如果第一次没有值 + if (item.ckGroupId) { + if (!groupRowSpan[item.ckGroupId]) { + groupRowSpan[item.ckGroupId] = {count: 1, firstIndex: index} + } else { + groupRowSpan[item.ckGroupId].count++; + data[index].groupRowSpan = 0 + } + } + + if (item.ckItemId) { + if (!itemRowSpan[item.ckItemId]) { + itemRowSpan[item.ckItemId] = {count: 1, firstIndex: index} + } else { + itemRowSpan[item.ckItemId].count++; + data[index].itemRowSpan = 0 + } + } + }) + + Object.values(groupRowSpan).forEach(({count, firstIndex}) => data[firstIndex].groupRowSpan = count) + Object.values(itemRowSpan).forEach(({count, firstIndex}) => data[firstIndex].itemRowSpan = count) }