import type { Ref } from 'vue' type ColumnConfig = { type: 'text' data: string title: string width?: number readOnly?: boolean } type CreateSettingsDeps = { formulaInput: Ref } const createRowSchema = (columns: ColumnConfig[]) => { const schema: Record = {} columns.forEach((col) => { if (col.data) schema[col.data] = null }) return schema } const createMockRows = (count: number) => { return Array.from({ length: count }, (_, index) => { const rowNumber = index + 1 const rowText = String(rowNumber).padStart(3, '0') return { seq: String(rowNumber), code: `DW${rowText}`, name: `单位汇总费用${rowNumber}`, value: String((rowNumber * 6).toFixed(2)), } }) } export const createUnitSummarySettings = ({ formulaInput }: CreateSettingsDeps) => { const columns: ColumnConfig[] = [ { type: 'text', data: 'seq', title: '序号', width: 60, readOnly: true }, { type: 'text', data: 'name', title: '费用名称', width: 240, readOnly: true }, { type: 'text', data: 'code', title: '代号', width: 160, readOnly: true }, ] const allowedSelectionDataKeys = new Set(['code', 'value']) return { data: createMockRows(30), //dataSchema: createRowSchema(columns), colWidths: 150, height: 400, columns, rowHeaders: false, nestedRows: false, bindRowsWithHeaders: true, selectionMode: 'single', className: 'htCenter', afterSelection(row: number, col: number) { if (row < 0 || col < 0) return const selectedDataKey = columns?.[col]?.data if (!selectedDataKey || !allowedSelectionDataKeys.has(selectedDataKey)) return const cellValue = this.getDataAtCell(row, col) if (cellValue == null) return formulaInput.value += String(cellValue) }, } }