diff --git a/src/views/system/role/RoleMenuModal.vue b/src/views/system/role/RoleMenuModal.vue index f5042b99..83fc3248 100644 --- a/src/views/system/role/RoleMenuModal.vue +++ b/src/views/system/role/RoleMenuModal.vue @@ -6,9 +6,9 @@ v-model:value="model[field]" :treeData="treeData" :fieldNames="{ title: 'name', key: 'id' }" - :checkStrictly="true" checkable toolbar + @check="menuCheck" title="菜单分配" /> @@ -32,6 +32,8 @@ const { t } = useI18n() const { createMessage } = useMessage() const emit = defineEmits(['success', 'register']) const treeData = ref([]) +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() diff --git a/src/views/system/tenantPackage/TenantPackageModal.vue b/src/views/system/tenantPackage/TenantPackageModal.vue index 3319bdeb..fac4766a 100644 --- a/src/views/system/tenantPackage/TenantPackageModal.vue +++ b/src/views/system/tenantPackage/TenantPackageModal.vue @@ -6,9 +6,9 @@ v-model:value="model[field]" :treeData="treeData" :fieldNames="{ title: 'name', key: 'id' }" - :checkStrictly="true" checkable toolbar + @check="menuCheck" title="菜单分配" /> @@ -32,6 +32,8 @@ const { createMessage } = useMessage() const emit = defineEmits(['success', 'register']) const isUpdate = ref(true) const treeData = ref([]) +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)