feat:日志&轨迹导出U盘功能
This commit is contained in:
parent
b765676068
commit
edb2ed2b45
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
entry/src/main/ets/common/utils/UsbUtils.ts
Normal file
41
entry/src/main/ets/common/utils/UsbUtils.ts
Normal file
@ -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<string> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -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 () => {
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user