日历完成

This commit is contained in:
luyuan 2020-10-12 16:44:22 +08:00
parent 4683d8882d
commit bbe9e3bcc2
Signed by: theluyuan
GPG Key ID: A7972FD973317FF3
3 changed files with 29 additions and 11 deletions

View File

@ -37,7 +37,7 @@ export async function userinfo(){
const user = await get<UserInfo>('personalInfo');
// console.log(user.data?.img)
if(user.code == 1001){
router.push("/")
// router.push("/")
return '未登录';
}
return {

View File

@ -1,14 +1,18 @@
import dayjs from 'dayjs'
export function getdate(){
export function getdate(yue?: number){
let now = dayjs()
if(yue != undefined){
now = now.month(now.month() + yue);
}
yue = now.month() + 1;
const day = now.date() // 当前天
now = now.date(1)
const week = now.day(); // 第一天是星期几
now = now.month(now.month() + 1);
now = now.date(0);
const month = now.date(); // 当前月有几天
const year = now.year()
console.log(day,week,month)
let i = 0;
@ -26,7 +30,6 @@ export function getdate(){
date[0][w] = {};
}
i++;
w = w == 0 ? 1 : w;
const zhou = Math.floor((i + w - 1) / 7)
const d = {
day: i
@ -36,7 +39,11 @@ export function getdate(){
}
date[zhou].push(d)
}
while(date[date.length - 1].length < 7){
date[date.length - 1].push({})
}
console.log(date)
return date;
return {date, year, yue};
}

View File

@ -1,15 +1,15 @@
<template>
<div class="date">
<div class="head">
<div>
<div @click="shang">
<img src="" alt="">
上一月
</div>
2020年9
{{month.year}}{{month.yue}}
<a-button type="primary" class="button">
周日历
</a-button>
<div>
<div @click="xia">
下一月
<img src="" alt="">
</div>
@ -25,7 +25,7 @@
<div>周六</div>
</div>
<div class="body">
<div class="row" v-for="(item,index) in month" :key="index">
<div class="row" v-for="(item,index) in month.date" :key="index">
<div v-for="(i,j) in item" :key="j">
<div class="day">
<div>
@ -193,8 +193,19 @@ export default defineComponent({
console.log(1)
const date = getdate();
const month = ref(date);
let yue = 0;
function xia(){
yue = yue + 1;
month.value = getdate(yue)
}
function shang(){
yue = yue - 1;
month.value = getdate(yue)
}
return {
month
month,
xia,
shang
}
}
})