refactor: 重命名文件扩展名为.ets,优化类型定义和导入逻辑
This commit is contained in:
		
							parent
							
								
									1c5d5c78c3
								
							
						
					
					
						commit
						da34d5dbb5
					
				| @ -1,10 +0,0 @@ | ||||
| /* | ||||
|  * @Author: wangzhongjie | ||||
|  * @Date: 2024-03-07 10:54:19 | ||||
|  * @LastEditors: wangzhongjie | ||||
|  * @LastEditTime: 2024-03-07 11:15:11 | ||||
|  * @Description:  | ||||
|  * @Email: shutdown0630@163.com | ||||
|  */ | ||||
| export * from "./global" | ||||
| export * from "./judge" | ||||
| @ -7,6 +7,4 @@ | ||||
|  * @Email: shutdown0630@163.com | ||||
|  */ | ||||
| 
 | ||||
| export const JudgeConfig={ | ||||
|    | ||||
| } | ||||
| 
 | ||||
							
								
								
									
										4
									
								
								entry/src/main/ets/model/Other.ets
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								entry/src/main/ets/model/Other.ets
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| export interface TakePhotoCallbackData { | ||||
|   fileSize: number; | ||||
|   errorCode: number | ||||
| } | ||||
| @ -17,3 +17,5 @@ export * from "./CarCheck" | ||||
| export * from "./api" | ||||
| 
 | ||||
| export * from "./TableColumn" | ||||
| 
 | ||||
| export * from "./Other" | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| import router from '@ohos.router' | ||||
| import { CarCheckDataType } from '../model/CarCheck' | ||||
| import { BaseInfoType } from '../model/Common' | ||||
| import { BaseInfoType, CarInfoType } from '../model/Common' | ||||
| import TopLogo from './compontents/TopLogo' | ||||
| 
 | ||||
