123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- // +----------------------------------------------------------------------
- // | framework
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://framework.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | github开源项目:https://github.com/zoujingli/framework
- // +----------------------------------------------------------------------
- namespace app\admin\controller;
- use library\Controller;
- use library\tools\Data;
- use think\Db;
- /**
- * 系统菜单管理
- * Class Menu
- * @package app\admin\controller
- */
- class Menu extends Controller
- {
- /**
- * 当前操作数据库
- * @var string
- */
- protected $table = 'SystemMenu';
- /**
- * 系统菜单管理
- */
- public function index()
- {
- $this->title = '系统菜单管理';
- $this->_page($this->table, false);
- }
- /**
- * 列表数据处理
- * @param array $data
- */
- protected function _index_page_filter(&$data)
- {
- foreach ($data as &$vo) {
- if ($vo['url'] !== '#') {
- $vo['url'] = url($vo['url']) . (empty($vo['params']) ? '' : "?{$vo['params']}");
- }
- $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id']));
- }
- $data = Data::arr2table($data);
- }
- /**
- * 添加系统菜单
- */
- public function add()
- {
- $this->applyCsrfToken();
- $this->_form($this->table, 'form');
- }
- /**
- * 编辑系统菜单
- */
- public function edit()
- {
- $this->applyCsrfToken();
- $this->_form($this->table, 'form');
- }
- /**
- * 表单数据处理
- * @param array $vo
- * @throws \ReflectionException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _form_filter(&$vo)
- {
- if ($this->request->isGet()) {
- // 上级菜单处理
- $_menus = Db::name($this->table)->where(['status' => '1'])->order('sort asc,id asc')->select();
- $_menus[] = ['title' => '顶级菜单', 'id' => '0', 'pid' => '-1'];
- $menus = Data::arr2table($_menus);
- foreach ($menus as $key => &$menu) if (substr_count($menu['path'], '-') > 3) unset($menus[$key]); # 移除三级以下的菜单
- elseif (isset($vo['pid']) && $vo['pid'] !== '' && $cur = "-{$vo['pid']}-{$vo['id']}")
- if (stripos("{$menu['path']}-", "{$cur}-") !== false || $menu['path'] === $cur) unset($menus[$key]); # 移除与自己相关联的菜单
- // 选择自己的上级菜单
- if (!isset($vo['pid']) && $this->request->get('pid', '0')) $vo['pid'] = $this->request->get('pid', '0');
- // 读取系统功能节点
- $nodes = \app\admin\service\AuthService::get();
- foreach ($nodes as $key => $node) {
- if (empty($node['is_menu'])) unset($nodes[$key]);
- unset($nodes[$key]['pnode'], $nodes[$key]['is_login'], $nodes[$key]['is_menu'], $nodes[$key]['is_auth']);
- }
- list($this->menus, $this->nodes) = [$menus, array_values($nodes)];
- }
- }
- /**
- * 启用系统菜单
- */
- public function resume()
- {
- $this->applyCsrfToken();
- $this->_save($this->table, ['status' => '1']);
- }
- /**
- * 禁用系统菜单
- */
- public function forbid()
- {
- $this->applyCsrfToken();
- $this->_save($this->table, ['status' => '0']);
- }
- /**
- * 删除系统菜单
- */
- public function remove()
- {
- $this->applyCsrfToken();
- $this->_delete($this->table);
- }
- }
|