fix: menu tree

pull/5/MERGE
xingyu 2023-04-27 11:06:32 +08:00
parent 7e9b6f933e
commit 07e7587bf1
3 changed files with 27 additions and 27 deletions

View File

@ -32,8 +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 menuKeys = ref<number[]>([])
const menuHalfKeys = ref<number[]>([])
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 120,
@ -54,28 +54,19 @@ const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data
const res = await getRole(data.record.id)
const menuRes = await listRoleMenus(data.record.id)
res.roleId = data.record.id
res.menuIds = menuRes
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 = menuKeys.value.concat(menuHalfKeys.value)
setModalProps({ confirmLoading: true })
await assignRoleMenu(values)
await assignRoleMenu({
roleId: values.id,
menuIds: menuKeys.value.concat(menuHalfKeys.value)
})
closeModal()
emit('success')
} finally {
@ -83,4 +74,14 @@ async function handleSubmit() {
setModalProps({ confirmLoading: false })
}
}
function menuReset() {
menuKeys.value = []
menuHalfKeys.value = []
}
function menuCheck(checkedKeys, e) {
menuKeys.value = checkedKeys.checked as number[]
menuHalfKeys.value = e.halfCheckedKeys as number[]
}
</script>

View File

@ -123,7 +123,7 @@ export const formSchema: FormSchema[] = [
export const menuScopeFormSchema: FormSchema[] = [
{
label: '角色编号',
field: 'roleId',
field: 'id',
show: false,
component: 'Input'
},

View File

@ -55,22 +55,11 @@ 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()
@ -88,4 +77,14 @@ async function handleSubmit() {
setModalProps({ confirmLoading: false })
}
}
function menuReset() {
menuKeys.value = []
menuHalfKeys.value = []
}
function menuCheck(checkedKeys, e) {
menuKeys.value = checkedKeys as (string | number)[]
menuHalfKeys.value = e.halfCheckedKeys as (string | number)[]
}
</script>