use-range.js 621 B

12345678910111213141516171819
  1. import { computed } from 'vue'
  2. import { isEmpty } from '@cip/utils/util'
  3. export const useRange = (props, defaultJoint = '与') => {
  4. const min = computed(() => {
  5. if (isEmpty(props.modelValue)) return props.config?.min
  6. return props.modelValue > props.config?.min ? props.modelValue : props.config?.min
  7. })
  8. const max = computed(() => {
  9. if (isEmpty(props.otherValue)) return props.config?.max
  10. return props.otherValue > props.config?.max ? props.config?.max : props.otherValue
  11. })
  12. const joint = computed(() => {
  13. return props.config?.joint ?? defaultJoint
  14. })
  15. return {
  16. min, max, joint
  17. }
  18. }