工料机、定额基价、定额费率、定额取费

This commit is contained in:
2026-01-03 14:59:45 +08:00
parent e974bf361d
commit 618bb6699e
65 changed files with 13251 additions and 2624 deletions

View File

@@ -1,75 +1,47 @@
//工程
import { ref } from 'vue'
import { handleRowOperation, codeRenderer } from '#/components/db-hst/tree'
const columns = ref<any[]>([
{type:'text',data:'code',title:'编号',renderer: codeRenderer},
{type:'text',data:'name',title:'名称'},
{type:'text',data:'unit',title:'单位', width: 50},
])
const mockData = ()=>{
const mockData = []
let codeCounter = 1
// 生成5个父级工程项目
for (let i = 0; i < 5; i++) {
const parentCode = `PRJ${String(codeCounter++).padStart(2, '0')}`
const parent = {
code: parentCode,
name: `工程分类${i + 1}`,
unit: ['项', 'm³', 'm²', 't', '套'][i % 5],
level: String(i),
__children: []
}
// 为每个父级生成2-4个子项
const childCount = Math.floor(Math.random() * 3) + 2
for (let j = 0; j < childCount; j++) {
const childCode = `${parentCode}-${String(j + 1).padStart(3, '0')}`
const child = {
code: childCode,
name: `${parent.name}-子项${j + 1}`,
unit: ['m³', 'm²', 't', '套', '台'][j % 5],
level: `${i}-${j + 1}`,
__children: []
}
// 为部分子项生成孙项
if (j === 0 && i < 3) {
const grandChildCount = Math.floor(Math.random() * 2) + 1
for (let k = 0; k < grandChildCount; k++) {
const grandChild = {
code: `${childCode}-${String(k + 1).padStart(2, '0')}`,
name: `${child.name}-明细${k + 1}`,
unit: ['m³', 'm²', 't', 'kg', '个'][k % 5],
level: `${i}-${j + 1}-${k + 1}`,
__children: []
}
child.__children.push(grandChild)
}
}
parent.__children.push(child)
}
mockData.push(parent)
}
return mockData
import { ref, nextTick } from 'vue'
import type { Ref } from 'vue'
import { useParentChildLineNestedRowsFalse } from '#/components/db-hst/nestedRows'
// 用于存储 projectHstRef 的引用
let projectHstRef: Ref<any> | null = null
const selectedRow = ref<any>(null) // 记录当前选中的行
// 回调函数,供 config.vue 使用
let onCellMouseDownCallback: ((row: number | null) => void) | null = null
// 初始化函数,由 config.vue 调用
export function initProjectHst(hstRef: Ref<any>, callback?: (row: number | null) => void) {
projectHstRef = hstRef
onCellMouseDownCallback = callback || null
}
let rowSchema: any = {level: null, __children: []}
// 根据 columns 的 data 字段生成对象结构
columns.value.forEach((col: any) => {
if (col.data && col.data !== 'level' && col.data !== '__children') {
rowSchema[col.data] = null
}
const { load: originalLoad, codeRenderer, handleRowOperation, initSchema, highlightDeselect } = useParentChildLineNestedRowsFalse({
getHotInstance: () => projectHstRef?.value?.hotInstance,
})
// 包装 load 函数,在加载前重置选中行
export function load(data: any[]) {
selectedRow.value = null
return originalLoad(data)
}
const columns:any[] = [
{type:'text',data:'number',title:'序号', width: 50, className: 'htCenter'},
{type:'text',data:'code',title:'编号',renderer: codeRenderer, code:true},
{type:'text',data:'name',title:'名称'},
{type:'text',data:'unit',title:'单位', width: 60, className: 'htCenter'},
{type:'text',data:'text1',title:'编码增加数', width: 100},
{type:'text',data:'text2',title:'尾节点', width: 100},
{type:'text',data:'text3',title:'子目编码增加数', width: 110},
]
export let dbSettings = {
data: mockData(),
dataSchema: rowSchema,
data: [],
dataSchema: initSchema(columns),
colWidths: 160,
columns: columns.value,
columns: columns,
rowHeaders: false,
nestedRows: true,
nestedRows: false,
bindRowsWithHeaders: true,
contextMenu: {
items: {
@@ -104,5 +76,37 @@ export let dbSettings = {
// redo: {}
}
},
currentRowClassName: 'row-highlight',
beforeOnCellMouseDown(event: MouseEvent, coords: any, TD: HTMLTableCellElement){
// 只能单击
if (event.button !== 0) {
return // 直接返回,不执行后续逻辑
}
selectedRow.value = coords
// 触发回调函数
if (onCellMouseDownCallback) {
onCellMouseDownCallback(selectedRow.value)
}
},
afterDeselect(){
highlightDeselect(this, selectedRow.value)
}
}
// 定义 topHstRef 的自定义右键菜单
export const contextMenuItems = [
{
key: 'row_above',
name: '新增行',
callback: (hotInstance: any) => {
// 执行新增行操作
handleRowOperation(hotInstance, 'append')
// 等待 DOM 更新后重新渲染以应用验证样式
nextTick(() => {
hotInstance.render()
})
}
},
]