feat: role menu && data scope

pull/4/MERGE
xingyuv 2023-04-12 16:31:08 +08:00
parent e40fb13ab9
commit 7e8d9dc62a
3 changed files with 74 additions and 51 deletions

View File

@ -1,22 +1,38 @@
<template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit">
<BasicForm @register="registerForm" />
<BasicForm @register="registerForm">
<template #menuIds="{ model, field }">
<BasicTree
v-model:value="model[field]"
:treeData="treeData"
:fieldNames="{ title: 'name', key: 'id' }"
checkable
toolbar
title="菜单分配"
/>
</template>
</BasicForm>
</BasicModal>
</template>
<script lang="ts" setup name="RoleMenuModal">
import { ref, unref } from 'vue'
import { BasicModal, useModalInner } from '@/components/Modal'
import { BasicForm, useForm } from '@/components/Form'
import { dataScopeFormSchema } from './role.data'
import { menuScopeFormSchema } from './role.data'
import { createRole, getRole, updateRole } from '@/api/system/role'
import { BasicTree, TreeItem } from '@/components/Tree'
import { listSimpleMenus } from '@/api/system/menu'
import { handleTree } from '@/utils/tree'
import { listRoleMenus } from '@/api/system/permission'
const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true)
const treeData = ref<TreeItem[]>([])
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 120,
baseColProps: { span: 24 },
schemas: dataScopeFormSchema,
schemas: menuScopeFormSchema,
showActionButtonGroup: false,
actionColOptions: { span: 23 }
})
@ -24,10 +40,16 @@ const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
resetFields()
setModalProps({ confirmLoading: false })
if (unref(treeData).length === 0) {
const res = await listSimpleMenus()
treeData.value = handleTree(res, 'id')
}
isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) {
const res = await getRole(data.record.id)
const menuRes = await listRoleMenus(data.record.id)
res.menuIds = menuRes
setFieldsValue({ ...res })
}
})

View File

@ -1,17 +1,32 @@
<template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit">
<BasicForm @register="registerForm" />
<BasicForm @register="registerForm">
<template #dataScopeDeptIds="{ model, field }">
<BasicTree
v-model:value="model[field]"
:treeData="treeData"
:fieldNames="{ title: 'name', key: 'id' }"
checkable
toolbar
title="部门分配"
/>
</template>
</BasicForm>
</BasicModal>
</template>
<script lang="ts" setup name="RoleScopeModal">
import { ref, unref } from 'vue'
import { BasicModal, useModalInner } from '@/components/Modal'
import { BasicForm, useForm } from '@/components/Form'
import { BasicTree, TreeItem } from '@/components/Tree'
import { dataScopeFormSchema } from './role.data'
import { createRole, getRole, updateRole } from '@/api/system/role'
import { listSimpleDept } from '@/api/system/dept'
import { handleTree } from '@/utils/tree'
const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true)
const treeData = ref<TreeItem[]>([])
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 120,
@ -24,6 +39,10 @@ const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
resetFields()
setModalProps({ confirmLoading: false })
if (unref(treeData).length === 0) {
const res = await listSimpleDept()
treeData.value = handleTree(res, 'id')
}
isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) {

View File

@ -1,8 +1,6 @@
import { BasicColumn, FormSchema, useRender } from '@/components/Table'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { listSimpleDept } from '@/api/system/dept'
import { SystemDataScopeEnum } from '@/enums/systemEnum'
import { listSimpleMenus } from '@/api/system/menu'
export const columns: BasicColumn[] = [
{
@ -122,6 +120,33 @@ export const formSchema: FormSchema[] = [
}
]
export const menuScopeFormSchema: FormSchema[] = [
{
label: '编号',
field: 'id',
show: false,
component: 'Input'
},
{
label: '角色名称',
field: 'name',
dynamicDisabled: true,
component: 'Input'
},
{
label: '角色标识',
field: 'code',
dynamicDisabled: true,
component: 'Input'
},
{
label: '菜单权限',
field: 'menuIds',
component: 'Input',
slot: 'menuIds'
}
]
export const dataScopeFormSchema: FormSchema[] = [
{
label: '编号',
@ -153,51 +178,8 @@ export const dataScopeFormSchema: FormSchema[] = [
{
label: '数据权限',
field: 'dataScopeDeptIds',
component: 'ApiTreeSelect',
ifShow: ({ values }) => values.dataScope === SystemDataScopeEnum.DEPT_CUSTOM,
componentProps: {
api: () => listSimpleDept(),
fieldNames: {
label: 'name',
key: 'id',
value: 'id'
},
handleTree: 'id'
}
}
]
export const menuScopeFormSchema: FormSchema[] = [
{
label: '编号',
field: 'id',
show: false,
component: 'Input'
},
{
label: '角色名称',
field: 'name',
dynamicDisabled: true,
component: 'Input'
},
{
label: '角色标识',
field: 'code',
dynamicDisabled: true,
component: 'Input'
},
{
label: '菜单权限',
field: 'menuIds',
component: 'ApiTreeSelect',
componentProps: {
api: () => listSimpleMenus(),
fieldNames: {
label: 'name',
key: 'id',
value: 'id'
},
handleTree: 'id'
}
component: 'Input',
slot: 'dataScopeDeptIds'
}
]