Skip to content

Commit e79b83e

Browse files
authored
Merge branch 'master' into fix-bugs
2 parents 619bd60 + e378add commit e79b83e

File tree

4 files changed

+69
-18
lines changed

4 files changed

+69
-18
lines changed

src/components/lib/AjaxTable.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export default {
4545
this.load_data();
4646
},
4747
load_data() {
48+
let limit = this.limit;
4849
this.loading = true;
4950
this.$axios
5051
.get(this.ajax_url, {
@@ -54,9 +55,11 @@ export default {
5455
}
5556
})
5657
.then(res => {
57-
this.total = res.data.count;
58-
this.tableData = res.data.res.map(this.process);
59-
this.loading = false;
58+
if (limit === this.limit) {
59+
this.total = res.data.count;
60+
this.tableData = res.data.res.map(this.process);
61+
this.loading = false;
62+
}
6063
})
6164
.catch(err => {
6265
this.$SegmentMessage.error(this, '[Ajax Table] Request Failed');

src/components/problem/listTag.vue

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,64 @@
1717
<script>
1818
import ProblemTag from './../lib/problemTag.vue';
1919
import apiurl from './../../apiurl';
20+
import AWaitLock from './../../methods/lock';
2021
2122
export default {
2223
name: 'listTag',
2324
data() {
2425
return {
25-
rendertags: []
26+
rendertags: new Array(),
2627
};
2728
},
2829
props: {
2930
tags: {
30-
type: Array
31+
type: Array,
32+
required: true,
3133
},
3234
},
3335
watch: {
3436
tags() {
3537
this.loadTag();
36-
}
38+
},
3739
},
3840
methods: {
3941
loadTag() {
4042
this.rendertags = [];
41-
for(let i = 0; i < this.tags.length; i += 1) {
42-
this.$axios
43-
.get(apiurl('/problem/tag/' + this.tags[i]))
44-
.then(detail => {
45-
let data = detail.data;
46-
this.rendertags.push({
47-
color: data.res.color,
48-
content: data.res.content
49-
});
43+
let t = this.$store.state.tags;
44+
for (let i = 0; i < this.tags.length; i += 1) {
45+
if (t.tagsLock[this.tags[i]] === undefined) {
46+
t.tagsLock[this.tags[i]] = new AWaitLock();
47+
}
48+
if (t.tagsData[this.tags[i]] !== undefined) {
49+
this.rendertags[i] = t.tagsData[this.tags[i]];
50+
} else {
51+
t.tagsLock[this.tags[i]].acquire().then(() => {
52+
if (t.tagsData[this.tags[i]] !== undefined) {
53+
t.tagsLock[this.tags[i]].release();
54+
this.rendertags[i] = t.tagsData[this.tags[i]];
55+
} else {
56+
this.$axios
57+
.get(apiurl('/problem/tag/' + this.tags[i]))
58+
.then((detail) => {
59+
let data = detail.data.res;
60+
t.tagsData[this.tags[i]] = {
61+
color: data.color,
62+
content: data.content,
63+
};
64+
this.rendertags[i] = t.tagsData[this.tags[i]];
65+
t.tagsLock[this.tags[i]].release();
66+
});
67+
}
5068
});
69+
}
5170
}
52-
}
71+
},
5372
},
5473
mounted() {
5574
this.loadTag();
5675
},
5776
components: {
5877
ProblemTag
59-
}
78+
},
6079
};
6180
</script>

src/methods/lock.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class AWaitLock {
2+
constructor() {
3+
this.lockQueue = [];
4+
this.locked = false;
5+
}
6+
7+
async acquire() {
8+
if (this.locked) {
9+
let that = this;
10+
await new Promise((resolve) => {
11+
that.lockQueue.push(resolve);
12+
});
13+
}
14+
this.locked = true;
15+
return true;
16+
}
17+
18+
release() {
19+
this.locked = false;
20+
let resolve = this.lockQueue.pop();
21+
if (resolve) {
22+
resolve();
23+
}
24+
}
25+
}
26+
27+
export default AWaitLock;

src/store/tags.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const tagsstore = {
22
state: {
3-
displayTags: false
3+
displayTags: false,
4+
tagsData: new Array(),
5+
tagsLock: new Array()
46
},
57
mutations: {
68
setDisplayTag(state, data) {

0 commit comments

Comments
 (0)