refactor: 统一 dept、menu、post、role 的代码风格
This commit is contained in:
333
apps/web-antd/src/views/system/menu/data.ts
Normal file
333
apps/web-antd/src/views/system/menu/data.ts
Normal file
@@ -0,0 +1,333 @@
|
||||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemMenuApi } from '#/api/system/menu';
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import { $t } from '#/locales';
|
||||
import { h } from 'vue';
|
||||
import { z } from '#/adapter/form';
|
||||
import { componentKeys } from '#/router/routes';
|
||||
import { getMenuList } from '#/api/system/menu';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
||||
import { handleTree } from '#/utils/tree';
|
||||
import { CommonStatusEnum, SystemMenuTypeEnum } from '#/utils/constants';
|
||||
import { isHttpUrl } from '@vben/utils';
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'parentId',
|
||||
label: '上级菜单',
|
||||
component: 'ApiTreeSelect',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
api: async () => {
|
||||
const data = await getMenuList();
|
||||
data.unshift({
|
||||
id: 0,
|
||||
name: '顶级部门',
|
||||
} as SystemMenuApi.SystemMenu);
|
||||
return handleTree(data);
|
||||
},
|
||||
class: 'w-full',
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
childrenField: 'children',
|
||||
placeholder: '请选择上级菜单',
|
||||
filterTreeNode(input: string, node: Recordable<any>) {
|
||||
if (!input || input.length === 0) {
|
||||
return true;
|
||||
}
|
||||
const name: string = node.label ?? '';
|
||||
if (!name) return false;
|
||||
return name.includes(input) || $t(name).includes(input);
|
||||
},
|
||||
showSearch: true,
|
||||
treeDefaultExpandedKeys: [0],
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
renderComponentContent() {
|
||||
return {
|
||||
title({ label, icon }: { label: string; icon: string }) {
|
||||
const components = [];
|
||||
if (!label) return '';
|
||||
if (icon) {
|
||||
components.push(h(IconifyIcon, { class: 'size-4', icon }));
|
||||
}
|
||||
components.push(h('span', { class: '' }, $t(label || '')));
|
||||
return h('div', { class: 'flex items-center gap-1' }, components);
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '菜单名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入菜单名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'type',
|
||||
label: '菜单类型',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.SYSTEM_MENU_TYPE, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(SystemMenuTypeEnum.DIR),
|
||||
},
|
||||
{
|
||||
fieldName: 'icon',
|
||||
label: '菜单图标',
|
||||
component: 'IconPicker',
|
||||
componentProps: {
|
||||
placeholder: '请选择菜单图标',
|
||||
prefix: 'carbon',
|
||||
},
|
||||
rules: 'required',
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.DIR, SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'path',
|
||||
label: '路由地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入路由地址',
|
||||
},
|
||||
rules: z.string(),
|
||||
help: '访问的路由地址,如:`user`。如需外网地址时,则以 `http(s)://` 开头',
|
||||
dependencies: {
|
||||
triggerFields: ['type', 'parentId'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.DIR, SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
},
|
||||
rules: (values) => {
|
||||
const schema = z.string().min(1, '路由地址不能为空');
|
||||
if (isHttpUrl(values.path)) {
|
||||
return schema;
|
||||
}
|
||||
if (values.parentId === 0) {
|
||||
return schema.refine((path) => path.charAt(0) === '/', '路径必须以 / 开头');
|
||||
}
|
||||
return schema.refine((path) => path.charAt(0) !== '/', '路径不能以 / 开头');
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
fieldName: 'component',
|
||||
label: '组件地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入组件地址',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'componentName',
|
||||
label: '组件名称',
|
||||
component: 'AutoComplete',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
class: 'w-full',
|
||||
filterOption(input: string, option: { value: string }) {
|
||||
return option.value.toLowerCase().includes(input.toLowerCase());
|
||||
},
|
||||
placeholder: '请选择组件名称',
|
||||
options: componentKeys.map((v) => ({ value: v })),
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'permission',
|
||||
label: '权限标识',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入菜单描述',
|
||||
},
|
||||
dependencies: {
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU, SystemMenuTypeEnum.BUTTON].includes(
|
||||
values.type,
|
||||
);
|
||||
},
|
||||
triggerFields: ['type'],
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'sort',
|
||||
label: '显示顺序',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
class: 'w-full',
|
||||
controlsPosition: 'right',
|
||||
placeholder: '请输入显示顺序',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '菜单状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'alwaysShow',
|
||||
label: '总是显示',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '总是', value: true },
|
||||
{ label: '不是', value: false },
|
||||
],
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: 'required',
|
||||
defaultValue: true,
|
||||
help: '选择不是时,当该菜单只有一个子菜单时,不展示自己,直接展示子菜单',
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'keepAlive',
|
||||
label: '缓存状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '缓存', value: true },
|
||||
{ label: '不缓存', value: false },
|
||||
],
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: 'required',
|
||||
defaultValue: true,
|
||||
help: '选择缓存时,则会被 `keep-alive` 缓存,必须填写「组件名称」字段',
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(
|
||||
onActionClick: OnActionClickFn<SystemMenuApi.SystemMenu>,
|
||||
): VxeTableGridOptions<SystemMenuApi.SystemMenu>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'name',
|
||||
title: '菜单名称',
|
||||
minWidth: 250,
|
||||
align: 'left',
|
||||
fixed: 'left',
|
||||
slots: { default: 'name' },
|
||||
treeNode: true,
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
title: '菜单类型',
|
||||
minWidth: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.SYSTEM_MENU_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'sort',
|
||||
title: '显示排序',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'permission',
|
||||
title: '权限标识',
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
field: 'path',
|
||||
title: '组件路径',
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
field: 'componentName',
|
||||
minWidth: 200,
|
||||
title: '组件名称',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'operation',
|
||||
title: '操作',
|
||||
align: 'right',
|
||||
minWidth: 200,
|
||||
fixed: 'right',
|
||||
headerAlign: 'center',
|
||||
showOverflow: false,
|
||||
cellRender: {
|
||||
attrs: {
|
||||
nameField: 'name',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
options: [
|
||||
{
|
||||
code: 'append',
|
||||
text: '新增下级',
|
||||
},
|
||||
'edit', // 默认的编辑按钮
|
||||
'delete', // 默认的删除按钮
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
<script lang="ts" setup>
|
||||
import type { OnActionClickFn, OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemMenuApi } from '#/api/system/menu';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
import { IconifyIcon, Plus } from '@vben/icons';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
import { ref } from 'vue';
|
||||
import { $t } from '#/locales';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getMenuList, deleteMenu } from '#/api/system/menu';
|
||||
import { SystemMenuTypeEnum } from '#/utils/constants';
|
||||
import { DICT_TYPE } from '#/utils/dict';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
import { IconifyIcon, Plus } from '@vben/icons';
|
||||
import Form from './modules/form.vue';
|
||||
import { useGridColumns } from './data';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
@@ -24,27 +25,6 @@ function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<SystemMenuApi.SystemMenu>) {
|
||||
switch (code) {
|
||||
case 'append': {
|
||||
onAppend(row);
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 创建菜单 */
|
||||
function onCreate() {
|
||||
formModalApi.setData({}).open();
|
||||
@@ -79,6 +59,27 @@ async function onDelete(row: SystemMenuApi.SystemMenu) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<SystemMenuApi.SystemMenu>) {
|
||||
switch (code) {
|
||||
case 'append': {
|
||||
onAppend(row);
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 切换树形展开/收缩状态 */
|
||||
const isExpanded = ref(false);
|
||||
function toggleExpand() {
|
||||
@@ -86,84 +87,6 @@ function toggleExpand() {
|
||||
gridApi.grid.setAllTreeExpand(isExpanded.value);
|
||||
}
|
||||
|
||||
function useGridColumns(
|
||||
onActionClick: OnActionClickFn<SystemMenuApi.SystemMenu>,
|
||||
): VxeTableGridOptions<SystemMenuApi.SystemMenu>['columns'] {
|
||||
return [
|
||||
{
|
||||
align: 'left',
|
||||
field: 'name',
|
||||
fixed: 'left',
|
||||
slots: { default: 'name' },
|
||||
title: '菜单名称',
|
||||
treeNode: true,
|
||||
minWidth: 250,
|
||||
},
|
||||
{
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.SYSTEM_MENU_TYPE },
|
||||
},
|
||||
field: 'type',
|
||||
title: '菜单类型',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'sort',
|
||||
title: '显示排序',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'permission',
|
||||
title: '权限标识',
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
field: 'path',
|
||||
title: '组件路径',
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
field: 'componentName',
|
||||
minWidth: 200,
|
||||
title: '组件名称',
|
||||
},
|
||||
{
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
align: 'right',
|
||||
cellRender: {
|
||||
attrs: {
|
||||
nameField: 'name',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
options: [
|
||||
{
|
||||
code: 'append',
|
||||
text: '新增下级',
|
||||
},
|
||||
'edit', // 默认的编辑按钮
|
||||
'delete', // 默认的删除按钮
|
||||
],
|
||||
},
|
||||
field: 'operation',
|
||||
fixed: 'right',
|
||||
headerAlign: 'center',
|
||||
showOverflow: false,
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: useGridColumns(onActionClick),
|
||||
@@ -194,6 +117,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
} as VxeTableGridOptions,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<FormModal @success="onRefresh" />
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
<script lang="ts" setup>
|
||||
import type { SystemMenuApi } from '#/api/system/menu';
|
||||
import type { Recordable } from '@vben/types';
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
|
||||
import { $t } from '#/locales';
|
||||
import { computed, h, ref } from 'vue';
|
||||
import { componentKeys } from '#/router/routes';
|
||||
import { useVbenForm, z } from '#/adapter/form';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createMenu, getMenu, updateMenu } from '#/api/system/menu';
|
||||
import { getMenuList } from '#/api/system/menu';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
||||
import { handleTree } from '#/utils/tree';
|
||||
import { CommonStatusEnum, SystemMenuTypeEnum } from '#/utils/constants';
|
||||
import { isHttpUrl } from '@vben/utils';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<SystemMenuApi.SystemMenu>();
|
||||
const getTitle = computed(() =>
|
||||
@@ -25,244 +18,10 @@ const getTitle = computed(() =>
|
||||
? $t('ui.actionTitle.edit', ['菜单'])
|
||||
: $t('ui.actionTitle.create', ['菜单']),
|
||||
);
|
||||
const schema: VbenFormSchema[] = [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'parentId',
|
||||
label: '上级菜单',
|
||||
component: 'ApiTreeSelect',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
api: async () => {
|
||||
const data = await getMenuList();
|
||||
data.unshift({
|
||||
id: 0,
|
||||
name: '顶级部门',
|
||||
} as SystemMenuApi.SystemMenu);
|
||||
return handleTree(data);
|
||||
},
|
||||
class: 'w-full',
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
childrenField: 'children',
|
||||
placeholder: '请选择上级菜单',
|
||||
filterTreeNode(input: string, node: Recordable<any>) {
|
||||
if (!input || input.length === 0) {
|
||||
return true;
|
||||
}
|
||||
const name: string = node.label ?? '';
|
||||
if (!name) return false;
|
||||
return name.includes(input) || $t(name).includes(input);
|
||||
},
|
||||
showSearch: true,
|
||||
treeDefaultExpandedKeys: [0],
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
renderComponentContent() {
|
||||
return {
|
||||
title({ label, icon }: { label: string; icon: string }) {
|
||||
const components = [];
|
||||
if (!label) return '';
|
||||
if (icon) {
|
||||
components.push(h(IconifyIcon, { class: 'size-4', icon }));
|
||||
}
|
||||
components.push(h('span', { class: '' }, $t(label || '')));
|
||||
return h('div', { class: 'flex items-center gap-1' }, components);
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '菜单名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入菜单名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'type',
|
||||
label: '菜单类型',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.SYSTEM_MENU_TYPE, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(SystemMenuTypeEnum.DIR),
|
||||
},
|
||||
{
|
||||
fieldName: 'icon',
|
||||
label: '菜单图标',
|
||||
component: 'IconPicker',
|
||||
componentProps: {
|
||||
placeholder: '请选择菜单图标',
|
||||
prefix: 'carbon',
|
||||
},
|
||||
rules: 'required',
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.DIR, SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'path',
|
||||
label: '路由地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入路由地址',
|
||||
},
|
||||
rules: z.string(),
|
||||
help: '访问的路由地址,如:`user`。如需外网地址时,则以 `http(s)://` 开头',
|
||||
dependencies: {
|
||||
triggerFields: ['type', 'parentId'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.DIR, SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
},
|
||||
rules: (values) => {
|
||||
const schema = z.string().min(1, '路由地址不能为空');
|
||||
if (isHttpUrl(values.path)) {
|
||||
return schema;
|
||||
}
|
||||
if (values.parentId === 0) {
|
||||
return schema.refine((path) => path.charAt(0) === '/', '路径必须以 / 开头');
|
||||
}
|
||||
return schema.refine((path) => path.charAt(0) !== '/', '路径不能以 / 开头');
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
fieldName: 'component',
|
||||
label: '组件地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入组件地址',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'componentName',
|
||||
label: '组件名称',
|
||||
component: 'AutoComplete',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
class: 'w-full',
|
||||
filterOption(input: string, option: { value: string }) {
|
||||
return option.value.toLowerCase().includes(input.toLowerCase());
|
||||
},
|
||||
placeholder: '请选择组件名称',
|
||||
options: componentKeys.map((v) => ({ value: v })),
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入菜单描述',
|
||||
},
|
||||
dependencies: {
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU, SystemMenuTypeEnum.BUTTON].includes(
|
||||
values.type,
|
||||
);
|
||||
},
|
||||
triggerFields: ['type'],
|
||||
},
|
||||
fieldName: 'permission',
|
||||
label: '权限标识',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
class: 'w-full',
|
||||
controlsPosition: 'right',
|
||||
placeholder: '请输入菜单顺序',
|
||||
},
|
||||
fieldName: 'sort',
|
||||
label: '菜单顺序',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
fieldName: 'status',
|
||||
label: '菜单状态',
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'alwaysShow',
|
||||
label: '总是显示',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '总是', value: true },
|
||||
{ label: '不是', value: false },
|
||||
],
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: 'required',
|
||||
defaultValue: true,
|
||||
help: '选择不是时,当该菜单只有一个子菜单时,不展示自己,直接展示子菜单',
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'keepAlive',
|
||||
label: '缓存状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '缓存', value: true },
|
||||
{ label: '不缓存', value: false },
|
||||
],
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: 'required',
|
||||
defaultValue: true,
|
||||
help: '选择缓存时,则会被 `keep-alive` 缓存,必须填写「组件名称」字段',
|
||||
dependencies: {
|
||||
triggerFields: ['type'],
|
||||
show: (values) => {
|
||||
return [SystemMenuTypeEnum.MENU].includes(values.type);
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
layout: 'horizontal',
|
||||
schema,
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
@@ -273,9 +32,11 @@ const [Modal, modalApi] = useVbenModal({
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as SystemMenuApi.SystemMenu;
|
||||
try {
|
||||
await (formData.value?.id ? updateMenu(data) : createMenu(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success({
|
||||
@@ -290,6 +51,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
if (!isOpen) {
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
let data = modalApi.getData<SystemMenuApi.SystemMenu>();
|
||||
if (!data) {
|
||||
return;
|
||||
@@ -302,11 +64,13 @@ const [Modal, modalApi] = useVbenModal({
|
||||
modalApi.lock(false);
|
||||
}
|
||||
}
|
||||
// 设置到 values
|
||||
formData.value = data;
|
||||
await formApi.setValues(formData.value);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle">
|
||||
<Form class="mx-4" />
|
||||
|
||||
Reference in New Issue
Block a user