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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/package.json +1 -1
  2. package/ui-cv/cv-badge/{uni-badge.vue → cv-badge.vue} +2 -2
  3. package/ui-cv/cv-calendar/calendar.js +762 -345
  4. package/ui-cv/cv-calendar/cv-calendar-item.vue +198 -0
  5. package/ui-cv/cv-calendar/cv-calendar.vue +508 -0
  6. package/ui-cv/cv-card/cv-card.vue +427 -0
  7. package/ui-cv/cv-col/cv-col.vue +2965 -0
  8. package/ui-cv/cv-collapse/cv-collapse.vue +146 -0
  9. package/ui-cv/cv-collapse-item/cv-collapse-item.vue +395 -0
  10. package/ui-cv/cv-combox/cv-combox.vue +250 -0
  11. package/ui-cv/cv-countdown/cv-countdown.vue +245 -0
  12. package/ui-cv/cv-data-checkbox/cv-data-checkbox.vue +841 -0
  13. package/ui-cv/cv-data-indexed-list/cv-data-indexed-list-item.vue +154 -0
  14. package/ui-cv/cv-data-indexed-list/cv-data-indexed-list.vue +376 -0
  15. package/ui-cv/cv-data-picker/cv-data-picker.vue +486 -0
  16. package/ui-cv/cv-data-pickerview/{uni-data-picker.js → cv-data-picker.js} +0 -0
  17. package/ui-cv/cv-data-pickerview/cv-data-pickerview.vue +304 -0
  18. package/ui-cv/cv-dateformat/cv-dateformat.vue +86 -0
  19. package/ui-cv/cv-datetime-picker/calendar.vue +752 -738
  20. package/ui-cv/cv-datetime-picker/cv-datetime-picker.vue +958 -0
  21. package/ui-cv/cv-datetime-picker/time-picker.vue +900 -892
  22. package/ui-cv/cv-easyinput/cv-easyinput.vue +514 -0
  23. package/ui-cv/cv-fab/cv-fab.vue +465 -0
  24. package/ui-cv/cv-fab/{uni-fab.vue.bak → cv-fab.vue.bak} +2 -2
  25. package/ui-cv/cv-fav/cv-fav.vue +150 -0
  26. package/ui-cv/cv-file-picker/cv-file-picker.vue +619 -0
  27. package/ui-cv/cv-form-item/cv-form-item.vue +1 -1
  28. package/ui-cv/cv-goods-nav/{uni-goods-nav.vue → cv-goods-nav.vue} +1 -1
  29. package/ui-cv/{cv-icons2/cv-icons2.vue → cv-icon2/cv-icon2.vue} +3 -3
  30. package/ui-cv/{cv-icons2 → cv-icon2}/icons.js +0 -0
  31. package/ui-cv/{cv-icons2 → cv-icon2}/uni.ttf +0 -0
  32. package/ui-cv/cv-indexed-list/cv-indexed-list-item.vue +154 -0
  33. package/ui-cv/cv-indexed-list/cv-indexed-list.vue +371 -0
  34. package/ui-cv/cv-input-password/cv-input-password.vue +2 -2
  35. package/ui-cv/{cv-link/uni-link.vue → cv-link2/cv-link2.vue} +1 -1
  36. package/ui-cv/cv-list/cv-list.vue +107 -0
  37. package/ui-cv/cv-list/cv-refresh.vue +65 -0
  38. package/ui-cv/cv-list-ad/cv-list-ad.vue +113 -0
  39. package/ui-cv/cv-list-chat/{uni-list-chat.scss → cv-list-chat.scss} +0 -0
  40. package/ui-cv/cv-list-chat/{uni-list-chat.vue → cv-list-chat.vue} +0 -0
  41. package/ui-cv/cv-list-item/cv-list-item.vue +449 -0
  42. package/ui-cv/cv-nav-bar/cv-nav-bar.vue +256 -0
  43. package/ui-cv/cv-nav-bar/{uni-status-bar.vue → cv-status-bar.vue} +0 -0
  44. package/ui-cv/cv-notice-bar/cv-notice-bar.vue +453 -0
  45. package/ui-cv/cv-number-box/cv-number-box.vue +223 -0
  46. package/ui-cv/cv-pagination/cv-pagination.vue +397 -0
  47. package/ui-cv/cv-popup/cv-popup.vue +429 -0
  48. package/ui-cv/cv-popup-dialog/{uni-popup-dialog.vue → cv-popup-dialog.vue} +0 -0
  49. package/ui-cv/cv-popup-message/cv-popup-message.vue +143 -0
  50. package/ui-cv/cv-popup-share/{uni-popup-share.vue → cv-popup-share.vue} +0 -0
  51. package/ui-cv/cv-row/{uni-row.vue → cv-row.vue} +1 -1
  52. package/ui-cv/cv-search-bar/cv-search-bar.vue +280 -0
  53. package/ui-cv/cv-section/{uni-section.vue → cv-section.vue} +0 -0
  54. package/ui-cv/cv-segmented-control/{uni-segmented-control.vue → cv-segmented-control.vue} +0 -0
  55. package/ui-cv/cv-status-bar/{uni-status-bar.vue → cv-status-bar.vue} +0 -0
  56. package/ui-cv/cv-steps/cv-steps.vue +293 -0
  57. package/ui-cv/cv-swipe-action/{uni-swipe-action.vue → cv-swipe-action.vue} +0 -0
  58. package/ui-cv/cv-swipe-action-item/{uni-swipe-action-item.vue → cv-swipe-action-item.vue} +0 -0
  59. package/ui-cv/cv-swiper-dot/cv-swiper-dot.vue +255 -0
  60. package/ui-cv/cv-table/cv-table.vue +460 -0
  61. package/ui-cv/cv-tag/cv-tag.vue +276 -0
  62. package/ui-cv/cv-tbody/cv-tbody.vue +28 -0
  63. package/ui-cv/cv-td/cv-td.vue +93 -0
  64. package/ui-cv/cv-test/{uni-test.vue → cv-test.vue} +0 -0
  65. package/ui-cv/cv-th/cv-th.vue +270 -0
  66. package/ui-cv/cv-thead/cv-thead.vue +114 -0
  67. package/ui-cv/cv-title/cv-title.vue +168 -0
  68. package/ui-cv/cv-tr/cv-tr.vue +166 -0
  69. package/ui-cv/cv-transition/cv-transition.vue +279 -0
  70. package/ui-cv/cv-calendar/uni-calendar-item.vue +0 -171
  71. package/ui-cv/cv-calendar/uni-calendar.vue +0 -504
  72. package/ui-cv/cv-card/uni-card.vue +0 -420
  73. package/ui-cv/cv-col/uni-col.vue +0 -2968
  74. package/ui-cv/cv-collapse/uni-collapse.vue +0 -146
  75. package/ui-cv/cv-collapse-item/uni-collapse-item.vue +0 -378
  76. package/ui-cv/cv-combox/uni-combox.vue +0 -237
  77. package/ui-cv/cv-countdown/uni-countdown.vue +0 -234
  78. package/ui-cv/cv-data-checkbox/uni-data-checkbox.vue +0 -792
  79. package/ui-cv/cv-data-indexed-list/uni-data-indexed-list-item.vue +0 -142
  80. package/ui-cv/cv-data-indexed-list/uni-data-indexed-list.vue +0 -364
  81. package/ui-cv/cv-data-picker/uni-data-picker.vue +0 -468
  82. package/ui-cv/cv-data-pickerview/uni-data-pickerview.vue +0 -298
  83. package/ui-cv/cv-dateformat/uni-dateformat.vue +0 -88
  84. package/ui-cv/cv-datetime-picker/uni-datetime-picker.vue +0 -874
  85. package/ui-cv/cv-easyinput/uni-easyinput.vue +0 -438
  86. package/ui-cv/cv-fab/uni-fab.vue +0 -443
  87. package/ui-cv/cv-fav/uni-fav.vue +0 -136
  88. package/ui-cv/cv-file-picker/uni-file-picker.vue +0 -614
  89. package/ui-cv/cv-indexed-list/uni-indexed-list-item.vue +0 -142
  90. package/ui-cv/cv-indexed-list/uni-indexed-list.vue +0 -357
  91. package/ui-cv/cv-list/uni-list.vue +0 -107
  92. package/ui-cv/cv-list/uni-refresh.vue +0 -65
  93. package/ui-cv/cv-list-ad/uni-list-ad.vue +0 -106
  94. package/ui-cv/cv-list-item/uni-list-item.vue +0 -428
  95. package/ui-cv/cv-nav-bar/uni-nav-bar.vue +0 -244
  96. package/ui-cv/cv-notice-bar/uni-notice-bar.vue +0 -394
  97. package/ui-cv/cv-number-box/uni-number-box.vue +0 -224
  98. package/ui-cv/cv-pagination/uni-pagination.vue +0 -376
  99. package/ui-cv/cv-popup/uni-popup.vue +0 -412
  100. package/ui-cv/cv-popup-message/uni-popup-message.vue +0 -143
  101. package/ui-cv/cv-search-bar/uni-search-bar.vue +0 -262
  102. package/ui-cv/cv-steps/uni-steps.vue +0 -250
  103. package/ui-cv/cv-swiper-dot/uni-swiper-dot.vue +0 -205
  104. package/ui-cv/cv-table/uni-table.vue +0 -455
  105. package/ui-cv/cv-tag/uni-tag.vue +0 -283
  106. package/ui-cv/cv-tbody/uni-tbody.vue +0 -30
  107. package/ui-cv/cv-td/uni-td.vue +0 -88
  108. package/ui-cv/cv-th/uni-th.vue +0 -259
  109. package/ui-cv/cv-thead/uni-thead.vue +0 -114
  110. package/ui-cv/cv-title/uni-title.vue +0 -171
  111. package/ui-cv/cv-tr/uni-tr.vue +0 -156
  112. package/ui-cv/cv-transition/uni-transition.vue +0 -287
