Commit 9589c051 authored by liujiangnan's avatar liujiangnan

feat: 去掉一个原生方法

parent 677c6f35
......@@ -15,8 +15,6 @@ export default class NewClass extends middleLayerBase {
initAir(this);
this.reWriteAir();
this.role = 'student';
this.onMiddleLayerLoadingFinish();
}
async start() {
......@@ -34,6 +32,8 @@ export default class NewClass extends middleLayerBase {
}
const { bundleInfo } = JSON.parse(jsonStr);
console.log("===bundleInfo===", bundleInfo);
this.DOMAIN = bundleInfo.base_url;
this.token = bundleInfo.token;
this.course_id = bundleInfo.course_id;
this.courseware_id = bundleInfo.courseware_id;
......@@ -44,6 +44,8 @@ export default class NewClass extends middleLayerBase {
this.loadOnlineCourseWare(this.course_id, false, this.courseware_id);
this.initListener();
this.onMiddleLayerLoadingFinish();
}
onHomeworkFinish(callBack, data = null) {
......
......@@ -69,41 +69,37 @@ export abstract class middleLayerBase extends cc.Component {
}
callNetworkApiPost(uri, data, callBack) {
this.getBaseUrl((baseUrl) => {
const xhr = new XMLHttpRequest();
const url = `${baseUrl}${uri}`;
xhr.open("POST", url, true);
xhr.setRequestHeader('content-type', 'application/json');
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {
callBack(JSON.parse(xhr.responseText));
}
const xhr = new XMLHttpRequest();
const url = `${this.DOMAIN}${uri}`;
xhr.open("POST", url, true);
xhr.setRequestHeader('content-type', 'application/json');
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {
callBack(JSON.parse(xhr.responseText));
}
xhr.send(JSON.stringify(data));
});
}
xhr.send(JSON.stringify(data));
}
callNetworkApiGet(uri, data, callBack) {
this.getBaseUrl((baseUrl) => {
let queryStr = '?';
const params = [];
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
params.push(`${key}=${data[key]}`);
}
let queryStr = '?';
const params = [];
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
params.push(`${key}=${data[key]}`);
}
queryStr += params.join("&");
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
callBack(xhr.responseText);
}
};
const url = `${baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
});
}
queryStr += params.join("&");
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
callBack(xhr.responseText);
}
};
const url = `${this.DOMAIN}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
}
getConfigInfo(url, callback) {
......@@ -118,30 +114,8 @@ export abstract class middleLayerBase extends cc.Component {
xhr.send();
}
DOMAIN;
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);
});
});
}
}
DOMAIN = "http://staging-openapi.iteachabc.com";
asyncCallNetworkApiGet(apiName, data): Promise<any> {
return new Promise((resolve, reject) => {
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