app.js
6.71 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
var App = function() {
return {
/** date-box 格式化日期 */
formatDate : function(date) {
return date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
+ date.getDate();
},
formatDateTime : function(date) {
return date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
+ date.getDate() + " " + date.getHours() + ":"
+ date.getMinutes() + ":" + date.getSeconds();
},
/** GridView 格式化Bool列 */
formatBool : function(value, row, index) {
if (value == 1) {
return "是";
} else if (value == 0) {
return "否";
}
return value;
},
/**GridView单元格鼠标悬停提示*/
formatCellTooltip : function (value, row, index) {
return "<span title='" + value + "'>" + value + "</span>";
},
/** 判断字符串是否为null或空字符串 */
isBlank : function(data) {
return data == null || data == '';
},
/** 打开标签页 */
openTab : function(title, url) {
if ($('#tabs').tabs('exists', title)) {
$("#tabs").tabs('select', title);
} else {
// 右键关闭会传过来null
if (url == null) {
return;
}
var content = '<iframe style="width:100%;height:100%;" scrolling="auto" frameborder="0" src="/iframeMenu?url='
+ url + '"></iframe>';
parent.$("#tabs").tabs('add', {
title : title,
content : content,
closable : true
});
}
},
/**转页面打开标签页*/
openTurnTab : function(title, url) {
if (parent.$('#tabs').tabs('exists', title)) {
parent.$("#tabs").tabs('select', title);
} else {
// 右键关闭会传过来null
if (url == null) {
return;
}
url = encodeURI(encodeURI(url));
var content = '<iframe style="width:100%;height:100%;" scrolling="auto" frameborder="0" src="/iframeTurnMenu?url='
+ url + '"></iframe>';
parent.$("#tabs").tabs('add', {
title : title,
content : content,
closable : true
});
}
},
/** 初始化省市级联控件 */
initAddress : function() {
if ($('#combobox-province') == null) {
return;
}
$('#combobox-province').combobox(
{
onShowPanel : function() {
$('#combobox-province').combobox('reload',
'/pub/area?level=0');
}
});
$('#combobox-city').combobox(
{
onShowPanel : function() {
var province = $('#combobox-province').combobox(
'getValue');
if (App.isBlank(province)) {
$('#combobox-city').combobox('hidePanel');
$.messager.alert('消息', '请选择省份', 'warning');
} else {
$('#combobox-city').combobox('reload',
'/pub/area?pCode=' + province);
}
}
});
$('#combobox-area')
.combobox(
{
onShowPanel : function() {
var city = $('#combobox-city').combobox(
'getValue');
if (App.isBlank(city)) {
$('#combobox-area').combobox(
'hidePanel');
$.messager.alert('消息', '请选择城市',
'warning');
} else {
$('#combobox-area').combobox('reload',
'/pub/area?pCode=' + city);
}
}
});
},
/** 关闭新增/修改窗口 */
closeAddDialog : function() {
$('#add-dialog').dialog('close');
$('#add-form').form('clear');
},
/** 关闭新增/修改窗口 */
closeDialog : function(dialog, form) {
$('#' + dialog).dialog('close');
if (form != null && form != '') {
$('#' + form).form('clear');
}
},
/**
* 将form封装成DataGrid的查询参数
* @formId 表单Id
*/
dataGridQueryParams : function(formId) {
var params = new Object();
$.each($('#' + formId).serializeArray(), function(i, item) {
params[item.name] = item.value;
});
return params;
},
/**
* 在页面中任何嵌套层次的窗口中获取顶层窗口
*
* @return 当前页面的顶层窗口对象
*/
getTopWinow : function() {
var p = window;
while (p != p.parent) {
p = p.parent;
}
return p;
},
/**
* 单选按钮组默认选中
* @param name 按钮组名称
* @param selectValue 选中项的值
*/
selectRadio : function(name, selectValue) {
$('[name="' + name + '"]:radio').each(function() {
if (this.value == selectValue) {
this.checked = "checked";
}
});
}
}
}();
(function($) {
//回车事件:查询
document.onkeydown = function(event) {
if(event.keyCode == 13) {
var buttons = $('#search-form').find($('.easyui-linkbutton'));
if (buttons.length > 0) {
buttons[0].click();
}
}
}
/** 确认密码验证 */
$.extend($.fn.validatebox.defaults.rules, {
equals : {
validator : function(value, param) {
return value == $(param[0]).val();
},
message : '两次密码输入应相同'
}
});
$.ajaxSetup({
complete : function(request, textStatus) {
// 通过XMLHttpRequest取得响应头,sessionstatus,
var sessionstatus = request.getResponseHeader("sessionstatus");
if (sessionstatus == 'timeout') {
// 如果超时就处理 ,指定要跳转的页面
var top = App.getTopWinow(); // 获取当前页面的顶层窗口对象
top.location.href = _ctx + "/pub/login"; // 跳转到登陆页面
}
//访问频率
var timerInterval = request.getResponseHeader('TimeInterval');
if (timerInterval != null && timerInterval != '') {
$.messager.alert('提示', '操作间隔为' + timerInterval + '秒,请不要频繁操作');
}
}
});
/**jQuery插件,将form表单序列化成JSON对象*/
$.fn.serializeJson = function() {
var json = {};
$(this.serializeArray()).each(function() {
json[this.name] = this.value;
});
return json;
};
// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for ( var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}
})(jQuery);