diff --git a/src/main.js b/src/main.js index d3acb01..2ef291b 100644 --- a/src/main.js +++ b/src/main.js @@ -1,10 +1,9 @@ import { createApp } from 'vue' - import Cookies from 'js-cookie' import ElementPlus from 'element-plus' import locale from 'element-plus/lib/locale/lang/zh-cn' // 中文语言 - +import 'dayjs/locale/zh-cn' import '@/assets/styles/index.scss' // global css import App from './App' @@ -41,6 +40,8 @@ import ImagePreview from "@/components/ImagePreview" import TreeSelect from '@/components/TreeSelect' // 字典标签组件 import DictTag from '@/components/DictTag' +// el-date-picker 快捷选项 +import dateOptions from '@/utils/dateOptions' const app = createApp(App) signalR.init( @@ -55,6 +56,7 @@ app.config.globalProperties.resetForm = resetForm app.config.globalProperties.handleTree = handleTree app.config.globalProperties.addDateRange = addDateRange app.config.globalProperties.selectDictLabel = selectDictLabel +app.config.globalProperties.dateOptions = dateOptions // 全局组件挂载 app.component('DictTag', DictTag) diff --git a/src/utils/dateOptions.js b/src/utils/dateOptions.js new file mode 100644 index 0000000..aea921e --- /dev/null +++ b/src/utils/dateOptions.js @@ -0,0 +1,77 @@ +// dayjs 参考:https://www.cnblogs.com/Airon-wei/p/14362160.html +import dayjs from 'dayjs' + +const dateOptions = [ +{ + text: '昨天', + value: () => { + const end = new Date(); + const start = new Date(); + start.setTime(start.getTime() - 3600 * 1000 * 24); + end.setTime(end.getTime() - 3600 * 1000 * 24); + // console.log(dayjs().format('YYYY-MM-DD HH:mm:ss')); + return [start, end] + } +}, +{ + text: '本周', + value: () => { + const end = dayjs().endOf('week').add(1, 'day').format('YYYY-MM-DD'); + const start = dayjs().startOf('week').add(1, 'day').format('YYYY-MM-DD') + return [start, end] + } +}, +{ + text: '上周', + value: () => { + const start = dayjs().add(-1, 'week').startOf('week').add(1, 'day').format('YYYY-MM-DD') + const end = dayjs().add(-1, 'week').endOf('week').add(1, 'day').format('YYYY-MM-DD') + return [start, end] + } +}, +{ + text: '本月', + value: () => { + const end = dayjs().endOf('month').format('YYYY-MM-DD') + const start = dayjs().startOf('month').format('YYYY-MM-DD') + + return [start, end] + }, +}, +{ + text: '上月', + value: () => { + const end = dayjs().startOf('month').format('YYYY-MM-DD') + const start = dayjs().add(-1, 'month').startOf('month').format('YYYY-MM-DD') + + return [start, end] + } +}, +{ + text: '最近一周', + value: () => { + const end = new Date() + const start = new Date() + start.setTime(start.getTime() - 3600 * 1000 * 24 * 7) + return [start, end] + }, +}, +{ + text: '最近一个月', + value: () => { + const end = new Date() + const start = new Date() + start.setTime(start.getTime() - 3600 * 1000 * 24 * 30) + return [start, end] + }, +}, +{ + text: '最近三个月', + value: () => { + const end = new Date() + const start = new Date() + start.setTime(start.getTime() - 3600 * 1000 * 24 * 90) + return [start, end] + }, +}] +export default dateOptions \ No newline at end of file