fix: menuTree check

pull/5/MERGE
xingyu 2023-04-27 10:40:01 +08:00
parent f3c8969719
commit 7e9b6f933e
2 changed files with 32 additions and 5 deletions

View File

@ -6,9 +6,9 @@
v-model:value="model[field]"
:treeData="treeData"
:fieldNames="{ title: 'name', key: 'id' }"
:checkStrictly="true"
checkable
toolbar
@check="menuCheck"
title="菜单分配"
/>
</template>
@ -32,6 +32,8 @@ const { t } = useI18n()
const { createMessage } = useMessage()
const emit = defineEmits(['success', 'register'])
const treeData = ref<TreeItem[]>([])
const menuKeys = ref<(string | number)[]>([])
const menuHalfKeys = ref<(string | number)[]>([])
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 120,
@ -43,6 +45,7 @@ const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
resetFields()
menuReset()
setModalProps({ confirmLoading: false })
if (unref(treeData).length === 0) {
const res = await listSimpleMenus()
@ -53,14 +56,24 @@ const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data
const menuRes = await listRoleMenus(data.record.id)
res.roleId = data.record.id
res.menuIds = menuRes
res.menuIds.checked = res.menuIds
menuKeys.value = res.menuIds
setFieldsValue({ ...res })
})
function menuCheck(checkedKeys, e) {
menuKeys.value = checkedKeys as (string | number)[]
menuHalfKeys.value = e.halfCheckedKeys as (string | number)[]
}
function menuReset() {
menuKeys.value = []
menuHalfKeys.value = []
}
async function handleSubmit() {
try {
const values = await validate()
values.menuIds = values.menuIds.checked
values.menuIds = menuKeys.value.concat(menuHalfKeys.value)
setModalProps({ confirmLoading: true })
await assignRoleMenu(values)
closeModal()

View File

@ -6,9 +6,9 @@
v-model:value="model[field]"
:treeData="treeData"
:fieldNames="{ title: 'name', key: 'id' }"
:checkStrictly="true"
checkable
toolbar
@check="menuCheck"
title="菜单分配"
/>
</template>
@ -32,6 +32,8 @@ const { createMessage } = useMessage()
const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true)
const treeData = ref<TreeItem[]>([])
const menuKeys = ref<(string | number)[]>([])
const menuHalfKeys = ref<(string | number)[]>([])
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 120,
@ -43,6 +45,7 @@ const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
resetFields()
menuReset()
setModalProps({ confirmLoading: false })
if (unref(treeData).length === 0) {
const res = await listSimpleMenus()
@ -53,14 +56,25 @@ const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data
if (unref(isUpdate)) {
const res = await getTenantPackage(data.record.id)
res.menuIds.checked = res.menuIds
menuKeys.value = res.menuIds
setFieldsValue({ ...res })
}
})
function menuCheck(checkedKeys, e) {
menuKeys.value = checkedKeys as (string | number)[]
menuHalfKeys.value = e.halfCheckedKeys as (string | number)[]
}
function menuReset() {
menuKeys.value = []
menuHalfKeys.value = []
}
async function handleSubmit() {
try {
const values = await validate()
values.menuIds = values.menuIds.checked
values.menuIds = menuKeys.value.concat(menuHalfKeys.value)
setModalProps({ confirmLoading: true })
if (unref(isUpdate)) {
await updateTenantPackage(values)