fix: 修改数据权限或者菜单权限失败 #I6Y6L4
parent
119c70835b
commit
6f6f0cea1c
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit">
|
<BasicModal v-bind="$attrs" @register="registerModal" title="修改角色菜单权限" @ok="handleSubmit">
|
||||||
<BasicForm @register="registerForm">
|
<BasicForm @register="registerForm">
|
||||||
<template #menuIds="{ model, field }">
|
<template #menuIds="{ model, field }">
|
||||||
<BasicTree
|
<BasicTree
|
||||||
|
@ -20,14 +20,13 @@ import { ref, unref } from 'vue'
|
||||||
import { BasicModal, useModalInner } from '@/components/Modal'
|
import { BasicModal, useModalInner } from '@/components/Modal'
|
||||||
import { BasicForm, useForm } from '@/components/Form'
|
import { BasicForm, useForm } from '@/components/Form'
|
||||||
import { menuScopeFormSchema } from './role.data'
|
import { menuScopeFormSchema } from './role.data'
|
||||||
import { createRole, getRole, updateRole } from '@/api/system/role'
|
import { getRole } from '@/api/system/role'
|
||||||
import { BasicTree, TreeItem } from '@/components/Tree'
|
import { BasicTree, TreeItem } from '@/components/Tree'
|
||||||
import { listSimpleMenus } from '@/api/system/menu'
|
import { listSimpleMenus } from '@/api/system/menu'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree } from '@/utils/tree'
|
||||||
import { listRoleMenus } from '@/api/system/permission'
|
import { assignRoleMenu, listRoleMenus } from '@/api/system/permission'
|
||||||
|
|
||||||
const emit = defineEmits(['success', 'register'])
|
const emit = defineEmits(['success', 'register'])
|
||||||
const isUpdate = ref(true)
|
|
||||||
const treeData = ref<TreeItem[]>([])
|
const treeData = ref<TreeItem[]>([])
|
||||||
|
|
||||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
|
@ -45,25 +44,18 @@ const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data
|
||||||
const res = await listSimpleMenus()
|
const res = await listSimpleMenus()
|
||||||
treeData.value = handleTree(res, 'id')
|
treeData.value = handleTree(res, 'id')
|
||||||
}
|
}
|
||||||
isUpdate.value = !!data?.isUpdate
|
|
||||||
|
|
||||||
if (unref(isUpdate)) {
|
const res = await getRole(data.record.id)
|
||||||
const res = await getRole(data.record.id)
|
const menuRes = await listRoleMenus(data.record.id)
|
||||||
const menuRes = await listRoleMenus(data.record.id)
|
res.menuIds = menuRes
|
||||||
res.menuIds = menuRes
|
setFieldsValue({ ...res })
|
||||||
setFieldsValue({ ...res })
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
try {
|
try {
|
||||||
const values = await validate()
|
const values = await validate()
|
||||||
setModalProps({ confirmLoading: true })
|
setModalProps({ confirmLoading: true })
|
||||||
if (unref(isUpdate)) {
|
await assignRoleMenu(values)
|
||||||
await updateRole(values)
|
|
||||||
} else {
|
|
||||||
await createRole(values)
|
|
||||||
}
|
|
||||||
closeModal()
|
closeModal()
|
||||||
emit('success')
|
emit('success')
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit">
|
<BasicModal v-bind="$attrs" @register="registerModal" title="编辑角色数据权限" @ok="handleSubmit">
|
||||||
<BasicForm @register="registerForm">
|
<BasicForm @register="registerForm">
|
||||||
<template #dataScopeDeptIds="{ model, field }">
|
<template #dataScopeDeptIds="{ model, field }">
|
||||||
<BasicTree
|
<BasicTree
|
||||||
|
@ -21,12 +21,12 @@ import { BasicModal, useModalInner } from '@/components/Modal'
|
||||||
import { BasicForm, useForm } from '@/components/Form'
|
import { BasicForm, useForm } from '@/components/Form'
|
||||||
import { BasicTree, TreeItem } from '@/components/Tree'
|
import { BasicTree, TreeItem } from '@/components/Tree'
|
||||||
import { dataScopeFormSchema } from './role.data'
|
import { dataScopeFormSchema } from './role.data'
|
||||||
import { createRole, getRole, updateRole } from '@/api/system/role'
|
import { getRole } from '@/api/system/role'
|
||||||
import { listSimpleDept } from '@/api/system/dept'
|
import { listSimpleDept } from '@/api/system/dept'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree } from '@/utils/tree'
|
||||||
|
import { assignRoleDataScope } from '@/api/system/permission'
|
||||||
|
|
||||||
const emit = defineEmits(['success', 'register'])
|
const emit = defineEmits(['success', 'register'])
|
||||||
const isUpdate = ref(true)
|
|
||||||
const treeData = ref<TreeItem[]>([])
|
const treeData = ref<TreeItem[]>([])
|
||||||
|
|
||||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
|
@ -44,23 +44,15 @@ const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data
|
||||||
const res = await listSimpleDept()
|
const res = await listSimpleDept()
|
||||||
treeData.value = handleTree(res, 'id')
|
treeData.value = handleTree(res, 'id')
|
||||||
}
|
}
|
||||||
isUpdate.value = !!data?.isUpdate
|
const res = await getRole(data.record.id)
|
||||||
|
setFieldsValue({ ...res })
|
||||||
if (unref(isUpdate)) {
|
|
||||||
const res = await getRole(data.record.id)
|
|
||||||
setFieldsValue({ ...res })
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
try {
|
try {
|
||||||
const values = await validate()
|
const values = await validate()
|
||||||
setModalProps({ confirmLoading: true })
|
setModalProps({ confirmLoading: true })
|
||||||
if (unref(isUpdate)) {
|
await assignRoleDataScope(values)
|
||||||
await updateRole(values)
|
|
||||||
} else {
|
|
||||||
await createRole(values)
|
|
||||||
}
|
|
||||||
closeModal()
|
closeModal()
|
||||||
emit('success')
|
emit('success')
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -91,11 +91,11 @@ function handleEdit(record: Recordable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMenu(record: Recordable) {
|
function handleMenu(record: Recordable) {
|
||||||
openMenuModal(true, { record, isUpdate: true })
|
openMenuModal(true, { record })
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDataScope(record: Recordable) {
|
function handleDataScope(record: Recordable) {
|
||||||
openScopeModal(true, { record, isUpdate: true })
|
openScopeModal(true, { record })
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleExport() {
|
async function handleExport() {
|
||||||
|
|
Loading…
Reference in New Issue