@uxda/appkit 4.3.2 → 4.3.4

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.
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="ocr-bank" :class="[disabled ? 'disabled' : '']" v-track-click="'身份证识别-点击'" @click="onPhotograph">
2
+ <div class="ocr-bank" :class="[disabled ? 'disabled' : '']" v-track-click="'银行卡识别-点击'" @click="!customClick ? onUpload() : null">
3
3
  <slot name="icon">
4
4
  <ns-icon name="https://cdn.ddjf.com/static/images/beidouxing/ocr-icon.png" />
5
5
  </slot>
@@ -11,132 +11,75 @@
11
11
 
12
12
  <script lang="ts" setup>
13
13
  import Taro, { showToast, showLoading, hideLoading, chooseMedia, chooseMessageFile, uploadFile } from '@tarojs/taro'
14
- import { NsIcon } from '@uxda/nutshell/taro'
14
+ import { NsIcon, useNutshell } from '@uxda/nutshell/taro'
15
15
  import { useAppKitOptions } from '../../Appkit'
16
16
  import { ref } from 'vue';
17
+ import { useHttp } from '../../balance/api'
18
+ import { compressImage, getCompressQuality } from '../composables/useUpload'
17
19
 
18
20
  const appKitOptions = useAppKitOptions()
21
+ const $http = useHttp(),
22
+ $n = useNutshell()
19
23
 
20
24
  const emits = defineEmits(['complete'])
21
25
 
