From bf990ba7ddb6fb666c2a5447a6d0c770cd4bee39 Mon Sep 17 00:00:00 2001 From: chenxt <10125295+chen-xintao97@user.noreply.gitee.com> Date: Fri, 23 Jan 2026 14:01:40 +0800 Subject: [PATCH] 人脸采集 --- src/components/FaceDetect/index.js | 72 ++++++++++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/src/components/FaceDetect/index.js b/src/components/FaceDetect/index.js index 52c6add..58d4a50 100644 --- a/src/components/FaceDetect/index.js +++ b/src/components/FaceDetect/index.js @@ -75,12 +75,12 @@ class FaceDetect extends Component { } //登录认证 getMedia = () => { - this.setState({thumbImg: ''}); - this.checkParams=[]; + this.setState({ thumbImg: '' }); + this.checkParams = []; const _this = this; return new Promise((resolve, reject) => { _this.video = document.getElementById("video"); - let constraints = {video: true}; + let constraints = { video: true }; navigator.mediaDevices.getUserMedia(constraints) .then((stream) => { if ("srcObject" in this.video) { @@ -121,9 +121,9 @@ class FaceDetect extends Component { _this.stopMedia(); return; } - if (dataReturn.data.code < 0 ) { + if (dataReturn.data.code < 0) { _this.changePercentStatus('exception'); - _this.changeStatusContent('人脸验证失败,请重新识别:'+dataReturn.data.msg); + _this.changeStatusContent('人脸验证失败,请重新识别:' + dataReturn.data.msg); //message.error('人脸验证失败!请重新识别'+dataReturn.data.msg); _this.stopMedia(); reject(); @@ -133,7 +133,7 @@ class FaceDetect extends Component { _this.changeCurrentPercent(100); resolve(); } - _this.checkParams= []; + _this.checkParams = []; } }, 200); }) @@ -148,12 +148,12 @@ class FaceDetect extends Component { //人脸采集 getMediaAddFace = () => { - this.setState({thumbImg: ''}); - this.checkParams=[]; + this.setState({ thumbImg: '' }); + this.checkParams = []; const _this = this; return new Promise((resolve, reject) => { _this.video = document.getElementById("video"); - let constraints = {video: true}; + let constraints = { video: true }; navigator.mediaDevices.getUserMedia(constraints) .then((stream) => { if ("srcObject" in this.video) { @@ -195,9 +195,9 @@ class FaceDetect extends Component { _this.stopMedia(); return; } - if (dataReturn.data.code < 0 ) { + if (dataReturn.data.code < 0) { _this.changePercentStatus('exception'); - _this.changeStatusContent('人脸采集失败:'+dataReturn.data.msg); + _this.changeStatusContent('人脸采集失败:' + dataReturn.data.msg); // message.error('人脸采集失败!请重新采集'+dataReturn.data.msg); _this.stopMedia(); reject(); @@ -207,17 +207,29 @@ class FaceDetect extends Component { let userinfo = this.props.app.userinfo; const sBrandId = userinfo?.sBrandsId; const sSubsidiaryId = userinfo?.sSubsidiaryId; - if(this.props.bClickSource?.includes('BtnAddFace') ){ + if (this.props.bClickSource?.includes('BtnAddFace')) { userinfo = { sUserName: this.props.masterData?.sEmployeeName, sEmployeeNo: this.props.masterData?.sEmployeeNo, - sEmployeeId : this.props.masterData?.sEmployeeId, - sDepartName: this.props.masterData?.sDepartName, - sId :this.props.masterData?.sId + sEmployeeId: this.props.masterData?.sEmployeeId, + sDepartName: this.props.masterData?.sDepartName, + sId: this.props.masterData?.sId + } + } + if (this.props?.app?.currentPane?.route?.includes('/indexPage/commonClassify')) { + if (!this.props?.slaveSelectedRowKeys?.length) { + message.warning('请先选择人员!'); + return + } + const rowData = this.props?.slaveData?.find(x => x.sId === this.props.slaveSelectedRowKeys[0]) + userinfo = { + sUserName: rowData?.sEmployeeName, + sEmployeeNo:rowData?.sEmployeeNo, + sEmployeeId: rowData?.sEmployeeId, + sDepartName: rowData?.sDepartName, + sId: rowData?.sId } - console.log('userinfo', userinfo); } - let item = { "image": img.split(',')[1], "image_type": "BASE64", @@ -237,16 +249,16 @@ class FaceDetect extends Component { const url = this.urlpre + `/face/faceAdd`; _this.changeStatusContent('人脸数据处理中,请稍等'); const dataReturn = await commonServices.postValueService(null, item, url); - if (dataReturn.data.code > 0 ) { + if (dataReturn.data.code > 0) { _this.changeStatusContent('人脸数据处理成功'); _this.props.onSaveFaceSuccess && _this.props.onSaveFaceSuccess(dataReturn); - }else{ - _this.changeStatusContent('人脸数据处理失败,'+dataReturn.data.msg+'请重新采集'); + } else { + _this.changeStatusContent('人脸数据处理失败,' + dataReturn.data.msg + '请重新采集'); } _this.changeCurrentPercent(100); resolve(); } - _this.checkParams= []; + _this.checkParams = []; } }, 200); }) @@ -261,7 +273,7 @@ class FaceDetect extends Component { saveFace = () => { const _this = this; const userinfo = this.props.app.userinfo; - if(undefined === userinfo.sEmployeeId || userinfo.sEmployeeId === '' ){ + if (undefined === userinfo.sEmployeeId || userinfo.sEmployeeId === '') { _this.changeStatusContent('您没有采集权限,请联系管理员,将您绑定成员工。'); message.error('您没有采集权限,请联系管理员,将您绑定成员工。'); return; @@ -313,18 +325,18 @@ class FaceDetect extends Component { let limit = 5; let check = 0; async function handleDetectFace() { - for (let i = 0; i < limit; i ++) { - check ++; + for (let i = 0; i < limit; i++) { + check++; let img = _this.getFace(); let item = { "image": img.split(',')[1], "image_type": "BASE64", "face_field": "faceshape,facetype,feature" } - const url = this.urlpre +`/face/faceSearch`; + const url = this.urlpre + `/face/faceSearch`; const dataReturn = await commonServices.postValueService(null, item, url); if (dataReturn.data.code === 1) { - _this.setState({thumbImg: _this.getFace()}) + _this.setState({ thumbImg: _this.getFace() }) _this.changeStatusContent('人脸验证成功'); _this.stopMedia(); _this.props.onDetectSuccess && _this.props.onDetectSuccess(dataReturn.data); @@ -343,7 +355,7 @@ class FaceDetect extends Component { const stream = this.video.srcObject; if (stream) { const tracks = stream.getTracks(); - tracks.forEach(function(track) { + tracks.forEach(function (track) { track.stop(); }); this.video.srcObject = null; @@ -369,10 +381,10 @@ class FaceDetect extends Component { "quality_control": "NORMAL", "liveness_control": "NORMAL" } - const url = this.urlpre +`/face/faceSearch`; + const url = this.urlpre + `/face/faceSearch`; const dataReturn = await commonServices.postValueService(null, item, url); if (dataReturn && dataReturn.data && dataReturn.data.code === 1) { - _this.setState({thumbImg: _this.getFace()}) + _this.setState({ thumbImg: _this.getFace() }) _this.changeStatusContent('人脸验证成功'); _this.stopMedia(); _this.props.onIdentifySuccess && _this.props.onIdentifySuccess(dataReturn.data); @@ -424,7 +436,7 @@ class FaceDetect extends Component { } render() { - const enable = ((this.props.enabled && this.user_id !== '' )|| this.props.actionType === 'identifyFace'); + const enable = ((this.props.enabled && this.user_id !== '') || this.props.actionType === 'identifyFace'); const faceCollection = commonFunc.showLocalMessage(this.props, 'faceCollection', '人脸采集'); return ( <> -- libgit2 0.22.2