瀏覽代碼

refactor(app): 优化文件下载进度显示

- 修改 MainViewScreen.tsx 中的进度显示逻辑,简化为直接显示百分比
- 更新 UpdateHelper.ts 中的 downloadToFile 函数,增加进度字符串参数- 优化下载进度的计算和显示格式
xuqm 1 周之前
父節點
當前提交
5400f38946
共有 2 個文件被更改,包括 13 次插入9 次删除
  1. 2 7
      src/app/screens/main/MainViewScreen.tsx
  2. 11 2
      src/common/UpdateHelper.ts

+ 2 - 7
src/app/screens/main/MainViewScreen.tsx

@@ -116,13 +116,8 @@ export default function WebViewScreen(props: Props) {
                     downloadToFile(
                       'https://download-api.51trust.com/ywx-android-sdk/common1.android.zip',
                       'common1.android.zip',
-                      (bytesWritten, contentLength) => {
-                        setProgress(
-                          `进度: ${(
-                            (bytesWritten / contentLength) *
-                            100
-                          ).toFixed(2)}%`,
-                        );
+                      (_bytesWritten, _contentLength, pro) => {
+                        setProgress(`进度: ${pro}%`);
                       },
                     )
                       .then(() => {

+ 11 - 2
src/common/UpdateHelper.ts

@@ -4,7 +4,11 @@ import { unzip } from 'react-native-zip-archive';
 export const downloadToFile = async (
   fileUrl: string,
   fileName: string,
-  listener?: (bytesWritten: number, contentLength: number) => void,
+  listener?: (
+    bytesWritten: number,
+    contentLength: number,
+    progress: string,
+  ) => void,
 ) => {
   // /storage/emulated/0/Android/data/com.trust.ywx/files/bundles/android/common.android.bundle
   const downloadDest = `${RNFS.ExternalDirectoryPath}/bundles/${fileName}`;
@@ -18,7 +22,12 @@ export const downloadToFile = async (
     fromUrl: fileUrl,
     toFile: downloadDest,
     progress: (res: any) => {
-      listener && listener(res.bytesWritten, res.contentLength);
+      listener &&
+        listener(
+          res.bytesWritten,
+          res.contentLength,
+          `进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`,
+        );
       console.log(
         `进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`,
       );