Skip to content

Commit 125ea26

Browse files
committed
LetCalendar: 显示当前日期、选择上周下周
Signed-off-by: LetMeFly666 <814114971@qq.com>
1 parent db35cbd commit 125ea26

File tree

10 files changed

+387
-7
lines changed

10 files changed

+387
-7
lines changed

CHANGELOG

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<!--
2+
* @Author: LetMeFly
3+
* @Date: 2025-01-03 18:25:38
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-01-03 18:25:46
6+
-->
7+
PS F:\OtherApps\Program\Git\Store\Store20_LeetCode> git pull origin master
8+
remote: Enumerating objects: 90, done.
9+
remote: Counting objects: 100% (49/49), done.
10+
remote: Compressing objects: 100% (21/21), done.
11+
Unpacking objects: 78% (71/90), 349.14 KiB | 113.00 KiB/sremote: Total 90 (delta 31), reused 41 (delta 28), pack-reused 41 (from 2)
12+
Unpacking objects: 100% (90/90), 422.81 KiB | 90.00 KiB/s, done.
13+
From ssh.github.com:LetMeFly666/LeetCode
14+
* branch master -> FETCH_HEAD
15+
4176b545178..db35cbdf428 master -> origin/master
16+
Updating 4176b545178..db35cbdf428
17+
Fast-forward
18+
Codes/0729-my-calendar-i.cpp | 41 +
19+
Codes/0729-my-calendar-i.go | 33 +
20+
Codes/0729-my-calendar-i.java | 33 +
21+
Codes/0729-my-calendar-i.py | 22 +
22+
Codes/0731-my-calendar-ii_20250103.cpp | 41 +
23+
Codes/0731-my-calendar-ii_20250103.go | 38 +
24+
Codes/0731-my-calendar-ii_20250103.java | 41 +
25+
Codes/0731-my-calendar-ii_20250103.py | 25 +
26+
Codes/3219-minimum-cost-for-cutting-cake-ii.cpp | 28 +
27+
Codes/3219-minimum-cost-for-cutting-cake-ii.go | 26 +
28+
Codes/3219-minimum-cost-for-cutting-cake-ii.java | 25 +
29+
Codes/3219-minimum-cost-for-cutting-cake-ii.py | 22 +
30+
Codes/3280-convert-date-to-binary.cpp | 22 +
31+
Codes/3280-convert-date-to-binary.go | 21 +
32+
Codes/3280-convert-date-to-binary.java | 15 +
33+
Codes/3280-convert-date-to-binary.py | 9 +
34+
.../3280-convert-date-to-binary_convertByHand.cpp | 29 +
35+
README.md | 4 +
36+
...50\213\345\256\211\346\216\222\350\241\250I.md" | 212 +++
37+
...0\213\345\256\211\346\216\222\350\241\250II.md" | 234 +++
38+
...0\217\346\200\273\345\274\200\351\224\200II.md" | 233 +++
39+
...277\233\345\210\266\350\241\250\347\244\272.md" | 189 +++
40+
Solutions/Other-Accumulation-Messy.md | 1664 +++++++++++++++++++-
41+
Solutions/Other-English-LearningNotes-SomeWords.md | 5 +-
42+
Solutions/Other-Github-How2Make1VerifiedCommit.md | 54 +-
43+
Solutions/Other-Japanese-LearningNotes.md | 24 +-
44+
api/calendar/README.md | 39 +-
45+
api/calendar/front/fileRouter.js | 8 +-
46+
api/calendar/front/files.js | 377 ++---
47+
api/calendar/front/temp/index6.html | 38 +
48+
api/calendar/front/temp/index7-temp.html | 160 ++
49+
api/calendar/front/temp/index8-temp.html | 177 +++
50+
api/calendar/front/temp/scripts2.js | 72 +
51+
api/calendar/front/temp/scripts3.js | 65 +
52+
api/calendar/front/temp/styles9.css | 45 +
53+
newSolution.py | 58 +-
54+
tryGoPy/.gitkeep | 14 +-
55+
...3\251\345\222\214\345\277\203\345\276\227.bash" | 3 +
56+
...15\346\226\260\346\211\223\345\214\205git-csdn" | 1 -
57+
39 files changed, 3849 insertions(+), 298 deletions(-)
58+
create mode 100644 Codes/0729-my-calendar-i.cpp
59+
create mode 100644 Codes/0729-my-calendar-i.go
60+
create mode 100644 Codes/0729-my-calendar-i.java
61+
create mode 100644 Codes/0729-my-calendar-i.py
62+
create mode 100644 Codes/0731-my-calendar-ii_20250103.cpp
63+
create mode 100644 Codes/0731-my-calendar-ii_20250103.go
64+
create mode 100644 Codes/0731-my-calendar-ii_20250103.java
65+
create mode 100644 Codes/3219-minimum-cost-for-cutting-cake-ii.cpp
66+
create mode 100644 Codes/3219-minimum-cost-for-cutting-cake-ii.go
67+
create mode 100644 Codes/3219-minimum-cost-for-cutting-cake-ii.java
68+
create mode 100644 Codes/3219-minimum-cost-for-cutting-cake-ii.py
69+
create mode 100644 Codes/3280-convert-date-to-binary.cpp
70+
create mode 100644 Codes/3280-convert-date-to-binary.go
71+
create mode 100644 Codes/3280-convert-date-to-binary.java
72+
create mode 100644 Codes/3280-convert-date-to-binary.py
73+
create mode 100644 Codes/3280-convert-date-to-binary_convertByHand.cpp
74+
create mode 100644 "Solutions/LeetCode 0729.\346\210\221\347\232\204\346\227\245\347\250\213\345\256\211\346\216\222\350\241\250I.md"
75+
create mode 100644 "Solutions/LeetCode 0731.\346\210\221\347\232\204\346\227\245\347\250\213\345\256\211\346\216\222\350\241\250II.md"
76+
create mode 100644 "Solutions/LeetCode 3219.\345\210\207\350\233\213\347\263\225\347\232\204\346\234\200\345\260\217\346\200\273\345\274\200\351\224\200II.md"
77+
create mode 100644 "Solutions/LeetCode 3280.\345\260\206\346\227\245\346\234\237\350\275\254\346\215\242\344\270\272\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272.md"
78+
create mode 100644 api/calendar/front/temp/index6.html
79+
create mode 100644 api/calendar/front/temp/index7-temp.html
80+
create mode 100644 api/calendar/front/temp/index8-temp.html
81+
create mode 100644 api/calendar/front/temp/scripts2.js
82+
create mode 100644 api/calendar/front/temp/scripts3.js
83+
create mode 100644 api/calendar/front/temp/styles9.css
84+
create mode 100644 "\345\207\272\345\233\275\345\217\202\344\274\232\344\270\273\350\246\201\346\210\220\347\273\251\345\222\214\345\277\203\345\276\227.bash"
85+
delete mode 100644 "\345\260\235\350\257\225\351\207\215\346\226\260\346\211\223\345\214\205git-csdn"

