@@ -96,14 +96,8 @@ export default {
9696 for (let i = 0 ; i <= this .totalWeek ; i++ ) {
9797 this .lessonsList .push ([]);
9898 }
99- // 强制清理一下缓存
100- if (localStorage .getItem (" refresh" ) === null ) {
101- this .clearLocalCache ();
102- localStorage .setItem (" refresh" , " true" );
103- console .log (" 清理缓存" );
104- } else if (this .curWeek > this .totalWeek || this .curWeek === 0 ) {
105- localStorage .removeItem (" refresh" );
106- }
99+ // 缓存验证
100+ this .validateLocalCache ();
107101 refreshExpCourse ();
108102 refreshNormalCourse ();
109103 this .setActiveDay ();
@@ -160,19 +154,19 @@ export default {
160154 if (Number (this .curWeek ) > Number (this .totalWeek )) {
161155 localStorage .setItem (" cur" , this .totalWeek .toString ())
162156 localStorage .setItem (" lessons" , " []" );
163- return ;
157+ } else {
158+ localStorage .setItem (" cur" , this .curWeek .toString ());
159+ this .getRound (this .curWeek );
160+ localStorage .setItem (" lessons" , JSON .stringify (this .lessonsList [this .curWeek ]));
164161 }
165- localStorage .setItem (" cur" , this .curWeek .toString ());
166- this .getRound (this .curWeek );
167- localStorage .setItem (" lessons" , JSON .stringify (this .lessonsList [this .curWeek ]));
168162 },
169163 // 获取所选周前后一周的课程
170164 getRound : function (index ) {
171- let exp = localStorage .getItem (" exp" );
172- let norm = localStorage .getItem (" norm" );
173165 let setCourse = () => {
174- exp = (exp == null ? [] : JSON .parse (exp));
175- norm = (norm == null ? [] : JSON .parse (norm));
166+ let expStr = localStorage .getItem (" exp" );
167+ let normStr = localStorage .getItem (" norm" );
168+ let exp = (expStr == null ? [] : JSON .parse (expStr));
169+ let norm = (normStr == null ? [] : JSON .parse (normStr));
176170 const fillCourse = async (w ) => {
177171 if (this .lessonsList [w].length === 0 ) {
178172 this .lessonsList [w] = simpleSelectWeek (w, exp .concat (norm));
@@ -186,7 +180,7 @@ export default {
186180 }, 500 );
187181 }
188182
189- if (exp == null ) {
183+ if (localStorage . getItem ( " exp" ) == null ) {
190184 this .show = true ;
191185 refreshExpCourse ((response ) => {
192186 if (response .status !== 200 ) {
@@ -198,7 +192,7 @@ export default {
198192 setCourse ();
199193 });
200194 }
201- if (norm == null ) {
195+ if (localStorage . getItem ( " norm" ) == null ) {
202196 this .show = true ;
203197 refreshNormalCourse ((response ) => {
204198 if (response .status !== 200 ) {
@@ -248,10 +242,20 @@ export default {
248242 return colors[num % colors .length ];
249243 },
250244
251- clearLocalCache : function () {
252- localStorage .removeItem (" lessons" );
253- localStorage .removeItem (" norm" );
254- localStorage .removeItem (" exp" );
245+ validateLocalCache : function () {
246+ let normStamp = localStorage .getItem (" normStamp" );
247+ let expStamp = localStorage .getItem (" expStamp" );
248+ if (normStamp !== START_TIME .toString () || expStamp !== START_TIME .toString ()) {
249+ localStorage .removeItem (" refresh" );
250+ localStorage .removeItem (" lessons" );
251+ this .show = true ;
252+ }
253+ if (normStamp !== START_TIME .toString ()) {
254+ localStorage .removeItem (" norm" );
255+ }
256+ if (expStamp !== START_TIME .toString ()) {
257+ localStorage .removeItem (" exp" );
258+ }
255259 },
256260 }
257261}
0 commit comments