@uxda/appkit 4.3.11 → 4.3.12

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.
@@ -17,8 +17,8 @@
17
17
  </div>
18
18
  </ns-form>
19
19
  <div class="row buttons">
20
- <ns-button class="cancel-btn" v-track-click="'手机号验证-取消'" @click="emits('cancel')">取消</ns-button>
21
- <ns-button color="primary" v-track-click="'手机号验证-确认'" @click="onOk">确认</ns-button>
20
+ <ns-button class="cancel-btn" v-track-click="'手机号验证-取消'" :r="20" @click="emits('cancel')">取消</ns-button>
21
+ <ns-button color="primary" v-track-click="'手机号验证-确认'" :r="20" @click="onOk">确认</ns-button>
22
22
  </div>
23
23
  </div>
24
24
  </template>
@@ -75,9 +75,9 @@ const props = defineProps<AppVerifyProps>();
75
75
  }
76
76
 
77
77
  .caption {
78
- font-size: 13px !important;
79
- color: #ccc;
80
- line-height: 21px;
78
+ font-size: 14px !important;
79
+ color: #666;
80
+ margin-bottom: 5px;
81
81
  }
82
82
 
83
83
  .number {
@@ -97,11 +97,20 @@ const props = defineProps<AppVerifyProps>();
97
97
  border-radius: 5px;
98
98
  flex: 1;
99
99
  padding-left: 12px;
100
+ .input-text {
101
+ text-align: left !important;
102
+ }
100
103
  }
101
104
 
102
105
  .form-btn {
103
106
  margin-left: 12px;
104
- width: 105px;
107
+ width: 90px;
108
+
109
+ .caption {
110
+ font-size: 10px !important;
111
+ color: #ccc;
112
+ margin-bottom: 0;
113
+ }
105
114
  }
106
115
  }
107
116
 
@@ -0,0 +1,202 @@
1
+ <template>
2
+ <div class="ocr-bank" :class="[disabled ? 'disabled' : '']" 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>
6
+ </div>
7
+
8
+ <nut-action-sheet v-model:visible="activeSheetVisible" :menu-items="actionSheetMenus" @choose="chooseImages"
9
+ cancel-txt="取消" />
10
+ </template>
11
+
12
+ <script lang="ts" setup>
13
+ import Taro, { showToast, showLoading, hideLoading, chooseMedia, chooseMessageFile, uploadFile } from '@tarojs/taro'
14
+ import { NsIcon, useNutshell } from '@uxda/nutshell/taro'
15
+ import { useAppKitOptions } from '../../Appkit'
16
+ import { ref } from 'vue';
17
+ import { useHttp } from '../../balance/api'
18
+ import { compressImage, getCompressQuality } from '../composables/useUpload'
19
+
20
+ const appKitOptions = useAppKitOptions()
21
+ const $http = useHttp(),
22
+ $n = useNutshell()
23
+
24
+ const emits = defineEmits(['complete'])
25
+
26
+ type OcrProps = {
27
+ disabled?: boolean,
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
40
+ }
41
+
42
+ const props = withDefaults(defineProps<OcrProps>(), {
43
+ disabled: false,
44
+ class: '',
45
+ uploadUrl: '/hkbase/file/uploadFile',
46
+ customClick: false
47
+ })
48
+
49
+ type BankCardType = {
50
+ bankCardNumber: string
51
+ bankCardType: string
52
+ bankName: string
53
+ }
54
+
55
+ async function onUploadFile(csRes: any) {
56
+ try {
57
+ let { path, size, tempFilePath } = csRes.tempFiles[0]
58
+ const compressImg: any = (await compressImage(path || tempFilePath, getCompressQuality(size))) || {}
59
+ const filePath = compressImg.tempFilePath || path
60
+
61
+ showLoading({ title: '银行卡识别中..', mask: true })
62
+
63
+ const session = appKitOptions.token()
64
+ const baseUrl = appKitOptions.baseUrl()
65
+ const upRes: any = await uploadFile({
66
+ url: baseUrl + props.uploadUrl,
67
+ filePath,
68
+ name: 'file',
69
+ formData: {
70
+ objectNo: `min${Date.now()}`,
71
+ appCode: appKitOptions.app(),
72
+ },
73
+ header: {
74
+ token: session || '',
75
+ },
76
+ })
77
+
78
+ const res = JSON.parse(upRes.data)
79
+ if (res.code === '200') {
80
+ await getBankCardInfo(res.result)
81
+ } else {
82
+ hideLoading()
83
+ showToast({
84
+ title: res.msg,
85
+ icon: 'error',
86
+ })
87
+ }
88
+ } catch (err) {
89
+ hideLoading()
90
+ console.log(err)
91
+ }
92
+ }
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
+ }
121
+
122
+ // 上传图片操作面板
123
+ const activeSheetVisible = ref(false)
124
+ const actionSheetMenus = [
125
+ {
126
+ name: '拍摄',
127
+ type: 'camera',
128
+ },
129
+ {
130
+ name: '从相册选择',
131
+ type: 'album',
132
+ },
133
+ {
134
+ name: '从聊天会话选择',
135
+ type: 'message',
136
+ },
137
+ ]
138
+ if (Taro.getEnv() === 'WEB') {
139
+ actionSheetMenus.pop()
140
+ }
141
+
142
+ // 选择图像上传
143
+ async function chooseImages(item: any) {
144
+ if (['camera', 'album'].includes(item.type)) {
145
+ const csRes = await chooseMedia({
146
+ count: 1,
147
+ sourceType: [item.type], // "camera" | "album"
148
+ maxDuration: 60, // 使用duration属性判断是图片还是视频,图片没有该属性
149
+ })
150
+
151
+ onUploadFile(csRes)
152
+ } else {
153
+ const csRes = await chooseMessageFile({
154
+ count: 1,
155
+ type: 'image',
156
+ })
157
+
158
+ onUploadFile(csRes)
159
+ }
160
+ }
161
+
162
+ async function onUpload() {
163
+ if (props.disabled) return
164
+
165
+ if (Taro.getEnv() === 'WEB') {
166
+ const csRes = await chooseMedia({
167
+ count: 1,
168
+ sourceType: ['album'], // "camera" | "album"
169
+ maxDuration: 60, // 使用duration属性判断是图片还是视频,图片没有该属性
170
+ })
171
+
172
+ onUploadFile(csRes)
173
+ return
174
+ }
175
+
176
+ activeSheetVisible.value = true
177
+ }
178
+
179
+ defineExpose({
180
+ onUpload
181
+ })
182
+ </script>
183
+
184
+ <style lang="scss">
185
+ .ocr-bank {
186
+ width: 24px;
187
+ height: 24px;
188
+ display: inline-flex;
189
+ align-items: center;
190
+
191
+ .ns-icon {
192
+ width: 24px;
193
+ height: 24px;
194
+ }
195
+
196
+ &.disabled {
197
+ .ns-icon {
198
+ filter: brightness(1.5) grayscale(1);
199
+ }
200
+ }
201
+ }
202
+ </style>
@@ -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,49 +18,29 @@ 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;
24
31
  idCardNo: string;
