仰望星辰工作室

feat: 实现插件菜单多主题适配与域名绑定功能重构

Y yang1145 提交于 2026-07-19 07:30 · 48b07c3 ·父提交 11e7c9c
feat: 实现插件菜单多主题适配与域名绑定功能重构

1. 新增layui/bootstrapui/jqueryui主题的菜单渲染器,统一插件菜单渲染逻辑
2. 重构domain_shop插件菜单结构,改为分组式菜单
3. 新增页面接管机制,接管set.php的url分支实现统一的域名绑定页面
4. 优化各主题的用户菜单显示逻辑,移除硬编码的域名修改入口
5. 更新主题开发与插件开发文档,补充新机制说明
12 个文件变更 +747 -73 13172193298@163.com
•MPHX/plugin.php +129 -8
•MPHX/theme.php +190 -0
•app_plugins/PLUGIN_DEV.md +97 -0
•app_plugins/domain_shop/bootstrap.php +66 -31
•templates/THEME_DEV.md +94 -0
•templates/bootstrapui/theme.php +48 -0
•templates/bootstrapui/user/index.php +2 -9
•templates/default/user/set.php +13 -5
•templates/jqueryui/theme.php +60 -0
•templates/jqueryui/user/index.php +2 -13
•templates/layui/theme.php +44 -0
•templates/layui/user/index.php +2 -7
变更内容
diff --git a/MPHX/plugin.php b/MPHX/plugin.php
index 3a460fc..eedd364 100644
--- a/MPHX/plugin.php
+++ b/MPHX/plugin.php
@@ -490,6 +490,91 @@ function mnbt_register_menu($side, $item)
 	return true;
 }
 
+/**
+ * 注册页面接管 —— 让插件接管或包裹主题整页渲染(mnbt_render 调用)
+ *
+ * 当 mnbt_render($view) 被调用时,引擎会按 priority 升序遍历所有注册的 override 回调,
+ * 第一个返回非 null 的值即生效,后续回调不再调用(短路语义)。
+ *
+ * @param string   $scope    'user' 或 'admin'
+ * @param string   $view     视图名(如 'set', 'list', 'sy', 'index')
+ * @param callable $callback 签名: function(array $vars): mixed
+ *                           返回值三选一:
+ *                           - null:                                    不接管(默认行为)
+ *                           - string:                                  完全接管,输出该字符串
+ *                           - ['before'=>string,'after'=>string]:      包裹模式,原视图前后插入内容
+ * @param int      $priority 优先级(数字越小越先执行),默认 10
+ * @return bool
+ *
+ * 示例 1:完全接管(替换整页)
+ *   mnbt_register_page_override('user', 'set', function ($vars) {
+ *       if (($_GET['gn'] ?? '') !== 'my_section') return null;
+ *       return '<div>我的自定义内容</div>';
+ *   });
+ *
+ * 示例 2:包裹模式(在原页面前后插入 banner)
+ *   mnbt_register_page_override('user', 'index', function ($vars) {
+ *       return [
+ *           'before' => '<div class="banner">公告</div>',
+ *           'after'  => '<script>console.log("page loaded")</script>',
+ *       ];
+ *   });
+ *
+ * 示例 3:按请求参数决定是否接管
+ *   mnbt_register_page_override('admin', 'list', function ($vars) {
+ *       if (($_GET['gn'] ?? '') === 'plugin_section') {
+ *           return render_my_plugin_page();
+ *       }
+ *       return null; // 其他 gn 走原逻辑
+ *   }, 5);
+ */
+function mnbt_register_page_override($scope, $view, $callback, $priority = 10)
+{
+	if (!is_callable($callback)) {
+		return false;
+	}
+	$scope = ($scope === 'admin') ? 'admin' : 'user';
+	$view = preg_replace('/[^a-zA-Z0-9_\-\/]/', '', (string)$view);
+	if ($view === '') {
+		return false;
+	}
+	return mnbt_add_filter('render.' . $scope . '.' . $view, $callback, $priority);
+}
+
+/**
+ * 注册 partial 接管 —— 让插件接管或包裹主题局部模板(mnbt_theme_include 调用)
+ *
+ * 当 mnbt_theme_include($view) 被调用时,引擎会按 priority 升序遍历所有注册的 override 回调,
+ * 第一个返回非 null 的值即生效,后续回调不再调用(短路语义)。
+ *
+ * @param string   $scope    'user' 或 'admin'
+ * @param string   $view     partial 名(如 'head', 'footer', 'sidebar')
+ * @param callable $callback 签名: function(array $vars): mixed
+ *                           返回值三选一:
+ *                           - null:                                    不接管(默认行为)
+ *                           - string:                                  完全接管,输出该字符串
+ *                           - ['before'=>string,'after'=>string]:      包裹模式,原 partial 前后插入内容
+ * @param int      $priority 优先级(数字越小越先执行),默认 10
+ * @return bool
+ *
+ * 示例:在用户端 head 末尾追加自定义 CSS
+ *   mnbt_register_partial_override('user', 'head', function ($vars) {
+ *       return ['after' => '<style>.my-plugin-banner{color:red}</style>'];
+ *   });
+ */
+function mnbt_register_partial_override($scope, $view, $callback, $priority = 10)
+{
+	if (!is_callable($callback)) {
+		return false;
+	}
+	$scope = ($scope === 'admin') ? 'admin' : 'user';
+	$view = preg_replace('/[^a-zA-Z0-9_\-\/]/', '', (string)$view);
+	if ($view === '') {
+		return false;
+	}
+	return mnbt_add_filter('include.' . $scope . '.' . $view, $callback, $priority);
+}
+
 function mnbt_plugin_option_get($slug, $key, $default = null)
 {
 	global $DB;
@@ -669,8 +754,8 @@ function _mnbt_plugin_render_menu_item($it, $depth = 0)
 	$icon  = htmlspecialchars($it['icon'] ?? 'mdi-puzzle', ENT_QUOTES, 'UTF-8');
 	if (!empty($it['children'])) {
 		$childrenHtml = _mnbt_plugin_render_menu_children($it['children'], $depth + 1);
-		return '<li class="nav-item-has-subnav">'
-			. ' <a href="javascript:void(0)"><i class="mdi ' . $icon . '"></i> <span>' . $title . '</span></a>'
+		return '<li class="nav-item nav-item-has-subnav">'
+			. '<a href="javascript:void(0)"><i class="mdi ' . $icon . '"></i> <span>' . $title . '</span></a>'
 			. '<ul class="nav nav-subnav">' . $childrenHtml . '</ul></li>';
 	}
 	$url = htmlspecialchars($it['url'] ?? 'javascript:void(0)', ENT_QUOTES, 'UTF-8');
@@ -690,21 +775,57 @@ function _mnbt_plugin_render_menu_children($children, $depth = 1)
 	return $html;
 }
 
