Commit af6160f8 authored by 范雪寒's avatar 范雪寒

feat:

parent 226ae6a6
......@@ -15,6 +15,9 @@
"_children": [
{
"__id__": 2
},
{
"__id__": 7
}
],
"_active": false,
......@@ -270,5 +273,79 @@
"_originalWidth": 0,
"_originalHeight": 0,
"_id": "29zXboiXFBKoIV4PQ2liTe"
},
{
"__type__": "cc.Node",
"_name": "middleLayer",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 8
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "6caZQRGatDJJMWpck1fhab"
},
{
"__type__": "d98e34LKINGEIpG3utycEds",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 7
},
"_enabled": true,
"label": null,
"text": "hello",
"_id": "92vsFTcCRNa43x2/GLXFra"
}
]
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.8",
"uuid": "15fea870-2ab5-4a2e-b2c5-9534af654642",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import { initAir } from "./air";
import { middleLayerBase } from "./middleLayerBase";
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends middleLayerBase {
reWriteAir() {
(<any>window).courseware.getData = async (callback) => {
let data = null;
if (this.courseItem && this.courseItem.data) {
data = JSON.parse(this.courseItem.data);
this.log("===成功调用getData===" + this.courseItem.data);
}
callback && callback(data);
}
if (!(<any>window).air) {
(<any>window).air = {};
}
(<any>window).air.hideAirClassLoading = () => {
(<any>window).air.onCourseInScreen && (<any>window).air.onCourseInScreen(() => {
console.log("***成功调用onCourseInScreen***");
});
this.hideWaitingLetters();
this.hideMask();
}
}
showMask() {
}
hideMask() {
}
hideWaitingLetters() {
}
showWaitingLetters() {
}
protected start(): void {
this.node.zIndex = 9999;
cc.game.addPersistRootNode(this.node);
}
role = 'student';
protected onLoad(): void {
initAir(this);
this.reWriteAir();
}
}
{
"ver": "1.0.8",
"uuid": "d98e3e0b-2883-4610-8a46-deeb7270476c",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
export abstract class middleLayerBase extends cc.Component {
abstract reWriteAir(): void;
abstract showMask(): void;
abstract hideMask(): void;
abstract hideWaitingLetters(): void;
abstract showWaitingLetters(): void;
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));
}
}
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]}`);
}
}
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();
});
}
async getBaseUrl(callback) {
const engineInfo = await this.getEngineInfo();
const { isDev } = JSON.parse(engineInfo);
if (isDev == 1) {
callback('http://staging-openapi.iteachabc.com');
} else {
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) {
return new Promise((resolve, reject) => {
this.callNetworkApiGet(apiName, data, (res => {
resolve(res);
}));
});
}
asyncCallNetworkApiPost(uri, data) {
return new Promise((resolve, reject) => {
this.callNetworkApiPost(uri, data, (res) => {
resolve(res);
});
});
}
loadOnlineBundle(bundleName) {
this.callNetworkApiGet(`/api/template/v1/${bundleName}`, {}, (datastr) => {
const data = JSON.parse(datastr);
let configData = null;
if (cc.sys.os == cc.sys.OS_IOS) {
configData = data.data.conf.ios;
} else if (cc.sys.os == cc.sys.OS_ANDROID) {
configData = data.data.conf.android;
} else {
configData = data.data.conf.web_desktop;
}
const sceneName = configData.sceneName;
const version = configData.version;
const bondleUrl = configData.bondleUrl;
this.loadBundle(sceneName, version, bondleUrl);
});
}
currentBundleInfo = null;
reloadBundle() {
const { sceneName, version, bondleUrl } = this.currentBundleInfo;
this.loadBundle(sceneName, version, bondleUrl);
}
loadBundle(sceneName, version, bondleUrl) {
this.currentBundleInfo = { sceneName, version, bondleUrl };
this.showMask();
this.showWaitingLetters();
cc.assetManager.loadBundle(bondleUrl, { version: version }, async (err, bundle) => {
bundle.loadScene(sceneName, null, null, (err, scene) => {
const btnRestart = cc.find('middleLayer/BtnRestart');
btnRestart.active = false;
cc.audioEngine.stopAll();
cc.director.runScene(scene, null, () => {
console.log('sceneName = ' + sceneName);
const canvas = cc.find('Canvas');
const middleLayer = cc.find('middleLayer');
cc.find('middleLayer/ExitBtn').active = true;
this.hideWaitingLetters();
this.hideMask();
canvas.getComponent(cc.Widget).updateAlignment();
middleLayer.scale = canvas.width / middleLayer.width;
// this.showLog('middleLayer.scale = ' + middleLayer.scale);
});
});
});
}
courses = null;
courseIndex = 0;
courseItem = null;
loadOnlineCourseWare(courseId, linkFlag = false) {
this.showWaitingLetters();
let api = `/api/courseware/v1/${courseId}/list`;
if (linkFlag === true) {
api = `/api/courseware/v1/${courseId}/eq/level/list`;
}
this.callNetworkApiGet(api, {}, (datastr) => {
const data = JSON.parse(datastr);
if (data.rows && data.rows.length > 0) {
this.courses = data.rows;
this.courseIndex = data.index || 0;
this.courseItem = data.rows[this.courseIndex];
}
if (this.courses && this.courses.length > 1 && this.courseIndex <= this.courses.length - 1) {
cc.find('middleLayer/BtnRight').active = true;
}
if (this.courseIndex > 0) {
cc.find('middleLayer/BtnLeft').active = false;
}
this.reWriteAir();
this.loadPageBundle();
});
}
loadPageBundle() {
let sceneName, version, bondleUrl = "";
if (cc.sys.os == cc.sys.OS_IOS) {
sceneName = this.courseItem.conf.ios.sceneName;
version = this.courseItem.conf.ios.version;
bondleUrl = this.courseItem.conf.ios.bondleUrl;
} else if (cc.sys.os == cc.sys.OS_ANDROID) {
sceneName = this.courseItem.conf.android.sceneName;
version = this.courseItem.conf.android.version;
bondleUrl = this.courseItem.conf.android.bondleUrl;
} else {
sceneName = this.courseItem.conf.web_desktop.sceneName;
version = this.courseItem.conf.web_desktop.version;
bondleUrl = this.courseItem.conf.web_desktop.bondleUrl;
}
this.loadBundle(sceneName, version, bondleUrl);
}
goPrePage() {
this.goTarIndexPage(this.courseIndex - 1);
}
goNextPage() {
this.goTarIndexPage(this.courseIndex + 1);
}
goTarIndexPage(index) {
if (!this.courses || index == this.courseIndex || index < 0 || index > this.courses.length - 1) {
return;
}
(<any>window).courseware.freeAllOcMethod();
this.courseIndex = index;
this.courseItem = this.courses[this.courseIndex];
this.loadPageBundle();
}
log(str: string) {
cc.log(str);
}
showTips(str: string) {
const tipsNode = new cc.Node();
tipsNode.parent = cc.find('Canvas');
tipsNode.zIndex = 100;
const bg = cc.instantiate(cc.find('middleLayer/bg'));
bg.parent = tipsNode;
bg.active = true;
bg.color = cc.color(100, 100, 100);
const labelNode = new cc.Node();
labelNode.parent = tipsNode;
const label = labelNode.addComponent(cc.Label);
label.string = str;
bg.width = 200;
bg.height = labelNode.height + 20;
cc.tween(tipsNode)
.set({ opacity: 255 })
.delay(1)
.to(1, { opacity: 0 })
.removeSelf()
.start();
}
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "9fdb1995-66ab-43ba-9a0d-1784672ccdf2",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
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