fix: 用户管理默认选中顶部 部门

This commit is contained in:
秋帆
2024-05-02 12:48:52 +08:00
parent 2642862569
commit 99c37d7de4

View File

@@ -6,7 +6,15 @@
<a-input v-model="deptName" placeholder="请输入部门名称" allow-clear style="margin-bottom: 10px"> <a-input v-model="deptName" placeholder="请输入部门名称" allow-clear style="margin-bottom: 10px">
<template #prefix><icon-search /></template> <template #prefix><icon-search /></template>
</a-input> </a-input>
<a-tree ref="treeRef" :data="deptList" default-expand-all show-line block-node @select="handleSelectDept"> <a-tree
ref="treeRef"
:data="deptList"
:selected-keys="selectedKeys"
default-expand-all
show-line
block-node
@select="handleSelectDept"
>
</a-tree> </a-tree>
</a-col> </a-col>
<a-col :xs="24" :md="20" :lg="20" :xl="20" :xxl="20"> <a-col :xs="24" :md="20" :lg="20" :xl="20" :xxl="20">
@@ -113,7 +121,12 @@ import has from '@/utils/has'
import { DisEnableStatusList } from '@/constant/common' import { DisEnableStatusList } from '@/constant/common'
defineOptions({ name: 'SystemUser' }) defineOptions({ name: 'SystemUser' })
interface queryFormType {
description?: string
status?: number
deptId?: string
sort: ['createTime,desc']
}
const columns: TableInstanceColumns[] = [ const columns: TableInstanceColumns[] = [
{ {
title: '序号', title: '序号',
@@ -152,10 +165,7 @@ const columns: TableInstanceColumns[] = [
} }
] ]
const queryForm = reactive({ const queryForm = reactive<queryFormType>({
description: undefined,
status: undefined,
deptId: undefined,
sort: ['createTime,desc'] sort: ['createTime,desc']
}) })
@@ -165,7 +175,7 @@ const {
pagination, pagination,
search, search,
handleDelete handleDelete
} = useTable((p) => listUser({ ...queryForm, page: p.page, size: p.size }), { immediate: true }) } = useTable((p) => listUser({ ...queryForm, page: p.page, size: p.size }), { immediate: false })
// 重置 // 重置
const reset = () => { const reset = () => {
@@ -194,9 +204,14 @@ const { deptList, getDeptList } = useDept({
onSuccess: () => { onSuccess: () => {
nextTick(() => { nextTick(() => {
treeRef.value?.expandAll(true) treeRef.value?.expandAll(true)
queryForm.deptId = deptList.value[0]?.key as string
search()
}) })
} }
}) })
const selectedKeys = computed(() => {
return [queryForm.deptId ? queryForm.deptId : '']
})
watch(deptName, (val) => { watch(deptName, (val) => {
getDeptList(val) getDeptList(val)
}) })