| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import { VideoItem } from './VideoItem';
- /**
- * 上传任务状态枚举
- */
- export enum UploadTaskStatus {
- Pending = 0, // 等待中
- Uploading = 1, // 上传中
- Success = 2, // 成功
- Failed = 3, // 失败
- Paused = 4 // 已暂停
- }
- /**
- * 上传任务数据源(用于LazyForEach优化)
- */
- export class UploadTaskDataSource implements IDataSource {
- private tasks: VideoItem[] = [];
- private listeners: DataChangeListener[] = [];
- public totalCount(): number {
- return this.tasks.length;
- }
- public getData(index: number): VideoItem {
- return this.tasks[index];
- }
- public registerDataChangeListener(listener: DataChangeListener): void {
- if (this.listeners.indexOf(listener) < 0) {
- this.listeners.push(listener);
- }
- }
- public unregisterDataChangeListener(listener: DataChangeListener): void {
- const pos = this.listeners.indexOf(listener);
- if (pos >= 0) {
- this.listeners.splice(pos, 1);
- }
- }
- /**
- * 更新数据源
- * @param tasks 新的任务列表
- */
- public updateTasks(tasks: VideoItem[]): void {
- this.tasks = tasks;
- this.notifyDataReload();
- }
- /**
- * 添加任务
- * @param task 任务
- */
- public addTask(task: VideoItem): void {
- this.tasks.push(task);
- this.notifyDataAdd(this.tasks.length - 1);
- }
- /**
- * 移除任务
- * @param index 索引
- */
- public removeTask(index: number): void {
- if (index >= 0 && index < this.tasks.length) {
- this.tasks.splice(index, 1);
- this.notifyDataDelete(index);
- }
- }
- /**
- * 清空任务
- */
- public clearTasks(): void {
- this.tasks = [];
- this.notifyDataReload();
- }
- /**
- * 通知数据重新加载
- */
- private notifyDataReload(): void {
- this.listeners.forEach(listener => {
- listener.onDataReloaded();
- });
- }
- /**
- * 通知数据添加
- * @param index 索引
- */
- private notifyDataAdd(index: number): void {
- this.listeners.forEach(listener => {
- listener.onDataAdd(index);
- });
- }
- /**
- * 通知数据删除
- * @param index 索引
- */
- private notifyDataDelete(index: number): void {
- this.listeners.forEach(listener => {
- listener.onDataDelete(index);
- });
- }
- /**
- * 通知数据变更
- * @param index 索引
- */
- private notifyDataChange(index: number): void {
- this.listeners.forEach(listener => {
- listener.onDataChange(index);
- });
- }
- }
|