Commit 2ec8b7f4 authored by liujiangnan's avatar liujiangnan

feat: 解锁逻辑

parent 94028df4
......@@ -2693,7 +2693,7 @@
"__id__": 113
}
],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 179
......@@ -11569,6 +11569,9 @@
"unitScrollView": {
"__id__": 209
},
"loading": {
"__id__": 181
},
"_id": "07a4e3ps9Eh6nMMwqOJzdc"
},
{
......
......@@ -38,9 +38,10 @@ export default class NewClass extends cc.Component {
// 点击课程
handleClickCourseItem() {
handleClickCourseItem(pid) {
const vc = this.Viewer.getComponent("PageViewer");
vc.toView("UnitPage", "rightIn")
vc.unitPage.attr({syllabus_pid: pid});
vc.toView("UnitPage", "rightIn");
}
// 获取课程清单
......@@ -73,7 +74,7 @@ export default class NewClass extends cc.Component {
ci.active = true;
ci.attr({syllabus_id: row.id});
ci.on("click", ()=>{
this.handleClickCourseItem();
this.handleClickCourseItem(ci[`syllabus_id`]);
})
});
this.SvContent.addChild(ci);
......
......@@ -6,7 +6,7 @@
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { getSprNodeByUrl, setSprNodeMaxLen } from "./util";
import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util";
const {ccclass, property} = cc._decorator;
......@@ -19,6 +19,9 @@ export default class NewClass extends cc.Component {
@property(cc.Node)
unitScrollView: cc.Node = null;
@property(cc.Node)
loading: cc.Node = null;
handleClickBackBtn() {
const vc = this.Viewer.getComponent("PageViewer");
vc.toView("HomePage", "leftIn")
......@@ -28,15 +31,45 @@ export default class NewClass extends cc.Component {
// onLoad () {}
start () {
this.initView();
async start () {
this.loading.active = true;
await this.initView();
this.loading.active = false;
}
async initView() {
await this.initUnitListView();
}
initView() {
this.initUnitListView();
syllabusLockStatusStore = {}; // 课件是否解锁的存储对象 { 99343: 'locked', 19834: 'unlock' }
syllabusFinishedStore = {}; // 课件是否完成的存储对象 { 99343: 'finished', 19834: 'unfinish' }
async getAndStoreSyllabusStatus(tree) {
const oneFlow = []; // 第一层需要获取解锁状态
const twoFlow = []; // 第二层需要获取完成状态
tree.forEach(item => {
item.children.forEach(one => {
oneFlow.push(one.id);
one.children.forEach(two => {
twoFlow.push(two.id);
});
});
});
const {rows} = await asyncCallNetworkApiGet(`/api/kyxq/v1/user/syllabus/status`, {syllabuses: [...oneFlow, ...twoFlow].join(`,`)});
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
if (oneFlow.includes(row.id)) {
this.syllabusLockStatusStore[row.id] = row.unlock == 0 ? 'locked' : 'unlock';
}
if (twoFlow.includes(row.id)) {
this.syllabusFinishedStore[row.id] = row.end == 0 ? 'unfinish' : 'finished';
}
}
}
initUnitListView() {
async initUnitListView() {
const dataBaseArr = [
[
......@@ -94,7 +127,8 @@ export default class NewClass extends cc.Component {
const dataArr = JSON.parse(JSON.stringify(dataBaseArr))
// dataArr.length = Math.ceil( Math.random() * dataArr.length ); //随机显示几个假数据
const {rows} = await asyncCallNetworkApiGet(`/api/syllabus/v2/tree`, {pid: this.node['syllabus_pid'], deep: 2});
await this.getAndStoreSyllabusStatus(rows);
const svNode = this.unitScrollView;
......@@ -102,7 +136,7 @@ export default class NewClass extends cc.Component {
view.width = svNode.width;
view.height = svNode.height;
const itemArr = this.getUnitItemDataArr(dataArr);
const itemArr = this.getUnitItemDataArr(rows);
const sv = svNode.getComponent(cc.ScrollView);
this.initScrollViewItem(sv, itemArr, 1);
......@@ -126,7 +160,7 @@ export default class NewClass extends cc.Component {
itemNode['data'] = data;
itemNode.removeAllChildren();
const subArr = data;
const subArr = data.children;
const baseX = subItem.x;
const baseY = subItem.y;
......@@ -143,7 +177,7 @@ export default class NewClass extends cc.Component {
const subData = subArr[j];
// console.log("subData: ", subData);
getSprNodeByUrl(subData.pic_url, (spr) => {
getSprNodeByUrl(subData.cover, (spr) => {
const sprNode = spr.node;
const picLayer = cc.find("mask/pic_frame", subNode);
......@@ -174,22 +208,23 @@ export default class NewClass extends cc.Component {
}
// 为方便测试,先全部解锁
const lockCover = cc.find("bg_cover_mask", subNode);
const isLock = Math.floor(Math.random() * 2);
if (isLock) {
lockCover.active = true;
} else {
lockCover.active = false;
}
lockCover.active = false;
// 下面是正常解锁逻辑
// const unLock = this.syllabusLockStatusStore[subData.id]==='unlock';
// lockCover.active = !unLock;
// if (i==0&&j==0) {
// // 说明是第一个
// lockCover.active = false;
// }
subNode.addComponent(cc.Button);
subNode.on("click", () => {
const vc = this.Viewer.getComponent("PageViewer");
vc.toView("MissionPage", "rightIn")
})
}
const labelNode = cc.instantiate(listLabel);
......
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