subject-two/entry/src/main/ets/pages/compontents/faceCompareByhaikang.ets
lixiao 226f7afc53 夜考逻辑优化
界面现实问题优化
2025-05-20 13:58:44 +08:00

353 lines
9.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//@ts-ignore
import util from '@ohos.util';
import { voiceService } from '../../common/service/voiceService'
import { faceCompare } from '../../api/userInfo'
import FileUtil from '../../common/utils/File'
import { VideoConfig } from '../interfaces'
import common from '@ohos.app.ability.common';
import { string2Bytes } from '../../common/utils/tools'
import { takePhoto } from '../../common/service/videoService'
import { GlobalConfig } from '../../config/index'
@Component
export default struct FaceCompare {
constructor() {
super()
}
@State imageBase64: string = 'data:image/jpeg;base64,'
@Prop sfzh: string;
@Prop lsh: string;
@Prop firstImage: string;
@Link faceCompareSucess: number;
@Link showFaceCompare: boolean;
@Link getqkFlag: boolean;
@Link faceCatchImg: string;
@State imageThumbnail: string = '';
private times = 1; //人脸比对失败次数, 超过3次将不会自动比对需要点击重新打开重新触发
private vocObj = null;
@State callBackFlag: boolean = false;
@State @Watch('clearIntervalFn') showFaceCompareFlag: Boolean = false;
@State video_url: string = 'rtsp://admin:12345qwe@192.168.5.41:8000/h264/ch2/main/av_stream'
@State previewUri: Resource = $r('app.media.2_nor')
@State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X
@State showControls: boolean = false
private controller: VideoController = new VideoController()
@State isAutoPlay: boolean = true
@State signNum: number = 0;
private fileUtil: FileUtil
private interval: any
@State param: VideoConfig = {
spls: '',
videoNum: '1',
faceFlag: false,
pztd: '1',
ljlx: '',
ip: '192.168.7.112',
port: '554',
userName: 'admin',
pwd: '12345qwe',
td1: '1',
td2: '2',
td3: '3',
td4: '4',
videoRecord1: false,
videoRecord2: false,
videoRecord3: false,
videoRecord4: false,
rlls: '1',
spzd4:false,
spzd3:false,
spzd2:false,
spzd1:false,
zdyz:'500',
}
private context = getContext(this) as common.UIAbilityContext;
build() {
Column() {
Column() {
Text('照片比对')
.lineHeight('16%')
.height('16%')
.fontWeight(FontWeight.Bold)
.fontSize(24)
Row() {
Row() {
Video({
src: this.showFaceCompare ? `rtsp://${this.param.userName}:${this.param.pwd}@${this.param.ip}:${this.param.port}/h264/ch${this.param.rlls}/main/av_stream` : '',
previewUri: this.previewUri,
currentProgressRate: PlaybackSpeed.Speed_Forward_1_00_X,
controller: this.controller,
})
.muted(true)
.width('100%')
.height('100%')
.autoPlay(this.isAutoPlay)
.controls(this.showControls)
}
.width('48%')
.height('100%')
Row() {
Image(this.firstImage)
.width('100%')
.height('100%')
.backgroundColor(Color.Black)
}
.width('48%')
.height('100%')
}
.width('88.9%')
.height('53.2%')
.justifyContent(FlexAlign.SpaceBetween)
Text('正在等待拍照…')
.lineHeight('16%')
.height('16%')
.fontWeight(FontWeight.Bold)
.fontColor('#CC7E00')
Column() {
Row() {
Text('若验证无响应,点击此处')
.lineHeight('100%')
.height('100%')
.fontColor('#000000')
Column() {
Text('重新打开')
.lineHeight('100%')
.height('100%')
.fontColor(Color.White)
.fontSize(23)
}
.width('22.8%')
.height('89.9%')
.backgroundImage($r('app.media.nor'))
.backgroundImageSize({ width: '100%', height: '100%' })
.onClick(async () => {
this.times = 1;
})
}
.width('88.9%')
.height('100%')
.justifyContent(FlexAlign.SpaceBetween)
}
.width('100%')
.height('16%')
.position({ y: '84%' })
.borderRadius({ topLeft: 0, topRight: 0, bottomLeft: 15, bottomRight: 15 })
.backgroundColor('#CCC4B8')
}
.width('68.75%')
.height('73.2%')
.backgroundColor('#E5E3DF')
.borderRadius(15)
.margin({ top: '4%' })
Column() {
}
.width('8.5%')
.height('15.1%')
.backgroundImage($r('app.media.close'))
.backgroundImageSize({ width: '100%', height: '100%' })
.onClick(() => {
this.controller.stop()
this.vocObj && this.vocObj.releasePlayer()
this.showFaceCompare = !this.showFaceCompare
this.showFaceCompareFlag=!this.showFaceCompareFlag
this.faceCompareSucess = -1
globalThis.statue = 2
})
}
.width('100%')
.height('100%')
.backgroundColor('rgba(0, 0, 0, 0.8)')
.position({ x: 0, y: 0 })
}
onPageShow() {
}
async aboutToAppear() {
const fileUtil = new FileUtil(this.context)
this.fileUtil = fileUtil
this.getVideoConfig()
}
clearIntervalFn() {
this.callBackFlag = false
clearInterval(this.interval)
this.vocObj && this.vocObj.releasePlayer()
}
getqkFn() {
let tmpList = [];
tmpList.push(string2Bytes(globalThis.signNum, 1 * 8)[0])
const param = {
id: 41,
list: tmpList,
carNo: globalThis.carInfo.carNo,
placeId: globalThis.carInfo.examinationRoomId
}
globalThis.udpClient2.sendMsgExt(param, this.context)
}
async faceComparFn() {
console.log('mmmmm0',1)
takePhoto(this.param, this.context, 'jt/',0,({base64})=>{
faceCompare({
sfzh: this.sfzh,
firstImage: this.firstImage.substr(22),
secondImage: base64,
type: 2,
verifyType: 1
}).then(res => {
console.log('mmmmm8',res)
if (res) {
this.controller.stop()
this.showFaceCompare = !this.showFaceCompare
this.showFaceCompareFlag=!this.showFaceCompareFlag
this.faceCompareSucess = 1;
// this.faceCatchImg = result
this.vocObj.playAudio({
type: 1,
name: 'yzcg.wav'
})
} else {
this.times++;
//3s后开始语音提示
this.vocObj.playAudio({
type: 1,
name: 'face_fail.mp3'
})
}
})
})
console.log('mmmmm8',9)
}
async heartMsg(context) {
let tmpList = []
const str = this.lsh
for (let i = 0;i < str.length; i++) {
tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0])
}
const param = {
id: 46,
list: tmpList,
carNo: globalThis.carInfo.carNo,
placeId: globalThis.carInfo.examinationRoomId,
sendCallback: () => {
this.callBackFlag = true
}
}
globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param, this.context)
clearInterval(this.interval)
this.interval = setInterval(() => {
if (this.callBackFlag) {
const param2 = {
id: 47,
list: tmpList,
carNo: globalThis.carInfo.carNo,
placeId: globalThis.carInfo.examinationRoomId,
}
globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param2, this.context)
}
}, 1000)
globalThis.udpClient2.setMsgCallBack((val) => {
if (val.id == '48') {
if (val.body[13] == '1') {
this.showFaceCompareFlag=!this.showFaceCompareFlag
this.showFaceCompare = !this.showFaceCompare
this.vocObj && this.vocObj.releasePlayer()
this.faceCompareSucess = 1
clearInterval(this.interval)
} else if (val.body[13] == '0' && this.callBackFlag) {
globalThis.statue = 2
this.vocObj && this.vocObj.playAudio({
type: 1,
name: 'face_chekc_fail.wav'
})
}
}
})
}
async getVideoConfig() {
console.log('faceEnterIn')
this.vocObj = new voiceService(async (status, val, next) => {
if (status == 'idle') {
if (val == 'face_check.mp3' || val == 'face_fail.mp3') {
if (this.times >= 3) {
globalThis.statue = 3
this.faceCompareSucess = -1;
this.vocObj && this.vocObj.playAudio({
type: 1,
name: 'face_checking.wav'
})
this.heartMsg(this.context)
} else {
setTimeout(() => {
this.faceComparFn()
}, 2000)
}
} else if (val == 'yzcg.wav') {
this.showFaceCompare = !this.showFaceCompare
this.showFaceCompareFlag=!this.showFaceCompareFlag
globalThis.statue = 4
this.faceCompareSucess = 1;
this.vocObj && this.vocObj.releasePlayer()
} else if (val == 'face_chekc_fail.wav') {
this.vocObj && this.vocObj.releasePlayer()
this.faceCompareSucess = -1
this.showFaceCompare = !this.showFaceCompare
this.showFaceCompareFlag=!this.showFaceCompareFlag
}
}
});
const data = await this.fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt');
console.log('faceEnterIn,data',data)
setTimeout(() => {
this.vocObj && this.vocObj.playAudio({
type: 1,
name: 'face_check.mp3'
})
}, 1000)
this.param = JSON.parse(data)
this.param.userName = JSON.parse(data).userName
this.param.ip = this.param.ip
this.param.pwd = this.param.pwd
this.param.port = this.param.port
this.param.rlls = this.param.rlls
this.controller.start()
}
async aboutToDisappear() {
}
}