feat: role menu && data scope
parent
e40fb13ab9
commit
7e8d9dc62a
|
@ -1,22 +1,38 @@
|
||||||
<template>
|
<template>
|
||||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit">
|
<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>
|
</BasicModal>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup name="RoleMenuModal">
|
<script lang="ts" setup name="RoleMenuModal">
|
||||||
import { ref, unref } from 'vue'
|
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 { dataScopeFormSchema } from './role.data'
|
import { menuScopeFormSchema } from './role.data'
|
||||||
import { createRole, getRole, updateRole } from '@/api/system/role'
|
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 emit = defineEmits(['success', 'register'])
|
||||||
const isUpdate = ref(true)
|
const isUpdate = ref(true)
|
||||||
|
const treeData = ref<TreeItem[]>([])
|
||||||
|
|
||||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
labelWidth: 120,
|
labelWidth: 120,
|
||||||
baseColProps: { span: 24 },
|
baseColProps: { span: 24 },
|
||||||
schemas: dataScopeFormSchema,
|
schemas: menuScopeFormSchema,
|
||||||
showActionButtonGroup: false,
|
showActionButtonGroup: false,
|
||||||
actionColOptions: { span: 23 }
|
actionColOptions: { span: 23 }
|
||||||
})
|
})
|
||||||
|
@ -24,10 +40,16 @@ const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
resetFields()
|
resetFields()
|
||||||
setModalProps({ confirmLoading: false })
|
setModalProps({ confirmLoading: false })
|
||||||
|
if (unref(treeData).length === 0) {
|
||||||
|
const res = await listSimpleMenus()
|
||||||
|
treeData.value = handleTree(res, 'id')
|
||||||
|
}
|
||||||
isUpdate.value = !!data?.isUpdate
|
isUpdate.value = !!data?.isUpdate
|
||||||
|
|
||||||
if (unref(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)
|
||||||
|
res.menuIds = menuRes
|
||||||
setFieldsValue({ ...res })
|
setFieldsValue({ ...res })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,17 +1,32 @@
|
||||||
<template>
|
<template>
|
||||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit">
|
<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>
|
</BasicModal>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup name="RoleScopeModal">
|
<script lang="ts" setup name="RoleScopeModal">
|
||||||
import { ref, unref } from 'vue'
|
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 { BasicTree, TreeItem } from '@/components/Tree'
|
||||||
import { dataScopeFormSchema } from './role.data'
|
import { dataScopeFormSchema } from './role.data'
|
||||||
import { createRole, getRole, updateRole } from '@/api/system/role'
|
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 emit = defineEmits(['success', 'register'])
|
||||||
const isUpdate = ref(true)
|
const isUpdate = ref(true)
|
||||||
|
const treeData = ref<TreeItem[]>([])
|
||||||
|
|
||||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
labelWidth: 120,
|
labelWidth: 120,
|
||||||
|
@ -24,6 +39,10 @@ const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
resetFields()
|
resetFields()
|
||||||
setModalProps({ confirmLoading: false })
|
setModalProps({ confirmLoading: false })
|
||||||
|
if (unref(treeData).length === 0) {
|
||||||
|
const res = await listSimpleDept()
|
||||||
|
treeData.value = handleTree(res, 'id')
|
||||||
|
}
|
||||||
isUpdate.value = !!data?.isUpdate
|
isUpdate.value = !!data?.isUpdate
|
||||||
|
|
||||||
if (unref(isUpdate)) {
|
if (unref(isUpdate)) {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { BasicColumn, FormSchema, useRender } from '@/components/Table'
|
import { BasicColumn, FormSchema, useRender } from '@/components/Table'
|
||||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||||
import { listSimpleDept } from '@/api/system/dept'
|
|
||||||
import { SystemDataScopeEnum } from '@/enums/systemEnum'
|
import { SystemDataScopeEnum } from '@/enums/systemEnum'
|
||||||
import { listSimpleMenus } from '@/api/system/menu'
|
|
||||||
|
|
||||||
export const columns: BasicColumn[] = [
|
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[] = [
|
export const dataScopeFormSchema: FormSchema[] = [
|
||||||
{
|
{
|
||||||
label: '编号',
|
label: '编号',
|
||||||
|
@ -153,51 +178,8 @@ export const dataScopeFormSchema: FormSchema[] = [
|
||||||
{
|
{
|
||||||
label: '数据权限',
|
label: '数据权限',
|
||||||
field: 'dataScopeDeptIds',
|
field: 'dataScopeDeptIds',
|
||||||
component: 'ApiTreeSelect',
|
|
||||||
ifShow: ({ values }) => values.dataScope === SystemDataScopeEnum.DEPT_CUSTOM,
|
ifShow: ({ values }) => values.dataScope === SystemDataScopeEnum.DEPT_CUSTOM,
|
||||||
componentProps: {
|
component: 'Input',
|
||||||
api: () => listSimpleDept(),
|
slot: 'dataScopeDeptIds'
|
||||||
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'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue