mindoc/views/manager/users.tpl

287 lines
14 KiB
Smarty
Raw Normal View History

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>用户管理 - Powered by MinDoc</title>
<!-- Bootstrap -->
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="/static/css/main.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="/static/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="/static/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="manual-reader">
{{template "widgets/header.tpl" .}}
<div class="container manual-body">
<div class="row">
<div class="page-left">
<ul class="menu">
<li><a href="{{urlfor "ManagerController.Index"}}" class="item"><i class="fa fa-dashboard" aria-hidden="true"></i> 仪表盘</a> </li>
<li class="active"><a href="{{urlfor "ManagerController.Users" }}" class="item"><i class="fa fa-users" aria-hidden="true"></i> 用户管理</a> </li>
<li><a href="{{urlfor "ManagerController.Books" }}" class="item"><i class="fa fa-gear" aria-hidden="true"></i> 项目管理</a> </li>
<li><a href="{{urlfor "ManagerController.Comments" }}" class="item"><i class="fa fa-comments-o" aria-hidden="true"></i> 评论管理</a> </li>
</ul>
</div>
<div class="page-right">
<div class="m-box">
<div class="box-head">
<strong class="box-title"> 成员管理</strong>
{{if eq .Member.Role 0}}
<button type="button" class="btn btn-success btn-sm pull-right" data-toggle="modal" data-target="#addMemberDialogModal"><i class="fa fa-user-plus" aria-hidden="true"></i> 添加成员</button>
{{end}}
</div>
</div>
<div class="box-body">
<div class="users-list" id="userList">
<template v-if="lists.length <= 0">
<div class="text-center">暂无数据</div>
</template>
<template v-else>
<table class="table">
<thead>
<tr>
<th width="80">ID</th>
<th width="80">头像</th>
<th>账号</th>
<th>角色</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="item in lists">
<td>${item.member_id}</td>
<td><img :src="item.avatar" onerror="this.src='/static/images/middle.gif'" class="img-circle" width="34" height="34"></td>
<td>${item.account}</td>
<td>
<template v-if="item.role == 0">
超级管理员
</template>
<template v-else>
2017-04-25 20:05:59 +08:00
<div class="btn-group">
<button type="button" class="btn btn-default btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
${item.role_name}
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="javascript:;" @click="setMemberRole(item.member_id,1)">管理员</a> </li>
<li><a href="javascript:;" @click="setMemberRole(item.member_id,2)">普通用户</a> </li>
</ul>
</div>
</template>
</td>
<td>
<template v-if="item.status == 0">
<span class="label label-success">正常</span>
</template>
<template v-else>
<span class="label label-danger">禁用</span>
</template>
</td>
<td>
2017-04-25 20:05:59 +08:00
<template v-if="item.role != 0">
<template v-if="item.status == 0">
<button type="button" class="btn btn-danger btn-sm" @click="setMemberStatus(item.member_id,1,$event)" data-loading-text="启用中...">禁用</button>
</template>
<template v-else>
2017-04-25 20:05:59 +08:00
<button type="button" class="btn btn-success btn-sm" @click="setMemberStatus(item.member_id,0,$event)" data-loading-text="禁用中...">启用</button>
</template>
</template>
</td>
</tr>
</tbody>
</table>
</template>
<nav>
{{.PageHtml}}
</nav>
</div>
</div>
</div>
</div>
</div>
{{template "widgets/footer.tpl" .}}
</div>
<!-- Modal -->
<div class="modal fade" id="addMemberDialogModal" tabindex="-1" role="dialog" aria-labelledby="addMemberDialogModalLabel">
<div class="modal-dialog" role="document">
<form method="post" autocomplete="off" class="form-horizontal" action="{{urlfor "ManagerController.CreateMember"}}" id="addMemberDialogForm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">创建用户</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-2 control-label" for="account">账号<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="text" name="account" class="form-control" placeholder="用户账号" id="account" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="password1">密码<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="password" class="form-control" placeholder="用户密码" name="password1" id="password1" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="password2">确认密码<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="password" class="form-control" placeholder="确认密码" name="password2" id="password2" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="email">邮箱<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="email" class="form-control" placeholder="邮箱" name="email" id="email" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">手机号</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="手机号" name="phone" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">角色</label>
<div class="col-sm-10">
<select name="role" class="form-control">
<option value="1">管理员</option>
<option value="2">普通用户</option>
</select>
</div>
</div>
<div class="form-group">
</div>
<div class="clearfix"></div>
</div>
<div class="modal-footer">
<span id="form-error-message"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-success">保存</button>
</div>
</div>
</form>
</div>
</div><!--END Modal-->
<script src="/static/jquery/1.12.4/jquery.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/vuejs/vue.min.js"></script>
<script src="/static/js/jquery.form.js" type="text/javascript"></script>
<script src="/static/js/main.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#addMemberDialogModal").on("show.bs.modal",function () {
window.addMemberDialogModalHtml = $(this).find("form").html();
}).on("hidden.bs.modal",function () {
$(this).find("form").html(window.addMemberDialogModalHtml);
});
$("#addMemberDialogForm").ajaxForm({
beforeSubmit : function () {
var account = $.trim($("#account").val());
if(account === ""){
return showError("账号不能为空");
}
var password1 = $.trim($("#password1").val());
var password2 = $("#password2").val();
if (password1 === "") {
return showError("密码不能为空");
}
if (password1 !== password2) {
return showError("确认密码不正确");
}
var email = $.trim($("#email").val());
if (email === "") {
return showError("邮箱不能为空");
}
return true;
},
success : function (res) {
if(res.errcode === 0){
app.lists.splice(0,0,res.data);
$("#addMemberDialogModal").modal("hide");
}else{
showError(res.message);
}
}
});
var app = new Vue({
el : "#userList",
data : {
lists : {{.Result}}
},
delimiters : ['${','}'],
methods : {
setMemberStatus : function (id,status,e) {
var $this = this;
$.ajax({
url : "{{urlfor "ManagerController.UpdateMemberStatus"}}",
type : "post",
data : { "member_id":id,"status" : status},
dataType : "json",
success : function (res) {
if (res.errcode === 0) {
for (var index in $this.lists) {
var item = $this.lists[index];
2017-04-25 20:05:59 +08:00
if (item.member_id === id) {
console.log(item);
2017-04-25 20:05:59 +08:00
$this.lists[index].status = status;
break;
//$this.lists.splice(index,1,item);
}
}
} else {
alert("操作失败:" + res.message);
}
}
})
2017-04-25 20:05:59 +08:00
},
setMemberRole : function (member_id, role) {
var $this = this;
$.ajax({
url :"{{urlfor "ManagerController.ChangeMemberRole"}}",
dataType :"json",
type :"post",
data : { "member_id" : member_id,"role" : role },
success : function (res) {
if(res.errcode === 0){
for (var index in $this.lists) {
var item = $this.lists[index];
if (item.member_id === member_id) {
$this.lists.splice(index,1,res.data);
break;
}
}
}else{
alert("操作失败:" + res.message);
}
}
})
}
}
});
Vue.nextTick(function () {
$("[data-toggle='tooltip']").tooltip();
});
});
</script>
</body>
</html>