Commit 2ec8b7f4 authored by liujiangnan's avatar liujiangnan

feat: 解锁逻辑

parent 94028df4
...@@ -2693,7 +2693,7 @@ ...@@ -2693,7 +2693,7 @@
"__id__": 113 "__id__": 113
} }
], ],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 179 "__id__": 179
...@@ -11569,6 +11569,9 @@ ...@@ -11569,6 +11569,9 @@
"unitScrollView": { "unitScrollView": {
"__id__": 209 "__id__": 209
}, },
"loading": {
"__id__": 181
},
"_id": "07a4e3ps9Eh6nMMwqOJzdc" "_id": "07a4e3ps9Eh6nMMwqOJzdc"
}, },
{ {
......
...@@ -38,9 +38,10 @@ export default class NewClass extends cc.Component { ...@@ -38,9 +38,10 @@ export default class NewClass extends cc.Component {
// 点击课程 // 点击课程
handleClickCourseItem() { handleClickCourseItem(pid) {
const vc = this.Viewer.getComponent("PageViewer"); 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 { ...@@ -73,7 +74,7 @@ export default class NewClass extends cc.Component {
ci.active = true; ci.active = true;
ci.attr({syllabus_id: row.id}); ci.attr({syllabus_id: row.id});
ci.on("click", ()=>{ ci.on("click", ()=>{
this.handleClickCourseItem(); this.handleClickCourseItem(ci[`syllabus_id`]);
}) })
}); });
this.SvContent.addChild(ci); this.SvContent.addChild(ci);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// Learn life-cycle callbacks: // Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html // - 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; const {ccclass, property} = cc._decorator;
...@@ -19,6 +19,9 @@ export default class NewClass extends cc.Component { ...@@ -19,6 +19,9 @@ export default class NewClass extends cc.Component {
@property(cc.Node) @property(cc.Node)
unitScrollView: cc.Node = null; unitScrollView: cc.Node = null;
@property(cc.Node)
loading: cc.Node = null;
handleClickBackBtn() { handleClickBackBtn() {
const vc = this.Viewer.getComponent("PageViewer"); const vc = this.Viewer.getComponent("PageViewer");
vc.toView("HomePage", "leftIn") vc.toView("HomePage", "leftIn")
...@@ -28,15 +31,45 @@ export default class NewClass extends cc.Component { ...@@ -28,15 +31,45 @@ export default class NewClass extends cc.Component {
// onLoad () {} // onLoad () {}
start () { async start () {
this.initView(); 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 = [ const dataBaseArr = [
[ [
...@@ -94,7 +127,8 @@ export default class NewClass extends cc.Component { ...@@ -94,7 +127,8 @@ export default class NewClass extends cc.Component {
const dataArr = JSON.parse(JSON.stringify(dataBaseArr)) const dataArr = JSON.parse(JSON.stringify(dataBaseArr))
// dataArr.length = Math.ceil( Math.random() * dataArr.length ); //随机显示几个假数据 // 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; const svNode = this.unitScrollView;
...@@ -102,7 +136,7 @@ export default class NewClass extends cc.Component { ...@@ -102,7 +136,7 @@ export default class NewClass extends cc.Component {
view.width = svNode.width; view.width = svNode.width;
view.height = svNode.height; view.height = svNode.height;
const itemArr = this.getUnitItemDataArr(dataArr); const itemArr = this.getUnitItemDataArr(rows);
const sv = svNode.getComponent(cc.ScrollView); const sv = svNode.getComponent(cc.ScrollView);
this.initScrollViewItem(sv, itemArr, 1); this.initScrollViewItem(sv, itemArr, 1);
...@@ -126,7 +160,7 @@ export default class NewClass extends cc.Component { ...@@ -126,7 +160,7 @@ export default class NewClass extends cc.Component {
itemNode['data'] = data; itemNode['data'] = data;
itemNode.removeAllChildren(); itemNode.removeAllChildren();
const subArr = data; const subArr = data.children;
const baseX = subItem.x; const baseX = subItem.x;
const baseY = subItem.y; const baseY = subItem.y;
...@@ -143,7 +177,7 @@ export default class NewClass extends cc.Component { ...@@ -143,7 +177,7 @@ export default class NewClass extends cc.Component {
const subData = subArr[j]; const subData = subArr[j];
// console.log("subData: ", subData); // console.log("subData: ", subData);
getSprNodeByUrl(subData.pic_url, (spr) => { getSprNodeByUrl(subData.cover, (spr) => {
const sprNode = spr.node; const sprNode = spr.node;
const picLayer = cc.find("mask/pic_frame", subNode); const picLayer = cc.find("mask/pic_frame", subNode);
...@@ -174,22 +208,23 @@ export default class NewClass extends cc.Component { ...@@ -174,22 +208,23 @@ export default class NewClass extends cc.Component {
} }
// 为方便测试,先全部解锁
const lockCover = cc.find("bg_cover_mask", subNode); const lockCover = cc.find("bg_cover_mask", subNode);
const isLock = Math.floor(Math.random() * 2); lockCover.active = false;
if (isLock) { // 下面是正常解锁逻辑
lockCover.active = true; // const unLock = this.syllabusLockStatusStore[subData.id]==='unlock';
} else { // lockCover.active = !unLock;
lockCover.active = false; // if (i==0&&j==0) {
} // // 说明是第一个
// lockCover.active = false;
// }
subNode.addComponent(cc.Button); subNode.addComponent(cc.Button);
subNode.on("click", () => { subNode.on("click", () => {
const vc = this.Viewer.getComponent("PageViewer"); const vc = this.Viewer.getComponent("PageViewer");
vc.toView("MissionPage", "rightIn") vc.toView("MissionPage", "rightIn")
}) })
} }
const labelNode = cc.instantiate(listLabel); 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