From 4af93746f09b67a899a8e260d774cccd361934dd Mon Sep 17 00:00:00 2001
From: liyuetong
Date: Tue, 3 Aug 2021 17:45:47 +0800
Subject: [PATCH] =?UTF-8?q?ocr=E5=85=A5=E5=8F=82=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/ebiz/sale/BankCardScan.vue | 60 +++++----
src/components/ebiz/sale/IdentityCardScan.vue | 124 ++++++++++--------
2 files changed, 99 insertions(+), 85 deletions(-)
diff --git a/src/components/ebiz/sale/BankCardScan.vue b/src/components/ebiz/sale/BankCardScan.vue
index b353b3748..9811fa53c 100644
--- a/src/components/ebiz/sale/BankCardScan.vue
+++ b/src/components/ebiz/sale/BankCardScan.vue
@@ -56,40 +56,44 @@ export default {
click() {
let that = this
if (window.localStorage.getItem('cardScanningType') == '0') {
- // console.log('11111')
- EWebBridge.webCallAppInJs('bankcard_ocr', {
- // 1是扫描。0是相册。
- scan: '1'
- }).then(data => {
- console.log(data,'data111111111111')
+ EWebBridge.webCallAppInJs('bankcard_ocr').then(data => {
console.log(JSON.parse(data),'JSON.parse(data)')
- if (JSON.parse(data).imageBase64) {
- that.state = 1
- that.bankCard = JSON.parse(data).cardNo
- that.src = JSON.parse(data).imageBase64
-
- window.localStorage.setItem('bankCardUrlPath', encodeURI(JSON.parse(data).path).replace(/\+/g, '%2B'))
- window.localStorage.setItem('bankCard', JSON.parse(data).number)
- that.isDisabled = false
+ let result = JSON.parse(data)
+ if(result.code == 1){
+ let bankCardInfo = result.content
+ if (bankCardInfo.imageBase64) {
+ that.state = 1
+ that.bankCard = bankCardInfo.cardNo
+ that.src = bankCardInfo.imageBase64
+ window.localStorage.setItem('bankCardUrlPath', encodeURI(bankCardInfo.imagePath).replace(/\+/g, '%2B'))
+ window.localStorage.setItem('bankCard', bankCardInfo.cardNo)
+ that.isDisabled = false
+ } else {
+ console.log('')
+ }
} else {
- console.log('')
+ //识别失败
+ this.$toast(result.message)
}
})
} else if (window.localStorage.getItem('cardScanningType') == '1') {
- // console.log('22222')
- EWebBridge.webCallAppInJs('bankcard_ocr', {
- // 1是扫描。0是相册。
- scan: '1'
- }).then(data => {
- if (JSON.parse(data).imageBase64) {
- that.state = 1
- that.bankCard = JSON.parse(data).cardNo
- that.src = JSON.parse(data).imageBase64
- window.localStorage.setItem('bankCardUrlInsuredPath', encodeURI(JSON.parse(data).path).replace(/\+/g, '%2B'))
- window.localStorage.setItem('bankCardInsured', JSON.parse(data).number)
- that.isDisabled = false
+ EWebBridge.webCallAppInJs('bankcard_ocr').then(data => {
+ let result = JSON.parse(data)
+ if(result.code == 1){
+ let bankCardInfo = result.content
+ if (bankCardInfo.imageBase64) {
+ that.state = 1
+ that.bankCard = bankCardInfo.cardNo
+ that.src = bankCardInfo.imageBase64
+ window.localStorage.setItem('bankCardUrlInsuredPath', encodeURI(bankCardInfo.imagePath).replace(/\+/g, '%2B'))
+ window.localStorage.setItem('bankCardInsured', bankCardInfo.cardNo)
+ that.isDisabled = false
+ } else {
+ console.log('')
+ }
} else {
- console.log('')
+ //识别失败
+ this.$toast(result.message)
}
})
}
diff --git a/src/components/ebiz/sale/IdentityCardScan.vue b/src/components/ebiz/sale/IdentityCardScan.vue
index f852ce723..bea9a2259 100644
--- a/src/components/ebiz/sale/IdentityCardScan.vue
+++ b/src/components/ebiz/sale/IdentityCardScan.vue
@@ -100,41 +100,46 @@ export default {
front() {
let that = this
EWebBridge.webCallAppInJs('idcard_ocr', {
- front: '1', //1是正面,0是反面。
-
- scan: '1' //1是扫描。0是相册。
+ front: '1' //1是正面,0是反面。
+ // scan: '1' //1是扫描。0是相册。
}).then(data => {
- console.log(data,'data111111111111')
- console.log(JSON.parse(data),'JSON.parse(data)')
- // if (JSON.parse(data).state == '1') {
- if (JSON.parse(data).imageBase64) {
- // console.log(JSON.parse(data).base64)
- if (that.scanFromInsured == 'true') {
- console.log(JSON.parse(data))
- // that.state = JSON.parse(data).state
- that.state = 1
- that.name = JSON.parse(data).name
- that.idCard = JSON.parse(data).number
- that.imgfront = JSON.parse(data).imageBase64
- that.birthYear = JSON.parse(data).birthdayYear
- that.birthMonth = JSON.parse(data).birthdayMonth.padStart(2, '0')
- that.birthDay = JSON.parse(data).birthdayDay.padStart(2, '0')
- that.gender = JSON.parse(data).gender
- window.localStorage.setItem('imgfrontPath', encodeURI(JSON.parse(data).imagePath).replace(/\+/g, '%2B'))
+ console.log(JSON.parse(data),'JSON.parse(data)')
+ let result = JSON.parse(data)
+ // if (idCardInfo.state == '1') {
+ if(result.code == 1){
+ let idCardInfo = result.content
+ if (idCardInfo.imageBase64) {
+ // console.log(idCardInfo.base64)
+ if (that.scanFromInsured == 'true') {
+ console.log(idCardInfo)
+ // that.state = idCardInfo.state
+ that.state = 1
+ that.name = idCardInfo.name
+ that.idCard = idCardInfo.number
+ that.imgfront = idCardInfo.imageBase64
+ that.birthYear = idCardInfo.birthdayYear
+ that.birthMonth = idCardInfo.birthdayMonth.padStart(2, '0')
+ that.birthDay = idCardInfo.birthdayDay.padStart(2, '0')
+ that.gender = idCardInfo.gender
+ window.localStorage.setItem('imgfrontPath', encodeURI(idCardInfo.imagePath).replace(/\+/g, '%2B'))
+ } else {
+ // that.state = idCardInfo.state
+ that.state = 1
+ that.name = idCardInfo.name
+ that.idCard = idCardInfo.number
+ that.imgfront = idCardInfo.imageBase64
+ that.birthYear = idCardInfo.birthdayYear
+ that.birthMonth = idCardInfo.birthdayMonth.padStart(2, '0')
+ that.birthDay = idCardInfo.birthdayDay.padStart(2, '0')
+ that.gender = idCardInfo.gender
+ window.localStorage.setItem('imgfrontInsuredPath', encodeURI(idCardInfo.imagePath).replace(/\+/g, '%2B'))
+ }
} else {
- // that.state = JSON.parse(data).state
- that.state = 1
- that.name = JSON.parse(data).name
- that.idCard = JSON.parse(data).number
- that.imgfront = JSON.parse(data).imageBase64
- that.birthYear = JSON.parse(data).birthdayYear
- that.birthMonth = JSON.parse(data).birthdayMonth.padStart(2, '0')
- that.birthDay = JSON.parse(data).birthdayDay.padStart(2, '0')
- that.gender = JSON.parse(data).gender
- window.localStorage.setItem('imgfrontInsuredPath', encodeURI(JSON.parse(data).imagePath).replace(/\+/g, '%2B'))
+ console.log('')
}
} else {
- console.log('')
+ //识别失败
+ this.$toast(result.message)
}
})
},
@@ -142,36 +147,41 @@ export default {
back() {
let that = this
EWebBridge.webCallAppInJs('idcard_ocr', {
- front: '0', //1是正面,0是反面。
- scan: '1' //1是扫描。0是相册。
+ front: '0' //1是正面,0是反面。
+ // scan: '1' //1是扫描。0是相册。
}).then(data => {
- if (that.scanFromInsured == 'true') {
- if (JSON.parse(data).imageBase64 == '1') {
- // if (JSON.parse(data).state == '1') {
- // that.stateBack = JSON.parse(data).state
- that.stateBack = 1
- that.imgBack = JSON.parse(data).imagePath
- that.startDate = JSON.parse(data).validDateStart
- that.endDate = JSON.parse(data).validDateEnd
-
- window.localStorage.setItem('imgBackPath', encodeURI(JSON.parse(data).path).replace(/\+/g, '%2B'))
+ console.log(JSON.parse(data),'JSON.parse(data)')
+ let result = JSON.parse(data)
+ if(result.code == 1){
+ let idCardInfo = result.content
+ if (that.scanFromInsured == 'true') {
+ if (idCardInfo.imageBase64) {
+ // if (idCardInfo.state == '1') {
+ // that.stateBack = idCardInfo.state
+ that.stateBack = 1
+ that.imgBack = idCardInfo.imagePath
+ that.startDate = idCardInfo.validDateStart
+ that.endDate = idCardInfo.validDateEnd
+ window.localStorage.setItem('imgBackPath', encodeURI(idCardInfo.imagePath).replace(/\+/g, '%2B'))
+ } else {
+ console.log('')
+ }
} else {
- console.log('')
+ if (idCardInfo.imageBase64) {
+ // if (idCardInfo.state == '1') {
+ // that.stateBack = idCardInfo.state
+ that.stateBack = 1
+ that.imgBack = idCardInfo.imagePath
+ window.localStorage.setItem('imgBackInsuredPath', encodeURI(idCardInfo.imagePath).replace(/\+/g, '%2B'))
+ that.startDate = idCardInfo.validDateStart
+ that.endDate = idCardInfo.validDateEnd
+ } else {
+ console.log('')
+ }
}
} else {
- if (JSON.parse(data).imageBase64 == '1') {
- // if (JSON.parse(data).state == '1') {
- // that.stateBack = JSON.parse(data).state
- that.stateBack = 1
- that.imgBack = JSON.parse(data).imagePath
-
- window.localStorage.setItem('imgBackInsuredPath', encodeURI(JSON.parse(data).path).replace(/\+/g, '%2B'))
-
- that.startDate = JSON.parse(data).validDateStart
- that.endDate = JSON.parse(data).validDateEnd
- } else {
- console.log('')
- }
+ //识别失败
+ this.$toast(result.message)
}
})
},