@@ -0,0 +1,958 @@
1
+ <template>
2
+ <view class="uni-date">
3
+ <view class="uni-date-editor" @click="show">
4
+ <slot>
5
+ <view class="uni-date-editor--x" :class="{ 'uni-date-editor--x__disabled': disabled, 'uni-date-x--border': border }">
6
+ <view v-if="!isRange" class="uni-date-x uni-date-single">
7
+ <view class="uni-date__icon-logo">
8
+ <image class="uni-date-editor--logo" :src="iconBase64" mode=""></image>
9
+ </view>
10
+ <input class="uni-date__input" type="text" v-model="singleVal" :placeholder="placeholder" :disabled="true" />
11
+ </view>
12
+ <view v-else class="uni-date-x uni-date-range">
13
+ <view class="uni-date__icon-logo">
14
+ <image class="uni-date-editor--logo" :src="iconBase64" mode=""></image>
15
+ </view>
16
+ <input
17
+ class="uni-date__input uni-date-range__input"
18
+ type="text"
19
+ v-model="range.startDate"
20
+ :placeholder="startPlaceholder"
21
+ :disabled="true"
22
+ />
23
+ <slot>
24
+ <view class="">{{ rangeSeparator }}</view>
25
+ </slot>
26
+ <input
27
+ class="uni-date__input uni-date-range__input"
28
+ type="text"
29
+ v-model="range.endDate"
30
+ :placeholder="endPlaceholder"
31
+ :disabled="true"
32
+ />
33
+ </view>
34
+ <view
35
+ v-show="clearIcon && !disabled && !isPhone && (singleVal || (range.startDate && range.endDate))"
36
+ class="uni-date__icon-clear"
37
+ @click.stop="clear"
38
+ >
39
+ <cv-icon2 type="clear" color="#e1e1e1" size="14"></cv-icon2>
40
+ </view>
41
+ </view>
42
+ </slot>
43
+ </view>
44
+
45
+ <view v-show="popup" class="uni-date-mask" @click="close"></view>
46
+ <view v-if="!isPhone" ref="datePicker" v-show="popup" class="uni-date-picker__container">
47
+ <view v-if="!isRange" class="uni-date-single--x" :style="popover">
48
+ <view v-show="hasTime" class="uni-date-changed popup-x-header">
49
+ <input class="uni-date__input uni-date-range__input" type="text" v-model="tempSingleDate" placeholder="选择日期" />
50
+ <time-picker
51
+ type="time"
52
+ v-model="time"
53
+ :border="false"
54
+ :disabled="!tempSingleDate"
55
+ :start="reactStartTime"
56
+ :end="reactEndTime"
57
+ >
58
+ <input
59
+ class="uni-date__input uni-date-range__input"
60
+ type="text"
61
+ v-model="time"
62
+ placeholder="选择时间"
63
+ :disabled="!tempSingleDate"
64
+ />
65
+ </time-picker>
66
+ </view>
67
+ <calendar
68
+ ref="pcSingle"
69
+ :showMonth="false"
70
+ :start-date="caleRange.startDate"
71
+ :end-date="caleRange.endDate"
72
+ :date="defSingleDate"
73
+ @change="singleChange"
74
+ />
75
+ <view v-if="hasTime" class="popup-x-footer">
76
+ <!-- <text class="">此刻</text> -->
77
+ <text class="confirm" @click="confirmSingleChange">确定</text>
78
+ </view>
79
+ <view class="uni-date-popper__arrow"></view>
80
+ </view>
81
+
82
+ <view v-else class="uni-date-range--x" :style="popover">
83
+ <view v-show="hasTime" class="popup-x-header uni-date-changed">
84
+ <view class="popup-x-header--datetime">
85
+ <input
86
+ class="uni-date__input uni-date-range__input"
87
+ type="text"
88
+ v-model="tempRange.startDate"
89
+ placeholder="开始日期"
90
+ />
91
+ <time-picker
92
+ type="time"
93
+ v-model="tempRange.startTime"
94
+ :start="reactStartTime"
95
+ :border="false"
96
+ :disabled="!tempRange.startDate"
97
+ >
98
+ <input
99
+ class="uni-date__input uni-date-range__input"
100
+ type="text"
101
+ v-model="tempRange.startTime"
102
+ placeholder="开始时间"
103
+ :disabled="!tempRange.startDate"
104
+ />
105
+ </time-picker>
106
+ </view>
107
+ <cv-icon2 type="arrowthinright" color="#999" style="line-height: 40px"></cv-icon2>
108
+ <view class="popup-x-header--datetime">
109
+ <input class="uni-date__input uni-date-range__input" type="text" v-model="tempRange.endDate" placeholder="结束日期" />
110
+ <time-picker
111
+ type="time"
112
+ v-model="tempRange.endTime"
113
+ :end="reactEndTime"
114
+ :border="false"
115
+ :disabled="!tempRange.endDate"
116
+ >
117
+ <input
118
+ class="uni-date__input uni-date-range__input"
119
+ type="text"
120
+ v-model="tempRange.endTime"
121
+ placeholder="结束时间"
122
+ :disabled="!tempRange.endDate"
123
+ />
124
+ </time-picker>
125
+ </view>
126
+ </view>
127
+ <view class="popup-x-body">
128
+ <calendar
129
+ ref="left"
130
+ :showMonth="false"
131
+ :start-date="caleRange.startDate"
132
+ :end-date="caleRange.endDate"
133
+ :range="true"
134
+ @change="leftChange"
135
+ :pleStatus="endMultipleStatus"
136
+ @firstEnterCale="updateRightCale"
137
+ @monthSwitch="leftMonthSwitch"
138
+ style="padding-right: 16px"
139
+ />
140
+ <calendar
141
+ ref="right"
142
+ :showMonth="false"
143
+ :start-date="caleRange.startDate"
144
+ :end-date="caleRange.endDate"
145
+ :range="true"
146
+ @change="rightChange"
147
+ :pleStatus="startMultipleStatus"
148
+ @firstEnterCale="updateLeftCale"
149
+ @monthSwitch="rightMonthSwitch"
150
+ style="padding-left: 16px; border-left: 1px solid #f1f1f1"
151
+ />
152
+ </view>
153
+ <view v-if="hasTime" class="popup-x-footer">
154
+ <text class="" @click="clear">清空</text>
155
+ <text class="confirm" @click="confirmRangeChange">确定</text>
156
+ </view>
157
+ </view>
158
+ </view>
159
+ <calendar
160
+ v-if="isPhone"
161
+ ref="mobile"
162
+ :clearDate="false"
163
+ :date="defSingleDate"
164
+ :defTime="reactMobDefTime"
165
+ :start-date="caleRange.startDate"
166
+ :end-date="caleRange.endDate"
167
+ :selectableTimes="mobSelectableTime"
168
+ :pleStatus="endMultipleStatus"
169
+ :showMonth="false"
170
+ :range="isRange"
171
+ :typeHasTime="hasTime"
172
+ :insert="false"
173
+ @confirm="mobileChange"
174
+ />
175
+ </view>
176
+ </template>
177
+ <script>
178
+ import calendar from './calendar.vue';
179
+ import timePicker from './time-picker.vue';
180
+
181
+ /**
182
+ * DatetimePicker 时间选择器
183
+ * @description 同时支持 PC 和移动端使用日历选择日期和日期范围
184
+ * @tutorial https://ext.dcloud.net.cn/plugin?id=3962
185
+ * @property {String} type 选择器类型
186
+ * @property {String|Array} value 绑定值
187
+ * @property {String} placeholder 单选择时的占位内容
188
+ * @property {String} start 起始时间
189
+ * @property {String} start 终止时间
190
+ * @property {String} start-placeholder 范围选择时开始日期的占位内容
191
+ * @property {String} end-placeholder 范围选择时结束日期的占位内容
192
+ * @property {String} range-separator 选择范围时的分隔符
193
+ * @property {Boolean} border = [true|false] 是否有边框
194
+ * @property {Boolean} disabled = [true|false] 是否禁用
195
+ * @property {Boolean} clearIcon = [true|false] 是否显示清除按钮(仅PC端适用)
196
+ * @event {Function} change 确定日期时触发的事件
197
+ **/
198
+
199
+ export default {
200
+ name: 'UniDatetimePicker',
201
+ components: {
202
+ calendar,
203
+ timePicker
204
+ },
205
+ data() {
206
+ return {
207
+ isRange: false,
208
+ hasTime: false,
209
+ mobileRange: false,
210
+ // 单选
211
+ singleVal: '',
212
+ tempSingleDate: '',
213
+ defSingleDate: '',
214
+ time: '',
215
+ // 范围选
216
+ caleRange: {
217
+ startDate: '',
218
+ startTime: '',
219
+ endDate: '',
220
+ endTime: ''
221
+ },
222
+ range: {
223
+ startDate: '',
224
+ // startTime: '',
225
+ endDate: ''
226
+ // endTime: ''
227
+ },
228
+ tempRange: {
229
+ startDate: '',
230
+ startTime: '',
231
+ endDate: '',
232
+ endTime: ''
233
+ },
234
+ // 左右日历同步数据
235
+ startMultipleStatus: {
236
+ before: '',
237
+ after: '',
238
+ data: [],
239
+ fulldate: ''
240
+ },
241
+ endMultipleStatus: {
242
+ before: '',
243
+ after: '',
244
+ data: [],
245
+ fulldate: ''
246
+ },
247
+ visible: false,
248
+ popup: false,
249
+ popover: null,
250
+ isEmitValue: false,
251
+ isPhone: false,
252
+ isFirstShow: true,
253
+ iconBase64:
254
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABmJLR0QA/wD/AP+gvaeTAAACVklEQVRoge2Zv2vTQRTAP4oWJQQskmolBAnSQVMcSxbp4ubmIEWETu0oIjg5iIOgpLNunfQfMHToUgpOVgfRqRAL4q8WRLQVq4sOdyHPL9/7evfNJReS+8DB433v7r37fl/eu9xBJBKUB0BLt+uDaOOQZb8SUNXyuKuRftg46NeXcBww6M8AC0ANOAycAyb1s7e6+SbNxi/gBfAQ2HadcA7YB/4MUPsKzLos4jzwewAcNy3mhMnx5I/9BiqUAD4DDWAXmAfqWt8Enlq+GBfSbEwAt4AicAxYBO7aTPaGzhu4KvTLQn/Hh9cpmGzcFvqmaXAyaxWE/MGTg93yXsgFUyfbOrJCJ2s8y+tRP21s0fmMTlmih8zT8WnN1GloCmJWaF0CpvrlSAb1/3fJXshNT470hZEIrZeoahqaU8BZ10Exa4XGtiCaKKL+EIHaMX8U81ZEP7ntrwi7n4CfWi7p+UCFdFdh7Rpaps9+mn93rjY2THut0QqtoVlIkpi1QjNyCzEdnl0W+idCXxb6VmKudaGfsbBhRbcHdEWhf5eYt0o6FVR6BjhqYcOKoQkt2y/SAB5rWVbpVeCilmUl3hb6JNeAI1p+ZWEjFzH9hsY2tEwHdHX9DGATWNLyceCeGL/YhY+58LWhy9o0uhJDKw3T4dlr4L6WZab5JvRBGJqs9UPI5R44lQfpx56pUzK0NlA3R6AK1Engu1+/nGhfK7R5bjtwGnXdFfpSJ6190Quz5grqQCC048lFXMhy2nQZWkUVsRowZv8OvLOPCvdHwE5APyKRSMQzfwE22DtT3T5PPwAAAABJRU5ErkJggg=='
255
+ };
256
+ },
257
+ props: {
258
+ type: {
259
+ type: String,
260
+ default: 'datetime'
261
+ },
262
+ value: {
263
+ type: [String, Number, Array, Date],
264
+ default: ''
265
+ },
266
+ modelValue: {
267
+ type: [String, Number, Array, Date],
268
+ default: ''
269
+ },
270
+ start: {
271
+ type: [Number, String],
272
+ default: ''
273
+ },
274
+ end: {
275
+ type: [Number, String],
276
+ default: ''
277
+ },
278
+ returnType: {
279
+ type: String,
280
+ default: 'string'
281
+ },
282
+ placeholder: {
283
+ type: String,
284
+ default: '选择日期'
285
+ },
286
+ startPlaceholder: {
287
+ type: String,
288
+ default: '起始日期'
289
+ },
290
+ endPlaceholder: {
291
+ type: String,
292
+ default: '结束日期'
293
+ },
294
+ rangeSeparator: {
295
+ type: String,
296
+ default: '-'
297
+ },
298
+ border: {
299
+ type: [Boolean],
300
+ default: true
301
+ },
302
+ disabled: {
303
+ type: [Boolean],
304
+ default: false
305
+ },
306
+ clearIcon: {
307
+ type: [Boolean],
308
+ default: true
309
+ }
310
+ },
311
+ watch: {
312
+ type: {
313
+ immediate: true,
314
+ handler(newVal, oldVal) {
315
+ if (newVal.indexOf('time') !== -1) {
316
+ this.hasTime = true;
317
+ } else {
318
+ this.hasTime = false;
319
+ }
320
+ if (newVal.indexOf('range') !== -1) {
321
+ this.isRange = true;
322
+ } else {
323
+ this.isRange = false;
324
+ }
325
+ }
326
+ },
327
+ value: {
328
+ immediate: true,
329
+ handler(newVal, oldVal) {
330
+ if (this.isEmitValue) {
331
+ this.isEmitValue = false;
332
+ return;
333
+ }
334
+ this.initPicker(newVal);
335
+ }
336
+ },
337
+
338
+ start: {
339
+ immediate: true,
340
+ handler(newVal, oldVal) {
341
+ if (!newVal) return;
342
+ const { defDate, defTime } = this.parseDate(newVal);
343
+ this.caleRange.startDate = defDate;
344
+ if (this.hasTime) {
345
+ this.caleRange.startTime = defTime;
346
+ }
347
+ }
348
+ },
349
+
350
+ end: {
351
+ immediate: true,
352
+ handler(newVal, oldVal) {
353
+ if (!newVal) return;
354
+ const { defDate, defTime } = this.parseDate(newVal);
355
+ this.caleRange.endDate = defDate;
356
+ if (this.hasTime) {
357
+ this.caleRange.endTime = defTime;
358
+ }
359
+ }
360
+ }
361
+ },
362
+ computed: {
363
+ reactStartTime() {
364
+ const activeDate = this.isRange ? this.tempRange.startDate : this.tempSingleDate;
365
+ const res = activeDate === this.caleRange.startDate ? this.caleRange.startTime : '';
366
+ return res;
367
+ },
368
+ reactEndTime() {
369
+ const activeDate = this.isRange ? this.tempRange.endDate : this.tempSingleDate;
370
+ const res = activeDate === this.caleRange.endDate ? this.caleRange.endTime : '';
371
+ return res;
372
+ },
373
+ reactMobDefTime() {
374
+ return this.isRange
375
+ ? {
376
+ start: this.tempRange.startTime,
377
+ end: this.tempRange.endTime
378
+ }
379
+ : this.time;
380
+ },
381
+ mobSelectableTime() {
382
+ return {
383
+ start: this.caleRange.startTime,
384
+ end: this.caleRange.endTime
385
+ };
386
+ },
387
+ datePopupWidth() {
388
+ // todo
389
+ return this.isRange ? 653 : 301;
390
+ }
391
+ },
392
+ created() {
393
+ this.form = this.getForm('uniForms');
394
+ this.formItem = this.getForm('uniFormsItem');
395
+
396
+ // if (this.formItem) {
397
+ // if (this.formItem.name) {
398
+ // this.rename = this.formItem.name
399
+ // this.form.inputChildrens.push(this)
400
+ // }
401
+ // }
402
+ },
403
+ mounted() {
404
+ this.platform();
405
+ },
406
+ methods: {
407
+ /**
408
+ * 获取父元素实例
409
+ */
410
+ getForm(name = 'uniForms') {
411
+ let parent = this.$parent;
412
+ let parentName = parent.$options.name;
413
+ while (parentName !== name) {
414
+ parent = parent.$parent;
415
+ if (!parent) return false;
416
+ parentName = parent.$options.name;
417
+ }
418
+ return parent;
419
+ },
420
+ initPicker(newVal) {
421
+ if (!newVal || (Array.isArray(newVal) && !newVal.length)) {
422
+ this.$nextTick(() => {
423
+ this.clear(false);
424
+ });
425
+ return;
426
+ }
427
+ if (!Array.isArray(newVal) && !this.isRange) {
428
+ const { defDate, defTime } = this.parseDate(newVal);
429
+ this.singleVal = defDate;
430
+ this.tempSingleDate = defDate;
431
+ this.defSingleDate = defDate;
432
+ if (this.hasTime) {
433
+ this.singleVal = defDate + ' ' + defTime;
434
+ this.time = defTime;
435
+ }
436
+ } else {
437
+ const [before, after] = newVal;
438
+ if (!before && !after) return;
439
+ const defBefore = this.parseDate(before);
440
+ const defAfter = this.parseDate(after);
441
+ const startDate = defBefore.defDate;
442
+ const endDate = defAfter.defDate;
443
+ this.range.startDate = this.tempRange.startDate = startDate;
444
+ this.range.endDate = this.tempRange.endDate = endDate;
445
+
446
+ if (this.hasTime) {
447
+ this.range.startDate = defBefore.defDate + ' ' + defBefore.defTime;
448
+ this.range.endDate = defAfter.defDate + ' ' + defAfter.defTime;
449
+ this.tempRange.startTime = defBefore.defTime;
450
+ this.tempRange.endTime = defAfter.defTime;
451
+ }
452
+ const defaultRange = {
453
+ before: defBefore.defDate,
454
+ after: defAfter.defDate
455
+ };
456
+ this.startMultipleStatus = Object.assign({}, this.startMultipleStatus, defaultRange, {
457
+ which: 'right'
458
+ });
459
+ this.endMultipleStatus = Object.assign({}, this.endMultipleStatus, defaultRange, {
460
+ which: 'left'
461
+ });
462
+ }
463
+ },
464
+ updateLeftCale(e) {
465
+ const left = this.$refs.left;
466
+ // 设置范围选
467
+ left.cale.setHoverMultiple(e.after);
468
+ left.setDate(this.$refs.left.nowDate.fullDate);
469
+ },
470
+ updateRightCale(e) {
471
+ const right = this.$refs.right;
472
+ // 设置范围选
473
+ right.cale.setHoverMultiple(e.after);
474
+ right.setDate(this.$refs.right.nowDate.fullDate);
475
+ },
476
+ platform() {
477
+ const systemInfo = uni.getSystemInfoSync();
478
+ this.isPhone = systemInfo.windowWidth <= 500;
479
+ this.windowWidth = systemInfo.windowWidth;
480
+ },
481
+ show(event) {
482
+ if (this.disabled) {
483
+ return;
484
+ }
485
+ this.platform();
486
+ if (this.isPhone) {
487
+ this.$refs.mobile.open();
488
+ return;
489
+ }
490
+ this.popover = {
491
+ top: '10px'
492
+ };
493
+ const dateEditor = uni.createSelectorQuery().in(this).select('.uni-date-editor');
494
+ dateEditor
495
+ .boundingClientRect((rect) => {
496
+ if (this.windowWidth - rect.left < this.datePopupWidth) {
497
+ this.popover.right = 0;
498
+ }
499
+ })
500
+ .exec();
501
+ setTimeout(() => {
502
+ this.popup = !this.popup;
503
+ if (!this.isPhone && this.isRange && this.isFirstShow) {
504
+ this.isFirstShow = false;
505
+ const { startDate, endDate } = this.range;
506
+ if (startDate && endDate) {
507
+ if (this.diffDate(startDate, endDate) < 30) {
508
+ this.$refs.right.next();
509
+ }
510
+ } else {
511
+ this.$refs.right.next();
512
+ this.$refs.right.cale.lastHover = false;
513
+ }
514
+ }
515
+ }, 20);
516
+ },
517
+
518
+ close() {
519
+ setTimeout(() => {
520
+ this.popup = false;
521
+ this.$emit('maskClick', this.value);
522
+ }, 20);
523
+ },
524
+ setEmit(value) {
525
+ if (this.returnType === 'timestamp' || this.returnType === 'date') {
526
+ if (!Array.isArray(value)) {
527
+ if (!this.hasTime) {
528
+ value = value + ' ' + '00:00:00';
529
+ }
530
+ value = this.createTimestamp(value);
531
+ if (this.returnType === 'date') {
532
+ value = new Date(value);
533
+ }
534
+ } else {
535
+ if (!this.hasTime) {
536
+ value[0] = value[0] + ' ' + '00:00:00';
537
+ value[1] = value[1] + ' ' + '00:00:00';
538
+ }
539
+ value[0] = this.createTimestamp(value[0]);
540
+ value[1] = this.createTimestamp(value[1]);
541
+ if (this.returnType === 'date') {
542
+ value[0] = new Date(value[0]);
543
+ value[1] = new Date(value[1]);
544
+ }
545
+ }
546
+ }
547
+ this.formItem && this.formItem.setValue(value);
548
+ this.$emit('change', value);
549
+ this.$emit('input', value);
550
+ this.$emit('update:modelValue', value);
551
+ this.isEmitValue = true;
552
+ },
553
+ createTimestamp(date) {
554
+ date = this.fixIosDateFormat(date);
555
+ return Date.parse(new Date(date));
556
+ },
557
+ singleChange(e) {
558
+ this.tempSingleDate = e.fulldate;
559
+ if (this.hasTime) return;
560
+ this.confirmSingleChange();
561
+ },
562
+
563
+ confirmSingleChange() {
564
+ if (!this.tempSingleDate) {
565
+ this.popup = false;
566
+ return;
567
+ }
568
+ if (this.hasTime) {
569
+ this.singleVal = this.tempSingleDate + ' ' + (this.time ? this.time : '00:00:00');
570
+ } else {
571
+ this.singleVal = this.tempSingleDate;
572
+ }
573
+ this.setEmit(this.singleVal);
574
+ this.popup = false;
575
+ },
576
+
577
+ leftChange(e) {
578
+ const { before, after } = e.range;
579
+ this.rangeChange(before, after);
580
+ const obj = {
581
+ before: e.range.before,
582
+ after: e.range.after,
583
+ data: e.range.data,
584
+ fulldate: e.fulldate
585
+ };
586
+ this.startMultipleStatus = Object.assign({}, this.startMultipleStatus, obj);
587
+ },
588
+
589
+ rightChange(e) {
590
+ const { before, after } = e.range;
591
+ this.rangeChange(before, after);
592
+ const obj = {
593
+ before: e.range.before,
594
+ after: e.range.after,
595
+ data: e.range.data,
596
+ fulldate: e.fulldate
597
+ };
598
+ this.endMultipleStatus = Object.assign({}, this.endMultipleStatus, obj);
599
+ },
600
+
601
+ mobileChange(e) {
602
+ if (this.isRange) {
603
+ const { before, after } = e.range;
604
+ this.handleStartAndEnd(before, after, true);
605
+ if (this.hasTime) {
606
+ const { startTime, endTime } = e.timeRange;
607
+ this.tempRange.startTime = startTime;
608
+ this.tempRange.endTime = endTime;
609
+ }
610
+ this.confirmRangeChange();
611
+ } else {
612
+ if (this.hasTime) {
613
+ this.singleVal = e.fulldate + ' ' + e.time;
614
+ } else {
615
+ this.singleVal = e.fulldate;
616
+ }
617
+ this.setEmit(this.singleVal);
618
+ }
619
+ this.$refs.mobile.close();
620
+ },
621
+
622
+ rangeChange(before, after) {
623
+ if (!(before && after)) return;
624
+ this.handleStartAndEnd(before, after, true);
625
+ if (this.hasTime) return;
626
+ this.confirmRangeChange();
627
+ },
628
+
629
+ confirmRangeChange() {
630
+ if (!this.tempRange.startDate && !this.tempRange.endDate) {
631
+ this.popup = false;
632
+ return;
633
+ }
634
+ let start, end;
635
+ if (!this.hasTime) {
636
+ start = this.range.startDate = this.tempRange.startDate;
637
+ end = this.range.endDate = this.tempRange.endDate;
638
+ } else {
639
+ start = this.range.startDate =
640
+ this.tempRange.startDate + ' ' + (this.tempRange.startTime ? this.tempRange.startTime : '00:00:00');
641
+ end = this.range.endDate = this.tempRange.endDate + ' ' + (this.tempRange.endTime ? this.tempRange.endTime : '00:00:00');
642
+ }
643
+ const displayRange = [start, end];
644
+ this.setEmit(displayRange);
645
+ this.popup = false;
646
+ },
647
+
648
+ handleStartAndEnd(before, after, temp = false) {
649
+ if (!(before && after)) return;
650
+ const type = temp ? 'tempRange' : 'range';
651
+ if (this.dateCompare(before, after)) {
652
+ this[type].startDate = before;
653
+ this[type].endDate = after;
654
+ } else {
655
+ this[type].startDate = after;
656
+ this[type].endDate = before;
657
+ }
658
+ },
659
+
660
+ /**
661
+ * 比较时间大小
662
+ */
663
+ dateCompare(startDate, endDate) {
664
+ // 计算截止时间
665
+ startDate = new Date(startDate.replace('-', '/').replace('-', '/'));
666
+ // 计算详细项的截止时间
667
+ endDate = new Date(endDate.replace('-', '/').replace('-', '/'));
668
+ if (startDate <= endDate) {
669
+ return true;
670
+ } else {
671
+ return false;
672
+ }
673
+ },
674
+
675
+ /**
676
+ * 比较时间差
677
+ */
678
+ diffDate(startDate, endDate) {
679
+ // 计算截止时间
680
+ startDate = new Date(startDate.replace('-', '/').replace('-', '/'));
681
+ // 计算详细项的截止时间
682
+ endDate = new Date(endDate.replace('-', '/').replace('-', '/'));
683
+ const diff = (endDate - startDate) / (24 * 60 * 60 * 1000);
684
+ return Math.abs(diff);
685
+ },
686
+
687
+ clear(needEmit = true) {
688
+ if (!this.isRange) {
689
+ this.singleVal = '';
690
+ if (this.isPhone) {
691
+ this.defSingleDate = '';
692
+ } else {
693
+ this.$refs.pcSingle.calendar.fullDate = '';
694
+ this.$refs.pcSingle.setDate();
695
+ }
696
+ if (needEmit) {
697
+ this.formItem && this.formItem.setValue('');
698
+ this.$emit('change', '');
699
+ this.$emit('input', '');
700
+ this.$emit('update:modelValue', '');
701
+ }
702
+ } else {
703
+ this.range.startDate = '';
704
+ this.range.endDate = '';
705
+ this.tempRange = {};
706
+ if (this.isPhone) {
707
+ this.endMultipleStatus = Object.assign(
708
+ {},
709
+ this.endMultipleStatus,
710
+ {
711
+ before: '',
712
+ after: '',
713
+ data: [],
714
+ fulldate: ''
715
+ },
716
+ {
717
+ which: 'left'
718
+ }
719
+ );
720
+ } else {
721
+ this.$refs.left.cale.multipleStatus.before = '';
722
+ this.$refs.left.cale.multipleStatus.after = '';
723
+ this.$refs.left.cale.multipleStatus.data = [];
724
+ this.$refs.left.cale.lastHover = false;
725
+ this.$refs.left.setDate();
726
+ this.$refs.right.cale.multipleStatus.before = '';
727
+ this.$refs.right.cale.multipleStatus.after = '';
728
+ this.$refs.right.cale.multipleStatus.data = [];
729
+ this.$refs.right.cale.lastHover = false;
730
+ this.$refs.right.setDate();
731
+ this.$refs.right.next();
732
+ }
733
+ if (needEmit) {
734
+ this.formItem && this.formItem.setValue([]);
735
+ this.$emit('change', []);
736
+ this.$emit('input', []);
737
+ this.$emit('update:modelValue', []);
738
+ }
739
+ }
740
+ },
741
+
742
+ parseDate(date) {
743
+ date = this.fixIosDateFormat(date);
744
+ const defVal = new Date(date);
745
+ const year = defVal.getFullYear();
746
+ const month = defVal.getMonth() + 1;
747
+ const day = defVal.getDate();
748
+ const hour = defVal.getHours();
749
+ const minute = defVal.getMinutes();
750
+ const second = defVal.getSeconds();
751
+ const defDate = year + '-' + this.lessTen(month) + '-' + this.lessTen(day);
752
+ const defTime = this.lessTen(hour) + ':' + this.lessTen(minute) + ':' + this.lessTen(second);
753
+ return {
754
+ defDate,
755
+ defTime
756
+ };
757
+ },
758
+
759
+ lessTen(item) {
760
+ return item < 10 ? '0' + item : item;
761
+ },
762
+
763
+ //兼容 iOS、safari 日期格式
764
+ fixIosDateFormat(value) {
765
+ if (typeof value === 'string') {
766
+ value = value.replace(/-/g, '/');
767
+ }
768
+ return value;
769
+ },
770
+
771
+ leftMonthSwitch(e) {
772
+ // console.log('leftMonthSwitch 返回:', e)
773
+ },
774
+ rightMonthSwitch(e) {
775
+ // console.log('rightMonthSwitch 返回:', e)
776
+ }
777
+ }
778
+ };
779
+ </script>
780
+
781
+ <style scoped>
782
+ @charset "UTF-8";
783
+
784
+ .uni-date-x {
785
+ display: flex;
786
+ flex-direction: row;
787
+ align-items: center;
788
+ justify-content: center;
789
+ padding: 0 10px;
790
+ border-radius: 4px;
791
+ background-color: #fff;
792
+ color: #666;
793
+ font-size: 14px;
794
+ }
795
+
796
+ .uni-date-x--border {
797
+ box-sizing: border-box;
798
+ border-radius: 4px;
799
+ border: 1px solid #dcdfe6;
800
+ }
801
+
802
+ .uni-date-editor--x {
803
+ position: relative;
804
+ }
805
+
806
+ .uni-date-editor--x .uni-date__icon-clear {
807
+ position: absolute;
808
+ top: 5px;
809
+ right: 0;
810
+ display: inline-block;
811
+ box-sizing: border-box;
812
+ border: 6px solid transparent;
813
+ margin-right: 6px;
814
+ /* #ifdef H5 */
815
+ cursor: pointer;
816
+ /* #endif */
817
+ }
818
+
819
+ .uni-date__input {
820
+ height: 40px;
821
+ width: 100%;
822
+ padding: 0 8px;
823
+ line-height: 40px;
824
+ font-size: 14px;
825
+ }
826
+
827
+ .uni-date-range__input {
828
+ text-align: center;
829
+ }
830
+
831
+ .uni-date-picker__container {
832
+ position: relative;
833
+ /* position: fixed;
834
+ left: 0;
835
+ right: 0;
836
+ top: 0;
837
+ bottom: 0;
838
+ box-sizing: border-box;
839
+ z-index: 996;
840
+ font-size: 14px; */
841
+ }
842
+
843
+ .uni-date-mask {
844
+ position: fixed;
845
+ bottom: 0px;
846
+ top: 0px;
847
+ left: 0px;
848
+ right: 0px;
849
+ background-color: rgba(0, 0, 0, 0);
850
+ transition-duration: 0.3s;
851
+ z-index: 996;
852
+ }
853
+
854
+ .uni-date-single--x {
855
+ /* padding: 0 8px; */
856
+ position: absolute;
857
+ top: 0;
858
+ z-index: 999;
859
+ border: 1px solid #e4e7ed;
860
+ box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
861
+ border-radius: 4px;
862
+ }
863
+
864
+ .uni-date-range--x {
865
+ padding: 0 8px;
866
+ background-color: #fff;
867
+ position: absolute;
868
+ top: 0;
869
+ z-index: 999;
870
+ border: 1px solid #e4e7ed;
871
+ box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
872
+ border-radius: 4px;
873
+ }
874
+
875
+ .uni-date-editor--x__disabled {
876
+ opacity: 0.4;
877
+ cursor: default;
878
+ }
879
+
880
+ .uni-date-editor--logo {
881
+ width: 16px;
882
+ height: 16px;
883
+ vertical-align: middle;
884
+ }
885
+
886
+ /* 添加时间 */
887
+ .popup-x-header {
888
+ /* #ifndef APP-NVUE */
889
+ display: flex;
890
+ /* #endif */
891
+ flex-direction: row;
892
+ /* justify-content: space-between; */
893
+ }
894
+
895
+ .popup-x-header--datetime {
896
+ /* #ifndef APP-NVUE */
897
+ display: flex;
898
+ /* #endif */
899
+ flex-direction: row;
900
+ flex: 1;
901
+ }
902
+
903
+ .popup-x-body {
904
+ display: flex;
905
+ }
906
+
907
+ .popup-x-footer {
908
+ padding: 0 15px;
909
+ border-top-color: #f1f1f1;
910
+ border-top-style: solid;
911
+ border-top-width: 1px;
912
+ background-color: #fff;
913
+ line-height: 40px;
914
+ text-align: right;
915
+ color: #666;
916
+ }
917
+
918
+ .popup-x-footer text:hover {
919
+ color: #007aff;
920
+ cursor: pointer;
921
+ opacity: 0.8;
922
+ }
923
+
924
+ .popup-x-footer .confirm {
925
+ margin-left: 20px;
926
+ color: #007aff;
927
+ }
928
+
929
+ .uni-date-changed {
930
+ background-color: #fff;
931
+ text-align: center;
932
+ color: #333;
933
+ border-bottom-color: #f1f1f1;
934
+ border-bottom-style: solid;
935
+ border-bottom-width: 1px;
936
+ /* padding: 0 50px; */
937
+ }
938
+
939
+ .uni-date-changed--time text {
940
+ /* padding: 0 20px; */
941
+ height: 50px;
942
+ line-height: 50px;
943
+ }
944
+
945
+ .uni-date-changed .uni-date-changed--time {
946
+ /* display: flex; */
947
+ flex: 1;
948
+ }
949
+
950
+ .uni-date-changed--time-date {
951
+ color: #333;
952
+ opacity: 0.6;
953
+ }
954
+
955
+ .mr-50 {
956
+ margin-right: 50px;
957
+ }
958
+ </style>