From 2c33e5aab787e478cdb9f8a95917f72060176c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Fri, 29 Apr 2022 20:01:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eelement=20ui=E7=BB=84?= =?UTF-8?q?=E4=BB=B6el-datepicker=E6=96=B0=E5=A2=9E=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 6 ++-- src/utils/dateOptions.js | 77 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/utils/dateOptions.js 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