权限表结构

CREATE TABLE `blog_auth` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '序号',
`pid` int(11) NOT NULL COMMENT '父级ID',
`auth_name` varchar(191) NOT NULL COMMENT '权限名字',
`auth_title` varchar(191) NOT NULL COMMENT '权限标题',
`auth_icon` varchar(191) DEFAULT NULL COMMENT '权限图标',
`auth_rule` varchar(191) NOT NULL COMMENT '权限路径',
`menu` tinyint(1) NOT NULL COMMENT '菜单 1=>显示菜单,0=>不显示菜单',
`debug` tinyint(1) NOT NULL COMMENT '调试模式 1-->仅调试模式显示,0-->任何时候都显示',
`create_by` int(11) NOT NULL COMMENT '创建人',
`update_by` int(11) NOT NULL COMMENT '更新人',
`create_time` int(11) NOT NULL COMMENT '创建时间',
`update_time` int(11) NOT NULL COMMENT '更新时间',
`delete_time` int(11) NOT NULL COMMENT '删除时间',
`sort` int(11) NOT NULL COMMENT '排序字段',
`status` tinyint(1) NOT NULL COMMENT '状态',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

相关代码

 /**
* @title 菜单列表
* @param int $uid
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getMenuList($uid = 0)
{//展示只有菜单类型的权限列表
$auth_list_info = Db::name('auth')->field(['id','pid','auth_title','auth_rule'])->select();
if ($auth_list_info === null){return [];}
$auth_list_info = is_array($auth_list_info) ? $auth_list_info : $auth_list_info->toArray();
return $this->getSonsInfo($auth_list_info);
} /**
* @title 菜单树生成
* @param array $items - 数据
* @param int $pid - 父级ID的值
* @param int $deep - 深度
* @return array
*/
protected function getSonsInfo(array $items,$pid=0,$deep=0)
{
$lists = [];
foreach ($items as $item){
if ($item['pid'] === $pid){
$item['deep'] = $deep;
$item['son'] = $this->getSonsInfo($items,$item['id'],$deep+1);
$lists[] = $item;
}
}
return $lists;
}

打印结果

Array ( [0] => Array ( [id] => 1 [pid] => 0 [auth_title] => 博客后台人员账户 [auth_rule] => backend/account/default [deep] => 0 [son] => Array ( [0] => Array ( [id] => 2 [pid] => 1 [auth_title] => 博客后台人员账户列表页 [auth_rule] => backend/account/index [deep] => 1 [son] => Array ( ) ) ) ) [1] => Array ( [id] => 9 [pid] => 0 [auth_title] => 博客后台首页 [auth_rule] => backend/index/default [deep] => 0 [son] => Array ( [0] => Array ( [id] => 10 [pid] => 9 [auth_title] => 博客后台首页 [auth_rule] => backend/index/index [deep] => 1 [son] => Array ( ) ) ) ) [2] => Array ( [id] => 19 [pid] => 0 [auth_title] => 博客后台文章管理 [auth_rule] => backend/article/default [deep] => 0 [son] => Array ( [0] => Array ( [id] => 20 [pid] => 19 [auth_title] => 博客后台文章列表页 [auth_rule] => backend/article/index [deep] => 1 [son] => Array ( ) ) ) ) )

最新文章

  1. 【leetcode】Minimum Depth of Binary Tree
  2. jQuery easyui combobox获取值|easyui-combobox获取多个值
  3. RCP:【转载】插件无法启动的解决方案
  4. IOS开发之——类似微信摇一摇的功能实现
  5. [C语言]一个很实用的服务端和客户端进行TCP通信的实例
  6. Python核心编程--学习笔记--6--序列(上)字符串
  7. 移动端页面的head头部内容
  8. IIS 发布网站遇到的问题
  9. Brackets 配置
  10. iOS常见异常Exec_Bad_Access问题解决办法
  11. 点击Input框弹出日期选项
  12. h5页面 video暂停播放 视频控件 以及当前页面只有一个可以播放效果
  13. Android第一次作业
  14. 集成Android人脸识别demo分享
  15. IIS6下使用多域名和通配符证书
  16. Android 开发 框架系列 OkHttp使用详解
  17. python学习笔记之斐波拉契数列学习
  18. Retrofit使用指南
  19. mysql构建一张百万级别数据的表信息测试
  20. MQTT---HiveMQ源代码具体解释(七)Netty-SSL/NoSSL

热门文章

  1. windows下去掉快捷方式图标的小箭头的几种方法
  2. vue后台_登录权限
  3. You can't specify target table 'a' for update in FROM clause
  4. linux调用库的方式
  5. SQL优化 | sql执行过长的时间,如何优化?
  6. treeview所有节点递归解法及注意!!!!!!!!!!!!!!!!!
  7. 利用sorket实现聊天功能-服务端实现
  8. 在Win7下玩PC游戏发生类似d3d9x_43.dll找不到的情况
  9. Python - social-auth-app-django 模块 - 商城项目 第三方方式登录 - 微博
  10. 11Flutter页面布局 Stack层叠组件 Stack与Align Stack与Positioned实现定位布局