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,6 +6,7 @@ cc.Class({ ...@@ -6,6 +6,7 @@ cc.Class({
}, },
callNetworkApiPost(baseUrl, uri, data, callBack) { callNetworkApiPost(baseUrl, uri, data, callBack) {
this.getBaseUrl((baseUrl) => {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
const url = `${baseUrl}${uri}`; const url = `${baseUrl}${uri}`;
xhr.open("POST", url, true); xhr.open("POST", url, true);
...@@ -16,9 +17,11 @@ cc.Class({ ...@@ -16,9 +17,11 @@ cc.Class({
} }
} }
xhr.send(JSON.stringify(data)); xhr.send(JSON.stringify(data));
});
}, },
callNetworkApiGet(baseUrl, uri, data, callBack) { callNetworkApiGet(baseUrl, uri, data, callBack) {
this.getBaseUrl((baseUrl) => {
let queryStr = '?'; let queryStr = '?';
const params = []; const params = [];
for (const key in data) { for (const key in data) {
...@@ -37,6 +40,7 @@ cc.Class({ ...@@ -37,6 +40,7 @@ cc.Class({
console.log('url = ' + url); console.log('url = ' + url);
xhr.open('GET', url, true); xhr.open('GET', url, true);
xhr.send(); 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