feat: 系统菜单增加自定义svg支持

This commit is contained in:
2026-08-19 17:44:48 +08:00
parent 22a5300e55
commit 4a634bb5db
13 changed files with 163 additions and 17 deletions
@@ -19,8 +19,10 @@ export namespace MenuDTO {
component?: string;
/** 重定向路径 */
redirect?: string;
/** 菜单图标 */
/** 菜单图标(Iconify 名) */
icon?: string;
/** 自定义 SVG(有值时优先于 icon) */
iconSvg?: string;
/** 排序 */
order?: number;
/** 菜单类型 */
@@ -49,8 +51,10 @@ export namespace MenuDTO {
component?: string;
/** 重定向路径 */
redirect?: string;
/** 菜单图标 */
/** 菜单图标(Iconify 名) */
icon?: string;
/** 自定义 SVG(有值时优先于 icon) */
iconSvg?: string;
/** 排序 */
order?: number;
/** 菜单类型 */
@@ -22,8 +22,10 @@ export namespace MenuVO {
component?: string;
/** 重定向路径 */
redirect?: string;
/** 菜单图标 */
/** 菜单图标(Iconify 名) */
icon?: string;
/** 自定义 SVG(有值时优先于 icon) */
iconSvg?: string;
/** 排序 */
order?: number;
/** 菜单类型 */
@@ -71,6 +71,7 @@ interface FormData {
component: string;
redirect: string;
icon: string;
iconSvg: string;
order: number;
type: string;
visible: boolean;
@@ -88,6 +89,7 @@ const formData = ref<FormData>({
component: '',
redirect: '',
icon: '',
iconSvg: '',
order: 0,
type: 'menu',
visible: true,
@@ -349,6 +351,7 @@ function open(edit: boolean, record?: MenuVO.MenuInfo) {
component: record.component || '',
redirect: record.redirect || '',
icon: record.icon || '',
iconSvg: record.iconSvg || '',
order: record.order || 0,
type: record.type,
visible: record.visible === 1, // 转换为boolean
@@ -377,6 +380,7 @@ function open(edit: boolean, record?: MenuVO.MenuInfo) {
component: '',
redirect: '',
icon: '',
iconSvg: '',
order: 0,
type: 'menu',
visible: true,
@@ -394,6 +398,7 @@ function open(edit: boolean, record?: MenuVO.MenuInfo) {
component: '',
redirect: '',
icon: '',
iconSvg: '',
order: 0,
type: 'menu',
visible: true,
@@ -479,6 +484,8 @@ async function handleSubmit() {
const submitData = {
...formData.value,
parentId: formData.value.parentId ?? null,
icon: formData.value.icon?.trim() || null,
iconSvg: formData.value.iconSvg?.trim() || null,
superMenu: formData.value.superMenu ? 1 : 0,
visible: formData.value.visible ? 1 : 0,
status: formData.value.status ? 1 : 0,
@@ -662,6 +669,23 @@ defineExpose({
</Popover>
</Form.Item>
<Form.Item label="自定义 SVG" name="iconSvg">
<div class="flex gap-3">
<Input.TextArea
v-model:value="formData.iconSvg"
placeholder="粘贴完整 <svg>...</svg>;有值时优先于上方 Iconify 图标"
:rows="4"
class="flex-1"
/>
<div
v-if="formData.iconSvg?.trim().startsWith('<svg')"
class="flex size-10 shrink-0 items-center justify-center rounded border border-border [&>svg]:size-6"
title="SVG 预览"
v-html="formData.iconSvg"
></div>
</div>
</Form.Item>
<Form.Item label="排序" name="order">
<InputNumber
v-model:value="formData.order"
@@ -456,7 +456,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
<!-- 图标列 -->
<template #icon="{ row }: { row: MenuVO.MenuInfo }">
<div
v-if="row.icon"
v-if="row.iconSvg?.trim()"
class="flex items-center justify-center [&>svg]:size-4"
title="自定义 SVG"
v-html="row.iconSvg"
></div>
<div
v-else-if="row.icon"
class="flex items-center justify-center"
:title="row.icon"
>