uview-pro 0.2.4 → 0.3.1
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/changelog.md +584 -545
- package/components/common/props.ts +22 -22
- package/components/u-action-sheet/types.ts +37 -35
- package/components/u-action-sheet/u-action-sheet.vue +178 -167
- package/components/u-alert-tips/types.ts +41 -39
- package/components/u-alert-tips/u-alert-tips.vue +238 -223
- package/components/u-avatar/types.ts +36 -34
- package/components/u-avatar/u-avatar.vue +217 -207
- package/components/u-avatar-cropper/types.ts +23 -23
- package/components/u-avatar-cropper/u-avatar-cropper.vue +297 -286
- package/components/u-avatar-cropper/weCropper.d.ts +62 -62
- package/components/u-avatar-cropper/weCropper.js +1281 -1281
- package/components/u-avatar-cropper/weCropper.ts +1276 -1276
- package/components/u-back-top/types.ts +36 -39
- package/components/u-back-top/u-back-top.vue +140 -128
- package/components/u-badge/types.ts +38 -36
- package/components/u-badge/u-badge.vue +183 -165
- package/components/u-button/types.ts +66 -66
- package/components/u-button/u-button.vue +579 -566
- package/components/u-calendar/types.ts +75 -75
- package/components/u-calendar/u-calendar.vue +793 -793
- package/components/u-car-keyboard/types.ts +14 -12
- package/components/u-car-keyboard/u-car-keyboard.vue +262 -253
- package/components/u-card/types.ts +61 -59
- package/components/u-card/u-card.vue +209 -194
- package/components/u-cell-group/types.ts +19 -17
- package/components/u-cell-group/u-cell-group.vue +60 -50
- package/components/u-cell-item/types.ts +56 -54
- package/components/u-cell-item/u-cell-item.vue +226 -213
- package/components/u-checkbox/types.ts +33 -31
- package/components/u-checkbox/u-checkbox.vue +282 -283
- package/components/u-checkbox-group/types.ts +34 -32
- package/components/u-checkbox-group/u-checkbox-group.vue +130 -130
- package/components/u-circle-progress/types.ts +54 -52
- package/components/u-circle-progress/u-circle-progress.vue +206 -191
- package/components/u-city-select/types.ts +22 -20
- package/components/u-city-select/u-city-select.vue +276 -264
- package/components/u-col/types.ts +32 -30
- package/components/u-col/u-col.vue +142 -123
- package/components/u-collapse/types.ts +33 -33
- package/components/u-collapse/u-collapse.vue +190 -186
- package/components/u-collapse-item/types.ts +27 -27
- package/components/u-collapse-item/u-collapse-item.vue +290 -285
- package/components/u-column-notice/types.ts +50 -48
- package/components/u-column-notice/u-column-notice.vue +222 -210
- package/components/u-count-down/types.ts +44 -42
- package/components/u-count-down/u-count-down.vue +286 -274
- package/components/u-count-to/types.ts +34 -32
- package/components/u-count-to/u-count-to.vue +266 -248
- package/components/u-divider/types.ts +33 -31
- package/components/u-divider/u-divider.vue +145 -129
- package/components/u-dropdown/types.ts +34 -32
- package/components/u-dropdown/u-dropdown.vue +330 -302
- package/components/u-dropdown-item/types.ts +29 -27
- package/components/u-dropdown-item/u-dropdown-item.vue +120 -128
- package/components/u-empty/types.ts +38 -36
- package/components/u-empty/u-empty.vue +103 -88
- package/components/u-field/types.ts +71 -69
- package/components/u-field/u-field.vue +388 -373
- package/components/u-form/types.ts +29 -27
- package/components/u-form/u-form.vue +130 -136
- package/components/u-form-item/types.ts +72 -70
- package/components/u-form-item/u-form-item.vue +447 -447
- package/components/u-full-screen/types.ts +16 -14
- package/components/u-full-screen/u-full-screen.vue +103 -89
- package/components/u-gap/types.ts +20 -18
- package/components/u-gap/u-gap.vue +50 -40
- package/components/u-grid/types.ts +21 -19
- package/components/u-grid/u-grid.vue +91 -93
- package/components/u-grid-item/types.ts +16 -16
- package/components/u-grid-item/u-grid-item.vue +130 -134
- package/components/u-icon/types.ts +61 -62
- package/components/u-icon/u-icon.vue +296 -294
- package/components/u-image/types.ts +51 -51
- package/components/u-image/u-image.vue +239 -230
- package/components/u-index-anchor/types.ts +16 -16
- package/components/u-index-anchor/u-index-anchor.vue +94 -86
- package/components/u-index-list/types.ts +43 -43
- package/components/u-index-list/u-index-list.vue +352 -355
- package/components/u-input/types.ts +137 -140
- package/components/u-input/u-input.vue +288 -279
- package/components/u-keyboard/types.ts +40 -40
- package/components/u-keyboard/u-keyboard.vue +178 -169
- package/components/u-lazy-load/types.ts +37 -37
- package/components/u-lazy-load/u-lazy-load.vue +246 -235
- package/components/u-line/types.ts +44 -44
- package/components/u-line/u-line.vue +68 -59
- package/components/u-line-progress/types.ts +58 -58
- package/components/u-line-progress/u-line-progress.vue +126 -117
- package/components/u-link/types.ts +43 -43
- package/components/u-link/u-link.vue +84 -75
- package/components/u-loading/types.ts +35 -35
- package/components/u-loading/u-loading.vue +105 -96
- package/components/u-loading-popup/types.ts +26 -26
- package/components/u-loading-popup/u-loading-popup.vue +253 -239
- package/components/u-loadmore/types.ts +79 -79
- package/components/u-loadmore/u-loadmore.vue +156 -145
- package/components/u-mask/types.ts +40 -43
- package/components/u-mask/u-mask.vue +113 -106
- package/components/u-message-input/types.ts +74 -74
- package/components/u-message-input/u-message-input.vue +281 -270
- package/components/u-modal/types.ts +118 -118
- package/components/u-modal/u-modal.vue +220 -211
- package/components/u-navbar/types.ts +103 -103
- package/components/u-navbar/u-navbar.vue +251 -240
- package/components/u-no-network/image.ts +2 -2
- package/components/u-no-network/types.ts +28 -28
- package/components/u-no-network/u-no-network.vue +303 -292
- package/components/u-notice-bar/types.ts +111 -111
- package/components/u-notice-bar/u-notice-bar.vue +189 -179
- package/components/u-number-box/types.ts +42 -42
- package/components/u-number-box/u-number-box.vue +321 -312
- package/components/u-number-keyboard/types.ts +26 -26
- package/components/u-number-keyboard/u-number-keyboard.vue +188 -179
- package/components/u-picker/types.ts +123 -123
- package/components/u-picker/u-picker.vue +685 -676
- package/components/u-popup/types.ts +59 -59
- package/components/u-popup/u-popup.vue +385 -375
- package/components/u-radio/types.ts +27 -25
- package/components/u-radio/u-radio.vue +279 -272
- package/components/u-radio-group/types.ts +31 -29
- package/components/u-radio-group/u-radio-group.vue +96 -108
- package/components/u-rate/types.ts +42 -40
- package/components/u-rate/u-rate.vue +249 -234
- package/components/u-read-more/types.ts +37 -35
- package/components/u-read-more/u-read-more.vue +172 -156
- package/components/u-root-portal/u-root-portal.vue +56 -54
- package/components/u-row/types.ts +22 -20
- package/components/u-row/u-row.vue +105 -87
- package/components/u-row-notice/types.ts +41 -39
- package/components/u-row-notice/u-row-notice.vue +256 -244
- package/components/u-safe-bottom/u-safe-bottom.vue +57 -46
- package/components/u-search/types.ts +55 -53
- package/components/u-search/u-search.vue +279 -268
- package/components/u-section/types.ts +34 -32
- package/components/u-section/u-section.vue +150 -131
- package/components/u-select/types.ts +45 -43
- package/components/u-select/u-select.vue +388 -378
- package/components/u-skeleton/types.ts +22 -20
- package/components/u-skeleton/u-skeleton.vue +231 -220
- package/components/u-slider/types.ts +34 -32
- package/components/u-slider/u-slider.vue +255 -247
- package/components/u-status-bar/u-status-bar.vue +74 -65
- package/components/u-steps/types.ts +30 -28
- package/components/u-steps/u-steps.vue +181 -169
- package/components/u-sticky/types.ts +24 -22
- package/components/u-sticky/u-sticky.vue +178 -162
- package/components/u-subsection/types.ts +38 -36
- package/components/u-subsection/u-subsection.vue +339 -328
- package/components/u-swipe-action/types.ts +52 -50
- package/components/u-swipe-action/u-swipe-action.vue +276 -260
- package/components/u-swiper/types.ts +49 -47
- package/components/u-swiper/u-swiper.vue +308 -291
- package/components/u-switch/types.ts +30 -28
- package/components/u-switch/u-switch.vue +150 -141
- package/components/u-tabbar/types.ts +38 -36
- package/components/u-tabbar/u-tabbar.vue +315 -298
- package/components/u-table/types.ts +27 -25
- package/components/u-table/u-table.vue +67 -55
- package/components/u-tabs/types.ts +53 -51
- package/components/u-tabs/u-tabs.vue +302 -291
- package/components/u-tabs-swiper/types.ts +55 -53
- package/components/u-tabs-swiper/u-tabs-swiper.vue +409 -397
- package/components/u-tag/types.ts +39 -37
- package/components/u-tag/u-tag.vue +268 -252
- package/components/u-td/types.ts +14 -12
- package/components/u-td/u-td.vue +98 -87
- package/components/u-text/types.ts +72 -72
- package/components/u-text/u-text.vue +343 -341
- package/components/u-th/types.ts +14 -12
- package/components/u-th/u-th.vue +92 -81
- package/components/u-time-line/u-time-line.vue +53 -39
- package/components/u-time-line-item/types.ts +16 -14
- package/components/u-time-line-item/u-time-line-item.vue +90 -78
- package/components/u-toast/types.ts +38 -36
- package/components/u-toast/u-toast.vue +240 -233
- package/components/u-top-tips/types.ts +16 -14
- package/components/u-top-tips/u-top-tips.vue +130 -113
- package/components/u-tr/types.ts +11 -8
- package/components/u-tr/u-tr.vue +39 -24
- package/components/u-upload/types.ts +82 -80
- package/components/u-upload/u-upload.vue +568 -559
- package/components/u-verification-code/types.ts +24 -22
- package/components/u-verification-code/u-verification-code.vue +176 -164
- package/components/u-waterfall/types.ts +18 -16
- package/components/u-waterfall/u-waterfall.vue +187 -175
- package/iconfont.css +913 -913
- package/index.scss +25 -25
- package/index.ts +38 -38
- package/libs/config/config.ts +26 -26
- package/libs/config/zIndex.ts +37 -37
- package/libs/css/color.scss +155 -155
- package/libs/css/common.scss +178 -178
- package/libs/css/style.components.scss +16 -16
- package/libs/css/style.h5.scss +8 -8
- package/libs/css/style.mp.scss +72 -72
- package/libs/css/style.nvue.scss +15 -15
- package/libs/css/style.vue.scss +188 -188
- package/libs/function/$parent.ts +24 -24
- package/libs/function/addUnit.ts +13 -13
- package/libs/function/color.ts +37 -37
- package/libs/function/colorGradient.ts +139 -139
- package/libs/function/debounce.ts +28 -28
- package/libs/function/deepClone.ts +39 -39
- package/libs/function/deepMerge.ts +35 -35
- package/libs/function/getParent.ts +63 -63
- package/libs/function/getRect.ts +26 -26
- package/libs/function/guid.ts +42 -42
- package/libs/function/md5.ts +403 -403
- package/libs/function/parent.ts +21 -21
- package/libs/function/queryParams.ts +64 -64
- package/libs/function/random.ts +16 -16
- package/libs/function/randomArray.ts +11 -11
- package/libs/function/route.ts +118 -118
- package/libs/function/styleUtils.ts +83 -83
- package/libs/function/sys.ts +15 -15
- package/libs/function/test.ts +289 -289
- package/libs/function/throttle.ts +31 -31
- package/libs/function/timeFormat.ts +55 -55
- package/libs/function/timeFrom.ts +48 -48
- package/libs/function/toast.ts +14 -14
- package/libs/function/trim.ts +21 -21
- package/libs/function/type2icon.ts +39 -39
- package/libs/hooks/index.ts +4 -3
- package/libs/hooks/useCompRelation.ts +364 -0
- package/libs/hooks/useComponent.ts +759 -759
- package/libs/hooks/useEmitter.ts +79 -79
- package/libs/hooks/useParent.ts +33 -33
- package/libs/hooks/useRect.ts +33 -33
- package/libs/index.ts +337 -320
- package/libs/request/auto-http.ts +76 -76
- package/libs/request/index.ts +242 -242
- package/libs/store/index.ts +88 -88
- package/libs/util/async-validator.d.ts +75 -75
- package/libs/util/async-validator.js +1 -1
- package/libs/util/calendar.d.ts +57 -57
- package/libs/util/emitter.ts +112 -112
- package/libs/util/eventBus.ts +86 -86
- package/libs/util/logger.ts +364 -364
- package/libs/util/mitt.ts +118 -118
- package/libs/util/parent.ts +20 -20
- package/package.json +4 -4
- package/readme.md +241 -241
- package/theme.scss +38 -38
- package/types/components.d.ts +97 -97
- package/types/global.d.ts +331 -331
- package/types/ignore-errors.d.ts +30 -30
- package/types/index.d.ts +19 -19
- package/types/uni-app.d.ts +63 -63
|
@@ -1,676 +1,685 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<u-popup
|
|
3
|
-
:maskCloseAble="maskCloseAble"
|
|
4
|
-
mode="bottom"
|
|
5
|
-
:popup="false"
|
|
6
|
-
v-model="popupValue"
|
|
7
|
-
length="auto"
|
|
8
|
-
:safeAreaInsetBottom="safeAreaInsetBottom"
|
|
9
|
-
@close="close"
|
|
10
|
-
:z-index="uZIndex"
|
|
11
|
-
>
|
|
12
|
-
<view class="u-datetime-picker">
|
|
13
|
-
<view class="u-picker-header" @touchmove.stop.prevent="">
|
|
14
|
-
<view
|
|
15
|
-
class="u-btn-picker u-btn-picker--tips"
|
|
16
|
-
:style="{ color: cancelColor }"
|
|
17
|
-
hover-class="u-opacity"
|
|
18
|
-
:hover-stay-time="150"
|
|
19
|
-
@tap="getResult('cancel')"
|
|
20
|
-
>
|
|
21
|
-
{{ cancelText }}
|
|
22
|
-
</view>
|
|
23
|
-
<view class="u-picker__title">{{ title }}</view>
|
|
24
|
-
<view
|
|
25
|
-
class="u-btn-picker u-btn-picker--primary"
|
|
26
|
-
:style="{ color: moving ? cancelColor : confirmColor }"
|
|
27
|
-
hover-class="u-opacity"
|
|
28
|
-
:hover-stay-time="150"
|
|
29
|
-
@touchmove.stop=""
|
|
30
|
-
@tap.stop="getResult('confirm')"
|
|
31
|
-
>
|
|
32
|
-
{{ confirmText }}
|
|
33
|
-
</view>
|
|
34
|
-
</view>
|
|
35
|
-
<view class="u-picker-body">
|
|
36
|
-
<picker-view
|
|
37
|
-
v-if="mode == 'region'"
|
|
38
|
-
:value="valueArr"
|
|
39
|
-
@change="change"
|
|
40
|
-
class="u-picker-view"
|
|
41
|
-
@pickstart="pickstart"
|
|
42
|
-
@pickend="pickend"
|
|
43
|
-
>
|
|
44
|
-
<picker-view-column v-if="!reset && params.province">
|
|
45
|
-
<view class="u-column-item" v-for="(item, index) in provinces" :key="index">
|
|
46
|
-
<view class="u-line-1">{{ item.label }}</view>
|
|
47
|
-
</view>
|
|
48
|
-
</picker-view-column>
|
|
49
|
-
<picker-view-column v-if="!reset && params.city">
|
|
50
|
-
<view class="u-column-item" v-for="(item, index) in citysRef" :key="index">
|
|
51
|
-
<view class="u-line-1">{{ item.label }}</view>
|
|
52
|
-
</view>
|
|
53
|
-
</picker-view-column>
|
|
54
|
-
<picker-view-column v-if="!reset && params.area">
|
|
55
|
-
<view class="u-column-item" v-for="(item, index) in areasRef" :key="index">
|
|
56
|
-
<view class="u-line-1">{{ item.label }}</view>
|
|
57
|
-
</view>
|
|
58
|
-
</picker-view-column>
|
|
59
|
-
</picker-view>
|
|
60
|
-
<picker-view
|
|
61
|
-
v-else-if="mode == 'time'"
|
|
62
|
-
:value="valueArr"
|
|
63
|
-
@change="change"
|
|
64
|
-
class="u-picker-view"
|
|
65
|
-
@pickstart="pickstart"
|
|
66
|
-
@pickend="pickend"
|
|
67
|
-
>
|
|
68
|
-
<picker-view-column v-if="!reset && params.year">
|
|
69
|
-
<view class="u-column-item" v-for="(item, index) in years" :key="index">
|
|
70
|
-
{{ item }}
|
|
71
|
-
<text class="u-text" v-if="showTimeTag">年</text>
|
|
72
|
-
</view>
|
|
73
|
-
</picker-view-column>
|
|
74
|
-
<picker-view-column v-if="!reset && params.month">
|
|
75
|
-
<view class="u-column-item" v-for="(item, index) in months" :key="index">
|
|
76
|
-
{{ formatNumber(item) }}
|
|
77
|
-
<text class="u-text" v-if="showTimeTag">月</text>
|
|
78
|
-
</view>
|
|
79
|
-
</picker-view-column>
|
|
80
|
-
<picker-view-column v-if="!reset && params.day">
|
|
81
|
-
<view class="u-column-item" v-for="(item, index) in days" :key="index">
|
|
82
|
-
{{ formatNumber(item) }}
|
|
83
|
-
<text class="u-text" v-if="showTimeTag">日</text>
|
|
84
|
-
</view>
|
|
85
|
-
</picker-view-column>
|
|
86
|
-
<picker-view-column v-if="!reset && params.hour">
|
|
87
|
-
<view class="u-column-item" v-for="(item, index) in hours" :key="index">
|
|
88
|
-
{{ formatNumber(item) }}
|
|
89
|
-
<text class="u-text" v-if="showTimeTag">时</text>
|
|
90
|
-
</view>
|
|
91
|
-
</picker-view-column>
|
|
92
|
-
<picker-view-column v-if="!reset && params.minute">
|
|
93
|
-
<view class="u-column-item" v-for="(item, index) in minutes" :key="index">
|
|
94
|
-
{{ formatNumber(item) }}
|
|
95
|
-
<text class="u-text" v-if="showTimeTag">分</text>
|
|
96
|
-
</view>
|
|
97
|
-
</picker-view-column>
|
|
98
|
-
<picker-view-column v-if="!reset && params.second">
|
|
99
|
-
<view class="u-column-item" v-for="(item, index) in seconds" :key="index">
|
|
100
|
-
{{ formatNumber(item) }}
|
|
101
|
-
<text class="u-text" v-if="showTimeTag">秒</text>
|
|
102
|
-
</view>
|
|
103
|
-
</picker-view-column>
|
|
104
|
-
</picker-view>
|
|
105
|
-
<picker-view
|
|
106
|
-
v-else-if="mode == 'selector'"
|
|
107
|
-
:value="valueArr"
|
|
108
|
-
@change="change"
|
|
109
|
-
class="u-picker-view"
|
|
110
|
-
@pickstart="pickstart"
|
|
111
|
-
@pickend="pickend"
|
|
112
|
-
>
|
|
113
|
-
<picker-view-column v-if="!reset">
|
|
114
|
-
<view class="u-column-item" v-for="(item, index) in range" :key="index">
|
|
115
|
-
<view class="u-line-1">{{ getItemValue(item, 'selector') }}</view>
|
|
116
|
-
</view>
|
|
117
|
-
</picker-view-column>
|
|
118
|
-
</picker-view>
|
|
119
|
-
<picker-view
|
|
120
|
-
v-else-if="mode == 'multiSelector'"
|
|
121
|
-
:value="valueArr"
|
|
122
|
-
@change="change"
|
|
123
|
-
class="u-picker-view"
|
|
124
|
-
@pickstart="pickstart"
|
|
125
|
-
@pickend="pickend"
|
|
126
|
-
>
|
|
127
|
-
<picker-view-column v-if="!reset" v-for="(item, index) in range" :key="index">
|
|
128
|
-
<view class="u-column-item" v-for="(item1, index1) in item" :key="index1">
|
|
129
|
-
<view class="u-line-1">{{ getItemValue(item1, 'multiSelector') }}</view>
|
|
130
|
-
</view>
|
|
131
|
-
</picker-view-column>
|
|
132
|
-
</picker-view>
|
|
133
|
-
</view>
|
|
134
|
-
</view>
|
|
135
|
-
</u-popup>
|
|
136
|
-
</template>
|
|
137
|
-
|
|
138
|
-
<script
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
*
|
|
160
|
-
* @
|
|
161
|
-
* @
|
|
162
|
-
* @property {
|
|
163
|
-
* @property {String}
|
|
164
|
-
* @property {String}
|
|
165
|
-
* @property {String}
|
|
166
|
-
* @property {Boolean}
|
|
167
|
-
* @property {
|
|
168
|
-
* @property {
|
|
169
|
-
* @property {
|
|
170
|
-
* @property {String}
|
|
171
|
-
* @
|
|
172
|
-
* @
|
|
173
|
-
* @
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
//
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
//
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
*
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
let
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (props.params.
|
|
357
|
-
valueArr.value.push(0);
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
if (props.params.
|
|
361
|
-
valueArr.value.push(0);
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
*
|
|
387
|
-
*/
|
|
388
|
-
function
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
valueArr.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if
|
|
527
|
-
if (props.params.
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
(props.
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
if (
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
if (props.params.
|
|
565
|
-
if (props.params.
|
|
566
|
-
if (props.params.
|
|
567
|
-
|
|
568
|
-
//
|
|
569
|
-
result =
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
content:
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
.u-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
padding:
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<u-popup
|
|
3
|
+
:maskCloseAble="maskCloseAble"
|
|
4
|
+
mode="bottom"
|
|
5
|
+
:popup="false"
|
|
6
|
+
v-model="popupValue"
|
|
7
|
+
length="auto"
|
|
8
|
+
:safeAreaInsetBottom="safeAreaInsetBottom"
|
|
9
|
+
@close="close"
|
|
10
|
+
:z-index="uZIndex"
|
|
11
|
+
>
|
|
12
|
+
<view class="u-datetime-picker">
|
|
13
|
+
<view class="u-picker-header" @touchmove.stop.prevent="">
|
|
14
|
+
<view
|
|
15
|
+
class="u-btn-picker u-btn-picker--tips"
|
|
16
|
+
:style="{ color: cancelColor }"
|
|
17
|
+
hover-class="u-opacity"
|
|
18
|
+
:hover-stay-time="150"
|
|
19
|
+
@tap="getResult('cancel')"
|
|
20
|
+
>
|
|
21
|
+
{{ cancelText }}
|
|
22
|
+
</view>
|
|
23
|
+
<view class="u-picker__title">{{ title }}</view>
|
|
24
|
+
<view
|
|
25
|
+
class="u-btn-picker u-btn-picker--primary"
|
|
26
|
+
:style="{ color: moving ? cancelColor : confirmColor }"
|
|
27
|
+
hover-class="u-opacity"
|
|
28
|
+
:hover-stay-time="150"
|
|
29
|
+
@touchmove.stop=""
|
|
30
|
+
@tap.stop="getResult('confirm')"
|
|
31
|
+
>
|
|
32
|
+
{{ confirmText }}
|
|
33
|
+
</view>
|
|
34
|
+
</view>
|
|
35
|
+
<view class="u-picker-body">
|
|
36
|
+
<picker-view
|
|
37
|
+
v-if="mode == 'region'"
|
|
38
|
+
:value="valueArr"
|
|
39
|
+
@change="change"
|
|
40
|
+
class="u-picker-view"
|
|
41
|
+
@pickstart="pickstart"
|
|
42
|
+
@pickend="pickend"
|
|
43
|
+
>
|
|
44
|
+
<picker-view-column v-if="!reset && params.province">
|
|
45
|
+
<view class="u-column-item" v-for="(item, index) in provinces" :key="index">
|
|
46
|
+
<view class="u-line-1">{{ item.label }}</view>
|
|
47
|
+
</view>
|
|
48
|
+
</picker-view-column>
|
|
49
|
+
<picker-view-column v-if="!reset && params.city">
|
|
50
|
+
<view class="u-column-item" v-for="(item, index) in citysRef" :key="index">
|
|
51
|
+
<view class="u-line-1">{{ item.label }}</view>
|
|
52
|
+
</view>
|
|
53
|
+
</picker-view-column>
|
|
54
|
+
<picker-view-column v-if="!reset && params.area">
|
|
55
|
+
<view class="u-column-item" v-for="(item, index) in areasRef" :key="index">
|
|
56
|
+
<view class="u-line-1">{{ item.label }}</view>
|
|
57
|
+
</view>
|
|
58
|
+
</picker-view-column>
|
|
59
|
+
</picker-view>
|
|
60
|
+
<picker-view
|
|
61
|
+
v-else-if="mode == 'time'"
|
|
62
|
+
:value="valueArr"
|
|
63
|
+
@change="change"
|
|
64
|
+
class="u-picker-view"
|
|
65
|
+
@pickstart="pickstart"
|
|
66
|
+
@pickend="pickend"
|
|
67
|
+
>
|
|
68
|
+
<picker-view-column v-if="!reset && params.year">
|
|
69
|
+
<view class="u-column-item" v-for="(item, index) in years" :key="index">
|
|
70
|
+
{{ item }}
|
|
71
|
+
<text class="u-text" v-if="showTimeTag">年</text>
|
|
72
|
+
</view>
|
|
73
|
+
</picker-view-column>
|
|
74
|
+
<picker-view-column v-if="!reset && params.month">
|
|
75
|
+
<view class="u-column-item" v-for="(item, index) in months" :key="index">
|
|
76
|
+
{{ formatNumber(item) }}
|
|
77
|
+
<text class="u-text" v-if="showTimeTag">月</text>
|
|
78
|
+
</view>
|
|
79
|
+
</picker-view-column>
|
|
80
|
+
<picker-view-column v-if="!reset && params.day">
|
|
81
|
+
<view class="u-column-item" v-for="(item, index) in days" :key="index">
|
|
82
|
+
{{ formatNumber(item) }}
|
|
83
|
+
<text class="u-text" v-if="showTimeTag">日</text>
|
|
84
|
+
</view>
|
|
85
|
+
</picker-view-column>
|
|
86
|
+
<picker-view-column v-if="!reset && params.hour">
|
|
87
|
+
<view class="u-column-item" v-for="(item, index) in hours" :key="index">
|
|
88
|
+
{{ formatNumber(item) }}
|
|
89
|
+
<text class="u-text" v-if="showTimeTag">时</text>
|
|
90
|
+
</view>
|
|
91
|
+
</picker-view-column>
|
|
92
|
+
<picker-view-column v-if="!reset && params.minute">
|
|
93
|
+
<view class="u-column-item" v-for="(item, index) in minutes" :key="index">
|
|
94
|
+
{{ formatNumber(item) }}
|
|
95
|
+
<text class="u-text" v-if="showTimeTag">分</text>
|
|
96
|
+
</view>
|
|
97
|
+
</picker-view-column>
|
|
98
|
+
<picker-view-column v-if="!reset && params.second">
|
|
99
|
+
<view class="u-column-item" v-for="(item, index) in seconds" :key="index">
|
|
100
|
+
{{ formatNumber(item) }}
|
|
101
|
+
<text class="u-text" v-if="showTimeTag">秒</text>
|
|
102
|
+
</view>
|
|
103
|
+
</picker-view-column>
|
|
104
|
+
</picker-view>
|
|
105
|
+
<picker-view
|
|
106
|
+
v-else-if="mode == 'selector'"
|
|
107
|
+
:value="valueArr"
|
|
108
|
+
@change="change"
|
|
109
|
+
class="u-picker-view"
|
|
110
|
+
@pickstart="pickstart"
|
|
111
|
+
@pickend="pickend"
|
|
112
|
+
>
|
|
113
|
+
<picker-view-column v-if="!reset">
|
|
114
|
+
<view class="u-column-item" v-for="(item, index) in range" :key="index">
|
|
115
|
+
<view class="u-line-1">{{ getItemValue(item, 'selector') }}</view>
|
|
116
|
+
</view>
|
|
117
|
+
</picker-view-column>
|
|
118
|
+
</picker-view>
|
|
119
|
+
<picker-view
|
|
120
|
+
v-else-if="mode == 'multiSelector'"
|
|
121
|
+
:value="valueArr"
|
|
122
|
+
@change="change"
|
|
123
|
+
class="u-picker-view"
|
|
124
|
+
@pickstart="pickstart"
|
|
125
|
+
@pickend="pickend"
|
|
126
|
+
>
|
|
127
|
+
<picker-view-column v-if="!reset" v-for="(item, index) in range" :key="index">
|
|
128
|
+
<view class="u-column-item" v-for="(item1, index1) in item" :key="index1">
|
|
129
|
+
<view class="u-line-1">{{ getItemValue(item1, 'multiSelector') }}</view>
|
|
130
|
+
</view>
|
|
131
|
+
</picker-view-column>
|
|
132
|
+
</picker-view>
|
|
133
|
+
</view>
|
|
134
|
+
</view>
|
|
135
|
+
</u-popup>
|
|
136
|
+
</template>
|
|
137
|
+
|
|
138
|
+
<script lang="ts">
|
|
139
|
+
export default {
|
|
140
|
+
name: 'u-picker',
|
|
141
|
+
options: {
|
|
142
|
+
addGlobalClass: true,
|
|
143
|
+
// #ifndef MP-TOUTIAO
|
|
144
|
+
virtualHost: true,
|
|
145
|
+
// #endif
|
|
146
|
+
styleIsolation: 'shared'
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
</script>
|
|
150
|
+
|
|
151
|
+
<script setup lang="ts">
|
|
152
|
+
import { ref, computed, watch, onMounted, nextTick } from 'vue';
|
|
153
|
+
import provinces from '../../libs/util/province';
|
|
154
|
+
import citys from '../../libs/util/city';
|
|
155
|
+
import areas from '../../libs/util/area';
|
|
156
|
+
import { PickerProps } from './types';
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* picker picker弹出选择器
|
|
160
|
+
* @description 此选择器有两种弹出模式:一是时间模式,可以配置年,日,月,时,分,秒参数 二是地区模式,可以配置省,市,区参数
|
|
161
|
+
* @tutorial https://uviewpro.cn/zh/components/picker.html
|
|
162
|
+
* @property {Object} params 需要显示的参数,见官网说明
|
|
163
|
+
* @property {String} mode 模式选择,region-地区类型,time-时间类型(默认time)
|
|
164
|
+
* @property {String Number} start-year 可选的开始年份,mode=time时有效(默认1950)
|
|
165
|
+
* @property {String Number} end-year 可选的结束年份,mode=time时有效(默认2050)
|
|
166
|
+
* @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
|
|
167
|
+
* @property {Boolean} show-time-tag 时间模式时,是否显示后面的年月日中文提示
|
|
168
|
+
* @property {String} cancel-color 取消按钮的颜色(默认#606266)
|
|
169
|
+
* @property {String} confirm-color 确认按钮的颜色(默认#2979ff)
|
|
170
|
+
* @property {String} default-time 默认选中的时间,mode=time时有效
|
|
171
|
+
* @property {String} confirm-text 确认按钮的文字
|
|
172
|
+
* @property {String} cancel-text 取消按钮的文字
|
|
173
|
+
* @property {String} default-region 默认选中的地区,中文形式,mode=region时有效
|
|
174
|
+
* @property {String} default-code 默认选中的地区,编号形式,mode=region时有效
|
|
175
|
+
* @property {Boolean} mask-close-able 是否允许通过点击遮罩关闭Picker(默认true)
|
|
176
|
+
* @property {String Number} z-index 弹出时的z-index值(默认1075)
|
|
177
|
+
* @property {Array} default-selector 数组形式,其中每一项表示选择了range对应项中的第几个
|
|
178
|
+
* @property {Array} range 自定义选择的数据,mode=selector或mode=multiSelector时有效
|
|
179
|
+
* @property {String} range-key 当range参数的元素为对象时,指定Object中的哪个key的值作为选择器显示内容
|
|
180
|
+
* @event {Function} confirm 点击确定按钮,返回当前选择的值
|
|
181
|
+
* @event {Function} cancel 点击取消按钮,返回当前选择的值
|
|
182
|
+
* @example <u-picker v-model="show" mode="time"></u-picker>
|
|
183
|
+
*/
|
|
184
|
+
const props = defineProps(PickerProps);
|
|
185
|
+
|
|
186
|
+
const popupValue = computed({
|
|
187
|
+
get: () => props.modelValue,
|
|
188
|
+
set: (val: boolean) => emit('update:modelValue', val)
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const emit = defineEmits(['update:modelValue', 'confirm', 'cancel', 'columnchange']);
|
|
192
|
+
|
|
193
|
+
// 主要数据
|
|
194
|
+
const years = ref<number[]>([]);
|
|
195
|
+
const months = ref<number[]>([]);
|
|
196
|
+
const days = ref<number[]>([]);
|
|
197
|
+
const hours = ref<number[]>([]);
|
|
198
|
+
const minutes = ref<number[]>([]);
|
|
199
|
+
const seconds = ref<number[]>([]);
|
|
200
|
+
const year = ref<number>(0);
|
|
201
|
+
const month = ref<number>(0);
|
|
202
|
+
const day = ref<number>(0);
|
|
203
|
+
const hour = ref<number>(0);
|
|
204
|
+
const minute = ref<number>(0);
|
|
205
|
+
const second = ref<number>(0);
|
|
206
|
+
const reset = ref(false);
|
|
207
|
+
const startDate = ref('');
|
|
208
|
+
const endDate = ref('');
|
|
209
|
+
const valueArr = ref<number[]>([]);
|
|
210
|
+
const provincesRef = ref<any[]>(provinces);
|
|
211
|
+
const citysRef = ref<any[]>(citys[0]);
|
|
212
|
+
const areasRef = ref<any[]>(areas[0][0]);
|
|
213
|
+
const province = ref<number>(0);
|
|
214
|
+
const city = ref<number>(0);
|
|
215
|
+
const area = ref<number>(0);
|
|
216
|
+
// 列是否还在滑动中,微信小程序如果在滑动中就点确定,结果可能不准确
|
|
217
|
+
const moving = ref(false);
|
|
218
|
+
const multiSelectorValue = ref<number[]>([]);
|
|
219
|
+
|
|
220
|
+
// 计算属性
|
|
221
|
+
// 引用这几个变量,是为了监听其变化
|
|
222
|
+
const propsChange = computed(
|
|
223
|
+
() =>
|
|
224
|
+
`${props.mode}-${props.defaultTime}-${props.startYear}-${props.endYear}-${props.defaultRegion}-${props.areaCode}`
|
|
225
|
+
);
|
|
226
|
+
// 引用这几个变量,是为了监听其变化
|
|
227
|
+
const regionChange = computed(() => `${province.value}-${city.value}`);
|
|
228
|
+
|
|
229
|
+
const yearAndMonth = computed(() => `${year.value}-${month.value}`);
|
|
230
|
+
// 如果用户有传递z-index值,优先使用
|
|
231
|
+
const uZIndex = computed(() => (props.zIndex ? props.zIndex : 1075));
|
|
232
|
+
|
|
233
|
+
// 监听
|
|
234
|
+
watch(propsChange, () => {
|
|
235
|
+
reset.value = true;
|
|
236
|
+
setTimeout(() => init(), 10);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// 如果地区发生变化,为了让picker联动起来,必须重置this.citys和this.areas
|
|
240
|
+
watch(regionChange, () => {
|
|
241
|
+
citysRef.value = citys[province.value];
|
|
242
|
+
areasRef.value = areas[province.value][city.value];
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// watch监听月份的变化,实时变更日的天数,因为不同月份,天数不一样
|
|
246
|
+
// 一个月可能有30,31天,甚至闰年2月的29天,平年2月28天
|
|
247
|
+
watch(yearAndMonth, () => {
|
|
248
|
+
if (props.params.year) setDays();
|
|
249
|
+
});
|
|
250
|
+
watch(
|
|
251
|
+
() => props.modelValue,
|
|
252
|
+
n => {
|
|
253
|
+
if (n) {
|
|
254
|
+
reset.value = true;
|
|
255
|
+
setTimeout(() => init(), 10);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
// 方法区
|
|
261
|
+
/**
|
|
262
|
+
* 标识滑动开始,只有微信小程序才有这样的事件
|
|
263
|
+
*/
|
|
264
|
+
function pickstart() {
|
|
265
|
+
// #ifdef MP-WEIXIN
|
|
266
|
+
moving.value = true;
|
|
267
|
+
// #endif
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* 标识滑动结束
|
|
271
|
+
*/
|
|
272
|
+
function pickend() {
|
|
273
|
+
// #ifdef MP-WEIXIN
|
|
274
|
+
moving.value = false;
|
|
275
|
+
// #endif
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* 对单列和多列形式的判断是否有传入变量的情况
|
|
279
|
+
* @param item 当前项
|
|
280
|
+
* @param mode 模式
|
|
281
|
+
*/
|
|
282
|
+
function getItemValue(item: any, mode: string) {
|
|
283
|
+
// 目前(2020-05-25)uni-app对微信小程序编译有错误,导致v-if为false中的内容也执行,错误导致
|
|
284
|
+
// 单列模式或者多列模式中的getItemValue同时被执行,故在这里再加一层判断
|
|
285
|
+
if (props.mode == mode) {
|
|
286
|
+
return typeof item == 'object' ? item[props.rangeKey] : item;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* 小于10前面补0,用于月份,日期,时分秒等
|
|
291
|
+
*/
|
|
292
|
+
function formatNumber(num: number | string) {
|
|
293
|
+
return +num < 10 ? '0' + num : String(num);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 生成递进的数组
|
|
297
|
+
*/
|
|
298
|
+
function generateArray(start: number, end: number) {
|
|
299
|
+
// 转为数值格式,否则用户给end-year等传递字符串值时,下面的end+1会导致字符串拼接,而不是相加
|
|
300
|
+
start = Number(start);
|
|
301
|
+
end = Number(end);
|
|
302
|
+
end = end > start ? end : start;
|
|
303
|
+
// 生成数组,获取其中的索引,并剪出来
|
|
304
|
+
return [...Array(end + 1).keys()].slice(start);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* 获取数组中指定值的索引
|
|
308
|
+
*/
|
|
309
|
+
function getIndex(arr: any[], val: any) {
|
|
310
|
+
let index = arr.indexOf(val);
|
|
311
|
+
// 如果index为-1(即找不到index值),~(-1)=-(-1)-1=0,导致条件不成立
|
|
312
|
+
return ~index ? index : 0;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* 日期时间处理,初始化各时间字段
|
|
316
|
+
*/
|
|
317
|
+
function initTimeValue() {
|
|
318
|
+
// 格式化时间,在IE浏览器(uni不存在此情况),无法识别日期间的"-"间隔符号
|
|
319
|
+
let fdate = props.defaultTime.replace(/\-/g, '/');
|
|
320
|
+
fdate = fdate && fdate.indexOf('/') == -1 ? `2020/01/01 ${fdate}` : fdate;
|
|
321
|
+
let time: Date;
|
|
322
|
+
if (fdate) time = new Date(fdate);
|
|
323
|
+
else time = new Date();
|
|
324
|
+
// 获取年日月时分秒
|
|
325
|
+
year.value = time.getFullYear();
|
|
326
|
+
month.value = Number(time.getMonth()) + 1;
|
|
327
|
+
day.value = time.getDate();
|
|
328
|
+
hour.value = time.getHours();
|
|
329
|
+
minute.value = time.getMinutes();
|
|
330
|
+
second.value = time.getSeconds();
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 初始化picker各列数据
|
|
334
|
+
*/
|
|
335
|
+
function init() {
|
|
336
|
+
valueArr.value = [];
|
|
337
|
+
reset.value = false;
|
|
338
|
+
if (props.mode == 'time') {
|
|
339
|
+
initTimeValue();
|
|
340
|
+
if (props.params.year) {
|
|
341
|
+
valueArr.value.push(0);
|
|
342
|
+
setYears();
|
|
343
|
+
}
|
|
344
|
+
if (props.params.month) {
|
|
345
|
+
valueArr.value.push(0);
|
|
346
|
+
setMonths();
|
|
347
|
+
}
|
|
348
|
+
if (props.params.day) {
|
|
349
|
+
valueArr.value.push(0);
|
|
350
|
+
setDays();
|
|
351
|
+
}
|
|
352
|
+
if (props.params.hour) {
|
|
353
|
+
valueArr.value.push(0);
|
|
354
|
+
setHours();
|
|
355
|
+
}
|
|
356
|
+
if (props.params.minute) {
|
|
357
|
+
valueArr.value.push(0);
|
|
358
|
+
setMinutes();
|
|
359
|
+
}
|
|
360
|
+
if (props.params.second) {
|
|
361
|
+
valueArr.value.push(0);
|
|
362
|
+
setSeconds();
|
|
363
|
+
}
|
|
364
|
+
} else if (props.mode == 'region') {
|
|
365
|
+
if (props.params.province) {
|
|
366
|
+
valueArr.value.push(0);
|
|
367
|
+
setProvinces();
|
|
368
|
+
}
|
|
369
|
+
if (props.params.city) {
|
|
370
|
+
valueArr.value.push(0);
|
|
371
|
+
setCitys();
|
|
372
|
+
}
|
|
373
|
+
if (props.params.area) {
|
|
374
|
+
valueArr.value.push(0);
|
|
375
|
+
setAreas();
|
|
376
|
+
}
|
|
377
|
+
} else if (props.mode == 'selector') {
|
|
378
|
+
valueArr.value = props.defaultSelector as number[];
|
|
379
|
+
} else if (props.mode == 'multiSelector') {
|
|
380
|
+
valueArr.value = props.defaultSelector as number[];
|
|
381
|
+
multiSelectorValue.value = props.defaultSelector as number[];
|
|
382
|
+
}
|
|
383
|
+
nextTick(() => {});
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* 设置年份列
|
|
387
|
+
*/
|
|
388
|
+
function setYears() {
|
|
389
|
+
// 获取年份集合
|
|
390
|
+
years.value = generateArray(props.startYear as number, props.endYear as number);
|
|
391
|
+
// 设置this.valueArr某一项的值,是为了让picker预选中某一个值
|
|
392
|
+
valueArr.value.splice(valueArr.value.length - 1, 1, getIndex(years.value, year.value));
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* 设置月份列
|
|
396
|
+
*/
|
|
397
|
+
function setMonths() {
|
|
398
|
+
months.value = generateArray(1, 12);
|
|
399
|
+
valueArr.value.splice(valueArr.value.length - 1, 1, getIndex(months.value, month.value));
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* 设置天数列
|
|
403
|
+
*/
|
|
404
|
+
function setDays() {
|
|
405
|
+
let totalDays = new Date(year.value, month.value, 0).getDate();
|
|
406
|
+
days.value = generateArray(1, totalDays);
|
|
407
|
+
let index = 0;
|
|
408
|
+
// 这里不能使用类似setMonths()中的this.valueArr.splice(this.valueArr.length - 1, 1, xxx)做法
|
|
409
|
+
// 因为this.month和this.year变化时,会触发watch中的this.setDays(),导致this.valueArr.length计算有误
|
|
410
|
+
if (props.params.year && props.params.month) index = 2;
|
|
411
|
+
else if (props.params.month) index = 1;
|
|
412
|
+
else if (props.params.year) index = 1;
|
|
413
|
+
else index = 0;
|
|
414
|
+
// 当月份变化时,会导致日期的天数也会变化,如果原来选的天数大于变化后的天数,则重置为变化后的最大值
|
|
415
|
+
// 比如原来选中3月31日,调整为2月后,日期变为最大29,这时如果day值继续为31显然不合理,于是将其置为29(picker-column从1开始)
|
|
416
|
+
if (day.value > days.value.length) day.value = days.value.length;
|
|
417
|
+
valueArr.value.splice(index, 1, getIndex(days.value, day.value));
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* 设置小时列
|
|
421
|
+
*/
|
|
422
|
+
function setHours() {
|
|
423
|
+
hours.value = generateArray(0, 23);
|
|
424
|
+
valueArr.value.splice(valueArr.value.length - 1, 1, getIndex(hours.value, hour.value));
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* 设置分钟列
|
|
428
|
+
*/
|
|
429
|
+
function setMinutes() {
|
|
430
|
+
minutes.value = generateArray(0, 59);
|
|
431
|
+
valueArr.value.splice(valueArr.value.length - 1, 1, getIndex(minutes.value, minute.value));
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* 设置秒数列
|
|
435
|
+
*/
|
|
436
|
+
function setSeconds() {
|
|
437
|
+
seconds.value = generateArray(0, 59);
|
|
438
|
+
valueArr.value.splice(valueArr.value.length - 1, 1, getIndex(seconds.value, second.value));
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* 设置省份列
|
|
442
|
+
*/
|
|
443
|
+
function setProvinces() {
|
|
444
|
+
// 判断是否需要province参数
|
|
445
|
+
if (!props.params.province) return;
|
|
446
|
+
let tmp: any = '';
|
|
447
|
+
let useCode = false;
|
|
448
|
+
// 如果同时配置了defaultRegion和areaCode,优先使用areaCode参数
|
|
449
|
+
if (props.areaCode.length) {
|
|
450
|
+
tmp = props.areaCode[0];
|
|
451
|
+
useCode = true;
|
|
452
|
+
} else if (props.defaultRegion.length) tmp = props.defaultRegion[0];
|
|
453
|
+
else tmp = 0;
|
|
454
|
+
// 历遍省份数组匹配
|
|
455
|
+
provinces.map((v: any, k: number) => {
|
|
456
|
+
if (useCode ? v.value == tmp : v.label == tmp) {
|
|
457
|
+
tmp = k;
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
province.value = tmp;
|
|
461
|
+
provincesRef.value = provinces;
|
|
462
|
+
// 设置默认省份的值
|
|
463
|
+
valueArr.value.splice(0, 1, province.value);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* 设置城市列
|
|
467
|
+
*/
|
|
468
|
+
function setCitys() {
|
|
469
|
+
if (!props.params.city) return;
|
|
470
|
+
let tmp: any = '';
|
|
471
|
+
let useCode = false;
|
|
472
|
+
if (props.areaCode.length) {
|
|
473
|
+
tmp = props.areaCode[1];
|
|
474
|
+
useCode = true;
|
|
475
|
+
} else if (props.defaultRegion.length) tmp = props.defaultRegion[1];
|
|
476
|
+
else tmp = 0;
|
|
477
|
+
// 历遍城市数组匹配
|
|
478
|
+
citys[province.value].map((v: any, k: number) => {
|
|
479
|
+
if (useCode ? v.value == tmp : v.label == tmp) {
|
|
480
|
+
tmp = k;
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
city.value = tmp;
|
|
484
|
+
citysRef.value = citys[province.value];
|
|
485
|
+
// 设置默认城市的值
|
|
486
|
+
valueArr.value.splice(1, 1, city.value);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* 设置区县列
|
|
490
|
+
*/
|
|
491
|
+
function setAreas() {
|
|
492
|
+
if (!props.params.area) return;
|
|
493
|
+
let tmp: any = '';
|
|
494
|
+
let useCode = false;
|
|
495
|
+
if (props.areaCode.length) {
|
|
496
|
+
tmp = props.areaCode[2];
|
|
497
|
+
useCode = true;
|
|
498
|
+
} else if (props.defaultRegion.length) tmp = props.defaultRegion[2];
|
|
499
|
+
else tmp = 0;
|
|
500
|
+
// 历遍区县数组匹配
|
|
501
|
+
areas[province.value][city.value].map((v: any, k: number) => {
|
|
502
|
+
if (useCode ? v.value == tmp : v.label == tmp) {
|
|
503
|
+
tmp = k;
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
area.value = tmp;
|
|
507
|
+
areasRef.value = areas[province.value][city.value];
|
|
508
|
+
// 设置默认区县的值
|
|
509
|
+
valueArr.value.splice(2, 1, area.value);
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* 关闭picker弹窗
|
|
513
|
+
*/
|
|
514
|
+
function close() {
|
|
515
|
+
emit('update:modelValue', false);
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* 用户更改picker的列选项
|
|
519
|
+
* @param e 事件对象
|
|
520
|
+
*/
|
|
521
|
+
function change(e: any) {
|
|
522
|
+
valueArr.value = e.detail.value;
|
|
523
|
+
let i = 0;
|
|
524
|
+
if (props.mode == 'time') {
|
|
525
|
+
// 这里使用i++,是因为valueArr数组的长度是不确定长度的,它根据params的值来配置长度
|
|
526
|
+
// 进入if规则,i会加1,保证了能获取准确的值
|
|
527
|
+
if (props.params.year) year.value = years.value[valueArr.value[i++]];
|
|
528
|
+
if (props.params.month) month.value = months.value[valueArr.value[i++]];
|
|
529
|
+
if (props.params.day) day.value = days.value[valueArr.value[i++]];
|
|
530
|
+
if (props.params.hour) hour.value = hours.value[valueArr.value[i++]];
|
|
531
|
+
if (props.params.minute) minute.value = minutes.value[valueArr.value[i++]];
|
|
532
|
+
if (props.params.second) second.value = seconds.value[valueArr.value[i++]];
|
|
533
|
+
} else if (props.mode == 'region') {
|
|
534
|
+
if (props.params.province) province.value = valueArr.value[i++];
|
|
535
|
+
if (props.params.city) city.value = valueArr.value[i++];
|
|
536
|
+
if (props.params.area) area.value = valueArr.value[i++];
|
|
537
|
+
} else if (props.mode == 'multiSelector') {
|
|
538
|
+
let index: number | null = null;
|
|
539
|
+
// 对比前后两个数组,寻找变更的是哪一列,如果某一个元素不同,即可判定该列发生了变化
|
|
540
|
+
(props.defaultSelector as number[]).map((val: number, idx: number) => {
|
|
541
|
+
if (val != e.detail.value[idx]) index = idx;
|
|
542
|
+
});
|
|
543
|
+
// 为了让用户对多列变化时,对动态设置其他列的变更
|
|
544
|
+
if (index != null) {
|
|
545
|
+
emit('columnchange', {
|
|
546
|
+
column: index,
|
|
547
|
+
index: e.detail.value[index]
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* 用户点击确定/取消按钮,获取结果
|
|
554
|
+
* @param event 事件名
|
|
555
|
+
*/
|
|
556
|
+
function getResult(event: string | null = null) {
|
|
557
|
+
// #ifdef MP-WEIXIN
|
|
558
|
+
// 微信小程序滑动中不允许点击确定,防止取值不准确
|
|
559
|
+
if (moving.value) return;
|
|
560
|
+
// #endif
|
|
561
|
+
let result: any = {};
|
|
562
|
+
// 只返回用户在params中配置了为true的字段
|
|
563
|
+
if (props.mode == 'time') {
|
|
564
|
+
if (props.params.year) result.year = formatNumber(year.value || 0); // 年
|
|
565
|
+
if (props.params.month) result.month = formatNumber(month.value || 0); // 月
|
|
566
|
+
if (props.params.day) result.day = formatNumber(day.value || 0); // 日
|
|
567
|
+
if (props.params.hour) result.hour = formatNumber(hour.value || 0); // 时
|
|
568
|
+
if (props.params.minute) result.minute = formatNumber(minute.value || 0); // 分
|
|
569
|
+
if (props.params.second) result.second = formatNumber(second.value || 0); // 秒
|
|
570
|
+
if (props.params.timestamp) result.timestamp = getTimestamp(); // 时间戳
|
|
571
|
+
} else if (props.mode == 'region') {
|
|
572
|
+
// 地区模式,返回省市区对象
|
|
573
|
+
if (props.params.province) result.province = provinces[province.value];
|
|
574
|
+
if (props.params.city) result.city = citys[province.value][city.value];
|
|
575
|
+
if (props.params.area) result.area = areas[province.value][city.value][area.value];
|
|
576
|
+
} else if (props.mode == 'selector') {
|
|
577
|
+
// 单列选择器,直接返回选中下标数组
|
|
578
|
+
result = valueArr.value;
|
|
579
|
+
} else if (props.mode == 'multiSelector') {
|
|
580
|
+
// 多列选择器,直接返回选中下标数组
|
|
581
|
+
result = valueArr.value;
|
|
582
|
+
}
|
|
583
|
+
// 只允许 emit 已声明的事件类型
|
|
584
|
+
if (event && ['update:modelValue', 'confirm', 'cancel', 'columnchange'].includes(event))
|
|
585
|
+
emit(event as 'update:modelValue' | 'confirm' | 'cancel' | 'columnchange', result);
|
|
586
|
+
close();
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* 获取时间戳(秒)
|
|
590
|
+
* @returns {number} 时间戳
|
|
591
|
+
*/
|
|
592
|
+
function getTimestamp() {
|
|
593
|
+
// yyyy-mm-dd为安卓写法,不支持iOS,需要使用"/"分隔,才能二者兼容
|
|
594
|
+
let time =
|
|
595
|
+
year.value + '/' + month.value + '/' + day.value + ' ' + hour.value + ':' + minute.value + ':' + second.value;
|
|
596
|
+
return new Date(time).getTime() / 1000;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// 组件挂载时初始化
|
|
600
|
+
onMounted(() => {
|
|
601
|
+
init();
|
|
602
|
+
});
|
|
603
|
+
</script>
|
|
604
|
+
|
|
605
|
+
<style lang="scss" scoped>
|
|
606
|
+
@import '../../libs/css/style.components.scss';
|
|
607
|
+
|
|
608
|
+
.u-datetime-picker {
|
|
609
|
+
position: relative;
|
|
610
|
+
z-index: 999;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
.u-picker-view {
|
|
614
|
+
height: 100%;
|
|
615
|
+
box-sizing: border-box;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
.u-picker-header {
|
|
619
|
+
width: 100%;
|
|
620
|
+
height: 90rpx;
|
|
621
|
+
padding: 0 40rpx;
|
|
622
|
+
@include vue-flex;
|
|
623
|
+
justify-content: space-between;
|
|
624
|
+
align-items: center;
|
|
625
|
+
box-sizing: border-box;
|
|
626
|
+
font-size: 30rpx;
|
|
627
|
+
background: #fff;
|
|
628
|
+
position: relative;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
.u-picker-header::after {
|
|
632
|
+
content: '';
|
|
633
|
+
position: absolute;
|
|
634
|
+
border-bottom: 1rpx solid #eaeef1;
|
|
635
|
+
-webkit-transform: scaleY(0.5);
|
|
636
|
+
transform: scaleY(0.5);
|
|
637
|
+
bottom: 0;
|
|
638
|
+
right: 0;
|
|
639
|
+
left: 0;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
.u-picker__title {
|
|
643
|
+
color: $u-content-color;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
.u-picker-body {
|
|
647
|
+
width: 100%;
|
|
648
|
+
height: 500rpx;
|
|
649
|
+
overflow: hidden;
|
|
650
|
+
background-color: #fff;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
.u-column-item {
|
|
654
|
+
@include vue-flex;
|
|
655
|
+
align-items: center;
|
|
656
|
+
justify-content: center;
|
|
657
|
+
font-size: 32rpx;
|
|
658
|
+
color: $u-main-color;
|
|
659
|
+
padding: 0 8rpx;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
.u-text {
|
|
663
|
+
font-size: 24rpx;
|
|
664
|
+
padding-left: 8rpx;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
.u-btn-picker {
|
|
668
|
+
padding: 16rpx;
|
|
669
|
+
box-sizing: border-box;
|
|
670
|
+
text-align: center;
|
|
671
|
+
text-decoration: none;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
.u-opacity {
|
|
675
|
+
opacity: 0.5;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
.u-btn-picker--primary {
|
|
679
|
+
color: $u-type-primary;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
.u-btn-picker--tips {
|
|
683
|
+
color: $u-tips-color;
|
|
684
|
+
}
|
|
685
|
+
</style>
|