fix: tenantpackage tree

This commit is contained in:
xingyu 2022-08-01 19:50:43 +08:00
parent 27133e971b
commit 7d3c59af6d

View File

@ -7,7 +7,7 @@ import { useTable } from '@/hooks/web/useTable'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { FormExpose } from '@/components/Form' import { FormExpose } from '@/components/Form'
import { TenantPackageVO } from '@/api/system/tenantPackage/types' import { TenantPackageVO } from '@/api/system/tenantPackage/types'
import { ElMessage, ElCard, ElCheckbox, ElTree } from 'element-plus' import { ElMessage, ElCard, ElSwitch, ElTree } from 'element-plus'
import { rules, allSchemas } from './tenantPackage.data' import { rules, allSchemas } from './tenantPackage.data'
import * as TenantPackageApi from '@/api/system/tenantPackage' import * as TenantPackageApi from '@/api/system/tenantPackage'
import { listSimpleMenusApi } from '@/api/system/menu' import { listSimpleMenusApi } from '@/api/system/menu'
@ -21,11 +21,15 @@ const defaultProps = {
// ========== ========== // ========== ==========
const menuOptions = ref([]) // const menuOptions = ref([]) //
const treeRef = ref<InstanceType<typeof ElTree>>() const treeRef = ref<InstanceType<typeof ElTree>>()
const treeNodeAll = ref(false)
// /
const handleCheckedTreeNodeAll = () => {
treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : [])
}
const getTree = async () => { const getTree = async () => {
const res = await listSimpleMenusApi() const res = await listSimpleMenusApi()
menuOptions.value = handleTree(res) menuOptions.value = handleTree(res)
} }
let menuCheckStrictly = true
const menuExpand = ref(false) const menuExpand = ref(false)
const menuNodeAll = ref(false) const menuNodeAll = ref(false)
@ -42,7 +46,6 @@ const formRef = ref<FormExpose>() // 表单 Ref
const actionType = ref('') // const actionType = ref('') //
const dialogVisible = ref(false) // const dialogVisible = ref(false) //
const dialogTitle = ref('edit') // const dialogTitle = ref('edit') //
const menuParentId = ref()
// //
const setDialogTile = (type: string) => { const setDialogTile = (type: string) => {
@ -58,7 +61,6 @@ const handleCreate = () => {
unref(formRef)?.getElFormRef()?.resetFields() unref(formRef)?.getElFormRef()?.resetFields()
// //
unref(treeRef)?.setCheckedKeys([]) unref(treeRef)?.setCheckedKeys([])
menuCheckStrictly = true
menuExpand.value = false menuExpand.value = false
menuNodeAll.value = false menuNodeAll.value = false
} }
@ -69,13 +71,8 @@ const handleUpdate = async (row: any) => {
// //
const res = await TenantPackageApi.getTenantPackageApi(row.id) const res = await TenantPackageApi.getTenantPackageApi(row.id)
unref(formRef)?.setValues(res) unref(formRef)?.setValues(res)
//
//
menuCheckStrictly = true
// //
unref(treeRef)?.setCheckedKeys(res.menuIds) unref(treeRef)?.setCheckedKeys(res.menuIds)
// 使
menuCheckStrictly = false
} }
// //
const submitForm = async () => { const submitForm = async () => {
@ -163,20 +160,23 @@ onMounted(async () => {
<el-card class="box-card"> <el-card class="box-card">
<template #header> <template #header>
<div class="card-header"> <div class="card-header">
<el-checkbox>展开/折叠</el-checkbox> 全选/全不选:
<el-checkbox>全选/全不选</el-checkbox> <el-switch
v-model="treeNodeAll"
inline-prompt
active-text="是"
inactive-text="否"
@change="handleCheckedTreeNodeAll()"
/>
</div> </div>
</template> </template>
<!-- default-expand-all-->
<el-tree <el-tree
ref="treeRef" ref="treeRef"
node-key="id" node-key="id"
v-model="menuParentId" show-checkbox
:props="defaultProps" :props="defaultProps"
:data="menuOptions" :data="menuOptions"
show-checkbox empty-text="加载中,请稍后"
:check-strictly="menuCheckStrictly"
empty-text="加载菜单中..."
/> />
</el-card> </el-card>
</template> </template>