fix: menuTree check
parent
f3c8969719
commit
7e9b6f933e
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue