@10yun/cv-mobile-ui 0.4.2 → 0.4.3

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 (166) hide show
  1. package/package.json +1 -1
  2. package/ui-uni/amap-wx/js/util.js +166 -158
  3. package/ui-uni/page-foot/page-foot.vue +38 -0
  4. package/ui-uni/page-head/page-head.vue +16 -0
  5. package/ui-uni/product.vue +52 -52
  6. package/ui-uni/u-charts/u-charts.js +743 -1092
  7. package/ui-uni/u-link/u-link.vue +59 -0
  8. package/ui-uni/uni-badge/uni-badge.vue +250 -0
  9. package/ui-uni/uni-calendar/calendar.js +546 -0
  10. package/ui-uni/uni-calendar/uni-calendar-item.vue +171 -0
  11. package/ui-uni/uni-calendar/uni-calendar.vue +504 -0
  12. package/{ui-cv/cv-calendar → ui-uni/uni-calendar}/util.js +0 -0
  13. package/ui-uni/uni-card/uni-card.vue +420 -0
  14. package/ui-uni/uni-col/uni-col.vue +2968 -0
  15. package/ui-uni/uni-collapse/uni-collapse.vue +146 -0
  16. package/ui-uni/uni-collapse-item/uni-collapse-item.vue +378 -0
  17. package/ui-uni/uni-combox/uni-combox.vue +237 -0
  18. package/ui-uni/uni-countdown/uni-countdown.vue +234 -0
  19. package/ui-uni/uni-data-checkbox/uni-data-checkbox.vue +792 -0
  20. package/{ui-cv/cv-data-indexed-list → ui-uni/uni-data-indexed-list}/clientdb.js +0 -0
  21. package/ui-uni/uni-data-indexed-list/uni-data-indexed-list-item.vue +142 -0
  22. package/ui-uni/uni-data-indexed-list/uni-data-indexed-list.vue +364 -0
  23. package/{ui-cv/cv-data-picker → ui-uni/uni-data-picker}/keypress.js +0 -0
  24. package/ui-uni/uni-data-picker/uni-data-picker.vue +468 -0
  25. package/{ui-cv/cv-data-pickerview/cv-data-picker.js → ui-uni/uni-data-pickerview/uni-data-picker.js} +0 -0
  26. package/ui-uni/uni-data-pickerview/uni-data-pickerview.vue +298 -0
  27. package/{ui-cv/cv-dateformat → ui-uni/uni-dateformat}/date-format.js +0 -0
  28. package/ui-uni/uni-dateformat/uni-dateformat.vue +88 -0
  29. package/{ui-cv/cv-datetime-picker → ui-uni/uni-datetime-picker}/calendar-item.vue +0 -0
  30. package/{ui-cv/cv-datetime-picker → ui-uni/uni-datetime-picker}/calendar.js +0 -0
  31. package/ui-uni/uni-datetime-picker/calendar.vue +747 -0
  32. package/{ui-cv/cv-datetime-picker → ui-uni/uni-datetime-picker}/keypress.js +0 -0
  33. package/ui-uni/uni-datetime-picker/time-picker.vue +899 -0
  34. package/ui-uni/uni-datetime-picker/uni-datetime-picker.vue +874 -0
  35. package/{ui-cv/cv-datetime-picker → ui-uni/uni-datetime-picker}/util.js +0 -0
  36. package/ui-uni/uni-drawer/keypress.js +45 -0
  37. package/ui-uni/uni-drawer/uni-drawer.vue +178 -0
  38. package/{ui-cv/cv-easyinput → ui-uni/uni-easyinput}/common.js +0 -0
  39. package/ui-uni/uni-easyinput/uni-easyinput.vue +438 -0
  40. package/ui-uni/uni-fab/uni-fab.vue +443 -0
  41. package/{ui-cv/cv-fab/cv-fab.vue.bak → ui-uni/uni-fab/uni-fab.vue.bak} +2 -2
  42. package/ui-uni/uni-fav/uni-fav.vue +136 -0
  43. package/{ui-cv/cv-file-picker → ui-uni/uni-file-picker}/choose-and-upload-file.js +0 -0
  44. package/ui-uni/uni-file-picker/uni-file-picker.vue +614 -0
  45. package/{ui-cv/cv-file-picker → ui-uni/uni-file-picker}/upload-file.vue +0 -0
  46. package/{ui-cv/cv-file-picker → ui-uni/uni-file-picker}/upload-image.vue +0 -0
  47. package/{ui-cv/cv-file-picker → ui-uni/uni-file-picker}/utils.js +0 -0
  48. package/ui-uni/uni-forms/uni-forms.vue +467 -0
  49. package/ui-uni/uni-forms/validate.js +486 -0
  50. package/ui-uni/uni-forms-item/uni-forms-item.vue +500 -0
  51. package/{ui-cv/cv-goods-nav/cv-goods-nav.vue → ui-uni/uni-goods-nav/uni-goods-nav.vue} +1 -1
  52. package/ui-uni/uni-grid/uni-grid.vue +141 -0
  53. package/ui-uni/uni-grid-item/uni-grid-item.vue +123 -0
  54. package/ui-uni/uni-group/uni-group.vue +123 -0
  55. package/ui-uni/uni-icons/icons.js +132 -0
  56. package/ui-uni/uni-icons/uni-icons.vue +72 -0
  57. package/{ui-cv/cv-icon2 → ui-uni/uni-icons}/uni.ttf +0 -0
  58. package/ui-uni/uni-indexed-list/uni-indexed-list-item.vue +142 -0
  59. package/ui-uni/uni-indexed-list/uni-indexed-list.vue +357 -0
  60. package/ui-uni/uni-link/uni-link.vue +117 -0
  61. package/ui-uni/uni-list/uni-list.vue +107 -0
  62. package/ui-uni/uni-list/uni-refresh.vue +65 -0
  63. package/{ui-cv/cv-list → ui-uni/uni-list}/uni-refresh.wxs +0 -0
  64. package/ui-uni/uni-list-ad/uni-list-ad.vue +106 -0
  65. package/{ui-cv/cv-list-chat/cv-list-chat.scss → ui-uni/uni-list-chat/uni-list-chat.scss} +0 -0
  66. package/{ui-cv/cv-list-chat/cv-list-chat.vue → ui-uni/uni-list-chat/uni-list-chat.vue} +0 -0
  67. package/ui-uni/uni-list-item/uni-list-item.vue +428 -0
  68. package/ui-uni/uni-load-more/uni-load-more.vue +366 -0
  69. package/ui-uni/uni-nav-bar/uni-nav-bar.vue +244 -0
  70. package/{ui-cv/cv-nav-bar/cv-status-bar.vue → ui-uni/uni-nav-bar/uni-status-bar.vue} +0 -0
  71. package/ui-uni/uni-notice-bar/uni-notice-bar.vue +394 -0
  72. package/ui-uni/uni-number-box/uni-number-box.vue +224 -0
  73. package/ui-uni/uni-pagination/uni-pagination.vue +376 -0
  74. package/{ui-cv/cv-popup → ui-uni/uni-popup}/keypress.js +0 -0
  75. package/{ui-cv/cv-popup → ui-uni/uni-popup}/popup.js +0 -0
  76. package/ui-uni/uni-popup/uni-popup.vue +412 -0
  77. package/{ui-cv/cv-popup-dialog → ui-uni/uni-popup-dialog}/keypress.js +0 -0
  78. package/{ui-cv/cv-popup-dialog/cv-popup-dialog.vue → ui-uni/uni-popup-dialog/uni-popup-dialog.vue} +0 -0
  79. package/ui-uni/uni-popup-message/uni-popup-message.vue +143 -0
  80. package/{ui-cv/cv-popup-share/cv-popup-share.vue → ui-uni/uni-popup-share/uni-popup-share.vue} +0 -0
  81. package/ui-uni/uni-rate/uni-rate.vue +357 -0
  82. package/ui-uni/uni-row/uni-row.vue +155 -0
  83. package/ui-uni/uni-search-bar/uni-search-bar.vue +262 -0
  84. package/{ui-cv/cv-section/cv-section.vue → ui-uni/uni-section/uni-section.vue} +0 -0
  85. package/{ui-cv/cv-segmented-control/cv-segmented-control.vue → ui-uni/uni-segmented-control/uni-segmented-control.vue} +0 -0
  86. package/{ui-cv/cv-status-bar/cv-status-bar.vue → ui-uni/uni-status-bar/uni-status-bar.vue} +0 -0
  87. package/ui-uni/uni-steps/uni-steps.vue +250 -0
  88. package/{ui-cv/cv-swipe-action/cv-swipe-action.vue → ui-uni/uni-swipe-action/uni-swipe-action.vue} +0 -0
  89. package/{ui-cv/cv-swipe-action-item → ui-uni/uni-swipe-action-item}/bindingx.js +0 -0
  90. package/{ui-cv/cv-swipe-action-item → ui-uni/uni-swipe-action-item}/index.wxs +0 -0
  91. package/{ui-cv/cv-swipe-action-item → ui-uni/uni-swipe-action-item}/isPC.js +0 -0
  92. package/{ui-cv/cv-swipe-action-item → ui-uni/uni-swipe-action-item}/mpalipay.js +0 -0
  93. package/{ui-cv/cv-swipe-action-item → ui-uni/uni-swipe-action-item}/mpother.js +0 -0
  94. package/{ui-cv/cv-swipe-action-item → ui-uni/uni-swipe-action-item}/mpwxs.js +0 -0
  95. package/{ui-cv/cv-swipe-action-item/cv-swipe-action-item.vue → ui-uni/uni-swipe-action-item/uni-swipe-action-item.vue} +0 -0
  96. package/ui-uni/uni-swiper-dot/uni-swiper-dot.vue +205 -0
  97. package/ui-uni/uni-table/uni-table.vue +455 -0
  98. package/ui-uni/uni-tag/uni-tag.vue +283 -0
  99. package/ui-uni/uni-tbody/uni-tbody.vue +30 -0
  100. package/ui-uni/uni-td/uni-td.vue +88 -0
  101. package/{ui-cv/cv-test/cv-test.vue → ui-uni/uni-test/uni-test.vue} +0 -0
  102. package/{ui-cv/cv-th → ui-uni/uni-th}/filter-dropdown.vue +0 -0
  103. package/ui-uni/uni-th/uni-th.vue +259 -0
  104. package/ui-uni/uni-thead/uni-thead.vue +114 -0
  105. package/ui-uni/uni-title/uni-title.vue +171 -0
  106. package/{ui-cv/cv-tr → ui-uni/uni-tr}/table-checkbox.vue +0 -0
  107. package/ui-uni/uni-tr/uni-tr.vue +156 -0
  108. package/{ui-cv/cv-transition → ui-uni/uni-transition}/createAnimation.js +0 -0
  109. package/ui-uni/uni-transition/uni-transition.vue +287 -0
  110. package/ui-cv/cv-badge/cv-badge.vue +0 -249
  111. package/ui-cv/cv-calendar/calendar.js +0 -963
  112. package/ui-cv/cv-calendar/cv-calendar-item.vue +0 -198
  113. package/ui-cv/cv-calendar/cv-calendar.vue +0 -508
  114. package/ui-cv/cv-card/cv-card.vue +0 -427
  115. package/ui-cv/cv-col/cv-col.vue +0 -2965
  116. package/ui-cv/cv-collapse/cv-collapse.vue +0 -146
  117. package/ui-cv/cv-collapse-item/cv-collapse-item.vue +0 -395
  118. package/ui-cv/cv-combox/cv-combox.vue +0 -250
  119. package/ui-cv/cv-countdown/cv-countdown.vue +0 -245
  120. package/ui-cv/cv-data-checkbox/cv-data-checkbox.vue +0 -841
  121. package/ui-cv/cv-data-indexed-list/cv-data-indexed-list-item.vue +0 -154
  122. package/ui-cv/cv-data-indexed-list/cv-data-indexed-list.vue +0 -376
  123. package/ui-cv/cv-data-picker/cv-data-picker.vue +0 -486
  124. package/ui-cv/cv-data-pickerview/cv-data-pickerview.vue +0 -304
  125. package/ui-cv/cv-dateformat/cv-dateformat.vue +0 -86
  126. package/ui-cv/cv-datetime-picker/calendar.vue +0 -761
  127. package/ui-cv/cv-datetime-picker/cv-datetime-picker.vue +0 -958
  128. package/ui-cv/cv-datetime-picker/time-picker.vue +0 -907
  129. package/ui-cv/cv-drawer/cv-drawer.vue +0 -185
  130. package/ui-cv/cv-drawer/keypress.js +0 -45
  131. package/ui-cv/cv-easyinput/cv-easyinput.vue +0 -514
  132. package/ui-cv/cv-fab/cv-fab.vue +0 -465
  133. package/ui-cv/cv-fav/cv-fav.vue +0 -150
  134. package/ui-cv/cv-file-picker/cv-file-picker.vue +0 -619
  135. package/ui-cv/cv-form-base/cv-form-base.vue +0 -470
  136. package/ui-cv/cv-form-base/validate.js +0 -477
  137. package/ui-cv/cv-grid-group/cv-grid-group.vue +0 -148
  138. package/ui-cv/cv-grid-item/cv-grid-item.vue +0 -132
  139. package/ui-cv/cv-icon2/cv-icon2.vue +0 -78
  140. package/ui-cv/cv-icon2/icons.js +0 -132
  141. package/ui-cv/cv-indexed-list/cv-indexed-list-item.vue +0 -154
  142. package/ui-cv/cv-indexed-list/cv-indexed-list.vue +0 -371
  143. package/ui-cv/cv-link2/cv-link2.vue +0 -130
  144. package/ui-cv/cv-list/cv-list.vue +0 -107
  145. package/ui-cv/cv-list/cv-refresh.vue +0 -65
  146. package/ui-cv/cv-list-ad/cv-list-ad.vue +0 -113
  147. package/ui-cv/cv-list-item/cv-list-item.vue +0 -449
  148. package/ui-cv/cv-nav-bar/cv-nav-bar.vue +0 -256
  149. package/ui-cv/cv-notice-bar/cv-notice-bar.vue +0 -453
  150. package/ui-cv/cv-number-box/cv-number-box.vue +0 -223
  151. package/ui-cv/cv-pagination/cv-pagination.vue +0 -397
  152. package/ui-cv/cv-popup/cv-popup.vue +0 -429
  153. package/ui-cv/cv-popup-message/cv-popup-message.vue +0 -143
  154. package/ui-cv/cv-row/cv-row.vue +0 -157
  155. package/ui-cv/cv-search-bar/cv-search-bar.vue +0 -280
  156. package/ui-cv/cv-steps/cv-steps.vue +0 -293
  157. package/ui-cv/cv-swiper-dot/cv-swiper-dot.vue +0 -255
  158. package/ui-cv/cv-table/cv-table.vue +0 -460
  159. package/ui-cv/cv-tag/cv-tag.vue +0 -276
  160. package/ui-cv/cv-tbody/cv-tbody.vue +0 -28
  161. package/ui-cv/cv-td/cv-td.vue +0 -93
  162. package/ui-cv/cv-th/cv-th.vue +0 -270
  163. package/ui-cv/cv-thead/cv-thead.vue +0 -114
  164. package/ui-cv/cv-title/cv-title.vue +0 -168
  165. package/ui-cv/cv-tr/cv-tr.vue +0 -166
  166. package/ui-cv/cv-transition/cv-transition.vue +0 -279
@@ -0,0 +1,899 @@
1
+ <template>
2
+ <view class="uni-datetime-picker">
3
+ <view @click="initTimePicker">
4
+ <slot>
5
+ <view class="uni-datetime-picker-timebox-pointer" :class="{'uni-datetime-picker-disabled': disabled, 'uni-datetime-picker-timebox': border}">
6
+ <text class="uni-datetime-picker-text">{{time}}</text>
7
+ <view v-if="!time" class="uni-datetime-picker-time">
8
+ <text class="uni-datetime-picker-text">选择{{title}}</text>
9
+ </view>
10
+ </view>
11
+ </slot>
12
+ </view>
13
+ <view v-if="visible" id="mask" class="uni-datetime-picker-mask" @click="tiggerTimePicker"></view>
14
+ <view v-if="visible" class="uni-datetime-picker-popup" :class="[dateShow && timeShow ? '' : 'fix-nvue-height']" :style="fixNvueBug">
15
+ <view class="uni-title">
16
+ <text class="uni-datetime-picker-text">设置{{title}}</text>
17
+ </view>
18
+ <view v-if="dateShow" class="uni-datetime-picker__container-box">
19
+ <picker-view class="uni-datetime-picker-view" :indicator-style="indicatorStyle" :value="ymd" @change="bindDateChange">
20
+ <picker-view-column>
21
+ <view class="uni-datetime-picker-item" v-for="(item,index) in years" :key="index">
22
+ <text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
23
+ </view>
24
+ </picker-view-column>
25
+ <picker-view-column>
26
+ <view class="uni-datetime-picker-item" v-for="(item,index) in months" :key="index">
27
+ <text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
28
+ </view>
29
+ </picker-view-column>
30
+ <picker-view-column>
31
+ <view class="uni-datetime-picker-item" v-for="(item,index) in days" :key="index">
32
+ <text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
33
+ </view>
34
+ </picker-view-column>
35
+ </picker-view>
36
+ <!-- 兼容 nvue 不支持伪类 -->
37
+ <text class="uni-datetime-picker-sign sign-left">-</text>
38
+ <text class="uni-datetime-picker-sign sign-right">-</text>
39
+ </view>
40
+ <view v-if="timeShow" class="uni-datetime-picker__container-box">
41
+ <picker-view class="uni-datetime-picker-view" :class="[hideSecond ? 'time-hide-second' : '']" :indicator-style="indicatorStyle" :value="hms" @change="bindTimeChange">
42
+ <picker-view-column>
43
+ <view class="uni-datetime-picker-item" v-for="(item,index) in hours" :key="index">
44
+ <text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
45
+ </view>
46
+ </picker-view-column>
47
+ <picker-view-column>
48
+ <view class="uni-datetime-picker-item" v-for="(item,index) in minutes" :key="index">
49
+ <text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
50
+ </view>
51
+ </picker-view-column>
52
+ <picker-view-column v-if="!hideSecond">
53
+ <view class="uni-datetime-picker-item" v-for="(item,index) in seconds" :key="index">
54
+ <text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
55
+ </view>
56
+ </picker-view-column>
57
+ </picker-view>
58
+ <!-- 兼容 nvue 不支持伪类 -->
59
+ <text class="uni-datetime-picker-sign" :class="[hideSecond ? 'sign-center' : 'sign-left']">:</text>
60
+ <text v-if="!hideSecond" class="uni-datetime-picker-sign sign-right">:</text>
61
+ </view>
62
+ <view class="uni-datetime-picker-btn">
63
+ <view @click="clearTime">
64
+ <text class="uni-datetime-picker-btn-text">清空</text>
65
+ </view>
66
+ <view class="uni-datetime-picker-btn-group">
67
+ <view class="uni-datetime-picker-cancel" @click="tiggerTimePicker">
68
+ <text class="uni-datetime-picker-btn-text">取消</text>
69
+ </view>
70
+ <view @click="setTime">
71
+ <text class="uni-datetime-picker-btn-text">确定</text>
72
+ </view>
73
+ </view>
74
+ </view>
75
+ </view>
76
+ <!-- #ifdef H5 -->
77
+ <!-- <keypress v-if="visible" @esc="tiggerTimePicker" @enter="setTime" /> -->
78
+ <!-- #endif -->
79
+ </view>
80
+ </template>
81
+
82
+ <script>
83
+ // #ifdef H5
84
+ import keypress from './keypress'
85
+ // #endif
86
+
87
+ /**
88
+ * DatetimePicker 时间选择器
89
+ * @description 可以同时选择日期和时间的选择器
90
+ * @tutorial https://ext.dcloud.net.cn/plugin?id=xxx
91
+ * @property {String} type = [datetime | date | time] 显示模式
92
+ * @property {Boolean} multiple = [true|false] 是否多选
93
+ * @property {String|Number} value 默认值
94
+ * @property {String|Number} start 起始日期或时间
95
+ * @property {String|Number} end 起始日期或时间
96
+ * @property {String} return-type = [timestamp | string]
97
+ * @event {Function} change 选中发生变化触发
98
+ */
99
+
100
+ export default {
101
+ name: 'UniDatetimePicker',
102
+ components: {
103
+ // #ifdef H5
104
+ keypress
105
+ // #endif
106
+ },
107
+ data() {
108
+ return {
109
+ indicatorStyle: `height: 50px;`,
110
+ visible: false,
111
+ fixNvueBug: {},
112
+ dateShow: true,
113
+ timeShow: true,
114
+ title: '日期和时间',
115
+ // 输入框当前时间
116
+ time: '',
117
+ // 当前的年月日时分秒
118
+ year: 1900,
119
+ month: 0,
120
+ day: 0,
121
+ hour: 0,
122
+ minute: 0,
123
+ second: 0,
124
+ // 起始时间
125
+ startYear: 1920,
126
+ startMonth: 1,
127
+ startDay: 1,
128
+ startHour: 0,
129
+ startMinute: 0,
130
+ startSecond: 0,
131
+ // 结束时间
132
+ endYear: 2120,
133
+ endMonth: 12,
134
+ endDay: 31,
135
+ endHour: 23,
136
+ endMinute: 59,
137
+ endSecond: 59,
138
+ }
139
+ },
140
+ props: {
141
+ type: {
142
+ type: String,
143
+ default: 'datetime'
144
+ },
145
+ value: {
146
+ type: [String, Number],
147
+ default: ''
148
+ },
149
+ modelValue: {
150
+ type: [String, Number],
151
+ default: ''
152
+ },
153
+ start: {
154
+ type: [Number, String],
155
+ default: ''
156
+ },
157
+ end: {
158
+ type: [Number, String],
159
+ default: ''
160
+ },
161
+ returnType: {
162
+ type: String,
163
+ default: 'string'
164
+ },
165
+ disabled: {
166
+ type: [Boolean, String],
167
+ default: false
168
+ },
169
+ border: {
170
+ type: [Boolean, String],
171
+ default: true
172
+ },
173
+ hideSecond: {
174
+ type: [Boolean, String],
175
+ default: false
176
+ }
177
+ },
178
+ watch: {
179
+ value: {
180
+ handler(newVal, oldVal) {
181
+ if (newVal) {
182
+ this.parseValue(this.fixIosDateFormat(newVal)) //兼容 iOS、safari 日期格式
183
+ this.initTime(false)
184
+ } else {
185
+ this.parseValue(Date.now())
186
+ }
187
+ },
188
+ immediate: true
189
+ },
190
+ type: {
191
+ handler(newValue) {
192
+ if (newValue === 'date') {
193
+ this.dateShow = true
194
+ this.timeShow = false
195
+ this.title = '日期'
196
+ } else if (newValue === 'time') {
197
+ this.dateShow = false
198
+ this.timeShow = true
199
+ this.title = '时间'
200
+ } else {
201
+ this.dateShow = true
202
+ this.timeShow = true
203
+ this.title = '日期和时间'
204
+ }
205
+ },
206
+ immediate: true
207
+ },
208
+ start: {
209
+ handler(newVal) {
210
+ this.parseDatetimeRange(this.fixIosDateFormat(newVal), 'start') //兼容 iOS、safari 日期格式
211
+ },
212
+ immediate: true
213
+ },
214
+ end: {
215
+ handler(newVal) {
216
+ this.parseDatetimeRange(this.fixIosDateFormat(newVal), 'end') //兼容 iOS、safari 日期格式
217
+ },
218
+ immediate: true
219
+ },
220
+
221
+ // 月、日、时、分、秒可选范围变化后,检查当前值是否在范围内,不在则当前值重置为可选范围第一项
222
+ months(newVal) {
223
+ this.checkValue('month', this.month, newVal)
224
+ },
225
+ days(newVal) {
226
+ this.checkValue('day', this.day, newVal)
227
+ },
228
+ hours(newVal) {
229
+ this.checkValue('hour', this.hour, newVal)
230
+ },
231
+ minutes(newVal) {
232
+ this.checkValue('minute', this.minute, newVal)
233
+ },
234
+ seconds(newVal) {
235
+ this.checkValue('second', this.second, newVal)
236
+ }
237
+ },
238
+ computed: {
239
+ // 当前年、月、日、时、分、秒选择范围
240
+ years() {
241
+ return this.getCurrentRange('year')
242
+ },
243
+
244
+ months() {
245
+ return this.getCurrentRange('month')
246
+ },
247
+
248
+ days() {
249
+ return this.getCurrentRange('day')
250
+ },
251
+
252
+ hours() {
253
+ return this.getCurrentRange('hour')
254
+ },
255
+
256
+ minutes() {
257
+ return this.getCurrentRange('minute')
258
+ },
259
+
260
+ seconds() {
261
+ return this.getCurrentRange('second')
262
+ },
263
+
264
+ // picker 当前值数组
265
+ ymd() {
266
+ return [this.year - this.minYear, this.month - this.minMonth, this.day - this.minDay]
267
+ },
268
+ hms() {
269
+ return [this.hour - this.minHour, this.minute - this.minMinute, this.second - this.minSecond]
270
+ },
271
+
272
+ // 当前 date 是 start
273
+ currentDateIsStart() {
274
+ return this.year === this.startYear && this.month === this.startMonth && this.day === this.startDay
275
+ },
276
+
277
+ // 当前 date 是 end
278
+ currentDateIsEnd() {
279
+ return this.year === this.endYear && this.month === this.endMonth && this.day === this.endDay
280
+ },
281
+
282
+ // 当前年、月、日、时、分、秒的最小值和最大值
283
+ minYear() {
284
+ return this.startYear
285
+ },
286
+ maxYear() {
287
+ return this.endYear
288
+ },
289
+ minMonth() {
290
+ if (this.year === this.startYear) {
291
+ return this.startMonth
292
+ } else {
293
+ return 1
294
+ }
295
+ },
296
+ maxMonth() {
297
+ if (this.year === this.endYear) {
298
+ return this.endMonth
299
+ } else {
300
+ return 12
301
+ }
302
+ },
303
+ minDay() {
304
+ if (this.year === this.startYear && this.month === this.startMonth) {
305
+ return this.startDay
306
+ } else {
307
+ return 1
308
+ }
309
+ },
310
+ maxDay() {
311
+ if (this.year === this.endYear && this.month === this.endMonth) {
312
+ return this.endDay
313
+ } else {
314
+ return this.daysInMonth(this.year, this.month)
315
+ }
316
+ },
317
+ minHour() {
318
+ if (this.type === 'datetime') {
319
+ if (this.currentDateIsStart) {
320
+ return this.startHour
321
+ } else {
322
+ return 0
323
+ }
324
+ }
325
+ if (this.type === 'time') {
326
+ return this.startHour
327
+ }
328
+ },
329
+ maxHour() {
330
+ if (this.type === 'datetime') {
331
+ if (this.currentDateIsEnd) {
332
+ return this.endHour
333
+ } else {
334
+ return 23
335
+ }
336
+ }
337
+ if (this.type === 'time') {
338
+ return this.endHour
339
+ }
340
+ },
341
+ minMinute() {
342
+ if (this.type === 'datetime') {
343
+ if (this.currentDateIsStart && this.hour === this.startHour) {
344
+ return this.startMinute
345
+ } else {
346
+ return 0
347
+ }
348
+ }
349
+ if (this.type === 'time') {
350
+ if (this.hour === this.startHour) {
351
+ return this.startMinute
352
+ } else {
353
+ return 0
354
+ }
355
+ }
356
+ },
357
+ maxMinute() {
358
+ if (this.type === 'datetime') {
359
+ if (this.currentDateIsEnd && this.hour === this.endHour) {
360
+ return this.endMinute
361
+ } else {
362
+ return 59
363
+ }
364
+ }
365
+ if (this.type === 'time') {
366
+ if (this.hour === this.endHour) {
367
+ return this.endMinute
368
+ } else {
369
+ return 59
370
+ }
371
+ }
372
+ },
373
+ minSecond() {
374
+ if (this.type === 'datetime') {
375
+ if (this.currentDateIsStart && this.hour === this.startHour && this.minute === this.startMinute) {
376
+ return this.startSecond
377
+ } else {
378
+ return 0
379
+ }
380
+ }
381
+ if (this.type === 'time') {
382
+ if (this.hour === this.startHour && this.minute === this.startMinute) {
383
+ return this.startSecond
384
+ } else {
385
+ return 0
386
+ }
387
+ }
388
+ },
389
+ maxSecond() {
390
+ if (this.type === 'datetime') {
391
+ if (this.currentDateIsEnd && this.hour === this.endHour && this.minute === this.endMinute) {
392
+ return this.endSecond
393
+ } else {
394
+ return 59
395
+ }
396
+ }
397
+ if (this.type === 'time') {
398
+ if (this.hour === this.endHour && this.minute === this.endMinute) {
399
+ return this.endSecond
400
+ } else {
401
+ return 59
402
+ }
403
+ }
404
+ }
405
+ },
406
+
407
+ mounted() {
408
+ // #ifdef APP-NVUE
409
+ const res = uni.getSystemInfoSync();
410
+ this.fixNvueBug = {
411
+ top: res.windowHeight / 2,
412
+ left: res.windowWidth / 2
413
+ }
414
+ // #endif
415
+ },
416
+
417
+ methods: {
418
+ /**
419
+ * @param {Object} item
420
+ * 小于 10 在前面加个 0
421
+ */
422
+
423
+ lessThanTen(item) {
424
+ return item < 10 ? '0' + item : item
425
+ },
426
+
427
+ /**
428
+ * 解析时分秒字符串,例如:00:00:00
429
+ * @param {String} timeString
430
+ */
431
+ parseTimeType(timeString) {
432
+ if (timeString) {
433
+ let timeArr = timeString.split(':')
434
+ this.hour = Number(timeArr[0])
435
+ this.minute = Number(timeArr[1])
436
+ this.second = Number(timeArr[2])
437
+ }
438
+ },
439
+
440
+ /**
441
+ * 解析选择器初始值,类型可以是字符串、时间戳,例如:2000-10-02、'08:30:00'、 1610695109000
442
+ * @param {String | Number} datetime
443
+ */
444
+ initPickerValue(datetime) {
445
+ let defaultValue = null
446
+ if (datetime) {
447
+ defaultValue = this.compareValueWithStartAndEnd(datetime, this.start, this.end)
448
+ } else {
449
+ defaultValue = Date.now()
450
+ defaultValue = this.compareValueWithStartAndEnd(defaultValue, this.start, this.end)
451
+ }
452
+ this.parseValue(defaultValue)
453
+ },
454
+
455
+ /**
456
+ * 初始值规则:
457
+ * - 用户设置初始值 value
458
+ * - 设置了起始时间 start、终止时间 end,并 start < value < end,初始值为 value, 否则初始值为 start
459
+ * - 只设置了起始时间 start,并 start < value,初始值为 value,否则初始值为 start
460
+ * - 只设置了终止时间 end,并 value < end,初始值为 value,否则初始值为 end
461
+ * - 无起始终止时间,则初始值为 value
462
+ * - 无初始值 value,则初始值为当前本地时间 Date.now()
463
+ * @param {Object} value
464
+ * @param {Object} dateBase
465
+ */
466
+ compareValueWithStartAndEnd(value, start, end) {
467
+ let winner = null
468
+ value = this.superTimeStamp(value)
469
+ start = this.superTimeStamp(start)
470
+ end = this.superTimeStamp(end)
471
+
472
+ if (start && end) {
473
+ if (value < start) {
474
+ winner = new Date(start)
475
+ } else if (value > end) {
476
+ winner = new Date(end)
477
+ } else {
478
+ winner = new Date(value)
479
+ }
480
+ } else if (start && !end) {
481
+ winner = start <= value ? new Date(value) : new Date(start)
482
+ } else if (!start && end) {
483
+ winner = value <= end ? new Date(value) : new Date(end)
484
+ } else {
485
+ winner = new Date(value)
486
+ }
487
+
488
+ return winner
489
+ },
490
+
491
+ /**
492
+ * 转换为可比较的时间戳,接受日期、时分秒、时间戳
493
+ * @param {Object} value
494
+ */
495
+ superTimeStamp(value) {
496
+ let dateBase = ''
497
+ if (this.type === 'time' && value && typeof value === 'string') {
498
+ const now = new Date()
499
+ const year = now.getFullYear()
500
+ const month = now.getMonth() + 1
501
+ const day = now.getDate()
502
+ dateBase = year + '/' + month + '/' + day + ' '
503
+ }
504
+ if (Number(value) && typeof value !== NaN) {
505
+ value = parseInt(value)
506
+ dateBase = 0
507
+ }
508
+ return this.createTimeStamp(dateBase + value)
509
+ },
510
+
511
+ /**
512
+ * 解析默认值 value,字符串、时间戳
513
+ * @param {Object} defaultTime
514
+ */
515
+ parseValue(value) {
516
+ if (!value) return
517
+ if (this.type === 'time' && typeof value === "string") {
518
+ this.parseTimeType(value)
519
+ } else {
520
+ let defaultDate = null
521
+ defaultDate = new Date(value)
522
+ if (this.type !== 'time') {
523
+ this.year = defaultDate.getFullYear()
524
+ this.month = defaultDate.getMonth() + 1
525
+ this.day = defaultDate.getDate()
526
+ }
527
+ if (this.type !== 'date') {
528
+ this.hour = defaultDate.getHours()
529
+ this.minute = defaultDate.getMinutes()
530
+ this.second = defaultDate.getSeconds()
531
+ }
532
+ }
533
+ if (this.hideSecond) {
534
+ this.second = 0
535
+ }
536
+ },
537
+
538
+ /**
539
+ * 解析可选择时间范围 start、end,年月日字符串、时间戳
540
+ * @param {Object} defaultTime
541
+ */
542
+ parseDatetimeRange(point, pointType) {
543
+ // 时间为空,则重置为初始值
544
+ if (!point) {
545
+ if (pointType === 'start') {
546
+ this.startYear = 1920
547
+ this.startMonth = 1
548
+ this.startDay = 1
549
+ this.startHour = 0
550
+ this.startMinute = 0
551
+ this.startSecond = 0
552
+ }
553
+ if (pointType === 'end') {
554
+ this.endYear = 120
555
+ this.endMonth = 12
556
+ this.endDay = 31
557
+ this.endHour = 23
558
+ this.endMinute = 59
559
+ this.endSecond = 59
560
+ }
561
+ return
562
+ }
563
+ if (this.type === 'time') {
564
+ const pointArr = point.split(':')
565
+ this[pointType + 'Hour'] = Number(pointArr[0])
566
+ this[pointType + 'Minute'] = Number(pointArr[1])
567
+ this[pointType + 'Second'] = Number(pointArr[2])
568
+ } else {
569
+ if (!point) {
570
+ pointType === 'start' ? this.startYear = this.year - 60 : this.endYear = this.year + 60
571
+ return
572
+ }
573
+ if (Number(point) && Number(point) !== NaN) {
574
+ point = parseInt(point)
575
+ }
576
+ // datetime 的 end 没有时分秒, 则不限制
577
+ const hasTime = /[0-9]:[0-9]/
578
+ if (this.type === 'datetime' && pointType === 'end' && typeof point === 'string' && !hasTime.test(
579
+ point)) {
580
+ point = point + ' 23:59:59'
581
+ }
582
+ const pointDate = new Date(point)
583
+ this[pointType + 'Year'] = pointDate.getFullYear()
584
+ this[pointType + 'Month'] = pointDate.getMonth() + 1
585
+ this[pointType + 'Day'] = pointDate.getDate()
586
+ if (this.type === 'datetime') {
587
+ this[pointType + 'Hour'] = pointDate.getHours()
588
+ this[pointType + 'Minute'] = pointDate.getMinutes()
589
+ this[pointType + 'Second'] = pointDate.getSeconds()
590
+ }
591
+ }
592
+ },
593
+
594
+ // 获取 年、月、日、时、分、秒 当前可选范围
595
+ getCurrentRange(value) {
596
+ const range = []
597
+ for (let i = this['min' + this.capitalize(value)]; i <= this['max' + this.capitalize(value)]; i++) {
598
+ range.push(i)
599
+ }
600
+ return range
601
+ },
602
+
603
+ // 字符串首字母大写
604
+ capitalize(str) {
605
+ return str.charAt(0).toUpperCase() + str.slice(1)
606
+ },
607
+
608
+ // 检查当前值是否在范围内,不在则当前值重置为可选范围第一项
609
+ checkValue(name, value, values) {
610
+ if (values.indexOf(value) === -1) {
611
+ this[name] = values[0]
612
+ }
613
+ },
614
+
615
+ // 每个月的实际天数
616
+ daysInMonth(year, month) { // Use 1 for January, 2 for February, etc.
617
+ return new Date(year, month, 0).getDate();
618
+ },
619
+
620
+ //兼容 iOS、safari 日期格式
621
+ fixIosDateFormat(value) {
622
+ if (typeof value === 'string') {
623
+ value = value.replace(/-/g, '/')
624
+ }
625
+ return value
626
+ },
627
+
628
+ /**
629
+ * 生成时间戳
630
+ * @param {Object} time
631
+ */
632
+ createTimeStamp(time) {
633
+ if (!time) return
634
+ if (typeof time === "number") {
635
+ return time
636
+ } else {
637
+ time = time.replace(/-/g, '/')
638
+ if (this.type === 'date') {
639
+ time = time + ' ' + '00:00:00'
640
+ }
641
+ return Date.parse(time)
642
+ }
643
+ },
644
+
645
+ /**
646
+ * 生成日期或时间的字符串
647
+ */
648
+ createDomSting() {
649
+ const yymmdd = this.year +
650
+ '-' +
651
+ this.lessThanTen(this.month) +
652
+ '-' +
653
+ this.lessThanTen(this.day)
654
+
655
+ let hhmmss = this.lessThanTen(this.hour) +
656
+ ':' +
657
+ this.lessThanTen(this.minute)
658
+
659
+ if (!this.hideSecond) {
660
+ hhmmss = hhmmss + ':' + this.lessThanTen(this.second)
661
+ }
662
+
663
+ if (this.type === 'date') {
664
+ return yymmdd
665
+ } else if (this.type === 'time') {
666
+ return hhmmss
667
+ } else {
668
+ return yymmdd + ' ' + hhmmss
669
+ }
670
+ },
671
+
672
+ /**
673
+ * 初始化返回值,并抛出 change 事件
674
+ */
675
+ initTime(emit = true) {
676
+ this.time = this.createDomSting()
677
+ if (!emit) return
678
+ if (this.returnType === 'timestamp' && this.type !== 'time') {
679
+ this.$emit('change', this.createTimeStamp(this.time))
680
+ this.$emit('input', this.createTimeStamp(this.time))
681
+ this.$emit('update:modelValue', this.createTimeStamp(this.time))
682
+ } else {
683
+ this.$emit('change', this.time)
684
+ this.$emit('input', this.time)
685
+ this.$emit('update:modelValue', this.time)
686
+ }
687
+ },
688
+
689
+ /**
690
+ * 用户选择日期或时间更新 data
691
+ * @param {Object} e
692
+ */
693
+ bindDateChange(e) {
694
+ const val = e.detail.value
695
+ this.year = this.years[val[0]]
696
+ this.month = this.months[val[1]]
697
+ this.day = this.days[val[2]]
698
+ },
699
+ bindTimeChange(e) {
700
+ const val = e.detail.value
701
+ this.hour = this.hours[val[0]]
702
+ this.minute = this.minutes[val[1]]
703
+ this.second = this.seconds[val[2]]
704
+ },
705
+
706
+ /**
707
+ * 初始化弹出层
708
+ */
709
+ initTimePicker() {
710
+ if (this.disabled) return
711
+ const value = this.fixIosDateFormat(this.value)
712
+ this.initPickerValue(value)
713
+ this.visible = !this.visible
714
+ },
715
+
716
+ /**
717
+ * 触发或关闭弹框
718
+ */
719
+ tiggerTimePicker(e) {
720
+ this.visible = !this.visible
721
+ },
722
+
723
+ /**
724
+ * 用户点击“清空”按钮,清空当前值
725
+ */
726
+ clearTime() {
727
+ this.time = ''
728
+ this.$emit('change', this.time)
729
+ this.$emit('input', this.time)
730
+ this.$emit('update:modelValue', this.time)
731
+ this.tiggerTimePicker()
732
+ },
733
+
734
+ /**
735
+ * 用户点击“确定”按钮
736
+ */
737
+ setTime() {
738
+ this.initTime()
739
+ this.tiggerTimePicker()
740
+ }
741
+ }
742
+ }
743
+ </script>
744
+
745
+ <style scoped>
746
+ @charset "UTF-8";
747
+
748
+ .uni-datetime-picker {
749
+ /* #ifndef APP-NVUE */
750
+ width: 100%;
751
+ /* #endif */
752
+ }
753
+
754
+ .uni-datetime-picker-view {
755
+ height: 130px;
756
+ width: 270px;
757
+ /* #ifndef APP-NVUE */
758
+ cursor: pointer;
759
+ /* #endif */
760
+ }
761
+
762
+ .uni-datetime-picker-item {
763
+ height: 50px;
764
+ line-height: 50px;
765
+ text-align: center;
766
+ font-size: 14px;
767
+ }
768
+
769
+ .uni-datetime-picker-btn {
770
+ margin-top: 60px;
771
+ /* #ifndef APP-NVUE */
772
+ display: flex;
773
+ cursor: pointer;
774
+ /* #endif */
775
+ flex-direction: row;
776
+ justify-content: space-between;
777
+ }
778
+
779
+ .uni-datetime-picker-btn-text {
780
+ font-size: 14px;
781
+ color: #007AFF;
782
+ }
783
+
784
+ .uni-datetime-picker-btn-group {
785
+ /* #ifndef APP-NVUE */
786
+ display: flex;
787
+ /* #endif */
788
+ flex-direction: row;
789
+ }
790
+
791
+ .uni-datetime-picker-cancel {
792
+ margin-right: 30px;
793
+ }
794
+
795
+ .uni-datetime-picker-mask {
796
+ position: fixed;
797
+ bottom: 0px;
798
+ top: 0px;
799
+ left: 0px;
800
+ right: 0px;
801
+ background-color: rgba(0, 0, 0, 0.4);
802
+ transition-duration: 0.3s;
803
+ z-index: 998;
804
+ }
805
+
806
+ .uni-datetime-picker-popup {
807
+ border-radius: 8px;
808
+ padding: 30px;
809
+ width: 270px;
810
+ /* #ifdef APP-NVUE */
811
+ height: 500px;
812
+ /* #endif */
813
+ /* #ifdef APP-NVUE */
814
+ width: 330px;
815
+ /* #endif */
816
+ background-color: #fff;
817
+ position: fixed;
818
+ top: 50%;
819
+ left: 50%;
820
+ transform: translate(-50%, -50%);
821
+ transition-duration: 0.3s;
822
+ z-index: 999;
823
+ }
824
+
825
+ .fix-nvue-height {
826
+ /* #ifdef APP-NVUE */
827
+ height: 330px;
828
+ /* #endif */
829
+ }
830
+
831
+ .uni-datetime-picker-time {
832
+ color: grey;
833
+ }
834
+
835
+ .uni-datetime-picker-column {
836
+ height: 50px;
837
+ }
838
+
839
+ .uni-datetime-picker-timebox {
840
+ border: 1px solid #E5E5E5;
841
+ border-radius: 5px;
842
+ padding: 7px 10px;
843
+ /* #ifndef APP-NVUE */
844
+ box-sizing: border-box;
845
+ cursor: pointer;
846
+ /* #endif */
847
+ }
848
+
849
+ .uni-datetime-picker-timebox-pointer {
850
+ /* #ifndef APP-NVUE */
851
+ cursor: pointer;
852
+ /* #endif */
853
+ }
854
+
855
+ .uni-datetime-picker-disabled {
856
+ opacity: 0.4;
857
+ /* #ifdef H5 */
858
+ cursor: not-allowed !important;
859
+ /* #endif */
860
+ }
861
+
862
+ .uni-datetime-picker-text {
863
+ font-size: 14px;
864
+ }
865
+
866
+ .uni-datetime-picker-sign {
867
+ position: absolute;
868
+ top: 53px;
869
+ /* 减掉 10px 的元素高度,兼容nvue */
870
+ color: #999;
871
+ /* #ifdef APP-NVUE */
872
+ font-size: 16px;
873
+ /* #endif */
874
+ }
875
+
876
+ .sign-left {
877
+ left: 86px;
878
+ }
879
+
880
+ .sign-right {
881
+ right: 86px;
882
+ }
883
+
884
+ .sign-center {
885
+ left: 135px;
886
+ }
887
+
888
+ .uni-datetime-picker__container-box {
889
+ position: relative;
890
+ display: flex;
891
+ align-items: center;
892
+ justify-content: center;
893
+ margin-top: 40px;
894
+ }
895
+
896
+ .time-hide-second {
897
+ width: 180px;
898
+ }
899
+ </style>