hy-app 0.6.3 → 0.6.5
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/components/hy-address-picker/hy-address-picker.vue +249 -249
- package/components/hy-address-picker/props.ts +103 -103
- package/components/hy-button/hy-button.vue +320 -295
- package/components/hy-button/index.scss +1 -1
- package/components/hy-button/props.ts +143 -143
- package/components/hy-button/typing.d.ts +43 -35
- package/components/hy-calendar/header.vue +58 -58
- package/components/hy-calendar/hy-calendar.vue +375 -375
- package/components/hy-calendar/month.vue +402 -402
- package/components/hy-calendar/props.ts +169 -169
- package/components/hy-calendar/typing.d.ts +45 -45
- package/components/hy-cell-item/hy-cell-item.vue +161 -161
- package/components/hy-cell-item/props.ts +59 -59
- package/components/hy-check-button/hy-check-button.vue +135 -135
- package/components/hy-code-input/hy-code-input.vue +231 -231
- package/components/hy-code-input/props.ts +90 -90
- package/components/hy-config-provider/hy-config-provider.vue +53 -53
- package/components/hy-config-provider/props.ts +30 -30
- package/components/hy-coupon/hy-coupon.vue +183 -183
- package/components/hy-coupon/props.ts +108 -108
- package/components/hy-datetime-picker/hy-datetime-picker.vue +536 -536
- package/components/hy-datetime-picker/props.ts +144 -144
- package/components/hy-divider/props.ts +83 -83
- package/components/hy-empty/icon.ts +72 -72
- package/components/hy-folding-panel/hy-folding-panel-group.vue +162 -162
- package/components/hy-form/hy-form.vue +220 -220
- package/components/hy-icon/hy-icon.vue +112 -112
- package/components/hy-index-bar/hy-index-bar.vue +185 -185
- package/components/hy-index-bar/index.scss +64 -64
- package/components/hy-index-bar/props.ts +94 -94
- package/components/hy-index-bar/typing.d.ts +36 -36
- package/components/hy-input/hy-input.vue +333 -333
- package/components/hy-input/props.ts +186 -186
- package/components/hy-modal/hy-modal.vue +211 -211
- package/components/hy-modal/props.ts +94 -94
- package/components/hy-modal/typing.d.ts +16 -16
- package/components/hy-notice-bar/hy-row-notice.vue +121 -121
- package/components/hy-notify/hy-notify.vue +174 -174
- package/components/hy-number-step/hy-number-step.vue +367 -367
- package/components/hy-overlay/hy-overlay.vue +1 -0
- package/components/hy-overlay/props.ts +5 -0
- package/components/hy-pagination/hy-pagination.vue +136 -136
- package/components/hy-pagination/props.ts +58 -58
- package/components/hy-parse/hy-parse.vue +550 -550
- package/components/hy-parse/node/node.vue +781 -781
- package/components/hy-parse/parser.js +1455 -1455
- package/components/hy-parse/props.ts +19 -19
- package/components/hy-parse/typing.d.ts +68 -68
- package/components/hy-picker/hy-picker.vue +435 -435
- package/components/hy-picker/props.ts +122 -122
- package/components/hy-picker/typing.d.ts +38 -38
- package/components/hy-qrcode/props.ts +72 -72
- package/components/hy-qrcode/qrcode.js.bak +1433 -1433
- package/components/hy-radio/props.ts +97 -97
- package/components/hy-read-more/props.ts +48 -48
- package/components/hy-search/props.ts +133 -133
- package/components/hy-signature/canvasHelper.ts +51 -51
- package/components/hy-signature/props.ts +121 -121
- package/components/hy-skeleton/hy-skeleton.vue +142 -142
- package/components/hy-skeleton/props.ts +46 -46
- package/components/hy-skeleton/typing.d.ts +31 -31
- package/components/hy-steps/hy-steps.vue +275 -275
- package/components/hy-steps/typing.d.ts +25 -25
- package/components/hy-table/hy-table.vue +630 -596
- package/components/hy-table/index.scss +15 -3
- package/components/hy-table/props.ts +62 -62
- package/components/hy-table/typing.d.ts +29 -29
- package/components/hy-tabs/hy-tabs.vue +335 -335
- package/components/hy-tabs/index.scss +3 -0
- package/components/hy-tabs/props.ts +77 -77
- package/components/hy-tag/hy-tag.vue +173 -174
- package/components/hy-tag/props.ts +89 -89
- package/components/hy-text/hy-text.vue +237 -237
- package/components/hy-text/props.ts +115 -115
- package/components/hy-textarea/hy-textarea.vue +198 -198
- package/components/hy-toast/hy-toast.vue +200 -194
- package/components/hy-toast/props.ts +3 -3
- package/components/hy-transition/hy-transition.vue +2 -2
- package/components/hy-upload/hy-upload.vue +384 -384
- package/components/hy-watermark/hy-watermark.vue +115 -35
- package/components/hy-watermark/index.scss +0 -9
- package/components/hy-watermark/props.ts +6 -1
- package/global.d.ts +94 -94
- package/libs/api/http.ts +119 -119
- package/libs/composables/index.ts +8 -8
- package/libs/composables/useMessage.ts +149 -149
- package/libs/composables/useToast.ts +45 -45
- package/libs/composables/useTranslate.ts +10 -10
- package/libs/css/_config.scss +5 -5
- package/libs/index.ts +8 -8
- package/libs/locale/index.ts +32 -32
- package/libs/locale/lang/en-US.ts +84 -84
- package/libs/locale/lang/zh-CN.ts +87 -87
- package/libs/typing/index.ts +2 -2
- package/libs/typing/modules/common.d.ts +139 -139
- package/libs/typing/modules/form.ts +176 -176
- package/libs/typing/modules/http.d.ts +19 -19
- package/libs/typing/modules/index.d.ts +12 -12
- package/libs/utils/inside.ts +340 -340
- package/libs/utils/inspect.ts +140 -140
- package/libs/utils/utils.ts +525 -525
- package/package.json +81 -81
- package/attributes.json +0 -1
- package/tags.json +0 -1
- package/web-types.json +0 -1
|
@@ -1,249 +1,249 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="hy-address-picker">
|
|
3
|
-
<view v-if="hasInput" class="hy-address-picker__has-input" @tap="onShowByClickInput">
|
|
4
|
-
<!-- @slot 自定义输入框 -->
|
|
5
|
-
<slot v-if="$slots.trigger" name="trigger" :value="inputValue"></slot>
|
|
6
|
-
<template v-else>
|
|
7
|
-
<hy-input
|
|
8
|
-
v-model="inputValue"
|
|
9
|
-
:disabled="input?.disabled"
|
|
10
|
-
:disabledColor="input?.disabledColor"
|
|
11
|
-
:shape="input?.shape"
|
|
12
|
-
:border="input?.border"
|
|
13
|
-
:prefixIcon="input?.prefixIcon"
|
|
14
|
-
:suffixIcon="input?.suffixIcon"
|
|
15
|
-
:color="input?.color"
|
|
16
|
-
:fontSize="input?.fontSize"
|
|
17
|
-
:inputAlign="input?.inputAlign"
|
|
18
|
-
:placeholder="input?.placeholder || t('placeholder')"
|
|
19
|
-
:placeholderStyle="input?.placeholderStyle"
|
|
20
|
-
:placeholderClass="input?.placeholderClass"
|
|
21
|
-
:customStyle="Object.assign({ 'pointer-events': 'none' }, input?.customStyle)"
|
|
22
|
-
></hy-input>
|
|
23
|
-
<view class="input-cover"></view>
|
|
24
|
-
</template>
|
|
25
|
-
</view>
|
|
26
|
-
<hy-picker
|
|
27
|
-
ref="uPickerRef"
|
|
28
|
-
:show="show || (hasInput && showByClickInput)"
|
|
29
|
-
:popupMode="popupMode"
|
|
30
|
-
:closeOnClickOverlay="closeOnClickOverlay"
|
|
31
|
-
:columns="columns"
|
|
32
|
-
:defaultIndex="defaultIndex"
|
|
33
|
-
:title="title"
|
|
34
|
-
label-key="name"
|
|
35
|
-
:itemHeight="itemHeight"
|
|
36
|
-
:loading="loading"
|
|
37
|
-
:showToolbar="showToolbar"
|
|
38
|
-
:visibleItemCount="visibleItemCount"
|
|
39
|
-
:cancelText="cancelText"
|
|
40
|
-
:cancelColor="cancelColor"
|
|
41
|
-
:confirmColor="confirmColor"
|
|
42
|
-
:toolbarRightSlot="toolbarRightSlot"
|
|
43
|
-
@close="close"
|
|
44
|
-
@cancel="cancel"
|
|
45
|
-
@confirm="confirm"
|
|
46
|
-
@change="change"
|
|
47
|
-
>
|
|
48
|
-
<template #toolbar-right>
|
|
49
|
-
<!-- @slot 工具栏右侧内容,自定义右侧内容,因为微信小程序限制,需要同时设置:toolbarRightSlot="true"生效。 -->
|
|
50
|
-
<slot name="toolbar-right">
|
|
51
|
-
{{ confirmText }}
|
|
52
|
-
</slot>
|
|
53
|
-
</template>
|
|
54
|
-
<template #toolbar-bottom>
|
|
55
|
-
<!-- @slot 工具栏下面内容,自定义底部内容 -->
|
|
56
|
-
<slot name="toolbar-bottom"></slot>
|
|
57
|
-
</template>
|
|
58
|
-
</hy-picker>
|
|
59
|
-
</view>
|
|
60
|
-
</template>
|
|
61
|
-
|
|
62
|
-
<script lang="ts">
|
|
63
|
-
export default {
|
|
64
|
-
name: 'hy-address-picker',
|
|
65
|
-
options: {
|
|
66
|
-
addGlobalClass: true,
|
|
67
|
-
virtualHost: true,
|
|
68
|
-
styleIsolation: 'shared'
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
</script>
|
|
72
|
-
|
|
73
|
-
<script setup lang="ts">
|
|
74
|
-
import { onMounted, ref, toRefs } from 'vue'
|
|
75
|
-
import type { IAddressPickerEmits } from './typing'
|
|
76
|
-
import address from '../../libs/utils/address.json'
|
|
77
|
-
import addressPickerProps from './props'
|
|
78
|
-
import { useTranslate } from '../../libs'
|
|
79
|
-
// 组件
|
|
80
|
-
import HyInput from '../hy-input/hy-input.vue'
|
|
81
|
-
import HyPicker from '../hy-picker/hy-picker.vue'
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 此选择器用于选择地址
|
|
85
|
-
* @displayName hy-address-picker
|
|
86
|
-
*/
|
|
87
|
-
defineOptions({})
|
|
88
|
-
|
|
89
|
-
const props = defineProps(addressPickerProps)
|
|
90
|
-
const { show, modelValue, hasInput, input, separator, closeOnClickOverlay } = toRefs(props)
|
|
91
|
-
const emit = defineEmits<IAddressPickerEmits>()
|
|
92
|
-
|
|
93
|
-
const { t } = useTranslate('addressPicker')
|
|
94
|
-
// 原来的日期选择器不方便,这里增加一个hasInput选项支持类似element的自带输入框的功能。
|
|
95
|
-
const inputValue = ref<string>('') // 表单显示值
|
|
96
|
-
const showByClickInput = ref<boolean>(false) // 是否在hasInput模式下显示日期选择
|
|
97
|
-
const columns = ref<any[]>([])
|
|
98
|
-
const uPickerRef = ref<InstanceType<typeof HyPicker> | null>()
|
|
99
|
-
const defaultIndex = ref<number[]>([])
|
|
100
|
-
|
|
101
|
-
function normalizeCityName(city: string) {
|
|
102
|
-
// 定义常见的后缀
|
|
103
|
-
const suffixes = ['市', '省', '自治区', '特别行政区', '县', '区']
|
|
104
|
-
suffixes.forEach((suffix) => {
|
|
105
|
-
if (city.endsWith(suffix)) {
|
|
106
|
-
city = city.slice(0, -suffix.length)
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
return city
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* @description 判断城市是否相等
|
|
113
|
-
* */
|
|
114
|
-
const areCitiesEqual = (city1: string, city2: string) => {
|
|
115
|
-
const normalizedCity1 = normalizeCityName(city1)
|
|
116
|
-
const normalizedCity2 = normalizeCityName(city2)
|
|
117
|
-
return normalizedCity1 === normalizedCity2
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* @description 更新各列的值
|
|
121
|
-
* */
|
|
122
|
-
const updateColumnValue = (value: string) => {
|
|
123
|
-
let provinceIndex, cityIndex, countyIndex
|
|
124
|
-
// 判断是初始化有数据就找到对应索引,无数据默认索引为0
|
|
125
|
-
if (value) {
|
|
126
|
-
const addressArr = value.split(separator.value)
|
|
127
|
-
// 查出省索引
|
|
128
|
-
provinceIndex = address.findIndex((item) => areCitiesEqual(item.name, addressArr[0]))
|
|
129
|
-
// 查出市索引
|
|
130
|
-
cityIndex = address[provinceIndex].areas.findIndex((item) =>
|
|
131
|
-
areCitiesEqual(item.name, addressArr[1])
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
// 查出县/区索引
|
|
135
|
-
countyIndex = address[provinceIndex].areas[cityIndex].areas.findIndex((item) =>
|
|
136
|
-
areCitiesEqual(item.name, addressArr[2])
|
|
137
|
-
)
|
|
138
|
-
} else {
|
|
139
|
-
provinceIndex = 0
|
|
140
|
-
cityIndex = 0
|
|
141
|
-
countyIndex = 0
|
|
142
|
-
}
|
|
143
|
-
// 省级数组
|
|
144
|
-
const provinceData = address.map((item) => ({
|
|
145
|
-
name: item.name,
|
|
146
|
-
code: item.code
|
|
147
|
-
}))
|
|
148
|
-
// 市级数组
|
|
149
|
-
const cityData = address[provinceIndex].areas.map((item) => ({
|
|
150
|
-
name: item.name,
|
|
151
|
-
code: item.code
|
|
152
|
-
}))
|
|
153
|
-
// 县/区级数组
|
|
154
|
-
const areaData = address[provinceIndex].areas[cityIndex].areas
|
|
155
|
-
|
|
156
|
-
// 默认索引
|
|
157
|
-
defaultIndex.value = [provinceIndex, cityIndex, countyIndex]
|
|
158
|
-
// 列表
|
|
159
|
-
columns.value = [provinceData, cityData, areaData]
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const init = () => {
|
|
163
|
-
// 获取当前值
|
|
164
|
-
inputValue.value = modelValue.value
|
|
165
|
-
// 更新列表
|
|
166
|
-
updateColumnValue(modelValue.value)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
onMounted(() => {
|
|
170
|
-
init()
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @description 关闭选择器
|
|
175
|
-
* */
|
|
176
|
-
const close = () => {
|
|
177
|
-
if (closeOnClickOverlay.value) {
|
|
178
|
-
if (hasInput.value) {
|
|
179
|
-
showByClickInput.value = false
|
|
180
|
-
}
|
|
181
|
-
emit('close')
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* @description 点击工具栏的取消按钮
|
|
187
|
-
* */
|
|
188
|
-
const cancel = () => {
|
|
189
|
-
if (hasInput.value) {
|
|
190
|
-
showByClickInput.value = false
|
|
191
|
-
}
|
|
192
|
-
emit('cancel')
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* @description 点击工具栏的确定按钮
|
|
197
|
-
* */
|
|
198
|
-
const confirm = ({ value }: { value: Record<string, any>[] }) => {
|
|
199
|
-
inputValue.value = value.map((item) => item.name).join(separator.value)
|
|
200
|
-
|
|
201
|
-
showByClickInput.value = false
|
|
202
|
-
emit('update:modelValue', inputValue.value)
|
|
203
|
-
emit('confirm', {
|
|
204
|
-
value: inputValue.value
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* @description 列发生变化时触发
|
|
210
|
-
* */
|
|
211
|
-
const change = (e: any) => {
|
|
212
|
-
const { columnIndex, index, indexs } = e
|
|
213
|
-
//如果改变的是第一列
|
|
214
|
-
if (columnIndex === 0) {
|
|
215
|
-
const children1 = address[index].areas.map((item) => {
|
|
216
|
-
return { name: item.name, code: item.code }
|
|
217
|
-
})
|
|
218
|
-
uPickerRef.value?.setColumnValues(1, children1)
|
|
219
|
-
//更换 第二列数据
|
|
220
|
-
const children2 = address[index].areas[indexs[1]].areas.map((item) => ({
|
|
221
|
-
...item
|
|
222
|
-
}))
|
|
223
|
-
uPickerRef.value?.setColumnValues(2, children2)
|
|
224
|
-
//更换 第三列数据
|
|
225
|
-
}
|
|
226
|
-
if (columnIndex === 1) {
|
|
227
|
-
//如果改变的是第二列
|
|
228
|
-
const children3 = address[indexs[0]].areas[indexs[1]].areas.map((item) => ({
|
|
229
|
-
...item
|
|
230
|
-
}))
|
|
231
|
-
uPickerRef.value?.setColumnValues(2, children3)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// 发出change时间,value为当前选中的时间戳
|
|
235
|
-
emit('change', {
|
|
236
|
-
...e
|
|
237
|
-
})
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const onShowByClickInput = () => {
|
|
241
|
-
if (!props.input?.disabled) {
|
|
242
|
-
showByClickInput.value = !showByClickInput.value
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
</script>
|
|
246
|
-
|
|
247
|
-
<style lang="scss" scoped>
|
|
248
|
-
@import './index.scss';
|
|
249
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view class="hy-address-picker">
|
|
3
|
+
<view v-if="hasInput" class="hy-address-picker__has-input" @tap="onShowByClickInput">
|
|
4
|
+
<!-- @slot 自定义输入框 -->
|
|
5
|
+
<slot v-if="$slots.trigger" name="trigger" :value="inputValue"></slot>
|
|
6
|
+
<template v-else>
|
|
7
|
+
<hy-input
|
|
8
|
+
v-model="inputValue"
|
|
9
|
+
:disabled="input?.disabled"
|
|
10
|
+
:disabledColor="input?.disabledColor"
|
|
11
|
+
:shape="input?.shape"
|
|
12
|
+
:border="input?.border"
|
|
13
|
+
:prefixIcon="input?.prefixIcon"
|
|
14
|
+
:suffixIcon="input?.suffixIcon"
|
|
15
|
+
:color="input?.color"
|
|
16
|
+
:fontSize="input?.fontSize"
|
|
17
|
+
:inputAlign="input?.inputAlign"
|
|
18
|
+
:placeholder="input?.placeholder || t('placeholder')"
|
|
19
|
+
:placeholderStyle="input?.placeholderStyle"
|
|
20
|
+
:placeholderClass="input?.placeholderClass"
|
|
21
|
+
:customStyle="Object.assign({ 'pointer-events': 'none' }, input?.customStyle)"
|
|
22
|
+
></hy-input>
|
|
23
|
+
<view class="input-cover"></view>
|
|
24
|
+
</template>
|
|
25
|
+
</view>
|
|
26
|
+
<hy-picker
|
|
27
|
+
ref="uPickerRef"
|
|
28
|
+
:show="show || (hasInput && showByClickInput)"
|
|
29
|
+
:popupMode="popupMode"
|
|
30
|
+
:closeOnClickOverlay="closeOnClickOverlay"
|
|
31
|
+
:columns="columns"
|
|
32
|
+
:defaultIndex="defaultIndex"
|
|
33
|
+
:title="title"
|
|
34
|
+
label-key="name"
|
|
35
|
+
:itemHeight="itemHeight"
|
|
36
|
+
:loading="loading"
|
|
37
|
+
:showToolbar="showToolbar"
|
|
38
|
+
:visibleItemCount="visibleItemCount"
|
|
39
|
+
:cancelText="cancelText"
|
|
40
|
+
:cancelColor="cancelColor"
|
|
41
|
+
:confirmColor="confirmColor"
|
|
42
|
+
:toolbarRightSlot="toolbarRightSlot"
|
|
43
|
+
@close="close"
|
|
44
|
+
@cancel="cancel"
|
|
45
|
+
@confirm="confirm"
|
|
46
|
+
@change="change"
|
|
47
|
+
>
|
|
48
|
+
<template #toolbar-right>
|
|
49
|
+
<!-- @slot 工具栏右侧内容,自定义右侧内容,因为微信小程序限制,需要同时设置:toolbarRightSlot="true"生效。 -->
|
|
50
|
+
<slot name="toolbar-right">
|
|
51
|
+
{{ confirmText }}
|
|
52
|
+
</slot>
|
|
53
|
+
</template>
|
|
54
|
+
<template #toolbar-bottom>
|
|
55
|
+
<!-- @slot 工具栏下面内容,自定义底部内容 -->
|
|
56
|
+
<slot name="toolbar-bottom"></slot>
|
|
57
|
+
</template>
|
|
58
|
+
</hy-picker>
|
|
59
|
+
</view>
|
|
60
|
+
</template>
|
|
61
|
+
|
|
62
|
+
<script lang="ts">
|
|
63
|
+
export default {
|
|
64
|
+
name: 'hy-address-picker',
|
|
65
|
+
options: {
|
|
66
|
+
addGlobalClass: true,
|
|
67
|
+
virtualHost: true,
|
|
68
|
+
styleIsolation: 'shared'
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<script setup lang="ts">
|
|
74
|
+
import { onMounted, ref, toRefs } from 'vue'
|
|
75
|
+
import type { IAddressPickerEmits } from './typing'
|
|
76
|
+
import address from '../../libs/utils/address.json'
|
|
77
|
+
import addressPickerProps from './props'
|
|
78
|
+
import { useTranslate } from '../../libs'
|
|
79
|
+
// 组件
|
|
80
|
+
import HyInput from '../hy-input/hy-input.vue'
|
|
81
|
+
import HyPicker from '../hy-picker/hy-picker.vue'
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 此选择器用于选择地址
|
|
85
|
+
* @displayName hy-address-picker
|
|
86
|
+
*/
|
|
87
|
+
defineOptions({})
|
|
88
|
+
|
|
89
|
+
const props = defineProps(addressPickerProps)
|
|
90
|
+
const { show, modelValue, hasInput, input, separator, closeOnClickOverlay } = toRefs(props)
|
|
91
|
+
const emit = defineEmits<IAddressPickerEmits>()
|
|
92
|
+
|
|
93
|
+
const { t } = useTranslate('addressPicker')
|
|
94
|
+
// 原来的日期选择器不方便,这里增加一个hasInput选项支持类似element的自带输入框的功能。
|
|
95
|
+
const inputValue = ref<string>('') // 表单显示值
|
|
96
|
+
const showByClickInput = ref<boolean>(false) // 是否在hasInput模式下显示日期选择
|
|
97
|
+
const columns = ref<any[]>([])
|
|
98
|
+
const uPickerRef = ref<InstanceType<typeof HyPicker> | null>()
|
|
99
|
+
const defaultIndex = ref<number[]>([])
|
|
100
|
+
|
|
101
|
+
function normalizeCityName(city: string) {
|
|
102
|
+
// 定义常见的后缀
|
|
103
|
+
const suffixes = ['市', '省', '自治区', '特别行政区', '县', '区']
|
|
104
|
+
suffixes.forEach((suffix) => {
|
|
105
|
+
if (city.endsWith(suffix)) {
|
|
106
|
+
city = city.slice(0, -suffix.length)
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
return city
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @description 判断城市是否相等
|
|
113
|
+
* */
|
|
114
|
+
const areCitiesEqual = (city1: string, city2: string) => {
|
|
115
|
+
const normalizedCity1 = normalizeCityName(city1)
|
|
116
|
+
const normalizedCity2 = normalizeCityName(city2)
|
|
117
|
+
return normalizedCity1 === normalizedCity2
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @description 更新各列的值
|
|
121
|
+
* */
|
|
122
|
+
const updateColumnValue = (value: string) => {
|
|
123
|
+
let provinceIndex, cityIndex, countyIndex
|
|
124
|
+
// 判断是初始化有数据就找到对应索引,无数据默认索引为0
|
|
125
|
+
if (value) {
|
|
126
|
+
const addressArr = value.split(separator.value)
|
|
127
|
+
// 查出省索引
|
|
128
|
+
provinceIndex = address.findIndex((item) => areCitiesEqual(item.name, addressArr[0]))
|
|
129
|
+
// 查出市索引
|
|
130
|
+
cityIndex = address[provinceIndex].areas.findIndex((item) =>
|
|
131
|
+
areCitiesEqual(item.name, addressArr[1])
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
// 查出县/区索引
|
|
135
|
+
countyIndex = address[provinceIndex].areas[cityIndex].areas.findIndex((item) =>
|
|
136
|
+
areCitiesEqual(item.name, addressArr[2])
|
|
137
|
+
)
|
|
138
|
+
} else {
|
|
139
|
+
provinceIndex = 0
|
|
140
|
+
cityIndex = 0
|
|
141
|
+
countyIndex = 0
|
|
142
|
+
}
|
|
143
|
+
// 省级数组
|
|
144
|
+
const provinceData = address.map((item) => ({
|
|
145
|
+
name: item.name,
|
|
146
|
+
code: item.code
|
|
147
|
+
}))
|
|
148
|
+
// 市级数组
|
|
149
|
+
const cityData = address[provinceIndex].areas.map((item) => ({
|
|
150
|
+
name: item.name,
|
|
151
|
+
code: item.code
|
|
152
|
+
}))
|
|
153
|
+
// 县/区级数组
|
|
154
|
+
const areaData = address[provinceIndex].areas[cityIndex].areas
|
|
155
|
+
|
|
156
|
+
// 默认索引
|
|
157
|
+
defaultIndex.value = [provinceIndex, cityIndex, countyIndex]
|
|
158
|
+
// 列表
|
|
159
|
+
columns.value = [provinceData, cityData, areaData]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const init = () => {
|
|
163
|
+
// 获取当前值
|
|
164
|
+
inputValue.value = modelValue.value
|
|
165
|
+
// 更新列表
|
|
166
|
+
updateColumnValue(modelValue.value)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
onMounted(() => {
|
|
170
|
+
init()
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @description 关闭选择器
|
|
175
|
+
* */
|
|
176
|
+
const close = () => {
|
|
177
|
+
if (closeOnClickOverlay.value) {
|
|
178
|
+
if (hasInput.value) {
|
|
179
|
+
showByClickInput.value = false
|
|
180
|
+
}
|
|
181
|
+
emit('close')
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @description 点击工具栏的取消按钮
|
|
187
|
+
* */
|
|
188
|
+
const cancel = () => {
|
|
189
|
+
if (hasInput.value) {
|
|
190
|
+
showByClickInput.value = false
|
|
191
|
+
}
|
|
192
|
+
emit('cancel')
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @description 点击工具栏的确定按钮
|
|
197
|
+
* */
|
|
198
|
+
const confirm = ({ value }: { value: Record<string, any>[] }) => {
|
|
199
|
+
inputValue.value = value.map((item) => item.name).join(separator.value)
|
|
200
|
+
|
|
201
|
+
showByClickInput.value = false
|
|
202
|
+
emit('update:modelValue', inputValue.value)
|
|
203
|
+
emit('confirm', {
|
|
204
|
+
value: inputValue.value
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @description 列发生变化时触发
|
|
210
|
+
* */
|
|
211
|
+
const change = (e: any) => {
|
|
212
|
+
const { columnIndex, index, indexs } = e
|
|
213
|
+
//如果改变的是第一列
|
|
214
|
+
if (columnIndex === 0) {
|
|
215
|
+
const children1 = address[index].areas.map((item) => {
|
|
216
|
+
return { name: item.name, code: item.code }
|
|
217
|
+
})
|
|
218
|
+
uPickerRef.value?.setColumnValues(1, children1)
|
|
219
|
+
//更换 第二列数据
|
|
220
|
+
const children2 = address[index].areas[indexs[1]].areas.map((item) => ({
|
|
221
|
+
...item
|
|
222
|
+
}))
|
|
223
|
+
uPickerRef.value?.setColumnValues(2, children2)
|
|
224
|
+
//更换 第三列数据
|
|
225
|
+
}
|
|
226
|
+
if (columnIndex === 1) {
|
|
227
|
+
//如果改变的是第二列
|
|
228
|
+
const children3 = address[indexs[0]].areas[indexs[1]].areas.map((item) => ({
|
|
229
|
+
...item
|
|
230
|
+
}))
|
|
231
|
+
uPickerRef.value?.setColumnValues(2, children3)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 发出change时间,value为当前选中的时间戳
|
|
235
|
+
emit('change', {
|
|
236
|
+
...e
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const onShowByClickInput = () => {
|
|
241
|
+
if (!props.input?.disabled) {
|
|
242
|
+
showByClickInput.value = !showByClickInput.value
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
</script>
|
|
246
|
+
|
|
247
|
+
<style lang="scss" scoped>
|
|
248
|
+
@import './index.scss';
|
|
249
|
+
</style>
|