use-range.js 915 B

1234567891011121314151617181920212223242526
  1. import { computed } from 'vue'
  2. import { isEmpty } from '@cip/utils/util'
  3. export const useRange = (props, defaultJoint = '与') => {
  4. const min = computed(() => {
  5. const configMin = props.config?.min
  6. // 如果modelValue不存在 直接返回配置的min
  7. if (isEmpty(props.modelValue)) return configMin
  8. // 如果modelValue存在但configMin不存在
  9. if (isEmpty(configMin)) return props.modelValue
  10. // 如果modelValue存在 configMin也存在
  11. return props.modelValue > configMin ? props.modelValue : configMin
  12. })
  13. const max = computed(() => {
  14. const configMax = props.config?.max
  15. if (isEmpty(props.otherValue)) return configMax
  16. if (isEmpty(configMax)) return props.otherValue
  17. return props.otherValue > configMax ? configMax : props.otherValue
  18. })
  19. const joint = computed(() => {
  20. return props.config?.joint ?? defaultJoint
  21. })
  22. return {
  23. min, max, joint
  24. }
  25. }