index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div
  3. :class="['basic-time-range',{'is-focus': isFocus}]"
  4. :style="{width}"
  5. >
  6. <cip-time-select
  7. class="cip-time-range"
  8. v-bind="{...attrs,...startInputProps}"
  9. v-model="proxyValue"
  10. :disabled="disabled"
  11. :maxTime="maxTime"
  12. :no-icon="true"
  13. @focus="onValueFocus"
  14. @blur="onValueBlur"
  15. />
  16. <span class="basic-time-range__link"> — </span>
  17. <cip-time-select
  18. class="cip-time-range"
  19. v-bind="{...attrs,...endInputProps}"
  20. v-model="proxyOtherValue[0].value"
  21. :disabled="disabled"
  22. :minTime="minTime"
  23. @focus="onOtherValueFocus"
  24. @blur="onOtherValueBlur"
  25. />
  26. </div>
  27. </template>
  28. <script>
  29. import { computed } from 'vue'
  30. import CipTimeSelect from '@cip/components/cip-time-select'
  31. import {
  32. formInputProps,
  33. fromInputEmits,
  34. useFormInput,
  35. useInputProps
  36. } from '@cip/components/helper/form-input'
  37. import { useFocusInput } from '../date-range/use-focus-input'
  38. export default {
  39. components: { CipTimeSelect },
  40. props: formInputProps,
  41. emits: [...fromInputEmits],
  42. setup (props, context) {
  43. const formInput = useFormInput(props, context, { maxOtherKey: 1 })
  44. const { width, securityConfig, proxyValue, proxyOtherValue } = formInput
  45. const startInputProps = useInputProps(props, [
  46. ['startPlaceholder', 'placeholder'],
  47. ['start', { defaultValue: '00:00' }],
  48. ['end', { defaultValue: '23:30' }],
  49. ['step', { defaultValue: '00:30' }]
  50. ])
  51. const endInputProps = useInputProps(props, [
  52. ['endPlaceholder', 'placeholder'],
  53. ['start', { defaultValue: '00:00' }],
  54. ['end', { defaultValue: '23:30' }],
  55. ['step', { defaultValue: '00:30' }]
  56. ])
  57. const attrs = computed(() => {
  58. return props.config?.attrs ?? {}
  59. })
  60. const startTransValue = computed(() => {
  61. return proxyValue.value ?? securityConfig.value.startDefaultValue
  62. })
  63. const endTransValue = computed(() => {
  64. return proxyOtherValue[0].value ?? securityConfig.value.endDefaultValue
  65. })
  66. const minTime = computed(() => {
  67. return startTransValue.value ?? securityConfig.value.start
  68. })
  69. const maxTime = computed(() => {
  70. return endTransValue.value ?? securityConfig.value.end
  71. })
  72. const [isValueFocus, onValueFocus, onValueBlur] = useFocusInput()
  73. const [isOtherValueFocus, onOtherValueFocus, onOtherValueBlur] = useFocusInput()
  74. const isFocus = computed(() => {
  75. return isValueFocus.value || isOtherValueFocus.value
  76. })
  77. return {
  78. proxyValue,
  79. proxyOtherValue,
  80. startTransValue,
  81. endTransValue,
  82. attrs,
  83. width,
  84. minTime,
  85. maxTime,
  86. startInputProps,
  87. endInputProps,
  88. isFocus,
  89. onValueFocus,
  90. onValueBlur,
  91. onOtherValueFocus,
  92. onOtherValueBlur
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="less">
  98. .basic-time-range{
  99. box-sizing: border-box;
  100. display: flex;
  101. flex-grow: 1;
  102. align-items: center;
  103. padding: 0 1px;
  104. line-height: var(~'--@{elNamespace}-component-size');
  105. box-shadow: 0 0 0 1px var(~'--@{elNamespace}-input-border-color',var(~'--@{elNamespace}-border-color')) inset;
  106. border-radius: var(~'--@{elNamespace}-input-border-radius',var(~'--@{elNamespace}-border-radius-base'));
  107. &:hover{
  108. box-shadow: 0 0 0 1px var(~'--@{elNamespace}-border-color-hover',var(~'--@{elNamespace}-border-color')) inset;
  109. }
  110. &.is-focus{
  111. box-shadow: 0 0 0 1px @primary inset;
  112. }
  113. &__link{
  114. color: var(~'--@{elNamespace}-input-text-color');
  115. margin: 0 4px;
  116. font-size: 16px;
  117. zoom: 0.625;
  118. }
  119. .cip-time-range.cip-time-select{
  120. flex-grow: 2;
  121. flex-basis: 0;
  122. line-height: var(~'--@{elNamespace}-component-size');
  123. .@{elNamespace}-input__wrapper{
  124. box-shadow: none !important;
  125. padding-top: 0;
  126. padding-bottom: 0;
  127. .@{elNamespace}-input__inner{
  128. text-align: center;
  129. }
  130. }
  131. }
  132. }
  133. </style>