|
@@ -5,6 +5,7 @@ import CourseItem from '../../../component/CourseItem';
|
|
|
import GoodsItem from '../../../component/GoodsItem';
|
|
|
import ScrollEventPlugin from '../../../util/ScrollEventPlugin';
|
|
|
import NotificationCenter from '../../../util/NotificationCenter';
|
|
|
+import WinBoxAPI from '../../../util/WinBoxAPI';
|
|
|
import {CommandBus, CMD_TYPE} from '../../../util/CommandBus';
|
|
|
|
|
|
class DownloadCollectionScene extends scene {
|
|
@@ -18,6 +19,35 @@ class DownloadCollectionScene extends scene {
|
|
|
this.noContent = false;
|
|
|
}
|
|
|
|
|
|
+ fetchDownloadList() {
|
|
|
+ APIClient.getUserDownloadList((isTrue, res) => {
|
|
|
+ // 判断响应内容
|
|
|
+ if (!isTrue || !res || !res.success) {
|
|
|
+ TVUtil.Toast.show('获取下载内容失败', 2000);
|
|
|
+ return;
|
|
|
+ };
|
|
|
+ // 遍历下载列表数据
|
|
|
+ const downloadedList = res.data || [];
|
|
|
+ let recs = [];
|
|
|
+ for (let i in downloadedList) {
|
|
|
+ recs.push(downloadedList[i]);
|
|
|
+ let item = downloadedList[i];
|
|
|
+ // 记录lessonId
|
|
|
+ this.lessonIds = [];
|
|
|
+ this.lessonIds.push(item['lessonId']);
|
|
|
+ // make a map of lessonId to courseId
|
|
|
+ this.lessonItems[item['lessonId']] = {
|
|
|
+ 'lessonName':item['lessonName'],
|
|
|
+ 'courseId':item['courseId'],
|
|
|
+ 'downloadStatus':item['downloadStatus'],
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let downloadStatusTableHtml = this.generateDownloadStatusTable({recs});
|
|
|
+ let downloadStatusTableWrapper = document.getElementById('download-status-table-wrapper');
|
|
|
+ downloadStatusTableWrapper.innerHTML = downloadStatusTableHtml;
|
|
|
+ this.moye.root.reRender();
|
|
|
+ })
|
|
|
+ }
|
|
|
/**
|
|
|
* @desc 为每一个标签绑定focus事件
|
|
|
*/
|
|
@@ -99,91 +129,93 @@ class DownloadCollectionScene extends scene {
|
|
|
/**
|
|
|
* @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>`
|
|
|
+ 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";
|
|
|
}
|
|
|
- const scrollList = `<div class="scroll-list scroll-lines-wrapper clearfix" id="download-status-table-wrapper">${trAcc}</div>`
|
|
|
- return scrollList;
|
|
|
+ count += 1;
|
|
|
+
|
|
|
+ //downloadDate
|
|
|
+ let downloadDateStr = '2017-09-10';
|
|
|
+ if (rec.gmtModified) {
|
|
|
+ let createDate = new Date();
|
|
|
+ createDate.setTime(rec.gmtModified);
|
|
|
+ downloadDateStr = Utils.dateFormat(createDate, 'yyyy-MM-dd');
|
|
|
+ }
|
|
|
+ let downloadStatus = rec['downloadStatus'];
|
|
|
+ let downloadDesc = '';
|
|
|
+
|
|
|
+ //storageUsage
|
|
|
+ let storageUsageStr = rec['resSize'] + '/' + rec['resTotal'];
|
|
|
+ // if (rec.storageUsage || 0){
|
|
|
+ // storageUsageStr = '' + parseInt((rec.storageUsage || 0)/1000) + 'M';
|
|
|
+ // }
|
|
|
+
|
|
|
+ //downloadStatus
|
|
|
+ switch (downloadStatus) {
|
|
|
+ case Consts.DOWNLOAD_STATUS_UNDOWNLOAD:
|
|
|
+ downloadDesc = '未下载';
|
|
|
+ break;
|
|
|
+ case Consts.DOWNLOAD_STATUS_ONGOING:
|
|
|
+ downloadDesc = '正在下载';
|
|
|
+ break;
|
|
|
+ case Consts.DOWNLOAD_STATUS_SUCCESS:
|
|
|
+ downloadDesc = '下载完成';
|
|
|
+ break;
|
|
|
+ case Consts.DOWNLOAD_STATUS_FAILED:
|
|
|
+ downloadDesc = '下载失败';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ downloadDesc = '未下载';
|
|
|
+ }
|
|
|
+ // 删除按钮是否可点击
|
|
|
+ let delDisable = downloadStatus === Consts.DOWNLOAD_STATUS_ONGOING ? true : false;
|
|
|
+ let feRole = delDisable ? '' : 'fe-role="Widget"';
|
|
|
+ let delImg = delDisable ? '<img src="./assets/img/DownloadScene/download_del_disable_btn.png" class="img-btn"/> '
|
|
|
+ : '<img src="./assets/img/DownloadScene/download_del_btn.png" class="img-btn"/>'
|
|
|
+
|
|
|
+ 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">${downloadDesc}(${storageUsageStr})</div>
|
|
|
+ <div class="five" >
|
|
|
+ <div id="download-btn-wrapper" fe-fole="Switch">
|
|
|
+ <div id="enter-btn-lesson-${rec['lessonId']}" class="download-enter-btn" fe-role="Widget" data-id="${rec['lessonId']}">
|
|
|
+ <img src="./assets/img/DownloadScene/download_enter_btn.png" class="img-btn"/>
|
|
|
+ </div>
|
|
|
+ <div id="del-btn-lesson-${rec['lessonId']}" class="download-del-btn" ${feRole} data-id="${rec['lessonId']}" >${delImg}</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>`
|
|
|
+ }
|
|
|
+
|
|
|
+ return `${trAcc}`;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @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);
|
|
|
+ deleteDownloadFile(lessonId, courseId) {
|
|
|
+ WinBoxAPI.deleteDownloadFile(lessonId, courseId, (isTrue, res) => {
|
|
|
+ if (!isTrue || !res || !res.success) {
|
|
|
+ TVUtil.Toast.show('本地文件删除失败', 2000);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //删除dom节点
|
|
|
+ let curNode = document.getElementById('lesson-download-record-'+lessonId);
|
|
|
curNode.parentNode.removeChild(curNode);
|
|
|
- //}
|
|
|
-
|
|
|
this.moye.root.reRender();
|
|
|
//找兄弟结点
|
|
|
- let findIdx = this.lessonIds.indexOf(lessonID);
|
|
|
+ let findIdx = this.lessonIds.indexOf(lessonId);
|
|
|
if(-1 == findIdx){
|
|
|
return;
|
|
|
}
|
|
@@ -196,8 +228,9 @@ class DownloadCollectionScene extends scene {
|
|
|
nextFocusLessonId = this.lessonIds[findIdx];
|
|
|
}
|
|
|
if(nextFocusLessonId){
|
|
|
- this.moye.root.getWidgetById('del-btn-lesson-'+nextFocusLessonId).focus();
|
|
|
+ this.moye.root.getWidgetById('del-btn-lesson-'+nextFocusLessonId).focus();
|
|
|
}
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
// ================= 收藏内容渲染逻辑 ==================
|
|
@@ -303,8 +336,8 @@ class DownloadCollectionScene extends scene {
|
|
|
onCreate() {
|
|
|
this.setContentView(require('../../../res/tpl/DownloadCollection.tpl'), {}, 'DownloadCollectionScene', {}, () => {
|
|
|
//页面渲染完成异步回调
|
|
|
+ this.fetchDownloadList();
|
|
|
this.initLeftTabOnFocus();
|
|
|
- this.renderRightDownloadContent();
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -315,18 +348,22 @@ class DownloadCollectionScene extends scene {
|
|
|
}
|
|
|
// 点击删除
|
|
|
if(e.target.con.classList.contains('download-del-btn')){
|
|
|
- let lessonID = e.target.con.dataset.id;
|
|
|
- let title = this.lessonItems[lessonID].lessonName;
|
|
|
+ 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')) {
|
|
|
+ this.showScene(require('./DelConfirmScene.js'), { parentScene, lessonId, title });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //点击快速进入
|
|
|
+ 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;
|
|
|
+ let downloadStatus = this.lessonItems[lessonId].downloadStatus;
|
|
|
+ this.showScene(require('./LessonScene.js'), {courseId, downloadStatus, id:lessonId, title:lessonName});
|
|
|
+ }
|
|
|
+ //点击收藏
|
|
|
+ if (e.target.con.classList.contains('item')) {
|
|
|
let params = e.target.id.split('-');
|
|
|
let id = params[1];
|
|
|
this.showScene(require(`./CourseScene.js`), { id });
|
|
@@ -342,8 +379,11 @@ class DownloadCollectionScene extends scene {
|
|
|
}
|
|
|
|
|
|
onResume(retData) {
|
|
|
- if (!retData) return;
|
|
|
- this.deleteDownloadItem(retData);
|
|
|
+ if (!retData || !retData.isDelete) return;
|
|
|
+ //send delete cmd
|
|
|
+ let lessonId = retData.lessonId;
|
|
|
+ let courseId = this.lessonItems[lessonId]['courseId']
|
|
|
+ this.deleteDownloadFile(lessonId, courseId)
|
|
|
}
|
|
|
|
|
|
onPause() {
|