|
@@ -1,4 +1,6 @@
|
|
|
import { GetMyTaskDailyDistribution } from '@/api/user';
|
|
|
+
|
|
|
+import { useRoute } from 'vue-router/composables';
|
|
|
import { ref, watchEffect, nextTick } from 'vue';
|
|
|
|
|
|
import dayjs from 'dayjs';
|
|
@@ -85,6 +87,7 @@ export const monthList = [
|
|
|
}
|
|
|
];
|
|
|
|
|
|
+// 日历显示模式
|
|
|
export const modeList = [
|
|
|
{
|
|
|
type: 'DAY',
|
|
@@ -101,32 +104,38 @@ export const modeList = [
|
|
|
* @param {Date} dateStamp
|
|
|
* @param {Emits} emits
|
|
|
*/
|
|
|
-export function useMonthlyCalendar(dateStamp, emits) {
|
|
|
+export function useMonthlyCalendar(emits) {
|
|
|
+ const route = useRoute();
|
|
|
+ const dateSta = route.query.dateStamp;
|
|
|
+ let dateStamp = dateSta ? new Date(dateSta) : new Date();
|
|
|
+
|
|
|
let focusDate = ref(dateStamp.getDate());
|
|
|
let focusMonth = ref(0);
|
|
|
let curYear = ref(dateStamp.getFullYear());
|
|
|
let curMonth = ref(dateStamp.getMonth() + 1);
|
|
|
- let calendarStyle = ref('');
|
|
|
|
|
|
const DAY = modeList[0].type;
|
|
|
const MONTH = modeList[1].type;
|
|
|
+ let time_unit = ref(modeList[0].type); // 当前日历模式
|
|
|
|
|
|
- let time_unit = ref(modeList[0].type);
|
|
|
- let dateArr = ref([]);
|
|
|
+ let calendar = ref([]); // 日历数组
|
|
|
+
|
|
|
+ // 根据日历模式切换样式
|
|
|
+ let calendarStyle = ref(''); // 日历样式
|
|
|
watchEffect(() => {
|
|
|
if (time_unit.value === DAY) {
|
|
|
- return (calendarStyle.value = `40px repeat(${dateArr.value.length > 35 ? 6 : 5}, 1fr) / repeat(7, 1fr)`);
|
|
|
+ return (calendarStyle.value = `40px repeat(${calendar.value.length > 35 ? 6 : 5}, 1fr) / repeat(7, 1fr)`);
|
|
|
}
|
|
|
if (time_unit.value === MONTH) return (calendarStyle.value = `repeat(4, 1fr) / repeat(3, 1fr)`);
|
|
|
});
|
|
|
|
|
|
+ // 得到当前日历任务每日分布
|
|
|
let date = ref(`${dateStamp.getFullYear()}-${dateStamp.getMonth() + 1}`);
|
|
|
let taskDailyDistribution = ref({}); // 任务每日分布
|
|
|
watchEffect(() => {
|
|
|
- const arr = date.value.split('-').map((item) => Number(item));
|
|
|
- curYear.value = arr[0];
|
|
|
- curMonth.value = arr[1];
|
|
|
- focusMonth.value = arr[1] - 1;
|
|
|
+ curYear.value = dayjs(date.value).year();
|
|
|
+ curMonth.value = dayjs(date.value).month() + 1;
|
|
|
+ focusMonth.value = dayjs(date.value).month();
|
|
|
GetMyTaskDailyDistribution({ month_stamp: date.value }).then(({ status, ...data }) => {
|
|
|
if (status !== 1) return;
|
|
|
const taskDailyArr = {};
|
|
@@ -170,7 +179,7 @@ export function useMonthlyCalendar(dateStamp, emits) {
|
|
|
isToday: j === curDate && isThisMonth
|
|
|
};
|
|
|
}
|
|
|
- if (arr.length === 35) return (dateArr.value = arr);
|
|
|
+ if (arr.length === 35) return (calendar.value = arr);
|
|
|
// 下月
|
|
|
let next = (arr.length < 35 ? 35 : 42) - dayOfWeek - daysInMonth;
|
|
|
for (let k = 1; k <= next; k++) {
|
|
@@ -182,7 +191,7 @@ export function useMonthlyCalendar(dateStamp, emits) {
|
|
|
isToday: false
|
|
|
});
|
|
|
}
|
|
|
- dateArr.value = arr;
|
|
|
+ calendar.value = arr;
|
|
|
}
|
|
|
getDateArr();
|
|
|
|
|
@@ -196,7 +205,7 @@ export function useMonthlyCalendar(dateStamp, emits) {
|
|
|
getDateArr();
|
|
|
}
|
|
|
|
|
|
- // 修改月份
|
|
|
+ // 月份向前或向后
|
|
|
function changeMonth(type) {
|
|
|
const curMonth = dayjs(date.value).month();
|
|
|
const curYear = dayjs(date.value).year();
|
|
@@ -227,6 +236,7 @@ export function useMonthlyCalendar(dateStamp, emits) {
|
|
|
emits('changeTimeUnit');
|
|
|
}
|
|
|
|
|
|
+ // 日模式 -> 选择日期
|
|
|
function selectDate(number, isCurMonth) {
|
|
|
if (time_unit.value === DAY) {
|
|
|
focusDate.value = number;
|
|
@@ -237,12 +247,14 @@ export function useMonthlyCalendar(dateStamp, emits) {
|
|
|
emits('changeDate');
|
|
|
}
|
|
|
|
|
|
+ // 月模式 -> 选择月份
|
|
|
function selectMonth(number) {
|
|
|
date.value = `${curYear.value}-${number + 1}`;
|
|
|
focusMonth.value = number;
|
|
|
nextTick(() => {
|
|
|
emits('changeDate');
|
|
|
});
|
|
|
+ getDateArr();
|
|
|
}
|
|
|
|
|
|
return {
|
|
@@ -253,7 +265,7 @@ export function useMonthlyCalendar(dateStamp, emits) {
|
|
|
curMonth,
|
|
|
focusDate,
|
|
|
calendarStyle,
|
|
|
- dateArr,
|
|
|
+ calendar,
|
|
|
taskDailyDistribution,
|
|
|
focusMonth,
|
|
|
backToday,
|