Skip to content

Commit

Permalink
Merge pull request #66 from mark8866/master
Browse files Browse the repository at this point in the history
fix node list bug and add a search example
  • Loading branch information
astaxie authored Mar 5, 2021
2 parents 83609dd + bba7d8e commit 6b74f2e
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 31 deletions.
7 changes: 5 additions & 2 deletions src/models/UserModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ func init() {
/************************************************************/

//get user list
func Getuserlist(page int64, page_size int64, sort string) (users []orm.Params, count int64) {
func Getuserlist(page int64, page_size int64, sort string, searchMap map[string]string) (users []orm.Params, count int64) {
o := orm.NewOrm()
user := new(User)
qs := o.QueryTable(user)
// 实现搜索过滤
for k, v := range searchMap {
qs = qs.Filter(k, v)
}
var offset int64
if page <= 1 {
offset = 0
Expand Down Expand Up @@ -141,4 +145,3 @@ func GetUserById(id int64) (user User) {
o.Read(&user, "Id")
return user
}

14 changes: 2 additions & 12 deletions src/rbac/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,8 @@ func (this *NodeController) Rsp(status bool, str string) {

func (this *NodeController) Index() {
if this.IsAjax() {
page, _ := this.GetInt64("page")
page_size, _ := this.GetInt64("rows")
sort := this.GetString("sort")
order := this.GetString("order")
if len(order) > 0 {
if order == "desc" {
sort = "-" + sort
}
} else {
sort = "Id"
}
nodes, count := m.GetNodelist(page, page_size, sort)
groupid, _ := this.GetInt64("group_id")
nodes, count := m.GetNodelistByGroupid(groupid)
for i := 0; i < len(nodes); i++ {
if nodes[i]["Pid"] != 0 {
nodes[i]["_parentId"] = nodes[i]["Pid"]
Expand Down
6 changes: 5 additions & 1 deletion src/rbac/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ func (this *RoleController) AddAccess() {
func (this *RoleController) RoleToUserList() {
roleid, _ := this.GetInt64("Id")
if this.IsAjax() {
users, count := m.Getuserlist(1, 1000, "Id")
// 先声明map
var searchMap map[string]string
// 再使用make函数创建一个非nil的map,nil map不能赋值
searchMap = make(map[string]string)
users, count := m.Getuserlist(1, 1000, "Id", searchMap)
list, _ := m.GetUserByRoleId(roleid)
for i := 0; i < len(users); i++ {
for x := 0; x < len(list); x++ {
Expand Down
18 changes: 17 additions & 1 deletion src/rbac/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,31 @@ func (this *UserController) Index() {
page_size, _ := this.GetInt64("rows")
sort := this.GetString("sort")
order := this.GetString("order")
// 获取搜索条件
Username__exact := this.GetString("Username__exact")
Nickname__contains := this.GetString("Nickname__contains")

// 先声明map
var searchMap map[string]string
// 再使用make函数创建一个非nil的map,nil map不能赋值
searchMap = make(map[string]string)
// 最后给已声明的map赋值
if len(Username__exact) > 0 {
searchMap["Username__exact"] = Username__exact
}
if len(Nickname__contains) > 0 {
searchMap["Nickname__contains"] = Nickname__contains
}
if len(order) > 0 {
if order == "desc" {
sort = "-" + sort
}
} else {
sort = "Id"
}
users, count := m.Getuserlist(page, page_size, sort)
users, count := m.Getuserlist(page, page_size, sort, searchMap)
if this.IsAjax() {

this.Data["json"] = &map[string]interface{}{"total": count, "rows": &users}
this.ServeJSON()
return
Expand Down
30 changes: 17 additions & 13 deletions static/easyui/jquery-easyui/jquery.easyui.min.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* jQuery EasyUI 1.3.4
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: [email protected]
* https://www.gnu.org/licenses/gpl.txt
* https://www.jeasyui.com/license_commercial.php
*
*/
/**
* jQuery EasyUI 1.3.4
*
* Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL or commercial licenses
* To use it on other terms please contact us: [email protected]
* https://www.gnu.org/licenses/gpl.txt
* https://www.jeasyui.com/license_commercial.php
*
*/
(function($){
$.parser={auto:true,onComplete:function(_1){
},plugins:["draggable","droppable","resizable","pagination","tooltip","linkbutton","menu","menubutton","splitbutton","progressbar","tree","combobox","combotree","combogrid","numberbox","validatebox","searchbox","numberspinner","timespinner","calendar","datebox","datetimebox","slider","layout","panel","datagrid","propertygrid","treegrid","tabs","accordion","window","dialog"],parse:function(_2){
Expand Down Expand Up @@ -7831,7 +7831,7 @@ dc.body2.triggerHandler("scroll");
_54c();
$(_545).datagrid("autoSizeColumn");
function _54c(){
if(opts.idField){
if(opts.idField && data.rows!= null){
for(var i=0;i<data.rows.length;i++){
var row=data.rows[i];
if(_54d(_546.selectedRows,row)){
Expand Down Expand Up @@ -8275,9 +8275,11 @@ var _5ca=$.data(_5c9,"datagrid");
var data=_5ca.data;
var rows=data.rows;
var _5cb=[];
if(rows != null){
for(var i=0;i<rows.length;i++){
_5cb.push($.extend({},rows[i]));
}
}
_5ca.originalRows=_5cb;
_5ca.updatedRows=[];
_5ca.insertedRows=[];
Expand Down Expand Up @@ -8831,6 +8833,7 @@ return;
}
}
var _660=["<table class=\"datagrid-btable\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody>"];
if(rows != null){
for(var i=0;i<rows.length;i++){
var css=opts.rowStyler?opts.rowStyler.call(_65b,i,rows[i]):"";
var _661="";
Expand All @@ -8850,6 +8853,7 @@ _660.push("<tr id=\""+_664+"\" datagrid-row-index=\""+i+"\" "+cls+" "+_663+">");
_660.push(this.renderRow.call(this,_65b,_65f,_65d,i,rows[i]));
_660.push("</tr>");
}
}
_660.push("</tbody></table>");
$(_65c).html(_660.join(""));
},renderFooter:function(_665,_666,_667){
Expand Down Expand Up @@ -12180,4 +12184,4 @@ return _8ff;
},onComplete:function(_904){
}};
})(jQuery);

5 changes: 3 additions & 2 deletions views/easyui/rbac/node.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
var URL="/rbac/node";
$(function(){
$("#treegrid").treegrid({
url:URL+"/index",
url:URL+"/index?group_id=1",
idField:"Id",
treeField:"Title",
fitColumns:"true",
columns:[[
{field:'Title',title:'显示名',width:150,editor:'text'},
{field:'Id',title:'ID',width:50},
{field:'Name',title:'应用名',width:100,editor:'text'},
{field:'Group__Id',title:'分组',width:80,
{field:'Group',title:'分组',width:80,
formatter:function(value){
for(var i=0; i<grouplist.length; i++){
if (grouplist[i].Id == value) return grouplist[i].Title;
Expand Down
25 changes: 25 additions & 0 deletions views/easyui/rbac/user.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ function reloadrow(){
$("#datagrid").datagrid("reload");
}
//添加用户弹窗
function addrow(){
$("#dialog").dialog('open');
Expand Down Expand Up @@ -217,6 +218,17 @@ function delrow(){
}
});
}
// 搜索
function searchForm() {
// form表单数据转为json
var data = $("#searchform").serializeArray();
vac.ajax(URL+"/index",data,"POST",function(data){
console.log(data)
$("#datagrid").datagrid("loadData",data)
}
)
}
</script>
<body>
<table id="datagrid" toolbar="#tb"></table>
Expand All @@ -227,7 +239,20 @@ function delrow(){
<a href="#" icon='icon-cancel' plain="true" onclick="delrow()" class="easyui-linkbutton" >删除</a>
<a href="#" icon='icon-reload' plain="true" onclick="reloadrow()" class="easyui-linkbutton" >刷新</a>
<a href="#" icon='icon-edit' plain="true" onclick="updateuserpassword()" class="easyui-linkbutton" >修改用户密码</a>
<div style="float:right;height:auto">
<form id="searchform">
用户名:<input name="Username__exact" value= ""/>
昵称;<input name = "Nickname__contains" value=""/>
<a href="#" icon='icon-search' plain="true" onclick="searchForm()" class="easyui-linkbutton" >搜索</a>
</form>
</div>
</div>
<!--表格内的右键菜单-->
<div id="mm" class="easyui-menu" style="width:120px;display: none" >
<div iconCls='icon-add' onclick="addrow()">新增</div>
Expand Down

0 comments on commit 6b74f2e

Please sign in to comment.