Merge pull request #6 from liupengfeicode/master

1.系统菜单增加顶级菜单选项卡,方便复杂菜单管理;
2.增加系统自定义图标,自用图标方便更新
This commit is contained in:
邹景立 2025-02-15 19:42:55 +08:00 committed by GitHub
commit 673479e9b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 55 additions and 3 deletions

View File

@ -44,6 +44,12 @@ class Menu extends Controller
{
$this->title = '系统菜单管理';
$this->type = $this->get['type'] ?? 'index';
// 获取顶级菜单ID
$this->pid = $this->get['pid'] ?? '';
// 查询顶级菜单集合
$this->menup_list = SystemMenu::mk()->where(['pid' => 0, 'status' => 1])->order('sort desc,id asc')->column('id,pid,title', 'id');
SystemMenu::mQuery()->layTable();
}
@ -66,6 +72,14 @@ class Menu extends Controller
}
// 菜单数据树数据变平化
$data = DataExtend::arr2table($data);
// 过滤非当前顶级菜单的下级菜单,并重新索引数组
if ($this->type === 'index' && $this->pid) {
$data = array_values(array_filter($data, function ($item) {
return strpos($item['spp'], ",{$this->pid},") !== false;
}));
}
foreach ($data as &$vo) {
if ($vo['url'] !== '#' && !preg_match('/^(https?:)?(\/\/|\\\\)/i', $vo['url'])) {
$vo['url'] = trim(url($vo['url']) . ($vo['params'] ? "?{$vo['params']}" : ''), '\\/');

View File

@ -55,6 +55,27 @@ class Plugs extends Controller
}
}
}
// 读取extra自定义字体图标
if (empty($this->extraIcons = $this->app->cache->get('ThinkAdminExtraIcons', []))) {
$style = file_get_contents(syspath('public/static/extra/icon/iconfont.css'));
if (preg_match_all('#\.(iconfont-[\w-]+):#', $style, $matches)) {
if (count($this->thinkIcons = $matches[1]) > 0) {
$this->app->cache->set('ThinkAdminExtraIcons', $this->extraIcons, 60);
}
}
}
// 读取extra自定义字体图标
if (empty($this->extraIcons = $this->app->cache->get('ThinkAdminExtraIcons', []))) {
$extraIconPath = syspath('public/static/extra/icon/iconfont.css');
if (file_exists($extraIconPath)) {
$style = file_get_contents($extraIconPath);
if (preg_match_all('#\.(iconfont-[\w-]+):#', $style, $matches)) {
if (count($this->extraIcons = $matches[1]) > 0) {
$this->app->cache->set('ThinkAdminExtraIcons', $this->extraIcons, 60);
}
}
}
}
$this->field = $this->app->request->get('field', 'icon');
$this->fetch(dirname(__DIR__, 2) . '/view/api/icon.html');
}

View File

@ -11,6 +11,9 @@
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<link rel="stylesheet" href="__ROOT__/static/theme/css/iconfont.css?at={:date('md')}">
<link rel="stylesheet" href="__ROOT__/static/plugs/layui/css/layui.css?v={:date('ymd')}">
{if file_exists(syspath("public/static/extra/icon/iconfont.css"))}
<link rel="stylesheet" href="__ROOT__/static/extra/icon/iconfont.css?at={:date('md')}">
{/if}
<style>
::-webkit-input-placeholder {
color: #aaa
@ -96,6 +99,12 @@
<body>
<ul>
{foreach $extraIcons??[] as $icon}
<li>
<i class="iconfont {$icon}"></i>
<div class="icon-title">{$icon}</div>
</li>
{/foreach}
{foreach $layuiIcons??[] as $icon}
<li>
<i class="layui-icon {$icon}"></i>

View File

@ -12,6 +12,9 @@
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=0.4">
<link rel="stylesheet" href="__ROOT__/static/plugs/layui/css/layui.css?at={:date('md')}">
<link rel="stylesheet" href="__ROOT__/static/theme/css/iconfont.css?at={:date('md')}">
{if file_exists(syspath("public/static/extra/icon/iconfont.css"))}
<link rel="stylesheet" href="__ROOT__/static/extra/icon/iconfont.css?at={:date('md')}">
{/if}
<link rel="stylesheet" href="__ROOT__/static/theme/css/console.css?at={:date('md')}">
<link rel="stylesheet" href="__ROOT__/static/extra/style.css?at={:date('md')}">
{block name="style"}{/block}

View File

@ -17,12 +17,17 @@
{block name="content"}
<div class="layui-tab layui-tab-card">
<ul class="layui-tab-title">
{foreach ['index'=>lang('系统菜单'),'recycle'=>lang('回 收 站')] as $k=>$v}
{if isset($type) and $type eq $k}
{foreach ['index'=>lang('全部菜单'),'recycle'=>lang('回 收 站')] as $k=>$v}
{if isset($type) and $type eq $k and isset($pid) and $pid == ''}
<li class="layui-this" data-open="{:url('index')}?type={$k}">{$v}</li>
{else}
<li data-open="{:url('index')}?type={$k}">{$v}</li>
{/if}{/foreach}
<!--顶级菜单-->
<!--{foreach $menup_list as $k=>$v}-->
<li data-open="{:url('index')}?type=index&pid={$v.id}" {if isset($pid) and $pid eq $v.id}class="layui-this"{/if} >{$v.title}</li>
<!--{/foreach}-->
</ul>
<div class="layui-tab-content">
<table id="MenuTable" data-url="{:request()->url()}" data-target-search="form.form-search"></table>
@ -34,7 +39,7 @@
$('#MenuTable').layTable({
even: true, height: 'full', page: false,
sort: {field: 'sort desc,id', type: 'asc'},
where: {type: '{$type|default="index"}'},
where: {type: '{$type|default="index"}', pid: '{$pid|default=""}'},
filter: function (items) {
var type = this.where.type;
return items.filter(function (item) {