修改菜单编辑模块

This commit is contained in:
Anyon 2019-11-27 14:43:49 +08:00
parent e016a227cc
commit b13b8e4bfc
2 changed files with 13 additions and 20 deletions

View File

@ -91,27 +91,19 @@ class Menu extends Controller
* 表单数据处理
* @param array $vo
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function _form_filter(&$vo)
{
if ($this->request->isGet()) {
// 选择自己的上级菜单
if (empty($vo['pid']) && $this->request->get('pid', '0')) {
$vo['pid'] = $this->request->get('pid', '0');
}
// 读取系统功能节点
$this->nodes = MenuService::instance()->getList();
// 选择自己的上级菜单
if (empty($vo['pid']) && $this->request->get('pid', '0')) $vo['pid'] = $this->request->get('pid', '0');
// 列出可选上级菜单
$menus = $this->app->db->name($this->table)->where(['status' => '1'])->order('sort desc,id asc')->select()->toArray();
$menus[] = ['title' => '顶菜单', 'id' => '0', 'pid' => '-1'];
$menus = $this->app->db->name($this->table)->where(['status' => '1'])->order('sort desc,id asc')->column('id,pid,title');
$menus[] = ['title' => '顶菜单', 'id' => '0', 'pid' => '-1'];
foreach ($this->menus = DataExtend::arr2table($menus) as $key => &$menu) {
if (substr_count($menu['path'], '-') > 3) unset($this->menus[$key]); # 移除三级以下的菜单
elseif (isset($vo['pid']) && $vo['pid'] !== '' && $cur = "-{$vo['pid']}-{$vo['id']}") {
if (stripos("{$menu['path']}-", "{$cur}-") !== false || $menu['path'] === $cur) unset($this->menus[$key]); # 移除与自己相关联的菜单
}
if ($menu['spt'] >= 3) unset($this->menus[$key]);
}
}
}

View File

@ -3,16 +3,16 @@
<div class="layui-card-body">
<div class="layui-form-item">
<label class="layui-form-label">上级菜单</label>
<label class="layui-form-label label-required-next">上级菜单</label>
<div class="layui-input-block">
<select name='pid' class='layui-select full-width' lay-ignore>
<!--{foreach $menus as $menu}-->
<!--{eq name='menu.id' value='$vo.pid|default=0'}-->
<select name='pid' class='layui-select' lay-search>
{foreach $menus as $menu}
{eq name='menu.id' value='$vo.pid|default=0'}
<option selected value='{$menu.id}'>{$menu.spl|raw}{$menu.title}</option>
<!--{else}-->
{else}
<option value='{$menu.id}'>{$menu.spl|raw}{$menu.title}</option>
<!--{/eq}-->
<!--{/foreach}-->
{/eq}
{/foreach}
</select>
<p class="help-block">必选,请选择上级菜单或顶级菜单(目前最多支持三级菜单)</p>
</div>
@ -74,6 +74,7 @@
{block name='script'}
<script>
require(['jquery.autocompleter'], function () {
layui.form.render();
$('[name="icon"]').on('change', function () {
$(this).parent().next().find('i').get(0).className = this.value
});