代码拉取完成,页面将自动刷新
9
权限目录遍历归属上下级不精确
开启的
权限目录遍历归属上下级不精确,例如match.user 会归类到user下面:
1.app/admin/model/SystemNode.php
protected function buildNodeTree($list)
{
$newList = [];
$repeatString = " ";
foreach ($list as $vo) {
if ($vo['type'] == 1) {
$newList[] = $vo;
foreach ($list as $v) {
//第二个参数是被查找的元素
/* if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
$v['node'] = "{$repeatString}├{$repeatString}" . $v['node'];
$newList[] = $v;
}*/
//这种判断太肤浅啦
//改为从开始位置判断 好像可以了
$length = strlen($vo['node']);
$head = substr($v['node'],0,$length);
if ($v['type'] == 2 && $head == $vo['node'] && strpos($v['node'], $vo['node'] . '/') !== false) {
$v['node'] = "{$repeatString}├{$repeatString}" . $v['node'];
$newList[] = $v;
}
}
}
}
return $newList;
}
2.app/admin/model/SystemAuth.php
/**
* 根据角色ID获取授权节点
* @param $authId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAuthorizeNodeListByAdminId($authId)
{
$checkNodeList = (new SystemAuthNode())
->where('auth_id', $authId)
->column('node_id');
$systemNode = new SystemNode();
$nodelList = $systemNode
->where('is_auth', 1)
->field('id,node,title,type,is_auth')
->select()
->toArray();
$newNodeList = [];
foreach ($nodelList as $vo) {
if ($vo['type'] == 1) {
$vo = array_merge($vo, ['field' => 'node', 'spread' => true]);
$vo['checked'] = false;
$vo['title'] = "{$vo['title']}【{$vo['node']}】";
$children = [];
foreach ($nodelList as $v) {
$length = strlen($vo['node']);
$head = substr($v['node'],0,$length);
if ($v['type'] == 2&& $head == $vo['node'] && strpos($v['node'], $vo['node'] . '/') !== false) {
$v = array_merge($v, ['field' => 'node', 'spread' => true]);
$v['checked'] = in_array($v['id'], $checkNodeList) ? true : false;
$v['title'] = "{$v['title']}【{$v['node']}】";
$children[] = $v;
}
}
!empty($children) && $vo['children'] = $children;
$newNodeList[] = $vo;
}
}
return $newNodeList;
}