UNPKG

yanzhen-design-vue

Version:

85 lines (84 loc) 3.21 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const vue = require("vue"); const dayjs = require("dayjs"); const utils = require("@yanzhen-libs/utils"); const utilsVue = require("@yanzhen-libs/utils-vue"); const lodashEs = require("lodash-es"); const rangeTime = require("./range-time.cjs"); function useRangeTime(props, emit, context) { const _ref = vue.ref(null); const updatePropsKeys = utilsVue.useDynamicProps({ update: true }); const value = utilsVue.useModel(props, "value", emit); const beginTime = utilsVue.useModel(props, "beginTime", emit); const endTime = utilsVue.useModel(props, "endTime", emit); const showTimeRef = vue.computed(() => { const { showTime } = props; const defaultValue = [dayjs("00:00:00", "HH:mm:ss"), dayjs("23:59:59", "HH:mm:ss")]; return showTime === true ? { format: "HH:mm:ss", defaultValue } : utils.isEmptyValue(showTime) ? false : showTime; }); const formatRef = vue.computed(() => { const format = props.format; const showTime = vue.unref(showTimeRef); if (showTime === false) { return utils.isEmptyValue(format) ? "YYYY-MM-DD" : format; } else { return utils.isEmptyValue(format) ? "YYYY-MM-DD HH:mm:ss" : format; } }); function handleUpdateValue(_value) { const format = vue.unref(formatRef); let [begin, end] = !utils.isEmptyArray(_value) ? _value : []; begin = utils.isEmptyValue(begin) ? void 0 : dayjs(begin).format(format); end = utils.isEmptyValue(end) ? void 0 : dayjs(end).format(format); beginTime.value = begin; endTime.value = end; value.value = utils.isEmptyValue(end) ? void 0 : [begin, end]; console.log(begin, end, beginTime.value, format, "begin, endbegin, end"); } const valueRef = vue.computed(() => { if (updatePropsKeys.includes("beginTime") && updatePropsKeys.includes("endTime")) { const begin2 = utils.isEmptyValue(vue.unref(beginTime)) ? void 0 : dayjs(vue.unref(beginTime)); const end2 = utils.isEmptyValue(vue.unref(endTime)) ? void 0 : dayjs(vue.unref(endTime)); return [begin2, end2]; } const [begin, end] = !utils.isEmptyArray(vue.unref(value)) ? vue.unref(value) : []; return [ utils.isEmptyValue(begin) ? void 0 : dayjs(begin), utils.isEmptyValue(end) ? void 0 : dayjs(end) ]; }); const attrs = vue.useAttrs(); const slots = vue.useSlots(); const slotKeys = Object.keys(slots); const config = vue.computed(() => lodashEs.pick(props, ...Object.keys(rangeTime.antRangePickerProps.props))); const proxyProps = utilsVue.useProxyProps(config, rangeTime.antRangePickerProps.emits, { emit, exclude: ["value", "showTime", "format"], filter: (key) => { switch (key) { case "onUpdate:value": case "onUpdate:beginTime": case "onUpdate:endTime": return false; } return true; } }); const propsRef = vue.computed(() => { return vue.mergeProps(vue.unref(attrs), vue.unref(proxyProps)); }); return { _ref, formatRef, showTimeRef, propsRef, slotKeys, valueRef, handleUpdateValue }; } exports.useRangeTime = useRangeTime;