Commit bf990ba7ddb6fb666c2a5447a6d0c770cd4bee39
1 parent
76ee774c
人脸采集
Showing
1 changed file
with
42 additions
and
30 deletions
src/components/FaceDetect/index.js
| @@ -75,12 +75,12 @@ class FaceDetect extends Component { | @@ -75,12 +75,12 @@ class FaceDetect extends Component { | ||
| 75 | } | 75 | } |
| 76 | //登录认证 | 76 | //登录认证 |
| 77 | getMedia = () => { | 77 | getMedia = () => { |
| 78 | - this.setState({thumbImg: ''}); | ||
| 79 | - this.checkParams=[]; | 78 | + this.setState({ thumbImg: '' }); |
| 79 | + this.checkParams = []; | ||
| 80 | const _this = this; | 80 | const _this = this; |
| 81 | return new Promise((resolve, reject) => { | 81 | return new Promise((resolve, reject) => { |
| 82 | _this.video = document.getElementById("video"); | 82 | _this.video = document.getElementById("video"); |
| 83 | - let constraints = {video: true}; | 83 | + let constraints = { video: true }; |
| 84 | navigator.mediaDevices.getUserMedia(constraints) | 84 | navigator.mediaDevices.getUserMedia(constraints) |
| 85 | .then((stream) => { | 85 | .then((stream) => { |
| 86 | if ("srcObject" in this.video) { | 86 | if ("srcObject" in this.video) { |
| @@ -121,9 +121,9 @@ class FaceDetect extends Component { | @@ -121,9 +121,9 @@ class FaceDetect extends Component { | ||
| 121 | _this.stopMedia(); | 121 | _this.stopMedia(); |
| 122 | return; | 122 | return; |
| 123 | } | 123 | } |
| 124 | - if (dataReturn.data.code < 0 ) { | 124 | + if (dataReturn.data.code < 0) { |
| 125 | _this.changePercentStatus('exception'); | 125 | _this.changePercentStatus('exception'); |
| 126 | - _this.changeStatusContent('人脸验证失败,请重新识别:'+dataReturn.data.msg); | 126 | + _this.changeStatusContent('人脸验证失败,请重新识别:' + dataReturn.data.msg); |
| 127 | //message.error('人脸验证失败!请重新识别'+dataReturn.data.msg); | 127 | //message.error('人脸验证失败!请重新识别'+dataReturn.data.msg); |
| 128 | _this.stopMedia(); | 128 | _this.stopMedia(); |
| 129 | reject(); | 129 | reject(); |
| @@ -133,7 +133,7 @@ class FaceDetect extends Component { | @@ -133,7 +133,7 @@ class FaceDetect extends Component { | ||
| 133 | _this.changeCurrentPercent(100); | 133 | _this.changeCurrentPercent(100); |
| 134 | resolve(); | 134 | resolve(); |
| 135 | } | 135 | } |
| 136 | - _this.checkParams= []; | 136 | + _this.checkParams = []; |
| 137 | } | 137 | } |
| 138 | }, 200); | 138 | }, 200); |
| 139 | }) | 139 | }) |
| @@ -148,12 +148,12 @@ class FaceDetect extends Component { | @@ -148,12 +148,12 @@ class FaceDetect extends Component { | ||
| 148 | 148 | ||
| 149 | //人脸采集 | 149 | //人脸采集 |
| 150 | getMediaAddFace = () => { | 150 | getMediaAddFace = () => { |
| 151 | - this.setState({thumbImg: ''}); | ||
| 152 | - this.checkParams=[]; | 151 | + this.setState({ thumbImg: '' }); |
| 152 | + this.checkParams = []; | ||
| 153 | const _this = this; | 153 | const _this = this; |
| 154 | return new Promise((resolve, reject) => { | 154 | return new Promise((resolve, reject) => { |
| 155 | _this.video = document.getElementById("video"); | 155 | _this.video = document.getElementById("video"); |
| 156 | - let constraints = {video: true}; | 156 | + let constraints = { video: true }; |
| 157 | navigator.mediaDevices.getUserMedia(constraints) | 157 | navigator.mediaDevices.getUserMedia(constraints) |
| 158 | .then((stream) => { | 158 | .then((stream) => { |
| 159 | if ("srcObject" in this.video) { | 159 | if ("srcObject" in this.video) { |
| @@ -195,9 +195,9 @@ class FaceDetect extends Component { | @@ -195,9 +195,9 @@ class FaceDetect extends Component { | ||
| 195 | _this.stopMedia(); | 195 | _this.stopMedia(); |
| 196 | return; | 196 | return; |
| 197 | } | 197 | } |
| 198 | - if (dataReturn.data.code < 0 ) { | 198 | + if (dataReturn.data.code < 0) { |
| 199 | _this.changePercentStatus('exception'); | 199 | _this.changePercentStatus('exception'); |
| 200 | - _this.changeStatusContent('人脸采集失败:'+dataReturn.data.msg); | 200 | + _this.changeStatusContent('人脸采集失败:' + dataReturn.data.msg); |
| 201 | // message.error('人脸采集失败!请重新采集'+dataReturn.data.msg); | 201 | // message.error('人脸采集失败!请重新采集'+dataReturn.data.msg); |
| 202 | _this.stopMedia(); | 202 | _this.stopMedia(); |
| 203 | reject(); | 203 | reject(); |
| @@ -207,17 +207,29 @@ class FaceDetect extends Component { | @@ -207,17 +207,29 @@ class FaceDetect extends Component { | ||
| 207 | let userinfo = this.props.app.userinfo; | 207 | let userinfo = this.props.app.userinfo; |
| 208 | const sBrandId = userinfo?.sBrandsId; | 208 | const sBrandId = userinfo?.sBrandsId; |
| 209 | const sSubsidiaryId = userinfo?.sSubsidiaryId; | 209 | const sSubsidiaryId = userinfo?.sSubsidiaryId; |
| 210 | - if(this.props.bClickSource?.includes('BtnAddFace') ){ | 210 | + if (this.props.bClickSource?.includes('BtnAddFace')) { |
| 211 | userinfo = { | 211 | userinfo = { |
| 212 | sUserName: this.props.masterData?.sEmployeeName, | 212 | sUserName: this.props.masterData?.sEmployeeName, |
| 213 | sEmployeeNo: this.props.masterData?.sEmployeeNo, | 213 | sEmployeeNo: this.props.masterData?.sEmployeeNo, |
| 214 | - sEmployeeId : this.props.masterData?.sEmployeeId, | ||
| 215 | - sDepartName: this.props.masterData?.sDepartName, | ||
| 216 | - sId :this.props.masterData?.sId | 214 | + sEmployeeId: this.props.masterData?.sEmployeeId, |
| 215 | + sDepartName: this.props.masterData?.sDepartName, | ||
| 216 | + sId: this.props.masterData?.sId | ||
| 217 | + } | ||
| 218 | + } | ||
| 219 | + if (this.props?.app?.currentPane?.route?.includes('/indexPage/commonClassify')) { | ||
| 220 | + if (!this.props?.slaveSelectedRowKeys?.length) { | ||
| 221 | + message.warning('请先选择人员!'); | ||
| 222 | + return | ||
| 223 | + } | ||
| 224 | + const rowData = this.props?.slaveData?.find(x => x.sId === this.props.slaveSelectedRowKeys[0]) | ||
| 225 | + userinfo = { | ||
| 226 | + sUserName: rowData?.sEmployeeName, | ||
| 227 | + sEmployeeNo:rowData?.sEmployeeNo, | ||
| 228 | + sEmployeeId: rowData?.sEmployeeId, | ||
| 229 | + sDepartName: rowData?.sDepartName, | ||
| 230 | + sId: rowData?.sId | ||
| 217 | } | 231 | } |
| 218 | - console.log('userinfo', userinfo); | ||
| 219 | } | 232 | } |
| 220 | - | ||
| 221 | let item = { | 233 | let item = { |
| 222 | "image": img.split(',')[1], | 234 | "image": img.split(',')[1], |
| 223 | "image_type": "BASE64", | 235 | "image_type": "BASE64", |
| @@ -237,16 +249,16 @@ class FaceDetect extends Component { | @@ -237,16 +249,16 @@ class FaceDetect extends Component { | ||
| 237 | const url = this.urlpre + `/face/faceAdd`; | 249 | const url = this.urlpre + `/face/faceAdd`; |
| 238 | _this.changeStatusContent('人脸数据处理中,请稍等'); | 250 | _this.changeStatusContent('人脸数据处理中,请稍等'); |
| 239 | const dataReturn = await commonServices.postValueService(null, item, url); | 251 | const dataReturn = await commonServices.postValueService(null, item, url); |
| 240 | - if (dataReturn.data.code > 0 ) { | 252 | + if (dataReturn.data.code > 0) { |
| 241 | _this.changeStatusContent('人脸数据处理成功'); | 253 | _this.changeStatusContent('人脸数据处理成功'); |
| 242 | _this.props.onSaveFaceSuccess && _this.props.onSaveFaceSuccess(dataReturn); | 254 | _this.props.onSaveFaceSuccess && _this.props.onSaveFaceSuccess(dataReturn); |
| 243 | - }else{ | ||
| 244 | - _this.changeStatusContent('人脸数据处理失败,'+dataReturn.data.msg+'请重新采集'); | 255 | + } else { |
| 256 | + _this.changeStatusContent('人脸数据处理失败,' + dataReturn.data.msg + '请重新采集'); | ||
| 245 | } | 257 | } |
| 246 | _this.changeCurrentPercent(100); | 258 | _this.changeCurrentPercent(100); |
| 247 | resolve(); | 259 | resolve(); |
| 248 | } | 260 | } |
| 249 | - _this.checkParams= []; | 261 | + _this.checkParams = []; |
| 250 | } | 262 | } |
| 251 | }, 200); | 263 | }, 200); |
| 252 | }) | 264 | }) |
| @@ -261,7 +273,7 @@ class FaceDetect extends Component { | @@ -261,7 +273,7 @@ class FaceDetect extends Component { | ||
| 261 | saveFace = () => { | 273 | saveFace = () => { |
| 262 | const _this = this; | 274 | const _this = this; |
| 263 | const userinfo = this.props.app.userinfo; | 275 | const userinfo = this.props.app.userinfo; |
| 264 | - if(undefined === userinfo.sEmployeeId || userinfo.sEmployeeId === '' ){ | 276 | + if (undefined === userinfo.sEmployeeId || userinfo.sEmployeeId === '') { |
| 265 | _this.changeStatusContent('您没有采集权限,请联系管理员,将您绑定成员工。'); | 277 | _this.changeStatusContent('您没有采集权限,请联系管理员,将您绑定成员工。'); |
| 266 | message.error('您没有采集权限,请联系管理员,将您绑定成员工。'); | 278 | message.error('您没有采集权限,请联系管理员,将您绑定成员工。'); |
| 267 | return; | 279 | return; |
| @@ -313,18 +325,18 @@ class FaceDetect extends Component { | @@ -313,18 +325,18 @@ class FaceDetect extends Component { | ||
| 313 | let limit = 5; | 325 | let limit = 5; |
| 314 | let check = 0; | 326 | let check = 0; |
| 315 | async function handleDetectFace() { | 327 | async function handleDetectFace() { |
| 316 | - for (let i = 0; i < limit; i ++) { | ||
| 317 | - check ++; | 328 | + for (let i = 0; i < limit; i++) { |
| 329 | + check++; | ||
| 318 | let img = _this.getFace(); | 330 | let img = _this.getFace(); |
| 319 | let item = { | 331 | let item = { |
| 320 | "image": img.split(',')[1], | 332 | "image": img.split(',')[1], |
| 321 | "image_type": "BASE64", | 333 | "image_type": "BASE64", |
| 322 | "face_field": "faceshape,facetype,feature" | 334 | "face_field": "faceshape,facetype,feature" |
| 323 | } | 335 | } |
| 324 | - const url = this.urlpre +`/face/faceSearch`; | 336 | + const url = this.urlpre + `/face/faceSearch`; |
| 325 | const dataReturn = await commonServices.postValueService(null, item, url); | 337 | const dataReturn = await commonServices.postValueService(null, item, url); |
| 326 | if (dataReturn.data.code === 1) { | 338 | if (dataReturn.data.code === 1) { |
| 327 | - _this.setState({thumbImg: _this.getFace()}) | 339 | + _this.setState({ thumbImg: _this.getFace() }) |
| 328 | _this.changeStatusContent('人脸验证成功'); | 340 | _this.changeStatusContent('人脸验证成功'); |
| 329 | _this.stopMedia(); | 341 | _this.stopMedia(); |
| 330 | _this.props.onDetectSuccess && _this.props.onDetectSuccess(dataReturn.data); | 342 | _this.props.onDetectSuccess && _this.props.onDetectSuccess(dataReturn.data); |
| @@ -343,7 +355,7 @@ class FaceDetect extends Component { | @@ -343,7 +355,7 @@ class FaceDetect extends Component { | ||
| 343 | const stream = this.video.srcObject; | 355 | const stream = this.video.srcObject; |
| 344 | if (stream) { | 356 | if (stream) { |
| 345 | const tracks = stream.getTracks(); | 357 | const tracks = stream.getTracks(); |
| 346 | - tracks.forEach(function(track) { | 358 | + tracks.forEach(function (track) { |
| 347 | track.stop(); | 359 | track.stop(); |
| 348 | }); | 360 | }); |
| 349 | this.video.srcObject = null; | 361 | this.video.srcObject = null; |
| @@ -369,10 +381,10 @@ class FaceDetect extends Component { | @@ -369,10 +381,10 @@ class FaceDetect extends Component { | ||
| 369 | "quality_control": "NORMAL", | 381 | "quality_control": "NORMAL", |
| 370 | "liveness_control": "NORMAL" | 382 | "liveness_control": "NORMAL" |
| 371 | } | 383 | } |
| 372 | - const url = this.urlpre +`/face/faceSearch`; | 384 | + const url = this.urlpre + `/face/faceSearch`; |
| 373 | const dataReturn = await commonServices.postValueService(null, item, url); | 385 | const dataReturn = await commonServices.postValueService(null, item, url); |
| 374 | if (dataReturn && dataReturn.data && dataReturn.data.code === 1) { | 386 | if (dataReturn && dataReturn.data && dataReturn.data.code === 1) { |
| 375 | - _this.setState({thumbImg: _this.getFace()}) | 387 | + _this.setState({ thumbImg: _this.getFace() }) |
| 376 | _this.changeStatusContent('人脸验证成功'); | 388 | _this.changeStatusContent('人脸验证成功'); |
| 377 | _this.stopMedia(); | 389 | _this.stopMedia(); |
| 378 | _this.props.onIdentifySuccess && _this.props.onIdentifySuccess(dataReturn.data); | 390 | _this.props.onIdentifySuccess && _this.props.onIdentifySuccess(dataReturn.data); |
| @@ -424,7 +436,7 @@ class FaceDetect extends Component { | @@ -424,7 +436,7 @@ class FaceDetect extends Component { | ||
| 424 | } | 436 | } |
| 425 | 437 | ||
| 426 | render() { | 438 | render() { |
| 427 | - const enable = ((this.props.enabled && this.user_id !== '' )|| this.props.actionType === 'identifyFace'); | 439 | + const enable = ((this.props.enabled && this.user_id !== '') || this.props.actionType === 'identifyFace'); |
| 428 | const faceCollection = commonFunc.showLocalMessage(this.props, 'faceCollection', '人脸采集'); | 440 | const faceCollection = commonFunc.showLocalMessage(this.props, 'faceCollection', '人脸采集'); |
| 429 | return ( | 441 | return ( |
| 430 | <> | 442 | <> |