ISBN扫码改为普通拍照摄像头+OCR识别
This commit is contained in:
parent
ec3fbc8bf0
commit
97b7cb5680
@ -1142,23 +1142,46 @@ export default {
|
||||
|
||||
// ISBN扫码
|
||||
scanISBN() {
|
||||
// 必须已登录孔网,否则直接弹窗不打开摄像头
|
||||
// 必须已登录孔网
|
||||
if (!this.isLoggedIn) {
|
||||
uni.showToast({ title: '请先登录孔网账号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.scanCode({
|
||||
onlyFromCamera: true,
|
||||
scanType: ['barcode'],
|
||||
// 打开普通拍照摄像头(不带扫码框),拍照后OCR识别ISBN
|
||||
uni.chooseImage({
|
||||
sourceType: ['camera'],
|
||||
count: 1,
|
||||
success: (res) => {
|
||||
this.isbn = (res.result || '').trim()
|
||||
uni.showLoading({ title: '识别中...' })
|
||||
const filePath = res.tempFilePaths[0]
|
||||
uni.uploadFile({
|
||||
url: 'https://book.xcx.ocr.buzhiyushu.cn/ocr',
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
success: (ocrRes) => {
|
||||
uni.hideLoading()
|
||||
try {
|
||||
const ocrData = JSON.parse(ocrRes.data)
|
||||
if (ocrData && ocrData.texts && ocrData.texts.ISBN) {
|
||||
this.isbn = ocrData.texts.ISBN.replace(/\D/g, '')
|
||||
this.searchISBN()
|
||||
} else {
|
||||
uni.showToast({ title: '未识别到ISBN,请重试或手动输入', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('OCR解析失败:', e)
|
||||
uni.showToast({ title: '识别失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '扫码取消或失败', icon: 'none' })
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '识别失败', icon: 'none' })
|
||||
}
|
||||
})
|
||||
},
|
||||
fail: () => {}
|
||||
})
|
||||
},
|
||||
|
||||
// ISBN搜索 - 查询图书中心 + 孔网市场
|
||||
searchISBN() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user