index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div :style="{ width: item?.width ? item?.width + 'px' : '100%' }">
  3. <div class="d-flex align-center">
  4. <div v-if="item?.label" class="form-label" :style="{'width': item.labelWidth + 'px'}">{{ item.label }}</div>
  5. <el-config-provider :locale="zhCn">
  6. <el-date-picker
  7. style="flex: 1;"
  8. v-model="value"
  9. size="large"
  10. :type="item.mode || 'date'"
  11. :placeholder="item.placeholder || '请选择'"
  12. :start-placeholder="item.startPlaceholder || '开始日期'"
  13. :end-placeholder="item.endPlaceholder || '结束日期'"
  14. :format="item.format"
  15. :value-format="item.valueFormat || 'x'"
  16. :disabled="item.disabled"
  17. :disabled-date="disabledDates"
  18. :date-format="item.dateFormat"
  19. :time-format="item.timeFormat"
  20. :default-value="item.defaultValue"
  21. :teleported="false"
  22. @change="modelValueUpDate"
  23. @clear="handleClear"
  24. @blur="handleOpen"
  25. >
  26. </el-date-picker>
  27. </el-config-provider>
  28. </div>
  29. </div>
  30. </template>
  31. <script setup>
  32. defineOptions({ name:'FormUI-v-text-field'})
  33. import { ref, watch } from 'vue'
  34. import zhCn from 'element-plus/es/locale/lang/zh-cn'
  35. import { ElDatePicker } from 'element-plus'
  36. const props = defineProps({item: Object, modelValue: [String, Number, Boolean, Array], changeFn: Function})
  37. const emit = defineEmits(['update:modelValue', 'change'])
  38. const item = props.item
  39. const value = ref(props.modelValue)
  40. watch(() => props.modelValue,
  41. (newVal) => {
  42. value.value = newVal
  43. },
  44. { immediate: true },
  45. { deep: true }
  46. )
  47. // 过去的日期不可选
  48. const disabledDates = (date) => {
  49. // 未来的日期不可选
  50. if (props.item?.disabledFutureDates) {
  51. return date.getTime() > Date.now()
  52. }
  53. const currentDate = new Date()
  54. if (!props.item.disabledDate) return false
  55. // 过去的日期不可选
  56. currentDate.setDate(currentDate.getDate() - 1)
  57. return date.getTime() < currentDate.getTime()
  58. }
  59. const modelValueUpDate = (val) => {
  60. value.value = val
  61. emit('update:modelValue', value.value)
  62. emit('change', value.value)
  63. }
  64. const handleClear = () => {
  65. value.value = null
  66. emit('change', value.value)
  67. }
  68. const handleOpen = () => {
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. // .removeDetailHeight {}
  73. :deep(.dp--menu-wrapper) {
  74. // top: 50px !important;
  75. left: 0 !important;
  76. }
  77. .detailMargin {
  78. margin-bottom: 22px;
  79. }
  80. </style>