1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// 数据
get dataList() {
let dataList = [];
console.log(this.$store.state.recordList);
for (let i = 0; i < this.$store.state.recordList.length; i++) {
const data = {
y: 0,
m: 0,
d: 0,
record: []
} as Data;
data.y = dayjs(this.$store.state.recordList[i].createdAt).year();
data.m = dayjs(this.$store.state.recordList[i].createdAt).month() + 1;
data.d = dayjs(this.$store.state.recordList[i].createdAt).date();
// 判断日期是否为同一天
if (i == 0) {
// 存入recordItem
data.record.push(this.$store.state.recordList[0]);
dataList.push(data);
} else if (
// 日期不重复的情况
data.y != dayjs(this.$store.state.recordList[i - 1].createdAt).year() ||
data.m !=
dayjs(this.$store.state.recordList[i - 1].createdAt).month() + 1 ||
data.d != dayjs(this.$store.state.recordList[i - 1].createdAt).date()
) {
// 存入recordItem
data.record.push(this.$store.state.recordList[i]);
dataList.push(data);
} else {
dataList[dataList.length - 1].record.push(
this.$store.state.recordList[i]
);
}
}
return dataList;
}
|