Commit 5644cfff by xiexiaoqin

scheduleList

parent a15b1efd
{
"component": true,
"disableScroll": true,
"allowsBounceVertical": "NO",
"usingComponents": {
"task-list": "../../components/taskList/taskList",
"file-list": "../../components/fileList/fileList",
......
{
"dependencies": {
"dd-store": "^1.8.4",
"less": "^3.11.1",
"rrule": "^2.6.4"
}
}
import { RRule, RRuleSet, rrulestr } from "rrule";
import { padZero } from "../../utils/utils";
export function getDateMap(minYear, maxYear) {
const DateMap = new Map();
const getOneYear = (year) => {
const yearDays = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 366 : 365;
for (let i = 1; i <= yearDays; i++) {
DateMap.set(new Date(year, 0, i).toLocaleDateString(), []);
}
}
for (let i = minYear; i <= maxYear; i++) {
getOneYear(i);
}
return DateMap
}
// 返回删除的日期
/**
* 如果删除单次重复会议返回['2020-04-20'],
* 如果删除此次及以后重复会议返回['future2020-04-20']
*/
export function getExcludeDate(data = []) {
const excludeDateList = [];
const futureList = [];
data.forEach(item => {
//删除此次及以后
if (item.length > 10) {
futureList.push(new Date(item.slice(6, 16).replace(/-/g, "/")).getTime());
}
//删除单次
else {
excludeDateList.push(item);
}
});
return {
excludeDateList,
minFutureTime: Math.min(...futureList)
};
}
// 返回跨天数
export function getNextDateList(startTime, endTime) {
let days = 0;
const nextDateList = [];
if (startTime.getDate() !== endTime.getDate()) {
//同一个月
if (startTime.getMonth() !== endTime.getMonth()) {
days = endTime.getDate() - startTime.getDate();
}
//跨月
else {
// 一个月份有多少天new Date(year, month, 0).getDate()
const startMonth = new Date(startTime.getFullYear(), startTime.getMonth(), 0).getDate();
days = startMonth - startTime.getDate() + endTime.getDate()
}
} else {
//跨一个月 不考虑
}
//返回跨天的日期数组
for (let i = 1; i <= days; i++) {
const newDate = new Date(startTime);
const nextDate = new Date(newDate.setDate(newDate.getDate() + i)).toLocaleDateString();
nextDateList.push(nextDate)
}
return nextDateList
}
export function getWeekNumber(year, month, days) {
const isLeapYear = (year) => (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)
const getMonthDays = (year, month) => [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] || (isLeapYear(year) ? 29 : 28);
//那一天是那一年中的第多少天
for (var i = 0; i < month; i++) {
days += getMonthDays(year, i);
}
//那一年第一天是星期几
var yearFirstDay = new Date(year, 0, 1).getDay();
var week = null;
if (yearFirstDay == 0) {
week = Math.ceil(days / 7);
} else {
days -= (6 - yearFirstDay + 1);
week = Math.ceil(days / 7);
}
return week;
}
export function getBlankList(year) {
const dateMap = getDateMap(year, year);
const DateList = [];
dateMap.forEach(function (value, key) {
const keyDate = new Date(key);
const year = keyDate.getFullYear();
const month = keyDate.getMonth();
const date = keyDate.getDate();
const day = keyDate.getDay();
// 生成年
if (month === 0 && date === 1) {
DateList.push({
type: "year",
value: year,
dateStr: `${year}`
});
}
//生成月
if (date === 1) {
DateList.push({
type: "month",
value: month + 1,
dateStr: `${year}/${month + 1}`
});
}
//生成周
if (day === 0) {
const rangeDate = new Date(year, month, date + 6);
const rangeMonth2 = new Date(rangeDate).getMonth();
const rangeDay2 = new Date(rangeDate).getDate();
DateList.push({
type: "week",
value: `第${getWeekNumber(year, month, date)}周,${month + 1}${date}日 - ${
rangeMonth2 == month ? "" : rangeMonth2 + 1 + "月"
}${rangeDay2}日`,
dateStr: `${year}/${month + 1}/${date}-week`
});
}
})
return DateList;
}
\ No newline at end of file
......@@ -9,7 +9,7 @@
</view>
</view>
</view>
<scroll-view class="indexScrollView" scroll-y="{{true}}" style="background: #FFFFFF" lower-threshold="100" onScrollToLower="lower" onScrollToUpper="upper" scroll-into-view="{{todayStr}}">
<scroll-view class="indexScrollView" scroll-y="{{true}}" style="background: #FFFFFF" lower-threshold="100" onScrollToLower="lower" scroll-into-view="{{todayStr}}">
<block a:for="{{scheduleList}}" key="{{item.dateStr}}">
<!-- 年 -->
<block a:if="{{item.type == 'year'}}">
......
{
"allowsBounceVertical": "YES",
"pullRefresh": true,
"usingComponents": {
"popup": "../../components/popup/index"
}
}
}
\ No newline at end of file
......@@ -51,6 +51,8 @@ export function getFormatDate(time, format, symbol) {
: `${year}/${month}/${day}`;
} else if (format === "HH:mm:ss") {
return `${hour}:${minutes}:${seconds}`;
} else if (format === "HH:mm") {
return `${hour}:${minutes}`;
}
}
// 返回每个月的第一天
......@@ -142,3 +144,7 @@ export function getCreateShowTime(createdTime) {
return timeResule
}
export function padZero(val) {
return ("00" + val).slice(-2);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment