Commit 8b2320d5 authored by liujiangnan's avatar liujiangnan

feat: 测试中间层

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