mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 03:09:19 +08:00
refactor: 删除菜单 name,标题必填且同级唯一并加库约束
This commit is contained in:
@@ -9,14 +9,12 @@ export namespace MenuDTO {
|
||||
parentId?: number | null;
|
||||
/** 超级菜单标识 */
|
||||
superMenu?: number;
|
||||
/** 菜单名称 */
|
||||
name: string;
|
||||
/** 路由名称(Vue Router name,建议英文唯一) */
|
||||
routeName?: string;
|
||||
/** 菜单标题(侧栏) */
|
||||
title?: string;
|
||||
/** 路由名称(Vue Router name,建议英文唯一;可空) */
|
||||
routeName?: null | string;
|
||||
/** 菜单标题(侧栏/管理端展示) */
|
||||
title: string;
|
||||
/** 标签页标题(可空;空则回退 title) */
|
||||
tabTitle?: string;
|
||||
tabTitle?: null | string;
|
||||
/** 路由路径 */
|
||||
path?: string;
|
||||
/** 组件路径 */
|
||||
@@ -24,9 +22,9 @@ export namespace MenuDTO {
|
||||
/** 重定向路径 */
|
||||
redirect?: string;
|
||||
/** 菜单图标(Iconify 名) */
|
||||
icon?: string;
|
||||
icon?: null | string;
|
||||
/** 自定义 SVG(有值时优先于 icon) */
|
||||
iconSvg?: string;
|
||||
iconSvg?: null | string;
|
||||
/** 排序 */
|
||||
order?: number;
|
||||
/** 菜单类型 */
|
||||
@@ -45,14 +43,12 @@ export namespace MenuDTO {
|
||||
parentId?: number | null;
|
||||
/** 超级菜单标识 */
|
||||
superMenu?: number;
|
||||
/** 菜单名称 */
|
||||
name: string;
|
||||
/** 路由名称(Vue Router name,建议英文唯一) */
|
||||
routeName?: string;
|
||||
/** 菜单标题(侧栏) */
|
||||
title?: string;
|
||||
/** 路由名称(Vue Router name,建议英文唯一;可空) */
|
||||
routeName?: null | string;
|
||||
/** 菜单标题(侧栏/管理端展示) */
|
||||
title: string;
|
||||
/** 标签页标题(可空;空则回退 title) */
|
||||
tabTitle?: string;
|
||||
tabTitle?: null | string;
|
||||
/** 路由路径 */
|
||||
path?: string;
|
||||
/** 组件路径 */
|
||||
@@ -60,9 +56,9 @@ export namespace MenuDTO {
|
||||
/** 重定向路径 */
|
||||
redirect?: string;
|
||||
/** 菜单图标(Iconify 名) */
|
||||
icon?: string;
|
||||
icon?: null | string;
|
||||
/** 自定义 SVG(有值时优先于 icon) */
|
||||
iconSvg?: string;
|
||||
iconSvg?: null | string;
|
||||
/** 排序 */
|
||||
order?: number;
|
||||
/** 菜单类型 */
|
||||
|
||||
@@ -12,12 +12,10 @@ export namespace MenuVO {
|
||||
parentId?: number;
|
||||
/** 超级菜单标识 */
|
||||
superMenu?: number;
|
||||
/** 菜单名称 */
|
||||
name: string;
|
||||
/** 路由名称(Vue Router name) */
|
||||
/** 路由名称(Vue Router name;可空) */
|
||||
routeName?: string;
|
||||
/** 菜单标题(侧栏) */
|
||||
title?: string;
|
||||
/** 菜单标题(侧栏/管理端展示) */
|
||||
title: string;
|
||||
/** 标签页标题(可空;空则回退 title) */
|
||||
tabTitle?: string;
|
||||
/** 路由路径 */
|
||||
|
||||
@@ -100,7 +100,7 @@ const menuTreeData = computed(() => {
|
||||
systemMenuList.value.forEach((menu) => {
|
||||
menuMap.set(menu.id, {
|
||||
key: menu.id,
|
||||
title: menu.name,
|
||||
title: menu.title || menu.routeName || `菜单#${menu.id}`,
|
||||
type: menu.type,
|
||||
superMenu: menu.superMenu,
|
||||
status: menu.status,
|
||||
|
||||
@@ -141,7 +141,7 @@ function getAllMenuIds(menus: CompanyMenuVO.CompanyMenuInfo[]): number[] {
|
||||
function convertToTreeData(menus: CompanyMenuVO.CompanyMenuInfo[]): any[] {
|
||||
return menus.map((menu) => ({
|
||||
key: menu.id,
|
||||
title: menu.name,
|
||||
title: menu.title || menu.routeName || `菜单#${menu.id}`,
|
||||
type: menu.type,
|
||||
superMenu: menu.superMenu,
|
||||
status: menu.status,
|
||||
|
||||
@@ -65,7 +65,6 @@ const formRef = ref();
|
||||
interface FormData {
|
||||
parentId: number | null;
|
||||
superMenu: boolean;
|
||||
name: string;
|
||||
routeName: string;
|
||||
title: string;
|
||||
/** 标签页标题,空则回退菜单标题 */
|
||||
@@ -86,7 +85,6 @@ interface FormData {
|
||||
const formData = ref<FormData>({
|
||||
parentId: null,
|
||||
superMenu: false,
|
||||
name: '',
|
||||
routeName: '',
|
||||
title: '',
|
||||
tabTitle: '',
|
||||
@@ -189,7 +187,7 @@ function buildMenuCascaderOptions(
|
||||
const sub = toOptions(children);
|
||||
return {
|
||||
value: menu.id,
|
||||
label: menu.title || menu.name,
|
||||
label: menu.title || menu.routeName || `菜单#${menu.id}`,
|
||||
children: sub.length ? sub : undefined,
|
||||
};
|
||||
});
|
||||
@@ -350,7 +348,6 @@ function open(edit: boolean, record?: MenuVO.MenuInfo) {
|
||||
formData.value = {
|
||||
parentId: record.parentId || null,
|
||||
superMenu: record.superMenu === 1, // 转换为boolean
|
||||
name: record.name,
|
||||
routeName: record.routeName || '',
|
||||
title: record.title || '',
|
||||
tabTitle: record.tabTitle || '',
|
||||
@@ -381,7 +378,6 @@ function open(edit: boolean, record?: MenuVO.MenuInfo) {
|
||||
formData.value = {
|
||||
parentId: record.id, // 自动设置为当前菜单的ID作为父菜单
|
||||
superMenu: false,
|
||||
name: '',
|
||||
routeName: '',
|
||||
title: '',
|
||||
tabTitle: '',
|
||||
@@ -401,7 +397,6 @@ function open(edit: boolean, record?: MenuVO.MenuInfo) {
|
||||
formData.value = {
|
||||
parentId: null,
|
||||
superMenu: false,
|
||||
name: '',
|
||||
routeName: '',
|
||||
title: '',
|
||||
tabTitle: '',
|
||||
@@ -618,11 +613,14 @@ defineExpose({
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="菜单名称"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: '请输入菜单名称' }]"
|
||||
label="菜单标题"
|
||||
name="title"
|
||||
:rules="[{ required: true, message: '请输入菜单标题' }]"
|
||||
>
|
||||
<Input v-model:value="formData.name" placeholder="请输入菜单名称" />
|
||||
<Input
|
||||
v-model:value="formData.title"
|
||||
placeholder="侧栏与管理端显示名称"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
@@ -630,21 +628,18 @@ defineExpose({
|
||||
name="routeName"
|
||||
:rules="[
|
||||
{
|
||||
pattern: /^[A-Za-z][A-Za-z0-9_]*$/,
|
||||
message: '须以字母开头,仅字母/数字/下划线',
|
||||
validator: async (_rule: unknown, value: string) => {
|
||||
if (!value?.trim()) return;
|
||||
if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(value.trim())) {
|
||||
throw new Error('须以字母开头,仅字母/数字/下划线');
|
||||
}
|
||||
},
|
||||
},
|
||||
]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.routeName"
|
||||
placeholder="Vue Router name,如 ShopList(可空,空则用菜单名称)"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="菜单标题" name="title">
|
||||
<Input
|
||||
v-model:value="formData.title"
|
||||
placeholder="侧边菜单显示名称"
|
||||
placeholder="Vue Router name,如 ShopList(可空,空则后端用 Menu_{id})"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ const menuTableBaseColumns: VxeGridProps<any>['columns'] = [
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '菜单名称',
|
||||
field: 'title',
|
||||
title: '菜单标题',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
treeNode: true,
|
||||
@@ -86,12 +86,6 @@ const menuTableBaseColumns: VxeGridProps<any>['columns'] = [
|
||||
minWidth: 140,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'title',
|
||||
title: '菜单标题',
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'tabTitle',
|
||||
title: '标签标题',
|
||||
@@ -289,7 +283,7 @@ async function handleDelete(record: MenuVO.MenuInfo) {
|
||||
function confirmDeleteMenu(record: MenuVO.MenuInfo) {
|
||||
Modal.confirm({
|
||||
title: '确定要删除这个菜单吗?',
|
||||
content: record.title || record.name || `ID ${record.id}`,
|
||||
content: record.title || record.routeName || `ID ${record.id}`,
|
||||
okText: '删除',
|
||||
okType: 'danger',
|
||||
cancelText: '取消',
|
||||
|
||||
Reference in New Issue
Block a user