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,41 +69,37 @@ export abstract class middleLayerBase extends cc.Component { ...@@ -69,41 +69,37 @@ 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 = `${this.DOMAIN}${uri}`;
const url = `${baseUrl}${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 = () => { if (xhr.readyState == 4) {
if (xhr.readyState == 4) { callBack(JSON.parse(xhr.responseText));
callBack(JSON.parse(xhr.responseText));
}
} }
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) { if (Object.hasOwnProperty.call(data, key)) {
if (Object.hasOwnProperty.call(data, key)) { params.push(`${key}=${data[key]}`);
params.push(`${key}=${data[key]}`);
}
} }
queryStr += params.join("&"); }
const xhr = new XMLHttpRequest(); queryStr += params.join("&");
xhr.onreadystatechange = () => { const xhr = new XMLHttpRequest();
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) { xhr.onreadystatechange = () => {
callBack(xhr.responseText); if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
} callBack(xhr.responseText);
}; }
const url = `${baseUrl}${uri}${queryStr}`; };
console.log('url = ' + url); const url = `${this.DOMAIN}${uri}${queryStr}`;
xhr.open('GET', url, true); console.log('url = ' + url);
xhr.send(); xhr.open('GET', url, true);
}); 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