File tree Expand file tree Collapse file tree 2 files changed +37
-16
lines changed Expand file tree Collapse file tree 2 files changed +37
-16
lines changed Original file line number Diff line number Diff line change 1717<script >
1818import SegmentTag from ' ./../lib/tag.vue' ;
1919import apiurl from ' ./../../apiurl' ;
20+ import AWaitLock from ' ./../../methods/lock' ;
2021
2122export 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: {
58- SegmentTag
59- }
77+ SegmentTag,
78+ },
6079};
6180 </script >
Original file line number Diff line number Diff line change 11const tagsstore = {
22 state : {
3- displayTags : false
3+ displayTags : false ,
4+ tagsData : new Array ( ) ,
5+ tagsLock : new Array ( )
46 } ,
57 mutations : {
68 setDisplayTag ( state , data ) {
You can’t perform that action at this time.
0 commit comments