tdesign-vue-next
Version:
TDesign Component for vue-next
112 lines (108 loc) • 3.95 kB
JavaScript
/**
* tdesign v1.20.2
* (c) 2026 tdesign
* @license MIT
*/
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { toRefs, computed, ref, watch } from 'vue';
import 'lodash-es';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-d9440b5f.js';
import '../../config-provider/hooks/useConfig.js';
import '../../_chunks/dep-dfeea6f5.js';
import { u as useVModel } from '../../_chunks/dep-cc2cf248.js';
import '@babel/runtime/helpers/defineProperty';
import { g as getDefaultFormat, e as extractTimeFormat, b as isValidDate, i as initYearMonthTime, f as formatDate, a as formatTime } from '../../_chunks/dep-954c2fab.js';
import '../../_chunks/dep-a6042a25.js';
import '../../config-provider/utils/context.js';
import '../../_chunks/dep-854d2777.js';
import 'dayjs';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/classCallCheck';
import '../../_chunks/dep-4c391d32.js';
import '../../_chunks/dep-2721b80a.js';
function useRangeValue(props) {
var _toRefs = toRefs(props),
valueFromProps = _toRefs.value,
modelValue = _toRefs.modelValue;
var _useVModel = useVModel(valueFromProps, modelValue, props.defaultValue, props.onChange),
_useVModel2 = _slicedToArray(_useVModel, 2),
rawValue = _useVModel2[0],
onRawChange = _useVModel2[1];
var value = computed(function () {
return Array.isArray(rawValue.value) ? rawValue.value : [];
});
var formatRef = computed(function () {
return getDefaultFormat({
mode: props.mode,
format: props.format,
valueType: props.valueType,
enableTimePicker: props.enableTimePicker
});
});
if (props.enableTimePicker) {
if (!extractTimeFormat(formatRef.value.format)) console.error("format: ".concat(formatRef.value.format, " \u4E0D\u89C4\u8303\uFF0C\u5305\u542B\u65F6\u95F4\u9009\u62E9\u5FC5\u987B\u8981\u6709\u65F6\u95F4\u683C\u5F0F\u5316 HH:mm:ss"));
}
if (!Array.isArray(rawValue.value)) {
console.error("typeof value: ".concat(rawValue.value, " must be Array!"));
} else if (!isValidDate(rawValue.value, formatRef.value.format)) {
console.error("value: ".concat(rawValue.value, " is invalid dateTime! Check whether the value is consistent with format: ").concat(formatRef.value.format));
}
var isFirstValueSelected = ref(false);
var time = ref(initYearMonthTime({
value: value.value,
mode: props.mode,
format: formatRef.value.format,
timeFormat: formatRef.value.timeFormat
}).time);
var month = ref(initYearMonthTime({
value: value.value,
mode: props.mode,
format: formatRef.value.format,
enableTimePicker: props.enableTimePicker
}).month);
var year = ref(initYearMonthTime({
value: value.value,
mode: props.mode,
format: formatRef.value.format
}).year);
var cacheValue = ref(formatDate(value.value, {
format: formatRef.value.format
}));
watch(function () {
return isFirstValueSelected.value;
}, function () {
if (year.value[1] < year.value[0]) {
year.value[1] = year.value[0];
}
if (year.value[0] === year.value[1] && month.value[1] < month.value[0]) {
month.value[1] = month.value[0];
}
});
watch(value, function (newValue) {
if (!rawValue.value) {
cacheValue.value = [];
return;
}
if (!isValidDate(newValue, formatRef.value.format)) return;
cacheValue.value = formatDate(newValue, {
format: formatRef.value.valueType,
targetFormat: formatRef.value.format
});
time.value = formatTime(newValue, formatRef.value.format, formatRef.value.timeFormat, props.defaultTime);
}, {
immediate: true
});
return {
year: year,
month: month,
value: value,
time: time,
isFirstValueSelected: isFirstValueSelected,
cacheValue: cacheValue,
onRawChange: onRawChange
};
}
export { useRangeValue };
//# sourceMappingURL=useRangeValue.js.map