@opentiny/vue-renderless
Version:
An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.
59 lines (58 loc) • 1.89 kB
JavaScript
import "../chunk-G2ADBYYC.js";
const optionMethod = (value) => {
const val = ("0" + value).slice(-2);
return { id: +val, label: val };
};
const watchModelValue = ({ props, state }) => () => {
const { modelValue, showSeconds } = props;
const num = showSeconds ? 3 : 2;
if (!showSeconds && modelValue.length === 3) {
state.seconds = modelValue[2];
}
state.dateArr = modelValue && state.dateArr.toString() !== "NaN,NaN,NaN" ? modelValue.slice(0, num) : [];
};
const watchVisible = ({ api, state }) => (value) => {
state.visible = value;
value && api.watchModelValue();
};
const updateVisible = ({ state, emit }) => (value) => {
state.visible = value;
emit("update:visible", value);
};
const confirm = ({ emit, state }) => (value) => {
const dateArr = value.map((item) => ("0" + item).slice(-2));
state.dateArr = dateArr;
emit("update:modelValue", state.value);
emit("confirm", state.value);
};
const clear = ({ state, emit, api, vm, dispatch }) => ($event) => {
state.dateArr = [];
vm.$refs.cascaderSelect.clear(state.dateArr);
emit("update:modelValue", state.dateArr);
emit("clear", state.dateArr);
dispatch("Picker", "handle-clear", $event);
api.updateVisible(false);
};
const getTimePeriod = ({ state, props }) => (unit, length) => {
const step = props.step || {};
const value = step[unit] || 1;
return Array.from({ length }).map((v, key) => key).filter((v) => v % value === 0).map((v) => optionMethod(v));
};
const computedOptions = ({ state, api, props }) => () => {
const { showSeconds } = props;
const options = [];
options.push(api.getTimePeriod("hour", 24));
options.push(api.getTimePeriod("minute", 60));
showSeconds && options.push(api.getTimePeriod("second", 60));
return options;
};
export {
clear,
computedOptions,
confirm,
getTimePeriod,
optionMethod,
updateVisible,
watchModelValue,
watchVisible
};