Commit 8b2320d5 authored by liujiangnan's avatar liujiangnan

feat: 测试中间层

parent 8f5dd213
......@@ -4,6 +4,7 @@ export function initAir(_this) {
const realAir = {
uploadUrl: "",
uploadData: null,
engineInfo: null,
hideAirClassLoading(templateName, loadData) {
_this.log("***成功调用hideAirClassLoading***");
window.air.onCourseInScreen && window.air.onCourseInScreen(() => {
......@@ -156,6 +157,7 @@ export function initAir(_this) {
_this.log(`===成功调用getEngineInfo===`);
// 调用原生获取机器信息
window.air.getEngineInfoCallback = (res) => {
window.air.engineInfo = res;
callback && callback(JSON.stringify(res));
window.air.getEngineInfoCallback = null;
};
......@@ -202,6 +204,9 @@ export function initAir(_this) {
console.log('汪汪汪')
} else {
console.error('非源生环境');
if(method == 'getEngineInfo'){
window.air.getEngineInfoCallback({isDev: 1});
}
}
},
freeAllOcMethod() {
......
......@@ -6,37 +6,41 @@ cc.Class({
},
callNetworkApiPost(baseUrl, uri, data, callBack) {
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));
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));
}
}
}
xhr.send(JSON.stringify(data));
xhr.send(JSON.stringify(data));
});
},
callNetworkApiGet(baseUrl, uri, data, callBack) {
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);
this.getBaseUrl((baseUrl) => {
let queryStr = '?';
const params = [];
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
params.push(`${key}=${data[key]}`);
}
}
};
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 = `${baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
});
},
// 需要预加载的数量
......@@ -52,6 +56,24 @@ cc.Class({
// this.preloadAll();
},
getBaseUrl(callback) {
if(window.air.engineInfo){
if(window.air.engineInfo.isDev==1){
callback('https://staging-teach.ireadabc.com');
}else{
callback('https://iteachabc.com');
}
}else{
window.air.getEngineInfo(()=>{
if(window.air.engineInfo.isDev==1){
callback('https://staging-teach.ireadabc.com');
}else{
callback('https://iteachabc.com');
}
});
}
},
start() {
this.node.zIndex = 9999;
cc.game.addPersistRootNode(this.node);
......
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