|
@@ -0,0 +1,366 @@
|
|
|
+import Consts from '../../../util/Consts';
|
|
|
+import Utils from '../../../util/Utils';
|
|
|
+import APIClient from '../../../util/API/APIClient';
|
|
|
+import CourseItem from '../../../component/CourseItem';
|
|
|
+import GoodsItem from '../../../component/GoodsItem';
|
|
|
+import ScrollEventPlugin from '../../../util/ScrollEventPlugin';
|
|
|
+import NotificationCenter from '../../../util/NotificationCenter';
|
|
|
+import {CommandBus, CMD_TYPE} from '../../../util/CommandBus';
|
|
|
+
|
|
|
+class DownloadCollectionScene extends scene {
|
|
|
+ constructor(scope) {
|
|
|
+ super(scope);
|
|
|
+ this.lessonIds = [];
|
|
|
+ this.lessonItems = {};
|
|
|
+ this.rightScrollEvent = new ScrollEventPlugin();
|
|
|
+ this.hasNextPage = false;
|
|
|
+ this.currentIndex = 1;
|
|
|
+ this.noContent = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc 为每一个标签绑定focus事件
|
|
|
+ */
|
|
|
+ initLeftTabOnFocus() {
|
|
|
+ let leftScroll = this.moye.root.getWidgetById('dc-left-tab-scroll');
|
|
|
+ leftScroll.on('focus', e => {
|
|
|
+ if (e.target.id == 'download') {
|
|
|
+ const currentDom = document.getElementById('download-content');
|
|
|
+ if (!currentDom) {
|
|
|
+ this.renderRightDownloadContent();
|
|
|
+ }
|
|
|
+ } else if (e.target.id == 'collection') {
|
|
|
+ const currentDom = document.getElementById('dc-right-content-scroll');
|
|
|
+ if (!currentDom) {
|
|
|
+ this.renderRightCollectionContent();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // ===================== 渲染下载列表逻辑 ======================
|
|
|
+ /**
|
|
|
+ * @desc 渲染出下载列表
|
|
|
+ */
|
|
|
+ renderRightDownloadContent() {
|
|
|
+ // 删除收藏列表节点
|
|
|
+ const courseWrapperNode = document.getElementById('dc-right-content-scroll');
|
|
|
+ if (courseWrapperNode) {
|
|
|
+ courseWrapperNode.parentNode.removeChild(courseWrapperNode);
|
|
|
+ }
|
|
|
+ // 显示下载列表背景
|
|
|
+ document.getElementById('download-background').setAttribute('style', 'visibility:visible');
|
|
|
+ // 重置收藏请求页码
|
|
|
+ this.currentIndex = 1;
|
|
|
+
|
|
|
+ /*
|
|
|
+ // 假数据,方便在网页调试
|
|
|
+ let recs = []
|
|
|
+ for(let i=1; i < 15; i++){
|
|
|
+ recs.push({
|
|
|
+ 'date':'2017-09-01',
|
|
|
+ 'courseName':'同步辅导语文一年级'+i,
|
|
|
+ 'courseID':'course-'+i,
|
|
|
+ 'lessonName':'悯农',
|
|
|
+ 'lessonID':'lesson-'+i,
|
|
|
+ 'downloadStatus':'下载完成',
|
|
|
+ 'createTime':1505187194,
|
|
|
+ 'storageUsage':150211,
|
|
|
+ });
|
|
|
+ }*/
|
|
|
+ // 调安卓获取已下载的文件列表
|
|
|
+ let {status, data, error} = CommandBus.execute({type:CMD_TYPE.DOWNLOAD_ALL_LESSON_STATUS_GET, payload:{}});
|
|
|
+ let recs = [];
|
|
|
+ if (!status && data && data.recs){
|
|
|
+ recs = data.recs;
|
|
|
+ }
|
|
|
+ // 记录已下载的课id,快速观看使用此id
|
|
|
+ this.lessonIds = [];
|
|
|
+ for(let idx in recs){
|
|
|
+ let item = recs[idx];
|
|
|
+ this.lessonIds.push(item['lessonID']);
|
|
|
+ // make a map of lessonID to courseID
|
|
|
+ this.lessonItems[item['lessonID']] = {
|
|
|
+ 'lessonName':item['lessonName'],
|
|
|
+ 'courseID':item['courseID'],
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let downloadTableHtml = this.generateDownloadStatusTable({recs});
|
|
|
+ let wrapper = document.createElement('div');
|
|
|
+ wrapper.setAttribute('id', 'download-content');
|
|
|
+ wrapper.setAttribute('class', 'download-content-wrapper');
|
|
|
+ wrapper.setAttribute('fe-role', 'Scroll');
|
|
|
+ wrapper.setAttribute('fe-cfg', 'scroll_dir:v,scroll_center:con,scroll_duration:0.2,scroll_easing:linea');
|
|
|
+ wrapper.innerHTML = downloadTableHtml;
|
|
|
+ document.getElementById('dc-right-panel').appendChild(wrapper);
|
|
|
+ this.moye.root.reRender();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc 生成下载列表
|
|
|
+ */
|
|
|
+ generateDownloadStatusTable({recs}) {
|
|
|
+ let trAcc = '';
|
|
|
+ let count = 0;
|
|
|
+ for (let idx in recs){
|
|
|
+ let rec = recs[idx];
|
|
|
+ let feCfg = "";
|
|
|
+ if (0 == count){
|
|
|
+ feCfg = "default_focus:yes";
|
|
|
+ }
|
|
|
+ count += 1;
|
|
|
+
|
|
|
+ //downloadDate
|
|
|
+ let downloadDateStr = '2017-09-10';
|
|
|
+ if (rec.createTime){
|
|
|
+ let createDate = new Date();
|
|
|
+ createDate.setTime(rec.createTime);
|
|
|
+ downloadDateStr = Utils.dateFormat(createDate, 'yyyy-MM-dd');
|
|
|
+ }
|
|
|
+ let downloadStatus = rec['downloadStatus'];
|
|
|
+ let downloadDesc = '';
|
|
|
+
|
|
|
+ //storageUsage
|
|
|
+ let storageUsageStr = '';
|
|
|
+ if (rec.storageUsage){
|
|
|
+ storageUsageStr = '' + parseInt(rec.storageUsage/1000) + 'M';
|
|
|
+ }
|
|
|
+
|
|
|
+ //downloadStatus
|
|
|
+ switch (downloadStatus) {
|
|
|
+ case Consts.DOWNLOAD_STATUS_UNDOWNLOAD:
|
|
|
+ downloadDesc = '未下载';
|
|
|
+ break;
|
|
|
+ case Consts.DOWNLOAD_STATUS_ONGOING:
|
|
|
+ // downloadDesc = '已下载'+rec['progress']*100 + '%';
|
|
|
+ downloadDesc = '正在下载';
|
|
|
+ break;
|
|
|
+ case Consts.DOWNLOAD_STATUS_SUCCESS:
|
|
|
+ downloadDesc = '下载完成';
|
|
|
+ break;
|
|
|
+ case Consts.DOWNLOAD_STATUS_FAILED:
|
|
|
+ downloadDesc = '下载失败';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ downloadDesc = '未下载';
|
|
|
+ }
|
|
|
+ if (!rec['lessonName'])
|
|
|
+ {
|
|
|
+ rec['lessonName'] = rec['courseName'];
|
|
|
+ }
|
|
|
+
|
|
|
+ trAcc += `<div id='lesson-download-record-${rec['lessonID']}' class="row" lesson_id="${rec['lessonID']}">
|
|
|
+ <div class="one">${downloadDateStr}</div>
|
|
|
+ <div class="two">${rec['courseName']}</div>
|
|
|
+ <div class="three">${rec['lessonName']}</div>
|
|
|
+ <div class="four">${storageUsageStr}</div>
|
|
|
+ <div class="five">${downloadDesc}</div>
|
|
|
+ <div class="six" >
|
|
|
+ <div id="download-btn-wrapper" fe-fole="Switch">
|
|
|
+ <img src="./assets/img/DownloadCollection/download_enter_btn.png" id="enter-btn-lesson-${rec['lessonID']}" class="download-enter-btn" fe-role="Widget" data-id="${rec['lessonID']}" />
|
|
|
+ <img src="./assets/img/DownloadCollection/download_del_btn.png" id="del-btn-lesson-${rec['lessonID']}" class="download-del-btn" fe-role="Widget" data-id="${rec['lessonID']}" />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>`
|
|
|
+ }
|
|
|
+ const scrollList = `<div class="scroll-list scroll-lines-wrapper clearfix" id="download-status-table-wrapper">${trAcc}</div>`
|
|
|
+ return scrollList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc 下载列表删除操作
|
|
|
+ */
|
|
|
+ deleteDownloadItem(retData) {
|
|
|
+ //send delete cmd
|
|
|
+ let lessonID = retData.lessonID;
|
|
|
+ let {status, data} = CommandBus.execute({type:CMD_TYPE.DOWNLOAD_LESSON_DELETE, payload:{lessonID}});
|
|
|
+ //delete dom node
|
|
|
+
|
|
|
+ //if(0 == status){
|
|
|
+ let curNode = document.getElementById('lesson-download-record-'+lessonID);
|
|
|
+ curNode.parentNode.removeChild(curNode);
|
|
|
+ //}
|
|
|
+
|
|
|
+ this.moye.root.reRender();
|
|
|
+ //找兄弟结点
|
|
|
+ let findIdx = this.lessonIds.indexOf(lessonID);
|
|
|
+ if(-1 == findIdx){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.lessonIds.splice(findIdx, 1);
|
|
|
+ if(findIdx >= this.lessonIds.length){
|
|
|
+ findIdx = this.lessonIds.length - 1;
|
|
|
+ }
|
|
|
+ let nextFocusLessonId = null;
|
|
|
+ if(findIdx >= 0){
|
|
|
+ nextFocusLessonId = this.lessonIds[findIdx];
|
|
|
+ }
|
|
|
+ if(nextFocusLessonId){
|
|
|
+ this.moye.root.getWidgetById('del-btn-lesson-'+nextFocusLessonId).focus();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ================= 收藏内容渲染逻辑 ==================
|
|
|
+ /**
|
|
|
+ * @desc 收藏内容渲染
|
|
|
+ */
|
|
|
+ renderRightCollectionContent() {
|
|
|
+ // 隐藏下载列表的背景
|
|
|
+ document.getElementById('download-background').setAttribute('style', 'visibility:hidden');
|
|
|
+ // 删除下载列表节点
|
|
|
+ const downloadWrapperNode = document.getElementById('download-content');
|
|
|
+ if (downloadWrapperNode) {
|
|
|
+ downloadWrapperNode.parentNode.removeChild(downloadWrapperNode);
|
|
|
+ }
|
|
|
+ // 创建课程列表容器节点并添加到dom中
|
|
|
+ let wrapper = document.createElement('div');
|
|
|
+ wrapper.setAttribute('id', 'dc-right-content-scroll');
|
|
|
+ wrapper.setAttribute('fe-role', 'Scroll');
|
|
|
+ wrapper.setAttribute('fe-cfg', 'scroll_dir:v');
|
|
|
+ const scrollList = `
|
|
|
+ <ul id="dc-right-content-list" class="scroll-list" ></ul>
|
|
|
+ <div id="no-content-message" style="display:none;">
|
|
|
+ 无内容
|
|
|
+ </div>`;
|
|
|
+ wrapper.innerHTML = scrollList;
|
|
|
+ document.getElementById('dc-right-panel').appendChild(wrapper);
|
|
|
+ // 重新渲染
|
|
|
+ this.moye.root.reRender();
|
|
|
+ // 加载收藏课程
|
|
|
+ this.loadCollectionList(this.currentIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc 加载收藏列表
|
|
|
+ */
|
|
|
+ loadCollectionList(index) {
|
|
|
+ //tagId='',返回全部的收藏
|
|
|
+ APIClient.getCollectionList('', index, (isTrue, res) => {
|
|
|
+ if (!isTrue) { return; }
|
|
|
+ if (!res.success) {
|
|
|
+ TVUtil.Toast.show('获取收藏列表失败!', 1500);
|
|
|
+ this.moye.root.reRender();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const { pageNo, pageSize, totalSize, list } = res.data || {};
|
|
|
+ this.hasNextPage = pageNo * pageSize < totalSize ? true : false;
|
|
|
+ this.currentIndex = pageNo;
|
|
|
+ this.renderCollectionList(list, CourseItem, index > 1);
|
|
|
+ this.rightScrollEvent.releaseEventLock();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc 滚动加载下一页收藏列表
|
|
|
+ */
|
|
|
+ initRightScrollReachEndEvent() {
|
|
|
+ this.rightScrollEvent.onScrollToBottom(() => {
|
|
|
+ if (!this.hasNextPage) { return; }//如果没有下一页了,则不继续下面的程序
|
|
|
+ this.loadCollectionList(this.currentIndex + 1);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc 渲染右侧面板中的收藏课程列表
|
|
|
+ */
|
|
|
+ renderCollectionList(dataset, component, isAppend) {
|
|
|
+ let list = document.getElementById('dc-right-content-list');
|
|
|
+
|
|
|
+ if (!isAppend) {
|
|
|
+ list.style.top = '0px';
|
|
|
+ while (list.hasChildNodes()) {
|
|
|
+ list.removeChild(list.lastChild);
|
|
|
+ }
|
|
|
+ this.initRightScrollReachEndEvent();
|
|
|
+ }
|
|
|
+
|
|
|
+ this.noContent = !dataset || dataset.length < 1;
|
|
|
+ FocusEngine.getWidgetById('dc-right-content-scroll').disabled = this.noContent;
|
|
|
+ document.getElementById('no-content-message').style.display = this.noContent ? '' : 'none';
|
|
|
+
|
|
|
+ for (let i in dataset) {
|
|
|
+ let currentItem = dataset[i];
|
|
|
+ let item = document.createElement('li');
|
|
|
+ item.setAttribute('id', `item-${currentItem.id}`);
|
|
|
+ item.setAttribute('class', 'item');
|
|
|
+ item.setAttribute('fe-role', 'Widget');
|
|
|
+ if(0 == i){
|
|
|
+ //第一个课程设为默认父组件的默认焦点子组件
|
|
|
+ item.setAttribute('fe-cfg', 'default_focus:yes');
|
|
|
+ }
|
|
|
+ const itemDataset = {
|
|
|
+ subject: currentItem.title,
|
|
|
+ subjectSub: currentItem.subTitle,
|
|
|
+ buyed: false,
|
|
|
+ img: Consts.IMG_PATH + '/' + currentItem.coverUrl,
|
|
|
+ };
|
|
|
+ item.innerHTML = component.createHTMLString(itemDataset);
|
|
|
+ list.appendChild(item);
|
|
|
+ }
|
|
|
+ this.moye.root.reRender();
|
|
|
+ }
|
|
|
+
|
|
|
+ onCreate() {
|
|
|
+ this.setContentView(require('../../../res/tpl/DownloadCollection.tpl'), {}, 'DownloadCollectionScene', {}, () => {
|
|
|
+ //页面渲染完成异步回调
|
|
|
+ this.initLeftTabOnFocus();
|
|
|
+ this.renderRightDownloadContent();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ onOK(e) {
|
|
|
+ // 点击删除
|
|
|
+ if(e.target.con.classList.contains('download-del-btn')){
|
|
|
+ let lessonID = e.target.con.dataset.id;
|
|
|
+ let title = this.lessonItems[lessonID].lessonName;
|
|
|
+ let parentScene = 'DownloadCollectionScene';
|
|
|
+ this.showScene(require('./DelConfirmScene.js'), { parentScene, lessonID, title });
|
|
|
+ // 点击快速观看
|
|
|
+ } else if (e.target.con.classList.contains('download-enter-btn')) {
|
|
|
+ let lessonID = e.target.con.dataset.id;
|
|
|
+ let courseID = this.lessonItems[lessonID].courseID;
|
|
|
+ let lessonName = this.lessonItems[lessonID].lessonName;
|
|
|
+ this.showScene(require('./LessonScene.js'), {id:lessonID, courseId:courseID, title:lessonName});
|
|
|
+ // 点击courseItem
|
|
|
+ } else if (e.target.con.classList.contains('item')) {
|
|
|
+ let params = e.target.id.split('-');
|
|
|
+ let id = params[1];
|
|
|
+ this.showScene(require(`./CourseScene.js`), { id });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ onKeydown() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ onKeyup() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ onResume(retData) {
|
|
|
+ if (!retData) return;
|
|
|
+ this.deleteDownloadItem(retData);
|
|
|
+ }
|
|
|
+
|
|
|
+ onPause() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ onDestroy() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ onActive() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ onInactive() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ onBack() {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = DownloadCollectionScene;
|