vue_zhongyou 1.0.10 → 1.0.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue_zhongyou",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "keywords": [],
@@ -109,6 +109,18 @@
109
109
  @click="openAddressPicker(field)"
110
110
  />
111
111
 
112
+ <!-- 单个日期时间 -->
113
+ <van-field
114
+ v-else-if="field.type === 'datetime'"
115
+ is-link
116
+ readonly
117
+ :label="field.label"
118
+ :label-width="60"
119
+ :placeholder="field.placeholder || '请选择日期时间'"
120
+ :model-value="getDateTimeText(field)"
121
+ :rules="field.rules || []"
122
+ @click="openDateTime(field)"
123
+ />
112
124
 
113
125
  <!-- 自定义内容 -->
114
126
  <slot v-else :field="field" :value="formData[field.field]" />
@@ -190,6 +202,23 @@
190
202
  @cancel="closeAddressPicker"
191
203
  />
192
204
  </van-popup>
205
+
206
+ <!-- 单个日期时间 -->
207
+ <van-popup v-model:show="dateTimePopup.visible" position="bottom" round>
208
+ <div class="datetime-popup">
209
+ <div class="popup-header">
210
+ <span class="cancel-btn" @click="closeDateTime">取消</span>
211
+ <span class="confirm-btn" @click="confirmDateTime">确定</span>
212
+ </div>
213
+ <nut-date-picker
214
+ v-model="dateTimePopup.selectedTime"
215
+ type="datetime"
216
+ :show-toolbar="false"
217
+ :filter="dateTimeFilter"
218
+ @change="onSingleDateTimeChange"
219
+ />
220
+ </div>
221
+ </van-popup>
193
222
  </template>
194
223
 
195
224
  <script setup>
@@ -254,6 +283,14 @@ const addressPopup = ref({
254
283
  columnsPlaceholder: null
255
284
  })
256
285
 
286
+ // 单个日期时间弹窗状态
287
+ const dateTimePopup = ref({
288
+ visible: false,
289
+ field: null,
290
+ selectedTime: new Date(),
291
+ currentHour: '8'
292
+ })
293
+
257
294
 
258
295
 
259
296
 
@@ -268,6 +305,7 @@ const getDefaultValue = (type) => {
268
305
  if (type === 'checkbox') return []
269
306
  if (type === 'dateRange') return ['', '']
270
307
  if (type === 'datetimeRange') return ['', '']
308
+ if (type === 'datetime') return ''
271
309
  if (type === 'address') return { province: '', city: '', county: '', code: '' }
272
310
  return ''
273
311
  }
@@ -441,27 +479,39 @@ const confirmDateTimeRange = () => {
441
479
  }
442
480
 
443
481
  // 日期时间选择器筛选函数
444
- const startTimeFilter = (type, options) => {
482
+ // 通用时间过滤函数,根据类型(开始时间/结束时间)和当前小时值过滤选项
483
+ const timeFilter = (type, options, timeType) => {
445
484
  if (type === 'hour') {
446
485
  return options.filter(option => ['08', '12', '13', '17'].includes(option.value))
447
486
  } else if (type === 'minute') {
448
- // 当小时位是'08'或者'12'时,分钟只保留'00'
449
- if (['12','13'].includes(dateTimeRangePopup.value.currentStartHour)) {
487
+ // 获取对应时间类型的当前小时值
488
+ const currentHour = timeType === 'start'
489
+ ? dateTimeRangePopup.value.currentStartHour
490
+ : dateTimeRangePopup.value.currentEndHour
491
+
492
+ // 当小时位是'12'或者'13'时,分钟只保留'00'
493
+ if (['12','13'].includes(currentHour)) {
450
494
  return options.filter(option => ['00'].includes(option.value))
451
- }else{
495
+ } else {
452
496
  return options.filter(option => ['30'].includes(option.value))
453
497
  }
454
498
  }
455
499
  return options
456
500
  }
457
- const endTimeFilter = (type, options) => {
501
+
502
+ // 开始时间和结束时间的过滤器包装函数
503
+ const startTimeFilter = (type, options) => timeFilter(type, options, 'start')
504
+ const endTimeFilter = (type, options) => timeFilter(type, options, 'end')
505
+
506
+ // 单个日期时间的过滤函数
507
+ const dateTimeFilter = (type, options) => {
458
508
  if (type === 'hour') {
459
509
  return options.filter(option => ['08', '12', '13', '17'].includes(option.value))
460
510
  } else if (type === 'minute') {
461
- // 当小时位是'08'或者'12'时,分钟只保留'00'
462
- if (['12','13'].includes(dateTimeRangePopup.value.currentEndHour)) {
511
+ // 当小时位是'12'或者'13'时,分钟只保留'00'
512
+ if (['12','13'].includes(dateTimePopup.value.currentHour)) {
463
513
  return options.filter(option => ['00'].includes(option.value))
464
- }else{
514
+ } else {
465
515
  return options.filter(option => ['30'].includes(option.value))
466
516
  }
467
517
  }
@@ -558,6 +608,73 @@ const getAddressText = (field) => {
558
608
  return parts.join('')
559
609
  }
560
610
 
611
+ // 单个日期时间
612
+ const openDateTime = (field) => {
613
+ dateTimePopup.value.visible = true
614
+ dateTimePopup.value.field = field
615
+
616
+ // 设置默认时间为当天8:30
617
+ const today = new Date()
618
+ const defaultTime = new Date(today)
619
+ defaultTime.setHours(8, 30, 0, 0)
620
+
621
+ // 将field的时间转换为日期时间格式
622
+ dateTimePopup.value.selectedTime = typeof field.defaultValue === 'string' ? reverseFormatDateTime(field.defaultValue) : defaultTime
623
+
624
+ // 初始化当前小时值
625
+ dateTimePopup.value.currentHour = '8'
626
+ }
627
+
628
+ const closeDateTime = () => {
629
+ dateTimePopup.value.visible = false
630
+ }
631
+
632
+ const confirmDateTime = () => {
633
+ if (!dateTimePopup.value.selectedTime) {
634
+ return
635
+ }
636
+
637
+ // 格式化日期时间
638
+ const dateTimeStr = formatDateTime(dateTimePopup.value.selectedTime)
639
+
640
+ // 更新表单数据
641
+ if (dateTimePopup.value.field) {
642
+ updateFieldValue(dateTimePopup.value.field.field, dateTimeStr)
643
+ }
644
+
645
+ // 关闭弹窗
646
+ closeDateTime()
647
+ }
648
+
649
+ const getDateTimeText = (field) => {
650
+ const value = formData[field.field]
651
+ return value || ''
652
+ }
653
+
654
+ const onSingleDateTimeChange = (params) => {
655
+ // 更新当前选择的时间
656
+ if (params && params.selectedValue) {
657
+ const [year, month, day, hour, minute] = params.selectedValue
658
+ const newDate = new Date(year, month - 1, day, hour, minute)
659
+ dateTimePopup.value.selectedTime = newDate
660
+
661
+ // 更新当前选择的小时值
662
+ if (params && params.selectedValue && params.columnIndex === 3) {
663
+ // 更新小时值
664
+ dateTimePopup.value.currentHour = params.selectedValue[3];
665
+
666
+ // 根据小时值设置默认分钟值
667
+ if (['08', '17'].includes(params.selectedValue[3])) {
668
+ // 小时为08或17时,分钟设为30
669
+ dateTimePopup.value.selectedTime.setMinutes(30)
670
+ } else if (['12', '13'].includes(params.selectedValue[3])) {
671
+ // 小时为12或13时,分钟设为00
672
+ dateTimePopup.value.selectedTime.setMinutes(0)
673
+ }
674
+ }
675
+ }
676
+ }
677
+
561
678
 
562
679
 
563
680
  </script>
@@ -630,6 +747,30 @@ const getAddressText = (field) => {
630
747
  }
631
748
  }
632
749
 
750
+ .datetime-popup {
751
+ .popup-header {
752
+ display: flex;
753
+ justify-content: space-between;
754
+ align-items: center;
755
+ padding: 16px;
756
+ border-bottom: 1px solid #f0f0f0;
757
+
758
+ .cancel-btn, .confirm-btn {
759
+ font-size: 16px;
760
+ padding: 4px 8px;
761
+ cursor: pointer;
762
+ }
763
+
764
+ .cancel-btn {
765
+ color: #666;
766
+ }
767
+
768
+ .confirm-btn {
769
+ color: #1989fa;
770
+ }
771
+ }
772
+ }
773
+
633
774
  :deep(.van-cell) {
634
775
  padding: 8px;
635
776
  }