index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div :class="['cip-date-scope',{'is-focus': isFocus, 'is-separate': isSeparate}]" :style="{width}">
  3. <basic-date-picker
  4. class="cip-date-range"
  5. v-model="proxyValue"
  6. :config="config"
  7. :disabled="disabled"
  8. @focus="onValueFocus"
  9. @blur="onValueBlur"
  10. />
  11. <span class="cip-date-scope__link"> — </span>
  12. <!-- 此处验证由上级处理-->
  13. <basic-date-picker
  14. class="cip-date-range"
  15. v-model="proxyOtherValue[0].value"
  16. :config="otherConfig"
  17. :disabled="disabled"
  18. @focus="onOtherValueFocus"
  19. @blur="onOtherValueBlur"
  20. />
  21. </div>
  22. </template>
  23. <script>
  24. import BasicDatePicker from '../../basic/date-picker'
  25. import { computed } from 'vue'
  26. import { useFormInput } from '@cip/components/hooks/form-input'
  27. import { formInputProps, fromInputEmits } from '../../form-input-props'
  28. import { dateInfoToTimes, getNotEmptyValue } from './util'
  29. import { getUsingConfig, isInputEmpty } from '@cip/utils/util'
  30. import { useFocusInput } from './use-focus-input'
  31. import { useCipConfig } from '@cip/components/hooks/use-cip-config'
  32. export default {
  33. components: { BasicDatePicker },
  34. props: formInputProps,
  35. emits: [...fromInputEmits],
  36. setup (props, context) {
  37. const {
  38. proxyValue,
  39. proxyOtherValue,
  40. securityConfig,
  41. ...formInput
  42. } = useFormInput(props, context, {
  43. maxOtherKey: 1
  44. })
  45. const cipConfig = useCipConfig()
  46. const isSeparate = computed(() => getUsingConfig(securityConfig.value.separate, cipConfig.range?.separate, false))
  47. const config = computed(() => {
  48. const config = { ...props.config }
  49. config.max = Math.min(...dateInfoToTimes(getNotEmptyValue(proxyOtherValue[0].value, props.config.max)))
  50. config.noIcon = !isSeparate.value // true
  51. return config
  52. })
  53. const otherConfig = computed(() => {
  54. const config = { ...props.config }
  55. config.min = Math.max(...dateInfoToTimes(getNotEmptyValue(proxyValue.value, securityConfig.value.otherMin ?? securityConfig.value.min)))
  56. if (!isInputEmpty(securityConfig.value.otherMax)) config.max = securityConfig.value.otherMax
  57. config.placeholder = securityConfig.value.otherPlaceholder
  58. // viewType为date或默认的时候,启用otherDate标记,返回值修改时分秒为23:59:59
  59. if (['date', undefined].includes(config.viewType)) config.isOtherDate = true
  60. return config
  61. })
  62. const [isValueFocus, onValueFocus, onValueBlur] = useFocusInput()
  63. const [isOtherValueFocus, onOtherValueFocus, onOtherValueBlur] = useFocusInput()
  64. const isFocus = computed(() => {
  65. return isValueFocus.value || isOtherValueFocus.value
  66. })
  67. return {
  68. ...formInput,
  69. onValueFocus,
  70. onValueBlur,
  71. onOtherValueFocus,
  72. onOtherValueBlur,
  73. isFocus,
  74. isSeparate,
  75. config,
  76. otherConfig,
  77. proxyValue,
  78. proxyOtherValue
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="less">
  84. .cip-date-scope{
  85. display: flex;
  86. width: 100%;
  87. align-items: center;
  88. &.is-separate{
  89. .cip-date-scope__link{
  90. // is-success 将导致字体变色
  91. color: var(~'--@{elNamespace}-input-text-color');
  92. font-size: 16px;
  93. zoom: 0.625;
  94. margin: 0 4px;
  95. }
  96. }
  97. }
  98. // 教研错误时的颜色变化
  99. .@{elNamespace}-form-item.is-error .cip-date-scope:not(.is-separate){
  100. box-shadow: 0 0 0 1px var(~'--@{elNamespace}-color-danger') inset;
  101. }
  102. .cip-date-scope:not(.is-separate){
  103. padding: 1px 1px;
  104. box-shadow: 0 0 0 1px var(~'--@{elNamespace}-input-border-color',var(~'--@{elNamespace}-border-color')) inset;
  105. border-radius: var(~'--@{elNamespace}-input-border-radius',var(~'--@{elNamespace}-border-radius-base'));
  106. &:hover{
  107. box-shadow: 0 0 0 1px var(~'--@{elNamespace}-border-color-hover',var(~'--@{elNamespace}-border-color')) inset;
  108. }
  109. &.is-focus{
  110. box-shadow: 0 0 0 1px @primary inset;
  111. }
  112. .cip-date-range.cip-form-picker{
  113. line-height: var(~'--@{elNamespace}-component-size');
  114. flex-grow: 2;
  115. flex-basis: 0;
  116. display: flex;
  117. .@{elNamespace}-input__wrapper{
  118. box-shadow: none;
  119. padding-top: 0;
  120. padding-bottom: 0;
  121. .@{elNamespace}-input__inner{
  122. text-align: center;
  123. }
  124. }
  125. }
  126. .cip-date-scope__link{
  127. // is-success 将导致字体变色
  128. color: var(~'--@{elNamespace}-input-text-color');
  129. font-size: 16px;
  130. zoom: 0.625;
  131. margin: 0 4px;
  132. }
  133. .@{elNamespace}-date-editor.@{elNamespace}-input{
  134. width: 100%;
  135. flex-shrink: 1;
  136. }
  137. .@{elNamespace}-input__suffix{
  138. right: 0;
  139. }
  140. }
  141. </style>