Commit 9589c051 authored by liujiangnan's avatar liujiangnan

feat: 去掉一个原生方法

parent 677c6f35
...@@ -15,8 +15,6 @@ export default class NewClass extends middleLayerBase { ...@@ -15,8 +15,6 @@ export default class NewClass extends middleLayerBase {
initAir(this); initAir(this);
this.reWriteAir(); this.reWriteAir();
this.role = 'student'; this.role = 'student';
this.onMiddleLayerLoadingFinish();
} }
async start() { async start() {
...@@ -34,6 +32,8 @@ export default class NewClass extends middleLayerBase { ...@@ -34,6 +32,8 @@ export default class NewClass extends middleLayerBase {
} }
const { bundleInfo } = JSON.parse(jsonStr); const { bundleInfo } = JSON.parse(jsonStr);
console.log("===bundleInfo===", bundleInfo);
this.DOMAIN = bundleInfo.base_url;
this.token = bundleInfo.token; this.token = bundleInfo.token;
this.course_id = bundleInfo.course_id; this.course_id = bundleInfo.course_id;
this.courseware_id = bundleInfo.courseware_id; this.courseware_id = bundleInfo.courseware_id;
...@@ -44,6 +44,8 @@ export default class NewClass extends middleLayerBase { ...@@ -44,6 +44,8 @@ export default class NewClass extends middleLayerBase {
this.loadOnlineCourseWare(this.course_id, false, this.courseware_id); this.loadOnlineCourseWare(this.course_id, false, this.courseware_id);
this.initListener(); this.initListener();
this.onMiddleLayerLoadingFinish();
} }
onHomeworkFinish(callBack, data = null) { onHomeworkFinish(callBack, data = null) {
......
...@@ -69,9 +69,8 @@ export abstract class middleLayerBase extends cc.Component { ...@@ -69,9 +69,8 @@ export abstract class middleLayerBase extends cc.Component {
} }
callNetworkApiPost(uri, data, callBack) { callNetworkApiPost(uri, data, callBack) {
this.getBaseUrl((baseUrl) => {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
const url = `${baseUrl}${uri}`; const url = `${this.DOMAIN}${uri}`;
xhr.open("POST", url, true); xhr.open("POST", url, true);
xhr.setRequestHeader('content-type', 'application/json'); xhr.setRequestHeader('content-type', 'application/json');
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
...@@ -80,11 +79,9 @@ export abstract class middleLayerBase extends cc.Component { ...@@ -80,11 +79,9 @@ export abstract class middleLayerBase extends cc.Component {
} }
} }
xhr.send(JSON.stringify(data)); xhr.send(JSON.stringify(data));
});
} }
callNetworkApiGet(uri, data, callBack) { callNetworkApiGet(uri, data, callBack) {
this.getBaseUrl((baseUrl) => {
let queryStr = '?'; let queryStr = '?';
const params = []; const params = [];
for (const key in data) { for (const key in data) {
...@@ -99,11 +96,10 @@ export abstract class middleLayerBase extends cc.Component { ...@@ -99,11 +96,10 @@ export abstract class middleLayerBase extends cc.Component {
callBack(xhr.responseText); callBack(xhr.responseText);
} }
}; };
const url = `${baseUrl}${uri}${queryStr}`; const url = `${this.DOMAIN}${uri}${queryStr}`;
console.log('url = ' + url); console.log('url = ' + url);
xhr.open('GET', url, true); xhr.open('GET', url, true);
xhr.send(); xhr.send();
});
} }
getConfigInfo(url, callback) { getConfigInfo(url, callback) {
...@@ -118,30 +114,8 @@ export abstract class middleLayerBase extends cc.Component { ...@@ -118,30 +114,8 @@ export abstract class middleLayerBase extends cc.Component {
xhr.send(); xhr.send();
} }
DOMAIN; DOMAIN = "http://staging-openapi.iteachabc.com";
async getBaseUrl(callback) {
const engineInfo = await this.getEngineInfo();
const { isDev } = JSON.parse(engineInfo);
if (isDev == 1) {
this.DOMAIN = "http://staging-teach.cdn.ireadabc.com/";
callback('http://staging-openapi.iteachabc.com');
} else {
this.DOMAIN = "http://teach.cdn.ireadabc.com/";
callback('http://openapi.iteachabc.com');
}
}
getEngineInfo() {
if ((<any>window).air.engineInfo) {
return (<any>window).air.engineInfo;
} else {
return new Promise((resolve, reject) => {
(<any>window).courseware.getEngineInfo(() => {
resolve((<any>window).air.engineInfo);
});
});
}
}
asyncCallNetworkApiGet(apiName, data): Promise<any> { asyncCallNetworkApiGet(apiName, data): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.callNetworkApiGet(apiName, data, (res => { this.callNetworkApiGet(apiName, data, (res => {
......
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