Commit 03ad8bbf authored by liujiangnan's avatar liujiangnan

feat: 书本跳转到下一页

parent 34343ce8
{
"ver": "2.0.1",
"uuid": "90f94989-cb3e-49e2-9452-757d066f2144",
"downloadMode": 0,
"duration": 19.435102,
"subMetas": {}
}
\ No newline at end of file
import { asyncDelay, onHomeworkFinish } from "../script/util";
import { asyncDelay, onHomeworkFinish, asyncCallNetworkApiGet, asyncCallNetworkApiPost, buttonOnClick, jumpToCourseWare } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator;
......@@ -6,48 +6,135 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.AudioClip)
bgMusic1: cc.AudioClip = null;
async getKidInfo() {
const kidDataStr = await asyncCallNetworkApiGet('/api/oxford/v1/kid/info', {
token: cc.sys.localStorage.getItem('token')
});
if (kidDataStr) {
return JSON.parse(kidDataStr).data;
}
return null;
}
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
}
addPreloadAnima() {
}
onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_cantouch = null;
initData() {
// 所有全局变量 默认都是null
async onLoadEnd() {
this._cantouch = true;
}
this.initListener();
initView() {
this.initBg();
this.initBtn();
}
// 浏览记录
this.currentIndex = this.getStoreCurrentIndex();
const node = cc.find(`Canvas/bg/L${this.currentIndex + 1}`);
node.x = 0;
initBg() {
}
const middleLayer = cc.find('middleLayer');
if (!middleLayer) {
cc.sys.localStorage.setItem('token', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGhvbmUiOiIxNTUwMDAwMDAwMSIsInNpZ24iOiI0OTliYjg5Yy1lYjI5LTQ2M2EtYjk5ZS0zNDg2NDUwMGEyOTkiLCJpYXQiOjE2NTQ2NzY4MzMsImV4cCI6MTY1NzI2ODgzM30.MacCd_XUhvpNrMukYu8YNRVSbc-hju_WBN_FeiRACuc');
}
const kidDataStr = await asyncCallNetworkApiGet('/api/oxford/v1/kid/info', {
token: cc.sys.localStorage.getItem('token')
});
const kidData = JSON.parse(kidDataStr);
if (!kidData.data || !kidData.data.id) {
middleLayer.getComponent('middleLayer').showTips("用户登录失效,请重新登录");
middleLayer.getComponent('middleLayer').loadOnlineBundle("NJ_login");
return;
}
const btnReturn = cc.find('Canvas/bg/btn_return');
buttonOnClick(btnReturn, () => {
const middleLayer = cc.find('middleLayer');
if (middleLayer) {
middleLayer.getComponent('middleLayer').loadOnlineBundle('NJ_YouLeChang');
}
});
const pid = middleLayer.getComponent('middleLayer').getData('NJ_YueDuJiaYouZhan');
initBtn() {
const classDataStr = await asyncCallNetworkApiGet('/api/syllabus/v1/tree', {
pid: pid, deep: 2
});
const ballData = JSON.parse(classDataStr);
ballData.forEach((data, idx) => {
if (idx >= 5) {
console.warn('idx >= 5');
return;
}
const level = cc.find(`Canvas/bg/L${idx+1}`);
data.children.forEach((book, i) => {
if (i >= 3) {
console.warn('book >= 3');
return;
}
const bookNode = cc.find(`book${i+1}`, level);
bookNode.attr({syllabus_id: book.id, pid: book.pid});
buttonOnClick(bookNode, async () => {
const kidInfo = await this.getKidInfo();
const activeLevels = kidInfo ? kidInfo.active_levels : [];
const activeItem = activeLevels.find(item => item.syllabus_id == data.id);
if (middleLayer && !activeItem) {
// 弹出激活码
middleLayer.getComponent('middleLayer').showActiveWindow();
return;
}
if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer');
const row = book.children.find(row => row.name == '索引页');
if (!row) {
middleLayerComponent.showTips("未配置‘索引页’");
return;
}
middleLayerComponent.setData('NJ_BookTable', {
folderId: book.id,
courseId: row.id,
});
jumpToCourseWare(row.id);
}
});
});
});
// 播放背景音乐
cc.audioEngine.stopMusic();
cc.audioEngine.playMusic(this.bgMusic1, true);
}
storeCurrentIndex() {
const middleLayer = cc.find('middleLayer');
if (!middleLayer) {
return;
}
const middleLayerComponent = middleLayer.getComponent('middleLayer');
middleLayerComponent.setData('NJ_YueDuJiaYouZhan_select_idx', this.currentIndex);
}
getStoreCurrentIndex() {
const middleLayer = cc.find('middleLayer');
if (!middleLayer) {
return 0;
}
const middleLayerComponent = middleLayer.getComponent('middleLayer');
const index = middleLayerComponent.getData('NJ_YueDuJiaYouZhan_select_idx');
return index || 0;
}
currentIndex = 0;
leftMove() {
const node = cc.find(`Canvas/bg/L${this.currentIndex+1}`);
const nextNode = cc.find(`Canvas/bg/L${this.currentIndex+2}`);
const node = cc.find(`Canvas/bg/L${this.currentIndex + 1}`);
const nextNode = cc.find(`Canvas/bg/L${this.currentIndex + 2}`);
this._cantouch = false;
cc.tween(node)
.to(.3, { x: -4000 }, { easing: 'cubicInOut' })
......@@ -55,9 +142,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
cc.tween(nextNode)
.to(.3, { x: 0 }, { easing: 'cubicInOut' })
.call(() => {
this.currentIndex ++;
cc.find(`Canvas/bg/right`).active = this.currentIndex<4;
cc.find(`Canvas/bg/left`).active = this.currentIndex>0;
this.currentIndex++;
this.storeCurrentIndex();
cc.find(`Canvas/bg/right`).active = this.currentIndex < 4;
cc.find(`Canvas/bg/left`).active = this.currentIndex > 0;
this._cantouch = true;
})
.start();
......@@ -66,7 +154,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
rightMove() {
const node = cc.find(`Canvas/bg/L${this.currentIndex+1}`);
const node = cc.find(`Canvas/bg/L${this.currentIndex + 1}`);
const beforeNode = cc.find(`Canvas/bg/L${this.currentIndex}`);
this._cantouch = false;
cc.tween(node)
......@@ -75,9 +163,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
cc.tween(beforeNode)
.to(.3, { x: 0 }, { easing: 'cubicInOut' })
.call(() => {
this.currentIndex --;
cc.find(`Canvas/bg/right`).active = this.currentIndex<4;
cc.find(`Canvas/bg/left`).active = this.currentIndex>0;
this.currentIndex--;
this.storeCurrentIndex();
cc.find(`Canvas/bg/right`).active = this.currentIndex < 4;
cc.find(`Canvas/bg/left`).active = this.currentIndex > 0;
this._cantouch = true;
})
.start();
......@@ -101,16 +190,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
const worldPoint = event.getLocation();
const x = worldPoint.x;
if (x > this.touchX + 100) {
if (this.currentIndex<=0) {
if (this.currentIndex <= 0) {
// 已经是第一个了
return;
}
console.log("======向右滑动=======");
this.rightMove();
}
}
if (x < this.touchX - 100) {
if (this.currentIndex>=4) {
if (this.currentIndex >= 4) {
// 已经是最后一个了
return;
}
......
......@@ -87,7 +87,7 @@ export class MyCocosSceneComponent extends cc.Component {
preload() {
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"]) {
// window["air"].onCourseInScreen = (next) => {
......@@ -95,7 +95,7 @@ export class MyCocosSceneComponent extends cc.Component {
// this.onLoadEnd();
// next();
// };
this.onLoadEnd();
await this.onLoadEnd();
window["air"].hideAirClassLoading();
} else {
this.onLoadEnd();
......
This diff is collapsed.
{
"ver": "2.3.5",
"uuid": "71877d61-effa-4495-acaa-306fe0f14a4a",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 107,
"height": 112,
"platformSettings": {},
"subMetas": {
"btn_return": {
"ver": "1.0.4",
"uuid": "55438c5a-174d-4da0-96b2-e11ea29bd18f",
"rawTextureUuid": "71877d61-effa-4495-acaa-306fe0f14a4a",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 107,
"height": 112,
"rawWidth": 107,
"rawHeight": 112,
"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