Solutions/Other-English-LearningNotes-SomeWords.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,8 @@ tags: [其他, 知识, 英语, Notes]
916916
|||
917917
|denominate|v. 以...(某种货币)为单位,将...命名为,称...为|
918918
|||
919+
|whaling|n. 捕鲸|
920+
|xerox|v. 打印,复印|
919921

920922
<p class="wordCounts">单词收录总数</p>
921923

Solutions/Other-Japanese-LearningNotes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ xx型
678678
|かれ||
679679
|たち||
680680
|だれ||
681-
|彼女(かのじょ)||
681+
|彼女(かのじょ)|她/女朋友|
682+
|彼氏(かれし)|男朋友|
682683
|女(おんな)|女的|
683684
|女の子(こ)|女孩|
684685
|男(おとこ)|男的|
@@ -701,6 +702,7 @@ xx型
701702
|子ども(こども)|孩子|
702703
|友達(ともだち)|朋友|
703704
|祖父(そふ)|祖父|
705+
|祖母(そぼ)|祖母|
704706
|御爺さん(おじいさん)|爷爷|
705707
|御婆さん(おばあさん)|奶奶|
706708
|おじさん|叔叔|
@@ -778,6 +780,8 @@ xx型
778780
|まず|首先|
779781
|それから|然后|
780782
|死に(しに)|死了|
783+
|亡くなり(なくなり)|去世了|
784+
|なぜ|为什么|
781785
|||
782786
|牛肉(ぎゅうにく)|牛肉|
783787
|豚肉(ぶたにく)|猪肉|

