|
@@ -756,53 +756,9 @@
|
|
|
allRows.push(newRow)
|
|
allRows.push(newRow)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // 按父子关系排序:父项在前,子项在对应的父项后面
|
|
|
|
|
- allRows.sort((a, b) => {
|
|
|
|
|
- // 先按orderNum排序父项
|
|
|
|
|
- if (a.isChild && !b.isChild) {
|
|
|
|
|
- // 如果a是子项,b是父项,需要检查a的父项是否在b之后
|
|
|
|
|
- const parentOfA = allRows.find(
|
|
|
|
|
- (item) => item.rowid === a.parentid || item.itemId === a.parentid
|
|
|
|
|
- )
|
|
|
|
|
- if (parentOfA && parentOfA.orderNum > b.orderNum) {
|
|
|
|
|
- return 1
|
|
|
|
|
- }
|
|
|
|
|
- return -1
|
|
|
|
|
- }
|
|
|
|
|
- if (!a.isChild && b.isChild) {
|
|
|
|
|
- // 如果a是父项,b是子项,需要检查b的父项是否在a之前
|
|
|
|
|
- const parentOfB = allRows.find(
|
|
|
|
|
- (item) => item.rowid === b.parentid || item.itemId === b.parentid
|
|
|
|
|
- )
|
|
|
|
|
- if (parentOfB && parentOfB.orderNum < a.orderNum) {
|
|
|
|
|
- return -1
|
|
|
|
|
- }
|
|
|
|
|
- return 1
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果都是父项或都是子项,按orderNum排序
|
|
|
|
|
- return (a.orderNum || 0) - (b.orderNum || 0)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 重新排序,确保子项紧跟在其对应的父项后面
|
|
|
|
|
- const sortedArray = []
|
|
|
|
|
- const parentItems = allRows.filter((item) => !item.isChild)
|
|
|
|
|
- const childItems = allRows.filter((item) => item.isChild)
|
|
|
|
|
-
|
|
|
|
|
- parentItems.forEach((parent) => {
|
|
|
|
|
- sortedArray.push(parent)
|
|
|
|
|
- // 找到并添加该父项的所有子项
|
|
|
|
|
- const relatedChildren = childItems.filter(
|
|
|
|
|
- (child) =>
|
|
|
|
|
- child.parentid === parent.rowid ||
|
|
|
|
|
- child.parentid === parent.itemId
|
|
|
|
|
- )
|
|
|
|
|
- // 子项按orderNum排序
|
|
|
|
|
- relatedChildren.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
|
|
|
|
|
- sortedArray.push(...relatedChildren)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- this.contentEditForm.fixedTable.fixedTables = sortedArray
|
|
|
|
|
|
|
+ // 使用统一的层次排序:父项在前,子项紧随其后
|
|
|
|
|
+ this.contentEditForm.fixedTable.fixedTables =
|
|
|
|
|
+ this.flattenHierarchy(allRows)
|
|
|
},
|
|
},
|
|
|
getFixedPreviewRowClass({ row }) {
|
|
getFixedPreviewRowClass({ row }) {
|
|
|
if (!row) return ''
|
|
if (!row) return ''
|
|
@@ -902,92 +858,9 @@
|
|
|
allRows.push(newRow)
|
|
allRows.push(newRow)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // 按父子关系排序:父项在前,子项在对应的父项后面
|
|
|
|
|
- // 1. 先创建一个映射表,方便通过ID查找父项
|
|
|
|
|
- const rowMap = new Map()
|
|
|
|
|
- const sortedArray = []
|
|
|
|
|
- const addedItems = new Set()
|
|
|
|
|
-
|
|
|
|
|
- // 深拷贝原始数据并过滤掉重复项
|
|
|
|
|
- const uniqueRows = allRows.reduce((acc, current) => {
|
|
|
|
|
- const isDuplicate = acc.some(
|
|
|
|
|
- (row) =>
|
|
|
|
|
- (row.rowid && current.rowid && row.rowid === current.rowid) ||
|
|
|
|
|
- (row.itemId && current.itemId && row.itemId === current.itemId)
|
|
|
|
|
- )
|
|
|
|
|
- if (!isDuplicate) {
|
|
|
|
|
- acc.push(JSON.parse(JSON.stringify(current)))
|
|
|
|
|
- }
|
|
|
|
|
- return acc
|
|
|
|
|
- }, [])
|
|
|
|
|
-
|
|
|
|
|
- // 填充映射表
|
|
|
|
|
- uniqueRows.forEach((row) => {
|
|
|
|
|
- if (row.rowid) rowMap.set(String(row.rowid), row)
|
|
|
|
|
- if (row.itemId) rowMap.set(String(row.itemId), row)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 先按orderNum排序所有父项
|
|
|
|
|
- const parentItems = uniqueRows.filter((item) => !item.isChild)
|
|
|
|
|
- parentItems.sort(
|
|
|
|
|
- (a, b) => (Number(a.orderNum) || 0) - (Number(b.orderNum) || 0)
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- // 递归添加父项及其子项的函数
|
|
|
|
|
- const addItemWithChildren = (item) => {
|
|
|
|
|
- // 确保项目ID唯一
|
|
|
|
|
- const itemIdKey = String(
|
|
|
|
|
- item.rowid || item.itemId || `temp_${Math.random()}`
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- // 如果已经添加过,则跳过
|
|
|
|
|
- if (addedItems.has(itemIdKey)) return
|
|
|
|
|
-
|
|
|
|
|
- // 添加当前项目
|
|
|
|
|
- sortedArray.push(item)
|
|
|
|
|
- addedItems.add(itemIdKey)
|
|
|
|
|
-
|
|
|
|
|
- // 找到并添加所有子项
|
|
|
|
|
- const children = uniqueRows.filter((child) => {
|
|
|
|
|
- if (child.isChild) {
|
|
|
|
|
- const childParentId = String(child.parentid)
|
|
|
|
|
- return (
|
|
|
|
|
- childParentId === String(item.rowid) ||
|
|
|
|
|
- childParentId === String(item.itemId)
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- return false
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 子项按orderNum排序
|
|
|
|
|
- children.sort(
|
|
|
|
|
- (a, b) => (Number(a.orderNum) || 0) - (Number(b.orderNum) || 0)
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- // 添加所有子项
|
|
|
|
|
- children.forEach((child) => addItemWithChildren(child))
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 遍历所有父项,添加父项及其子项
|
|
|
|
|
- parentItems.forEach((parent) => addItemWithChildren(parent))
|
|
|
|
|
-
|
|
|
|
|
- // 添加剩余的没有被添加的项目(应该很少,但作为兜底)
|
|
|
|
|
- uniqueRows.forEach((row) => {
|
|
|
|
|
- const itemIdKey = String(
|
|
|
|
|
- row.rowid || row.itemId || `temp_${Math.random()}`
|
|
|
|
|
- )
|
|
|
|
|
- if (!addedItems.has(itemIdKey)) {
|
|
|
|
|
- sortedArray.push(row)
|
|
|
|
|
- addedItems.add(itemIdKey)
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 最后,重新计算显示序号,确保序号连续且正确
|
|
|
|
|
- sortedArray.forEach((item, index) => {
|
|
|
|
|
- item.orderText = String(index + 1)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- this.contentEditForm.dynamicTable.dynamicTables = sortedArray
|
|
|
|
|
|
|
+ // 使用统一的层次排序:父项在前,子项紧随其后
|
|
|
|
|
+ this.contentEditForm.dynamicTable.dynamicTables =
|
|
|
|
|
+ this.flattenHierarchy(allRows)
|
|
|
},
|
|
},
|
|
|
// 字符串转对象数组
|
|
// 字符串转对象数组
|
|
|
stringToObjects(str) {
|
|
stringToObjects(str) {
|