管理员管理列表效果:
添加管理员效果:
编辑管理员效果:
管理员权限设置:
管理员管理控制器:controllers/admins.go
var db = common.DB // 管理员列表 func AdminList(c *gin.Context) { //获取列表 users := modes.AdminList(c) //获取管理员列表 c.HTML(http.StatusOK, "admins/list.html", gin.H{ "list": users, "count": len(users), "start_date": c.Query("start_date"), "end_date": c.Query("end_date"), "admin_uname": c.Query("admin_uname"), "admin_truename": c.Query("admin_truename"), }) } // 管理员添加 func AdminAdd(c *gin.Context) { //获取管理员列表 c.HTML(http.StatusOK, "admins/admin_add.html", gin.H{}) } // 管理员编辑 func AdminEdit(c *gin.Context) { aidd, _ := strconv.Atoi(c.Query("aid")) var info modes.Admins info = modes.AdminsItem(aidd) //获取管理员列表 c.HTML(http.StatusOK, "admins/admin_edit.html", gin.H{ "info": info, }) } // 管理员保存 func AdminSave(c *gin.Context) { admin := modes.Admins{} c.ShouldBind(&admin) if admin.AdminUid > 0 { res, msg := modes.AdminsSave(admin, c) if res != true { c.JSON(http.StatusOK, gin.H{"code": 400, "msg": msg}) return } c.JSON(http.StatusOK, gin.H{"code": 0, "msg": "修改成功"}) } else { res, msg := modes.AdminsAdd(admin, c) if res != true { c.JSON(http.StatusOK, gin.H{"code": 400, "msg": msg}) return } c.JSON(http.StatusOK, gin.H{"code": 0, "msg": "添加成功"}) } } // 管理员删除 func AdminDel(c *gin.Context) { uid := c.Query("uid") uidd, _ := strconv.Atoi(uid) stat, msg := modes.AdminDel(uidd, c) if stat != true { c.JSON(http.StatusOK, gin.H{"code": 400, "msg": msg}) return } c.JSON(http.StatusOK, gin.H{"code": 0, "msg": "删除成功"}) } // 更改管理员状态 func AdminStatus(c *gin.Context) { uid := c.Query("uid") status := c.Query("admin_status") uidd, _ := strconv.Atoi(uid) stat, msg := modes.AdminStatus(uidd, status) if stat != true { c.JSON(http.StatusOK, gin.H{"code": 400, "msg": msg}) return } c.JSON(http.StatusOK, gin.H{"code": 0, "msg": "修改成功"}) } // 管理员权限 func AdminPower(c *gin.Context) { aidd, _ := strconv.Atoi(c.Query("aid")) var info modes.Admins info = modes.AdminsItem(aidd) //获取权限 power := modes.PowerItem(aidd) power_str := "," + power.AdminPowers + "," //获取菜单列表 menus, _ := modes.MenuList() //获取管理员权限 c.HTML(http.StatusOK, "admins/admin_power.html", gin.H{ "info": info, "power": power, "menus": menus, "power_str": power_str, }) } // 管理员权限保存 func AdminPowerSave(c *gin.Context) { //获取所有参数 aaid, _ := strconv.Atoi(c.PostForm("aaid")) admin_powers := c.PostFormArray("pids[]") is_admin, _ := strconv.Atoi(c.PostForm("is_admin")) p := strings.Join(admin_powers, ",") if p == "" { p = "0," } res := modes.PowerSave(aaid, is_admin, p) if res != true { c.JSON(http.StatusOK, gin.H{"code": 400, "msg": "设置权限失败"}) return } c.JSON(http.StatusOK, gin.H{"code": 0, "msg": "设置权限成功"}) }
管理员管理模型:modes/adminsModel.go
var DB = common.DB //管理员 type Admins struct { AdminUid int `form:"admin_uid"` AdminUname string `form:"admin_uname"` AdminPasswd string `form:"admin_passwd"` AdminTruename string `form:"admin_truename"` AdminDept string `form:"admin_dept"` Lastlogin string `form:"last_login"` Logincount int `form:"logincount"` IsAdmin int `form:"is_admin"` AdminStatus int `form:"admin_status"` AdminRemark string `form:"admin_remark"` AddDatetime string `form:"add_datetime"` } //权限表 type AdminsPowers struct { Id int `form:"id"` AdminUid int `form:"auid"` AdminPowers string `form:"admin_powers"` LastDatetime string `form:"last_datetime"` AddDatetime string `form:"add_datetime"` } //管理员注册 func AdminsAdd(admin Admins,c *gin.Context) (bool,string) { //密码加密 admin.AdminPasswd = common.MyMd5(admin.AdminPasswd) admin.AddDatetime = time.Now().Format(common.TimeTem) admin.Lastlogin = time.Now().Format(common.TimeTem) //判断用户名是否重复 var count int64 DB.Model(Admins{}).Where("admin_uname=?",admin.AdminUname).Count(&count) if count > 0 { return false,"该管理员账号已存在,请重新设置其他账号" } res := DB.Model(Admins{}).Create(&admin) if res.RowsAffected == 1{ return true,"创建成功" } return false,res.Error.Error() } //管理员修改 func AdminsSave(admin Admins,c *gin.Context) (bool,string) { //密码加密 if strings.TrimSpace(admin.AdminPasswd) != ""{ admin.AdminPasswd = common.MyMd5(admin.AdminPasswd) } DB.Model(Admins{}).Where("admin_uid=?",admin.AdminUid).Updates(&admin) return true,"创建成功" } //管理员修改密码 func AdminsChangePass(admin_id int,oldpass string,newpass string,) (bool,string) { var admin = Admins{} //密码加密 if strings.TrimSpace(oldpass) != ""{ oldpass = common.MyMd5(oldpass) } if strings.TrimSpace(newpass) != ""{ newpass = common.MyMd5(newpass) } DB.Model(Admins{}).Where("admin_uid=?",admin_id).First(&admin) if admin.AdminPasswd != oldpass { return false,"旧密码输入错误" } DB.Model(Admins{}).Where("admin_uid=?",admin.AdminUid).Updates(Admins{ AdminPasswd: newpass, }) return true,"密码修改成功" } //获取管理员 func AdminsItem(aid int) (Admins) { var info Admins DB.Model(Admins{}).Where("admin_uid=?",aid).Find(&info) return info } //获取管理员账号 func AdminsUname(aid int) (string) { //var uname string var users Admins DB.Model(Admins{}).Select("admin_uname").Where("admin_uid=?",aid).First(&users) return users.AdminUname } //删除管理员 func AdminDel(uid int,c *gin.Context) (bool,string) { //goadmin uid=6的不能被删除 if uid == 6 { return false,"系统超级管理员不能被删除!" } //不能自己删除自己 admin_id,exist := c.Get("admin_uid") if exist && admin_id == uid { return false,"不能删除当前登录的账号!" } //判断权限 res := DB.Delete(Admins{},uid) if res.Error != nil{ return false,res.Error.Error() } return true,"删除成功" } //更改状态 func AdminStatus(uid int,status string) (bool,string) { //goadmin uid=6的不能被删除 if uid == 6 { return false,"系统超级管理员不能被停用!" } //判断权限 res := DB.Model(Admins{}).Where("admin_uid=?",uid).Update("admin_status",status) if res.Error != nil{ return false,res.Error.Error() } return true,"删除成功" } //管理员列表 func AdminList(c *gin.Context) ([]Admins) { users := []Admins{} NewDb := DB if admin_uname,isExist := c.GetQuery("admin_uname");isExist == true{ if strings.TrimSpace(admin_uname) != ""{ NewDb = NewDb.Where("admin_uname = ?",admin_uname) } } if admin_truename,isExist := c.GetQuery("admin_truename");isExist == true{ if strings.TrimSpace(admin_truename) != ""{ NewDb = NewDb.Where("admin_truename = ?",admin_truename) } } if start_date,isExist := c.GetQuery("start_date");isExist == true{ if strings.TrimSpace(start_date) != "" { start_date = start_date + " 00:00:00" NewDb = NewDb.Where("add_datetime > ?", start_date) } } if end_date,isExist := c.GetQuery("end_date");isExist == true{ if strings.TrimSpace(end_date) != "" { end_date = end_date+" 23:59:59" NewDb = NewDb.Where("add_datetime <= ?",end_date) } } res := NewDb.Model(Admins{}).Find(&users) if res.Error != nil { return users } return users } //获取管理员权限 func PowerItem(aid int) (AdminsPowers) { var p AdminsPowers DB.Model(AdminsPowers{}).Where("admin_uid=?",aid).Find(&p) return p } //保存管理员权限 func PowerSave(aaid int,is_admin int,power string) (bool) { //更新权限状态 DB.Model(Admins{}).Where("admin_uid=?",aaid).Update("is_admin",is_admin) var num int64 DB.Model(AdminsPowers{}).Where("admin_uid=?",aaid).Count(&num) if num > 0 { //修改 DB.Model(AdminsPowers{}).Where("admin_uid=?",aaid).Updates(AdminsPowers{ AdminPowers:power, LastDatetime: time.Now().Format(common.TimeTem), }) }else{ DB.Model(AdminsPowers{}).Create(&AdminsPowers{ AdminUid: aaid, AddDatetime: time.Now().Format(common.TimeTem), AdminPowers:power, LastDatetime: time.Now().Format(common.TimeTem), }) } return true } //获取管理员日志列表 func AdminLogList(c *gin.Context) ([]AdminsLog) { log_list := []AdminsLog{} admin :=Admins{} NewDb := DB if admin_uname,isExist := c.GetQuery("admin_uname");isExist == true{ if strings.TrimSpace(admin_uname) != ""{ res := DB.Model(Admins{}).Where("admin_uname=?",admin_uname).Find(&admin) if res.Error == nil { NewDb = NewDb.Where("admin_uid = ?",admin.AdminUid) } } } if ip_addr,isExist := c.GetQuery("ip_addr");isExist == true{ if strings.TrimSpace(ip_addr) != ""{ if strings.Contains(ip_addr,":") { ipa := strings.Split(ip_addr,":") ip_addr = ipa[0] } NewDb = NewDb.Where("ip_addr like ?",ip_addr+"%") } } if start_date,isExist := c.GetQuery("start_date");isExist == true{ if strings.TrimSpace(start_date) != "" { start_date = start_date + " 00:00:00" NewDb = NewDb.Where("add_datetime > ?", start_date) } } if end_date,isExist := c.GetQuery("end_date");isExist == true{ if strings.TrimSpace(end_date) != "" { end_date = end_date+" 23:59:59" NewDb = NewDb.Where("add_datetime <= ?",end_date) } } res := NewDb.Model(AdminsLog{}).Find(&log_list) if res.Error != nil { return log_list } return log_list }
管理员列表视图:views/admins/admins/list.html
<!--搜索--> <div class="text-c"> <form action="/admin/admin_list" method="get"> 日期范围: <input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" name="start_date" value="{{.start_date}}" style="width:120px;"> - <input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" class="input-text Wdate" name="end_date" value="{{.end_date}}" style="width:120px;"> <input type="text" class="input-text" style="width:150px" placeholder="管理员登录账号" id="admin_uname" name="admin_uname" value="{{.admin_uname}}"> <input type="text" class="input-text" style="width:150px" placeholder="管理员姓名" id="admin_truename" name="admin_truename" value="{{.admin_truename}}"> <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont"></i> 搜用户</button> </form> </div> <!--添加管理员--> <div class="cl pd-5 bg-1 bk-gray mt-20"> {{ $admin_uid := GetAdminId}} <a href="javascript:;" {{if has_powa $admin_uid "/admin/admin_add"}} style="display:none" {{end}} onclick="admin_add('添加管理员','/admin/admin_add','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont"></i> 添加管理员</a> </span> <span class="r">共有数据:<strong>{{.count}}</strong> 条</span> </div> <!--管理员列表--> <table class="table table-border table-bordered table-hover table-sort table-bg"> <thead> <tr> <th scope="col" colspan="12">员工列表</th> </tr> <tr class="text-c"> <th width="25"><input type="checkbox" name="" value=""></th> <th width="40">ID</th> <th width="120">登录名</th> <th width="120">姓名</th> <th width="120">部门</th> <th width="150">管理员级别</th> <th width="130">最后登录时间</th> <th width="100">登录次数</th> <th>管理员备注</th> <th width="130">加入时间</th> <th width="100">是否已启用</th> <th width="100">操作</th> </tr> </thead> <tbody> {{ range $k,$v1 := .list}} <tr class="text-c"> <td><input type="checkbox" value="{{$v1.AdminUid}}" name=""></td> <td>{{$v1.AdminUid}}</td> <td>{{$v1.AdminUname}}</td> <td>{{$v1.AdminTruename}}</td> <td>{{$v1.AdminDept}}</td> <td> {{if eq $v1.IsAdmin 1}} 普通管理员 {{else}} 超级管理员 {{end}} </td> <td>{{$v1.Lastlogin}}</td> <td>{{$v1.Logincount}}</td> <td>{{$v1.AdminRemark}}</td> <td>{{$v1.AddDatetime}}</td> <td class="td-status"> {{if eq $v1.AdminStatus 1}} <span class="label label-success radius">已启用</span> {{else}} <span class="label radius">已停用</span> {{end}} </td> <td class="td-manage"> {{if eq $v1.AdminStatus 1}} <a style="text-decoration:none" onClick="admin_stop(this,{{$v1.AdminUid}})" href="javascript:;" title="停用"><i class="Hui-iconfont"></i></a> {{else}} <a style="text-decoration:none" onClick="admin_start(this,{{$v1.AdminUid}})" href="javascript:;" title="启用"><i class="Hui-iconfont"></i></a> {{end}} <a title="编辑" href="javascript:;" {{if has_powa $admin_uid "/admin/admin_edit"}} style="display:none" {{end}} onclick="admin_edit('管理员编辑','/admin/admin_edit',{{$v1.AdminUid}},'800','500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont"></i></a> <a title="权限设置" href="javascript:;" {{if has_powa $admin_uid "/admin/admin_power"}} style="display:none" {{end}} onclick="admin_power('权限设置','/admin/admin_power',{{$v1.AdminUid}},'800','500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont"></i></a> <a title="删除" href="javascript:;" {{if has_powa $admin_uid "/admin/admin_del"}} style="display:none" {{end}} onclick="admin_del(this,{{$v1.AdminUid}})" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont"></i></a></td> </tr> {{ end }} </tbody> </table> <!--javascript 脚本--> <script type="text/javascript" src="/static/h-ui.lib/My97DatePicker/4.8/WdatePicker.js"></script> <script type="text/javascript" src="/static/h-ui.lib/datatables/1.10.15/jquery.dataTables.min.js"></script> <script type="text/javascript" src="/static/h-ui.lib/laypage/1.2/laypage.js"></script> <script type="text/javascript"> $('.table-sort').dataTable({ "aaSorting": [[ 1, "desc" ]],//默认第几个排序 "bStateSave": true,//状态保存 "aoColumnDefs": [ //{"bVisible": true, "aTargets": [ 3,4,5 ]} ,//控制列的隐藏显示 {"orderable":false,"aTargets":[0,11]}// 不参与排序的列 ] }); /* 参数解释: title 标题 url 请求的url id 需要操作的数据id w 弹出层宽度(缺省调默认值) h 弹出层高度(缺省调默认值) */ /*管理员-增加*/ function admin_add(title,url,w,h){ layer_show(title,url,w,h); } /*管理员-删除*/ function admin_del(obj,id){ layer.confirm('确认要删除吗?',function(index){ //此处请求后台程序,下方是成功后的前台处理…… $.get("/admin/admin_del",{uid:id},function (data){ if (data.code == 0){ $(obj).parents("tr").remove(); layer.msg('已删除!',{icon:1,time:1000}); }else{ layer.alert(data.msg) } },'json') }); } /*管理员-编辑*/ function admin_edit(title,url,id,w,h){ layer_show(title,url+"?aid="+id,w,h); } /*管理员-编辑*/ function admin_power(title,url,id,w,h){ layer_show(title,url+"?aid="+id,w,h); } /*管理员-停用*/ function admin_stop(obj,id){ layer.confirm('确认要停用吗?',function(index){ //此处请求后台程序,下方是成功后的前台处理…… $.get("/admin/admin_status",{uid:id,admin_status:2},function (data){ if (data.code == 0) { $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this,'+id+')" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont"></i></a>'); $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已停用</span>'); $(obj).remove(); layer.msg('已停用!',{icon: 5,time:1000}); }else{ layer.alert(data.msg) } },'json') }); } /*管理员-启用*/ function admin_start(obj,id){ layer.confirm('确认要启用吗?',function(index){ //此处请求后台程序,下方是成功后的前台处理…… $.get("/admin/admin_status",{uid:id,admin_status:1},function (data){ if (data.code == 0) { $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,'+id+')" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont"></i></a>'); $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>'); $(obj).remove(); layer.msg('已启用!', {icon: 6,time:1000}); }else{ layer.alert(data.msg) } }) }); } </script>
添加管理员视图:admins/admin_add.html
<form action="/admin/admin_save" method="post" class="form form-horizontal" id="form-admin-add"> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>登录账号:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text" value="" placeholder="" id="admin_uname" name="admin_uname"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="password" name="admin_passwd"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="password" class="input-text" autocomplete="off" placeholder="确认新密码" id="password2" name="password2"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>姓名:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text" value="" placeholder="" id="admin_truename" name="admin_truename"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>部门:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text" value="" placeholder="" id="admin_dept" name="admin_dept"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员级别:</label> <div class="formControls col-xs-8 col-sm-9 skin-minimal"> <div class="radio-box"> <input name="is_admin" type="radio" id="is_admin-1" value="1" checked> <label for="is_admin-1">普通管理员</label> </div> <div class="radio-box"> <input name="is_admin" type="radio" id="is_admin-2" value="2"> <label for="is_admin-2">超级管理员(不受权限控制)</label> </div> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员状态:</label> <div class="formControls col-xs-8 col-sm-9 skin-minimal"> <div class="radio-box"> <input name="admin_status" type="radio" id="admin_status-1" value="1" checked> <label for="admin_status-1">启用</label> </div> <div class="radio-box"> <input name="admin_status" type="radio" id="admin_status-2" value="1"> <label for="admin_status-2">停用</label> </div> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3">备注:</label> <div class="formControls col-xs-8 col-sm-9"> <textarea name="admin_remark" cols="" rows="" class="textarea" placeholder="说点什么...200个字符以内" dragonfly="true" onKeyUp="textarealength(this,200)"></textarea> <p class="textarea-numberbar"><em class="textarea-length">0</em>/200</p> </div> </div> <div class="row cl"> <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3"> <input class="btn btn-primary radius" type="submit" value=" 提交 "> </div> </div> </form> <script type="text/javascript"> $(function(){ $('.skin-minimal input').iCheck({ checkboxClass: 'icheckbox-blue', radioClass: 'iradio-blue', increaseArea: '20%' }); $("#form-admin-add").validate({ rules:{ admin_uname:{ required:true, minlength:6, maxlength:20 }, password:{ required:true, minlength:6, maxlength:20 }, password2:{ required:true, minlength:6, maxlength:20, equalTo: "#password" }, admin_truename:{ required:true, }, }, onkeyup:false, focusCleanup:true, success:"valid", submitHandler:function(form){ $(form).ajaxSubmit(function (data){ if (data.code == 0){ var index = parent.layer.getFrameIndex(window.name); parent.window.location.reload(); parent.layer.close(index); }else{ layer.alert(data.msg) } }); } }); }); </script>
编辑管理员视图:admin_edit.html
<form action="/admin/admin_save" method="post" class="form form-horizontal" id="form-admin-add"> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>登录账号:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text" value="{{.info.AdminUname}}" placeholder="" id="admin_uname" name="admin_uname" > </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="password" name="admin_passwd"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="password" class="input-text" autocomplete="off" placeholder="确认新密码" id="password2" name="password2"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>姓名:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text" value="{{.info.AdminTruename}}" placeholder="" id="admin_truename" name="admin_truename"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>部门:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text" value="{{.info.AdminDept}}" placeholder="" id="admin_dept" name="admin_dept"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员级别:</label> <div class="formControls col-xs-8 col-sm-9 skin-minimal"> <div class="radio-box"> <input name="is_admin" type="radio" id="is_admin-1" value="1" {{if eq .info.IsAdmin 1}}checked{{end}}> <label for="is_admin-1">普通管理员</label> </div> <div class="radio-box"> <input name="is_admin" type="radio" id="is_admin-2" value="2" {{if eq .info.IsAdmin 2}}checked{{end}}> <label for="is_admin-2">超级管理员(不受权限控制)</label> </div> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员状态:</label> <div class="formControls col-xs-8 col-sm-9 skin-minimal"> <div class="radio-box"> <input name="admin_status" type="radio" id="admin_status-1" value="1" {{if eq .info.AdminStatus 1}}checked{{end}}> <label for="admin_status-1">启用</label> </div> <div class="radio-box"> <input name="admin_status" type="radio" id="admin_status-2" value="1" {{if eq .info.AdminStatus 2}}checked{{end}}> <label for="admin_status-2">停用</label> </div> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3">备注:</label> <div class="formControls col-xs-8 col-sm-9"> <textarea name="admin_remark" cols="" rows="" class="textarea" placeholder="说点什么...200个字符以内" dragonfly="true" onKeyUp="textarealength(this,200)">{{.info.AdminRemark}}</textarea> <p class="textarea-numberbar"><em class="textarea-length">0</em>/200</p> </div> </div> <div class="row cl"> <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3"> <input type="hidden" name="admin_uid" id="admin_uid" value="{{.info.AdminUid}}"> <input class="btn btn-primary radius" type="submit" value=" 提交 "> </div> </div> </form> <script type="text/javascript"> $(function(){ $('.skin-minimal input').iCheck({ checkboxClass: 'icheckbox-blue', radioClass: 'iradio-blue', increaseArea: '20%' }); $("#form-admin-add").validate({ rules:{ admin_uname:{ required:true, minlength:6, maxlength:20 }, password2:{ equalTo: "#password" }, admin_truename:{ required:true, }, }, onkeyup:false, focusCleanup:true, success:"valid", submitHandler:function(form){ $(form).ajaxSubmit(function (data){ if (data.code == 0){ var index = parent.layer.getFrameIndex(window.name); parent.window.location.reload(); parent.layer.close(index); }else{ layer.alert(data.msg) } }); } }); }); </script>
管理员权限设置 admin_power.html
<form action="/admin/admin_power_save" method="post" class="form form-horizontal" id="form-admin-role-add"> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3">管理员账号:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="text" disabled class="input-text" value="{{.info.AdminUname}}" placeholder="" > </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3">管理员姓名:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="text" disabled class="input-text" value="{{.info.AdminTruename}}" placeholder="" > </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员级别:</label> <div class="formControls col-xs-8 col-sm-9 skin-minimal"> <div class="radio-box"> <input name="is_admin" type="radio" id="is_admin-1" value="1" {{if eq .info.IsAdmin 1}}checked{{end}}> <label for="is_admin-1">普通管理员</label> </div> <div class="radio-box"> <input name="is_admin" type="radio" id="is_admin-2" value="2" {{if eq .info.IsAdmin 2}}checked{{end}}> <label for="is_admin-2">超级管理员(拥有所有权限)</label> </div> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3">权限列表:</label> <div class="formControls col-xs-8 col-sm-9"> {{ range $k,$v1 := .menus}} <dl class="permission-list"> <dt> <label> <input type="checkbox" value="{{$v1.Id}}" name="pids[]" {{if has_pow $.power_str $v1.Id}}checked{{end}} id="user-Character-{{$v1.Id}}"> {{$v1.MenuName}}</label> </dt> {{range $k2,$v2 := $v1.Children }} <dd> <dl class="cl permission-list2"> <dt> <label class=""> <input type="checkbox" value="{{$v2.Id}}" name="pids[]" {{if has_pow $.power_str $v2.Id}}checked{{end}} id="user-Character-{{$v1.Id}}-{{$v2.Id}}"> {{$v2.MenuName}}</label> </dt> <dd> {{range $k3,$v3 := $v2.Children }} <label class=""> <input type="checkbox" value="{{$v3.Id}}" name="pids[]" {{if has_pow $.power_str $v3.Id}}checked{{end}} id="user-Character-{{$v1.Id}}-{{$v2.Id}}-{{$v3.Id}}"> {{$v3.MenuName}}</label> {{end}} </dd> </dl> </dd> {{end}} </dl> {{end}} </div> </div> <div class="row cl"> <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3"> <input type="hidden" name="aaid" value="{{.info.AdminUid}}"> <button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button> </div> </div> </form> <script type="text/javascript"> $(function(){ $(".permission-list dt input:checkbox").click(function(){ $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked")); }); $(".permission-list2 dd input:checkbox").click(function(){ var l =$(this).parent().parent().find("input:checked").length; var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length; if($(this).prop("checked")){ $(this).closest("dl").find("dt input:checkbox").prop("checked",true); $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true); } else{ if(l==0){ //$(this).closest("dl").find("dt input:checkbox").prop("checked",false); } if(l2==0){ //$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false); } } }); $("#form-admin-role-add").validate({ rules:{ }, onkeyup:false, focusCleanup:true, success:"valid", submitHandler:function(form){ $(form).ajaxSubmit(function (data){ if (data.code == 0){ var index = parent.layer.getFrameIndex(window.name); parent.window.location.reload(); parent.layer.close(index); }else{ layer.alert(data.msg) } }); } }); }); </script>
完结
标签:管理中心,uid,admin,管理员,msg,gin,权限,true From: https://www.cnblogs.com/ypeih/p/17344311.html