WhatHappened.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
C:\Users\LetMeFly\Desktop\a>git status
2+
fatal: not a git repository (or any of the parent directories): .git
3+
4+
C:\Users\LetMeFly\Desktop\a>git init
5+
Initialized empty Git repository in C:/Users/LetMeFly/Desktop/a/.git/
6+
7+
C:\Users\LetMeFly\Desktop\a>git checkout -b api
8+
Switched to a new branch 'api'
9+
10+
C:\Users\LetMeFly\Desktop\a>git checkout master
11+
error: pathspec 'master' did not match any file(s) known to git
12+
13+
C:\Users\LetMeFly\Desktop\a>git branch
14+
15+
C:\Users\LetMeFly\Desktop\a>git branch
16+
17+
C:\Users\LetMeFly\Desktop\a>git branch
18+
19+
C:\Users\LetMeFly\Desktop\a>git branch -a
20+
21+
C:\Users\LetMeFly\Desktop\a>git branch -v
22+
23+
C:\Users\LetMeFly\Desktop\a>

api/calendar/README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: LetMeFly
33
* @Date: 2024-12-15 16:10:07
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2025-01-02 23:07:18
5+
* @LastEditTime: 2025-01-03 22:06:01
66
-->
77
# 目的
88

@@ -836,6 +836,35 @@ html表格,设置所有列等宽。
836836

837837
用户选择的时候会依据鼠标位置,高亮选中的小格子的部分。
838838

839+
<hr/>
840+
841+
我在写一个模仿Mac日历的HTML,当前html源码为
842+
```
843+
844+
```
845+
当前css源码为
846+
```
847+
848+
```
849+
当前js源码为
850+
```
851+
852+
```
853+
如果你了解了,请回复好的,并等待我的下一步指令
854+
855+
<hr/>
856+
857+
我想在表头上添加日期,默认显示当前这一周(使用js实时获取)。
858+
859+
加上左右两个箭头,点击可以切换到上一周或下一周。
860+
861+
<hr/>
862+
863+
<hr/>
864+
<hr/>
865+
<hr/>
866+
<hr/>
867+
<hr/>
839868
<hr/>
840869
<hr/>
841870
<hr/>

api/calendar/front/files.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: LetMeFly
33
* @Date: 2024-12-25 23:31:55
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2025-01-02 23:02:32
5+
* @LastEditTime: 2025-01-03 21:58:21
66
*/
77
/* 以下为前端各个页面的源码 */
88
// index.html
@@ -42,7 +42,7 @@ export const indexHTML = `
4242
`;
4343

