| | |
| | | </div> |
| | | </div> |
| | | |
| | | <FormDiaLog ref="dialogRef" @success="getList" v-model="visible" v-if="visible" /> |
| | | <FormDiaLog ref="dialogRef" @success="handleFormSuccess" v-model="visible" v-if="visible" /> |
| | | <ShareDiaLog ref="shareDialogRef" @success="getList" v-model="shareVisible" v-if="shareVisible" /> |
| | | </basic-container> |
| | | </template> |
| | |
| | | const list = ref([]) |
| | | const total = ref(0) |
| | | const selectedIds = ref([]) |
| | | const selectedRows = ref([]) |
| | | const lastActionParentRow = ref(null) |
| | | const queryParamsRef = ref(null) |
| | | const dialogRef = ref(null) |
| | | const shareDialogRef = ref(null) |
| | |
| | | }) |
| | | const deptTree = ref([]) |
| | | const route = useRoute() |
| | | const treeResolveMap = new Map() |
| | | |
| | | provide('dictObj', dictObj) |
| | | provide('deptTree', deptTree) |
| | |
| | | } |
| | | |
| | | function handleAddChild(row) { |
| | | lastActionParentRow.value = row |
| | | visible.value = true |
| | | nextTick(() => { |
| | | dialogRef.value?.open({ mode: 'add', parent: row }) |
| | |
| | | cancelButtonClass: 'command-message-box-cancel', |
| | | }) |
| | | const ids = row ? row.id : selectedIds.value.join(',') |
| | | const rows = row ? [row] : selectedRows.value |
| | | await remove(ids) |
| | | saveOperationLog({ |
| | | requestUri: route.path, |
| | |
| | | }) |
| | | ElMessage.success('删除成功') |
| | | selectedIds.value = [] |
| | | getList() |
| | | selectedRows.value = [] |
| | | const parentIds = Array.from(new Set(rows.map(item => item.parentId).filter(Boolean))) |
| | | const hasRoot = rows.some(item => !item.parentId) |
| | | if (hasRoot) { |
| | | getList() |
| | | } |
| | | parentIds.forEach(parentId => refreshChildNodes(parentId)) |
| | | } |
| | | |
| | | function handleSelectionChange(rows) { |
| | | selectedIds.value = rows.map(item => item.id) |
| | | selectedRows.value = rows |
| | | } |
| | | |
| | | function getDictList() { |
| | |
| | | } |
| | | |
| | | function loadChildren(row, treeNode, resolve) { |
| | | treeResolveMap.set(row.id, { resolve, row }) |
| | | getChildLazyTree({ parentId: row.id }) |
| | | .then(res => { |
| | | resolve(res?.data?.data ?? []) |
| | | const children = res?.data?.data ?? [] |
| | | row.hasChildren = children.length > 0 |
| | | resolve(children) |
| | | }) |
| | | .catch(() => resolve([])) |
| | | .catch(() => { |
| | | row.hasChildren = false |
| | | resolve([]) |
| | | }) |
| | | } |
| | | |
| | | function refreshChildNodes(parentId) { |
| | | const cache = treeResolveMap.get(parentId) |
| | | if (!cache?.resolve) return |
| | | getChildLazyTree({ parentId }) |
| | | .then(res => { |
| | | const children = res?.data?.data ?? [] |
| | | if (cache.row) { |
| | | cache.row.hasChildren = children.length > 0 |
| | | } |
| | | cache.resolve(children) |
| | | }) |
| | | .catch(() => { |
| | | if (cache.row) { |
| | | cache.row.hasChildren = false |
| | | } |
| | | cache.resolve([]) |
| | | }) |
| | | } |
| | | |
| | | function handleFormSuccess(payload = {}) { |
| | | if (payload?.parentId) { |
| | | refreshChildNodes(payload.parentId) |
| | | if (payload.isAddChild && lastActionParentRow.value?.id === payload.parentId) { |
| | | lastActionParentRow.value.hasChildren = true |
| | | } |
| | | lastActionParentRow.value = null |
| | | return |
| | | } |
| | | lastActionParentRow.value = null |
| | | getList() |
| | | } |
| | | |
| | | onMounted(() => { |