@uxda/appkit 4.2.24 → 4.2.26
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/.eslintrc.mjs +7 -7
- package/README.md +187 -187
- package/babel.config.js +12 -12
- package/dist/appkit.css +3 -3
- package/dist/index.js +8 -8
- package/package.json +79 -79
- package/project.config.json +15 -15
- package/project.tt.json +13 -13
- package/rollup.config.mjs +67 -67
- package/src/Appkit.ts +66 -66
- package/src/balance/api/endpoints.ts +133 -133
- package/src/balance/api/index.ts +106 -106
- package/src/balance/components/AccountView.vue +760 -760
- package/src/balance/components/BalanceCard.vue +215 -215
- package/src/balance/components/BalanceReminder.vue +85 -85
- package/src/balance/components/ConsumptionFilter.vue +218 -218
- package/src/balance/components/ConsumptionRules.vue +68 -68
- package/src/balance/components/DateFilter.vue +250 -250
- package/src/balance/components/DateRange.vue +80 -80
- package/src/balance/components/ListFilter.vue +62 -62
- package/src/balance/components/ListFilterPicker.vue +191 -191
- package/src/balance/components/PromoterCard.vue +237 -237
- package/src/balance/components/SecondBalance.vue +71 -71
- package/src/balance/components/Tip.vue +45 -45
- package/src/balance/components/index.ts +8 -8
- package/src/balance/types.ts +97 -97
- package/src/components/bt-cropper/index.vue +730 -774
- package/src/components/bt-cropper/utils/calcCropper.js +42 -42
- package/src/components/bt-cropper/utils/calcImagePosition.js +23 -23
- package/src/components/bt-cropper/utils/calcImageSize.js +37 -37
- package/src/components/bt-cropper/utils/calcPointDistance.js +12 -12
- package/src/components/bt-cropper/utils/calcRightAndBottom.js +7 -7
- package/src/components/bt-cropper/utils/ratio.js +3 -3
- package/src/components/bt-cropper/utils/tools.js +25 -25
- package/src/components/dd-area/index.vue +225 -225
- package/src/components/dd-icon/doc.md +21 -21
- package/src/components/dd-icon/index.vue +23 -23
- package/src/components/dd-notice-bar/index.vue +78 -78
- package/src/components/dd-search/doc.md +34 -34
- package/src/components/dd-search/index.vue +168 -168
- package/src/components/dd-selector/index.vue +124 -124
- package/src/components/dd-skeleton/doc.md +19 -19
- package/src/components/dd-skeleton/index.vue +36 -36
- package/src/global.ts +6 -6
- package/src/index.ts +89 -89
- package/src/main.scss +1 -1
- package/src/notice/api/endpoints.ts +17 -17
- package/src/notice/api/index.ts +106 -106
- package/src/notice/components/NoticeBanner.vue +243 -243
- package/src/notice/components/NoticeEntry.vue +99 -99
- package/src/notice/components/NoticeList.vue +315 -315
- package/src/notice/components/NoticePopup.vue +162 -162
- package/src/notice/components/index.ts +5 -5
- package/src/notice/components/useCommonList.ts +86 -86
- package/src/notice/components/useNotice.ts +35 -35
- package/src/notice/index.ts +1 -1
- package/src/notice/types.ts +25 -25
- package/src/payment/api/config.ts +7 -7
- package/src/payment/api/endpoints.ts +103 -103
- package/src/payment/api/index.ts +100 -100
- package/src/payment/components/AmountPicker.vue +90 -90
- package/src/payment/components/RechargeResult.vue +69 -69
- package/src/payment/components/RechargeView.vue +155 -155
- package/src/payment/components/RightsPicker.vue +105 -105
- package/src/payment/components/TradeView.vue +317 -317
- package/src/payment/components/UserAgreement.vue +234 -234
- package/src/payment/components/index.ts +22 -22
- package/src/payment/index.ts +5 -5
- package/src/payment/services/index.ts +16 -16
- package/src/payment/services/invoke-recharge.ts +25 -25
- package/src/payment/services/request-payment.ts +58 -58
- package/src/payment/types.ts +28 -28
- package/src/register/components/SelfRegistration.vue +233 -233
- package/src/register/components/index.ts +2 -2
- package/src/shared/components/AppDrawer.vue +54 -54
- package/src/shared/components/AppVerify.vue +128 -128
- package/src/shared/components/DeviceVersion.vue +63 -68
- package/src/shared/components/EmptyView.vue +33 -33
- package/src/shared/components/OcrBusinessLicense.vue +130 -130
- package/src/shared/components/OcrIcon.vue +202 -202
- package/src/shared/components/PageHeader.vue +84 -84
- package/src/shared/components/index.ts +8 -8
- package/src/shared/composables/index.ts +8 -8
- package/src/shared/composables/useAmount.ts +46 -46
- package/src/shared/composables/useCountdown.ts +46 -46
- package/src/shared/composables/useCrypto.ts +76 -76
- package/src/shared/composables/useDragBox.ts +97 -97
- package/src/shared/composables/useEncode.ts +43 -43
- package/src/shared/composables/useLogger.ts +124 -124
- package/src/shared/composables/useSafeArea.ts +46 -46
- package/src/shared/composables/useTabbar.ts +24 -24
- package/src/shared/composables/useUpload.ts +54 -54
- package/src/shared/composables/useValidator.ts +32 -32
- package/src/shared/http/Http.ts +136 -136
- package/src/shared/http/index.ts +1 -1
- package/src/shared/http/types.ts +157 -157
- package/src/shared/index.ts +3 -3
- package/src/shared/weixin/payment.ts +38 -38
- package/src/styles/vars.scss +3 -3
- package/src/user/api/endpoints.ts +17 -17
- package/src/user/api/index.ts +111 -111
- package/src/user/components/LoginSetting.vue +114 -114
- package/src/user/components/UserAuth.vue +257 -257
- package/src/user/components/UserBinding.vue +307 -307
- package/src/user/components/UserBindingSuccess.vue +80 -80
- package/src/user/components/UserEntry.vue +133 -133
- package/src/user/components/UserFeedback.vue +431 -431
- package/src/user/components/UserFeedbackEntry.vue +175 -192
- package/src/user/components/UserHeadCrop.vue +65 -65
- package/src/user/components/UserInfo.vue +826 -826
- package/src/user/components/UserResourceEmpty.vue +75 -75
- package/src/user/components/index.ts +23 -23
- package/src/user/index.ts +1 -1
- package/tsconfig.json +30 -30
- package/types/global.d.ts +21 -21
- package/types/vue.d.ts +10 -10
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div :class="['ocr-business-license', disabled ? 'disabled' : '']" class="ocr-icon" @click="onIconClick">
|
|
3
|
-
<ns-icon name="https://cdn.ddjf.com/static/images/beidouxing/ocr-icon.png" />
|
|
4
|
-
</div>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script lang="ts" setup>
|
|
8
|
-
import Taro from '@tarojs/taro';
|
|
9
|
-
import { NsIcon } from '@uxda/nutshell/taro';
|
|
10
|
-
import { useAppKitOptions } from '../../Appkit';
|
|
11
|
-
|
|
12
|
-
const appKitOptions = useAppKitOptions();
|
|
13
|
-
|
|
14
|
-
const emits = defineEmits(['complete']);
|
|
15
|
-
|
|
16
|
-
type OcrBusinessLicenseProps = {
|
|
17
|
-
disabled: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const props = defineProps<OcrBusinessLicenseProps>();
|
|
21
|
-
|
|
22
|
-
export type OcrResult = {
|
|
23
|
-
companyName: string;
|
|
24
|
-
idCardNo: string;
|
|
25
|
-
legalPersonName: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
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
|
-
function allTrim(str: string) {
|
|
53
|
-
return str.replace(/\s+/g, '');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function onIconClick() {
|
|
57
|
-
if (props.disabled) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
console.log('===onIconClick');
|
|
61
|
-
let result: OcrResult | null = null;
|
|
62
|
-
try {
|
|
63
|
-
const csRes = await Taro.chooseImage({
|
|
64
|
-
count: 1,
|
|
65
|
-
});
|
|
66
|
-
let { path, size } = csRes.tempFiles[0];
|
|
67
|
-
const compressImg: any =
|
|
68
|
-
(await taroImgCompress(path, getCompressQuality(size))) || {};
|
|
69
|
-
const filePath = compressImg.tempFilePath || path;
|
|
70
|
-
Taro.showLoading({ title: '营业执照识别中..' });
|
|
71
|
-
const session = appKitOptions.token();
|
|
72
|
-
const baseUrl = appKitOptions.baseUrl();
|
|
73
|
-
const upRes: any = await Taro.uploadFile({
|
|
74
|
-
url: baseUrl + '/promoact/common/parseBusinessLicense',
|
|
75
|
-
filePath,
|
|
76
|
-
name: 'file',
|
|
77
|
-
formData: {
|
|
78
|
-
objectNo: `min${Date.now()}`,
|
|
79
|
-
},
|
|
80
|
-
header: {
|
|
81
|
-
token: session || '',
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
Taro.hideLoading();
|
|
85
|
-
const res = JSON.parse(upRes.data);
|
|
86
|
-
if (res.code === '200') {
|
|
87
|
-
const faceInfo = res.result || {};
|
|
88
|
-
result = {
|
|
89
|
-
companyName: allTrim(faceInfo.companyName || ''),
|
|
90
|
-
idCardNo: allTrim(faceInfo.idCardNo || ''),
|
|
91
|
-
legalPersonName: allTrim(faceInfo.legalPersonName || ''),
|
|
92
|
-
fileId: faceInfo.fileId,
|
|
93
|
-
originalUrl: faceInfo.originalUrl,
|
|
94
|
-
downloadUrl: faceInfo.downloadUrl,
|
|
95
|
-
};
|
|
96
|
-
console.log('===识别', result);
|
|
97
|
-
if (!result.companyName && !result.idCardNo) {
|
|
98
|
-
Taro.showToast({ title: '识别失败,请重试', icon: 'none' });
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
Taro.showToast({
|
|
102
|
-
title: res.msg,
|
|
103
|
-
icon: 'error',
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
} catch (err) {
|
|
107
|
-
Taro.hideLoading();
|
|
108
|
-
console.log(err);
|
|
109
|
-
}
|
|
110
|
-
emits('complete', result);
|
|
111
|
-
}
|
|
112
|
-
</script>
|
|
113
|
-
|
|
114
|
-
<style lang="scss">
|
|
115
|
-
.ocr-business-license {
|
|
116
|
-
width: 24px;
|
|
117
|
-
height: 24px;
|
|
118
|
-
|
|
119
|
-
.ns-icon {
|
|
120
|
-
width: 24px;
|
|
121
|
-
height: 24px;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
&.disabled {
|
|
125
|
-
.ns-icon {
|
|
126
|
-
filter: brightness(1.5) grayscale(1);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="['ocr-business-license', disabled ? 'disabled' : '']" class="ocr-icon" @click="onIconClick">
|
|
3
|
+
<ns-icon name="https://cdn.ddjf.com/static/images/beidouxing/ocr-icon.png" />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts" setup>
|
|
8
|
+
import Taro from '@tarojs/taro';
|
|
9
|
+
import { NsIcon } from '@uxda/nutshell/taro';
|
|
10
|
+
import { useAppKitOptions } from '../../Appkit';
|
|
11
|
+
|
|
12
|
+
const appKitOptions = useAppKitOptions();
|
|
13
|
+
|
|
14
|
+
const emits = defineEmits(['complete']);
|
|
15
|
+
|
|
16
|
+
type OcrBusinessLicenseProps = {
|
|
17
|
+
disabled: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const props = defineProps<OcrBusinessLicenseProps>();
|
|
21
|
+
|
|
22
|
+
export type OcrResult = {
|
|
23
|
+
companyName: string;
|
|
24
|
+
idCardNo: string;
|
|
25
|
+
legalPersonName: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
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
|
+
function allTrim(str: string) {
|
|
53
|
+
return str.replace(/\s+/g, '');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function onIconClick() {
|
|
57
|
+
if (props.disabled) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
console.log('===onIconClick');
|
|
61
|
+
let result: OcrResult | null = null;
|
|
62
|
+
try {
|
|
63
|
+
const csRes = await Taro.chooseImage({
|
|
64
|
+
count: 1,
|
|
65
|
+
});
|
|
66
|
+
let { path, size } = csRes.tempFiles[0];
|
|
67
|
+
const compressImg: any =
|
|
68
|
+
(await taroImgCompress(path, getCompressQuality(size))) || {};
|
|
69
|
+
const filePath = compressImg.tempFilePath || path;
|
|
70
|
+
Taro.showLoading({ title: '营业执照识别中..' });
|
|
71
|
+
const session = appKitOptions.token();
|
|
72
|
+
const baseUrl = appKitOptions.baseUrl();
|
|
73
|
+
const upRes: any = await Taro.uploadFile({
|
|
74
|
+
url: baseUrl + '/promoact/common/parseBusinessLicense',
|
|
75
|
+
filePath,
|
|
76
|
+
name: 'file',
|
|
77
|
+
formData: {
|
|
78
|
+
objectNo: `min${Date.now()}`,
|
|
79
|
+
},
|
|
80
|
+
header: {
|
|
81
|
+
token: session || '',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
Taro.hideLoading();
|
|
85
|
+
const res = JSON.parse(upRes.data);
|
|
86
|
+
if (res.code === '200') {
|
|
87
|
+
const faceInfo = res.result || {};
|
|
88
|
+
result = {
|
|
89
|
+
companyName: allTrim(faceInfo.companyName || ''),
|
|
90
|
+
idCardNo: allTrim(faceInfo.idCardNo || ''),
|
|
91
|
+
legalPersonName: allTrim(faceInfo.legalPersonName || ''),
|
|
92
|
+
fileId: faceInfo.fileId,
|
|
93
|
+
originalUrl: faceInfo.originalUrl,
|
|
94
|
+
downloadUrl: faceInfo.downloadUrl,
|
|
95
|
+
};
|
|
96
|
+
console.log('===识别', result);
|
|
97
|
+
if (!result.companyName && !result.idCardNo) {
|
|
98
|
+
Taro.showToast({ title: '识别失败,请重试', icon: 'none' });
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
Taro.showToast({
|
|
102
|
+
title: res.msg,
|
|
103
|
+
icon: 'error',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
Taro.hideLoading();
|
|
108
|
+
console.log(err);
|
|
109
|
+
}
|
|
110
|
+
emits('complete', result);
|
|
111
|
+
}
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<style lang="scss">
|
|
115
|
+
.ocr-business-license {
|
|
116
|
+
width: 24px;
|
|
117
|
+
height: 24px;
|
|
118
|
+
|
|
119
|
+
.ns-icon {
|
|
120
|
+
width: 24px;
|
|
121
|
+
height: 24px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
&.disabled {
|
|
125
|
+
.ns-icon {
|
|
126
|
+
filter: brightness(1.5) grayscale(1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
</style>
|
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="ocr-icon" :class="[disabled ? 'disabled' : '']" @click="onPhotograph">
|
|
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 from '@tarojs/taro'
|
|
14
|
-
import { NsIcon } from '@uxda/nutshell/taro'
|
|
15
|
-
import { useAppKitOptions } from '../../Appkit'
|
|
16
|
-
import { ref } from 'vue';
|
|
17
|
-
|
|
18
|
-
const appKitOptions = useAppKitOptions()
|
|
19
|
-
|
|
20
|
-
const emits = defineEmits(['complete'])
|
|
21
|
-
|
|
22
|
-
type OcrIconProps = {
|
|
23
|
-
disabled?: boolean,
|
|
24
|
-
side?: 'face' | 'back',
|
|
25
|
-
class?: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const props = withDefaults(defineProps<OcrIconProps>(), {
|
|
29
|
-
disabled: false,
|
|
30
|
-
side: 'face',
|
|
31
|
-
class: ''
|
|
32
|
-
})
|
|
33
|
-
|
|
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
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
Taro.compressImage({
|
|
55
|
-
src: src,
|
|
56
|
-
quality: quality,
|
|
57
|
-
success: (res) => {
|
|
58
|
-
resolve(res)
|
|
59
|
-
},
|
|
60
|
-
fail: (res) => {
|
|
61
|
-
reject(res)
|
|
62
|
-
},
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function getCompressQuality(size: number) {
|
|
68
|
-
let quality = 100
|
|
69
|
-
const curSize = size / (1024 * 1024)
|
|
70
|
-
if (curSize > 6) {
|
|
71
|
-
quality = quality - ((curSize - 6) / curSize) * 100
|
|
72
|
-
}
|
|
73
|
-
return quality
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function allTrim(str: string) {
|
|
77
|
-
return str.replace(/\s+/g, '')
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function onUploadFile(csRes: any) {
|
|
81
|
-
let result: OcrResultType | null = null
|
|
82
|
-
try {
|
|
83
|
-
let { path, size, tempFilePath } = csRes.tempFiles[0]
|
|
84
|
-
const compressImg: any = (await taroImgCompress(path || tempFilePath, getCompressQuality(size))) || {}
|
|
85
|
-
const filePath = compressImg.tempFilePath || path
|
|
86
|
-
Taro.showLoading({ title: '身份证识别中..' })
|
|
87
|
-
|
|
88
|
-
const session = appKitOptions.token()
|
|
89
|
-
const baseUrl = appKitOptions.baseUrl()
|
|
90
|
-
const upRes: any = await Taro.uploadFile({
|
|
91
|
-
url: baseUrl + '/hkapprove/ocr/idcard',
|
|
92
|
-
filePath,
|
|
93
|
-
name: 'file',
|
|
94
|
-
formData: {
|
|
95
|
-
objectNo: `min${Date.now()}`,
|
|
96
|
-
side: props.side,
|
|
97
|
-
},
|
|
98
|
-
header: {
|
|
99
|
-
token: session || '',
|
|
100
|
-
},
|
|
101
|
-
})
|
|
102
|
-
Taro.hideLoading()
|
|
103
|
-
|
|
104
|
-
const res = JSON.parse(upRes.data)
|
|
105
|
-
if (res.code === '200') {
|
|
106
|
-
const faceInfo = res.result.faceInfo || {}
|
|
107
|
-
const backInfo = res.result.backInfo || {}
|
|
108
|
-
result = {
|
|
109
|
-
faceInfo: {
|
|
110
|
-
name: allTrim(faceInfo.name || ''),
|
|
111
|
-
certNo: allTrim(faceInfo.num || ''),
|
|
112
|
-
address: allTrim(faceInfo.address || ''),
|
|
113
|
-
},
|
|
114
|
-
backInfo: {
|
|
115
|
-
startDate: backInfo?.startDate || '',
|
|
116
|
-
endDate: backInfo?.endDate || ''
|
|
117
|
-
},
|
|
118
|
-
fileUploadVO: res.result.fileUploadVO || {},
|
|
119
|
-
}
|
|
120
|
-
console.log('===识别', result)
|
|
121
|
-
if (props.side === 'face' && !result.faceInfo.name && !result.faceInfo.certNo) {
|
|
122
|
-
Taro.showToast({ title: '识别失败,请重试', icon: 'none' })
|
|
123
|
-
}
|
|
124
|
-
if (props.side === 'back' && !result.backInfo?.startDate && !result.backInfo?.endDate) {
|
|
125
|
-
Taro.showToast({ title: '识别失败,请重试', icon: 'none' })
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
Taro.showToast({
|
|
129
|
-
title: res.msg,
|
|
130
|
-
icon: 'error',
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
} catch (err) {
|
|
134
|
-
Taro.hideLoading()
|
|
135
|
-
console.log(err)
|
|
136
|
-
}
|
|
137
|
-
emits('complete', result)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// 上传图片操作面板
|
|
142
|
-
const activeSheetVisible = ref(false)
|
|
143
|
-
const actionSheetMenus = [
|
|
144
|
-
{
|
|
145
|
-
name: '拍摄',
|
|
146
|
-
type: 'camera',
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
name: '从相册选择',
|
|
150
|
-
type: 'album',
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
name: '从聊天会话选择',
|
|
154
|
-
type: 'message',
|
|
155
|
-
},
|
|
156
|
-
]
|
|
157
|
-
// 选择图像上传
|
|
158
|
-
async function chooseImages(item: any) {
|
|
159
|
-
if (['camera', 'album'].includes(item.type)) {
|
|
160
|
-
const csRes = await Taro.chooseMedia({
|
|
161
|
-
count: 1,
|
|
162
|
-
sourceType: [item.type], // "camera" | "album"
|
|
163
|
-
maxDuration: 60, // 使用duration属性判断是图片还是视频,图片没有该属性
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
onUploadFile(csRes)
|
|
167
|
-
} else {
|
|
168
|
-
const csRes = await Taro.chooseMessageFile({
|
|
169
|
-
count: 1,
|
|
170
|
-
type: 'image',
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
onUploadFile(csRes)
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function onPhotograph() {
|
|
178
|
-
if (props.disabled) return
|
|
179
|
-
|
|
180
|
-
activeSheetVisible.value = true
|
|
181
|
-
}
|
|
182
|
-
</script>
|
|
183
|
-
|
|
184
|
-
<style lang="scss">
|
|
185
|
-
.ocr-icon {
|
|
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
|
+
<template>
|
|
2
|
+
<div class="ocr-icon" :class="[disabled ? 'disabled' : '']" @click="onPhotograph">
|
|
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 from '@tarojs/taro'
|
|
14
|
+
import { NsIcon } from '@uxda/nutshell/taro'
|
|
15
|
+
import { useAppKitOptions } from '../../Appkit'
|
|
16
|
+
import { ref } from 'vue';
|
|
17
|
+
|
|
18
|
+
const appKitOptions = useAppKitOptions()
|
|
19
|
+
|
|
20
|
+
const emits = defineEmits(['complete'])
|
|
21
|
+
|
|
22
|
+
type OcrIconProps = {
|
|
23
|
+
disabled?: boolean,
|
|
24
|
+
side?: 'face' | 'back',
|
|
25
|
+
class?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const props = withDefaults(defineProps<OcrIconProps>(), {
|
|
29
|
+
disabled: false,
|
|
30
|
+
side: 'face',
|
|
31
|
+
class: ''
|
|
32
|
+
})
|
|
33
|
+
|
|
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
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
Taro.compressImage({
|
|
55
|
+
src: src,
|
|
56
|
+
quality: quality,
|
|
57
|
+
success: (res) => {
|
|
58
|
+
resolve(res)
|
|
59
|
+
},
|
|
60
|
+
fail: (res) => {
|
|
61
|
+
reject(res)
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getCompressQuality(size: number) {
|
|
68
|
+
let quality = 100
|
|
69
|
+
const curSize = size / (1024 * 1024)
|
|
70
|
+
if (curSize > 6) {
|
|
71
|
+
quality = quality - ((curSize - 6) / curSize) * 100
|
|
72
|
+
}
|
|
73
|
+
return quality
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function allTrim(str: string) {
|
|
77
|
+
return str.replace(/\s+/g, '')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function onUploadFile(csRes: any) {
|
|
81
|
+
let result: OcrResultType | null = null
|
|
82
|
+
try {
|
|
83
|
+
let { path, size, tempFilePath } = csRes.tempFiles[0]
|
|
84
|
+
const compressImg: any = (await taroImgCompress(path || tempFilePath, getCompressQuality(size))) || {}
|
|
85
|
+
const filePath = compressImg.tempFilePath || path
|
|
86
|
+
Taro.showLoading({ title: '身份证识别中..' })
|
|
87
|
+
|
|
88
|
+
const session = appKitOptions.token()
|
|
89
|
+
const baseUrl = appKitOptions.baseUrl()
|
|
90
|
+
const upRes: any = await Taro.uploadFile({
|
|
91
|
+
url: baseUrl + '/hkapprove/ocr/idcard',
|
|
92
|
+
filePath,
|
|
93
|
+
name: 'file',
|
|
94
|
+
formData: {
|
|
95
|
+
objectNo: `min${Date.now()}`,
|
|
96
|
+
side: props.side,
|
|
97
|
+
},
|
|
98
|
+
header: {
|
|
99
|
+
token: session || '',
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
Taro.hideLoading()
|
|
103
|
+
|
|
104
|
+
const res = JSON.parse(upRes.data)
|
|
105
|
+
if (res.code === '200') {
|
|
106
|
+
const faceInfo = res.result.faceInfo || {}
|
|
107
|
+
const backInfo = res.result.backInfo || {}
|
|
108
|
+
result = {
|
|
109
|
+
faceInfo: {
|
|
110
|
+
name: allTrim(faceInfo.name || ''),
|
|
111
|
+
certNo: allTrim(faceInfo.num || ''),
|
|
112
|
+
address: allTrim(faceInfo.address || ''),
|
|
113
|
+
},
|
|
114
|
+
backInfo: {
|
|
115
|
+
startDate: backInfo?.startDate || '',
|
|
116
|
+
endDate: backInfo?.endDate || ''
|
|
117
|
+
},
|
|
118
|
+
fileUploadVO: res.result.fileUploadVO || {},
|
|
119
|
+
}
|
|
120
|
+
console.log('===识别', result)
|
|
121
|
+
if (props.side === 'face' && !result.faceInfo.name && !result.faceInfo.certNo) {
|
|
122
|
+
Taro.showToast({ title: '识别失败,请重试', icon: 'none' })
|
|
123
|
+
}
|
|
124
|
+
if (props.side === 'back' && !result.backInfo?.startDate && !result.backInfo?.endDate) {
|
|
125
|
+
Taro.showToast({ title: '识别失败,请重试', icon: 'none' })
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
Taro.showToast({
|
|
129
|
+
title: res.msg,
|
|
130
|
+
icon: 'error',
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
} catch (err) {
|
|
134
|
+
Taro.hideLoading()
|
|
135
|
+
console.log(err)
|
|
136
|
+
}
|
|
137
|
+
emits('complete', result)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
// 上传图片操作面板
|
|
142
|
+
const activeSheetVisible = ref(false)
|
|
143
|
+
const actionSheetMenus = [
|
|
144
|
+
{
|
|
145
|
+
name: '拍摄',
|
|
146
|
+
type: 'camera',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: '从相册选择',
|
|
150
|
+
type: 'album',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: '从聊天会话选择',
|
|
154
|
+
type: 'message',
|
|
155
|
+
},
|
|
156
|
+
]
|
|
157
|
+
// 选择图像上传
|
|
158
|
+
async function chooseImages(item: any) {
|
|
159
|
+
if (['camera', 'album'].includes(item.type)) {
|
|
160
|
+
const csRes = await Taro.chooseMedia({
|
|
161
|
+
count: 1,
|
|
162
|
+
sourceType: [item.type], // "camera" | "album"
|
|
163
|
+
maxDuration: 60, // 使用duration属性判断是图片还是视频,图片没有该属性
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
onUploadFile(csRes)
|
|
167
|
+
} else {
|
|
168
|
+
const csRes = await Taro.chooseMessageFile({
|
|
169
|
+
count: 1,
|
|
170
|
+
type: 'image',
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
onUploadFile(csRes)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function onPhotograph() {
|
|
178
|
+
if (props.disabled) return
|
|
179
|
+
|
|
180
|
+
activeSheetVisible.value = true
|
|
181
|
+
}
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<style lang="scss">
|
|
185
|
+
.ocr-icon {
|
|
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>
|