仰望星辰工作室

fix(theme): 修复插件二级菜单项强制渲染默认图标导致文字偏移的问题

Y yang1145 提交于 2026-07-19 07:40 · c813437 ·父提交 cd4ea79
fix(theme): 修复插件二级菜单项强制渲染默认图标导致文字偏移的问题
2 个文件变更 +14 -5 13172193298@163.com
•MPHX/plugin.php +8 -3
•templates/layui/theme.php +6 -2
变更内容
diff --git a/MPHX/plugin.php b/MPHX/plugin.php
index eedd364..5354cdf 100644
--- a/MPHX/plugin.php
+++ b/MPHX/plugin.php
@@ -751,16 +751,21 @@ function mnbt_plugin_menus($side)
 function _mnbt_plugin_render_menu_item($it, $depth = 0)
 {
 	$title = htmlspecialchars($it['title'] ?? '', ENT_QUOTES, 'UTF-8');
-	$icon  = htmlspecialchars($it['icon'] ?? 'mdi-puzzle', ENT_QUOTES, 'UTF-8');
+	$iconHtml = '';
+	if (!empty($it['icon'])) {
+		$icon = htmlspecialchars($it['icon'], ENT_QUOTES, 'UTF-8');
+		$iconHtml = '<i class="mdi ' . $icon . '"></i> ';
+	}
 	if (!empty($it['children'])) {
 		$childrenHtml = _mnbt_plugin_render_menu_children($it['children'], $depth + 1);
+		$parentIconHtml = $iconHtml !== '' ? $iconHtml : '<i class="mdi mdi-puzzle"></i> ';
 		return '<li class="nav-item nav-item-has-subnav">'
-			. '<a href="javascript:void(0)"><i class="mdi ' . $icon . '"></i> <span>' . $title . '</span></a>'
+			. '<a href="javascript:void(0)">' . $parentIconHtml . '<span>' . $title . '</span></a>'
 			. '<ul class="nav nav-subnav">' . $childrenHtml . '</ul></li>';
 	}
 	$url = htmlspecialchars($it['url'] ?? 'javascript:void(0)', ENT_QUOTES, 'UTF-8');
 	$mt = !empty($it['multitabs']) || strpos($url, 'plugin.php') !== false ? ' multitabs' : '';
-	return '<li> <a class="' . trim($mt) . '" href="' . $url . '"><i class="mdi ' . $icon . '"></i> ' . $title . '</a> </li>';
+	return '<li> <a class="' . trim($mt) . '" href="' . $url . '">' . $iconHtml . $title . '</a> </li>';
 }
 
 function _mnbt_plugin_render_menu_children($children, $depth = 1)
diff --git a/templates/layui/theme.php b/templates/layui/theme.php
index f764919..6080d25 100644
--- a/templates/layui/theme.php
+++ b/templates/layui/theme.php
@@ -26,9 +26,13 @@ mnbt_register_theme_menu_renderer('user', function ($items) {
 			foreach ($it['children'] as $child) {
 				$childTitle = htmlspecialchars($child['title'] ?? '', ENT_QUOTES, 'UTF-8');
 				$childUrl   = htmlspecialchars($child['url'] ?? 'javascript:void(0)', ENT_QUOTES, 'UTF-8');
-				$childIcon  = htmlspecialchars($child['icon'] ?? 'mdi-circle-small', ENT_QUOTES, 'UTF-8');
+				$childIconHtml = '';
+				if (!empty($child['icon'])) {
+					$childIcon = htmlspecialchars($child['icon'], ENT_QUOTES, 'UTF-8');
+					$childIconHtml = '<i class="mdi ' . $childIcon . '"></i> ';
+				}
 				$mt = !empty($child['multitabs']) || strpos($childUrl, 'plugin.php') !== false ? ' multitabs' : '';
-				$childrenHtml .= '<li><a href="' . $childUrl . '" class="' . trim($mt) . '"><i class="mdi ' . $childIcon . '"></i> ' . $childTitle . '</a></li>';
+				$childrenHtml .= '<li><a href="' . $childUrl . '" class="' . trim($mt) . '">' . $childIconHtml . $childTitle . '</a></li>';
 			}
 			$html .= '<li class="ly-menu-item ly-submenu">'
 				. '<a href="javascript:;"><i class="mdi ' . $icon . '"></i><span>' . $title . '</span><i class="mdi mdi-chevron-right ly-arrow"></i></a>'