From edb2ed2b45802a2a63a837c63e08b923e38b75f4 Mon Sep 17 00:00:00 2001 From: Surenjun Date: Fri, 10 Oct 2025 14:27:56 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=97=A5=E5=BF=97&=E8=BD=A8?= =?UTF-8?q?=E8=BF=B9=E5=AF=BC=E5=87=BAU=E7=9B=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/common/service/indexService.ts | 8 ++-- entry/src/main/ets/common/utils/UsbUtils.ts | 41 +++++++++++++++++++ entry/src/main/ets/pages/Index.ets | 23 ++++++++--- entry/src/main/module.json5 | 7 +++- 4 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 entry/src/main/ets/common/utils/UsbUtils.ts diff --git a/entry/src/main/ets/common/service/indexService.ts b/entry/src/main/ets/common/service/indexService.ts index f87bf8f9..f10a5294 100644 --- a/entry/src/main/ets/common/service/indexService.ts +++ b/entry/src/main/ets/common/service/indexService.ts @@ -105,7 +105,7 @@ export async function uploadLogFile() { // 将要上传的文件拷贝到缓存目录并压缩 -async function getCopyFiles() { +export async function getCopyFiles() { const absolutePath = '/mnt/hmdfs/100/account/device_view/local/files/duolun/logs' const tempPath = globalThis.context.cacheDir + '/temp'; @@ -140,10 +140,12 @@ async function getCopyFiles() { const filenames = await fs.listFile('/data/log/hilog'); for (let i = 0; i < filenames.length; i++) { if (filenames[i].split('.')[0] == 'hilog') { - const date = filenames[i].split('.')[2].split('-')[0] - if (date == nowDate) { + try { fs.copyFileSync('/data/log/hilog/' + filenames[i], globalThis.context.cacheDir + '/temp/' + filenames[i]) + } catch (e) { + console.error(TAG, e); } + } } diff --git a/entry/src/main/ets/common/utils/UsbUtils.ts b/entry/src/main/ets/common/utils/UsbUtils.ts new file mode 100644 index 00000000..a3f6364a --- /dev/null +++ b/entry/src/main/ets/common/utils/UsbUtils.ts @@ -0,0 +1,41 @@ +import common from '@ohos.app.ability.common' +import fs from '@ohos.file.fs'; +import zlib from '@ohos.zlib'; +import { getCurrentTime } from './tools' +import {getCopyFiles} from '../service/indexService' +const TAG = '[usbUtils]' + +export class UsbUtils { + private context: common.UIAbilityContext + + constructor(context: common.UIAbilityContext) { + this.context = context + } + + getUsbDiskPath(): Promise { + return new Promise((resolve, reject) => { + let path = "" + try { + path = fs.listFileSync("/mnt/data/external")[0] + } catch (error) { + console.log("err", JSON.stringify(error)) + reject(error) + return + } + resolve('/mnt/data/external' + '/' + path) + }) + } + + async copyFilesToUsb() { + const time = await getCurrentTime(0) + const date = time.split(' ')[0] + const output = await this.getUsbDiskPath(); + const filename = await getCopyFiles(); + const filePath = globalThis.context.cacheDir + '/' + filename + let stat = fs.statSync(filePath) + console.log(TAG,`压缩包文件${globalThis.carInfo?.carNo}-${date}大小:` + (Math.ceil(stat.size / 1024 / 1024)) + 'M') + fs.copyFileSync(filePath, `${output}/${globalThis.carInfo?.carNo}-${date}.zip`) + console.log(TAG,'转移压缩包完成:' ,output) + fs.rmdirSync(filePath); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 9a81e43b..1d4f6d35 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -20,10 +20,7 @@ import { delPic } from '../common/service/videoService'; import imageBtn from './compontents/imageBtn'; import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; import {updateModelAndCar} from '../common/autoUpdate/index' -// import {uploadLogFile} from '../common/service/indexService' -import { getModalValueCdAndCar } from '../api'; - -// import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; +import { UsbUtils } from '../common/utils/UsbUtils' @Entry @Component @@ -80,7 +77,23 @@ struct Index { Column() { Column() { Row() { - Image($r('app.media.logo')).width('30%').height('5.5%').margin({ left: 24 }) + Image($r('app.media.logo')).width('30%').height('5.5%').margin({ left: 24 }) .gesture( + GestureGroup(GestureMode.Exclusive, + TapGesture({ count: 2 }) + .onAction(async () => { + const usbUtils = new UsbUtils(this.context) + this.loading = true + this.loadingText = '正在导出日志和轨迹,请稍候……' + try { + await usbUtils.copyFilesToUsb() + } catch (e) { + + } + this.loading = false + this.loadingText = '' + }) + ) + ) Row() { Image($r('app.media.btn_setting')).width('16.7%').height('12.2%') .onClick(async () => { diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index 72245448..20642f50 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -1,10 +1,10 @@ - { "module": { "name": "entry", "type": "entry", "description": "$string:module_desc", + "srcEntry": "./ets/entryability/EntryAbility.ts", "mainElement": "EntryAbility", "deviceTypes": [ "default", @@ -13,7 +13,6 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", - "abilities": [ { "name": "EntryAbility", @@ -37,7 +36,11 @@ } ], "requestPermissions":[ + {"name": "ohos.permission.INSTALL_BUNDLE"}, + {"name": "ohos.permission.UNINSTALL_BUNDLE"}, + {"name": "ohos.permission.ACCESS_SERVICE_DM"}, {"name": "ohos.permission.CONNECTIVITY_INTERNAL"}, + {"name": "ohos.permission.SET_TIME"}, { "name": "ohos.permission.INTERNET"