userList.html
8.98 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>用户管理</title>
<link href="../../css/frame.css" rel="stylesheet" />
<link href="../../scripts/easyui/themes/default/easyui.css" rel="stylesheet" />
<link href="../../scripts/easyui/themes/icon.css" rel="stylesheet" />
<style type="text/css">
#userToolbar {
padding:5px;
height:25px;
width:100%;
}
.l-btn-icon {
display:inline-block;
height:16px;
width:16px;
vertical-align:-2px;
margin-left:5px;
}
#userManagerForm {
width:100%;
height:100%;
}
#userManagerForm table {
height:100%;
width:100%;
border-collapse:collapse;
}
.tdTitle {
width:60px;
}
.operateModify {
color:blue;
}
.operateDelete {
color:red;
}
</style>
</head>
<body>
<div id="userList">
</div>
<div style="height:0;width:0;overflow:hidden;">
<div id="userToolbar">
<a href="#" class="easyui-linkbutton" onclick="showAddUserWindow()" data-options="iconCls:'icon-add'">添加用户</a>
</div>
<div id="userManagerDialog" class="easyui-dialog" data-options="closed:true,modal:true,buttons:'#userWindowBtns'"
style="height:160px;width:500px;">
<form id="userManagerForm">
<table>
<tr>
<td class="tdTitle">用户名</td>
<td class="tdContent">
<input type="text" name="usr" id="usr"/>
</td>
</tr>
<tr>
<td class="tdTitle">密码</td>
<td class="tdContent">
<input type="password" name="pwd" id="pwd" onfocus="removeValue()"/>
</td>
</tr>
</table>
</form>
</div>
<div id="userWindowBtns">
<a href="#" class="easyui-linkbutton" onclick="btnUserManagerHandler()" data-options="iconCls:'icon-save'">保存</a>
<a href="#" class="easyui-linkbutton" onclick="closeUserManagerWindow()" data-options="iconCls:'icon-cancel'">关闭</a>
</div>
</div>
<script src="../../scripts/easyui/jquery.min.js"></script>
<script src="../../scripts/easyui/jquery.easyui.min.js"></script>
<script src="../../scripts/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../../scripts/jquery.validate.min.js"></script>
<script src="../../scripts/jquery.validate.extend.js"></script>
<script src="../../scripts/utilities.js"></script>
<script type="text/javascript">
//操作类型
var operateType = "";
var userUrls = {
list: function () {
return "/do/trafficController/userManager?Command=1&t=" + new Date().getTime();
},
add: function () { return "/do/trafficController/userManager?Command=2&t=" + new Date().getTime(); },
del: function () { return "/do/trafficController/userManager?Command=3&t=" + new Date().getTime(); },
modify: function () { return "/do/trafficController/userManager?Command=4&t=" + new Date().getTime(); }
};
$().ready(function() {
initUserList();
var validateOptions = {
rules: {
usr: {
required: true,
username:true
},
pwd: {
required: true,
rangelength:[3,16]
}
}
};
$("#userManagerForm").validate(validateOptions);
});
//加载用户列表
function initUserList() {
var options = {
url:userUrls.list(),
fit: true,
method:"get",
striped: true,
singleSelect:true,
rownumbers: true,
toolbar:"#userToolbar",
columns: [[
{ field: 'usr', title: '用户名', width: 200, align: 'right' },
{ field: 'pwd', title: '密码', width: 80, align: 'right', hidden: true },
{ field: 'none', title: '操作', width: 150, align: 'center', formatter:createOperateLink}
]],
loadFilter: createJsonDataForDatagrid
};
$("#userList").datagrid(options);
}
//转换成datagrid组件需要的格式
function createJsonDataForDatagrid(data) {
var jsonObj = {
total: 0,
rows:[]
};
if (data.error) {
var allUserString = data.feedback.Msg;
var allUsers = allUserString.split(',');
for (var i = 0; i < allUsers.length; i++) {
if (allUsers[i] != "admin") {
jsonObj.rows.push({
usr: allUsers[i],
pwd: ""
});
}
}
jsonObj.total = jsonObj.rows.length;
}
return jsonObj;
}
function createOperateLink(value,row,index) {
return "<a href='#' class='operateModify' onclick='showModifyUserWindow(\""+row.usr+"\")'>修改</a> <a href='#' class='operateDelete' onclick='deleteUser(\""+row.usr+"\")'>删除</a>";
}
function showAddUserWindow() {
operateType = "add";
openUserManagerWindow({
title:"添加用户"
});
$("#usr").removeAttr("disabled");
}
//修改用户
function showModifyUserWindow(userName) {
operateType = "modify";
openUserManagerWindow({
title:"修改用户"
});
//加载数据
$("#usr").val(userName);
$("#pwd").val("undefined");
$("#userManagerForm").valid();
$("#usr").attr("disabled","disabled");
}
//确定是添加用户,还是修改用户
function btnUserManagerHandler() {
//进行验证
var formObj = $("#userManagerForm");
if (!formObj.valid()) {
$.messager.alert("提示", "参数验证有误,请修改后再提交!", "error");
return;
}
if($("#pwd").val() == "undefined"){
closeUserManagerWindow();
return;
}
//判断是添加,还是修改
var url = "";
if (operateType == "add") {
url = userUrls.add();
} else {
url = userUrls.modify();
}
$("#usr").removeAttr("disabled");
var params = sy.serializeObject(formObj);
$.get(url, params, function (data) {
var msg = null;
if (data.error) {
msg = operateType == "add" ? "添加成功!" : "修改成功!";
$.messager.alert("提示", msg, "info", function () {
closeUserManagerWindow();
});
reloadUserList();
} else {
msg = operateType == "add" ? "添加用户失败!" : "修改用户失败!";
$.messager.alert("提示", msg + "错误:" + data.feedback.Msg, "error");
}
}, "json");
}
//关闭用户管理窗口
function closeUserManagerWindow() {
$("#userManagerDialog").dialog("close");
}
function openUserManagerWindow(options) {
$("#userManagerDialog").dialog(options).dialog("open");
$("#userManagerForm").form("clear");
}
//删除用户
function deleteUser(userName) {
var confirm = $.messager.confirm("提示", "确定要删除该用户吗?", function (isConfirm) {
if (isConfirm) {
$.get(userUrls.del(), {
usr:userName
}, function (data) {
if (data.error) {
$.messager.alert("提示", "删除成功!", "info");
reloadUserList();
} else {
$.messager.alert("提示", "删除失败!", "info");
}
}, "json");
}
});
}
//重新加载用户
function reloadUserList() {
$("#userList").datagrid("reload");
}
function removeValue(){
$("#pwd").val("");
}
</script>
</body>
</html>