-function mnbt_plugin_render_menu_side_html($side)
+/**
+ * 内部:将插件菜单树渲染成 default 主题的侧边栏 HTML(lyear 风格)。
+ * 作为未注册主题渲染器时的 fallback。
+ */
+function _mnbt_plugin_render_default_menu_html($side)
 {
 	$side = $side === 'admin' ? 'admin' : 'user';
 	$items = mnbt_plugin_menus($side);
 	if (!$items) {
 		return '';
 	}
-	$inner = '';
+	$groups = [];
+	$leafs = [];
 	foreach ($items as $it) {
-		$inner .= _mnbt_plugin_render_menu_item($it, 1);
+		if (!empty($it['children'])) {
+			$groups[] = $it;
+		} else {
+			$leafs[] = $it;
+		}
 	}
-	if ($inner === '') {
-		return '';
+	$html = '';
+	foreach ($groups as $group) {
+		$html .= _mnbt_plugin_render_menu_item($group, 1);
+	}
+	if (!empty($leafs)) {
+		$leafsHtml = _mnbt_plugin_render_menu_children($leafs, 1);
+		$html .= '<li class="nav-item nav-item-has-subnav">'
+			. '<a href="javascript:void(0)"><i class="mdi mdi-puzzle"></i> <span>插件管理</span></a>'
+			. '<ul class="nav nav-subnav">' . $leafsHtml . '</ul></li>';
+	}
+	return $html;
+}
+
+/**
+ * 渲染插件侧边栏菜单。
+ *
+ * 引擎优先使用当前主题注册的菜单渲染器(通过 mnbt_register_theme_menu_renderer)。
+ * 若当前主题没有注册渲染器,则回退到 default 主题结构(lyear 风格)。
+ *
+ * @param string $side 'user' 或 'admin'
+ * @return string
+ */
+function mnbt_plugin_render_menu_side_html($side)
+{
+	$side = $side === 'admin' ? 'admin' : 'user';
+	$renderer = $GLOBALS['mnbt_theme_menu_renderers'][$side] ?? null;
+	if (is_callable($renderer)) {
+		$items = mnbt_plugin_menus($side);
+		return (string)call_user_func($renderer, $items);
 	}
-	return '<li class="nav-item nav-item-has-subnav"> <a href="javascript:void(0)"> <i class="mdi mdi-puzzle"></i> <span>插件管理</span> </a><ul class="nav nav-subnav">' . $inner . '</ul></li>';
+	return _mnbt_plugin_render_default_menu_html($side);
 }
 
 function mnbt_plugin_render_menu_admin_html()
diff --git a/MPHX/theme.php b/MPHX/theme.php
index ed9c5a4..f241eb6 100644
--- a/MPHX/theme.php
+++ b/MPHX/theme.php
@@ -12,6 +12,9 @@ if (!defined('IN_CRONLITE')) {
 define('MNBT_THEME_ROOT', ROOT . 'templates/');
 define('MNBT_THEME_DEFAULT', 'default');
 
+// 主题可注册的菜单渲染器:scope => callback(array $items): string
+$GLOBALS['mnbt_theme_menu_renderers'] = ['user' => null, 'admin' => null];
+
 /**
  * 规范化主题名
  */
@@ -69,6 +72,7 @@ function mnbt_theme_resolve($view, $scope = 'user')
 		return null;
 	}
 
+	mnbt_theme_ensure_loaded($scope);
 	$theme = mnbt_theme_name($scope);
 	$candidates = [
 		MNBT_THEME_ROOT . $theme . '/' . $scope . '/' . $view . '.php',
@@ -142,29 +146,202 @@ function mnbt_asset_url($path = '')
 	return $path === '' ? '../imsetes/' : '../imsetes/' . $path;
 }
 
+/**
+ * 注册主题菜单渲染器。
+ *
+ * 每个主题在初始化时调用此函数,告诉引擎如何把自己作用域下的插件菜单树
+ * (由 mnbt_register_menu 注册)渲染成该主题侧边栏所需的 HTML。
+ *
+ * @param string   $scope    'user' 或 'admin'
+ * @param callable $callback 签名: function(array $items): string
+ *                           $items 是按 order 排好序的插件菜单树,每项含:
+ *                           - title, icon, url, order, multitabs
+ *                           - children: 子菜单数组(可选)
+ * @return bool
+ *
+ * 示例(layui 主题):
+ *   mnbt_register_theme_menu_renderer('user', function ($items) {
+ *       $html = '';
+ *       foreach ($items as $it) {
+ *           if (!empty($it['children'])) { ... 分组 ... }
+ *           else { ... 叶子 ... }
+ *       }
+ *       return $html;
+ *   });
+ */
+function mnbt_register_theme_menu_renderer($scope, $callback)
+{
+	if (!is_callable($callback)) {
+		return false;
+	}
+	$scope = ($scope === 'admin') ? 'admin' : 'user';
+	$GLOBALS['mnbt_theme_menu_renderers'][$scope] = $callback;
+	return true;
+}
+
+/**
+ * 确保当前主题的 theme.php 初始化文件已被加载。
+ *
+ * 引擎会在首次解析主题视图时自动调用本函数。主题开发者只需在
+ * templates/{theme}/theme.php 中注册渲染器,无需手动在 index.php 中引入。
+ */
+function mnbt_theme_ensure_loaded($scope = 'user')
+{
+	static $loaded = [];
+	$scope = ($scope === 'admin') ? 'admin' : 'user';
+	if (!empty($loaded[$scope])) {
+		return;
+	}
+	$loaded[$scope] = true;
+	$theme = mnbt_theme_name($scope);
+	$initFile = MNBT_THEME_ROOT . $theme . '/theme.php';
+	if (is_file($initFile)) {
+		include_once $initFile;
+	}
+}
+
+/**
+ * 内部辅助:按 priority 遍历 override filter,第一个返回非 null 的值即短路。
+ *
+ * 与 mnbt_apply_filters 不同,本函数不串联 filter 输出 —— 任何一个 filter 返回非 null
+ * 即停止后续 filter 调用。这样插件可以用低 priority "抢注" 接管,避免被高 priority 覆盖。
+ *
+ * @param string $hook filter 名
+ * @param array  $vars 传给回调的变量
+ * @return mixed|null 第一个非 null 返回值;全部返回 null 时为 null
+ */
+function _mnbt_theme_first_override($hook, array $vars)
+{
+	if (empty($GLOBALS['mnbt_plugin_filters'][$hook])) {
+		return null;
+	}
+	$buckets = $GLOBALS['mnbt_plugin_filters'][$hook];
+	ksort($buckets, SORT_NUMERIC);
+	foreach ($buckets as $list) {
+		foreach ($list as $item) {
+			$prev = $GLOBALS['mnbt_plugin_current'];
+			$GLOBALS['mnbt_plugin_current'] = $item['plugin'];
+			try {
+				$result = call_user_func($item['cb'], $vars);
+			} catch (Throwable $e) {
+				error_log('[MNBT theme] override ' . $hook . ' @' . $item['plugin'] . ': ' . $e->getMessage());
+				$result = null;
+			}
+			$GLOBALS['mnbt_plugin_current'] = $prev;
+			if ($result !== null) {
+				return $result;
+			}
+		}
+	}
+	return null;
+}
+
 /**
  * 引入主题局部模板
+ *
+ * 插件可通过 mnbt_register_partial_override() 注册 override(filter 名: include.{scope}.{view})
+ * 介入 partial 渲染流程。回调签名: function(array $vars): mixed
+ *
+ * 回调返回值的三种模式:
+ *   - null                                    → 不接管,继续加载原 partial(默认行为)
+ *   - string                                  → 完全接管,直接输出该字符串,跳过原 partial
+ *   - ['before' => string, 'after' => string] → 包裹模式,在原 partial 输出前后插入内容
+ *
+ * @param string $view  视图名
+ * @param array  $vars  传入模板的变量
+ * @param string $scope 'user' 或 'admin'
+ * @return bool 是否成功加载
  */
 function mnbt_theme_include($view, array $vars = [], $scope = 'user')
 {
+	$filterName = 'include.' . $scope . '.' . $view;
+	$override   = _mnbt_theme_first_override($filterName, $vars);
+
+	// 模式 1:完全接管
+	if (is_string($override)) {
+		echo $override;
+		return true;
+	}
+
+	// 解析包裹模式
+	$before = '';
+	$after  = '';
+	if (is_array($override)) {
+		$before = (string)($override['before'] ?? '');
+		$after  = (string)($override['after']  ?? '');
+	}
+
 	$path = mnbt_theme_resolve($view, $scope);
 	if ($path === null) {
+		if ($before !== '' || $after !== '') {
+			echo $before . $after;
+			return true;
+		}
 		trigger_error('Theme partial not found: ' . $scope . '/' . $view, E_USER_WARNING);
 		return false;
 	}
+
+	// 模式 2:包裹模式 - 输出 before
+	if ($before !== '') {
+		echo $before;
+	}
+
+	// 加载原 partial
 	extract($GLOBALS, EXTR_SKIP);
 	if ($vars) {
 		extract($vars, EXTR_OVERWRITE);
 	}
 	include $path;
+
+	// 模式 2:包裹模式 - 输出 after
+	if ($after !== '') {
+		echo $after;
+	}
 	return true;
 }
 
 /**
  * 渲染页面模板
+ *
+ * 插件可通过 mnbt_register_page_override() 注册 override(filter 名: render.{scope}.{view})
+ * 介入整页渲染流程。回调签名: function(array $vars): mixed
+ *
+ * 回调返回值的三种模式:
+ *   - null                                    → 不接管,继续加载原主题文件(默认行为)
+ *   - string                                  → 完全接管,直接输出该字符串,跳过原主题文件
+ *   - ['before' => string, 'after' => string] → 包裹模式,在原主题文件输出前后插入内容
+ *
+ * 多个插件注册同一 view 的 override 时,按 priority 升序执行,第一个返回非 null 的值生效,
+ * 后续 filter 不再调用(短路语义)。
+ *
+ * @param string $view  视图名
+ * @param array  $vars  传入模板的变量
+ * @param bool   $exit  渲染完成后是否 exit
+ * @param string $scope 'user' 或 'admin'
+ * @return bool
  */
 function mnbt_render($view, array $vars = [], $exit = true, $scope = 'user')
 {
+	$filterName = 'render.' . $scope . '.' . $view;
+	$override   = _mnbt_theme_first_override($filterName, $vars);
+
+	// 模式 1:完全接管
+	if (is_string($override)) {
+		echo $override;
+		if ($exit) {
+			exit;
+		}
+		return true;
+	}
+
+	// 解析包裹模式
+	$before = '';
+	$after  = '';
+	if (is_array($override)) {
+		$before = (string)($override['before'] ?? '');
+		$after  = (string)($override['after']  ?? '');
+	}
+
 	$path = mnbt_theme_resolve($view, $scope);
 	if ($path === null) {
 		http_response_code(500);
@@ -174,11 +351,24 @@ function mnbt_render($view, array $vars = [], $exit = true, $scope = 'user')
 		}
 		return false;
 	}
+
+	// 模式 2:before
+	if ($before !== '') {
+		echo $before;
+	}
+
+	// 加载原主题文件
 	extract($GLOBALS, EXTR_SKIP);
 	if ($vars) {
 		extract($vars, EXTR_OVERWRITE);
 	}
 	include $path;
+
+	// 模式 2:after
+	if ($after !== '') {
+		echo $after;
+	}
+
 	if ($exit) {
 		exit;
 	}
diff --git a/app_plugins/PLUGIN_DEV.md b/app_plugins/PLUGIN_DEV.md
index 35ba20d..f087e34 100644
--- a/app_plugins/PLUGIN_DEV.md
+++ b/app_plugins/PLUGIN_DEV.md
@@ -220,6 +220,7 @@ json_exit('提示文案');
 ### 3.4 菜单与页面
 
 ```php
+// 单个入口:会被自动归入「插件管理」分组
 mnbt_register_menu('admin', [
 	'title' => '标题',
 	'page' => 'settings',     // 自动生成 url: plugin.php?p=slug&page=settings
@@ -229,6 +230,17 @@ mnbt_register_menu('admin', [
 	'multitabs' => true,
 ]);
 
+// 独立分组(推荐:一个插件有多个入口时)
+mnbt_register_menu('user', [
+	'title'    => '域名服务',
+	'icon'     => 'mdi-web',
+	'order'    => 40,
+	'children' => [
+		['title' => '域名绑定', 'page' => 'bind', 'icon' => 'mdi-domain', 'multitabs' => true],
+		['title' => 'DNS 记录', 'page' => 'dns_records', 'icon' => 'mdi-dns', 'multitabs' => true],
+	],
+]);
+
 mnbt_register_page('admin', 'settings', 'admin/settings.php', '页面标题');
 mnbt_register_page('user', 'index', 'user/index.php', '用户页');
 ```
@@ -238,12 +250,97 @@ mnbt_register_page('user', 'index', 'user/index.php', '用户页');
 | 管理页 | `admin/plugin.php?p={slug}&page={page}` |
 | 用户页 | `user/plugin.php?p={slug}&page={page}` |
 
+**菜单渲染规则**:
+- 注册时带 `children` 的项 → 渲染为独立侧边栏分组(如「域名服务」)
+- 注册时不带 `children` 的项 → 统一归入「插件管理」分组
+- 分组和叶子项都按 `order` 升序排列
+
+**多主题适配**:
+- 插件只负责提供**菜单数据树**,不要写死 HTML 结构
+- 每个主题可注册自己的菜单渲染器(详见 `templates/THEME_DEV.md` §7.4)
+- 引擎会自动使用当前主题渲染器,未注册时回退到 default 主题结构
+- 因此插件新增/修改菜单项后,**无需修改任何主题文件**
+
 页面文件内可:
 
 - 管理端:`mnbt_admin_include('head');`
 - 用户端:`mnbt_theme_include('head');`(与 default 主题一致时)
 - 使用全局 `$DB`、`$conf`、`$yhc`(用户端)、`$islogin` / `$islogins`
 
+#### 3.4.1 页面接管(Page Override)
+
+让插件**接管或包裹已有主题页面的整页输出**,无需修改主题文件。当核心入口(`user/set.php`、`admin/list.php` 等)调用 `mnbt_render($view)` 时,引擎会按 priority 升序遍历所有注册的 override 回调,第一个返回非 null 的值即生效,后续回调不再调用(短路语义)。
+
+```php
+// 模式 1:完全接管(替换整页)
+mnbt_register_page_override('user', 'set', function ($vars) {
+    if (($_GET['gn'] ?? '') !== 'my_section') return null; // 其他 gn 走原逻辑
+    return '<div>我的自定义内容</div>';
+});
+
+// 模式 2:包裹模式(在原页面前后插入 banner)
+mnbt_register_page_override('user', 'index', function ($vars) {
+    return [
+        'before' => '<div class="banner">公告</div>',
+        'after'  => '<script>console.log("page loaded")</script>',
+    ];
+});
+
+// 模式 3:管理端接管 + 优先级控制
+mnbt_register_page_override('admin', 'list', function ($vars) {
+    if (($_GET['gn'] ?? '') === 'plugin_section') {
+        return render_my_plugin_page();
+    }
+    return null;
+}, 5); // priority=5,比默认 10 更早执行
+```
+
+| 参数 | 说明 |
+|------|------|
+| `scope` | `'user'` 或 `'admin'` |
+| `view` | 视图名(如 `'set'`、`'list'`、`'sy'`、`'index'`),对应 `mnbt_render($view)` 的参数 |
+| `callback` | 签名 `function(array $vars): mixed`,详见下方回调返回值 |
+| `priority` | 优先级(数字越小越先执行),默认 10 |
+
+**回调返回值(三选一)**:
+- `null` → 不接管,继续加载原主题文件(默认行为)
+- `string` → 完全接管,直接输出该字符串,跳过原主题文件
+- `['before' => string, 'after' => string]` → 包裹模式,在原主题文件输出前后插入内容(`before`/`after` 任一可省略)
+
+**多插件协作**:
+- 多个插件注册同一 view 的 override 时,按 priority 升序执行
+- 第一个返回非 null 的回调生效,后续回调不再调用(短路语义)
+- 想让某插件优先接管,给它更低的 priority(如 `5`、`1`)
+
+**适用场景**:
+- 插件化原核心功能(如接管 `set.php` 的某个 `gn` 分支)
+- 在所有页面注入全局 banner / 公告 / 统计代码(包裹模式 + 高 priority)
+- 替换整个页面输出(如自定义登录页、自定义后台首页)
+- 根据请求参数(`$_GET['gn']`)决定是否接管
+
+#### 3.4.2 Partial 接管(Partial Override)
+
+让插件**接管或包裹主题局部模板**(如 `head`、`footer`)的输出。当主题调用 `mnbt_theme_include($view)` 时,引擎会按 priority 升序遍历所有注册的 override 回调,第一个返回非 null 的值即生效。
+
+```php
+// 模式 1:完全接管 head
+mnbt_register_partial_override('user', 'head', function ($vars) {
+    return '<!-- 自定义 head -->...';
+});
+
+// 模式 2:在 head 末尾追加自定义 CSS(包裹模式)
+mnbt_register_partial_override('user', 'head', function ($vars) {
+    return ['after' => '<style>.my-plugin-banner{color:red}</style>'];
+});
+
+// 模式 3:在 footer 开头插入统计代码
+mnbt_register_partial_override('user', 'footer', function ($vars) {
+    return ['before' => '<script src="analytics.js"></script>'];
+});
+```
+
+参数与回调返回值与 `mnbt_register_page_override` 完全相同。
+
 ### 3.5 配置存储
 
 表:`MN_plugin_option`(`plugin_slug` + `k` + `v`)。
diff --git a/app_plugins/domain_shop/bootstrap.php b/app_plugins/domain_shop/bootstrap.php
index b8f1ec3..f68c647 100644
--- a/app_plugins/domain_shop/bootstrap.php
+++ b/app_plugins/domain_shop/bootstrap.php
@@ -21,25 +21,32 @@ mnbt_plugin_register('domain_shop', ['name' => '域名商品与 DNS 解析']);
  * 1. 后台菜单
  * ============================================================ */
 mnbt_register_menu('admin', [
-	'title' => '域名商品',
-	'page'  => 'products',
-	'icon'  => 'mdi-domain',
-	'order' => 30,
-	'multitabs' => true,
-]);
-mnbt_register_menu('admin', [
-	'title' => 'DNS 服务商',
-	'page'  => 'dns_provider',
-	'icon'  => 'mdi-dns',
-	'order' => 31,
-	'multitabs' => true,
-]);
-mnbt_register_menu('admin', [
-	'title' => 'DNS 记录',
-	'page'  => 'dns_records',
-	'icon'  => 'mdi-format-list-bulleted',
-	'order' => 32,
-	'multitabs' => true,
+	'title'    => '域名服务',
+	'icon'     => 'mdi-web',
+	'order'    => 30,
+	'children' => [
+		[
+			'title'     => '域名商品',
+			'page'      => 'products',
+			'icon'      => 'mdi-domain',
+			'order'     => 10,
+			'multitabs' => true,
+		],
+		[
+			'title'     => 'DNS 服务商',
+			'page'      => 'dns_provider',
+			'icon'      => 'mdi-dns',
+			'order'     => 20,
+			'multitabs' => true,
+		],
+		[
+			'title'     => 'DNS 记录',
+			'page'      => 'dns_records',
+			'icon'      => 'mdi-format-list-bulleted',
+			'order'     => 30,
+			'multitabs' => true,
+		],
+	],
 ]);
 
 mnbt_register_page('admin', 'products',      'admin/products.php',      '域名商品列表');
@@ -51,18 +58,25 @@ mnbt_register_page('admin', 'dns_records',   'admin/dns_records.php',   'DNS 记
  * 2. 用户端菜单(default 主题 sidebar 自动渲染)
  * ============================================================ */
 mnbt_register_menu('user', [
-	'title' => '我的 DNS 记录',
-	'page'  => 'dns_records',
-	'icon'  => 'mdi-dns',
-	'order' => 40,
-	'multitabs' => true,
-]);
-mnbt_register_menu('user', [
-	'title' => '域名绑定',
-	'page'  => 'bind',
-	'icon'  => 'mdi-domain',
-	'order' => 41,
-	'multitabs' => true,
+	'title'    => '域名服务',
+	'icon'     => 'mdi-web',
+	'order'    => 40,
+	'children' => [
+		[
+			'title'     => '域名绑定',
+			'page'      => 'bind',
+			'icon'      => 'mdi-domain',
+			'order'     => 10,
+			'multitabs' => true,
+		],
+		[
+			'title'     => '我的 DNS 记录',
+			'page'      => 'dns_records',
+			'icon'      => 'mdi-dns',
+			'order'     => 20,
+			'multitabs' => true,
+		],
+	],
 ]);
 mnbt_register_page('user', 'dns_records', 'user/dns_records.php', '我的 DNS 记录');
 mnbt_register_page('user', 'bind',        'user/bind.php',        '域名绑定');
@@ -305,3 +319,24 @@ mnbt_register_route('POST', '/domain/buy', function ($params, $ctx) {
 	require_once __DIR__ . '/lib/buy.php';
 	domain_shop_handle_buy();
 });
+
+/* ============================================================
+ * 11. 页面接管:set.php 的 gn=url 分支
+ *     通过 mnbt_register_page_override() 注册 filter,
+ *     当用户访问 set.php?gn=url 且非 CDN 产品时,
+ *     返回 iframe 加载插件 bind 页,替代原主题 set.php 的 url 分支。
+ *     其他 gn(CDN_url/pass/php/ssl 等)返回 null,走原主题逻辑。
+ *     此机制使所有主题(default/layui/bootstrapui/jqueryui)自动适配,
+ *     无需修改各主题的 set.php 文件。
+ * ============================================================ */
+mnbt_register_page_override('user', 'set', function ($vars) {
+	$gn = $_GET['gn'] ?? '';
+	if ($gn !== 'url') return null; // 仅接管 url 分支
+	global $yhc;
+	if (!isset($yhc) || !is_array($yhc)) return null;
+	if (($yhc['hxc'] ?? '') == '1') return null; // CDN 产品走原 CDN_url 分支
+	// 非泛解析产品:返回 iframe 加载插件域名绑定页
+	return '<div style="width:100%;height:calc(100vh - 120px);min-height:500px;padding:0;">'
+		. '<iframe src="plugin.php?p=domain_shop&page=bind" style="width:100%;height:100%;border:0;" frameborder="0" allowtransparency="true"></iframe>'
+		. '</div>';
+});
diff --git a/templates/THEME_DEV.md b/templates/THEME_DEV.md
index a72c82c..3614651 100644
--- a/templates/THEME_DEV.md
+++ b/templates/THEME_DEV.md
@@ -360,6 +360,69 @@ if (function_exists('mnbt_plugin_render_menu_user_html')) {
 
 管理端用 `mnbt_plugin_render_menu_admin_html()`。**必须保留**,否则插件菜单不会显示。
 
+### 7.4 插件菜单多主题适配(菜单渲染器)
+
+从 V1.82 起,引擎支持**主题注册自己的菜单渲染器**,解决"插件菜单在不同主题下结构不兼容"问题。
+
+**原理**:
+- 插件通过 `mnbt_register_menu('user', ...)` 注册的是**菜单数据树**(title/icon/url/order/children),不带 HTML 结构
+- 主题通过 `mnbt_register_theme_menu_renderer('user', $callback)` 注册**渲染器**,把这棵树转换成当前主题需要的 HTML
+- 主题 `index.php` 中调用 `mnbt_plugin_render_menu_user_html()` 时,引擎自动使用当前主题注册的渲染器
+- 若主题未注册渲染器,引擎回退到 default 主题(lyear)结构
+
+**主题开发者需要做的两件事**:
+
+1. 在主题根目录创建 `theme.php`,注册渲染器:
+
+```php
+<?php
+// templates/my_theme/theme.php
+if (!defined('IN_CRONLITE')) exit;
+
+mnbt_register_theme_menu_renderer('user', function ($items) {
+    $html = '';
+    foreach ($items as $it) {
+        $title = htmlspecialchars($it['title'] ?? '');
+        $icon  = htmlspecialchars($it['icon'] ?? 'mdi-puzzle');
+        if (!empty($it['children'])) {
+            // 分组
+            $html .= '<li class="my-submenu">'
+                   . '<a href="javascript:;"><i class="mdi ' . $icon . '"></i> ' . $title . '</a>'
+                   . '<ul class="my-subnav">';
+            foreach ($it['children'] as $child) {
+                $childTitle = htmlspecialchars($child['title'] ?? '');
+                $childUrl   = htmlspecialchars($child['url'] ?? 'javascript:void(0)');
+                $mt = !empty($child['multitabs']) || strpos($childUrl, 'plugin.php') !== false ? ' multitabs' : '';
+                $html .= '<li><a href="' . $childUrl . '" class="' . trim($mt) . '">' . $childTitle . '</a></li>';
+            }
+            $html .= '</ul></li>';
+        } else {
+            // 叶子项
+            $url = htmlspecialchars($it['url'] ?? 'javascript:void(0)');
+            $mt = !empty($it['multitabs']) || strpos($url, 'plugin.php') !== false ? ' multitabs' : '';
+            $html .= '<li><a href="' . $url . '" class="' . trim($mt) . '"><i class="mdi ' . $icon . '"></i> ' . $title . '</a></li>';
+        }
+    }
+    return $html;
+});
+```
+
+2. 在 `index.php` 的侧边栏合适位置调用:
+
+```php
+<?php
+if (function_exists('mnbt_plugin_render_menu_user_html')) {
+  echo mnbt_plugin_render_menu_user_html();
+}
+?>
+```
+
+**注意事项**:
+- `theme.php` 会在引擎首次解析该主题视图时**自动加载**(通过 `mnbt_theme_ensure_loaded`),无需手动 include
+- 叶子项建议统一归入一个分组(如「插件管理」),或按主题风格平铺
+- 必须给链接加 `multitabs` 类,才能让多标签插件正确接管
+- 管理端菜单同理,注册 `'admin'` scope 的渲染器
+
 ---
 
 ## 8. 主题引擎行为细节
@@ -384,6 +447,37 @@ if (function_exists('mnbt_plugin_render_menu_user_html')) {
 
 管理端同理(`admintheme` / `active_admin_theme`)。
 
+### 8.4 页面接管机制(Page Override)
+
+从 V1.82 起,主题引擎在 `mnbt_render()` 和 `mnbt_theme_include()` 中增加了**前置 override**机制,允许插件接管或包裹主题文件输出:
+
+| 引擎函数 | override 名 | 触发时机 |
+|----------|-------------|----------|
+| `mnbt_render($view)` | `render.{scope}.{view}` | 加载主题页面前 |
+| `mnbt_theme_include($view)` | `include.{scope}.{view}` | 加载 partial 前 |
+
+**回调返回值的三种模式**:
+- `null` → 不接管,主题文件照常加载(默认行为)
+- `string` → 完全接管,直接输出该字符串,主题文件**不会被执行**
+- `['before' => string, 'after' => string]` → 包裹模式,在主题文件输出前后插入内容
+
+**多插件协作**:
+- 按 priority 升序遍历,第一个返回非 null 的回调生效(短路语义)
+- 后续回调不再调用
+
+**典型场景**:
+- 完全接管:插件替换某页面分支(如 `set.php?gn=url`)
+- 包裹模式:在所有页面注入全局 banner / 公告 / 统计代码
+- 优先级控制:低 priority 抢注接管,高 priority 包裹装饰
+
+**主题开发者注意**:
+- 此机制**不影响**主题文件的编写,只是多了一个"被插件接管/包裹"的可能
+- 如果想让某页面**完全不被插件接管**,可在主题中直接 `include` 而非 `mnbt_render()`(不推荐,会破坏插件生态)
+- 完全接管模式下,插件返回的 HTML 通常已自带 `mnbt_theme_include('head')`,主题无需担心样式缺失
+- 包裹模式下,主题文件正常执行,插件只是在前后追加内容,不影响主题布局
+
+详见 `app_plugins/PLUGIN_DEV.md` §3.4.1。
+
 ---
 
 ## 9. 混合 UI 框架主题策略
diff --git a/templates/bootstrapui/theme.php b/templates/bootstrapui/theme.php
new file mode 100644
index 0000000..30b4276
--- /dev/null
+++ b/templates/bootstrapui/theme.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * BootstrapUI 主题初始化文件
+ * 引擎会在首次解析本主题视图时自动加载(通过 mnbt_theme_ensure_loaded)。
+ */
+if (!defined('IN_CRONLITE')) {
+	exit;
+}
+
+/**
+ * 渲染插件菜单树为 BootstrapUI 主题的侧边栏结构。
+ *
+ * @param array $items 插件菜单树(已按 order 排序)
+ * @return string
+ */
+mnbt_register_theme_menu_renderer('user', function ($items) {
+	if (empty($items)) {
+		return '';
+	}
+	$html = '';
+	$groupIdx = 0;
+	foreach ($items as $it) {
+		$title = htmlspecialchars($it['title'] ?? '', ENT_QUOTES, 'UTF-8');
+		$icon  = htmlspecialchars($it['icon'] ?? 'mdi-puzzle', ENT_QUOTES, 'UTF-8');
+		if (!empty($it['children'])) {
+			$groupId = 'bsui-plugin-sub-' . $groupIdx;
+			$groupIdx++;
+			$childrenHtml = '';
+			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');
+				$mt = !empty($child['multitabs']) || strpos($childUrl, 'plugin.php') !== false ? ' multitabs' : '';
+				$childrenHtml .= '<li><a class="bsui-subnav-link' . $mt . '" href="' . $childUrl . '"><i class="mdi ' . $childIcon . '"></i> ' . $childTitle . '</a></li>';
+			}
+			$html .= '<li class="bsui-nav-item">'
+				. '<a href="#' . $groupId . '" class="bsui-nav-link" data-toggle="collapse" role="button" aria-expanded="false">'
+				. '<i class="mdi ' . $icon . '"></i> ' . $title . ' <i class="mdi mdi-chevron-right arrow"></i></a>'
+				. '<ul class="collapse bsui-subnav" id="' . $groupId . '">' . $childrenHtml . '</ul></li>';
+		} else {
+			$url = htmlspecialchars($it['url'] ?? 'javascript:void(0)', ENT_QUOTES, 'UTF-8');
+			$mt = !empty($it['multitabs']) || strpos($url, 'plugin.php') !== false ? ' multitabs' : '';
+			$html .= '<li class="bsui-nav-item">'
+				. '<a href="' . $url . '" class="bsui-nav-link' . $mt . '"><i class="mdi ' . $icon . '"></i> ' . $title . '</a></li>';
+		}
+	}
+	return $html;
+});
diff --git a/templates/bootstrapui/user/index.php b/templates/bootstrapui/user/index.php
index d302ef8..01ef95f 100644
--- a/templates/bootstrapui/user/index.php
+++ b/templates/bootstrapui/user/index.php
@@ -46,21 +46,14 @@
           </a>
         </li>
 
-<?php if($yhc['hxc']=='1'){ ?>
         <li class="bsui-nav-item">
           <a href="#sub-basic" class="bsui-nav-link" data-toggle="collapse" role="button" aria-expanded="false">
             <i class="mdi mdi-console"></i> 基本配置 <i class="mdi mdi-chevron-right arrow"></i>
           </a>
           <ul class="collapse bsui-subnav" id="sub-basic">
+<?php if($yhc['hxc']=='1'){ ?>
             <li><a class="bsui-subnav-link multitabs" href="set.php?gn=CDN_url">域名修改</a></li>
-          </ul>
-        </li>
 <?php }else{ ?>
-        <li class="bsui-nav-item">
-          <a href="#sub-basic" class="bsui-nav-link" data-toggle="collapse" role="button" aria-expanded="false">
-            <i class="mdi mdi-console"></i> 基本配置 <i class="mdi mdi-chevron-right arrow"></i>
-          </a>
-          <ul class="collapse bsui-subnav" id="sub-basic">
             <li><a class="bsui-subnav-link multitabs" href="set.php?gn=php">PHP版本切换</a></li>
             <li><a class="bsui-subnav-link multitabs" href="set.php?gn=url">域名修改</a></li>
             <li><a class="bsui-subnav-link multitabs" href="set.php?gn=pass">设置密码访问</a></li>
@@ -72,6 +65,7 @@
             <li><a class="bsui-subnav-link multitabs" href="set.php?gn=gzip">Gzip配置</a></li>
             <li><a class="bsui-subnav-link multitabs" href="set.php?gn=cache">缓存配置</a></li>
             <li><a class="bsui-subnav-link multitabs" href="set.php?gn=xgpass">修改密码</a></li>
+<?php }?>
           </ul>
         </li>
         <li class="bsui-nav-item">
@@ -95,7 +89,6 @@
             <li><a class="bsui-subnav-link multitabs" href="notice.php">通知日志</a></li>
           </ul>
         </li>
-<?php }?>
 <?php
 if (function_exists('mnbt_plugin_render_menu_user_html')) {
   echo mnbt_plugin_render_menu_user_html();
diff --git a/templates/default/user/set.php b/templates/default/user/set.php
index a14b85f..7c991c9 100644
--- a/templates/default/user/set.php
+++ b/templates/default/user/set.php
@@ -340,12 +340,20 @@ elseif($set == "nginxrz")
     
 }
 elseif($set=='url' && $yhc['hxc']!='1'){
-// 域名绑定已迁移至 domain_shop 插件,此处通过 iframe 加载插件页面
-// 旧 url 分支的 PHP 逻辑($cert 查询、AJAX、表单、JS)已全部迁移到
-// app_plugins/domain_shop/user/bind.php 与 app_plugins/domain_shop/user/api/bind.php
+// 域名绑定已由 domain_shop 插件通过 mnbt_register_page_override('user','set') 接管
+// 正常情况下本分支不会执行(filter 在 mnbt_render() 阶段已返回 iframe)
+// 此处保留占位符,仅在插件未启用时作为 fallback 提示
 ?>
-<div style="width:100%;height:calc(100vh - 120px);min-height:500px;padding:0;">
-  <iframe src="plugin.php?p=domain_shop&page=bind" style="width:100%;height:100%;border:0;" frameborder="0" allowtransparency="true"></iframe>
+<div class="container" style="padding-top:5%;">
+  <div class="col-sm-6">
+    <div class="card">
+      <div class="card-header"><h4>域名绑定</h4></div>
+      <div class="card-body">
+        <p class="text-muted">域名绑定功能由 domain_shop 插件提供。</p>
+        <p class="text-muted">请联系管理员启用该插件,或前往 <a href="plugin.php?p=domain_shop&page=bind">域名绑定页</a> 直接访问。</p>
+      </div>
+    </div>
+  </div>
 </div>
 <?php }elseif($set=='pass'){
 $cert=$DB->get_row_prepare("SELECT * FROM MN_bt WHERE btdh=? limit 1", [$ssbt]);
diff --git a/templates/jqueryui/theme.php b/templates/jqueryui/theme.php
new file mode 100644
index 0000000..279c4b6
--- /dev/null
+++ b/templates/jqueryui/theme.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * jQueryUI 主题初始化文件
+ * 引擎会在首次解析本主题视图时自动加载(通过 mnbt_theme_ensure_loaded)。
+ */
+if (!defined('IN_CRONLITE')) {
+	exit;
+}
+
+/**
+ * 渲染插件菜单树为 jQueryUI 主题的侧边栏结构。
+ *
+ * 该主题使用 jQueryUI accordion,每个分组都是 <h3> + <div><ul class="jqui-subnav">...</ul></div>。
+ * 叶子项统一归入「插件管理」分组。
+ *
+ * @param array $items 插件菜单树(已按 order 排序)
+ * @return string
+ */
+mnbt_register_theme_menu_renderer('user', function ($items) {
+	if (empty($items)) {
+		return '';
+	}
+	$groups = [];
+	$leafs = [];
+	foreach ($items as $it) {
+		if (!empty($it['children'])) {
+			$groups[] = $it;
+		} else {
+			$leafs[] = $it;
+		}
+	}
+	$html = '';
+	foreach ($groups as $it) {
+		$title = htmlspecialchars($it['title'] ?? '', ENT_QUOTES, 'UTF-8');
+		$icon  = htmlspecialchars($it['icon'] ?? 'mdi-puzzle', ENT_QUOTES, 'UTF-8');
+		$childrenHtml = '';
+		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');
+			$mt = !empty($child['multitabs']) || strpos($childUrl, 'plugin.php') !== false ? ' multitabs' : '';
+			$childrenHtml .= '<li><a class="' . trim($mt) . '" href="' . $childUrl . '"><i class="mdi ' . $childIcon . '"></i> ' . $childTitle . '</a></li>';
+		}
+		$html .= '<h3><i class="mdi ' . $icon . '"></i> ' . $title . '</h3>'
+			. '<div><ul class="jqui-subnav">' . $childrenHtml . '</ul></div>';
+	}
+	if (!empty($leafs)) {
+		$leafsHtml = '';
+		foreach ($leafs as $it) {
+			$title = htmlspecialchars($it['title'] ?? '', ENT_QUOTES, 'UTF-8');
+			$icon  = htmlspecialchars($it['icon'] ?? 'mdi-puzzle', ENT_QUOTES, 'UTF-8');
+			$url   = htmlspecialchars($it['url'] ?? 'javascript:void(0)', ENT_QUOTES, 'UTF-8');
+			$mt = !empty($it['multitabs']) || strpos($url, 'plugin.php') !== false ? ' multitabs' : '';
+			$leafsHtml .= '<li><a class="' . trim($mt) . '" href="' . $url . '"><i class="mdi ' . $icon . '"></i> ' . $title . '</a></li>';
+		}
+		$html .= '<h3><i class="mdi mdi-puzzle"></i> 插件管理</h3>'
+			. '<div><ul class="jqui-subnav">' . $leafsHtml . '</ul></div>';
+	}
+	return $html;
+});
diff --git a/templates/jqueryui/user/index.php b/templates/jqueryui/user/index.php
index 86ee284..6950001 100644
--- a/templates/jqueryui/user/index.php
+++ b/templates/jqueryui/user/index.php
@@ -44,7 +44,6 @@
 
     <!-- jQueryUI accordion 主导航 -->
     <div id="jqui-sidebar-accordion">
-<?php if($yhc['hxc']=='1'){ ?>
       <h3><i class="mdi mdi-home"></i> 控制面板</h3>
       <div>
         <ul class="jqui-subnav">
@@ -54,19 +53,9 @@
       <h3><i class="mdi mdi-console"></i> 基本配置</h3>
       <div>
         <ul class="jqui-subnav">
+<?php if($yhc['hxc']=='1'){ ?>
           <li><a class="multitabs" href="set.php?gn=CDN_url">域名修改</a></li>
-        </ul>
-      </div>
 <?php }else{ ?>
-      <h3><i class="mdi mdi-home"></i> 控制面板</h3>
-      <div>
-        <ul class="jqui-subnav">
-          <li><a href="sy.php" class="multitabs">控制面板</a></li>
-        </ul>
-      </div>
-      <h3><i class="mdi mdi-console"></i> 基本配置</h3>
-      <div>
-        <ul class="jqui-subnav">
           <li><a class="multitabs" href="set.php?gn=php">PHP版本切换</a></li>
           <li><a class="multitabs" href="set.php?gn=url">域名修改</a></li>
           <li><a class="multitabs" href="set.php?gn=pass">设置密码访问</a></li>
@@ -78,6 +67,7 @@
           <li><a class="multitabs" href="set.php?gn=gzip">Gzip配置</a></li>
           <li><a class="multitabs" href="set.php?gn=cache">缓存配置</a></li>
           <li><a class="multitabs" href="set.php?gn=xgpass">修改密码</a></li>
+<?php }?>
         </ul>
       </div>
       <h3><i class="mdi mdi-format-align-justify"></i> 数据管理</h3>
@@ -97,7 +87,6 @@
           <li><a class="multitabs" href="notice.php">通知日志</a></li>
         </ul>
       </div>
-<?php }?>
 <?php
 if (function_exists('mnbt_plugin_render_menu_user_html')) {
   echo mnbt_plugin_render_menu_user_html();
diff --git a/templates/layui/theme.php b/templates/layui/theme.php
new file mode 100644
index 0000000..f764919
--- /dev/null
+++ b/templates/layui/theme.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Layui 主题初始化文件
+ * 引擎会在首次解析本主题视图时自动加载(通过 mnbt_theme_ensure_loaded)。
+ */
+if (!defined('IN_CRONLITE')) {
+	exit;
+}
+
+/**
+ * 渲染插件菜单树为 Layui 主题的侧边栏结构。
+ *
+ * @param array $items 插件菜单树(已按 order 排序)
+ * @return string
+ */
+mnbt_register_theme_menu_renderer('user', function ($items) {
+	if (empty($items)) {
+		return '';
+	}
+	$html = '';
+	foreach ($items as $it) {
+		$title = htmlspecialchars($it['title'] ?? '', ENT_QUOTES, 'UTF-8');
+		$icon  = htmlspecialchars($it['icon'] ?? 'mdi-puzzle', ENT_QUOTES, 'UTF-8');
+		if (!empty($it['children'])) {
+			$childrenHtml = '';
+			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');
+				$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>';
+			}
+			$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>'
+				. '<ul class="ly-submenu-list">' . $childrenHtml . '</ul></li>';
+		} else {
+			$url = htmlspecialchars($it['url'] ?? 'javascript:void(0)', ENT_QUOTES, 'UTF-8');
+			$mt = !empty($it['multitabs']) || strpos($url, 'plugin.php') !== false ? ' multitabs' : '';
+			$html .= '<li class="ly-menu-item">'
+				. '<a href="' . $url . '" class="' . trim($mt) . '"><i class="mdi ' . $icon . '"></i><span>' . $title . '</span></a></li>';
+		}
+	}
+	return $html;
+});
diff --git a/templates/layui/user/index.php b/templates/layui/user/index.php
index 2e33635..0edfe53 100644
--- a/templates/layui/user/index.php
+++ b/templates/layui/user/index.php
@@ -46,17 +46,12 @@
         <li class="ly-menu-item">
           <a href="site_stats.php" class="multitabs"><i class="mdi mdi-chart-bar"></i><span>站点统计</span></a>
         </li>
-<?php if($yhc['hxc']=='1'){ ?>
         <li class="ly-menu-item ly-submenu">
           <a href="javascript:;"><i class="mdi mdi-console"></i><span>基本配置</span><i class="mdi mdi-chevron-right ly-arrow"></i></a>
           <ul class="ly-submenu-list">
+<?php if($yhc['hxc']=='1'){ ?>
             <li><a href="set.php?gn=CDN_url" class="multitabs">域名修改</a></li>
-          </ul>
-        </li>
 <?php }else{ ?>
-        <li class="ly-menu-item ly-submenu">
-          <a href="javascript:;"><i class="mdi mdi-console"></i><span>基本配置</span><i class="mdi mdi-chevron-right ly-arrow"></i></a>
-          <ul class="ly-submenu-list">
             <li><a href="set.php?gn=php" class="multitabs">PHP版本切换</a></li>
             <li><a href="set.php?gn=url" class="multitabs">域名修改</a></li>
             <li><a href="set.php?gn=pass" class="multitabs">设置密码访问</a></li>
@@ -68,6 +63,7 @@
             <li><a href="set.php?gn=gzip" class="multitabs">Gzip配置</a></li>
             <li><a href="set.php?gn=cache" class="multitabs">缓存配置</a></li>
             <li><a href="set.php?gn=xgpass" class="multitabs">修改密码</a></li>
+<?php }?>
           </ul>
         </li>
         <li class="ly-menu-item ly-submenu">
@@ -87,7 +83,6 @@
             <li><a href="notice.php" class="multitabs">通知日志</a></li>
           </ul>
         </li>
-<?php }?>
 <?php
 if (function_exists('mnbt_plugin_render_menu_user_html')) {
   echo mnbt_plugin_render_menu_user_html();