index.js
7.31 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
$(document).ready(function(){
$.disableBack();
//$.beforeUnload();
var layout=$(document.body).children(".rs-base").children(".rs-layout");
layout.layout({
fit:true
});
var north=layout.layout("panel","north");
var west=layout.layout("panel","west");
var center=layout.layout("panel","center");
var menu=layout.children(".rs-menu");//$(document.body).children(".rs-menu");
var menuSearch=north.find(".menu-search input");
var userMore=north.find(".more");
var userWindow=$(document.body).children(".rs-user");
var btnMenu=west.find(".btn-menu");
var btnHome=west.find(".btn-crm");
var btnExit=west.find(".btn-exit");
var tabs=$('<div class="rs-tabs"></div>').appendTo(center).tabs({
fit : true,
border : false,
plain:true,
// tabHeight:22,
tabWidth:150,
onBeforeClose: function(title,index){
var tab=tabs.tabs("getTab",index);
// var editors=tab.find(".ckeditor");
// for (var i = 0; i < editors.length; i++) {
// var editor = $(editors[i]);
//
// }
return true;
},
onAdd:function(title,index){
$(this).tabs('getTab',index).addClass('rs-box');
}
}).tabs("add", {
title : '首页',
href : './home'
});
initMenu();
initSearchMenu();
initUser();
/*事件绑定*/
layout.bind("_resize.menu",function(){
menu.height(west.height());
});
btnMenu.bind("click.menu",function(){
if(btnMenu.hasClass("shrink")){
menuShrink();
}else{
menuExpand();
}
});
btnHome.bind("click.home",function(){
tabs.tabs("select",0);
});
btnExit.bind("click.exit",function(){
$.messager.confirm(resource.msg_title, resource.onExit,function(r){
if (r){
window.location.href="./logout";
}
});
});
// menu.bind("mouseleave.menu",function(){
// menuShrink();
// });
$(document).bind("click.menu",function(e){ //收菜单
var obj=$(e.target);
// if(obj.closest(".pl-home-page")){ //
// return;
// }
var m=obj.closest(".rs-menu,.pl-home-module");
if(!obj.hasClass("btn-menu")&&m&&m.length==0){
menuShrink();
}
});
function initMenu() {
menu.rs_load().css({
height:west.height(),
top:north.height()
}).rs_load("show");
menuLoad('./menu/select.json');
}
function initSearchMenu(){
menuSearch.combobox({
prompt:resource.index.menuSearch,
valueField:'id',
textField: 'text',
editable:true,
panelWidth:260,
panelHeight:'auto',
panelMaxHeight:200,
hasDownArrow:false,
url:'./menu/select/search.json',
loadFilter: loadFilterUtils,
filter: function(q, row){
var opts = $(this).combobox('options');
//添加判断子菜单是否匹配
var isFind=row[opts.textField].indexOf(q) >= 0;
if(!isFind){
for (var i = 0; i < row.child.length; i++) {
if(row.child[i].indexOf(q) >= 0){
isFind=true;
break;
}
}
}
return isFind;
},
formatter: function(row){
var opts = $(this).combobox('options');
//生成子菜单内容
row.child=[];
var html=row[opts.textField];
appendChild(row.children,1);
return html;
function appendChild(items,c){
if(items){
var t=c+1;
for (var i = 0; i < items.length; i++) {
if(items[i]&&items[i].text){
row.child.push(items[i].text);
html+=('<div class="nav-select">'+appendSpace(c)+items[i].text+'</div>');
appendChild(items[i].children,t);
}
}
}
}
function appendSpace(c){
var space="";
for (var i = 0; i < c; i++) {
space+=("<i class='out'></i>");
}
return space;
}
},
onHidePanel:function(){
var t=menuSearch.combobox("getValue");
if(t){
data=menuSearch.combobox("getData");
if(data){
for (var i = 0; i < data.length; i++) {
if(data[i]&&data[i].id==t&&data[i].url){
showTabUtils({text:formatMenuName(data[i].text),url:data[i].url});
break;
}
}
}
}
}
});
menuSearch.combo('panel').parent().addClass("menu-search-combo");
menuSearch.parent().find(".textbox-text").bind("focus.menuSearch",function(){
$(this).select();
});
}
function initUser(){
userWindow.window({
title:'用户信息'
}).tabs({
fit:true,
tabPosition:'left'
});
var pwdPanel=userWindow.tabs("getTab",0)
userWindow.tabs('update', {
tab: pwdPanel,
options: {
title: '密码修改'
}
});
var pwdForm=pwdPanel.find("form.password");
var lblOldPwd=pwdForm.find("div.oldpwd");
var txtOldPwd=pwdForm.find("input.oldpwd").textbox({
required:true,
invalidMessage:'请输入旧密码',
type:'password'
});
var lblNewPwd=pwdForm.find("div.newpwd");
var txtNewPwd=pwdForm.find("input.newpwd").textbox({
required:true,
invalidMessage:'请输入新密码',
type:'password'
});
var lblRepPwd=pwdForm.find("div.repeatpwd");
var txtRepPwd=pwdForm.find("input.repeatpwd").textbox({
required:true,
invalidMessage:'请输入重复密码',
type:'password'
});
var btnConfirm=pwdForm.find(".confirm");
btnConfirm.bind("click.password",function(){
var oldpwd=$.trim(txtOldPwd.textbox("getValue"));
var newpwd=$.trim(txtNewPwd.textbox("getValue"));
var reppwd=$.trim(txtRepPwd.textbox("getValue"));
if(oldpwd==newpwd){ //cn.runsa.password.newPwdNotMatch
$.messager.alert(resource.msg_title,resource.cn_runsa_password.newPwdNotMatch);
return;
}
if(reppwd!=newpwd){//cn.runsa.password.repeatPwdNotMatch
$.messager.alert(resource.msg_title,resource.cn_runsa_password.repeatPwdNotMatch);
return;
}
if(newpwd.length<8){//cn.runsa.password.newpwdLenthError
$.messager.alert(resource.msg_title,resource.cn_runsa_password.newpwdLenthError);
return;
}
if(pwdForm.form("validate")){
$.messager.progress();
var data={
oldPwd:oldpwd,
newPwd:newpwd,
repPwd:reppwd
};
$.post("./users/password/update.json",data,function(json){
$.messager.progress('close');
if(responseUtils(json)){
$.messager.alert(resource.msg_title,'密码已修改,请重新登录.','info',function(){
window.location.href="./logout";
});
}
});
}
});
userMore.bind("click.user",function(){
userWindow.show().window("center").window("open");
});
}
function formatMenuName(name){
var i=name.lastIndexOf("(");
return i>0?name.substring(0,i):name;
}
});
var animateSpeed=500;
function menuShrink(){
var layout=$(document.body).children(".rs-base").children(".rs-layout");
var west=layout.layout("panel","west");
var btnMenu=west.find(".btn-menu");
var menu=layout.children(".rs-menu");
btnMenu.removeClass("shrink");
menu.animate({
left:-menu.width()+west.width()
}, animateSpeed);
}
function menuExpand(){
var layout=$(document.body).children(".rs-base").children(".rs-layout");
var west=layout.layout("panel","west");
var btnMenu=west.find(".btn-menu");
var menu=layout.children(".rs-menu");
btnMenu.addClass("shrink");
menu.animate({
left:west.width()
}, animateSpeed);
}
function menuLoad(url){
var layout=$(document.body).children(".rs-base").children(".rs-layout");
var menu=layout.children(".rs-menu");
menu.tree({
url:url,
lines:false,
checkbox:false,
onClick: function(node){
if(node.state=="open"){
$(this).tree("collapse",node.target);
}else{
$(this).tree("expand",node.target);
showTabUtils(node);
}
if(node.url&&node.url!=""){
menuShrink();
}
},
onLoadSuccess:function(node, data){
$(this).rs_load("hide");
},
onSelect : showTabUtils
});
}