| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <template>
- <div id="app">
- <header></header>
- <main class="content">
- <Face
- v-if="visible"
- ref="face"
- v-model="resultImage"
- :default-image="imageUrl"></Face>
- <div class="hidden">
- <Face default-image="/face.jpg"></Face>
- </div>
- </main>
- <footer>
- <div class="info">
- <span v-if="!imageUrl">
- 请将人脸移入框内正对摄像头,并保持光线充足。勿佩戴帽子、墨镜
- </span>
- </div>
- <div>
- <el-button
- size="large"
- type="info"
- @click="hide()">
- 关闭
- </el-button>
- <el-button
- :loading="loading"
- size="large"
- type="primary"
- @click="handleSubmit">
- 确定
- </el-button>
- </div>
- </footer>
- </div>
- </template>
- <script>
- import { faceidentify11 } from '@/api/face'
- import compressImg from '@/assets/compress'
- import Face from '@/components/GetFace/FaceDetector'
- export default {
- data () {
- return {
- loading: false,
- visible: false,
- imageUrl: '',
- resultImage: null
- }
- },
- mounted () {
- const { ipcRenderer, remote } = require('electron')
- console.log(remote.getGlobal('windows')['index'])
- ipcRenderer.on('showFaceDetector', (event, data, skipCheck) => {
- this.visible = true
- this.resultImage = null
- this.imageUrl = data || ''
- this.skipCheck = skipCheck
- console.log(data, skipCheck)
- this.$nextTick(() => {
- this.show()
- // 打开摄像头
- if (!data) {
- this.$refs.face.fnOpen()
- }
- })
- })
- },
- components: {
- Face
- },
- methods: {
- show () {
- require('electron').remote.getCurrentWindow().show()
- },
- hide (data) {
- this.visible = false
- this.$refs.face && this.$refs.face.fnClose()
- data && this.sendResult(data)
- require('electron').remote.getCurrentWindow().hide()
- },
- handleSubmit () {
- let msg = ''
- if (!this.resultImage) {
- this.$message.error('未获取到人脸图像,请重新选择图片或拍照')
- return
- }
- if (this.resultImage.width * this.resultImage.height < 250 * 250) {
- msg = '人脸图太小,是否仍然提交?'
- }
- const submit = async () => {
- let validFace = await this.faceidentify11(this.resultImage.url)
- if (validFace) {
- this.$message.success('人脸校验成功。')
- setTimeout(() => {
- if (this.resultImage.width * this.resultImage.height > 400 * 400) {
- compressImg(this.resultImage.url, 400).then(res => {
- this.hide(res)
- })
- } else {
- this.hide(this.resultImage.url)
- }
- }, 1000)
- }
- }
- if (msg) {
- this.$confirm(msg, '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- submit()
- }).catch(() => {
- })
- } else {
- submit()
- }
- },
- // 人脸比对API
- faceidentify11 (face) {
- if (this.skipCheck) return face
- this.loading = true
- return faceidentify11({ img1: face.split(',')[1], img2: face.split(',')[1] }).then(res => {
- if (res.errInfo === '成功') {
- return face
- } else {
- this.$message({
- showClose: true,
- message: '人脸模糊,请重新拍照',
- type: 'error'
- })
- return false
- }
- }).catch(() => {
- this.$message({
- showClose: true,
- message: '人脸模糊,请重新拍照',
- type: 'error'
- })
- return false
- }).finally(() => {
- this.loading = false
- })
- },
- sendResult (data) {
- const { ipcRenderer, remote } = require('electron')
- ipcRenderer.sendTo(remote.getGlobal('windows')['index'], 'getDectectorResult', data)
- }
- }
- }
- </script>
- <style lang="scss">
- * {
- padding: 0; margin: 0;
- }
- body,html {
- height: 100%;
- }
- #app {
- display: flex; height: 100%; flex-direction: column; background: #eee;
- }
- .content {
- display: flex; flex: 1;
- }
- footer {
- padding: 10px; margin: 0 10px 10px; background: #fff; border: 1px solid #ddd; display: flex; justify-content: space-between; align-items: center;
- .info{
- color: red; font-size: 18px;
- }
- }
- .hidden {
- width: 0; height: 0; overflow: hidden;
- }
- </style>
|