Commit 7d3c59af6d522c7300111a99ca68b23239840706
1 parent
27133e97
fix: tenantpackage tree
Showing
1 changed file
with
16 additions
and
16 deletions
yudao-ui-admin-vue3/src/views/system/tenantPackage/index.vue
| @@ -7,7 +7,7 @@ import { useTable } from '@/hooks/web/useTable' | @@ -7,7 +7,7 @@ import { useTable } from '@/hooks/web/useTable' | ||
| 7 | import { useI18n } from '@/hooks/web/useI18n' | 7 | import { useI18n } from '@/hooks/web/useI18n' |
| 8 | import { FormExpose } from '@/components/Form' | 8 | import { FormExpose } from '@/components/Form' |
| 9 | import { TenantPackageVO } from '@/api/system/tenantPackage/types' | 9 | import { TenantPackageVO } from '@/api/system/tenantPackage/types' |
| 10 | -import { ElMessage, ElCard, ElCheckbox, ElTree } from 'element-plus' | 10 | +import { ElMessage, ElCard, ElSwitch, ElTree } from 'element-plus' |
| 11 | import { rules, allSchemas } from './tenantPackage.data' | 11 | import { rules, allSchemas } from './tenantPackage.data' |
| 12 | import * as TenantPackageApi from '@/api/system/tenantPackage' | 12 | import * as TenantPackageApi from '@/api/system/tenantPackage' |
| 13 | import { listSimpleMenusApi } from '@/api/system/menu' | 13 | import { listSimpleMenusApi } from '@/api/system/menu' |
| @@ -21,11 +21,15 @@ const defaultProps = { | @@ -21,11 +21,15 @@ const defaultProps = { | ||
| 21 | // ========== 创建菜单树结构 ========== | 21 | // ========== 创建菜单树结构 ========== |
| 22 | const menuOptions = ref([]) // 树形结构 | 22 | const menuOptions = ref([]) // 树形结构 |
| 23 | const treeRef = ref<InstanceType<typeof ElTree>>() | 23 | const treeRef = ref<InstanceType<typeof ElTree>>() |
| 24 | +const treeNodeAll = ref(false) | ||
| 25 | +// 全选/全不选 | ||
| 26 | +const handleCheckedTreeNodeAll = () => { | ||
| 27 | + treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : []) | ||
| 28 | +} | ||
| 24 | const getTree = async () => { | 29 | const getTree = async () => { |
| 25 | const res = await listSimpleMenusApi() | 30 | const res = await listSimpleMenusApi() |
| 26 | menuOptions.value = handleTree(res) | 31 | menuOptions.value = handleTree(res) |
| 27 | } | 32 | } |
| 28 | -let menuCheckStrictly = true | ||
| 29 | const menuExpand = ref(false) | 33 | const menuExpand = ref(false) |
| 30 | const menuNodeAll = ref(false) | 34 | const menuNodeAll = ref(false) |
| 31 | 35 | ||
| @@ -42,7 +46,6 @@ const formRef = ref<FormExpose>() // 表单 Ref | @@ -42,7 +46,6 @@ const formRef = ref<FormExpose>() // 表单 Ref | ||
| 42 | const actionType = ref('') // 操作按钮的类型 | 46 | const actionType = ref('') // 操作按钮的类型 |
| 43 | const dialogVisible = ref(false) // 是否显示弹出层 | 47 | const dialogVisible = ref(false) // 是否显示弹出层 |
| 44 | const dialogTitle = ref('edit') // 弹出层标题 | 48 | const dialogTitle = ref('edit') // 弹出层标题 |
| 45 | -const menuParentId = ref() | ||
| 46 | 49 | ||
| 47 | // 设置标题 | 50 | // 设置标题 |
| 48 | const setDialogTile = (type: string) => { | 51 | const setDialogTile = (type: string) => { |
| @@ -58,7 +61,6 @@ const handleCreate = () => { | @@ -58,7 +61,6 @@ const handleCreate = () => { | ||
| 58 | unref(formRef)?.getElFormRef()?.resetFields() | 61 | unref(formRef)?.getElFormRef()?.resetFields() |
| 59 | //重置菜单树 | 62 | //重置菜单树 |
| 60 | unref(treeRef)?.setCheckedKeys([]) | 63 | unref(treeRef)?.setCheckedKeys([]) |
| 61 | - menuCheckStrictly = true | ||
| 62 | menuExpand.value = false | 64 | menuExpand.value = false |
| 63 | menuNodeAll.value = false | 65 | menuNodeAll.value = false |
| 64 | } | 66 | } |
| @@ -69,13 +71,8 @@ const handleUpdate = async (row: any) => { | @@ -69,13 +71,8 @@ const handleUpdate = async (row: any) => { | ||
| 69 | // 设置数据 | 71 | // 设置数据 |
| 70 | const res = await TenantPackageApi.getTenantPackageApi(row.id) | 72 | const res = await TenantPackageApi.getTenantPackageApi(row.id) |
| 71 | unref(formRef)?.setValues(res) | 73 | unref(formRef)?.setValues(res) |
| 72 | - // 设置菜单项 | ||
| 73 | - // 设置为严格,避免设置父节点自动选中子节点,解决半选中问题 | ||
| 74 | - menuCheckStrictly = true | ||
| 75 | // 设置选中 | 74 | // 设置选中 |
| 76 | unref(treeRef)?.setCheckedKeys(res.menuIds) | 75 | unref(treeRef)?.setCheckedKeys(res.menuIds) |
| 77 | - // 设置为非严格,继续使用半选中 | ||
| 78 | - menuCheckStrictly = false | ||
| 79 | } | 76 | } |
| 80 | // 提交按钮 | 77 | // 提交按钮 |
| 81 | const submitForm = async () => { | 78 | const submitForm = async () => { |
| @@ -163,20 +160,23 @@ onMounted(async () => { | @@ -163,20 +160,23 @@ onMounted(async () => { | ||
| 163 | <el-card class="box-card"> | 160 | <el-card class="box-card"> |
| 164 | <template #header> | 161 | <template #header> |
| 165 | <div class="card-header"> | 162 | <div class="card-header"> |
| 166 | - <el-checkbox>展开/折叠</el-checkbox> | ||
| 167 | - <el-checkbox>全选/全不选</el-checkbox> | 163 | + 全选/全不选: |
| 164 | + <el-switch | ||
| 165 | + v-model="treeNodeAll" | ||
| 166 | + inline-prompt | ||
| 167 | + active-text="是" | ||
| 168 | + inactive-text="否" | ||
| 169 | + @change="handleCheckedTreeNodeAll()" | ||
| 170 | + /> | ||
| 168 | </div> | 171 | </div> |
| 169 | </template> | 172 | </template> |
| 170 | - <!-- default-expand-all--> | ||
| 171 | <el-tree | 173 | <el-tree |
| 172 | ref="treeRef" | 174 | ref="treeRef" |
| 173 | node-key="id" | 175 | node-key="id" |
| 174 | - v-model="menuParentId" | 176 | + show-checkbox |
| 175 | :props="defaultProps" | 177 | :props="defaultProps" |
| 176 | :data="menuOptions" | 178 | :data="menuOptions" |
| 177 | - show-checkbox | ||
| 178 | - :check-strictly="menuCheckStrictly" | ||
| 179 | - empty-text="加载菜单中..." | 179 | + empty-text="加载中,请稍后" |
| 180 | /> | 180 | /> |
| 181 | </el-card> | 181 | </el-card> |
| 182 | </template> | 182 | </template> |