import Vue from "vue"; import dayjs from "dayjs"; // 默认中文 require("dayjs/locale/zh-cn"); dayjs.locale("zh-cn"); Vue.prototype.$date = dayjs; Vue.filter("date", function(value) { return value && dayjs(value).format("YYYY-MM-DD"); }); Vue.filter("dateTime", function(value, format = "YYYY-MM-DD HH:mm:ss") { if ((value + "").length == 10) { value *= 1000; } return value && dayjs(value).format(format); }); const week = "周一、周二、周三、周四、周五、周六、周曰".split("、"); Vue.filter("week", function(v) { return week[v]; }); Vue.prototype.$dateRange = { // startToEnd: (unit) => { const v = [ dayjs() .startOf(unit) .toDate(), dayjs() .endOf(unit) .toDate() ]; return v; }, // before: (days) => { return [ dayjs() .add(days, "day") .startOf("d") .toDate(), dayjs() .endOf("d") .toDate() ]; }, // yesterday: (days) => { return [ dayjs() .add(days, "day") .startOf("d") .toDate(), dayjs() .add(days, "day") .endOf("d") .toDate() ]; } };