4444
export const stylesCSS = `
45-
/* styles.css */
45+
/* style.css */
4646
body {
4747
font-family: Arial, sans-serif;
4848
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-01-03 21:58:45
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-01-03 22:36:03
6+
*/
7+
// script.js
8+
document.addEventListener('DOMContentLoaded', function () {
9+
/* 初始化日期 */
10+
const tableBody = document.querySelector('#calendarTable tbody');
11+
const dateRow = document.querySelector('#dateRow');
12+
const weekRange = document.querySelector('#weekRange');
13+
const prevWeekButton = document.querySelector('#prevWeek');
14+
const nextWeekButton = document.querySelector('#nextWeek');
15+
16+
let currentDate = new Date(); // 当前日期
17+
18+
// 生成时间行
19+
const hours = 24; // 24小时制
20+
for (let i = 0; i < hours; i++) {
21+
const row = document.createElement('tr');
22+
row.innerHTML = '<td>' + i + ':00</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>';
23+
tableBody.appendChild(row);
24+
}
25+
26+
// 更新日期行和周范围显示
27+
function updateDates() {
28+
const startOfWeek = getStartOfWeek(currentDate);
29+
const oneDay_ths = dateRow.querySelectorAll('th');
30+
31+
for (let i = 0; i < 7; i++) {
32+
const date = new Date(startOfWeek);
33+
date.setDate(startOfWeek.getDate() + i);
34+
oneDay_ths[i + 1].querySelector('span').innerHTML = date.toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' });
35+
}
36+
37+
// 更新周范围显示
38+
const endOfWeek = new Date(startOfWeek);
39+
endOfWeek.setDate(startOfWeek.getDate() + 6);
40+
weekRange.textContent = startOfWeek.toLocaleDateString('zh-CN') + '-' + endOfWeek.toLocaleDateString('zh-CN');
41+
42+
// 如果显示周是当前周,则高亮今天
43+
if (currentDate.toDateString() == getStartOfWeek(new Date()).toDateString()) {
44+
console.log('this week');
45+
const day = (new Date()).getDay();
46+
const index = day ? day : 7; // 周日的下标是7
47+
oneDay_ths[index].classList.add('today');
48+
} else {
49+
oneDay_ths.forEach(th => th.classList.remove('today'));
50+
}
51+
}
52+
53+
/**
54+
* 获取当前周的周一
55+
* @param {Date} date
56+
* @returns {Date}
57+
*/
58+
function getStartOfWeek(date) {
59+
const day = date.getDay();
60+
const diff = date.getDate() - day + (day === 0 ? -6 : 1); // 如果当前是周日,则减去6天
61+
return new Date(date.setDate(diff));
62+
}
63+
64+
// 切换到上一周
65+
prevWeekButton.addEventListener('click', () => {
66+
currentDate.setDate(currentDate.getDate() - 7);
67+
updateDates();
68+
});
69+
70+
// 切换到下一周
71+
nextWeekButton.addEventListener('click', () => {
72+
currentDate.setDate(currentDate.getDate() + 7);
73+
updateDates();
74+
});
75+
76+
// 初始化日期
77+
updateDates();
78+
79+
/* 定义拖拽高亮 */
80+
// 高亮单元格逻辑(保持不变)
81+
let isDragging = false;
82+
let startCell = null;
83+
let endCell = null;
84+
85+
tableBody.addEventListener('mousedown', function (e) {
86+
if (e.target.tagName === 'TD' && e.target.cellIndex !== 0) {
87+
isDragging = true;
88+
startCell = e.target;
89+
highlightCells(startCell, startCell);
90+
}
91+
});
92+
93+
tableBody.addEventListener('mouseover', function (e) {
94+
if (isDragging && e.target.tagName === 'TD' && e.target.cellIndex !== 0) {
95+
endCell = e.target;
96+
highlightCells(startCell, endCell);
97+
}
98+
});
99+
100+
tableBody.addEventListener('mouseup', function () {
101+
isDragging = false;
102+
startCell = null;
103+
endCell = null;
104+
});
105+
106+
function highlightCells(start, end) {
107+
const startRow = start.parentElement.rowIndex;
108+
const startCol = start.cellIndex;
109+
const endRow = end.parentElement.rowIndex;
110+
111+
const minRow = Math.min(startRow, endRow);
112+
const maxRow = Math.max(startRow, endRow);
113+
const Col = startCol;
114+
115+
// 清除之前的高亮
116+
const allCells = tableBody.querySelectorAll('td');
117+
allCells.forEach(cell => cell.classList.remove('time-slot'));
118+
119+
// 高亮选中的区域
120+
for (let i = minRow - 1; i <= maxRow - 1; i++) { // 表头还有一行
121+
const cell = tableBody.rows[i].cells[Col];
122+
cell.classList.add('time-slot');
123+
}
124+
}
125+
});

0 commit comments

Comments
 (0)