Compare commits

..

2 Commits

Author SHA1 Message Date
luozhun 60c0f62aed Merge remote-tracking branch 'origin/main' 2024-11-15 16:31:09 +08:00
luozhun 28bbc32efb refactor(superManagement): 提取合并单元格计算逻辑
- 将 ckProjectDetail 和 deductedDetail 函数中的合并单元格计算逻辑提取到单独的函数 calculationMergeSpan 中- 在 assessmentRecord/index.tsx 中添加 calculationMergeSpan 函数实现合并单元格计算
- 通过提取公共逻辑,提高代码复用性和可维护性
2024-11-15 16:31:01 +08:00
2 changed files with 36 additions and 60 deletions

View File

@ -7,6 +7,7 @@ import {deleteDataModal, submitSimpleFormModal} from "@/components/tsx/ModalPro.
import api from "@/axios"; import api from "@/axios";
import {message} from "ant-design-vue"; import {message} from "ant-design-vue";
import {dictSelectNodes} from "@/config/dict.ts"; import {dictSelectNodes} from "@/config/dict.ts";
import {calculationMergeSpan} from "@/views/unitManage/police/assessmentRecord";
export const saveOrUpdateCkProject = (params: SaveOrUpdateCkProjectParams = { export const saveOrUpdateCkProject = (params: SaveOrUpdateCkProjectParams = {
name: '', name: '',
@ -62,35 +63,7 @@ export const deleteCkProjectById = (name: string, ckProjectId: string, callback:
export const ckProjectDetail = async (ckProjectId: string): Promise<CkProjectDetailRes[]> => { export const ckProjectDetail = async (ckProjectId: string): Promise<CkProjectDetailRes[]> => {
const {data} = await api.get<CkProjectDetailRes[]>('/assessmentCriteria/ckProjectDetail', {ckProjectId}) const {data} = await api.get<CkProjectDetailRes[]>('/assessmentCriteria/ckProjectDetail', {ckProjectId})
calculationMergeSpan(data)
const groupRowSpan: Record<string, { firstIndex: number, count: number }> = {}
const itemRowSpan: Record<string, { firstIndex: number, count: number }> = {}
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)
return data return data
} }

View File

@ -5,37 +5,8 @@ import {Modal, Table} from "ant-design-vue";
export const deductedDetail = async (assessmentRecord: AssessmentRecordPagerVo) => { export const deductedDetail = async (assessmentRecord: AssessmentRecordPagerVo) => {
const {data} = await api.get<DeductedDetailRes[]>('/assessmentRecord/deductedDetail', {assessmentRecordId: assessmentRecord.snowFlakeId}) const {data} = await api.get<DeductedDetailRes[]>('/assessmentRecord/deductedDetail', {assessmentRecordId: assessmentRecord.snowFlakeId})
const groupRowSpan: Record<string, { firstIndex: number, count: number }> = {}
const itemRowSpan: Record<string, { firstIndex: number, count: number }> = {}
data.forEach((item, index) => { calculationMergeSpan(data)
//如果第一次没有值
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;
})
const ckProjectDetailTableColumns: ColumnsType<DeductedDetailRes> = [ const ckProjectDetailTableColumns: ColumnsType<DeductedDetailRes> = [
{ {
@ -99,5 +70,37 @@ export const deductedDetail = async (assessmentRecord: AssessmentRecordPagerVo)
></Table> ></Table>
</div> </div>
}) })
}
/**
*
* @param data
*/
export const calculationMergeSpan = (data: Record<string, any>[]) => {
const groupRowSpan: Record<string, { firstIndex: number, count: number }> = {}
const itemRowSpan: Record<string, { firstIndex: number, count: number }> = {}
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)
} }