Commit 552e95c2 by 胡悦

修改日历每月天数

1 parent 28f5fb55

2.34 MB | W: | H:

2.34 MB | W: | H:

assets/images/sprite.png
assets/images/sprite.png
assets/images/sprite.png
assets/images/sprite.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -14,21 +14,23 @@
</view>
</view>
<view class="calendar-dates">
<view class="calendar-date" v-for="(date, index) in clockInDateList" :key="index">
<view :class="['calendar-date', `lines${getMaxLen}`]" v-for="(date, index) in clockInDateList" :key="index">
<template v-if="date.day">
<view @click="openDetail(date)">
<view v-if="date.dayState != 1"
:class="['tag', TYPE_LIST.find(item => item.value == date.dayState).class]">
<view v-if="date.dayState != 1" :class="getTagClass(date)">
{{ DAY_STATE[date.dayState] }}</view>
<view class="date-num" v-if="date.day != currentInfo.day">{{ date.day || '' }}</view>
<view class="current-date" v-else>今</view>
<template v-if="!date.isDefault">
<view :class="['date-desc first-child', date.clockInState != 0 || date.clockInAbnormalAttire ? 'date-red' : '']">{{
date.clockInState == 3 ? '缺卡' : date.clockInTime1 }}<view v-if="date.clockInAbnormalAttire"
<view
:class="['date-desc first-child', date.clockInState != 0 || date.clockInAbnormalAttire ? 'date-red' : '']">
{{
date.clockInState == 3 ? '缺卡' : date.clockInTime1 }}<view v-if="date.clockInAbnormalAttire"
class="sprite-icon icon-dress-code"></view>
</view>
<view :class="['date-desc', date.clockOutState != 0 || date.clockOutAbnormalAttire ? 'date-red' : '']">{{
date.clockOutState == 3 ? '缺卡' : date.clockOutTime1 }}<view v-if="date.clockOutAbnormalAttire"
<view
:class="['date-desc', date.clockOutState != 0 || date.clockOutAbnormalAttire ? 'date-red' : '']">{{
date.clockOutState == 3 ? '缺卡' : date.clockOutTime1 }}<view v-if="date.clockOutAbnormalAttire"
class="sprite-icon icon-dress-code"></view>
</view>
</template>
......@@ -87,25 +89,40 @@ export default {
},
computed: {
dates() {
//
const firstDayOfMonth = new Date(this.currentInfo.year, this.currentInfo.month - 1, 1)
const dates = []
for (let i = 0, len = this.datesd.length; i < len; i++) {
dates.push(this.datesd[i])
// 获取当前日期
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth();
// 获取当月第一天是星期几,注意 getDay() 返回值 0 代表周日,1 - 6 代表周一到周六
const firstDayOfMonth = new Date(year, month, 1);
const firstDayWeekday = firstDayOfMonth.getDay();
// 获取当月的总天数
const lastDayOfMonth = new Date(year, month + 1, 0);
const totalDays = lastDayOfMonth.getDate();
// 创建一个初始数组,根据当月第一天是星期几插入相应数量的 null
const daysArray = [];
for (let i = 0; i < (firstDayWeekday === 0 ? 6 : firstDayWeekday - 1); i++) {
daysArray.push(null);
}
if (firstDayOfMonth.getDay() == 0) {
// 第一行只有一天的情况
for (let i = 1; i <= 6; i++) {
dates.unshift(null)
}
} else {
for (let i = 1; i < firstDayOfMonth.getDay(); i++) {
dates.unshift(null)
}
// 填充当月的日期
for (let day = 1; day <= totalDays; day++) {
daysArray.push(day);
}
console.log(dates)
return dates
return daysArray;
},
getMaxLen() {
const max_len = Math.ceil(this.dates.length / 7)
return max_len
},
getTagClass() {
return (date) => {
if (!date || date.dayState === null) {
return ['tag'];
}
const item = TYPE_LIST.find(item => item.value == date.dayState);
return item ? ['tag', item.class] : ['tag'];
}
}
},
mounted(options) {
console.log('Calendar.adsfads')
......@@ -155,7 +172,7 @@ export default {
async getNewCalendar() {
const params = this.getParams()
const res = await uni.$api.pointApi.newCalendar(params)
if(res) {
if (res) {
console.log(this.dates, 'dates')
this.dates.forEach(item => {
const clockData = res.clockInDateList.find(i => i.day == item)
......@@ -248,7 +265,6 @@ export default {
.calendar-date {
position: relative;
width: calc(100% / 7);
min-height: calc((100vh - #{toRpx(550)}) / 5);
background-color: #fff;
padding: toRpx(22) toRpx(32);
display: flex;
......@@ -360,6 +376,18 @@ export default {
margin-bottom: toRpx(6);
}
}
&.lines5 {
min-height: calc((100vh - #{toRpx(550)}) / 5);
}
&.lines6 {
min-height: calc((100vh - #{toRpx(550)}) / 6);
.date-num {
margin-bottom: toRpx(0);
}
}
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!