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 absolutePath = '/mnt/hmdfs/100/account/device_view/local/files/duolun/logs' | ||||||
|   const tempPath = globalThis.context.cacheDir + '/temp'; |   const tempPath = globalThis.context.cacheDir + '/temp'; | ||||||
| 
 | 
 | ||||||
| @ -140,10 +140,12 @@ async function getCopyFiles() { | |||||||
|   const filenames = await fs.listFile('/data/log/hilog'); |   const filenames = await fs.listFile('/data/log/hilog'); | ||||||
|   for (let i = 0; i < filenames.length; i++) { |   for (let i = 0; i < filenames.length; i++) { | ||||||
|     if (filenames[i].split('.')[0] == 'hilog') { |     if (filenames[i].split('.')[0] == 'hilog') { | ||||||
|       const date = filenames[i].split('.')[2].split('-')[0] |       try { | ||||||
|       if (date == nowDate) { |  | ||||||
|         fs.copyFileSync('/data/log/hilog/' + filenames[i], globalThis.context.cacheDir + '/temp/' + filenames[i]) |         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 imageBtn from './compontents/imageBtn'; | ||||||
| import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; | import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; | ||||||
| import {updateModelAndCar} from '../common/autoUpdate/index' | import {updateModelAndCar} from '../common/autoUpdate/index' | ||||||
| // import  {uploadLogFile} from '../common/service/indexService' | import { UsbUtils } from '../common/utils/UsbUtils' | ||||||
| import { getModalValueCdAndCar } from '../api'; |  | ||||||
| 
 |  | ||||||
| // import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; |  | ||||||
| 
 | 
 | ||||||
| @Entry | @Entry | ||||||
| @Component | @Component | ||||||
| @ -80,7 +77,23 @@ struct Index { | |||||||
|     Column() { |     Column() { | ||||||
|       Column() { |       Column() { | ||||||
|         Row() { |         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() { |           Row() { | ||||||
|             Image($r('app.media.btn_setting')).width('16.7%').height('12.2%') |             Image($r('app.media.btn_setting')).width('16.7%').height('12.2%') | ||||||
|               .onClick(async () => { |               .onClick(async () => { | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| { | { | ||||||
|   "module": { |   "module": { | ||||||
|     "name": "entry", |     "name": "entry", | ||||||
|     "type": "entry", |     "type": "entry", | ||||||
|     "description": "$string:module_desc", |     "description": "$string:module_desc", | ||||||
|  |     "srcEntry": "./ets/entryability/EntryAbility.ts", | ||||||
|     "mainElement": "EntryAbility", |     "mainElement": "EntryAbility", | ||||||
|     "deviceTypes": [ |     "deviceTypes": [ | ||||||
|       "default", |       "default", | ||||||
| @ -13,7 +13,6 @@ | |||||||
|     "deliveryWithInstall": true, |     "deliveryWithInstall": true, | ||||||
|     "installationFree": false, |     "installationFree": false, | ||||||
|     "pages": "$profile:main_pages", |     "pages": "$profile:main_pages", | ||||||
| 
 |  | ||||||
|     "abilities": [ |     "abilities": [ | ||||||
|       { |       { | ||||||
|         "name": "EntryAbility", |         "name": "EntryAbility", | ||||||
| @ -37,7 +36,11 @@ | |||||||
|       } |       } | ||||||
|     ], |     ], | ||||||
|     "requestPermissions":[ |     "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.CONNECTIVITY_INTERNAL"}, | ||||||
|  | 
 | ||||||
|       {"name": "ohos.permission.SET_TIME"}, |       {"name": "ohos.permission.SET_TIME"}, | ||||||
|       { |       { | ||||||
|         "name": "ohos.permission.INTERNET" |         "name": "ohos.permission.INTERNET" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user