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