Commit e74399ed authored by limingzhe's avatar limingzhe

fix: 断线 重连 改用storeData

parent 5f8cd4e2
...@@ -157,6 +157,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -157,6 +157,7 @@ export class PlayComponent implements OnInit, OnDestroy {
if (aspect) { if (aspect) {
console.log('aspect : ', aspect); console.log('aspect : ', aspect);
this.initPageData(aspect); this.initPageData(aspect);
this.initStoreData(aspect);
} }
if (data && typeof data == 'object') { if (data && typeof data == 'object') {
...@@ -185,6 +186,50 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -185,6 +186,50 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
// 用于存储私有数据 当翻页时清空
storeData;
initStoreData(aspect) {
const storeDataStr = aspect?.user_aspect;
if (!storeDataStr) {
this.storeData = {};
} else {
this.storeData = JSON.parse(storeDataStr);
}
console.log('this.storeData: ', this.storeData);
}
setStoreData(key, value, isSend=true) {
if (this.storeData) {
console.log('this.storeData: ', this.storeData);
this.storeData[key] = value;
if (isSend) {
this.sendStoreData();
}
}
}
getStoreData(key) {
return this.storeData && this.storeData[key];
}
sendStoreData() {
const data = this.storeData;
if (window && window['courseware']) {
let storeAspect = window['courseware'].storeAspect;
if (storeAspect) {
storeAspect(data);
}
}
}
// 用于存储公共数据 当翻页时清空 // 用于存储公共数据 当翻页时清空
pageData; pageData;
initPageData(aspect) { initPageData(aspect) {
...@@ -502,6 +547,9 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -502,6 +547,9 @@ export class PlayComponent implements OnInit, OnDestroy {
c.onEvent('game_start', (data, next) => { c.onEvent('game_start', (data, next) => {
this.setStoreData('progress', '1');
this.gameStart(); this.gameStart();
if (next) { if (next) {
next(); next();
...@@ -558,6 +606,12 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -558,6 +606,12 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
_initView() { _initView() {
// const spr = new MySprite() // const spr = new MySprite()
// spr.init(this.images.get("result_panel_item")); // spr.init(this.images.get("result_panel_item"));
...@@ -684,7 +738,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -684,7 +738,7 @@ export class PlayComponent implements OnInit, OnDestroy {
relink() { relink() {
const progress = this.getPageData('progress'); const progress = this.getStoreData('progress');
if (this.isTeacher) { if (this.isTeacher) {
if (progress != null) { if (progress != null) {
...@@ -699,7 +753,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -699,7 +753,7 @@ export class PlayComponent implements OnInit, OnDestroy {
this.gameStart(); this.gameStart();
const resultData = this.getPageData('resultData') const resultData = this.getStoreData('resultData')
if (resultData) { if (resultData) {
this.initResultView(resultData); this.initResultView(resultData);
return; return;
...@@ -770,7 +824,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -770,7 +824,7 @@ export class PlayComponent implements OnInit, OnDestroy {
} else { } else {
const resultData = this.getResultData(); const resultData = this.getResultData();
this.sendResult(resultData); this.sendResult(resultData);
this.setPageData('resultData', resultData); this.setStoreData('resultData', resultData);
} }
...@@ -1560,7 +1614,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1560,7 +1614,7 @@ export class PlayComponent implements OnInit, OnDestroy {
if (this.sendBtn && this.sendBtn.visible) { if (this.sendBtn && this.sendBtn.visible) {
if (this.checkClickTargetSv(this.sendBtn)) { if (this.checkClickTargetSv(this.sendBtn)) {
this.sendServerEvent('game_start', {}); this.sendServerEvent('game_start', {});
this.setPageData('progress', '1'); // this.setPageData('progress', '1');
this.playAudio('submit', true); this.playAudio('submit', true);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment