index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="basic-time-range" :style="{width}">
  3. <el-time-select class="cip-form-picker"
  4. :model-value="startTransValue"
  5. @update:modelValue="emitStart"
  6. :disabled="disabled"
  7. :placeholder="startPlaceholder"
  8. :start="start"
  9. :end="end"
  10. :step="step"
  11. :maxTime="maxTime"
  12. v-bind="attrs"></el-time-select>
  13. <span class="basic-time-range__link">至</span>
  14. <el-time-select class="cip-form-picker"
  15. :model-value="endTransValue"
  16. @update:modelValue="emitEnd"
  17. :disabled="disabled"
  18. :placeholder="endPlaceholder"
  19. :start="start"
  20. :end="end"
  21. :step="step"
  22. :minTime="minTime"
  23. v-bind="attrs"></el-time-select>
  24. </div>
  25. </template>
  26. <script>
  27. import { ElTimeSelect } from 'element-plus'
  28. import { useFormInput } from '@cip/components/hooks/form-input'
  29. import { formInputProps } from '../../form-input-props'
  30. import { computed } from 'vue'
  31. // import dayjs from 'dayjs'
  32. export default {
  33. components: { ElTimeSelect },
  34. props: formInputProps,
  35. emits: ['update:modelValue', 'update:otherValue'],
  36. setup (props, context) {
  37. const formInput = useFormInput(props, context)
  38. const attrs = computed(() => {
  39. return props.config?.attrs ?? {}
  40. })
  41. const startPlaceholder = computed(() => {
  42. return props.config?.startPlaceholder ?? '请输入'
  43. })
  44. const endPlaceholder = computed(() => {
  45. return props.config?.endPlaceholder ?? '请输入'
  46. })
  47. const width = computed(() => {
  48. return props.config?.width ?? ''
  49. })
  50. const start = computed(() => {
  51. return props.config?.start ?? '08:00'
  52. })
  53. const end = computed(() => {
  54. return props.config?.end ?? '20:00'
  55. })
  56. const step = computed(() => {
  57. return props.config?.step ?? '00:30'
  58. })
  59. const startDefaultValue = computed(() => {
  60. return props.config.startDefaultValue
  61. })
  62. const startTransValue = computed(() => {
  63. return props.modelValue ?? startDefaultValue.value
  64. })
  65. const endTransValue = computed(() => {
  66. return props.otherValue ?? props.config.endDefaultValue
  67. })
  68. const minTime = computed(() => {
  69. return startTransValue?.value ?? start.value
  70. })
  71. const maxTime = computed(() => {
  72. return endTransValue?.value ?? end.value
  73. })
  74. const emitStart = (val) => {
  75. context.emit('update:modelValue', val)
  76. }
  77. const emitEnd = (val) => {
  78. context.emit('update:otherValue', val)
  79. }
  80. return {
  81. ...formInput,
  82. startTransValue,
  83. endTransValue,
  84. emitStart,
  85. emitEnd,
  86. attrs,
  87. start,
  88. end,
  89. step,
  90. startPlaceholder,
  91. endPlaceholder,
  92. width,
  93. minTime,
  94. maxTime
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="less" scoped>
  100. .basic-time-range{
  101. display: flex;
  102. flex-grow: 1;
  103. align-content: center;
  104. &__link{
  105. margin: 0 8px;
  106. }
  107. .cip-form-picker{
  108. flex: 1;
  109. width: 100%;
  110. }
  111. }
  112. </style>