From 5400f38946e3ab089b0d61f7f32c2d621cd697db Mon Sep 17 00:00:00 2001 From: xuqm Date: Fri, 29 Aug 2025 19:03:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor(app):=20=E4=BC=98=E5=8C=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E8=BD=BD=E8=BF=9B=E5=BA=A6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 MainViewScreen.tsx 中的进度显示逻辑,简化为直接显示百分比 - 更新 UpdateHelper.ts 中的 downloadToFile 函数,增加进度字符串参数- 优化下载进度的计算和显示格式 --- src/app/screens/main/MainViewScreen.tsx | 9 ++------- src/common/UpdateHelper.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/app/screens/main/MainViewScreen.tsx b/src/app/screens/main/MainViewScreen.tsx index bc4aaa7..a71dc92 100644 --- a/src/app/screens/main/MainViewScreen.tsx +++ b/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(() => { diff --git a/src/common/UpdateHelper.ts b/src/common/UpdateHelper.ts index 8205a5b..468568a 100644 --- a/src/common/UpdateHelper.ts +++ b/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)}%`, );