diff --git a/entry/src/main/ets/pages/compontents/FaceCompare.ets b/entry/src/main/ets/pages/compontents/FaceCompare.ets index 807f5a5e..1d439504 100644 --- a/entry/src/main/ets/pages/compontents/FaceCompare.ets +++ b/entry/src/main/ets/pages/compontents/FaceCompare.ets @@ -190,12 +190,12 @@ export default struct FaceCompare { console.log('mmmmm0', 2) this.param.pztd = this.param.rlls const data = await takePhoto(this.param, this.context, 'jt/', 1,) - this.base64 = this.imageBase64 + (data.base64 || "") + this.base64 = this.imageBase64 + (data?.base64 || "") console.log('mmmmt', this.base64) faceCompare({ sfzh: this.sfzh, firstImage: this.firstImage.substr(22), - secondImage: data.base64 || "", + secondImage: data?.base64 || "", type: "2", verifyType: "1" }) diff --git a/entry/src/main/ets/pages/judgeSDK/utils/judgeTask.ets b/entry/src/main/ets/pages/judgeSDK/utils/judgeTask.ets index c8ad2925..ebfdccb0 100644 --- a/entry/src/main/ets/pages/judgeSDK/utils/judgeTask.ets +++ b/entry/src/main/ets/pages/judgeSDK/utils/judgeTask.ets @@ -1,8 +1,6 @@ -import Prompt from '@system.prompt' - const TAG = 'SURENJUN_JUDGE' -interface DelayConfig{ +interface DelayConfig { isDelay: boolean delayTime?: number } @@ -12,47 +10,46 @@ interface QUEUE { delayConfig?: DelayConfig } -type GoTask = (currentTask:QUEUE)=>Promise +type GoTask = (currentTask: QUEUE) => Promise export default class JudgeTask { - private queue?:QUEUE[] = [] - private status: string - - constructor() { - this.queue = [] - this.status = 'end' - } - //执行任务 - goTask:GoTask = async (currentTask:QUEUE) => { + goTask: GoTask = async (currentTask: QUEUE) => { const fn = currentTask.fn; - const delayConfig = currentTask.delayConfig || {isDelay:false,delayTime:1000} + const delayConfig = currentTask.delayConfig || { + isDelay: false, delayTime: 1000 + } const isDelay = delayConfig.isDelay const delayTime = delayConfig.delayTime return false } - + private queue?: QUEUE[] = [] + private status: string executeQueue = async () => { const queue = this.queue; const executeQueue = this.executeQueue - if (queue.length) { + if (queue?.length) { for (const currentTask of queue) { await this.goTask(currentTask) - this.queue.shift() + this.queue?.shift() await executeQueue() } } else { this.status = 'end' } } - - addTask = async (fn:Function, delayConfig?: DelayConfig) => { - this.queue.push({ + addTask = async (fn: Function, delayConfig?: DelayConfig) => { + this.queue?.push({ fn, delayConfig }); - if (this.status == 'end' && this.queue.length === 1) { + if (this.status == 'end' && this.queue?.length === 1) { await this.executeQueue(); } } + + constructor() { + this.queue = [] + this.status = 'end' + } } diff --git a/entry/src/main/ets/utils/FileHelp.ets b/entry/src/main/ets/utils/FileHelp.ets index 7189cc9c..9e0d2c15 100644 --- a/entry/src/main/ets/utils/FileHelp.ets +++ b/entry/src/main/ets/utils/FileHelp.ets @@ -54,9 +54,9 @@ export class FileHelper { } } - async getUserAlbumItemByDisplayName(displayName: string): Promise { - let fetchResult: photoAccessHelper.FetchResult = null - let album: photoAccessHelper.Album = null + async getUserAlbumItemByDisplayName(displayName: string): Promise { + let fetchResult: photoAccessHelper.FetchResult | null = null; + let album: photoAccessHelper.Album | null = null try { console.log(FileHelpTag, 'getUserAlbumItemByDisplayName'); let predicates = new dataSharePredicates.DataSharePredicates(); @@ -98,7 +98,7 @@ export class FileHelper { let asset = await assetsResult.getFirstObject(); console.log(FileHelpTag, ' addAssetToAlbum one asset uri : ' + asset.uri + ', photoType : ' + asset.photoType + ', displayName : ' + asset.displayName); - await album.addAssets([asset]); + await album?.addAssets([asset]); console.log(FileHelpTag, ' addAssetToAlbum success '); } } catch (err) { @@ -109,7 +109,7 @@ export class FileHelper { public async deleteFileOfAlbum(album_Name: string, file_type: number | string | boolean): Promise { console.log(FileHelpTag, ' deletePictureOfAlbum album_Name:' + album_Name); - let photoFetchResult: photoAccessHelper.FetchResult = null; + let photoFetchResult: photoAccessHelper.FetchResult | null = null; try { let album = await this.getUserAlbumItemByName(album_Name); let predicates = new dataSharePredicates.DataSharePredicates(); @@ -118,20 +118,23 @@ export class FileHelper { fetchColumns: this.FILE_ASSET_FETCH_COLUMNS, predicates: predicates }; - photoFetchResult = await album.getAssets(fetchOptions) - let all_fileAsset = await photoFetchResult.getAllObjects(); + photoFetchResult = (await album?.getAssets(fetchOptions)) || null + let all_fileAsset = (await photoFetchResult?.getAllObjects()) || null; let uri_array: string[] = [] console.log(FileHelpTag, ' deletePictureOfAlbum iterator begin', album_Name); - for (let onfile of all_fileAsset) { - console.log(FileHelpTag, album_Name, - ' deletePictureOfAlbum uri : ' + onfile.uri + ', photoType : ' + onfile.photoType + - ', displayName : ' + onfile.displayName); - uri_array.push(onfile.uri); + if (all_fileAsset) { + for (let onfile of all_fileAsset) { + console.log(FileHelpTag, album_Name, + ' deletePictureOfAlbum uri : ' + onfile.uri + ', photoType : ' + onfile.photoType + + ', displayName : ' + onfile.displayName); + uri_array.push(onfile.uri); + } } + await this.userFileMgr.deleteAssets(uri_array); - let albumFetchResult: photoAccessHelper.FetchResult = null; + let albumFetchResult: photoAccessHelper.FetchResult | null = null; try { albumFetchResult = await this.userFileMgr.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); @@ -162,7 +165,7 @@ export class FileHelper { public async deleteAllPictures(): Promise { console.log(FileHelpTag, ' deleteAllPictures'); - let photoFetchResult: photoAccessHelper.FetchResult = null; + let photoFetchResult: photoAccessHelper.FetchResult | null = null try { let predicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { @@ -216,9 +219,9 @@ export class FileHelper { // return album; // } - async getUserAlbumItemByName(albumName: string): Promise { - let fetchResult: photoAccessHelper.FetchResult = null - let album: photoAccessHelper.Album = null + async getUserAlbumItemByName(albumName: string): Promise { + let fetchResult: photoAccessHelper.FetchResult | null = null + let album: photoAccessHelper.Album | null = null try { console.log(FileHelpTag, 'getUserAlbumItemByName'); let predicates = new dataSharePredicates.DataSharePredicates(); @@ -246,7 +249,7 @@ export class FileHelper { } - public async createAlbum(albumName: string): Promise { + public async createAlbum(albumName: string): Promise { try { console.log(FileHelpTag, " createAlbum beging"); let albumAsset = await this.userFileMgr.createAlbum(albumName); @@ -257,7 +260,7 @@ export class FileHelper { return albumAsset.albumUri; } catch (err) { console.error(FileHelpTag, ' createAlbum failed with err: ' + err); - } finally { + return undefined; // Ensure a return value in case of an error } } @@ -277,10 +280,11 @@ export class FileHelper { } } - public async queryAlbum(type: photoAccessHelper.AlbumType, subType: photoAccessHelper.AlbumSubtype): Promise { + public async queryAlbum(type: photoAccessHelper.AlbumType, + subType: photoAccessHelper.AlbumSubtype): Promise { let firstUri = ""; - let fetchResult: photoAccessHelper.FetchResult = null; + let fetchResult: photoAccessHelper.FetchResult | null = null try { fetchResult = await this.userFileMgr.getAlbums(type, subType); console.log(FileHelpTag, ' queryAlbum success count: ' + fetchResult.getCount()); @@ -327,13 +331,13 @@ export class FileHelper { public async deleteAllVideos(type: photoAccessHelper.AlbumType, subType: photoAccessHelper.AlbumSubtype): Promise { - let fetchResult: photoAccessHelper.FetchResult = null; + let fetchResult: photoAccessHelper.FetchResult | null = null; + let photoFetchResult: photoAccessHelper.FetchResult | null = null; try { fetchResult = await this.userFileMgr.getAlbums(type, subType); console.log(FileHelpTag, ' 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 = null; let count = 0; console.log(FileHelpTag, ' get one Album name : ' + albumAsset.albumName); try { diff --git a/entry/src/main/ets/utils/Video.ets b/entry/src/main/ets/utils/Video.ets index 446ee300..50f7623c 100644 --- a/entry/src/main/ets/utils/Video.ets +++ b/entry/src/main/ets/utils/Video.ets @@ -78,7 +78,7 @@ export async function endRecordVideo(record_handleObj: RecordHandleType) { } -export async function saveStartRecordVideo(path: string, context?: common.UIAbilityContext): Promise { +export async function saveStartRecordVideo(path: string, context: common.UIAbilityContext): Promise { return new Promise(async (resolve, reject) => { const fileUtil = new FileUtils(context) const fileHelper = new FileHelper(context); @@ -130,7 +130,7 @@ interface takePhotoParam { * @returns */ -export async function delPic(day: number, type: number, context?: common.UIAbilityContext) { +export async function delPic(day: number, type: number, context: common.UIAbilityContext) { let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); console.log('albumGetAssetsDemoCallback'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); @@ -155,41 +155,61 @@ export async function delPic(day: number, type: number, context?: common.UIAbili } export async function takePhoto(param: VideoConfig, context: common.UIAbilityContext, dir: string, flag = 1, - callback?: (data: TakePhotoCallbackData) => void) { + callback?: (data: TakePhotoCallbackData) => void): Promise { 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` + const num = Math.floor(Math.random() * 10000); + const fileName = `picture_record${num}.jpg`; if (flag == 0) { - rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err: BusinessError, snapResult: record.RtspResult) => { - callback({ fileSize: snapResult.fileSize, errorCode: snapResult.errorCode }) + return new Promise((resolve, reject) => { + rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err: BusinessError, snapResult: record.RtspResult) => { + if (snapResult && snapResult.errorCode === 0) { + if (callback) { + callback({ + fileSize: snapResult.fileSize, + errorCode: snapResult.errorCode, + }); + } + resolve(); + } else { + promptAction.showToast({ + message: `拍照失败`, + duration: 3000, + }); + reject(err); + } + }); }); } else { return new Promise(async (resolve, reject) => { - const time = GetCurrentTime() - const date = time.split(' ')[0] - let dirName = dir ? dir : date - rtsp_server.getVideoSnapshot(context, video_uri, fileName, dirName, true, + const time = GetCurrentTime(); + const date = time.split(' ')[0]; + let dirName = dir ? dir : date; + rtsp_server.getVideoSnapshot( + context, + video_uri, + fileName, + dirName, + true, async (err: BusinessError, snapResult: record.RtspResult) => { - if (snapResult.result && snapResult.errorCode == 0) { + if (snapResult.result && snapResult.errorCode === 0) { resolve({ base64: snapResult.dataString, name: snapResult.fileName, fileSize: snapResult.fileSize, - errorCode: snapResult.errorCode - }) + errorCode: snapResult.errorCode, + }); } else { promptAction.showToast({ message: `拍照失败`, - duration: 3000 + duration: 3000, }); - reject(false) - // reject() + reject(false); } - - }); - }) + } + ); + }); } } @@ -202,14 +222,14 @@ export async function deleteAllFileByPiC(dirName: string, type = 1, context: com export async function deleteAllVideos(context: common.UIAbilityContext, type: photoAccessHelper.AlbumType, subType: photoAccessHelper.AlbumSubtype): Promise { - let fetchResult: photoAccessHelper.FetchResult = null; + let fetchResult: photoAccessHelper.FetchResult | null = null; let count = 0; try { const userFileMgr = photoAccessHelper.getPhotoAccessHelper(context); fetchResult = await userFileMgr.getAlbums(type, subType); for (let i = 0; i < fetchResult.getCount(); i++) { let albumAsset: photoAccessHelper.Album = await fetchResult.getObjectByPosition(i); - let photoFetchResult: photoAccessHelper.FetchResult = null; + let photoFetchResult: photoAccessHelper.FetchResult | null = null; try { let predicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = {