24
24
</div >
25
25
</div >
26
26
<script type =" text/javascript" >
27
+ Map .prototype .forEachAsync = async function (fn ) {
28
+ return Promise .all (this .forEach (fn));
29
+ };
30
+ Array .prototype .forEachAsync = async function (fn ) {
31
+ return Promise .all (this .map (fn));
32
+ };
27
33
function getSeasonId () {
28
34
let str = window .location .pathname .split (' /' ).filter (x => x);
29
35
if (str .length > 2 )
@@ -55,7 +61,11 @@ function getDetailCla(id) {
55
61
default : break ;
56
62
}
57
63
}
58
- $ (' #infoContent' ).html (` <div class="ui four statistics">
64
+ $ (' #infoContent' ).html (`
65
+ <div class="ui inverted disabled dimmer" id="infoLoader">
66
+ <div class="ui text pink loader">正在加载...</div>
67
+ </div>
68
+ <div class="ui four statistics">
59
69
<div class="statistic">
60
70
<div class="value req">
61
71
${ rankTotal}
@@ -91,15 +101,35 @@ function getDetailCla(id) {
91
101
</div>
92
102
<h2>详细信息</h2><blockquote id="statistic_info"></blockquote>` )
93
103
94
- for (let a of str) {
95
- let cid = a .split (' #' )[0 ], rank = a .split (' #' )[1 ];
96
- fetch (` /sport/queryContest/${ cid} ` )
97
- .then (response => response .json ())
98
- .then (data => {
99
- $ (" #statistic_info" ).append (` <p>${ getGradeName (data .grade ) + getTypeName (data .type ) + data .title } 第 ${ rank} 名。</p>` );
104
+ let map = new Map ();
105
+ $ (' #infoLoader' ).addClass (' active' );
106
+ $ (' #infoLoader' ).removeClass (' disabled' );
107
+ (async function () {
108
+ await str .forEachAsync (async a => {
109
+
110
+ let cid = a .split (' #' )[0 ], rank = a .split (' #' )[1 ];
111
+
112
+ let res = await fetch (` /sport/queryContest/${ cid} ` );
113
+ let data = await res .json ();
114
+ let formalTitle = getGradeName (data .grade ) + getTypeName (data .type ) + data .title ;
115
+ let tmp = map .get (formalTitle);
116
+ if (tmp) {
117
+ map .set (formalTitle, tmp + ' 、' + rank);
118
+ } else {
119
+ map .set (formalTitle, rank);
120
+ }
121
+
122
+ })
123
+ try {
124
+ await map .forEachAsync ((value , key ) => {
125
+ console .log (value, key)
126
+ $ (" #statistic_info" ).append (` <p>${ key} 第 ${ value} 名。</p>` );
100
127
})
101
- }
102
128
129
+ } catch (e) {}
130
+ $ (' #infoLoader' ).removeClass (' active' );
131
+ $ (' #infoLoader' ).addClass (' disabled' );
132
+ }) ();
103
133
}
104
134
function getDetailStu (id ) {
105
135
$ (' #infoModal' ).modal (' show' );
@@ -117,7 +147,10 @@ function getDetailStu(id) {
117
147
default : break ;
118
148
}
119
149
}
120
- $ (' #infoContent' ).html (` <div class="ui four statistics">
150
+ $ (' #infoContent' ).html (`
151
+ <div class="ui inverted disabled dimmer" id="infoLoader">
152
+ <div class="ui text pink loader">正在加载...</div>
153
+ </div><div class="ui four statistics">
121
154
<div class="statistic">
122
155
<div class="value req">
123
156
${ rankTotal}
@@ -153,14 +186,36 @@ function getDetailStu(id) {
153
186
</div>
154
187
<h2>详细信息</h2><blockquote id="statistic_info"></blockquote>` )
155
188
156
- for (let a of str) {
157
- let cid = a .split (' #' )[0 ], rank = a .split (' #' )[1 ];
158
- fetch (` /sport/queryContest/${ cid} ` )
159
- .then (response => response .json ())
160
- .then (data => {
161
- $ (" #statistic_info" ).append (` <p>${ getGradeName (data .grade ) + getTypeName (data .type ) + data .title } 第 ${ rank} 名。</p>` );
189
+ let map = new Map ();
190
+ $ (' #infoLoader' ).addClass (' active' );
191
+ $ (' #infoLoader' ).removeClass (' disabled' );
192
+ (async function () {
193
+ await str .forEachAsync (async a => {
194
+
195
+ let cid = a .split (' #' )[0 ], rank = a .split (' #' )[1 ];
196
+
197
+ let res = await fetch (` /sport/queryContest/${ cid} ` );
198
+ let data = await res .json ();
199
+ let formalTitle = getGradeName (data .grade ) + getTypeName (data .type ) + data .title ;
200
+ let tmp = map .get (formalTitle);
201
+ if (tmp) {
202
+ map .set (formalTitle, tmp + ' 、' + rank);
203
+ } else {
204
+ map .set (formalTitle, rank);
205
+ }
206
+
207
+ })
208
+ try {
209
+ await map .forEachAsync ((value , key ) => {
210
+ console .log (value, key)
211
+ $ (" #statistic_info" ).append (` <p>${ key} 第 ${ value} 名。</p>` );
162
212
})
163
- }
213
+
214
+ } catch (e) {}
215
+ $ (' #infoLoader' ).removeClass (' active' );
216
+ $ (' #infoLoader' ).addClass (' disabled' );
217
+ }) ();
218
+
164
219
165
220
}
166
221
function copyText (text ) {
@@ -215,6 +270,8 @@ function fetchContest() {
215
270
.then (response => response .json ())
216
271
.then (data => {
217
272
$ (' #season_content' ).html (marked .parse (data .content ));
273
+ hljs .highlightAll ();
274
+ $ (' #contest_num' ).html (data .contests .length );
218
275
localStorage .setItem (` season${ getSeasonId ()} _content` , data .content );
219
276
localStorage .setItem (` season${ getSeasonId ()} _contests` , JSON .stringify (data .contests ));
220
277
let contests = data .contests ;
@@ -284,13 +341,17 @@ function fetchSearch() {
284
341
})
285
342
}
286
343
$ (document ).ready (function () {
344
+ hljs .highlightAll ();
287
345
let str = $ (' #titleVal' ).val ();
288
346
console .log (str);
289
347
$ (' title' ).text (` ${ str} - 成绩表 2.0` );
290
348
if (getSeasonId ()) {
291
349
fetchContest (); fetchSearch ();
292
350
293
- setInterval (function () {
351
+ let readyInterval = setInterval (function () {
352
+ if (! getSeasonId ()) {
353
+ clearInterval (readyInterval);
354
+ }
294
355
if (localStorage .getItem (" last_fetch_time" ) != null ) {
295
356
let ls = new Date (localStorage .getItem (" last_fetch_time" ));
296
357
if ((new Date ()) - ls <= 10000 ) return ;
@@ -311,7 +372,8 @@ $('#mainUiContainer').bind('pjax:end', function () {
311
372
NProgress .done ();
312
373
$ (' .ui.mobile.sidebar' ).sidebar (' hide' );
313
374
let str = $ (' #titleVal' ).val ();
314
- console .log (str);
375
+ // console.log(str);
376
+ hljs .highlightAll ();
315
377
$ (' title' ).text (` ${ str} - 成绩表 2.0` );
316
378
let sid = getSeasonId ();
317
379
if (sid) {
@@ -323,8 +385,10 @@ $('#mainUiContainer').bind('pjax:end', function () {
323
385
}
324
386
if (getSeasonId ()) {
325
387
fetchContest (); fetchSearch ();
326
-
327
- setInterval (function () {
388
+ let pjaxInterval = setInterval (function () {
389
+ if (! getSeasonId ()) {
390
+ clearInterval (pjaxInterval);
391
+ }
328
392
if (localStorage .getItem (" last_fetch_time" ) != null ) {
329
393
let ls = new Date (localStorage .getItem (" last_fetch_time" ));
330
394
if ((new Date ()) - ls <= 10000 ) return ;
0 commit comments