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 { FormExpose } from '@/components/Form'
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 * as TenantPackageApi from '@/api/system/tenantPackage'
import { listSimpleMenusApi } from '@/api/system/menu'
@ -21,11 +21,15 @@ const defaultProps = {
// ========== ==========
const menuOptions = ref([]) //
const treeRef = ref<InstanceType<typeof ElTree>>()
const treeNodeAll = ref(false)
// /
const handleCheckedTreeNodeAll = () => {
treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : [])
}
const getTree = async () => {
const res = await listSimpleMenusApi()
menuOptions.value = handleTree(res)
}
let menuCheckStrictly = true
const menuExpand = ref(false)
const menuNodeAll = ref(false)
@ -42,7 +46,6 @@ const formRef = ref<FormExpose>() // 表单 Ref
const actionType = ref('') //
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const menuParentId = ref()
//
const setDialogTile = (type: string) => {
@ -58,7 +61,6 @@ const handleCreate = () => {
unref(formRef)?.getElFormRef()?.resetFields()
//
unref(treeRef)?.setCheckedKeys([])
menuCheckStrictly = true
menuExpand.value = false
menuNodeAll.value = false
}
@ -69,13 +71,8 @@ const handleUpdate = async (row: any) => {
//
const res = await TenantPackageApi.getTenantPackageApi(row.id)
unref(formRef)?.setValues(res)
//
//
menuCheckStrictly = true
//
unref(treeRef)?.setCheckedKeys(res.menuIds)
// 使
menuCheckStrictly = false
}
//
const submitForm = async () => {
@ -163,20 +160,23 @@ onMounted(async () => {
<el-card class="box-card">
<template #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>
</template>
<!-- default-expand-all-->
<el-tree
ref="treeRef"
node-key="id"
v-model="menuParentId"
show-checkbox
:props="defaultProps"
:data="menuOptions"
show-checkbox
:check-strictly="menuCheckStrictly"
empty-text="加载菜单中..."
empty-text="加载中,请稍后"
/>
</el-card>
</template>