@uxda/appkit 1.1.2 → 1.2.2

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.
@@ -0,0 +1,220 @@
1
+ <!--* NAME: index-->
2
+ <!--* AUTHOR: yanglong-->
3
+ <!--* UPDATE: 2022-02-21 17:43-->
4
+ <!--* TIP: 微信原生实现多列选择器-->
5
+ <script setup lang="ts">
6
+ import {computed, ref, watch} from 'vue'
7
+ import Taro from '@tarojs/taro'
8
+ import DdIcon from '../dd-icon/index.vue'
9
+
10
+ interface AreaItem {
11
+ value: string
12
+ shortId: string
13
+ label: string
14
+ children: AreaItem[]
15
+ }
16
+
17
+ export type AreaType = 'province' | 'city' | 'region'
18
+
19
+ export interface PropsType {
20
+ value?: string // 地址code
21
+ rightIcon?: boolean
22
+ placeholder?: string
23
+ disabled?: boolean
24
+ type?: AreaType
25
+ formatter?: (values: AreaItem[]) => string
26
+ }
27
+
28
+ const props = withDefaults(defineProps<PropsType>(), {
29
+ value: '',
30
+ rightIcon: true,
31
+ placeholder: '请选择',
32
+ disabled: false,
33
+ type: 'region',
34
+ formatter: (values: AreaItem[]) => values.map((item:AreaItem) => item.label).join('')
35
+ })
36
+ const emit = defineEmits(['update:value', 'change', 'cancel'])
37
+
38
+ const areaFormatOptions = computed<AreaItem[]>(() => {
39
+ const {province_list, city_list, county_list} = JSON.parse(Taro.getStorageSync('wechat_area'))
40
+ const map = new Map()
41
+ city_list.forEach((item: any) => {
42
+ const provinceShortId = item.id.slice(0, 2)
43
+ if (!map.has(provinceShortId)) {
44
+ map.set(provinceShortId, [])
45
+ }
46
+ map.get(provinceShortId).push({
47
+ ...item,
48
+ shortId: item.id.slice(0, 4)
49
+ })
50
+ })
51
+ county_list.forEach((item: any) => {
52
+ const cityShortId = item.id.slice(0, 4)
53
+ if (!map.has(cityShortId)) {
54
+ map.set(cityShortId, [])
55
+ }
56
+ map.get(cityShortId).push({
57
+ ...item,
58
+ shortId: item.id
59
+ })
60
+ })
61
+ return province_list.map((province: any) => {
62
+ const provinceShortId = province.id.slice(0, 2)
63
+ return {
64
+ value: province.id,
65
+ shortId: provinceShortId,
66
+ label: province.name,
67
+ children: map.get(provinceShortId)?.map((city: any) => ({
68
+ value: city.id,
69
+ shortId: city.shortId,
70
+ label: city.name,
71
+ children: map.get(city.shortId)?.map((region: any) => ({
72
+ value: region.id,
73
+ shortId: region.shortId,
74
+ label: region.name,
75
+ children: []
76
+ })) ?? [],
77
+ })) ?? [],
78
+ }
79
+ })
80
+ })
81
+
82
+ const tmpSelectedIndex = ref<number[]>([0, 0, 0])
83
+ const selectedIndex = ref<number[]>([0, 0, 0])
84
+ const selectedItem = ref<AreaItem[]>([])
85
+
86
+ const options = computed<AreaItem[][]>(() => {
87
+ const provinceOption = areaFormatOptions.value
88
+ if (props.type === 'province') {
89
+ return [provinceOption]
90
+ }
91
+ const cityOption = provinceOption[tmpSelectedIndex.value[0]].children
92
+ if (props.type === 'city') {
93
+ return [provinceOption, cityOption]
94
+ }
95
+ const regionOption = cityOption[tmpSelectedIndex.value[1]].children
96
+ return [provinceOption, cityOption, regionOption]
97
+ })
98
+
99
+ function init() {
100
+ selectedIndex.value = findIndexByValue()
101
+ tmpSelectedIndex.value = [...selectedIndex.value]
102
+ if (props.value){
103
+ const items = []
104
+ for (let index = 0; index < options.value.length; index++) {
105
+ const item = options.value[index][selectedIndex.value[index]]
106
+ if (item){
107
+ items.push(item)
108
+ }
109
+ }
110
+ selectedItem.value = items
111
+ }
112
+ }
113
+
114
+ function findIndexByValue() {
115
+ if (props.value) {
116
+ const provinceId = props.value.slice(0, 2).toString().padEnd(6, '0')
117
+ const cityId = props.value.slice(0, 4).toString().padEnd(6, '0')
118
+ const regionId = props.value.toString()
119
+ for (let provinceIndex = 0; provinceIndex < areaFormatOptions.value.length; provinceIndex++) {
120
+ const province = areaFormatOptions.value[provinceIndex]
121
+ if (provinceId == province.value) {
122
+ for (let cityIndex = 0; cityIndex < province.children.length; cityIndex++) {
123
+ const city = province.children[cityIndex]
124
+ if (cityId == city.value) {
125
+ for (let regionIndex = 0; regionIndex < city.children.length; regionIndex++) {
126
+ const region = city.children[regionIndex]
127
+ if (regionId == region.value) {
128
+ return [provinceIndex, cityIndex, regionIndex]
129
+ }
130
+ }
131
+ return [provinceIndex, cityIndex, 0]
132
+ }
133
+ }
134
+ return [provinceIndex, 0, 0]
135
+ }
136
+ }
137
+ }
138
+ return [0, 0, 0]
139
+ }
140
+
141
+ function onChange() {
142
+ const lastSelectedIndex = options.value.length - 1
143
+ const result = {
144
+ values: [],
145
+ labels: []
146
+ }
147
+ for (let index = 0; index <= lastSelectedIndex; index++) {
148
+ const item = options.value[index][tmpSelectedIndex.value[index]]
149
+ result.values.push(item.value)
150
+ result.labels.push(item.label)
151
+ }
152
+ emit('update:value', result.values[result.values.length-1])
153
+ emit('change', result)
154
+ console.log(result)
155
+ }
156
+
157
+ function onCancel(e: any) {
158
+ init()
159
+ emit('cancel', e)
160
+ }
161
+
162
+ function onColumnChange({detail: {column, value}}) {
163
+ const resetIndex = Array.from({length: tmpSelectedIndex.value.length - column - 1, }).fill(0)
164
+ tmpSelectedIndex.value = [...tmpSelectedIndex.value.slice(0,column), value, ...resetIndex ]
165
+ console.log(tmpSelectedIndex.value)
166
+ }
167
+
168
+ watch(
169
+ () => props.value,
170
+ () => { init() },
171
+ {deep: true, immediate: true}
172
+ )
173
+ </script>
174
+
175
+ <template>
176
+ <picker
177
+ :range="options"
178
+ range-key="label"
179
+ :value="tmpSelectedIndex"
180
+ mode="multiSelector"
181
+ @columnchange="onColumnChange"
182
+ @change="onChange"
183
+ @cancel="onCancel"
184
+ style="flex: 1"
185
+ :disabled="props.disabled">
186
+ <div class="dd-area">
187
+ <div
188
+ :class="props.value && !props.disabled ? 'dd-area-value' : 'dd-area-label'">
189
+ {{ props.value ? props.formatter(selectedItem) : props.placeholder }}
190
+ </div>
191
+ <slot name="icon">
192
+ <DdIcon
193
+ v-if="props.rightIcon"
194
+ name="icon-arrow"
195
+ size="11px"
196
+ :color="
197
+ props.value !== '' && !props.disabled ? '#353535' : '#DFDFDF'
198
+ "
199
+ class="icon-arrow"/>
200
+ </slot>
201
+ </div>
202
+ </picker>
203
+ </template>
204
+
205
+ <style lang="scss">
206
+ .dd-area {
207
+ display: flex;
208
+ justify-content: flex-end;
209
+ align-items: center;
210
+
211
+ &-value {
212
+ text-align: right;
213
+ color: black;
214
+ }
215
+
216
+ &-label {
217
+ color: var(--placeholder-color);
218
+ }
219
+ }
220
+ </style>
@@ -0,0 +1,21 @@
1
+ # ddIcon 空内容展示
2
+ ### 使用iconfont图标
3
+
4
+ #
5
+ ## 使用
6
+
7
+ ``` javascript
8
+ import ddIcon from '~/components/ddIcon/index.vue'
9
+ ```
10
+ ``` html
11
+ <dd-icon name="icon-arrow" size="11px" color="#DFDFDF" />
12
+ ```
13
+
14
+ ## Prop
15
+
16
+ | 字段 | 说明 | 类型 | 默认值 |
17
+ |-----------|-------------|---------|----------|
18
+ | name | icon名称 | string | '' |
19
+ | color | icon颜色 | string | inherit |
20
+ | size | icon字体大小 | string | 16px |
21
+ | weight | icon字体字重 | string | normal |
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ const props = withDefaults(
4
+ defineProps<{
5
+ name: string
6
+ color?: string
7
+ size?: string
8
+ weight?: string
9
+ }>(),
10
+ {
11
+ color: 'inherit',
12
+ size: '16px',
13
+ weight: 'normal',
14
+ }
15
+ )
16
+ const styles = computed(() => {
17
+ return `color: ${props.color}; font-size: ${props.size}; font-weight: ${props.weight};`
18
+ })
19
+ </script>
20
+
21
+ <template>
22
+ <view class="iconfont" :class="name" :style="styles"></view>
23
+ </template>
@@ -0,0 +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 = currentIndex.value >= 0 ? props.options[currentIndex.value]?.label : ''
68
+ }
69
+ </script>
70
+
71
+ <template>
72
+ <picker
73
+ mode="selector"
74
+ :range="props.options"
75
+ range-key="label"
76
+ :value="currentIndex"
77
+ @cancel="onCancel"
78
+ @change="onChange"
79
+ style="flex: 1"
80
+ :disabled="props.disabled">
81
+ <slot name="content">
82
+ <div class="dd-selector">
83
+ <div class="dd-selector-value">
84
+ <div
85
+ :class="
86
+ currentIndex >= 0 && !props.disabled
87
+ ? 'dd-selector-value'
88
+ : 'dd-selector-label'
89
+ ">
90
+ {{ currentLabel || props.placeholder }}
91
+ </div>
92
+ <div>
93
+ <slot name="tips"></slot>
94
+ </div>
95
+ </div>
96
+ <slot name="icon">
97
+ <DdIcon
98
+ v-if="props.rightIcon"
99
+ name="icon-arrow"
100
+ size="11px"
101
+ :color="
102
+ currentIndex >= 0 && !props.disabled ? '#353535' : '#DFDFDF'
103
+ "
104
+ class="icon-arrow" />
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>
@@ -0,0 +1,111 @@
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
+ ocrResult = {
71
+ faceInfo: {
72
+ name: allTrim(res.result?.faceInfo?.name || ''),
73
+ certNo: allTrim(res.result?.faceInfo?.num || ''),
74
+ address: allTrim(res.result?.faceInfo?.address || ''),
75
+ },
76
+ fileUploadVO: res.result?.fileUploadVO || {},
77
+ }
78
+ if (!ocrResult.faceInfo.name && !ocrResult.faceInfo.certNo) {
79
+ Taro.showToast({title: '识别失败,请重试', icon: 'none'})
80
+ }
81
+ } else {
82
+ Taro.showToast({
83
+ title: res.msg,
84
+ icon: 'error',
85
+ })
86
+ }
87
+ } catch (err) {
88
+ Taro.hideLoading()
89
+ console.log(err)
90
+ }
91
+ emits('ocr', ocrResult)
92
+ }
93
+ </script>
94
+
95
+ <template>
96
+ <div class="ocr-id" @click="ocrIDCard">
97
+ <slot name="icon">
98
+ <img class="ocr-id__img" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MCIgaGVpZ2h0PSI0MCIgZmlsbD0ibm9uZSI+PHBhdGggb3BhY2l0eT0iLjAxIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTQwIDB2NDBIMFYwaDQweiIgZmlsbD0iI0M0QzRDNCIvPjxwYXRoIGZpbGwtcnVsZT0iZXZ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LS41MDMuNDU0LS45MSAxLjAxNC0uOTFzMS4wMTUuNDA3IDEuMDE1LjkxVjMxLjgxYy0uMDAzIDIuMjYtMi4wNSA0LjEtNC41NjcgNC4xSDQuNTY0QzIuMDQ5IDM1LjkxIDAgMzQuMDcgMCAzMS44MTF6IiBmaWxsPSIjNEJDQjkzIi8+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMi4xNzQgMjEuNzc4YzAtNC44NyAzLjcwNS04LjgzIDguMjYtOC44MyA0LjU1NiAwIDguMjYyIDMuOTYgOC4yNjIgOC44M3MtMy43MDYgOC44MzItOC4yNjEgOC44MzJjLTQuNTU2IDAtOC4yNjEtMy45NjItOC4yNjEtOC44MzJ6bTEuNzc5LjEzYzAgMy43OTYgMi45MDcgNi44ODMgNi40ODIgNi44ODMgMy41NzQgMCA2LjQ4MS0zLjA4NyA2LjQ4MS02Ljg4M3MtMi45MDctNi44ODMtNi40ODItNi44ODNjLTMuNTc0IDAtNi40ODEgMy4wODctNi40ODEgNi44ODN6IiBmaWxsPSIjNEJDQjkzIi8+PC9zdmc+"/>
99
+ </slot>
100
+ </div>
101
+ </template>
102
+
103
+ <style lang="scss">
104
+ .ocr-id {
105
+
106
+ &__img {
107
+ width: 20px;
108
+ height: 20px;
109
+ }
110
+ }
111
+ </style>
@@ -0,0 +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
+ }
13
+ } | null
package/src/index.ts CHANGED
@@ -9,6 +9,10 @@ import {
9
9
  Popup,
10
10
  OverLay,
11
11
  DatePicker,
12
+ Form,
13
+ FormItem,
14
+ Cell,
15
+ CellGroup
12
16
  } from '@nutui/nutui-taro'
13
17
  import { type AppKitOptions, useAppKitOptions, DollarApp } from './Appkit'
14
18
  import { PaymentParams, RechargeParams } from './payment/types'
@@ -22,6 +26,10 @@ const nutComponents = [
22
26
  Popup,
23
27
  OverLay,
24
28
  DatePicker,
29
+ Form,
30
+ FormItem,
31
+ Cell,
32
+ CellGroup
25
33
  ]
26
34
 
27
35
  const appComponents = {
@@ -75,6 +83,7 @@ export default AppKit
75
83
  export * from './payment'
76
84
  export * from './balance'
77
85
  export * from './shared'
86
+ export * from './register'
78
87
  export {
79
88
  type AppKitOptions
80
89
  }