首页 > 其他分享 >管理中心,管理员管理,及管理员权限设置

管理中心,管理员管理,及管理员权限设置

时间:2023-04-22 22:47:59浏览次数:33  
标签:管理中心 uid admin 管理员 msg gin 权限 true

管理员管理列表效果:

 添加管理员效果:

编辑管理员效果:

 

管理员权限设置:

 

管理员管理控制器: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">&#xe665;</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">&#xe600;</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">&#xe631;</i></a>
            {{else}}
            <a style="text-decoration:none" onClick="admin_start(this,{{$v1.AdminUid}})" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</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">&#xe6df;</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">&#xe61d;</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">&#xe6e2;</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">&#xe615;</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">&#xe631;</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="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </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="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </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

相关文章

  • 管理中心,管理员日志管理
    前言:管理员日志管理,添加日志,删除日志。管理员在后台的每个操作,都记录对应的地址,以及操作参数。正文: 管理员管理列表页面效果: 控制器代码:controllers/adminLog.go//日志列表,带翻页funcAdminLogList(c*gin.Context){//获取列表list:=modes.AdminLogLis......
  • 管理中心,文章分类管理,文章管理,文件上传,文章回收站
    前言:文章分类管理,文章管理,文章回收站正文: 分类管理效果: 添加分类: 文章列表效果: 添加文章效果: 文章回收站效果: 控制器代码:admins/controllers/news.go//文章分类列表funcNewsCateList(c*gin.Context){list:=modes.NewsCateList(c)c.HTML......
  • 一分钟夺回Windows系统权限
    Windows10总是替我们想得很周到,各种各样的安全设置,云里雾里感觉老安全了。可是,为什么我自己的电脑,权限反而不是自己的?!删除个文件还要权限?别管那么多,把我的电脑还给我!一分钟夺回Windows系统权限对“此电脑”右键选择“管理”进入管理设置:在“系统工具”的下拉菜单中找到“本......
  • 权限登录实现
    数据库校验用户​从之前的分析我们可以知道,我们可以自定义一个UserDetailsService,让SpringSecurity使用我们的UserDetailsService。我们自己的UserDetailsService可以从数据库中查询用户名和密码数据库CREATETABLE`sys_user`(`id`BIGINT(20)NOTNULLAUTO_INC......
  • 认证详细流程 权限登录思路
     Authentication接口:它的实现类,表示当前访问系统的用户,封装了用户相关信息。AuthenticationManager接口:定义了认证Authentication的方法UserDetailsService接口:加载用户特定数据的核心接口。里面定义了一个根据用户名查询用户信息的方法。UserDetails接口:提供核心用户信息......
  • 权限登录准备工作
    1导入依赖<!--redis依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!--fastjson依赖-......
  • 如何备份及恢复 Linux 文件权限
    你可能听说或碰到过这样的事情:一个系统管理员菜鸟不小心输入”chmod-R777/”从而导致了巨大的悲剧,使得整个系统遭到了严重的破坏。在日常管理中,我们有许多工具可以用来备份文件权限,如cp、rsync、etckeeper等。如果你使用了这个备份工具,那么你的确不需要担心改变的文件权限问题......
  • Linux权限维持-隐藏总结
    攻击者在获取服务器权限后,会通过一些技巧来隐藏自己的踪迹和后门文件,本文总结下Linux的一些隐藏手段。隐藏文件Linux下创建一个隐藏文件:touch.test.txttouch命令可以创建一个文件,文件名前面加一个. 就代表是隐藏文件查看Linux下的隐藏文件需要用到命令:ls-al这里,我们可以......
  • cmd默认管理员身份运行
    1.在开始菜单搜索框里输入secpol或本地安全策略或运行secpol.msc,右键单击以管理员身份打开。win+R输入secpol.msc2.展开本地策略,选择安全选项,然后在右侧找到用户帐户控制:以管理员批准模式运行所有管理员,双击以将本地安全设置更改为禁用。3.重启计算机......
  • NTFS安全权限
    一、NTFS权限概述1、通过设置NTFS权限,实现不同用户访问不同对象(文件,文件夹)的权限2、分配了正确访问权限后,用户才能访问不同的权限3、设置权限防止资源被篡改、删除 二、文件系统概述 文件系统即在外部存储设备上组织文件的方法(在存储分区上打格子,格子是存储文件的一个存储单元,格......