新增element ui组件el-datepicker新增快捷选项

This commit is contained in:
不做码农 2022-04-29 20:01:25 +08:00
parent 554c9b8690
commit 2c33e5aab7
2 changed files with 81 additions and 2 deletions

View File

@ -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)

77
src/utils/dateOptions.js Normal file
View File

@ -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