切换导航条
此项目
正在载入...
登录
何书鹏
/
anttest
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
Karson
8 years ago
提交
725782cf7ba3da926558a0fb7b2829a93b045baa
1 个父辈
3f42ab8b
移除了Menu类
修复在PHP5.5下类冲突的BUG
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
66 行增加
和
169 行删除
application/admin/controller/Index.php
application/admin/lang/zh-cn/general/database.php
application/admin/library/Auth.php
extend/fast/Menu.php
application/admin/controller/Index.php
查看文件 @
725782c
...
...
@@ -3,7 +3,6 @@
namespace
app\admin\controller
;
use
app\common\controller\Backend
;
use
fast\Menu
;
use
think\Validate
;
/**
...
...
@@ -28,7 +27,7 @@ class Index extends Backend
public
function
index
()
{
//
$menulist
=
Menu
::
instance
()
->
s
idebar
([
$menulist
=
$this
->
auth
->
getS
idebar
([
'dashboard'
=>
'hot'
,
'auth'
=>
[
'new'
,
'red'
,
'badge'
],
'auth/admin'
=>
12
,
...
...
application/admin/lang/zh-cn/general/database.php
查看文件 @
725782c
...
...
@@ -18,7 +18,7 @@ return [
'Max output:%s'
=>
'最大返回%s条'
,
'Total:%s'
=>
'共有%s条记录! '
,
'Row:%s'
=>
'记录:%s'
,
'Executes one or multiple queries which are concatenated by a semicolon'
=>
'请输入SQL语句,支持批量查询,多条SQL以分号(
,
)分格'
,
'Executes one or multiple queries which are concatenated by a semicolon'
=>
'请输入SQL语句,支持批量查询,多条SQL以分号(
;
)分格'
,
'Query affected %s rows and took %s seconds'
=>
'共影响%s条记录! 耗时:%s秒!'
,
'Query returned an empty result'
=>
'返回结果为空!'
,
'Query took %s seconds'
=>
'耗时%s秒!'
,
...
...
application/admin/library/Auth.php
查看文件 @
725782c
...
...
@@ -4,6 +4,7 @@ namespace app\admin\library;
use
app\admin\model\Admin
;
use
fast\Random
;
use
fast\Tree
;
use
think\Cookie
;
use
think\Request
;
use
think\Session
;
...
...
@@ -202,4 +203,67 @@ class Auth extends \fast\Auth
return
in_array
(
'*'
,
$this
->
getRuleIds
())
?
TRUE
:
FALSE
;
}
/**
* 获取左侧菜单栏
*
* @param array $params URL对应的badge数据
* @return string
*/
public
function
getSidebar
(
$params
=
[])
{
$colorArr
=
[
'red'
,
'green'
,
'yellow'
,
'blue'
,
'teal'
,
'orange'
,
'purple'
];
$colorNums
=
count
(
$colorArr
);
$badgeList
=
[];
// 生成菜单的badge
foreach
(
$params
as
$k
=>
$v
)
{
if
(
stripos
(
$k
,
'/'
)
===
false
)
{
$url
=
'/admin/'
.
$k
;
}
else
{
$url
=
url
(
$k
);
}
if
(
is_array
(
$v
))
{
$nums
=
isset
(
$v
[
0
])
?
$v
[
0
]
:
0
;
$color
=
isset
(
$v
[
1
])
?
$v
[
1
]
:
$colorArr
[(
is_numeric
(
$nums
)
?
$nums
:
strlen
(
$nums
))
%
$colorNums
];
$class
=
isset
(
$v
[
2
])
?
$v
[
2
]
:
'label'
;
}
else
{
$nums
=
$v
;
$color
=
$colorArr
[(
is_numeric
(
$nums
)
?
$nums
:
strlen
(
$nums
))
%
$colorNums
];
$class
=
'label'
;
}
//必须nums大于0才显示
if
(
$nums
)
{
$badgeList
[
$url
]
=
'<small class="'
.
$class
.
' pull-right bg-'
.
$color
.
'">'
.
$nums
.
'</small>'
;
}
}
// 读取管理员当前拥有的权限节点
$userRule
=
$this
->
getRuleList
();
$select_id
=
0
;
$dashboard
=
rtrim
(
url
(
'dashboard/'
),
'/'
);
// 必须将结果集转换为数组
$ruleList
=
collection
(
model
(
'AuthRule'
)
->
where
(
'ismenu'
,
1
)
->
order
(
'weigh'
,
'desc'
)
->
cache
(
"__menu__"
)
->
select
())
->
toArray
();
foreach
(
$ruleList
as
$k
=>
&
$v
)
{
if
(
!
in_array
(
$v
[
'name'
],
$userRule
))
continue
;
$select_id
=
$v
[
'name'
]
==
$dashboard
?
$v
[
'id'
]
:
$select_id
;
$v
[
'url'
]
=
$v
[
'name'
];
$v
[
'badge'
]
=
isset
(
$badgeList
[
$v
[
'name'
]])
?
$badgeList
[
$v
[
'name'
]]
:
''
;
}
// 构造菜单数据
Tree
::
instance
()
->
init
(
$ruleList
);
$menu
=
Tree
::
instance
()
->
getTreeMenu
(
0
,
'<li class="@class"><a href="@url" addtabs="@id" url="@url"><i class="@icon"></i> <span>@title</span> <span class="pull-right-container">@caret @badge</span></a> @childlist</li>'
,
$select_id
,
''
,
'ul'
,
'class="treeview-menu"'
);
return
$menu
;
}
}
...
...
extend/fast/Menu.php
已删除
100644 → 0
查看文件 @
3f42ab8
<?php
namespace
fast
;
use
app\admin\library\Auth
;
use
fast\Tree
;
use
think\Config
;
use
think\Db
;
/**
* 菜单
*/
class
Menu
{
protected
static
$instance
;
//默认配置
protected
$config
=
[];
public
function
__construct
(
$options
=
[])
{
if
(
$config
=
Config
::
get
(
'menu'
))
{
$this
->
config
=
array_merge
(
$this
->
config
,
$config
);
}
$this
->
config
=
array_merge
(
$this
->
config
,
is_array
(
$options
)
?
$options
:
[]);
}
/**
* 单例
* @param array $options 参数
* @return Menu
*/
public
static
function
instance
(
$options
=
[])
{
if
(
is_null
(
self
::
$instance
))
{
self
::
$instance
=
new
static
(
$options
);
}
return
self
::
$instance
;
}
/**
* 导入节点数据
* @param array $treearr
* @param int $pid
* @param string $module
*/
public
function
import
(
$treearr
,
$pid
=
0
,
$module
=
NULL
)
{
$module
=
is_null
(
$module
)
?
Config
::
user
(
'request.modulename'
)
:
$module
;
foreach
(
$treearr
as
$key
=>
&
$v
)
{
$controller
=
strtolower
(
$v
[
'controller'
])
.
(
$v
[
'childlist'
]
?
"_folder"
:
''
);
$icon
=
isset
(
$v
[
'icon'
])
?
$v
[
'icon'
]
:
(
stripos
(
$v
[
'name'
],
'_'
)
!==
FALSE
?
$v
[
'childlist'
]
?
'folder'
:
'circle-o'
:
strtolower
(
$v
[
'name'
]));
$actionkeys
=
array_keys
(
$v
[
'actionlist'
]);
$action
=
'-'
.
(
$v
[
'actionlist'
]
?
reset
(
$actionkeys
)
:
''
);
$values
=
array
(
'name'
=>
$v
[
'name'
],
'weigh'
=>
$key
,
'pid'
=>
$pid
,
'module'
=>
$module
,
'controller'
=>
$controller
,
'action'
=>
$action
,
'icon'
=>
$icon
,
'type'
=>
'menu'
,
'status'
=>
'normal'
);
$id
=
Db
::
table
(
"node"
)
->
data
(
$values
)
->
insert
();
$v
[
'id'
]
=
$id
;
}
unset
(
$v
);
foreach
(
$treearr
as
$k
=>
$v
)
{
if
(
$v
[
'childlist'
])
{
$this
->
import
(
$v
[
'childlist'
],
$v
[
'id'
],
$module
);
}
else
{
$i
=
0
;
foreach
(
$v
[
'actionlist'
]
as
$m
=>
$n
)
{
$values
=
array
(
'name'
=>
$n
?
$n
:
$m
,
'weigh'
=>
$i
,
'pid'
=>
$v
[
'id'
],
'module'
=>
$module
,
'controller'
=>
strtolower
(
$v
[
'controller'
]),
'action'
=>
$m
,
'icon'
=>
'circle-o'
,
'type'
=>
'file'
,
'status'
=>
'normal'
);
Db
::
table
(
"node"
)
->
data
(
$values
)
->
insert
();
$i
++
;
}
}
}
}
/**
* 获取左侧菜单栏
*
* @param array $params URL对应的badge数据
* @return string
*/
public
function
sidebar
(
$params
=
[])
{
$colorArr
=
[
'red'
,
'green'
,
'yellow'
,
'blue'
,
'teal'
,
'orange'
,
'purple'
];
$colorNums
=
count
(
$colorArr
);
$badgeList
=
[];
// 生成菜单的badge
foreach
(
$params
as
$k
=>
$v
)
{
if
(
stripos
(
$k
,
'/'
)
===
false
)
{
$url
=
'/admin/'
.
$k
;
}
else
{
$url
=
url
(
$k
);
}
if
(
is_array
(
$v
))
{
$nums
=
isset
(
$v
[
0
])
?
$v
[
0
]
:
0
;
$color
=
isset
(
$v
[
1
])
?
$v
[
1
]
:
$colorArr
[(
is_numeric
(
$nums
)
?
$nums
:
strlen
(
$nums
))
%
$colorNums
];
$class
=
isset
(
$v
[
2
])
?
$v
[
2
]
:
'label'
;
}
else
{
$nums
=
$v
;
$color
=
$colorArr
[(
is_numeric
(
$nums
)
?
$nums
:
strlen
(
$nums
))
%
$colorNums
];
$class
=
'label'
;
}
//必须nums大于0才显示
if
(
$nums
)
{
$badgeList
[
$url
]
=
'<small class="'
.
$class
.
' pull-right bg-'
.
$color
.
'">'
.
$nums
.
'</small>'
;
}
}
// 读取管理员当前拥有的权限节点
$userRule
=
Auth
::
instance
()
->
getRuleList
();
$select_id
=
0
;
$dashboard
=
rtrim
(
url
(
'dashboard/'
),
'/'
);
// 必须将结果集转换为数组
$ruleList
=
collection
(
model
(
'AuthRule'
)
->
where
(
'ismenu'
,
1
)
->
order
(
'weigh'
,
'desc'
)
->
cache
(
"__menu__"
)
->
select
())
->
toArray
();
foreach
(
$ruleList
as
$k
=>
&
$v
)
{
if
(
!
in_array
(
$v
[
'name'
],
$userRule
))
continue
;
$select_id
=
$v
[
'name'
]
==
$dashboard
?
$v
[
'id'
]
:
$select_id
;
$v
[
'url'
]
=
$v
[
'name'
];
$v
[
'badge'
]
=
isset
(
$badgeList
[
$v
[
'name'
]])
?
$badgeList
[
$v
[
'name'
]]
:
''
;
}
// 构造菜单数据
Tree
::
instance
()
->
init
(
$ruleList
);
$menu
=
Tree
::
instance
()
->
getTreeMenu
(
0
,
'<li class="@class"><a href="@url" addtabs="@id" url="@url"><i class="@icon"></i> <span>@title</span> <span class="pull-right-container">@caret @badge</span></a> @childlist</li>'
,
$select_id
,
''
,
'ul'
,
'class="treeview-menu"'
);
return
$menu
;
}
}
请
注册
或
登录
后发表评论