This commit is contained in:
2025-12-18 16:37:33 +08:00
commit e974bf361d
4183 changed files with 497339 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
//工程
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
}
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
}
})
export let dbSettings = {
data: mockData(),
dataSchema: rowSchema,
colWidths: 160,
columns: columns.value,
rowHeaders: false,
nestedRows: true,
bindRowsWithHeaders: true,
contextMenu: {
items: {
custom_row_above: {
name: '在上方插入行',
callback: function() {
handleRowOperation(this, 'above')
}
},
custom_row_below: {
name: '在下方插入行',
callback: function() {
handleRowOperation(this, 'below')
}
},
separator1: '---------',
custom_add_child: {
name: '添加子行',
callback: function() {
handleRowOperation(this, 'child')
}
},
separator2: '---------',
remove_row: {
name: '删除行',
callback: function() {
handleRowOperation(this, 'delete')
}
},
// separator3: '---------',
// undo: {},
// redo: {}
}
},
}