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"; import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -6,48 +6,135 @@ const { ccclass, property } = cc._decorator; ...@@ -6,48 +6,135 @@ const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class SceneComponent extends MyCocosSceneComponent { 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() { addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
} }
addPreloadAudio() { addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
} }
addPreloadAnima() { addPreloadAnima() {
} }
onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_cantouch = null; _cantouch = null;
initData() { async onLoadEnd() {
// 所有全局变量 默认都是null
this._cantouch = true; this._cantouch = true;
} this.initListener();
initView() { // 浏览记录
this.initBg(); this.currentIndex = this.getStoreCurrentIndex();
this.initBtn(); 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; currentIndex = 0;
leftMove() { leftMove() {
const node = cc.find(`Canvas/bg/L${this.currentIndex+1}`); const node = cc.find(`Canvas/bg/L${this.currentIndex + 1}`);
const nextNode = cc.find(`Canvas/bg/L${this.currentIndex+2}`); const nextNode = cc.find(`Canvas/bg/L${this.currentIndex + 2}`);
this._cantouch = false; this._cantouch = false;
cc.tween(node) cc.tween(node)
.to(.3, { x: -4000 }, { easing: 'cubicInOut' }) .to(.3, { x: -4000 }, { easing: 'cubicInOut' })
...@@ -55,9 +142,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -55,9 +142,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
cc.tween(nextNode) cc.tween(nextNode)
.to(.3, { x: 0 }, { easing: 'cubicInOut' }) .to(.3, { x: 0 }, { easing: 'cubicInOut' })
.call(() => { .call(() => {
this.currentIndex ++; this.currentIndex++;
cc.find(`Canvas/bg/right`).active = this.currentIndex<4; this.storeCurrentIndex();
cc.find(`Canvas/bg/left`).active = this.currentIndex>0; cc.find(`Canvas/bg/right`).active = this.currentIndex < 4;
cc.find(`Canvas/bg/left`).active = this.currentIndex > 0;
this._cantouch = true; this._cantouch = true;
}) })
.start(); .start();
...@@ -66,7 +154,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -66,7 +154,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
rightMove() { 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}`); const beforeNode = cc.find(`Canvas/bg/L${this.currentIndex}`);
this._cantouch = false; this._cantouch = false;
cc.tween(node) cc.tween(node)
...@@ -75,9 +163,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -75,9 +163,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
cc.tween(beforeNode) cc.tween(beforeNode)
.to(.3, { x: 0 }, { easing: 'cubicInOut' }) .to(.3, { x: 0 }, { easing: 'cubicInOut' })
.call(() => { .call(() => {
this.currentIndex --; this.currentIndex--;
cc.find(`Canvas/bg/right`).active = this.currentIndex<4; this.storeCurrentIndex();
cc.find(`Canvas/bg/left`).active = this.currentIndex>0; cc.find(`Canvas/bg/right`).active = this.currentIndex < 4;
cc.find(`Canvas/bg/left`).active = this.currentIndex > 0;
this._cantouch = true; this._cantouch = true;
}) })
.start(); .start();
...@@ -101,16 +190,16 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -101,16 +190,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
const worldPoint = event.getLocation(); const worldPoint = event.getLocation();
const x = worldPoint.x; const x = worldPoint.x;
if (x > this.touchX + 100) { if (x > this.touchX + 100) {
if (this.currentIndex<=0) { if (this.currentIndex <= 0) {
// 已经是第一个了 // 已经是第一个了
return; return;
} }
console.log("======向右滑动======="); console.log("======向右滑动=======");
this.rightMove(); this.rightMove();
} }
if (x < this.touchX - 100) { if (x < this.touchX - 100) {
if (this.currentIndex>=4) { if (this.currentIndex >= 4) {
// 已经是最后一个了 // 已经是最后一个了
return; return;
} }
......
...@@ -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": "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