| @Entry | ||||
| @ -9,7 +9,7 @@ struct Index { | ||||
|   @State ratio: number = 1280 / 960 | ||||
|   @State url: string = '' | ||||
|   @State baseInfo: BaseInfoType = {} | ||||
|   @State carInfo: CarCheckDataType = {} | ||||
|   @State carInfo: CarInfoType = {} | ||||
|   @State @Watch('outClick') outFlag: boolean = false; | ||||
| 
 | ||||
|   build() { | ||||
| @ -88,8 +88,8 @@ struct Index { | ||||
|   aboutToAppear() { | ||||
|     // this.vocObj = new voiceService(async (status, val, next) => { | ||||
|     // }); | ||||
|     this.carInfo = AppStorage.get('carInfo') | ||||
|     this.baseInfo = AppStorage.get('baseinfo') as BaseInfoType | ||||
|     this.carInfo = AppStorage.get<CarInfoType>('carInfo') | ||||
|     this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo') | ||||
|   } | ||||
| 
 | ||||
|   outClick() { | ||||
|  | ||||
| @ -1404,15 +1404,3 @@ struct LabelBlock { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| interface systemParam { | ||||
|   'Param341': boolean, //是否按顺序考试 | ||||
|   'Param803Str': string, //开始考试前必须解开安全带或关车门 | ||||
|   'Param612Str': string, //开始考试触发方式 | ||||
|   'Param305Str': string, //视频保存天数 | ||||
|   'Param352Str': string, //车上考试过一次就不能缺考 | ||||
|   'Param828Str': string, //828考生待考界面,安全员显示考试员 | ||||
|   'Param770Str': string, //车上没有缺考功能 | ||||
|   'Param830Str': string, //同一学员连续第二次考试时不再验证身份 | ||||
|   'Param364': string, //考前上车准备 | ||||
|   'Param398': string, //考前上车准备 | ||||
| } | ||||
| @ -53,6 +53,7 @@ import { | ||||
| } from './api/index'; | ||||
| import { writeObjectOut } from '../../api/judge'; | ||||
| import { saveStartRecordVideo } from '../../utils/Video'; | ||||
| import common from '@ohos.app.ability.common'; | ||||
| 
 | ||||
| const judgeTag = 'SURENJUN_JUDGE' | ||||
| 
 | ||||
|  | ||||
| @ -1,16 +1,15 @@ | ||||
| import mediaLibrary from '@ohos.multimedia.mediaLibrary' | ||||
| import photoAccessHelper from '@ohos.file.photoAccessHelper' | ||||
| import dataSharePredicates from '@ohos.data.dataSharePredicates' | ||||
| import { dateFormat, getCurrentTime, isSevenDaysAgo } from '../utils/tools' | ||||
| // import rtsp_server from '@ohos.rtsprecord'; | ||||
| import record from '@ohos.rtsprecord'; | ||||
| import { FileHelper } from './FileHelper'; | ||||
| import FileUtil from '../utils/File'; | ||||
| import { GlobalConfig } from '../../config'; | ||||
| import promptAction from '@ohos.promptAction'; | ||||
| import { GetCurrentTime, IsDaysAgo } from './Common'; | ||||
| import { RecordHandleType, VideoConfig } from '../model'; | ||||
| import { RecordHandleType, TakePhotoCallbackData, VideoConfig } from '../model'; | ||||
| import common from '@ohos.app.ability.common'; | ||||
| import { FileHelper } from '../common/service/FileHelper'; | ||||
| import FileUtil from '../common/utils/File'; | ||||
| import dayTs from './Date'; | ||||
| import { GlobalConfig } from '../config'; | ||||
| import { BusinessError } from '@ohos.base'; | ||||
| 
 | ||||
| const rtsp_server = record.createServer(); | ||||
| //开始录屏 | ||||
| @ -84,29 +83,37 @@ export async function endRecordVideo(record_handleObj: RecordHandleType) { | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| export async function saveStartRecordVideo(path) { | ||||
|   return new Promise(async (reslove, reject) => { | ||||
|     const fileUtil = new FileUtil(globalThis.context) | ||||
| export async function saveStartRecordVideo(path: string, context?: common.UIAbilityContext): Promise<RecordHandleType> { | ||||
|   context = context || globalThis.context | ||||
|   return new Promise(async (resolve, reject) => { | ||||
|     const fileUtil = new FileUtil(context) | ||||
|     const fileHelper = new FileHelper(); | ||||
|     const date = dateFormat(new Date).split(' ')[0] | ||||
|     // const date = dateFormat(new Date).split(' ')[0] | ||||
|     const date = dayTs().format('YYYY-MM-DD HH:mm:ss').split(' ')[0] | ||||
|     fileHelper.createAlbum(date); | ||||
|     // const folderPath = await fileUtil.initFolder(`/${path}/${date}`); | ||||
|     const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt'); | ||||
|     const param = JSON.parse(data) | ||||
|     const record_handle = { | ||||
|       1: 0, | ||||
|       2: 1, | ||||
|       3: 2, | ||||
|       4: 3 | ||||
|     // TODO:待修改 | ||||
|     const data: string = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt'); | ||||
|     const param: VideoConfig = JSON.parse(data) | ||||
|     const record_handle: RecordHandleType = { | ||||
|       rocord_handle1: 0, | ||||
|       rocord_handle2: 1, | ||||
|       rocord_handle3: 2, | ||||
|       rocord_handle4: 3 | ||||
|     } | ||||
|     for (let i = 1; i <= 4; i++) { | ||||
|       if (param['videoRecord'+i]) { | ||||
|         console.log('pathpath0', path) | ||||
|       // if (param['videoRecord'+i]) { | ||||
|       // | ||||
|       //   record_handle[i] = await getFilehandleCode(i, param, date, path, i) | ||||
|       // } | ||||
|       if (Reflect.get(param, 'videoRecord' + i)) { | ||||
|         // Reflect.set(record_handle, i, await getFileHandleCode(i, param, date, path, i)); | ||||
|         const data = await startRecordVideo(param, i, context, date, path, i); | ||||
|         Reflect.set(record_handle, i, data); | ||||
| 
 | ||||
|         record_handle[i] = await getfilehandleCode(i, param, date, path, i) | ||||
|       } | ||||
|     } | ||||
|     reslove(record_handle) | ||||
|     resolve(record_handle) | ||||
|   }) | ||||
| } | ||||
| 
 | ||||
| @ -135,7 +142,7 @@ interface takePhotoParam { | ||||
|  */ | ||||
| const fileHelper = new FileHelper(); | ||||
| 
 | ||||
| export async function delPic(day, type) { | ||||
| export async function delPic(day: number, type: number) { | ||||
|   let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(globalThis.context); | ||||
|   console.info('albumGetAssetsDemoCallback'); | ||||
|   let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); | ||||
| @ -162,82 +169,79 @@ export async function delPic(day, type) { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export async function takePhoto(param, context, dir, flag = 1, callback?) { | ||||
| export async function takePhoto(param: VideoConfig, context: common.UIAbilityContext, dir: string, flag = 1, | ||||
|   callback?: (data: TakePhotoCallbackData) => void) { | ||||
|   let video_uri = `rtsp://${param.userName}:${param.pwd}@${param.ip}:${param.port}/h264/ch${param.pztd}/main/av_stream`; | ||||
| 
 | ||||
|   const num = Math.floor(Math.random() * 10000) | ||||
|   const fileName = `picture_record${num}.jpg` | ||||
| 
 | ||||
|   if (flag == 0) { | ||||
|     rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err, snapResult) => { | ||||
|     rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err: BusinessError, snapResult: record.RtspResult) => { | ||||
|       callback({ fileSize: snapResult.fileSize, errorCode: snapResult.errorCode }) | ||||
|     }); | ||||
|   } else { | ||||
|     return new Promise<takePhotoParam>(async (resolve, reject) => { | ||||
|       const time = await getCurrentTime() | ||||
|       const time = await GetCurrentTime() | ||||
|       const date = time.split(' ')[0] | ||||
|       let dirName = dir ? dir : date | ||||
|       rtsp_server.getVideoSnapshot(context, video_uri, fileName, dirName, true, async (err, snapResult) => { | ||||
|         if (snapResult.result && snapResult.errorCode == 0) { | ||||
|           resolve({ | ||||
|             base64: snapResult.dataString, | ||||
|             name: snapResult.fileName, | ||||
|             fileSize: snapResult.fileSize, | ||||
|             errorCode: snapResult.errorCode | ||||
|           }) | ||||
|         } else { | ||||
|           promptAction.showToast({ | ||||
|             message: `拍照失败`, | ||||
|             duration: 3000 | ||||
|           }); | ||||
|           reject(false) | ||||
|           // reject() | ||||
|         } | ||||
|       rtsp_server.getVideoSnapshot(context, video_uri, fileName, dirName, true, | ||||
|         async (err: BusinessError, snapResult: record.RtspResult) => { | ||||
|           if (snapResult.result && snapResult.errorCode == 0) { | ||||
|             resolve({ | ||||
|               base64: snapResult.dataString, | ||||
|               name: snapResult.fileName, | ||||
|               fileSize: snapResult.fileSize, | ||||
|               errorCode: snapResult.errorCode | ||||
|             }) | ||||
|           } else { | ||||
|             promptAction.showToast({ | ||||
|               message: `拍照失败`, | ||||
|               duration: 3000 | ||||
|             }); | ||||
|             reject(false) | ||||
|             // reject() | ||||
|           } | ||||
| 
 | ||||
|       }); | ||||
|         }); | ||||
|     }) | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| //type:1 是图片 2是视频 | ||||
| export async function deleteAllFileByPiC(dirName, type = 1) { | ||||
| export async function deleteAllFileByPiC(dirName: string, type = 1) { | ||||
|   // const fileHelper = new FileHelper(); | ||||
|   fileHelper.deleteFileOfAlbum(dirName, type); | ||||
| } | ||||
| 
 | ||||
| export async function deleteAllVideos(context, type: photoAccessHelper.AlbumType, | ||||
| export async function deleteAllVideos(context: common.UIAbilityContext, type: photoAccessHelper.AlbumType, | ||||
|   subType: photoAccessHelper.AlbumSubtype): Promise<void> { | ||||
|   let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = null; | ||||
|   try { | ||||
|     const userFileMgr = photoAccessHelper.getPhotoAccessHelper(context); | ||||
|     fetchResult = await userFileMgr.getAlbums(type, subType); | ||||
|     console.log('baoyihu get Album fetchResult, count: ' + fetchResult.getCount()); | ||||
|     for (let i = 0; i < fetchResult.getCount(); i++) { | ||||
|       let albumAsset: photoAccessHelper.Album = await fetchResult.getObjectByPosition(i); | ||||
|       let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = null; | ||||
|       let count = 0; | ||||
|       try { | ||||
|         let predicates = new dataSharePredicates.DataSharePredicates(); | ||||
|         let fetchOptions = { | ||||
|         let fetchOptions: photoAccessHelper.FetchOptions = { | ||||
|           fetchColumns: FILE_ASSET_FETCH_COLUMNS, | ||||
|           predicates: predicates | ||||
|         }; | ||||
|         photoFetchResult = await albumAsset.getAssets(fetchOptions); | ||||
|         count = photoFetchResult.getCount(); | ||||
|         console.log('baoyihu photoFetchResult count: ' + count); | ||||
|         var all_fileAsset = await photoFetchResult.getAllObjects(); | ||||
|         var uri_array = [] | ||||
|         console.log('baoyihu batch delete begin'); | ||||
|         let all_fileAsset = await photoFetchResult.getAllObjects(); | ||||
|         let uri_array: string[] = [] | ||||
|         for (let onfile of all_fileAsset) { | ||||
|           console.log('baoyihu push one uri : ' + onfile.uri); | ||||
|           uri_array.push(onfile.uri); | ||||
|         } | ||||
|         await userFileMgr.deleteAssets(uri_array); | ||||
| 
 | ||||
|         console.log('baoyihu batch delete end'); | ||||
|       } catch (err) { | ||||
|         console.log('baoyihu get Album getPhotoAssets failed with err: ' + err); | ||||
|       } finally { | ||||
|         if (photoFetchResult != null) { | ||||
|           photoFetchResult.close(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user