|
|
@@ -65,6 +65,8 @@ export struct UploadMusicPage {
|
|
|
@State @Watch('onDuplicateActionChange') selectedDuplicateIndex: number[] = [0];
|
|
|
@State uploadProgress: number = 0;
|
|
|
@State uploadSpeed: string = '0 KB/s';
|
|
|
+ @State uploadReceivedSize: number = 0;
|
|
|
+ @State totalSize: number = 0;
|
|
|
@State uploadedCount: number = 0;
|
|
|
@State totalUploadCount: number = 0;
|
|
|
@State isUploading: boolean = false;
|
|
|
@@ -77,6 +79,9 @@ export struct UploadMusicPage {
|
|
|
@State isLoadingFolders: boolean = false;
|
|
|
@State pendingCount: number = 0;
|
|
|
@State finishedCount: number = 0;
|
|
|
+ // 上传速度计算相关变量
|
|
|
+ private lastUploadTime: number = 0;
|
|
|
+ private lastUploadedSize: number = 0;
|
|
|
// RemoteDriveManager实例
|
|
|
private webdavManager: RemoteDriveManager = RemoteDriveManager.getInstance();
|
|
|
// 性能优化:使用LazyDataSource优化队列列表渲染
|
|
|
@@ -364,6 +369,8 @@ export struct UploadMusicPage {
|
|
|
*/
|
|
|
private handleUploadStart(): void {
|
|
|
this.isUploading = true;
|
|
|
+ this.lastUploadTime = Date.now();
|
|
|
+ this.lastUploadedSize = 0;
|
|
|
Logger.info(TAG, '上传开始');
|
|
|
}
|
|
|
|
|
|
@@ -373,13 +380,32 @@ export struct UploadMusicPage {
|
|
|
private handleUploadProgress(): void {
|
|
|
const uploaded = this.webdavManager.uploadReceivedSize;
|
|
|
const total = this.webdavManager.uploadTotalSize;
|
|
|
-
|
|
|
+ this.uploadReceivedSize = uploaded;
|
|
|
+ this.totalSize = total;
|
|
|
if (total > 0) {
|
|
|
this.uploadProgress = Math.floor((uploaded / total) * 100);
|
|
|
|
|
|
- // 计算上传速度(简化版,实际应该基于时间差计算)
|
|
|
- const speedMBps = uploaded / (1024 * 1024);
|
|
|
- this.uploadSpeed = `${speedMBps.toFixed(2)} MB/s`;
|
|
|
+ // 计算上传速度(基于时间差计算)
|
|
|
+ const currentTime = Date.now();
|
|
|
+ if (this.lastUploadTime > 0) {
|
|
|
+ const timeDiff = (currentTime - this.lastUploadTime) / 1000; // 转换为秒
|
|
|
+ const sizeDiff = uploaded - this.lastUploadedSize; // 字节差
|
|
|
+
|
|
|
+ if (timeDiff > 0 && sizeDiff >= 0) {
|
|
|
+ const speedBytesPerSecond = sizeDiff / timeDiff;
|
|
|
+ if (speedBytesPerSecond < 1024) {
|
|
|
+ this.uploadSpeed = `${speedBytesPerSecond.toFixed(2)} B/s`;
|
|
|
+ } else if (speedBytesPerSecond < 1024 * 1024) {
|
|
|
+ this.uploadSpeed = `${(speedBytesPerSecond / 1024).toFixed(2)} KB/s`;
|
|
|
+ } else {
|
|
|
+ this.uploadSpeed = `${(speedBytesPerSecond / (1024 * 1024)).toFixed(2)} MB/s`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新上次记录的时间和大小
|
|
|
+ this.lastUploadTime = currentTime;
|
|
|
+ this.lastUploadedSize = uploaded;
|
|
|
}
|
|
|
|
|
|
Logger.info(TAG, `上传进度: ${this.uploadProgress}%`);
|
|
|
@@ -780,6 +806,23 @@ export struct UploadMusicPage {
|
|
|
return lastSlash >= 0 ? normalized.substring(lastSlash + 1) : normalized;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 格式化文件大小
|
|
|
+ * @param sizeInBytes 文件大小(字节)
|
|
|
+ * @returns 格式化后的文件大小字符串
|
|
|
+ */
|
|
|
+ private formatFileSize(sizeInBytes: number): string {
|
|
|
+ if (sizeInBytes < 1024) {
|
|
|
+ return `${sizeInBytes} B`;
|
|
|
+ } else if (sizeInBytes < 1024 * 1024) {
|
|
|
+ return `${(sizeInBytes / 1024).toFixed(2)} KB`;
|
|
|
+ } else if (sizeInBytes < 1024 * 1024 * 1024) {
|
|
|
+ return `${(sizeInBytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
|
+ } else {
|
|
|
+ return `${(sizeInBytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 移除已选文件
|
|
|
* @param index 文件索引
|
|
|
@@ -1137,8 +1180,10 @@ export struct UploadMusicPage {
|
|
|
Column({ space: 16 }) {
|
|
|
// 标题行
|
|
|
Row({ space: 8 }) {
|
|
|
- Text('⏫')
|
|
|
+ SymbolGlyph($r('sys.symbol.text_and_arrow_up'))
|
|
|
.fontSize(20)
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Text('上传中')
|
|
|
.fontSize(16)
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
@@ -1149,8 +1194,10 @@ export struct UploadMusicPage {
|
|
|
// 当前文件信息卡片
|
|
|
Column({ space: 10 }) {
|
|
|
Row({ space: 8 }) {
|
|
|
- Text('🎵')
|
|
|
- .fontSize(18)
|
|
|
+ SymbolGlyph($r('sys.symbol.doc_text'))
|
|
|
+ .fontSize(20)
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Text(this.currentTask.name)
|
|
|
.fontSize(14)
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
@@ -1179,7 +1226,15 @@ export struct UploadMusicPage {
|
|
|
|
|
|
Text(`${this.uploadSpeed}`)
|
|
|
.fontSize(13)
|
|
|
- .fontColor(this.isDarkMode ? '#99FFFFFF' : '#8E8E93')
|
|
|
+ .fontColor($r('app.color.text_color'))
|
|
|
+ .opacity(0.8)
|
|
|
+ .textAlign(TextAlign.End)
|
|
|
+ Blank()
|
|
|
+ Text(`${this.formatFileSize(this.uploadReceivedSize)} / ${this.formatFileSize(this.totalSize)}`)
|
|
|
+ .fontSize(12)
|
|
|
+ .fontColor($r('app.color.text_color'))
|
|
|
+ .opacity(0.8)
|
|
|
+ .textAlign(TextAlign.End)
|
|
|
}
|
|
|
.width('100%')
|
|
|
|
|
|
@@ -1264,8 +1319,10 @@ export struct UploadMusicPage {
|
|
|
Column({ space: 16 }) {
|
|
|
// 标题行
|
|
|
Row({ space: 8 }) {
|
|
|
- Text('📊')
|
|
|
+ SymbolGlyph($r('sys.symbol.ranking'))
|
|
|
.fontSize(20)
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Text('任务队列')
|
|
|
.fontSize(16)
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
@@ -1406,8 +1463,10 @@ export struct UploadMusicPage {
|
|
|
StartUploadButton() {
|
|
|
Button({ type: ButtonType.Normal }) {
|
|
|
Row({ space: 10 }) {
|
|
|
- Text('🚀')
|
|
|
+ SymbolGlyph($r('sys.symbol.arrow_up_to_line'))
|
|
|
.fontSize(20)
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Text('开始上传')
|
|
|
.fontSize(16)
|
|
|
.fontWeight(FontWeight.Bold)
|
|
|
@@ -1415,11 +1474,10 @@ export struct UploadMusicPage {
|
|
|
}
|
|
|
.width('100%')
|
|
|
.height(54)
|
|
|
- .backgroundColor(this.themeColor)
|
|
|
- .fontColor('#FFFFFF')
|
|
|
+ .backgroundColor($r('app.color.index_background'))
|
|
|
.borderRadius(12)
|
|
|
.enabled(!this.isUploading && this.selectedFiles.length > 0 && this.selectedAccount !== null)
|
|
|
- .opacity((!this.isUploading && this.selectedFiles.length > 0 && this.selectedAccount !== null) ? 1.0 : 0.4)
|
|
|
+ .opacity((!this.isUploading && this.selectedFiles.length > 0 && this.selectedAccount !== null) ? 1.0 : 0.9)
|
|
|
.shadow({
|
|
|
radius: 12,
|
|
|
color: this.themeColor + '50',
|
|
|
@@ -1440,8 +1498,10 @@ export struct UploadMusicPage {
|
|
|
Column({ space: 16 }) {
|
|
|
// 标题行
|
|
|
Row({ space: 8 }) {
|
|
|
- Text('📁')
|
|
|
+ SymbolGlyph($r('sys.symbol.folder'))
|
|
|
.fontSize(20)
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Text('远程配置')
|
|
|
.fontSize(16)
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
@@ -1457,8 +1517,6 @@ export struct UploadMusicPage {
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
.fontColor(this.isDarkMode ? '#99FFFFFF' : '#66000000')
|
|
|
Row({ space: 8 }) {
|
|
|
- Text('📂')
|
|
|
- .fontSize(18)
|
|
|
|
|
|
Text(this.uploadPath || '请选择远程目录')
|
|
|
.fontSize(15)
|
|
|
@@ -1782,8 +1840,10 @@ export struct UploadMusicPage {
|
|
|
Column({ space: 16 }) {
|
|
|
// 标题行
|
|
|
Row({ space: 8 }) {
|
|
|
- Text('🎵')
|
|
|
+ SymbolGlyph($r('sys.symbol.doc_text'))
|
|
|
.fontSize(20)
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Text('选择文件')
|
|
|
.fontSize(16)
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
@@ -1795,8 +1855,10 @@ export struct UploadMusicPage {
|
|
|
Row({ space: 10 }) {
|
|
|
Button({ type: ButtonType.Normal }) {
|
|
|
Row({ space: 6 }) {
|
|
|
- Text('📁')
|
|
|
- .fontSize(16)
|
|
|
+ SymbolGlyph($r('sys.symbol.folder'))
|
|
|
+ .fontSize(20)
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Text('从文件管理器')
|
|
|
.fontSize(14)
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
@@ -1804,8 +1866,7 @@ export struct UploadMusicPage {
|
|
|
}
|
|
|
.layoutWeight(1)
|
|
|
.height(48)
|
|
|
- .backgroundColor(this.themeColor)
|
|
|
- .fontColor('#FFFFFF')
|
|
|
+ .backgroundColor($r('app.color.index_background'))
|
|
|
.borderRadius(10)
|
|
|
.shadow({
|
|
|
radius: 8,
|
|
|
@@ -1819,8 +1880,10 @@ export struct UploadMusicPage {
|
|
|
|
|
|
Button({ type: ButtonType.Normal }) {
|
|
|
Row({ space: 6 }) {
|
|
|
- Text('🎵')
|
|
|
- .fontSize(16)
|
|
|
+ SymbolGlyph($r('sys.symbol.music'))
|
|
|
+ .fontSize(20)
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Text('从本地目录')
|
|
|
.fontSize(14)
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
@@ -1828,8 +1891,7 @@ export struct UploadMusicPage {
|
|
|
}
|
|
|
.layoutWeight(1)
|
|
|
.height(48)
|
|
|
- .backgroundColor(this.themeColor)
|
|
|
- .fontColor('#FFFFFF')
|
|
|
+ .backgroundColor($r('app.color.index_background'))
|
|
|
.borderRadius(10)
|
|
|
.shadow({
|
|
|
radius: 8,
|
|
|
@@ -1902,8 +1964,10 @@ export struct UploadMusicPage {
|
|
|
Column({ space: 16 }) {
|
|
|
// 标题行
|
|
|
Row({ space: 8 }) {
|
|
|
- Text('📋')
|
|
|
+ SymbolGlyph($r('sys.symbol.doc'))
|
|
|
.fontSize(20)
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Text('已选文件')
|
|
|
.fontSize(16)
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
@@ -1932,9 +1996,11 @@ export struct UploadMusicPage {
|
|
|
ListItem() {
|
|
|
Row({ space: 12 }) {
|
|
|
// 文件/文件夹图标
|
|
|
- Text(this.selectedFileTypes[index] === 'folder' ? '📁' : '🎵')
|
|
|
+ SymbolGlyph(this.selectedFileTypes[index] === 'folder' ?
|
|
|
+ $r('sys.symbol.folder'):$r('sys.symbol.music'))
|
|
|
.fontSize(20)
|
|
|
-
|
|
|
+ .fontColor([this.themeColor])
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
Column({ space: 2 }) {
|
|
|
Text(fileName)
|
|
|
.fontSize(14)
|