lts.js
7.23 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
/**
* 这里封装一些公共的JS
* @author Robert HG (254963746@qq.com)
*/
/**
* @type {{}}
*/
var LTS = {
colFormatter: {},
ReExp: {
time: /^\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}$/, // yyyy-MM-dd HH:mm:ss
number: /^\d+$/ // 正整数
}
};
/**
* 将JSON对象转为字符串
*/
LTS.colFormatter.stringifyJSON = function (v) {
return v ? JSON.stringify(v) : v;
};
LTS.colFormatter.needFeedbackLabel = function (v) {
return v ? "需要" : "不需要";
};
LTS.colFormatter.jobTypeFormat = function (v) {
if (v == 'CRON') {
return "Cron任务";
} else if (v == "REPEAT") {
return "Repeat任务";
} else if (v == 'REAL_TIME') {
return "实时任务";
} else if (v == 'TRIGGER_TIME') {
return "定时任务";
}
return v;
};
LTS.colFormatter.formatRelyOnPrevCycle = function (v) {
return v ? "依赖" : "不依赖";
};
LTS.colFormatter.formatGroup = function (v, row) {
if (row.nodeType == 'JOB_CLIENT' || row.nodeType == 'TASK_TRACKER') {
return v;
} else {
return "";
}
};
LTS.colFormatter.formatRetryTimes = function (v, row) {
return row['retryTimes'] + "/" + row['maxRetryTimes'];
};
LTS.colFormatter.repeatIntervalFormat = function (v, row) {
if (!row['repeatInterval']) {
return "";
}
return row['repeatInterval'] + "ms";
};
LTS.colFormatter.repeatCountFormat = function (v, row) {
if (!row['repeatInterval']) {
return "";
}
if (row['repeatCount'] == -1) {
return row['repeatedCount'] + '/(无限)';
}
return row['repeatedCount'] + '/' + (row['repeatCount'])
};
template.defaults.escape = false; // 关闭转移功能
template.helper('dateFormat', function (date, format) {
if (!date) {
return "";
}
return DateUtil.format(date, format);
});
template.helper('format', function (v, colFormatter, row) {
var formatterFn = LTS.colFormatter[colFormatter];
return formatterFn ? formatterFn(v, row) : obj;
});
/**
* 封装的分页表格
*/
function LtsTable(options) {
this.cachedParams = {};
//var defaultOpts = {
// url: '',
// templateId: '',
// pageSize: 10,
// container: null
//};
this.container = options.container;
this.pageSize = options.pageSize || 10;
this.templateId = options.templateId;
this.url = options.url;
var _this = this;
_this.renderEmpty = function () {
_this.render({}, 0, {}, 1);
};
_this.render = function (rows, results, params, curPage) {
var html = template(_this.templateId, {rows: rows, results: results, pageSize: _this.pageSize});
_this.container.html(html);
_this.container.children('table').footable();
if (results == 0) results = 1;
_this.container.find(".pagination-sm").twbsPagination({
totalPages: (results % _this.pageSize == 0) ? results / _this.pageSize : results / _this.pageSize + 1,
visiblePages: 7,
startPage: curPage,
first: '«',
prev: '‹',
next: '›',
last: '»',
onPageClick: function (event, page) {
_this.post(_this.cachedParams, page);
}
});
};
_this.post = function (params, curPage) {
params['start'] = (curPage - 1) * _this.pageSize;
params['limit'] = _this.pageSize;
_this.showLoading();
$.ajax({
url: _this.url,
type: 'POST',
dataType: 'json',
data: params,
success: function (json) {
if (json && json.success) {
_this.cachedParams = params;
var results = json['results'];
var rows = json['rows'];
_this.render(rows, results, params, curPage);
} else {
if (json) {
swal(json['msg']);
}
}
},
complete: function () {
_this.hideLoading();
}
});
};
_this.showLoading = function () {
var loading = '<div id="loading" style="width:50px;position:absolute;left: -100px;"><img src="assets/img/loading.gif" style="width:30px;"/></div>';
var offset = _this.container.offset();
var left = _this.container.width() / 2 + offset.left;
if ($("#loading").length == 0) {
$('body').append(loading);
}
$("#loading").offset({top: offset.top + _this.container.height() / 2, left: left});
};
_this.hideLoading = function () {
$("#loading").offset({
left: -100
});
};
}
jQuery.fn.extend({
ltsTable: function (options) {
var container = $(this);
var opts = {};
$.extend(opts, options, {container: container});
return new LtsTable(opts);
}
});
if (window.Highcharts) {
Highcharts.setOptions({
global: {
useUTC: false
},
lang: {
months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
shortMonths: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
weekdays: ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
resetZoom: '查看全图',
resetZoomTitle: '查看全图',
downloadPNG: '下载PNG',
downloadJPEG: '下载JPEG',
downloadPDF: '下载PDF',
downloadSVG: '下载SVG',
exportButtonTitle: '导出成图片',
printButtonTitle: '打印图表',
loading: '数据加载中,请稍候...'
}
});
}
function showLineChart(chartId, title, yTitle, series, colors, valueSuffix) {
if (!colors) {
colors = ['#FCAF64', '#1bd0dc', '#f9b700', '#eb6100', '#eb6877', '#a98fc2', '#9dd30d', '#1c95bd', '#9999ff', '#5674b9', '#009944'];
}
$(chartId).highcharts({
chart: {
zoomType: 'x',
type: 'spline'
},
colors: colors,
title: {
text: title
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: yTitle
},
min: 0,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: valueSuffix || '',
dateTimeLabelFormats: {
minute: "%Y-%m-%d %H:%M"
},
crosshairs: true,
shared: true
},
plotOptions: {
series: {
fillOpacity: 0.1,
shadow: false,
marker: {
enabled: false,
radius: 4,
fillColor: null,
lineWidth: 2,
lineColor: '#FFFFFF',
states: {hover: {enabled: true}}
}
}
},
credits: {
enabled: false
},
series: series
});
}