@uxda/appkit 4.1.24 → 4.1.25

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.
Files changed (116) hide show
  1. package/.eslintrc.mjs +7 -7
  2. package/README.md +187 -187
  3. package/babel.config.js +12 -12
  4. package/dist/appkit.css +21 -24
  5. package/dist/assets/asset-3B_CoPto +1 -0
  6. package/dist/index.js +1117 -1055
  7. package/package.json +75 -77
  8. package/project.config.json +15 -15
  9. package/project.tt.json +13 -13
  10. package/rollup.config.mjs +56 -56
  11. package/src/Appkit.ts +66 -72
  12. package/src/balance/api/endpoints.ts +126 -126
  13. package/src/balance/api/index.ts +82 -82
  14. package/src/balance/components/AccountView.vue +748 -748
  15. package/src/balance/components/BalanceCard.vue +205 -205
  16. package/src/balance/components/BalanceReminder.vue +85 -85
  17. package/src/balance/components/ConsumptionFilter.vue +218 -218
  18. package/src/balance/components/ConsumptionRules.vue +68 -68
  19. package/src/balance/components/DateFilter.vue +230 -249
  20. package/src/balance/components/DateRange.vue +75 -80
  21. package/src/balance/components/ListFilter.vue +63 -63
  22. package/src/balance/components/ListFilterPicker.vue +186 -186
  23. package/src/balance/components/SecondBalance.vue +71 -71
  24. package/src/balance/components/Tip.vue +45 -45
  25. package/src/balance/components/index.ts +13 -13
  26. package/src/balance/types.ts +91 -91
  27. package/src/components/bt-cropper/index.vue +774 -774
  28. package/src/components/bt-cropper/utils/calcCropper.js +42 -42
  29. package/src/components/bt-cropper/utils/calcImagePosition.js +23 -23
  30. package/src/components/bt-cropper/utils/calcImageSize.js +37 -37
  31. package/src/components/bt-cropper/utils/calcPointDistance.js +12 -12
  32. package/src/components/bt-cropper/utils/calcRightAndBottom.js +7 -7
  33. package/src/components/bt-cropper/utils/ratio.js +3 -3
  34. package/src/components/bt-cropper/utils/tools.js +25 -25
  35. package/src/components/dd-area/index.vue +225 -225
  36. package/src/components/dd-icon/doc.md +21 -21
  37. package/src/components/dd-icon/index.vue +23 -23
  38. package/src/components/dd-notice-bar/index.vue +78 -78
  39. package/src/components/dd-search/doc.md +34 -34
  40. package/src/components/dd-search/index.vue +168 -168
  41. package/src/components/dd-selector/index.vue +124 -124
  42. package/src/components/dd-skeleton/doc.md +19 -19
  43. package/src/components/dd-skeleton/index.vue +36 -36
  44. package/src/components/ocr-id/index.vue +114 -114
  45. package/src/components/ocr-id/types.d.ts +12 -12
  46. package/src/global.ts +6 -6
  47. package/src/index.ts +89 -93
  48. package/src/main.scss +1 -1
  49. package/src/notice/api/endpoints.ts +17 -17
  50. package/src/notice/api/index.ts +82 -82
  51. package/src/notice/components/NoticeBanner.vue +243 -243
  52. package/src/notice/components/NoticeEntry.vue +99 -99
  53. package/src/notice/components/NoticeList.vue +315 -315
  54. package/src/notice/components/NoticePopup.vue +162 -162
  55. package/src/notice/components/index.ts +5 -5
  56. package/src/notice/components/useCommonList.ts +86 -86
  57. package/src/notice/components/useNotice.ts +35 -35
  58. package/src/notice/index.ts +1 -1
  59. package/src/notice/types.ts +25 -25
  60. package/src/payment/api/config.ts +7 -7
  61. package/src/payment/api/endpoints.ts +103 -103
  62. package/src/payment/api/index.ts +76 -71
  63. package/src/payment/components/AmountPicker.vue +93 -93
  64. package/src/payment/components/RechargeResult.vue +69 -69
  65. package/src/payment/components/RechargeView.vue +154 -151
  66. package/src/payment/components/RightsPicker.vue +105 -105
  67. package/src/payment/components/TradeView.vue +294 -294
  68. package/src/payment/components/UserAgreement.vue +234 -234
  69. package/src/payment/components/index.ts +22 -22
  70. package/src/payment/index.ts +5 -5
  71. package/src/payment/services/index.ts +16 -16
  72. package/src/payment/services/invoke-recharge.ts +25 -25
  73. package/src/payment/services/request-payment.ts +58 -58
  74. package/src/payment/types.ts +28 -28
  75. package/src/register/components/SelfRegistration.vue +254 -254
  76. package/src/register/components/index.ts +2 -2
  77. package/src/shared/components/AppDrawer.vue +58 -58
  78. package/src/shared/components/AppVerify.vue +129 -129
  79. package/src/shared/components/DeviceVersion.vue +68 -68
  80. package/src/shared/components/EmptyView.vue +33 -33
  81. package/src/shared/components/OcrBusinessLicense.vue +133 -133
  82. package/src/shared/components/OcrIcon.vue +133 -133
  83. package/src/shared/components/PageHeader.vue +79 -79
  84. package/src/shared/components/index.ts +8 -8
  85. package/src/shared/composables/index.ts +7 -7
  86. package/src/shared/composables/useCountdown.ts +46 -46
  87. package/src/shared/composables/useCrypto.ts +76 -76
  88. package/src/shared/composables/useDragBox.ts +97 -97
  89. package/src/shared/composables/useEncode.ts +43 -43
  90. package/src/shared/composables/useSafeArea.ts +46 -46
  91. package/src/shared/composables/useTabbar.ts +24 -24
  92. package/src/shared/composables/useUpload.ts +54 -54
  93. package/src/shared/composables/useValidator.ts +31 -31
  94. package/src/shared/http/Http.ts +136 -136
  95. package/src/shared/http/index.ts +1 -1
  96. package/src/shared/http/types.ts +157 -157
  97. package/src/shared/index.ts +3 -3
  98. package/src/shared/weixin/payment.ts +38 -38
  99. package/src/styles/fonts.scss +2 -2
  100. package/src/styles/vars.scss +3 -3
  101. package/src/user/api/endpoints.ts +17 -17
  102. package/src/user/api/index.ts +87 -87
  103. package/src/user/components/LoginSetting.vue +114 -114
  104. package/src/user/components/UserBinding.vue +307 -307
  105. package/src/user/components/UserBindingSuccess.vue +80 -80
  106. package/src/user/components/UserEntry.vue +137 -137
  107. package/src/user/components/UserFeedback.vue +431 -431
  108. package/src/user/components/UserFeedbackEntry.vue +192 -192
  109. package/src/user/components/UserHeadCrop.vue +65 -65
  110. package/src/user/components/UserInfo.vue +637 -637
  111. package/src/user/components/UserResourceEmpty.vue +75 -75
  112. package/src/user/components/index.ts +21 -21
  113. package/src/user/index.ts +1 -1
  114. package/tsconfig.json +30 -30
  115. package/types/global.d.ts +21 -21
  116. package/types/vue.d.ts +10 -10
