forked from TruthHun/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.html
More file actions
367 lines (355 loc) · 19 KB
/
users.html
File metadata and controls
367 lines (355 loc) · 19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!DOCTYPE html>
<html lang="zh-CN">
<head>
{{template "widgets/head.html" .}}
<style>.fix-time{display: block;white-space: nowrap;width: 141px;overflow: hidden;}</style>
</head>
<body>
<div class="manual-reader">
{{template "widgets/header.html" .}}
<div class="container manual-body">
<div class="row">
<div class="page-left">
{{template "manager/menu.html" .}}
</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>
<form class="form-inline" role="form" style="margin-top: 15px;">
<div class="form-group">
<select name="role" class="form-control">
<option value="">全部</option>
<option value="1" {{if eq .Role 0}}selected{{end}}>管理员</option>
<option value="3" {{if eq .Role 3}}selected{{end}}>作者</option>
<option value="2" {{if eq .Role 2}}selected{{end}}>读者</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" value="{{.Wd}}" name="wd" placeholder="搜索用户">
</div>
<button type="submit" class="btn btn-default">提交</button>
</form>
<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>
<th>注册</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="item in lists">
<td>${item.member_id}</td>
<td>
<a :href="'/user/'+item.account" target="_blank">
<img :src="item.avatar" onerror="this.src='/static/images/avatar.png'" class="img-circle" width="34" height="34">
</a>
</td>
<td>
<a :href="'/user/'+item.account" target="_blank">${item.nickname}(${item.account})</a>
<br>
<span class="text-muted">email:${item.email}</span><br>
<span class="text-muted" v-if="item.wechat_no">微信:${item.wechat_no}</span>
</td>
<td>
<template v-if="item.role == 0">
超级管理员
</template>
<template v-else-if="item.member_id == {{.Member.MemberId}}">
${item.role_name}
</template>
<template v-else>
<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,3)">作者</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>
<div class="fix-time">${item.create_time}</div>
</td>
<td>
<template v-if="item.member_id == {{.Member.MemberId}}">
</template>
<template v-else-if="item.role != 0">
<a :href="'{{urlfor "ManagerController.EditMember" ":id" ""}}' + item.member_id" class="btn btn-sm btn-default" @click="editMember(item.member_id)">
编辑
</a>
<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>
<button type="button" class="btn btn-success btn-sm" @click="setMemberStatus(item.member_id,0,$event)" data-loading-text="禁用中...">启用</button>
</template>
<button type="button" class="btn btn-danger btn-sm" @click="deleteMember(item.member_id,$event)" :data-user="item.nickname" data-loading-text="删除中">删除</button>
</template>
</td>
</tr>
</tbody>
</table>
</template>
<nav class="pagination-container">
{{.PageHtml}}
</nav>
</div>
</div>
</div>
</div>
</div>
</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">×</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="account">昵称<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="text" name="nickname" class="form-control" placeholder="用户昵称" id="nickname" maxlength="20">
</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 hidden">
<label class="col-sm-2 control-label">角色</label>
<div class="col-sm-10">
<select name="role" class="form-control">
<option value="2">普通用户</option>
<option value="1">管理员</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" data-loading-text="保存中..." id="btnAddMember">保存</button>
</div>
</div>
</form>
</div>
</div><!--END Modal-->
{{/*<script src="/static/jquery/1.12.4/jquery.min.js" type="text/javascript"></script>*/}}
<script src="/static/jquery/1.12.4/jquery.min.js" type="text/javascript"></script>
{{/*<script src="/static/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>*/}}
<script src="/static/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="{{$.StaticDomain}}/static/vuejs/vue.min.js"></script>
<script src="{{$.StaticDomain}}/static/js/jquery.form.js" type="text/javascript"></script>
<script src="/static/js/main.js?version={{$.Version}}" 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("邮箱不能为空");
}
$("#btnAddMember").button("loading");
return true;
},
success : function (res) {
if(res.errcode === 0){
app.lists.splice(0,0,res.data);
$("#addMemberDialogModal").modal("hide");
}else{
showError(res.message);
}
$("#btnAddMember").button("reset");
},
error : function () {
showError("服务器异常");
$("#btnAddMember").button("reset");
}
});
var app = new Vue({
el : "#userList",
data : {
lists : {{.Result}}
},
delimiters : ['${','}'],
created:function(){
var lists = this.lists
for (var i = 0; i < lists.length; i++) {
lists[i].create_time=this.formatTime(lists[i].create_time)
}
this.lists = lists
},
methods : {
formatTime:function(time){
date = new Date(time)
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(this.formatNumber).join('-') + ' ' + [hour, minute, second].map(this.formatNumber).join(':')
},
formatNumber:function(n){
n = n.toString()
return n[1] ? n : '0' + n
},
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];
if (item.member_id === id) {
console.log(item);
$this.lists[index].status = status;
break;
//$this.lists.splice(index,1,item);
}
}
} else {
alert("操作失败:" + res.message);
}
}
})
},
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);
}
}
})
},
deleteMember : function (id, e) {
var $this = this, user = e.target.dataset.user
if(confirm('您确定要删除用户【'+user+'】吗?')){
$.ajax({
url : "{{urlfor "ManagerController.DeleteMember"}}",
type : "post",
data : { "id":id },
dataType : "json",
success : function (res) {
if (res.errcode === 0) {
for (var index in $this.lists) {
var item = $this.lists[index];
if (item.member_id == id) {
console.log(item);
$this.lists.splice(index,1);
break;
}
}
} else {
alert("操作失败:" + res.message);
}
}
})
}
}
}
});
Vue.nextTick(function () {
$("[data-toggle='tooltip']").tooltip();
});
});
</script>
</body>
</html>