Commit 1335a7aef79de21832a4dff6fa35f91326d61147
1 parent
90db83e1
feat: add dept tree select
Showing
2 changed files
with
20 additions
and
9 deletions
yudao-ui-admin-vue3/src/views/system/dept/index.vue
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { useI18n } from '@/hooks/web/useI18n' | 2 | import { useI18n } from '@/hooks/web/useI18n' |
| 3 | -import { ElCard, ElTree, ElTreeSelect, ElMessage, ElMessageBox } from 'element-plus' | 3 | +import { ElInput, ElCard, ElTree, ElTreeSelect, ElMessage, ElMessageBox } from 'element-plus' |
| 4 | import { handleTree } from '@/utils/tree' | 4 | import { handleTree } from '@/utils/tree' |
| 5 | -import { onMounted, ref, unref } from 'vue' | 5 | +import { onMounted, ref, unref, watch } from 'vue' |
| 6 | import * as DeptApi from '@/api/system/dept' | 6 | import * as DeptApi from '@/api/system/dept' |
| 7 | import { Form, FormExpose } from '@/components/Form' | 7 | import { Form, FormExpose } from '@/components/Form' |
| 8 | import { modelSchema } from './dept.data' | 8 | import { modelSchema } from './dept.data' |
| @@ -28,6 +28,7 @@ const deptParentId = ref(0) // 上级ID | @@ -28,6 +28,7 @@ const deptParentId = ref(0) // 上级ID | ||
| 28 | const formRef = ref<FormExpose>() | 28 | const formRef = ref<FormExpose>() |
| 29 | 29 | ||
| 30 | // ========== 创建部门树结构 ========== | 30 | // ========== 创建部门树结构 ========== |
| 31 | +const filterText = ref('') | ||
| 31 | const deptOptions = ref([]) // 树形结构 | 32 | const deptOptions = ref([]) // 树形结构 |
| 32 | const treeRef = ref<InstanceType<typeof ElTree>>() | 33 | const treeRef = ref<InstanceType<typeof ElTree>>() |
| 33 | const getTree = async () => { | 34 | const getTree = async () => { |
| @@ -38,9 +39,13 @@ const filterNode = (value: string, data: Tree) => { | @@ -38,9 +39,13 @@ const filterNode = (value: string, data: Tree) => { | ||
| 38 | if (!value) return true | 39 | if (!value) return true |
| 39 | return data.name.includes(value) | 40 | return data.name.includes(value) |
| 40 | } | 41 | } |
| 42 | +watch(filterText, (val) => { | ||
| 43 | + treeRef.value!.filter(val) | ||
| 44 | +}) | ||
| 41 | // 新增 | 45 | // 新增 |
| 42 | -const handleAdd = () => { | 46 | +const handleAdd = (data: { id: number }) => { |
| 43 | // 重置表单 | 47 | // 重置表单 |
| 48 | + deptParentId.value = data.id | ||
| 44 | formTitle.value = '新增部门' | 49 | formTitle.value = '新增部门' |
| 45 | unref(formRef)?.getElFormRef()?.resetFields() | 50 | unref(formRef)?.getElFormRef()?.resetFields() |
| 46 | showForm.value = true | 51 | showForm.value = true |
| @@ -73,7 +78,7 @@ const submitForm = async () => { | @@ -73,7 +78,7 @@ const submitForm = async () => { | ||
| 73 | // 提交请求 | 78 | // 提交请求 |
| 74 | try { | 79 | try { |
| 75 | const data = unref(formRef)?.formModel as DeptVO | 80 | const data = unref(formRef)?.formModel as DeptVO |
| 76 | - deptParentId.value = data.parentId | 81 | + data.parentId = deptParentId.value |
| 77 | // TODO: 表单提交待完善 | 82 | // TODO: 表单提交待完善 |
| 78 | if (formTitle.value.startsWith('新增')) { | 83 | if (formTitle.value.startsWith('新增')) { |
| 79 | await DeptApi.createDeptApi(data) | 84 | await DeptApi.createDeptApi(data) |
| @@ -104,6 +109,7 @@ onMounted(async () => { | @@ -104,6 +109,7 @@ onMounted(async () => { | ||
| 104 | <div class="custom-tree-container"> | 109 | <div class="custom-tree-container"> |
| 105 | <!-- <p>部门列表</p> --> | 110 | <!-- <p>部门列表</p> --> |
| 106 | <!-- 操作工具栏 --> | 111 | <!-- 操作工具栏 --> |
| 112 | + <el-input v-model="filterText" placeholder="搜索部门" /> | ||
| 107 | <el-tree | 113 | <el-tree |
| 108 | ref="treeRef" | 114 | ref="treeRef" |
| 109 | node-key="id" | 115 | node-key="id" |
| @@ -111,13 +117,13 @@ onMounted(async () => { | @@ -111,13 +117,13 @@ onMounted(async () => { | ||
| 111 | :props="defaultProps" | 117 | :props="defaultProps" |
| 112 | :highlight-current="true" | 118 | :highlight-current="true" |
| 113 | default-expand-all | 119 | default-expand-all |
| 114 | - :filter-method="filterNode" | 120 | + :filter-node-method="filterNode" |
| 115 | > | 121 | > |
| 116 | <template #default="{ node, data }"> | 122 | <template #default="{ node, data }"> |
| 117 | <span class="custom-tree-node"> | 123 | <span class="custom-tree-node"> |
| 118 | <span>{{ node.label }}</span> | 124 | <span>{{ node.label }}</span> |
| 119 | <span> | 125 | <span> |
| 120 | - <el-button link v-hasPermi="['system:dept:create']" @click="handleAdd()"> | 126 | + <el-button link v-hasPermi="['system:dept:create']" @click="handleAdd(data)"> |
| 121 | <Icon icon="ep:plus" class="mr-5px" /> | 127 | <Icon icon="ep:plus" class="mr-5px" /> |
| 122 | </el-button> | 128 | </el-button> |
| 123 | <el-button link v-hasPermi="['system:dept:update']" @click="handleUpdate(data)"> | 129 | <el-button link v-hasPermi="['system:dept:update']" @click="handleUpdate(data)"> |
yudao-ui-admin-vue3/src/views/system/user/index.vue
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | -import { onMounted, ref, unref } from 'vue' | 2 | +import { onMounted, ref, unref, watch } from 'vue' |
| 3 | import dayjs from 'dayjs' | 3 | import dayjs from 'dayjs' |
| 4 | import { | 4 | import { |
| 5 | + ElInput, | ||
| 5 | ElMessage, | 6 | ElMessage, |
| 6 | ElCard, | 7 | ElCard, |
| 7 | ElTree, | 8 | ElTree, |
| @@ -55,6 +56,7 @@ const { register, tableObject, methods } = useTable<UserVO>({ | @@ -55,6 +56,7 @@ const { register, tableObject, methods } = useTable<UserVO>({ | ||
| 55 | const { getList, setSearchParams, delList, exportList } = methods | 56 | const { getList, setSearchParams, delList, exportList } = methods |
| 56 | 57 | ||
| 57 | // ========== 创建部门树结构 ========== | 58 | // ========== 创建部门树结构 ========== |
| 59 | +const filterText = ref('') | ||
| 58 | const deptOptions = ref([]) // 树形结构 | 60 | const deptOptions = ref([]) // 树形结构 |
| 59 | const searchForm = ref<FormExpose>() | 61 | const searchForm = ref<FormExpose>() |
| 60 | const treeRef = ref<InstanceType<typeof ElTree>>() | 62 | const treeRef = ref<InstanceType<typeof ElTree>>() |
| @@ -73,7 +75,9 @@ const handleDeptNodeClick = (data: { [key: string]: any }) => { | @@ -73,7 +75,9 @@ const handleDeptNodeClick = (data: { [key: string]: any }) => { | ||
| 73 | tableTitle.value = data.name | 75 | tableTitle.value = data.name |
| 74 | methods.getList() | 76 | methods.getList() |
| 75 | } | 77 | } |
| 76 | - | 78 | +watch(filterText, (val) => { |
| 79 | + treeRef.value!.filter(val) | ||
| 80 | +}) | ||
| 77 | // ========== CRUD 相关 ========== | 81 | // ========== CRUD 相关 ========== |
| 78 | const loading = ref(false) // 遮罩层 | 82 | const loading = ref(false) // 遮罩层 |
| 79 | const actionType = ref('') // 操作按钮的类型 | 83 | const actionType = ref('') // 操作按钮的类型 |
| @@ -265,6 +269,7 @@ getList() | @@ -265,6 +269,7 @@ getList() | ||
| 265 | <span>部门列表</span> | 269 | <span>部门列表</span> |
| 266 | </div> | 270 | </div> |
| 267 | </template> | 271 | </template> |
| 272 | + <el-input v-model="filterText" placeholder="搜索部门" /> | ||
| 268 | <el-tree | 273 | <el-tree |
| 269 | ref="treeRef" | 274 | ref="treeRef" |
| 270 | node-key="id" | 275 | node-key="id" |
| @@ -272,7 +277,7 @@ getList() | @@ -272,7 +277,7 @@ getList() | ||
| 272 | :data="deptOptions" | 277 | :data="deptOptions" |
| 273 | :props="defaultProps" | 278 | :props="defaultProps" |
| 274 | :highlight-current="true" | 279 | :highlight-current="true" |
| 275 | - :filter-method="filterNode" | 280 | + :filter-node-method="filterNode" |
| 276 | :expand-on-click-node="false" | 281 | :expand-on-click-node="false" |
| 277 | @node-click="handleDeptNodeClick" | 282 | @node-click="handleDeptNodeClick" |
| 278 | /> | 283 | /> |