25
32
  legalPersonName: string;
33
+ [x: string]: any;
26
34
  };
27
35
 
28
- async function taroImgCompress(src: string, quality = 80) {
29
- return new Promise((resolve, reject) => {
30
- Taro.compressImage({
31
- src: src,
32
- quality: quality,
33
- success: (res) => {
34
- resolve(res)
35
- },
36
- fail: (res) => {
37
- reject(res)
38
- },
39
- })
40
- })
41
- }
42
-
43
- function getCompressQuality(size: number) {
44
- let quality = 100;
45
- const curSize = size / (1024 * 1024);
46
- if (curSize > 6) {
47
- quality = quality - ((curSize - 6) / curSize) * 100;
48
- }
49
- return quality;
50
- }
51
-
52
36
  function allTrim(str: string) {
53
37
  return str.replace(/\s+/g, '');
54
38
  }
55
39
 
56
- async function onIconClick() {
40
+ async function onUpload() {
57
41
  if (props.disabled) {
58
42
  return;
59
43
  }
60
- console.log('===onIconClick');
61
44
  let result: OcrResult | null = null;
62
45
  try {
63
46
  const csRes = await chooseMedia({
@@ -65,15 +48,10 @@ async function onIconClick() {
65
48
  sourceType: ['album', 'camera']
66
49
  });
67
50
  let { size, tempFilePath } = csRes.tempFiles[0];
68
- let filePath
69
- if (Taro.getEnv() !== 'WEB') {
70
- const compressImg: any = (await taroImgCompress(tempFilePath, getCompressQuality(size))) || {}
71
- filePath = compressImg.tempFilePath
72
- } else {
73
- filePath = tempFilePath
74
- }
51
+ const compressImg: any = (await compressImage(tempFilePath, getCompressQuality(size))) || {}
52
+ const filePath = compressImg.tempFilePath
75
53
 
76
- showLoading({ title: '营业执照识别中..' });
54
+ showLoading({ title: '营业执照识别中..', mask: true });
77
55
 
78
56
  const session = appKitOptions.token();
79
57
  const baseUrl = appKitOptions.baseUrl();
@@ -83,6 +61,7 @@ async function onIconClick() {
83
61
  name: 'file',
84
62
  formData: {
85
63
  objectNo: `min${Date.now()}`,
64
+ appCode: appKitOptions.app(),
86
65
  },
87
66
  header: {
88
67
  token: session || '',
@@ -116,6 +95,10 @@ async function onIconClick() {
116
95
  }
117
96
  emits('complete', result);
118
97
  }
98
+
99
+ defineExpose({
100
+ onUpload
101
+ })
119
102
  </script>
120
103
 
121
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?.signDate)) {
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">