@@ -1,124 +1,124 @@
1
- <!--* NAME: index-->
2
- <!--* AUTHOR: yanglong-->
3
- <!--* UPDATE: 2022-02-23 09:33-->
4
- <!--* TIP: 微信原生实现单列选择器-->
5
- <script setup lang="ts">
6
- import { computed, ref, watch } from 'vue'
7
- import DdIcon from '../dd-icon/index.vue'
8
-
9
- interface Option {
10
- label?: string
11
- value?: string
12
- }
13
- interface PropsType {
14
- value?: string
15
- options?: Option[]
16
- placeholder?: string
17
- rightIcon?: boolean
18
- disabled?: boolean
19
- }
20
-
21
- const props = withDefaults(defineProps<PropsType>(), {
22
- value: '',
23
- options: () => [],
24
- placeholder: '请选择',
25
- rightIcon: true,
26
- disabled: false,
27
- })
28
-
29
- const currentIndex = ref<number>()
30
- const currentLabel = ref<string>()
31
-
32
- const emit = defineEmits(['update:value', 'change', 'cancel'])
33
- function onChange(e) {
34
- const index = e.detail.value as number
35
- const item = props.options[index]
36
- if (item === void 0) return
37
- currentIndex.value = index
38
- currentLabel.value = item.label
39
- emit('update:value', item.value)
40
- emit('change', item)
41
- }
42
-
43
- // 通过value查询item index
44
- function findIndexByValue(value: string) {
45
- if (value == undefined) return undefined
46
- const index = props.options.findIndex((item: Option) => item.value == value)
47
- return index >= 0 ? index : undefined
48
- }
49
-
50
- function onCancel(e) {
51
- emit('cancel', e)
52
- }
53
-
54
- watch(
55
- () => props,
56
- () => {
57
- init()
58
- },
59
- {
60
- deep: true,
61
- immediate: true,
62
- }
63
- )
64
-
65
- function init() {
66
- currentIndex.value = findIndexByValue(props.value)
67
- currentLabel.value =
68
- currentIndex.value >= 0 ? (props.options[currentIndex.value] || {}).label : ''
69
- }
70
- </script>
71
-
72
- <template>
73
- <picker
74
- mode="selector"
75
- :range="props.options"
76
- range-key="label"
77
- :value="currentIndex"
78
- @cancel="onCancel"
79
- @change="onChange"
80
- style="flex: 1"
81
- :disabled="props.disabled"
82
- >
83
- <slot name="content">
84
- <div class="dd-selector">
85
- <div class="dd-selector-value">
86
- <div
87
- :class="
88
- currentIndex >= 0 && !props.disabled ? 'dd-selector-value' : 'dd-selector-label'
89
- "
90
- >
91
- {{ currentLabel || props.placeholder }}
92
- </div>
93
- <div>
94
- <slot name="tips"></slot>
95
- </div>
96
- </div>
97
- <slot name="icon">
98
- <DdIcon
99
- v-if="props.rightIcon"
100
- name="icon-arrow"
101
- size="11px"
102
- :color="currentIndex >= 0 && !props.disabled ? '#353535' : '#DFDFDF'"
103
- class="icon-arrow"
104
- />
105
- </slot>
106
- </div>
107
- </slot>
108
- </picker>
109
- </template>
110
-
111
- <style lang="scss">
112
- .dd-selector {
113
- display: flex;
114
- justify-content: flex-end;
115
- align-items: center;
116
- &-value {
117
- text-align: right;
118
- color: black;
119
- }
120
- &-label {
121
- color: var(--placeholder-color);
122
- }
123
- }
124
- </style>
1
+ <!--* NAME: index-->
2
+ <!--* AUTHOR: yanglong-->
3
+ <!--* UPDATE: 2022-02-23 09:33-->
4
+ <!--* TIP: 微信原生实现单列选择器-->
5
+ <script setup lang="ts">
6
+ import { computed, ref, watch } from 'vue'
7
+ import DdIcon from '../dd-icon/index.vue'
8
+
9
+ interface Option {
10
+ label?: string
11
+ value?: string
12
+ }
13
+ interface PropsType {
14
+ value?: string
15
+ options?: Option[]
16
+ placeholder?: string
17
+ rightIcon?: boolean
18
+ disabled?: boolean
19
+ }
20
+
21
+ const props = withDefaults(defineProps<PropsType>(), {
22
+ value: '',
23
+ options: () => [],
24
+ placeholder: '请选择',
25
+ rightIcon: true,
26
+ disabled: false,
27
+ })
28
+
29
+ const currentIndex = ref<number>()
30
+ const currentLabel = ref<string>()
31
+
32
+ const emit = defineEmits(['update:value', 'change', 'cancel'])
33
+ function onChange(e) {
34
+ const index = e.detail.value as number
35
+ const item = props.options[index]
36
+ if (item === void 0) return
37
+ currentIndex.value = index
38
+ currentLabel.value = item.label
39
+ emit('update:value', item.value)
40
+ emit('change', item)
41
+ }
42
+
43
+ // 通过value查询item index
44
+ function findIndexByValue(value: string) {
45
+ if (value == undefined) return undefined
46
+ const index = props.options.findIndex((item: Option) => item.value == value)
47
+ return index >= 0 ? index : undefined
48
+ }
49
+
50
+ function onCancel(e) {
51
+ emit('cancel', e)
52
+ }
53
+
54
+ watch(
55
+ () => props,
56
+ () => {
57
+ init()
58
+ },
59
+ {
60
+ deep: true,
61
+ immediate: true,
62
+ }
63
+ )
64
+
65
+ function init() {
66
+ currentIndex.value = findIndexByValue(props.value)
67
+ currentLabel.value =
68
+ currentIndex.value >= 0 ? (props.options[currentIndex.value] || {}).label : ''
69
+ }
70
+ </script>
71
+
72
+ <template>
73
+ <picker
74
+ mode="selector"
75
+ :range="props.options"
76
+ range-key="label"
77
+ :value="currentIndex"
78
+ @cancel="onCancel"
79
+ @change="onChange"
80
+ style="flex: 1"
81
+ :disabled="props.disabled"
82
+ >
83
+ <slot name="content">
84
+ <div class="dd-selector">
85
+ <div class="dd-selector-value">
86
+ <div
87
+ :class="
88
+ currentIndex >= 0 && !props.disabled ? 'dd-selector-value' : 'dd-selector-label'
89
+ "
90
+ >
91
+ {{ currentLabel || props.placeholder }}
92
+ </div>
93
+ <div>
94
+ <slot name="tips"></slot>
95
+ </div>
96
+ </div>
97
+ <slot name="icon">
98
+ <DdIcon
99
+ v-if="props.rightIcon"
100
+ name="icon-arrow"
101
+ size="11px"
102
+ :color="currentIndex >= 0 && !props.disabled ? '#353535' : '#DFDFDF'"
103
+ class="icon-arrow"
104
+ />
105
+ </slot>
106
+ </div>
107
+ </slot>
108
+ </picker>
109
+ </template>
110
+
111
+ <style lang="scss">
112
+ .dd-selector {
113
+ display: flex;
114
+ justify-content: flex-end;
115
+ align-items: center;
116
+ &-value {
117
+ text-align: right;
118
+ color: black;
119
+ }
120
+ &-label {
121
+ color: var(--placeholder-color);
122
+ }
123
+ }
124
+ </style>
@@ -1,19 +1,19 @@
1
- # ddSkeleton 骨架屏
2
-
3
- #
4
- ## 使用
5
-
6
- ``` javascript
7
- import ddSkeleton from '~/components/ddSkeleton/index.vue'
8
- ```
9
- ``` html
10
- <dd-skeleton @onSuccess="onSuccess" />
11
- ```
12
-
13
- ## Prop
14
-
15
- | 字段 | 说明 | 类型 | 默认值 |
16
- |-----------|-------------|---------|----------|
17
- | row | 大骨架个数 | number | 3 |
18
- | shortRow | 短骨架的行数 | string | 2 |
19
- | longRow | 长骨架的行数 | string | 3 |
1
+ # ddSkeleton 骨架屏
2
+
3
+ #
4
+ ## 使用
5
+
6
+ ``` javascript
7
+ import ddSkeleton from '~/components/ddSkeleton/index.vue'
8
+ ```
9
+ ``` html
10
+ <dd-skeleton @onSuccess="onSuccess" />
11
+ ```
12
+
13
+ ## Prop
14
+
15
+ | 字段 | 说明 | 类型 | 默认值 |
16
+ |-----------|-------------|---------|----------|
17
+ | row | 大骨架个数 | number | 3 |
18
+ | shortRow | 短骨架的行数 | string | 2 |
19
+ | longRow | 长骨架的行数 | string | 3 |
@@ -1,36 +1,36 @@
1
- <script setup lang="ts">
2
- interface PropType {
3
- row?: number
4
- shortRow?: string
5
- longRow?: string
6
- }
7
-
8
- withDefaults(defineProps<PropType>(), {
9
- row: 3,
10
- shortRow: '2',
11
- longRow: '4',
12
- })
13
- </script>
14
-
15
- <template>
16
- <div class="dd-skeleton">
17
- <div class="dd-skeleton__item" v-for="(item, key) in row" :key="key">
18
- <nut-skeleton
19
- width="40%"
20
- height="15px"
21
- animated
22
- v-if="Number(shortRow) > 0"
23
- :row="shortRow"
24
- ></nut-skeleton>
25
- <nut-skeleton width="100%" height="15px" title animated :row="longRow"></nut-skeleton>
26
- </div>
27
- </div>
28
- </template>
29
-
30
- <style lang="scss">
31
- .dd-skeleton {
32
- &__item {
33
- margin-top: 10px;
34
- }
35
- }
36
- </style>
1
+ <script setup lang="ts">
2
+ interface PropType {
3
+ row?: number
4
+ shortRow?: string
5
+ longRow?: string
6
+ }
7
+
8
+ withDefaults(defineProps<PropType>(), {
9
+ row: 3,
10
+ shortRow: '2',
11
+ longRow: '4',
12
+ })
13
+ </script>
14
+
15
+ <template>
16
+ <div class="dd-skeleton">
17
+ <div class="dd-skeleton__item" v-for="(item, key) in row" :key="key">
18
+ <nut-skeleton
19
+ width="40%"
20
+ height="15px"
21
+ animated
22
+ v-if="Number(shortRow) > 0"
23
+ :row="shortRow"
24
+ ></nut-skeleton>
25
+ <nut-skeleton width="100%" height="15px" title animated :row="longRow"></nut-skeleton>
26
+ </div>
27
+ </div>
28
+ </template>
29
+
30
+ <style lang="scss">
31
+ .dd-skeleton {
32
+ &__item {
33
+ margin-top: 10px;
34
+ }
35
+ }
36
+ </style>
@@ -1,114 +1,114 @@
1
- <script setup lang="ts">
2
- import Taro from '@tarojs/taro'
3
- import { OcrResultType } from './types'
4
- import { useAppKitOptions } from '../../Appkit'
5
-
6
- const emits = defineEmits(['ocr'])
7
-
8
- const appKitOptions = useAppKitOptions()
9
-
10
- // 压缩图片
11
- async function taroImgCompress(src: string, quality = 80) {
12
- return new Promise((resolve, reject) => {
13
- Taro.compressImage({
14
- src: src,
15
- quality: quality,
16
- success: (res) => {
17
- resolve(res)
18
- },
19
- fail: (res) => {
20
- reject(res)
21
- },
22
- })
23
- })
24
- }
25
-
26
- // 压缩质量
27
- function getCompressQuality(size: number) {
28
- let quality = 100
29
- const curSize = size / (1024 * 1024)
30
- if (curSize > 6) {
31
- quality = quality - ((curSize - 6) / curSize) * 100
32
- }
33
- return quality
34
- }
35
-
36
- // 清除字符串内空格
37
- function allTrim(str: string) {
38
- return str.replace(/\s+/g, '')
39
- }
40
-
41
- // 拍照识别
42
- async function ocrIDCard() {
43
- let ocrResult: OcrResultType = null
44
- try {
45
- const csRes = await Taro.chooseImage({
46
- count: 1,
47
- })
48
- let { path, size } = csRes.tempFiles[0]
49
- const compressImg: any = (await taroImgCompress(path, getCompressQuality(size))) || {}
50
- const filePath = compressImg.tempFilePath || path
51
- Taro.showLoading({ title: '身份证识别中..' })
52
- const session = appKitOptions.token()
53
- const baseUrl = appKitOptions.baseUrl()
54
- const upRes: any = await Taro.uploadFile({
55
- url: baseUrl + '/hkapprove/ocr/idcard',
56
- filePath,
57
- name: 'file',
58
- formData: {
59
- objectNo: `min${Date.now()}`,
60
- side: 'face',
61
- },
62
- header: {
63
- sessionKey: session || '',
64
- token: session || '',
65
- },
66
- })
67
- Taro.hideLoading()
68
- const res = JSON.parse(upRes.data)
69
- if (res.code === '200') {
70
- const faceInfo = res.result.faceInfo || {}
71
- ocrResult = {
72
- faceInfo: {
73
- name: allTrim(faceInfo.name || ''),
74
- certNo: allTrim(faceInfo.num || ''),
75
- address: allTrim(faceInfo.address || ''),
76
- },
77
- fileUploadVO: res.result.fileUploadVO || {},
78
- }
79
- if (!ocrResult.faceInfo.name && !ocrResult.faceInfo.certNo) {
80
- Taro.showToast({ title: '识别失败,请重试', icon: 'none' })
81
- }
82
- } else {
83
- Taro.showToast({
84
- title: res.msg,
85
- icon: 'error',
86
- })
87
- }
88
- } catch (err) {
89
- Taro.hideLoading()
90
- console.log(err)
91
- }
92
- emits('ocr', ocrResult)
93
- }
94
- </script>
95
-
96
- <template>
97
- <div class="ocr-id" @click="ocrIDCard">
98
- <slot name="icon">
99
- <img
100
- class="ocr-id__img"
101
- src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MCIgaGVpZ2h0PSI0MCIgZmlsbD0ibm9uZSI+PHBhdGggb3BhY2l0eT0iLjAxIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTQwIDB2NDBIMFYwaDQweiIgZmlsbD0iI0M0QzRDNCIvPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMzMuMDQ0IDE3LjM2M2MuOTYgMCAxLjczOS0uNzkgMS43MzktMS43NjYgMC0uOTc1LS43NzktMS43NjYtMS43NC0xLjc2Ni0uOTYgMC0xLjczOC43OS0xLjczOCAxLjc2NnMuNzc4IDEuNzY2IDEuNzM5IDEuNzY2eiIgZmlsbD0iIzRCQ0I5MyIvPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMCAzMS44MTJWMTQuNzg4Yz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IDguMjYyIDMuOTYgOC4yNjIgOC44M3MtMy43MDYgOC44MzItOC4yNjEgOC44MzJjLTQuNTU2IDAtOC4yNjEtMy45NjItOC4yNjEtOC44MzJ6bTEuNzc5LjEzYzAgMy43OTYgMi45MDcgNi44ODMgNi40ODIgNi44ODMgMy41NzQgMCA2LjQ4MS0zLjA4NyA2LjQ4MS02Ljg4M3MtMi45MDctNi44ODMtNi40ODItNi44ODNjLTMuNTc0IDAtNi40ODEgMy4wODctNi40ODEgNi44ODN6IiBmaWxsPSIjNEJDQjkzIi8+PC9zdmc+"
102
- />
103
- </slot>
104
- </div>
105
- </template>
106
-
107
- <style lang="scss">
108
- .ocr-id {
109
- &__img {
110
- width: 20px;
111
- height: 20px;
112
- }
113
- }
114
- </style>
1
+ <script setup lang="ts">
2
+ import Taro from '@tarojs/taro'
3
+ import { OcrResultType } from './types'
4
+ import { useAppKitOptions } from '../../Appkit'
5
+
6
+ const emits = defineEmits(['ocr'])
7
+
8
+ const appKitOptions = useAppKitOptions()
9
+
10
+ // 压缩图片
11
+ async function taroImgCompress(src: string, quality = 80) {
12
+ return new Promise((resolve, reject) => {
13
+ Taro.compressImage({
14
+ src: src,
15
+ quality: quality,
16
+ success: (res) => {
17
+ resolve(res)
18
+ },
19
+ fail: (res) => {
20
+ reject(res)
21
+ },
22
+ })
23
+ })
24
+ }
25
+
26
+ // 压缩质量
27
+ function getCompressQuality(size: number) {
28
+ let quality = 100
29
+ const curSize = size / (1024 * 1024)
30
+ if (curSize > 6) {
31
+ quality = quality - ((curSize - 6) / curSize) * 100
32
+ }
33
+ return quality
34
+ }
35
+
36
+ // 清除字符串内空格
37
+ function allTrim(str: string) {
38
+ return str.replace(/\s+/g, '')
39
+ }
40
+
41
+ // 拍照识别
42
+ async function ocrIDCard() {
43
+ let ocrResult: OcrResultType = null
44
+ try {
45
+ const csRes = await Taro.chooseImage({
46
+ count: 1,
47
+ })
48
+ let { path, size } = csRes.tempFiles[0]
49
+ const compressImg: any = (await taroImgCompress(path, getCompressQuality(size))) || {}
50
+ const filePath = compressImg.tempFilePath || path
51
+ Taro.showLoading({ title: '身份证识别中..' })
52
+ const session = appKitOptions.token()
53
+ const baseUrl = appKitOptions.baseUrl()
54
+ const upRes: any = await Taro.uploadFile({
55
+ url: baseUrl + '/hkapprove/ocr/idcard',
56
+ filePath,
57
+ name: 'file',
58
+ formData: {
59
+ objectNo: `min${Date.now()}`,
60
+ side: 'face',
61
+ },
62
+ header: {
63
+ sessionKey: session || '',
64
+ token: session || '',
65
+ },
66
+ })
67
+ Taro.hideLoading()
68
+ const res = JSON.parse(upRes.data)
69
+ if (res.code === '200') {
70
+ const faceInfo = res.result.faceInfo || {}
71
+ ocrResult = {
72
+ faceInfo: {
73
+ name: allTrim(faceInfo.name || ''),
74
+ certNo: allTrim(faceInfo.num || ''),
75
+ address: allTrim(faceInfo.address || ''),
76
+ },
77
+ fileUploadVO: res.result.fileUploadVO || {},
78
+ }
79
+ if (!ocrResult.faceInfo.name && !ocrResult.faceInfo.certNo) {
80
+ Taro.showToast({ title: '识别失败,请重试', icon: 'none' })
81
+ }
82
+ } else {
83
+ Taro.showToast({
84
+ title: res.msg,
85
+ icon: 'error',
86
+ })
87
+ }
88
+ } catch (err) {
89
+ Taro.hideLoading()
90
+ console.log(err)
91
+ }
92
+ emits('ocr', ocrResult)
93
+ }
94
+ </script>
95
+
96
+ <template>
97
+ <div class="ocr-id" @click="ocrIDCard">
98
+ <slot name="icon">
99
+ <img
100
+ class="ocr-id__img"
101
+ src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MCIgaGVpZ2h0PSI0MCIgZmlsbD0ibm9uZSI+PHBhdGggb3BhY2l0eT0iLjAxIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTQwIDB2NDBIMFYwaDQweiIgZmlsbD0iI0M0QzRDNCIvPjxwYXR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LTIuMjc2VjIxLjU5NmMwLS41MDMuNDU0LS45MSAxLjAxNC0uOTFzMS4wMTUuNDA3IDEuMDE1LjkxVjMxLjgxYy0uMDAzIDIuMjYtMi4wNSA0LjEtNC41NjcgNC4xSDQuNTY0QzIuMDQ5IDM1LjkxIDAgMzQuMDcgMCAzMS44MTF6IiBmaWxsPSIjNEJDQjkzIi8+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMi4xNzQgMjEuNzc4YzAtNC44NyAzLjcwNS04LjgzIDguMjYtOC44MyA0LjU1NiAwIDguMjYyIDMuOTYgOC4yNjIgOC44M3MtMy43MDYgOC44MzItOC4yNjEgOC44MzJjLTQuNTU2IDAtOC4yNjEtMy45NjItOC4yNjEtOC44MzJ6bTEuNzc5LjEzYzAgMy43OTYgMi45MDcgNi44ODMgNi40ODIgNi44ODMgMy41NzQgMCA2LjQ4MS0zLjA4NyA2LjQ4MS02Ljg4M3MtMi45MDctNi44ODMtNi40ODItNi44ODNjLTMuNTc0IDAtNi40ODEgMy4wODctNi40ODEgNi44ODN6IiBmaWxsPSIjNEJDQjkzIi8+PC9zdmc+"
102
+ />
103
+ </slot>
104
+ </div>
105
+ </template>
106
+
107
+ <style lang="scss">
108
+ .ocr-id {
109
+ &__img {
110
+ width: 20px;
111
+ height: 20px;
112
+ }
113
+ }
114
+ </style>
@@ -1,13 +1,13 @@
1
- export type OcrResultType = {
2
- faceInfo: {
3
- name: string
4
- certNo: string
5
- address: string
6
- }
7
- fileUploadVO: {
8
- fileKey: string
9
- fileUrl: string
10
- objectNo: string
11
- thumbnailUrl?: string
12
- }
1
+ export type OcrResultType = {
2
+ faceInfo: {
3
+ name: string
4
+ certNo: string
5
+ address: string
6
+ }
7
+ fileUploadVO: {
8
+ fileKey: string
9
+ fileUrl: string
10
+ objectNo: string
11
+ thumbnailUrl?: string
12
+ }
13
13
  } | null
package/src/global.ts CHANGED
@@ -1,7 +1,7 @@
1
- const globalData: any = {
2
-
3
- }
4
-
5
- export {
6
- globalData
1
+ const globalData: any = {
2
+
3
+ }
4
+
5
+ export {
6
+ globalData
7
7
  }