Files
shanxia2.0/web-admin/src/utils/view-dialog-refresh.ts
T
2026-07-05 10:07:24 +08:00

36 lines
957 B
TypeScript

import type { Ref } from 'vue'
export function syncViewRowFromFlatList<T extends { id: string | number }>(
viewRow: Ref<T | null>,
list: T[]
) {
const current = viewRow.value
if (!current?.id) return
const updated = list.find(row => row.id === current.id)
if (updated) viewRow.value = updated
}
export function findNodeInTreeById<T extends { id: string | number; children?: T[] }>(
nodes: T[],
id: string | number
): T | undefined {
for (const node of nodes) {
if (node.id === id) return node
if (node.children?.length) {
const found = findNodeInTreeById(node.children, id)
if (found) return found
}
}
return undefined
}
export function syncViewRowFromTree<T extends { id: string | number; children?: T[] }>(
viewRow: Ref<T | null>,
roots: T[]
) {
const current = viewRow.value
if (!current?.id) return
const updated = findNodeInTreeById(roots, current.id)
if (updated) viewRow.value = updated
}