738beb6284085b48b543812d0b37355442b7da68d554f191c60b3000e90f98a184ddf0e8375507ed3aa793b59f90af08b258c39cc7e6a8e822d4ae064b5980 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { ref, onMounted, nextTick } from 'vue';
  2. import { useEventListener } from '@vueuse/core';
  3. import { isArray } from '@vue/shared';
  4. import { isNumber } from '../../../../utils/types.mjs';
  5. const useLifecycle = (props, initData, resetSize) => {
  6. const sliderWrapper = ref();
  7. onMounted(async () => {
  8. if (props.range) {
  9. if (isArray(props.modelValue)) {
  10. initData.firstValue = Math.max(props.min, props.modelValue[0]);
  11. initData.secondValue = Math.min(props.max, props.modelValue[1]);
  12. } else {
  13. initData.firstValue = props.min;
  14. initData.secondValue = props.max;
  15. }
  16. initData.oldValue = [initData.firstValue, initData.secondValue];
  17. } else {
  18. if (!isNumber(props.modelValue) || Number.isNaN(props.modelValue)) {
  19. initData.firstValue = props.min;
  20. } else {
  21. initData.firstValue = Math.min(props.max, Math.max(props.min, props.modelValue));
  22. }
  23. initData.oldValue = initData.firstValue;
  24. }
  25. useEventListener(window, "resize", resetSize);
  26. await nextTick();
  27. resetSize();
  28. });
  29. return {
  30. sliderWrapper
  31. };
  32. };
  33. export { useLifecycle };
  34. //# sourceMappingURL=use-lifecycle.mjs.map