Skip to content

Commit e2732a8

Browse files
author
石源
committed
update
1 parent fbe6755 commit e2732a8

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

src/main/webapp/js/tools.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,33 @@ var Tools = {
7575
return (f.indexOf('.' + new Array(decimals + 1).join('0'), f.length - (decimals + 1)) !== -1 ? f.slice(0, -decimals - 1) : f) + sizes[i];
7676
},
7777

78+
formatMillisec: function (millisec) {
79+
if (!_.isNumber(millisec) || millisec < 0) {
80+
return null;
81+
}
82+
83+
if (millisec < 1000) {
84+
return Math.ceil(millisec) + "ms";
85+
}
86+
87+
millisec /= 1000;
88+
if (millisec < 60) {
89+
return Math.ceil(millisec) + "s";
90+
}
91+
92+
millisec /= 60;
93+
if (millisec < 60) {
94+
return Math.ceil(millisec) + "m";
95+
}
96+
97+
millisec /= 60;
98+
if (millisec < 24) {
99+
return Math.ceil(millisec) + "h";
100+
}
101+
102+
return Math.ceil(millisec / 24) + "d";
103+
},
104+
78105
/*
79106
* LOAD SCRIPTS
80107
* Usage:

src/main/webapp/modules/home.html

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@
6060
},
6161

6262
mounted: function () {
63+
$.fn.dataTable.ext.type.order['duration-pre'] = function (data) {
64+
var matches = data.match(/^(\d+(?:\.\d+)?)\s*([a-z]+)/i);
65+
if (!matches) {
66+
return -1;
67+
}
68+
var duration = parseFloat(matches[1]);
69+
switch (matches[2]) {
70+
case "d":
71+
duration *= 24;
72+
case "h":
73+
duration *= 60;
74+
case "m":
75+
duration *= 60;
76+
case "s":
77+
duration *= 1000;
78+
}
79+
return duration;
80+
};
6381
var me = this, dt = me.dataTable = $(me.$el).find('table:first').DataTable({
6482
bDestroy: true,
6583
bProcessing: true,
@@ -70,13 +88,37 @@
7088
{title: "方法名", data: "methodName", name: "methodName"},
7189
{title: "成功数", data: "successCount", name: "successCount"},
7290
{title: "失败数", data: "errorCount", name: "errorCount"},
73-
{title: "最小时长", data: "minDuration", name: "minDuration"},
74-
{title: "最大时长", data: "maxDuration", name: "maxDuration"},
75-
{title: "总时长", data: "totalDuration", name: "totalDuration"},
91+
{
92+
title: "最小时长",
93+
data: "minDuration",
94+
name: "minDuration",
95+
type: "duration",
96+
render: function (data, type, row, meta) {
97+
return Tools.formatMillisec(data);
98+
}
99+
},
100+
{
101+
title: "最大时长",
102+
data: "maxDuration",
103+
name: "maxDuration",
104+
type: "duration",
105+
render: function (data, type, row, meta) {
106+
return Tools.formatMillisec(data);
107+
}
108+
},
109+
{
110+
title: "总时长",
111+
data: "totalDuration",
112+
name: "totalDuration",
113+
type: "duration",
114+
render: function (data, type, row, meta) {
115+
return Tools.formatMillisec(data);
116+
}
117+
},
76118
{
77119
title: "平均时长",
78120
render: function (data, type, row, meta) {
79-
return Math.round(row.totalDuration / (row.successCount + row.errorCount));
121+
return Tools.formatMillisec(row.totalDuration / (row.successCount + row.errorCount));
80122
}
81123
}
82124
],

0 commit comments

Comments
 (0)