Просмотр исходного кода

reactor:日期选择新增选项;

zhangchong 7 месяцев назад
Родитель
Сommit
882edb7fe8
2 измененных файлов с 45 добавлено и 98 удалено
  1. 1 1
      src/utils/callCenter.ts
  2. 44 97
      src/utils/constants.ts

+ 1 - 1
src/utils/callCenter.ts

@@ -7,7 +7,7 @@ import { useThemeConfig } from '@/stores/themeConfig';
 import { storeToRefs } from 'pinia';
 
 /**
- * @description 呼叫中心配置 方法
+ * @description 为了兼容不同呼叫中心 呼叫中心配置 方法
  * @return
  *     cityName: 'name', // 中文名称
  *     cityCode: 'code', // 6位区号

+ 44 - 97
src/utils/constants.ts

@@ -11,131 +11,79 @@ export const shortcuts = [
 	{
 		text: '今天',
 		value: () => {
-			const end = new Date();
-			const start = new Date();
-			// 今天的开始时间
-			start.setHours(0);
-			start.setMinutes(0);
-			start.setSeconds(0);
-			// 今天的结束时间
-			end.setHours(23);
-			end.setMinutes(59);
-			end.setSeconds(59);
-			return [start, end];
+			return [dayjs().startOf('day'), dayjs().endOf('day')];
+		},
+	},
+	{
+		text: '本周',
+		value: () => {
+			return [dayjs().startOf('week'), dayjs().endOf('week')];
+		},
+	},
+	{
+		text: '上周',
+		value: () => {
+			return [dayjs().subtract(1, 'week').startOf('week'), dayjs().subtract(1, 'week').endOf('week')];
 		},
 	},
 	{
 		text: '近一周',
 		value: () => {
-			const end = new Date();
-			const start = new Date();
-			// 今天的开始时间
-			start.setHours(0);
-			start.setMinutes(0);
-			start.setSeconds(0);
-			// 今天的结束时间
-			end.setHours(23);
-			end.setMinutes(59);
-			end.setSeconds(59);
-			start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
-			return [start, end];
+			return [dayjs().subtract(7, 'day').startOf('day'), dayjs().endOf('day')];
+		},
+	},
+	{
+		text: '本月',
+		value: () => {
+			return [dayjs().startOf('month'), dayjs().endOf('month')];
+		},
+	},
+	{
+		text: '上个月',
+		value: () => {
+			return [dayjs().subtract(1, 'month').startOf('month'), dayjs().subtract(1, 'month').endOf('month')];
 		},
 	},
 	{
 		text: '近一个月',
 		value: () => {
-			const end = new Date();
-			const start = new Date();
-			// 今天的开始时间
-			start.setHours(0);
-			start.setMinutes(0);
-			start.setSeconds(0);
-			// 今天的结束时间
-			end.setHours(23);
-			end.setMinutes(59);
-			end.setSeconds(59);
-			start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
-			return [start, end];
+			return [dayjs().subtract(30, 'day').startOf('day'), dayjs().endOf('day')];
 		},
 	},
 	{
 		text: '上季度',
 		value: () => {
-			let oDate = new Date();
-			let prevMonth = oDate.getMonth() - 3;
-			const end = new Date();
-			const start = new Date();
-			start.setMonth(prevMonth);
-			start.setDate(1);
-			start.setHours(0);
-			start.setMinutes(0);
-			start.setSeconds(0);
-			end.setMonth(prevMonth + 3);
-			end.setDate(0);
-			end.setHours(23);
-			end.setMinutes(59);
-			end.setSeconds(59);
-			return [start, end];
+			return [dayjs().subtract(3, 'month').startOf('month'), dayjs().endOf('month')];
 		},
 	},
 	{
 		text: '本季度',
 		value: () => {
-			const end = new Date();
-			const start = new Date();
-			start.setMonth(Math.floor(new Date().getMonth() / 3) * 3);
-			start.setDate(1);
-			start.setHours(0);
-			start.setMinutes(0);
-			start.setSeconds(0);
-			end.setMonth(Math.floor(new Date().getMonth() / 3) * 3 + 3);
-			end.setDate(0);
-			end.setHours(23);
-			end.setMinutes(59);
-			end.setSeconds(59);
-			return [start, end];
+			return [dayjs().startOf('month'), dayjs().add(3, 'month').endOf('month')];
 		},
 	},
 	{
 		text: '去年',
 		value: () => {
-			let oDate = new Date();
-			let prevYear = oDate.getFullYear() - 1;
-			const end = new Date();
-			const start = new Date();
-			start.setFullYear(prevYear);
-			start.setMonth(0);
-			start.setDate(1);
-			end.setFullYear(prevYear);
-			end.setMonth(11);
-			end.setDate(31);
-			// 今天的开始时间
-			start.setHours(0);
-			start.setMinutes(0);
-			start.setSeconds(0);
-			// 今天的结束时间
-			end.setHours(23);
-			end.setMinutes(59);
-			end.setSeconds(59);
-			return [start, end];
+			return [dayjs().subtract(1, 'year').startOf('year'), dayjs().endOf('year').subtract(1, 'year')];
+		},
+	},
+	{
+		text: '今年上半年',
+		value: () => {
+			return [dayjs().startOf('year'), dayjs().endOf('year').subtract(6, 'month')];
+		},
+	},
+	{
+		text: '今年下半年',
+		value: () => {
+			return [dayjs().startOf('year').add(6, 'month'), dayjs().endOf('year')];
 		},
 	},
 	{
 		text: '今年',
 		value: () => {
-			const end = new Date();
-			const start = new Date();
-			start.setMonth(0);
-			start.setDate(1);
-			// 今天的开始时间
-			start.setHours(0);
-			start.setMinutes(0);
-			start.setSeconds(0);
-			// 今天的结束时间
-			end.setHours(23);
-			end.setMinutes(59);
-			end.setSeconds(59);
-			return [start, end];
+			return [dayjs().startOf('year'), dayjs().endOf('year')];
 		},
 	},
 ];
@@ -184,8 +132,7 @@ export const disabledDate = (time: Date) => {
 // 默认选择日期
 export const defaultDate = [dayjs().startOf('day').format('YYYY-MM-DD'), dayjs().endOf('day').format('YYYY-MM-DD')];
 // 默认选择日期
-export const defaultDateOneMonth = [	dayjs().startOf('day').subtract(1, 'month').format('YYYY-MM-DD'),
-	dayjs().endOf('day').format('YYYY-MM-DD'),];
+export const defaultDateOneMonth = [dayjs().startOf('day').subtract(1, 'month').format('YYYY-MM-DD'), dayjs().endOf('day').format('YYYY-MM-DD')];
 // 默认选择日期时间
 export const defaultDateTime = [dayjs().startOf('day').format('YYYY-MM-DD[T]HH:mm:ss'), dayjs().endOf('day').format('YYYY-MM-DD[T]HH:mm:ss')];
 // 默认选择日期(近三个月)