birdpaper-ui
Version:
一个通用的 vue3 UI组件库。A common vue3 UI component library.
78 lines (77 loc) • 2.63 kB
JavaScript
;
const vue = require("vue");
const birdpaperIcon = require("birdpaper-icon");
const types = require("../types.js");
const core = require("../core.js");
const timeTable_vue_vue_type_script_setup_true_lang = require("./time-table.vue.js");
const _sfc_main = vue.defineComponent({
name: "DateTable",
components: { timeTable: timeTable_vue_vue_type_script_setup_true_lang, IconArrowLeftSLine: birdpaperIcon.IconArrowLeftSLine, IconArrowRightSLine: birdpaperIcon.IconArrowRightSLine, IconArrowLeftDoubleFill: birdpaperIcon.IconArrowLeftDoubleFill, IconArrowRightDoubleFill: birdpaperIcon.IconArrowRightDoubleFill },
emits: ["change-picker"],
setup(props, { emit }) {
const name = "bp-date-table";
let ctx = null;
ctx = vue.inject(types.dateInjectionKey);
const { toDay, current, currentMonth, currentYear, dates, setDates, changeMonth, changeYear, weeks, months } = core.useDayJs(
ctx.langs,
ctx.modelValue.value
);
const currentVal = vue.ref(current.value && current.value.format("YYYY-MM-DD"));
const currentTimeVal = vue.ref("");
setDates("YYYY-MM-DD");
const timeTableRef = vue.ref();
const handleSelect = (date) => {
currentVal.value = date.value;
if (ctx.showTime) {
const time = timeTableRef.value.getTime();
currentTimeVal.value = time;
return;
}
ctx.onSelect(currentVal.value, {}, true);
};
const onTimeSelect = (time) => {
currentTimeVal.value = time;
};
const handleChange = (mode, type, step = 1) => {
let v = mode === "month" ? currentMonth.value : currentYear.value;
v = type === "next" ? v + step : v - step;
mode === "month" ? changeMonth(v) : changeYear(v);
setDates(ctx.valueFormat);
};
const handleChangePicker = (typeName, val) => {
emit("change-picker", typeName, val);
};
const getValue = () => {
const val = `${currentVal.value} ${currentTimeVal.value}`;
ctx.onSelect(val, {}, true);
return val;
};
const setNow = () => {
currentVal.value = current.value && current.value.format("YYYY-MM-DD");
timeTableRef.value.setNow();
currentTimeVal.value = timeTableRef.value.getTime();
};
return {
ctx,
toDay,
current,
currentVal,
currentTimeVal,
name,
weeks,
months,
dates,
currentYear,
currentMonth,
handleChange,
handleSelect,
handleChangePicker,
PanelType: types.PanelType,
timeTableRef,
onTimeSelect,
getValue,
setNow
};
}
});
module.exports = _sfc_main;