@uxda/appkit 4.1.4 → 4.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/appkit.css +8 -2
- package/dist/index.js +1043 -1104
- package/package.json +2 -2
- package/src/shared/components/OcrBusinessLicense.vue +55 -40
- package/src/shared/components/OcrIcon.vue +15 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxda/appkit",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.6",
|
|
4
4
|
"description": "小程序应用开发包",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@uxda/nutshell": "^1.0.0",
|
|
38
38
|
"dayjs": "^1.11.10",
|
|
39
39
|
"validator": "^13.12.0",
|
|
40
|
-
"vue": "^3.
|
|
40
|
+
"vue": "^3.5.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/core": "^7.8.0",
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="ocr-icon" @click="onIconClick">
|
|
2
|
+
<div :class="['ocr-business-license', disabled ? 'disabled' : '']" class="ocr-icon" @click="onIconClick">
|
|
3
3
|
<ns-icon name="https://simple.shensi.tech/icons/ocr.svg" />
|
|
4
4
|
</div>
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script lang="ts" setup>
|
|
8
|
-
import Taro from '@tarojs/taro'
|
|
9
|
-
import { NsIcon } from '@uxda/nutshell/taro'
|
|
10
|
-
import { useAppKitOptions } from '../../Appkit'
|
|
8
|
+
import Taro from '@tarojs/taro'
|
|
9
|
+
import { NsIcon } from '@uxda/nutshell/taro'
|
|
10
|
+
import { useAppKitOptions } from '../../Appkit'
|
|
11
11
|
|
|
12
|
-
const appKitOptions = useAppKitOptions()
|
|
12
|
+
const appKitOptions = useAppKitOptions()
|
|
13
13
|
|
|
14
|
-
const emits = defineEmits(['complete'])
|
|
14
|
+
const emits = defineEmits(['complete'])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
type OcrBusinessLicenseProps = {
|
|
18
|
+
disabled: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
defineProps<OcrBusinessLicenseProps>()
|
|
15
22
|
|
|
16
23
|
export type OcrResult = {
|
|
17
|
-
companyName: string
|
|
18
|
-
idCardNo: string
|
|
19
|
-
legalPersonName: string
|
|
20
|
-
}
|
|
24
|
+
companyName: string
|
|
25
|
+
idCardNo: string
|
|
26
|
+
legalPersonName: string
|
|
27
|
+
}
|
|
21
28
|
|
|
22
29
|
async function taroImgCompress(src: string, quality = 80) {
|
|
23
30
|
return new Promise((resolve, reject) => {
|
|
@@ -25,42 +32,45 @@ async function taroImgCompress(src: string, quality = 80) {
|
|
|
25
32
|
src: src,
|
|
26
33
|
quality: quality,
|
|
27
34
|
success: (res) => {
|
|
28
|
-
resolve(res)
|
|
35
|
+
resolve(res)
|
|
29
36
|
},
|
|
30
37
|
fail: (res) => {
|
|
31
|
-
reject(res)
|
|
38
|
+
reject(res)
|
|
32
39
|
},
|
|
33
|
-
})
|
|
34
|
-
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
function getCompressQuality(size: number) {
|
|
38
|
-
let quality = 100
|
|
39
|
-
const curSize = size / (1024 * 1024)
|
|
45
|
+
let quality = 100
|
|
46
|
+
const curSize = size / (1024 * 1024)
|
|
40
47
|
if (curSize > 6) {
|
|
41
|
-
quality = quality - ((curSize - 6) / curSize) * 100
|
|
48
|
+
quality = quality - ((curSize - 6) / curSize) * 100
|
|
42
49
|
}
|
|
43
|
-
return quality
|
|
50
|
+
return quality
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
function allTrim(str: string) {
|
|
47
|
-
return str.replace(/\s+/g, '')
|
|
54
|
+
return str.replace(/\s+/g, '')
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
async function onIconClick() {
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
if (props.disabled) {
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
console.log('===onIconClick')
|
|
62
|
+
let result: OcrResult | null = null
|
|
53
63
|
try {
|
|
54
64
|
const csRes = await Taro.chooseImage({
|
|
55
65
|
count: 1,
|
|
56
|
-
})
|
|
57
|
-
let { path, size } = csRes.tempFiles[0]
|
|
66
|
+
})
|
|
67
|
+
let { path, size } = csRes.tempFiles[0]
|
|
58
68
|
const compressImg: any =
|
|
59
|
-
(await taroImgCompress(path, getCompressQuality(size))) || {}
|
|
60
|
-
const filePath = compressImg.tempFilePath || path
|
|
61
|
-
Taro.showLoading({ title: '营业执照识别中..' })
|
|
62
|
-
const session = appKitOptions.token()
|
|
63
|
-
const baseUrl = appKitOptions.baseUrl()
|
|
69
|
+
(await taroImgCompress(path, getCompressQuality(size))) || {}
|
|
70
|
+
const filePath = compressImg.tempFilePath || path
|
|
71
|
+
Taro.showLoading({ title: '营业执照识别中..' })
|
|
72
|
+
const session = appKitOptions.token()
|
|
73
|
+
const baseUrl = appKitOptions.baseUrl()
|
|
64
74
|
const upRes: any = await Taro.uploadFile({
|
|
65
75
|
url: baseUrl + '/promoact/common/parseBusinessLicense',
|
|
66
76
|
filePath,
|
|
@@ -72,11 +82,11 @@ async function onIconClick() {
|
|
|
72
82
|
sessionKey: session || '',
|
|
73
83
|
token: session || '',
|
|
74
84
|
},
|
|
75
|
-
})
|
|
76
|
-
Taro.hideLoading()
|
|
77
|
-
const res = JSON.parse(upRes.data)
|
|
85
|
+
})
|
|
86
|
+
Taro.hideLoading()
|
|
87
|
+
const res = JSON.parse(upRes.data)
|
|
78
88
|
if (res.code === '200') {
|
|
79
|
-
const faceInfo = res.result || {}
|
|
89
|
+
const faceInfo = res.result || {}
|
|
80
90
|
result = {
|
|
81
91
|
companyName: allTrim(faceInfo.companyName || ''),
|
|
82
92
|
idCardNo: allTrim(faceInfo.idCardNo || ''),
|
|
@@ -84,32 +94,37 @@ async function onIconClick() {
|
|
|
84
94
|
fileId: faceInfo.fileId,
|
|
85
95
|
originalUrl: faceInfo.originalUrl,
|
|
86
96
|
downloadUrl: faceInfo.downloadUrl,
|
|
87
|
-
}
|
|
88
|
-
console.log('===识别', result)
|
|
97
|
+
}
|
|
98
|
+
console.log('===识别', result)
|
|
89
99
|
if (!result.companyName && !result.idCardNo) {
|
|
90
|
-
Taro.showToast({ title: '识别失败,请重试', icon: 'none' })
|
|
100
|
+
Taro.showToast({ title: '识别失败,请重试', icon: 'none' })
|
|
91
101
|
}
|
|
92
102
|
} else {
|
|
93
103
|
Taro.showToast({
|
|
94
104
|
title: res.msg,
|
|
95
105
|
icon: 'error',
|
|
96
|
-
})
|
|
106
|
+
})
|
|
97
107
|
}
|
|
98
108
|
} catch (err) {
|
|
99
|
-
Taro.hideLoading()
|
|
100
|
-
console.log(err)
|
|
109
|
+
Taro.hideLoading()
|
|
110
|
+
console.log(err)
|
|
101
111
|
}
|
|
102
|
-
emits('complete', result)
|
|
112
|
+
emits('complete', result)
|
|
103
113
|
}
|
|
104
114
|
</script>
|
|
105
115
|
|
|
106
116
|
<style lang="scss">
|
|
107
|
-
.ocr-
|
|
117
|
+
.ocr-business-license {
|
|
108
118
|
width: 24px;
|
|
109
119
|
height: 24px;
|
|
110
120
|
.ns-icon {
|
|
111
121
|
width: 24px;
|
|
112
122
|
height: 24px;
|
|
113
123
|
}
|
|
124
|
+
&.disabled {
|
|
125
|
+
.ns-icon {
|
|
126
|
+
filter: brightness(1.5) grayscale(1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
114
129
|
}
|
|
115
130
|
</style>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="ocr-icon" @click="onIconClick">
|
|
2
|
+
<div :class="['ocr-icon', disabled ? 'disabled' : '']" @click="onIconClick">
|
|
3
3
|
<ns-icon name="https://simple.shensi.tech/icons/ocr.svg" />
|
|
4
4
|
</div>
|
|
5
5
|
</template>
|
|
@@ -13,6 +13,12 @@ const appKitOptions = useAppKitOptions()
|
|
|
13
13
|
|
|
14
14
|
const emits = defineEmits(['complete'])
|
|
15
15
|
|
|
16
|
+
type OcrIconProps = {
|
|
17
|
+
disabled: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
defineProps<OcrIconProps>()
|
|
21
|
+
|
|
16
22
|
export type OcrResult = {
|
|
17
23
|
name: string
|
|
18
24
|
number: string
|
|
@@ -48,7 +54,9 @@ function allTrim(str: string) {
|
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
async function onIconClick() {
|
|
51
|
-
|
|
57
|
+
if (props.disabled) {
|
|
58
|
+
return
|
|
59
|
+
}
|
|
52
60
|
let result: OcrResult | null = null
|
|
53
61
|
try {
|
|
54
62
|
const csRes = await Taro.chooseImage({
|
|
@@ -115,5 +123,10 @@ async function onIconClick() {
|
|
|
115
123
|
width: 24px;
|
|
116
124
|
height: 24px;
|
|
117
125
|
}
|
|
126
|
+
&.disabled {
|
|
127
|
+
.ns-icon {
|
|
128
|
+
filter: brightness(1.5) grayscale(1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
118
131
|
}
|
|
119
132
|
</style>
|