This commit is contained in:
zlwu committed 2026-08-27 14:23:18 +08:00
1 parent e56d227fe8
commit 4611dbc2b2
237 files changed
+1384060 -24942

No files matched your search

@@ -0,0 +1,65 @@
import { computed, unref, type ComputedRef, type Ref } from 'vue'
import type { Plan } from '@/api/pl'
import {
buildPlPlanListSpanMethod,
flattenPlanListRows,
getPlanListDisplayIndex,
type PlPlanListDisplayRow
} from '@/utils/pl-plan-list-display-rows'
export function usePlPlanMergeListTable(options: {
planList: Ref<Plan[]> | ComputedRef<Plan[]>
visiblePlanMergeProps: ComputedRef<string[]>
selectedRows: Ref<Plan[]>
pagination: { page: number; pageSize: number }
onView?: (plan: Plan) => void
}) {
const displayRows = computed(() => flattenPlanListRows(unref(options.planList)))
const planListSpanMethod = computed(() =>
buildPlPlanListSpanMethod([...options.visiblePlanMergeProps.value])
)
function getDisplayRowIndex(index: number) {
return getPlanListDisplayIndex(
displayRows.value,
index,
options.pagination.page,
options.pagination.pageSize
)
}
function isPlanFirstRowSelectable(row: PlPlanListDisplayRow) {
return row.isPlanFirstRow
}
function handleDisplaySelectionChange(selection: PlPlanListDisplayRow[]) {
const seen = new Set<string>()
const plans: Plan[] = []
for (const item of selection || []) {
const plan = item?.plan
if (!plan?.id || seen.has(plan.id)) continue
seen.add(plan.id)
plans.push(plan)
}
options.selectedRows.value = plans
}
function handleDisplayRowDblClick(row: PlPlanListDisplayRow) {
if (row?.plan && options.onView) options.onView(row.plan)
}
function findPlanFirstDisplayRow(planId: string) {
return displayRows.value.find((item) => item.plan.id === planId && item.isPlanFirstRow)
}
return {
displayRows,
planListSpanMethod,
getDisplayRowIndex,
isPlanFirstRowSelectable,
handleDisplaySelectionChange,
handleDisplayRowDblClick,
findPlanFirstDisplayRow
}
}