22
- type OcrIconProps = {
26
+ type OcrProps = {
23
27
  disabled?: boolean,
24
- side?: 'face' | 'back',
25
28
  class?: string
29
+ uploadUrl?: string
30
+ customClick?: boolean
31
+ }
32
+ type FileType = {
33
+ "downloadUrl": string,
34
+ "fileId": string,
35
+ "fileName": string,
36
+ "fileSize": number,
37
+ "fileSuffix": string,
38
+ "fileType": string,
39
+ "originalUrl": string
26
40
  }
27
41
 
28
- const props = withDefaults(defineProps<OcrIconProps>(), {
42
+ const props = withDefaults(defineProps<OcrProps>(), {
29
43
  disabled: false,
30
- side: 'face',
31
- class: ''
44
+ class: '',
45
+ uploadUrl: '/hkbase/file/uploadFile',
46
+ customClick: false
32
47
  })
33
48
 
34
- type OcrResultType = {
35
- faceInfo: {
36
- name: string
37
- certNo: string
38
- address: string
39
- }
40
- backInfo: {
41
- startDate: string
42
- endDate: string
43
- }
44
- fileUploadVO: {
45
- fileKey: string
46
- fileUrl: string
47
- objectNo: string
48
- thumbnailUrl?: string
49
- }
50
- }
51
-
52
- async function taroImgCompress(src: string, quality = 80) {
53
- if (Taro.getEnv() === 'WEB') {
54
- return src;
55
- } else {
56
- return new Promise((resolve, reject) => {
57
- Taro.compressImage({
58
- src: src,
59
- quality: quality,
60
- success: (res) => {
61
- resolve(res)
62
- },
63
- fail: (res) => {
64
- reject(res)
65
- },
66
- })
67
- })
68
- }
69
- }
70
-
71
- function getCompressQuality(size: number) {
72
- let quality = 100
73
- const curSize = size / (1024 * 1024)
74
- if (curSize > 6) {
75
- quality = quality - ((curSize - 6) / curSize) * 100
76
- }
77
- return quality
78
- }
79
-
80
- function allTrim(str: string) {
81
- return str.replace(/\s+/g, '')
49
+ type BankCardType = {
50
+ bankCardNumber: string
51
+ bankCardType: string
52
+ bankName: string
82
53
  }
83
54
 
84
55
  async function onUploadFile(csRes: any) {
85
- let result: OcrResultType | null = null
86
56
  try {
87
- console.log('===上传', csRes)
88
57
  let { path, size, tempFilePath } = csRes.tempFiles[0]
89
- let filePath
90
- if (Taro.getEnv() !== 'WEB') {
91
- const compressImg: any = (await taroImgCompress(path || tempFilePath, getCompressQuality(size))) || {}
92
- filePath = compressImg.tempFilePath || path
93
- } else {
94
- filePath = path || tempFilePath
95
- }
58
+ const compressImg: any = (await compressImage(path || tempFilePath, getCompressQuality(size))) || {}
59
+ const filePath = compressImg.tempFilePath || path
96
60
 
97
- console.log(filePath, 'filePath')
98
- showLoading({ title: '身份证识别中..' })
61
+ showLoading({ title: '银行卡识别中..', mask: true })
99
62
 
100
63
  const session = appKitOptions.token()
101
64
  const baseUrl = appKitOptions.baseUrl()
102
65
  const upRes: any = await uploadFile({
103
- url: baseUrl + '/hkapprove/ocr/idcard',
66
+ url: baseUrl + props.uploadUrl,
104
67
  filePath,
105
68
  name: 'file',
106
69
  formData: {
107
70
  objectNo: `min${Date.now()}`,
108
- side: props.side,
71
+ appCode: appKitOptions.app(),
109
72
  },
110
73
  header: {
111
74
  token: session || '',
112
75
  },
113
76
  })
114
- hideLoading()
115
77
 
116
78
  const res = JSON.parse(upRes.data)
117
79
  if (res.code === '200') {
118
- const faceInfo = res.result.faceInfo || {}
119
- const backInfo = res.result.backInfo || {}
120
- result = {
121
- faceInfo: {
122
- name: allTrim(faceInfo.name || ''),
123
- certNo: allTrim(faceInfo.num || ''),
124
- address: allTrim(faceInfo.address || ''),
125
- },
126
- backInfo: {
127
- startDate: backInfo?.startDate || '',
128
- endDate: backInfo?.endDate || ''
129
- },
130
- fileUploadVO: res.result.fileUploadVO || {},
131
- }
132
- console.log('===识别', result)
133
- if (props.side === 'face' && !result.faceInfo.name && !result.faceInfo.certNo) {
134
- showToast({ title: '识别失败,请重试', icon: 'none' })
135
- }
136
- if (props.side === 'back' && !result.backInfo?.startDate && !result.backInfo?.endDate) {
137
- showToast({ title: '识别失败,请重试', icon: 'none' })
138
- }
80
+ await getBankCardInfo(res.result)
139
81
  } else {
82
+ hideLoading()
140
83
  showToast({
141
84
  title: res.msg,
142
85
  icon: 'error',
@@ -146,9 +89,35 @@ async function onUploadFile(csRes: any) {
146
89
  hideLoading()
147
90
  console.log(err)
148
91
  }
149
- emits('complete', result)
150
92
  }
151
93
 
94
+ // 根据银行卡路径获取银行卡信息
95
+ async function getBankCardInfo(file: string | FileType) {
96
+ try {
97
+ const res: BankCardType = await $http.get('/hkbase/common/bankCard', {
98
+ fileUrl: typeof file === 'string' ? file : file.originalUrl,
99
+ })
100
+ hideLoading()
101
+
102
+ if (res && !res.bankCardNumber) {
103
+ $n.dialog({
104
+ title: '识别失败',
105
+ message: `您上传的图片可能不够清晰或与当前功能不符,请重新上传一张清晰、完整的图片。谢谢!`,
106
+ okText: '我知道了',
107
+ cancelText: '',
108
+ })
109
+ return
110
+ }
111
+
112
+ emits('complete', {
113
+ ...res,
114
+ fileUrl: typeof file === 'string' ? file : file.originalUrl,
115
+ fileKey: typeof file === 'string' ? file : file.fileId,
116
+ })
117
+ } catch (err) {
118
+ hideLoading()
119
+ }
120
+ }
152
121
 
153
122
  // 上传图片操作面板
154
123
  const activeSheetVisible = ref(false)
@@ -190,7 +159,7 @@ async function chooseImages(item: any) {
190
159
  }
191
160
  }
192
161
 
193
- async function onPhotograph() {
162
+ async function onUpload() {
194
163
  if (props.disabled) return
195
164
 
196
165
  if (Taro.getEnv() === 'WEB') {
@@ -206,6 +175,10 @@ async function onPhotograph() {
206
175
 
207
176
  activeSheetVisible.value = true
208
177
  }
178
+
179
+ defineExpose({
180
+ onUpload
181
+ })
209
182
  </script>
210
183
 
211
184
  <style lang="scss">
@@ -1,6 +1,8 @@
1
1
  <template>
2
- <div :class="['ocr-business-license', disabled ? 'disabled' : '']" class="ocr-icon" v-track-click="'营业执照识别-点击'" @click="onIconClick">
3
- <ns-icon name="https://cdn.ddjf.com/static/images/beidouxing/ocr-icon.png" />
2
+ <div :class="['ocr-business-license', disabled ? 'disabled' : '']" class="ocr-icon" v-track-click="'营业执照识别-点击'" @click="!customClick ? onUpload() : null">
3
+ <slot name="icon">
4
+ <ns-icon name="https://cdn.ddjf.com/static/images/beidouxing/ocr-icon.png" />
5
+ </slot>
4
6
  </div>
5
7
  </template>
6
8
 
@@ -8,6 +10,7 @@
8
10
  import Taro, { showToast, showLoading, hideLoading, uploadFile, chooseMedia } from '@tarojs/taro';
9
11
  import { NsIcon } from '@uxda/nutshell/taro';
10
12
  import { useAppKitOptions } from '../../Appkit';
13
+ import { compressImage, getCompressQuality } from '../composables/useUpload';
11
14
 
12
15
  const appKitOptions = useAppKitOptions();
13
16
 
@@ -15,9 +18,13 @@ const emits = defineEmits(['complete']);
15
18
 
16
19
  type OcrBusinessLicenseProps = {
17
20
  disabled: boolean;
21
+ customClick?: boolean
18
22
  };
19
23
 
20
- const props = defineProps<OcrBusinessLicenseProps>();
24
+ const props = withDefaults(defineProps<OcrBusinessLicenseProps>(), {
25
+ disabled: false,
26
+ customClick: false
27
+ });
21
28
 
22
29
  export type OcrResult = {
23
30
  companyName: string;
@@ -26,39 +33,14 @@ export type OcrResult = {
26
33
  [x: string]: any;
27
34
  };
28
35
 
29
- async function taroImgCompress(src: string, quality = 80) {
30
- return new Promise((resolve, reject) => {
31
- Taro.compressImage({
32
- src: src,
33
- quality: quality,
34
- success: (res) => {
35
- resolve(res)
36
- },
37
- fail: (res) => {
38
- reject(res)
39
- },
40
- })
41
- })
42
- }
43
-
44
- function getCompressQuality(size: number) {
45
- let quality = 100;
46
- const curSize = size / (1024 * 1024);
47
- if (curSize > 6) {
48
- quality = quality - ((curSize - 6) / curSize) * 100;
49
- }
50
- return quality;
51
- }
52
-
53
36
  function allTrim(str: string) {
54
37
  return str.replace(/\s+/g, '');
55
38
  }
56
39
 
57
- async function onIconClick() {
40
+ async function onUpload() {
58
41
  if (props.disabled) {
59
42
  return;
60
43
  }
61
- console.log('===onIconClick');
62
44
  let result: OcrResult | null = null;
63
45
  try {
64
46
  const csRes = await chooseMedia({
@@ -66,15 +48,10 @@ async function onIconClick() {
66
48
  sourceType: ['album', 'camera']
67
49
  });
68
50
  let { size, tempFilePath } = csRes.tempFiles[0];
69
- let filePath
70
- if (Taro.getEnv() !== 'WEB') {
71
- const compressImg: any = (await taroImgCompress(tempFilePath, getCompressQuality(size))) || {}
72
- filePath = compressImg.tempFilePath
73
- } else {
74
- filePath = tempFilePath
75
- }
51
+ const compressImg: any = (await compressImage(tempFilePath, getCompressQuality(size))) || {}
52
+ const filePath = compressImg.tempFilePath
76
53
 
77
- showLoading({ title: '营业执照识别中..' });
54
+ showLoading({ title: '营业执照识别中..', mask: true });
78
55
 
79
56
  const session = appKitOptions.token();
80
57
  const baseUrl = appKitOptions.baseUrl();
@@ -84,6 +61,7 @@ async function onIconClick() {
84
61
  name: 'file',
85
62
  formData: {
86
63
  objectNo: `min${Date.now()}`,
64
+ appCode: appKitOptions.app(),
87
65
  },
88
66
  header: {
89
67
  token: session || '',
@@ -117,6 +95,10 @@ async function onIconClick() {
117
95
  }
118
96
  emits('complete', result);
119
97
  }
98
+
99
+ defineExpose({
100
+ onUpload
101
+ })
120
102
  </script>
121
103
 
122
104
  <style lang="scss">
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="ocr-icon" :class="[disabled ? 'disabled' : '']" v-track-click="'身份证识别-点击'" @click="onPhotograph">
2
+ <div class="ocr-icon" :class="[disabled ? 'disabled' : '', className]" v-track-click="'身份证识别-点击'" @click="!customClick ? onUpload() : null">
3
3
  <slot name="icon">
4
4
  <ns-icon name="https://cdn.ddjf.com/static/images/beidouxing/ocr-icon.png" />
5
5
  </slot>
@@ -11,24 +11,44 @@
11
11
 
12
12
  <script lang="ts" setup>
13
13
  import Taro, { showToast, showLoading, hideLoading, chooseMedia, chooseMessageFile, uploadFile } from '@tarojs/taro'
14
- import { NsIcon } from '@uxda/nutshell/taro'
14
+ import { NsIcon, useNutshell } from '@uxda/nutshell/taro'
15
15
  import { useAppKitOptions } from '../../Appkit'
16
16
  import { ref } from 'vue';
17
+ import { useHttp } from '../../balance/api'
18
+ import { compressImage, getCompressQuality } from '../composables/useUpload'
17
19
 
18
20
  const appKitOptions = useAppKitOptions()
21
+ const $http = useHttp(),
22
+ $n = useNutshell()
19
23
 
20
24
  const emits = defineEmits(['complete'])
21
25
 
22
- type OcrIconProps = {
26
+ type OcrProps = {
23
27
  disabled?: boolean,
24
28
  side?: 'face' | 'back',
25
- class?: string
29
+ className?: string
30
+ uploadUrl?: string
31
+ customUpload?: Function
32
+ hasUploadVo?: boolean
33
+ customClick?: boolean
34
+ }
35
+ type FileType = {
36
+ "downloadUrl": string,
37
+ "fileId": string,
38
+ "fileName": string,
39
+ "fileSize": number,
40
+ "fileSuffix": string,
41
+ "fileType": string,
42
+ "originalUrl": string
26
43
  }
27
44
 
28
- const props = withDefaults(defineProps<OcrIconProps>(), {
45
+ const props = withDefaults(defineProps<OcrProps>(), {
29
46
  disabled: false,
30
47
  side: 'face',
31
- class: ''
48
+ className: '',
49
+ hasUploadVo: true,
50
+ customClick: false,
51
+ uploadUrl: '/saas-base/file/uploadPublic',
32
52
  })
33
53
 
34
54
  type OcrResultType = {
@@ -49,34 +69,6 @@ type OcrResultType = {
49
69
  }
50
70
  }
51
71
 
52
- async function taroImgCompress(src: string, quality = 80) {
53
- if (Taro.getEnv() === 'WEB') {
54
- return src;
55
- } else {
56
- return new Promise((resolve, reject) => {
57
- Taro.compressImage({
58
- src: src,
59
- quality: quality,
60
- success: (res) => {
61
- resolve(res)
62
- },
63
- fail: (res) => {
64
- reject(res)
65
- },
66
- })
67
- })
68
- }
69
- }
70
-
71
- function getCompressQuality(size: number) {
72
- let quality = 100
73
- const curSize = size / (1024 * 1024)
74
- if (curSize > 6) {
75
- quality = quality - ((curSize - 6) / curSize) * 100
76
- }
77
- return quality
78
- }
79
-
80
72
  function allTrim(str: string) {
81
73
  return str.replace(/\s+/g, '')
82
74
  }
@@ -84,59 +76,62 @@ function allTrim(str: string) {
84
76
  async function onUploadFile(csRes: any) {
85
77
  let result: OcrResultType | null = null
86
78
  try {
87
- console.log('===上传', csRes)
88
79
  let { path, size, tempFilePath } = csRes.tempFiles[0]
89
- let filePath
90
- if (Taro.getEnv() !== 'WEB') {
91
- const compressImg: any = (await taroImgCompress(path || tempFilePath, getCompressQuality(size))) || {}
92
- filePath = compressImg.tempFilePath || path
93
- } else {
94
- filePath = path || tempFilePath
80
+ const compressImg: any = (await compressImage(path || tempFilePath, getCompressQuality(size))) || {}
81
+ const filePath = compressImg.tempFilePath || path
82
+
83
+ if (props.customUpload) {
84
+ props.customUpload(filePath)
85
+ return
95
86
  }
96
87
 
97
- console.log(filePath, 'filePath')
98
- showLoading({ title: '身份证识别中..' })
88
+ showLoading({ title: '身份证识别中..', mask: true })
99
89
 
100
90
  const session = appKitOptions.token()
101
91
  const baseUrl = appKitOptions.baseUrl()
102
92
  const upRes: any = await uploadFile({
103
- url: baseUrl + '/hkapprove/ocr/idcard',
93
+ url: `${baseUrl}${!props.hasUploadVo ? props.uploadUrl : '/hkapprove/ocr/idcard'}`,
104
94
  filePath,
105
95
  name: 'file',
106
96
  formData: {
107
97
  objectNo: `min${Date.now()}`,
108
98
  side: props.side,
99
+ appCode: appKitOptions.app(),
109
100
  },
110
101
  header: {
111
102
  token: session || '',
112
103
  },
113
104
  })
114
- hideLoading()
115
105
 
116
106
  const res = JSON.parse(upRes.data)
117
107
  if (res.code === '200') {
118
- const faceInfo = res.result.faceInfo || {}
119
- const backInfo = res.result.backInfo || {}
120
- result = {
121
- faceInfo: {
122
- name: allTrim(faceInfo.name || ''),
123
- certNo: allTrim(faceInfo.num || ''),
124
- address: allTrim(faceInfo.address || ''),
125
- },
126
- backInfo: {
127
- startDate: backInfo?.startDate || '',
128
- endDate: backInfo?.endDate || ''
129
- },
130
- fileUploadVO: res.result.fileUploadVO || {},
131
- }
132
- console.log('===识别', result)
133
- if (props.side === 'face' && !result.faceInfo.name && !result.faceInfo.certNo) {
134
- showToast({ title: '识别失败,请重试', icon: 'none' })
135
- }
136
- if (props.side === 'back' && !result.backInfo?.startDate && !result.backInfo?.endDate) {
137
- showToast({ title: '识别失败,请重试', icon: 'none' })
108
+ if (props.hasUploadVo) {
109
+ hideLoading()
110
+ const faceInfo = res.result.faceInfo || {}
111
+ const backInfo = res.result.backInfo || {}
112
+ result = {
113
+ faceInfo: {
114
+ name: allTrim(faceInfo.name || ''),
115
+ certNo: allTrim(faceInfo.num || ''),
116
+ address: allTrim(faceInfo.address || ''),
117
+ },
118
+ backInfo: {
119
+ startDate: backInfo?.startDate || '',
120
+ endDate: backInfo?.endDate || ''
121
+ },
122
+ fileUploadVO: res.result.fileUploadVO || {},
123
+ }
124
+ if (props.side === 'face' && !result.faceInfo.name && !result.faceInfo.certNo) {
125
+ showToast({ title: '识别失败,请重试', icon: 'none' })
126
+ }
127
+ if (props.side === 'back' && !result.backInfo?.startDate && !result.backInfo?.endDate) {
128
+ showToast({ title: '识别失败,请重试', icon: 'none' })
129
+ }
130
+ } else {
131
+ await getOcrInfo(res.result)
138
132
  }
139
133
  } else {
134
+ hideLoading()
140
135
  showToast({
141
136
  title: res.msg,
142
137
  icon: 'error',
@@ -146,9 +141,48 @@ async function onUploadFile(csRes: any) {
146
141
  hideLoading()
147
142
  console.log(err)
148
143
  }
149
- emits('complete', result)
144
+
145
+ props.hasUploadVo && (result?.faceInfo.name || result?.backInfo.startDate) && emits('complete', result)
150
146
  }
151
147
 
148
+ // 根据证件路径获取证件信息
149
+ async function getOcrInfo(file: string | FileType) {
150
+ try {
151
+ const res: any = await $http.get('/hkbase/common/idCard', {
152
+ fileUrl: typeof file === 'string' ? file : file.originalUrl,
153
+ side: props.side,
154
+ })
155
+ hideLoading()
156
+
157
+ if ((props.side === 'face' && !res?.name) || (props.side === 'back' && !res?.startDate)) {
158
+ $n.dialog({
159
+ title: '识别失败',
160
+ message: `您上传的图片可能不够清晰或与当前功能不符,请重新上传一张清晰、完整的图片。谢谢!`,
161
+ okText: '我知道了',
162
+ cancelText: '',
163
+ })
164
+ return
165
+ }
166
+
167
+ emits('complete', {
168
+ faceInfo: {
169
+ name: allTrim(res?.name || ''),
170
+ certNo: allTrim(res?.cardNumber || ''),
171
+ address: allTrim(res?.address || ''),
172
+ },
173
+ backInfo: {
174
+ startDate: res?.expireDate || '',
175
+ endDate: res?.signDate || ''
176
+ },
177
+ fileUploadVO: {
178
+ fileUrl: typeof file === 'string' ? file : file.originalUrl,
179
+ fileKey: typeof file === 'string' ? file : file.fileId,
180
+ },
181
+ })
182
+ } catch (err) {
183
+ hideLoading()
184
+ }
185
+ }
152
186
 
153
187
  // 上传图片操作面板
154
188
  const activeSheetVisible = ref(false)
@@ -190,7 +224,7 @@ async function chooseImages(item: any) {
190
224
  }
191
225
  }
192
226
 
193
- async function onPhotograph() {
227
+ async function onUpload() {
194
228
  if (props.disabled) return
195
229
 
196
230
  if (Taro.getEnv() === 'WEB') {
@@ -206,6 +240,10 @@ async function onPhotograph() {
206
240
 
207
241
  activeSheetVisible.value = true
208
242
  }
243
+
244
+ defineExpose({
245
+ onUpload
246
+ })
209
247
  </script>
210
248
 
211
249
  <style lang="scss">