Commit 252528f3 authored by liujiangnan's avatar liujiangnan

feat

parent 21d40a4b
This diff is collapsed.
import { asyncDelay, onHomeworkFinish } from "../script/util"; import { asyncDelay, asyncCallNetworkApiGet, getSpriteFrimeByUrl, buttonOnClick,
showLoading, hideLoading } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent"; import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -18,21 +19,75 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -18,21 +19,75 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
onLoadEnd() { rows = null;
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考 orgId = 9;
this.initData(); routers = [];
async onLoadEnd() {
await this.initData();
this.initView(); this.initView();
this.initListener(); this.initListener();
} }
_cantouch = null; async loadData(pid = null) {
initData() { const query = { orgid: this.orgId };
// 所有全局变量 默认都是null if (pid) {
this._cantouch = true; query["pid"] = pid;
}
const res: any = await asyncCallNetworkApiGet("/api/syllabus/v1/list", query);
const rows = JSON.parse(res).rows;
return rows;
}
async initData() {
this.rows = this.loadData();
}
drawPage() {
const contentNode = cc.find("Canvas/pages/view/content");
const item = cc.find("item", contentNode);
// 清理原来的数据
item.parent = this.node;
contentNode.removeAllChildren();
item.parent = contentNode;
// 绘制
for (let i = 0; i < this.rows.length; i++) {
const row = this.rows[i];
const itemClone = cc.instantiate(item);
itemClone.parent = contentNode;
itemClone.active = true;
itemClone.attr({item_id: row.id});
cc.find(`text`, itemClone).getComponent(cc.Label).string = row.name;
if (row.cover) {
getSpriteFrimeByUrl(row.cover, (spriteFrame) => {
const coverNode = cc.find(`cover`, itemClone);
coverNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
const sx = 70 / coverNode.width;
const sy = 80 / coverNode.height;
coverNode.scale = Math.min(sx, sy);
});
}
buttonOnClick(itemClone, async () => {
this.routers.push(itemClone);
showLoading();
await this.loadData(row.id);
this.drawPage();
hideLoading();
if (this.routers.length > 0) {
cc.find(`Canvas/back`).active = false;
}
});
}
} }
initView() { initView() {
this.initBg(); this.initBg();
this.drawPage();
} }
initBg() { initBg() {
...@@ -41,7 +96,18 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -41,7 +96,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
initListener() { initListener() {
const back = cc.find(`Canvas/back`);
buttonOnClick(back, async () => {
showLoading();
const item = this.routers.pop();
await this.loadData(item.id);
this.drawPage();
hideLoading();
if (this.routers.length === 0) {
back.active = false;
}
});
} }
playLocalAudio(audioName) { playLocalAudio(audioName) {
......
...@@ -87,7 +87,7 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -87,7 +87,7 @@ export class MyCocosSceneComponent extends cc.Component {
preload() { preload() {
const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList); const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList);
cc.assetManager.loadAny(preloadArr, null, null, (err, data) => { cc.assetManager.loadAny(preloadArr, null, null, async (err, data) => {
if (window && window["air"]) { if (window && window["air"]) {
// window["air"].onCourseInScreen = (next) => { // window["air"].onCourseInScreen = (next) => {
...@@ -95,7 +95,7 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -95,7 +95,7 @@ export class MyCocosSceneComponent extends cc.Component {
// this.onLoadEnd(); // this.onLoadEnd();
// next(); // next();
// }; // };
this.onLoadEnd(); await this.onLoadEnd();
window["air"].hideAirClassLoading(); window["air"].hideAirClassLoading();
} else { } else {
this.onLoadEnd(); this.onLoadEnd();
......
This diff is collapsed.
{
"ver": "2.3.5",
"uuid": "e999b601-f784-47f8-bbdf-10fcaeb5f833",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 108,
"height": 113,
"platformSettings": {},
"subMetas": {
"back": {
"ver": "1.0.4",
"uuid": "de271a39-457b-4acc-89c7-d9b75dc64b8e",
"rawTextureUuid": "e999b601-f784-47f8-bbdf-10fcaeb5f833",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 108,
"height": 113,
"rawWidth": 108,
"rawHeight": 113,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"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