-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1354 lines (1183 loc) · 42.5 KB
/
index.html
File metadata and controls
1354 lines (1183 loc) · 42.5 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>Wow 伙伴!</title>
<style>
@font-face {
font-family: 'CustomFont';
src: url('font.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
* {
font-family: 'CustomFont', sans-serif !important;
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
.header-container {
position: fixed;
top: 15px;
left: 15px;
right: 15px;
display: flex;
justify-content: space-between;
align-items: flex-start;
padding: 0;
}
/* 响应式设计 */
@media (max-width: 768px) {
.header-container {
flex-direction: column;
align-items: flex-start;
}
.saying-container {
width: 100%;
margin-top: 20px;
}
}
@media (max-width: 480px) {
h1 {
font-size: 24px;
}
#dateDisplay {
font-size: 12px;
}
.saying-text {
font-size: 14px;
}
}
.saying-container {
width: 400px;
text-align: right;
padding: 20px;
}
.footer-info {
position: fixed;
bottom: 20px;
left: 20px;
font-size: 12px;
color: #666;
text-align: left;
}
.saying-text {
font-size: 18px;
color: #333;
margin-bottom: 10px;
line-height: 1.6;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
opacity: 1;
transition: opacity 0.5s ease;
}
.saying-text.fade-out {
opacity: 0;
}
.saying-from {
font-size: 14px;
color: #666;
font-style: italic;
white-space: nowrap;
opacity: 1;
transition: opacity 0.5s ease;
}
.saying-from.fade-out {
opacity: 0;
}
.time-date-container {
margin-left: 20px;
padding-top: 15px;
}
h1 {
color: rgb(6, 6, 6);
margin: 0;
font-size: 37px;
}
#dateDisplay {
color: rgb(6, 6, 6);
margin: 2px 0 0 0;
font-size: 15px;
text-align: left;
}
/* 浮动工具栏 */
.floating-toolbar {
position: fixed;
bottom: 25px;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 6px;
padding: 10px 16px;
background: rgba(255, 255, 255, 0.85);
border-radius: 50px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
backdrop-filter: blur(10px);
z-index: 1000;
}
.toolbar-btn {
width: 36px;
height: 36px;
border: none;
background: transparent;
border-radius: 50%;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
padding: 6px;
position: relative;
}
.toolbar-btn:hover {
background: rgba(0, 0, 0, 0.05);
transform: scale(1.1);
}
.toolbar-btn.primary {
background: #667eea;
}
.toolbar-btn.primary:hover {
background: #5568d3;
transform: scale(1.1);
}
.toolbar-btn.primary img {
opacity: 1;
filter: brightness(0) invert(1);
}
.toolbar-btn img {
width: 22px;
height: 22px;
opacity: 0.7;
transition: opacity 0.2s ease;
}
.toolbar-btn:hover img {
opacity: 1;
}
/* 工具提示 */
.toolbar-btn::before {
content: attr(data-tooltip);
position: absolute;
bottom: 50px;
left: 50%;
transform: translateX(-50%) scale(0.8);
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 6px 12px;
border-radius: 8px;
font-size: 12px;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: all 0.2s ease;
z-index: 1001;
}
.toolbar-btn:hover::before {
opacity: 1;
transform: translateX(-50%) scale(1);
}
.toolbar-divider {
width: 1px;
height: 24px;
background: rgba(0, 0, 0, 0.1);
margin: 0 4px;
}
.zoom-display {
font-size: 14px;
color: #666;
min-width: 50px;
text-align: center;
user-select: none;
}
/* 子菜单 */
.submenu-container {
position: relative;
}
.submenu {
position: absolute;
bottom: 55px;
left: 50%;
transform: translateX(-50%) scale(0.9);
background: rgba(255, 255, 255, 0.98);
border-radius: 16px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
padding: 8px;
display: none;
flex-direction: column;
gap: 4px;
min-width: 160px;
opacity: 0;
transition: all 0.2s ease;
}
.submenu.show {
display: flex;
opacity: 1;
transform: translateX(-50%) scale(1);
}
.submenu-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 16px;
border: none;
background: transparent;
border-radius: 12px;
cursor: pointer;
font-size: 14px;
color: #333;
text-align: left;
transition: all 0.2s ease;
white-space: nowrap;
}
.submenu-item:hover {
background: rgba(0, 0, 0, 0.05);
}
.submenu-item img {
width: 18px;
height: 18px;
opacity: 0.7;
}
/* 右下角提醒卡片 */
.toast-container {
position: fixed;
bottom: 80px;
right: 20px;
z-index: 3000;
display: flex;
flex-direction: column;
gap: 10px;
}
.toast-card {
background: white;
border-radius: 12px;
padding: 16px 20px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
display: flex;
align-items: center;
gap: 12px;
min-width: 280px;
max-width: 400px;
animation: toastSlideIn 0.3s ease;
border-left: 4px solid #667eea;
}
@keyframes toastSlideIn {
from {
opacity: 0;
transform: translateX(100px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes toastSlideOut {
from {
opacity: 1;
transform: translateX(0);
}
to {
opacity: 0;
transform: translateX(100px);
}
}
.toast-card.hide {
animation: toastSlideOut 0.3s ease forwards;
}
.toast-icon {
width: 24px;
height: 24px;
flex-shrink: 0;
}
.toast-content {
flex: 1;
}
.toast-title {
font-size: 14px;
font-weight: 600;
color: #333;
margin-bottom: 4px;
}
.toast-message {
font-size: 13px;
color: #666;
}
/* 作业编辑弹窗 iframe */
.modal-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 2000;
justify-content: center;
align-items: center;
}
.modal-overlay.show {
display: flex;
}
.modal-iframe {
width: 90%;
max-width: 500px;
height: 80vh;
border: none;
border-radius: 0;
box-shadow: none;
background: transparent;
}
/* 作业卡片区域 */
.homework-container {
position: fixed;
top: 120px;
left: 15px;
right: 20px;
bottom: 100px;
overflow-y: auto;
padding: 20px;
z-index: 100;
}
.homework-grid {
display: flex;
flex-direction: column;
flex-wrap: wrap;
gap: 20px;
max-width: 1200px;
margin: 0;
width: 100%;
max-height: calc(100vh - 220px);
align-content: flex-start;
}
.homework-card {
width: 300px;
background: white;
border-radius: 12px;
padding: 16px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
transition: all 0.2s ease;
border: 1px solid #f0f0f0;
break-inside: avoid;
}
.homework-grid:empty::before {
content: "📝\A暂无作业,点击下方的\"新建作业\"按钮添加";
white-space: pre;
text-align: center;
font-size: 16px;
color: #999;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.homework-card:hover {
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
transform: translateY(-2px);
}
.card-subject {
font-size: 14px;
font-weight: bold;
color: #667eea;
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid #f0f0f0;
}
.homework-item {
position: relative;
padding: 12px 0;
border-bottom: 1px solid #f5f5f5;
display: flex;
flex-direction: column;
justify-content: center;
min-height: 60px;
}
.homework-item:last-child {
border-bottom: none;
}
.item-header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
margin-bottom: 4px;
}
.item-content {
font-size: 14px;
color: #333;
line-height: 1.6;
flex: 1;
}
.item-tags {
display: flex;
flex-wrap: wrap;
gap: 4px;
flex-shrink: 0;
}
.item-tag {
font-size: 11px;
padding: 2px 8px;
background: #f5f5f5;
border-radius: 10px;
color: #666;
}
.item-actions {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
display: flex;
gap: 4px;
opacity: 0;
transition: opacity 0.2s ease;
background: white;
padding-left: 10px;
}
.homework-item:hover .item-actions {
opacity: 1;
}
.item-btn {
width: 24px;
height: 24px;
border: none;
background: transparent;
border-radius: 4px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
}
.item-btn:hover {
background: rgba(0, 0, 0, 0.05);
}
.item-btn img {
width: 14px;
height: 14px;
opacity: 0.6;
}
.item-btn:hover img {
opacity: 1;
}
.item-date {
font-size: 11px;
color: #999;
margin-top: 4px;
}
.empty-state {
text-align: center;
padding: 60px 20px;
color: #999;
}
.empty-state img {
width: 80px;
height: 80px;
opacity: 0.3;
margin-bottom: 16px;
}
</style>
</head>
<body>
<div class="header-container">
<div class="time-date-container">
<h1 id="timeDisplay">Wow 伙伴!</h1>
<div id="dateDisplay"></div>
</div>
<div class="saying-container">
<div class="saying-text" id="sayingText"></div>
<div class="saying-from" id="sayingFrom"></div>
</div>
</div>
<div class="footer-info">
<div>开发中画面,不代表最终效果</div>
<div>AssignSticker 1.3.0-Dangerous Star (debug)</div>
</div>
<!-- 作业卡片展示区域 -->
<div class="homework-container" id="homeworkContainer">
<div class="homework-grid" id="homeworkGrid">
<!-- 作业卡片将在这里动态生成 -->
</div>
</div>
<!-- 作业编辑弹窗 -->
<div class="modal-overlay" id="homeworkModal">
<iframe class="modal-iframe" id="homeworkIframe" src="htmls/more/homework_modal.html"></iframe>
</div>
<!-- 浮动工具栏 -->
<div class="floating-toolbar">
<!-- 新建作业 -->
<button class="toolbar-btn primary" data-tooltip="新建作业" onclick="openHomeworkModal()">
<img src="icons/icons/add.svg" alt="新建">
</button>
<!-- 保存 -->
<div class="submenu-container">
<button class="toolbar-btn" data-tooltip="保存" onclick="toggleSubmenu('save-submenu')">
<img src="icons/icons/save.svg" alt="保存">
</button>
<div class="submenu" id="save-submenu">
<button class="submenu-item">
<img src="icons/icons/image.svg" alt="图片">
<span>保存为图片</span>
</button>
<button class="submenu-item" onclick="saveHomeworkToFile()">
<img src="icons/icons/save.svg" alt="保存">
<span>手动保存作业</span>
</button>
</div>
</div>
<!-- 全屏 -->
<button class="toolbar-btn" data-tooltip="全屏">
<img src="icons/icons/fullscreen.svg" alt="全屏">
</button>
<!-- 隐藏 -->
<button class="toolbar-btn" data-tooltip="隐藏" onclick="hideMainWindow()">
<img src="icons/icons/hide.svg" alt="隐藏">
</button>
<div class="toolbar-divider"></div>
<!-- 缩小 -->
<button class="toolbar-btn" data-tooltip="缩小">
<img src="icons/icons/minimize.svg" alt="缩小">
</button>
<!-- 显示比例 -->
<span class="zoom-display">100%</span>
<!-- 放大 -->
<button class="toolbar-btn" data-tooltip="放大">
<img src="icons/icons/maximize.svg" alt="放大">
</button>
<div class="toolbar-divider"></div>
<!-- 锁定 -->
<button class="toolbar-btn" data-tooltip="锁定">
<img src="icons/icons/lock.svg" alt="锁定">
</button>
<!-- 设置 -->
<button class="toolbar-btn" data-tooltip="设置" onclick="openSettings()">
<img src="icons/icons/settings.svg" alt="设置">
</button>
<!-- 退出 -->
<button class="toolbar-btn" data-tooltip="退出" onclick="exitApp()">
<img src="icons/icons/exit.svg" alt="退出">
</button>
<!-- 重启 -->
<button class="toolbar-btn" data-tooltip="重启" onclick="restartApp()">
<img src="icons/icons/restart.svg" alt="重启">
</button>
</div>
<!-- 右下角提醒卡片 -->
<div class="toast-container" id="toastContainer"></div>
<script>
function updateTime() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
const timeString = `${hours}:${minutes}:${seconds}`;
document.getElementById('timeDisplay').textContent = timeString;
}
function updateDate() {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
const weekDay = weekDays[now.getDay()];
const dateString = `${year}年${month}月${day}日 ${weekDay}`;
document.getElementById('dateDisplay').textContent = dateString;
}
// 初始化显示时间和日期
updateTime();
updateDate();
// 加载一言(带淡入淡出效果)
function loadSaying() {
const sayingText = document.getElementById('sayingText');
const sayingFrom = document.getElementById('sayingFrom');
// 淡出
sayingText.classList.add('fade-out');
sayingFrom.classList.add('fade-out');
// 等待淡出完成后加载新内容
setTimeout(() => {
fetch('saying/saying_sc.json')
.then(response => response.json())
.then(data => {
const sayings = data.sayings;
const randomIndex = Math.floor(Math.random() * sayings.length);
const randomSaying = sayings[randomIndex];
sayingText.textContent = randomSaying.text;
sayingFrom.textContent = randomSaying.from;
// 淡入
sayingText.classList.remove('fade-out');
sayingFrom.classList.remove('fade-out');
})
.catch(error => {
console.error('加载一言失败:', error);
// 出错时也恢复显示
sayingText.classList.remove('fade-out');
sayingFrom.classList.remove('fade-out');
});
}, 500); // 等待500ms淡出动画完成
}
// 初始化加载一言
loadSaying();
// 每秒更新一次时间
setInterval(updateTime, 1000);
// 每30秒切换一次一言
setInterval(loadSaying, 30000);
// 子菜单切换功能
function toggleSubmenu(submenuId) {
const submenu = document.getElementById(submenuId);
const isShowing = submenu.classList.contains('show');
// 关闭所有子菜单
document.querySelectorAll('.submenu').forEach(menu => {
menu.classList.remove('show');
});
// 如果当前菜单未显示,则显示它
if (!isShowing) {
submenu.classList.add('show');
}
}
// 点击其他地方关闭子菜单
document.addEventListener('click', function(e) {
if (!e.target.closest('.submenu-container')) {
document.querySelectorAll('.submenu').forEach(menu => {
menu.classList.remove('show');
});
}
});
// 作业编辑弹窗功能
function openHomeworkModal() {
const iframe = document.getElementById('homeworkIframe');
if (iframe.contentWindow && iframe.contentWindow.resetToCreateMode) {
iframe.contentWindow.resetToCreateMode();
}
document.getElementById('homeworkModal').classList.add('show');
}
function openEditHomeworkModal(id) {
const homeworkList = getHomeworkList();
const homework = homeworkList.find(h => h.id === id);
if (!homework) {
alert('作业不存在');
return;
}
const iframe = document.getElementById('homeworkIframe');
if (iframe.contentWindow && iframe.contentWindow.loadHomeworkForEdit) {
iframe.contentWindow.loadHomeworkForEdit(homework);
}
document.getElementById('homeworkModal').classList.add('show');
}
function closeHomeworkModal() {
document.getElementById('homeworkModal').classList.remove('show');
// 重置 iframe 中的表单
const iframe = document.getElementById('homeworkIframe');
if (iframe.contentWindow && iframe.contentWindow.resetHomeworkForm) {
iframe.contentWindow.resetHomeworkForm();
}
}
// 设置窗口功能
async function openSettings() {
try {
if (window.pywebview && window.pywebview.api) {
const result = await window.pywebview.api.openSettingsWindow();
if (!result.success) {
console.error('打开设置窗口失败:', result.message);
}
} else {
console.error('API 不可用');
}
} catch (error) {
console.error('打开设置窗口出错:', error);
}
}
// 供 iframe 调用的回调函数
function onHomeworkSaved(homeworkData) {
console.log('作业已保存:', homeworkData);
// 保存到本地存储
saveHomework(homeworkData);
// 刷新显示
renderHomeworkCards();
closeHomeworkModal();
}
// 作业数据管理
// 作业数据缓存
let homeworkCache = null;
// 从服务器加载作业数据
async function loadHomeworkFromServer() {
try {
if (window.pywebview && window.pywebview.api) {
const result = await window.pywebview.api.loadHomeworkData();
if (result.success) {
homeworkCache = result.data || [];
// 同步到 localStorage
localStorage.setItem('homeworkList', JSON.stringify(homeworkCache));
return homeworkCache;
}
}
} catch (error) {
console.error('从服务器加载作业失败:', error);
}
// 如果服务器加载失败,从 localStorage 加载
const data = localStorage.getItem('homeworkList');
homeworkCache = data ? JSON.parse(data) : [];
return homeworkCache;
}
function getHomeworkList() {
// 如果有缓存,返回缓存
if (homeworkCache !== null) {
return homeworkCache;
}
// 否则从 localStorage 加载
const data = localStorage.getItem('homeworkList');
return data ? JSON.parse(data) : [];
}
function saveHomework(homeworkData) {
const list = getHomeworkList();
// 如果是编辑模式(有id),更新原有作业
if (homeworkData.id) {
const index = list.findIndex(h => h.id === homeworkData.id);
if (index !== -1) {
list[index] = {
...list[index],
...homeworkData,
updatedAt: new Date().toISOString()
};
}
} else {
// 新建模式
const homework = {
id: Date.now(),
...homeworkData,
createdAt: new Date().toISOString()
};
list.push(homework);
}
localStorage.setItem('homeworkList', JSON.stringify(list));
}
function deleteHomework(id) {
const list = getHomeworkList();
const newList = list.filter(h => h.id !== id);
localStorage.setItem('homeworkList', JSON.stringify(newList));
renderHomeworkCards();
}
// 显示右下角提醒卡片
function showToast(title, message, duration = 3000) {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = 'toast-card';
toast.innerHTML = `
<img src="icons/icons/alert.svg" alt="提醒" class="toast-icon">
<div class="toast-content">
<div class="toast-title">${title}</div>
<div class="toast-message">${message}</div>
</div>
`;
container.appendChild(toast);
// 自动关闭
setTimeout(() => {
toast.classList.add('hide');
setTimeout(() => {
toast.remove();
}, 300);
}, duration);
}
// 手动保存作业到文件
async function saveHomeworkToFile() {
const homeworkList = getHomeworkList();
if (homeworkList.length === 0) {
showToast('提示', '当前没有作业可保存');
return;
}
try {
// 调用 Python API 保存作业
if (window.pywebview && window.pywebview.api) {
const result = await window.pywebview.api.saveHomeworkToFile(homeworkList);
if (result.success) {
showToast('保存成功', result.message);
} else {
showToast('保存失败', result.message);
}
} else {
showToast('提示', '保存功能不可用');
}
} catch (error) {
console.error('保存作业失败:', error);
showToast('保存失败', error.message);
}
}
// 重启应用程序
async function restartApp() {
try {
if (window.pywebview && window.pywebview.api) {
showToast('重启', '应用程序正在重启...');
await window.pywebview.api.restartApp();
} else {
showToast('提示', '重启功能不可用');
}
} catch (error) {
console.error('重启失败:', error);
showToast('重启失败', error.message);
}
}
// 退出应用程序
async function exitApp() {
try {
if (window.pywebview && window.pywebview.api) {
await window.pywebview.api.exitApp();
} else {
// 如果API不可用,直接关闭窗口
window.close();
}
} catch (error) {
console.error('退出失败:', error);
window.close();
}
}
// 隐藏主窗口并显示小组件
async function hideMainWindow() {
try {
if (window.pywebview && window.pywebview.api) {
await window.pywebview.api.hideMainWindow();
} else {
showToast('提示', '隐藏功能不可用');
}
} catch (error) {
console.error('隐藏失败:', error);
showToast('隐藏失败', error.message);
}
}
// 自动保存作业(每5分钟)
function startAutoSave() {
// 每5分钟执行一次自动保存
setInterval(async () => {
const homeworkList = getHomeworkList();
// 只有在有作业时才保存
if (homeworkList.length === 0) {
return;
}
try {
if (window.pywebview && window.pywebview.api) {
const result = await window.pywebview.api.autoSaveHomework(homeworkList);
if (result.success) {
console.log('自动保存成功:', result.message);
} else {
console.error('自动保存失败:', result.message);
}
}
} catch (error) {
console.error('自动保存出错:', error);
}
}, 5 * 60 * 1000); // 5分钟 = 300000毫秒