-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeekFlow.html
More file actions
1179 lines (1038 loc) · 46.4 KB
/
Copy pathWeekFlow.html
File metadata and controls
1179 lines (1038 loc) · 46.4 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="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>智能周报生成系统</title>
<script src="https://cdn.jsdelivr.net/npm/docx@8.0.1/build/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/file-saver@2.0.5/dist/FileSaver.min.js"></script>
<style>
:root {
--primary: #3B82F6;
--border: #E5E7EB;
--hover-bg: #F3F4F6;
--primary-hover: #2563eb;
background: #f8fafc; /* 添加浅色背景 */
}
html, body {
height: 100%;
min-height: 100vh; /* 新增 */
}
body {
font-family: system-ui;
margin: 0;
padding: 0 0;
position: relative;
overflow-x: hidden;
min-height: 100vh;
display: flex; /* 新增 */
flex-direction: column; /* 新增 */
}
body::after {
content: '';
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: linear-gradient(45deg, #f8fafc 20%, #e2e8f0 80%); /* 减少颜色对比度 */
filter: blur(60px); /* 增大模糊半径 */
opacity: 0.2; /* 进一步降低透明度 */
z-index: -1;
}
.container {
background: #ffffff; /* 改为纯白色 */
border-radius: 12px;
box-shadow: 0 8px 30px rgba(0,0,0,0.08);
padding: 2rem;
position: relative;
z-index: 1;
}
/* 新增页脚样式 */
.app-footer {
text-align: center;
color: #666;
padding: 1rem 0;
border-top: 1px solid #eee;
flex-shrink: 0; /* 关键属性 */
}
.footer-info {
font-size: 0.75rem;
color: #999;
margin-top: 0.5rem;
}
.footer-info a {
color: var(--primary);
text-decoration: none;
}
.section {
margin: 2rem 0;
border: 1px solid #e2e8f0; /* 修改边框颜色 */
border-radius: 12px;
padding: 1.5rem;
background: white;
transition: transform 0.2s; /* 添加悬停动效 */
}
.section:hover {
transform: translateY(-2px);
}
.section-title {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1rem;
color: #1e40af; /* 深蓝色标题 */
position: relative;
padding-left: 28px;
}
.section-title::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 20px;
height: 20px;
background: #bfdbfe; /* 装饰性圆点 */
border-radius: 50%;
}
.input-group {
display: flex;
gap: 0.5rem;
margin: 0.5rem 0;
align-items: center;
position: relative;
user-select: auto;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.input-group.dragging {
transform: scale(1.02);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
z-index: 10;
background: white;
}
.sortable-container {
transition: all 0.3s ease;
}
/* 新增日期选择器样式 */
.date-picker {
width: 120px;
padding: 0.75rem;
border: 1px solid var(--border);
border-radius: 6px;
margin-right: 0.5rem;
}
.input-field {
flex: 1;
padding: 0.75rem;
border: 1px solid var(--border);
border-radius: 6px;
padding-right: 2rem;
min-height: 40px; /* 新增最小高度 */
resize: vertical; /* 允许垂直缩放 */
overflow-y: hidden; /* 添加滚动条 */
white-space: pre-wrap; /* 保留换行 */
}
.input-field:focus {
outline: none;
border-color: #93c5fd;
box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.3);
}
.drag-handle {
cursor: move;
padding: 0.5rem;
opacity: 0.5;
transition: opacity 0.2s;
user-select: none;
}
.drag-handle:hover {
opacity: 1;
}
.delete-btn {
position: absolute;
right: 0.5rem;
top: 50%;
transform: translateY(-50%);
opacity: 0;
transition: opacity 0.2s;
cursor: pointer;
color: #6B7280;
}
.input-group:hover .delete-btn {
opacity: 0.5;
}
.delete-btn:hover {
opacity: 1 !important;
color: #EF4444;
}
.add-row-btn {
width: 100%;
margin-top: 0.5rem;
padding: 0.5rem;
border: 1px dashed var(--border);
border-radius: 6px;
background: none;
cursor: pointer;
color: #6B7280;
transition: all 0.2s;
}
.add-row-btn:hover {
background: var(--hover-bg);
border-color: var(--primary);
color: var(--primary);
}
.export-btn {
display: flex; /* 新增flex布局 */
align-items: center; /* 垂直居中 */
justify-content: center; /* 水平居中 */
gap: 8px; /* 新增图标文字间距 */
width: 200px;
margin: 2rem auto 0;
background: var(--primary);
color: white;
border: none;
padding: 14px 28px;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s;
font-size: 16px;
}
/* 新增 SVG 图标对齐修正 */
.export-btn svg {
margin: 0; /* 移除默认边距 */
flex-shrink: 0; /* 禁止图标缩放 */
}
.export-btn:hover {
background: var(--primary-hover);
transform: translateY(-2px);
box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3);
}
.clear-btn {
position: absolute;
top: 24px;
right: 24px;
background: #EF4444;
padding: 12px 24px;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s;
display: flex;
gap: 8px;
align-items: center;
color: white;
border: none;
font-weight: 500;
z-index: 10;
}
.clear-btn:hover {
background: #DC2626;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}
.color-tag {
width: 4px;
height: 24px;
background: #93c5fd;
border-radius: 2px;
margin-right: 8px;
transition: 0.3s ease;
}
.input-group:hover .color-tag {
width: 8px;
}
/* 新增分栏布局 */
.main-container {
display: flex;
gap: 1.5rem;
margin: 1rem;
padding: 1rem auto;
max-width: none;
flex-grow: 1;
height: auto !important;
flex: 1;
padding-bottom: 2rem;
}
.left-panel {
position: fixed;
width: 22.5%; /* 改为比例布局 */
height: calc(100vh - 40px);
overflow-y: auto;
padding-right: 0.5rem;
}
.right-content {
flex: 3; /* 比例调整为1:2 */
margin-left: calc(22.5% + 20px); /* 动态计算边距 */
height: auto !important;
overflow-y: auto;
}
/* 新增占位卡片样式 */
.placeholder-card {
background: white;
border-radius: 12px;
padding: 2rem;
text-align: center;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
border: 1px solid #e2e8f0;
min-height: 300px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
/* 新增数据分析面板样式 */
.data-panel {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.data-card {
background: white;
border-radius: 12px;
padding: 1.5rem;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.data-title {
font-size: 0.875rem;
color: #64748b;
}
.data-value {
font-size: 2rem;
font-weight: 600;
color: #1e40af;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 1rem;
}
.stat-item {
background: #f8fafc;
border-radius: 8px;
padding: 1rem;
text-align: center;
}
.stat-label {
display: block;
font-size: 0.75rem;
color: #64748b;
}
.stat-value {
font-size: 1.25rem;
font-weight: 600;
color: #3b82f6;
}
.notice-box {
background: #fff7ed;
border-radius: 8px;
padding: 1rem;
border-left: 4px solid #fb923c;
}
.notice-box h3 {
margin: 0 0 0.5rem 0;
font-size: 0.875rem;
color: #c2410c;
}
.notice-box ul {
margin: 0;
padding-left: 1.25rem;
font-size: 0.875rem;
color: #854d0e;
}
.progress-text {
font-size: 0.75rem;
fill: #3b82f6;
text-anchor: middle;
dominant-baseline: middle;
}
/* 移动端适配保持原样 */
@media (max-width: 1200px) {
.left-panel {
width: 25%;
}
.right-content {
margin-left: calc(25% + 20px);
}
}
@media (max-width: 992px) {
.main-container {
flex-direction: column;
}
.left-panel {
width: 100%;
height: auto;
position: static;
margin-bottom: 1.5rem;
}
.right-content {
margin-left: 0;
width: 100%;
}
}
@media (max-width: 768px) {
.container {
padding: 1rem;
}
.section-title {
font-size: 1.1rem;
padding-left: 24px;
}
.input-group {
flex-wrap: wrap;
}
.date-picker {
width: 100%;
margin: 0.5rem 0;
}
}
@media (max-width: 576px) {
.data-card {
flex-direction: column;
align-items: flex-start;
}
.data-value {
font-size: 1.5rem;
}
.export-btn {
width: 100%;
padding: 12px;
}
.stats-grid {
grid-template-columns: 1fr;
}
.input-field {
min-height: 48px;
}
.drag-handle {
padding: 0.8rem;
}
}
</style>
</head>
<body>
<div class="main-container">
<!-- 新增左侧面板 -->
<div class="left-panel">
<div class="container">
<div class="data-panel">
<div class="data-card">
<div class="data-title">总条目</div>
<div class="data-value" id="totalCount">0</div>
</div>
<div class="stats-grid">
<div class="stat-item">
<span class="stat-label">内容条目</span>
<span class="stat-value" id="workCount">0</span>
</div>
<div class="stat-item">
<span class="stat-label">汇总条目</span>
<span class="stat-value" id="summaryCount">0</span>
</div>
<div class="stat-item">
<span class="stat-label">下周计划</span>
<span class="stat-value" id="planCount">0</span>
</div>
<div class="stat-item">
<span class="stat-label">重点工作</span>
<span class="stat-value" id="keyworkCount">0</span>
</div>
</div>
<!-- 新增时间统计卡片 -->
<div class="data-card" style="margin-top: 1rem;">
<div class="data-title">入职公司已经</div>
<div class="stats-grid" id="time-stats">
<div class="stat-item">
<span class="stat-label">年数</span>
<span class="stat-value" id="yearsCount">0</span>
</div>
<div class="stat-item">
<span class="stat-label">月数</span>
<span class="stat-value" id="monthsCount">0</span>
</div>
<div class="stat-item">
<span class="stat-label">周数</span>
<span class="stat-value" id="weeksCount">0</span>
</div>
<div class="stat-item">
<span class="stat-label">天数</span>
<span class="stat-value" id="daysCount">0</span>
</div>
</div>
</div>
<div class="notice-box">
<h3>注意事项</h3>
<ul>
<li>按住 ≡ 拖动排序</li>
<li>选中输入框进行编辑</li>
<li>点击 × 删除条目</li>
</ul>
</div>
</div>
</div>
</div>
<!-- 原内容包裹在右侧容器 -->
<div class="right-content">
<!-- 原有 container 内容保持不变... -->
<div class="container">
<h1 id="weekTitle" style="margin-bottom: 1.5rem; color: #1F2937; font-size: 1.5rem; font-weight: 600;"></h1>
<button class="clear-btn" onclick="confirmClear()">
<svg width="18" height="18" viewBox="0 0 24 24">
<path fill="currentColor" d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/>
</svg>
清空数据
</button>
<div class="section">
<div class="section-title">本周工作内容</div>
<div id="work-content" class="sortable-container">
<div class="input-group" draggable="true">
<div class="color-tag"></div>
<div class="drag-handle">≡</div>
<input type="date" class="date-picker" placeholder="选择日期">
<input type="text" class="input-field" placeholder="输入工作内容">
<div class="delete-btn">×</div>
</div>
</div>
<button class="add-row-btn" onclick="addNewRow(this)">+ 添加新条目</button>
</div>
<!-- 新增本周工作汇总 -->
<div class="section">
<div class="section-title">本周工作汇总</div>
<div id="work-summary" class="sortable-container">
<div class="input-group" draggable="true">
<div class="color-tag"></div>
<div class="drag-handle">≡</div>
<input type="text" class="input-field" placeholder="输入汇总内容">
<div class="delete-btn">×</div>
</div>
</div>
<button class="add-row-btn" onclick="addNewRow(this)">+ 添加新条目</button>
</div>
<!-- 新增下周工作计划 -->
<div class="section">
<div class="section-title">下周工作计划</div>
<div id="next-week-plan" class="sortable-container">
<div class="input-group" draggable="true">
<div class="color-tag"></div>
<div class="drag-handle">≡</div>
<input type="text" class="input-field" placeholder="输入计划内容">
<div class="delete-btn">×</div>
</div>
</div>
<button class="add-row-btn" onclick="addNewRow(this)">+ 添加新条目</button>
</div>
<!-- 新增重点工作进度汇报 -->
<div class="section">
<div class="section-title">重点工作进度汇报</div>
<div id="key-progress" class="sortable-container">
<div class="input-group" draggable="true">
<div class="color-tag"></div>
<div class="drag-handle">≡</div>
<input type="text" class="input-field" placeholder="输入汇报内容">
<div class="delete-btn">×</div>
</div>
</div>
<button class="add-row-btn" onclick="addNewRow(this)">+ 添加新条目</button>
</div>
<button class="export-btn" onclick="exportToWord()">
<svg class="spinner" width="18" height="18" viewBox="0 0 24 24" style="display:none;">
<path fill="currentColor" d="M12,4V2A10,10 0 0,0 2,12H4A8,8 0 0,1 12,4Z"/>
</svg>
<svg width="18" height="18" viewBox="0 0 24 24">
<path fill="currentColor" d="M14,17H7V15H14V17M17,13H7V11H17V13M17,9H7V7H17V9M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3Z"/>
</svg>
导出周报
</button>
</div>
</div>
</div>
<footer class="app-footer">
<span id="hitokoto-text">加载中...</span>
<div class="footer-info">
© 2025 Developed by TiantianYZJ
| 遵循 <a href="https://www.gnu.org/licenses/gpl-3.0.html" target="_blank">GNU GPLv3</a>
| GitHub <a href="https://github.com/TiantianYZJ/WeekFlow" target="_blank">源码仓库</a>
</div>
</footer>
</body>
<script>
// window.addEventListener('beforeunload', (e) => {
// if (hasUnsavedChanges()) { // 需要实现 hasUnsavedChanges 函数
// e.preventDefault();
// e.returnValue = '';
// }
// });
// function hasUnsavedChanges() {
// return Array.from(document.querySelectorAll('.input-field'))
// .some(input => input.value.trim() !== '');
// }
// 在脚本中添加清空功能
function confirmClear() {
if (confirm('确定要清空所有数据吗?此操作不可恢复!')) {
// 清空所有输入
document.querySelectorAll('.input-group').forEach(group => group.remove());
// 清除本地存储
localStorage.removeItem('weekflow-draft');
// 恢复初始状态
['work-content', 'work-summary', 'next-week-plan', 'key-progress'].forEach(id => {
const container = document.getElementById(id);
const template = container.querySelector('.input-group')?.cloneNode(true) || createInitialRow(id);
container.innerHTML = '';
container.appendChild(template);
});
// 修改恢复初始状态的方式
['work-content', 'work-summary', 'next-week-plan', 'key-progress'].forEach(id => {
const container = document.getElementById(id);
container.innerHTML = '';
container.appendChild(createInitialRow(id)); // 直接创建新初始行
});
updateStats(); // 新增统计更新
setTimeout(updateStats, 0); // 确保DOM更新后再次刷新
}
}
// 新增数据统计功能
function updateStats() {
// 统计各区域条目数量
const workCount = document.querySelectorAll('#work-content .input-group').length;
const summaryCount = document.querySelectorAll('#work-summary .input-group').length;
const planCount = document.querySelectorAll('#next-week-plan .input-group').length;
const keyworkCount = document.querySelectorAll('#key-progress .input-group').length;
const total = workCount + summaryCount + planCount + keyworkCount;
// 更新数字显示
document.getElementById('workCount').textContent = workCount;
document.getElementById('summaryCount').textContent = summaryCount;
document.getElementById('planCount').textContent = planCount;
document.getElementById('keyworkCount').textContent = keyworkCount;
document.getElementById('totalCount').textContent = total;
}
// 在JavaScript中添加时间计算函数(放在updateStats函数附近)
function updateTimeStats() {
const startDate = new Date(2017, 11, 6); // 月份从0开始计算(12月是11)
const today = new Date();
// 计算时间差
const timeDiff = today - startDate;
const days = Math.floor(timeDiff / (1000 * 3600 * 24));
const weeks = Math.floor(days / 7);
const months = Math.floor(days / 30.436875); // 平均每月天数
const years = Math.floor(days / 365.2425); // 平均年天数
// 更新显示
document.getElementById('daysCount').textContent = days;
document.getElementById('weeksCount').textContent = weeks;
document.getElementById('monthsCount').textContent = months;
document.getElementById('yearsCount').textContent = years;
}
// 在DOM加载时和每天自动更新
document.addEventListener('DOMContentLoaded', () => {
updateTimeStats();
setInterval(updateTimeStats, 1000);
});
// 创建初始行模板
function createInitialRow(sectionId) {
const row = document.createElement('div');
row.className = 'input-group';
row.draggable = true;
row.innerHTML = `
<div class="color-tag"></div> <!-- 新增颜色标签 -->
<div class="drag-handle">≡</div>
${sectionId === 'work-content' ? '<input type="date" class="date-picker">' : ''}
<input type="text" class="input-field" placeholder="${
sectionId === 'work-content' ? '输入工作内容' :
sectionId === 'work-summary' ? '输入汇总内容' :
sectionId === 'next-week-plan' ? '输入计划内容' : '输入汇报内容'}">
<div class="delete-btn">×</div>
`;
// 新增颜色设置逻辑
const colorTag = row.querySelector('.color-tag');
if (sectionId === 'work-content') {
colorTag.style.background = '#93c5fd';
} else if (sectionId === 'work-summary') {
colorTag.style.background = '#86efac';
} else if (sectionId === 'key-progress') { // 新增颜色分支
colorTag.style.background = '#fca5a5'; // 红色标签
} else {
colorTag.style.background = '#d8b4fe';
}
return row;
}
// 拖拽排序功能
document.querySelectorAll('.sortable-container').forEach(container => {
let draggedItem = null;
container.addEventListener('dragstart', e => {
if (e.target.closest('.input-group')) {
draggedItem = e.target.closest('.input-group');
setTimeout(() => draggedItem.classList.add('dragging'), 0);
}
});
container.addEventListener('dragover', e => {
e.preventDefault();
const afterElement = getDragAfterElement(container, e.clientY);
const currentItem = draggedItem;
if (afterElement == null) {
container.appendChild(currentItem);
} else {
container.insertBefore(currentItem, afterElement);
}
});
container.addEventListener('click', e => {
if (e.target.closest('.delete-btn')) {
e.target.closest('.input-group').remove();
updateStats(); // 确保删除时更新统计
}
});
container.addEventListener('dragend', () => {
draggedItem.classList.remove('dragging');
});
function getDragAfterElement(container, y) {
return [...container.querySelectorAll('.input-group:not(.dragging)')]
.reduce((closest, child) => {
const box = child.getBoundingClientRect();
const offset = y - box.top - box.height / 2;
if (offset < 0 && offset > closest.offset) {
return { offset, element: child };
} else {
return closest;
}
}, { offset: Number.NEGATIVE_INFINITY }).element;
}
});
// 修改添加新行函数
function addNewRow(button, data = {}) {
const container = button.previousElementSibling;
const newRow = document.createElement('div');
newRow.className = 'input-group';
newRow.draggable = true;
// 根据容器ID判断是否添加日期选择器
const isContentSection = container.id === 'work-content';
// 根据容器ID设置对应的placeholder
const sectionId = container.id;
const placeholderMap = {
'work-content': '输入工作内容',
'work-summary': '输入汇总内容',
'next-week-plan': '输入计划内容',
'key-progress': '输入汇报内容'
};
// 更新模板添加颜色标签
newRow.innerHTML = `
<div class="color-tag"></div>
<div class="drag-handle">≡</div>
${sectionId === 'work-content' ? '<input type="date" class="date-picker" placeholder="选择日期">' : ''}
<textarea class="input-field" placeholder="${placeholderMap[sectionId] || '输入内容'}"></textarea>
<div class="delete-btn">×</div>
`;
// 新增颜色分类逻辑
const colorTag = newRow.querySelector('.color-tag');
if (sectionId === 'work-content') {
colorTag.style.background = '#93c5fd';
} else if (sectionId === 'work-summary') {
colorTag.style.background = '#86efac';
} else if (sectionId === 'key-progress') { // 新增颜色分支
colorTag.style.background = '#fca5a5'; // 红色标签
} else {
colorTag.style.background = '#d8b4fe';
}
container.appendChild(newRow);
updateStats(); // 添加统计更新
newRow.querySelector('.input-field').focus(); // 聚焦到文本输入框
// 改为使用事件委托
newRow.querySelector('.delete-btn').addEventListener('click', function() {
this.closest('.input-group').remove();
});
if (data.date) newRow.querySelector('.date-picker').value = data.date;
if (data.text) newRow.querySelector('.input-field').value = data.text;
// 添加事件监听:聚焦时禁用拖动,失焦时恢复拖动
newRow.querySelectorAll('.date-picker, .input-field').forEach(input => {
input.addEventListener('focus', () => {
newRow.draggable = false;
newRow.style.opacity = '0.8'; // 添加视觉反馈
});
input.addEventListener('blur', () => {
newRow.draggable = true;
newRow.style.opacity = '1';
});
});
}
// 添加自动保存监听
document.addEventListener('input', () => {
saveDraft();
debouncedSave();
});
function autoExpand(input) {
input.style.height = 'auto';
input.style.height = input.scrollHeight + 'px';
}
document.querySelectorAll('.input-field').forEach(input => {
input.addEventListener('input', () => autoExpand(input));
});
const debouncedSave = debounce(saveDraft, 1000);
function debounce(fn, delay) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), delay);
};
}
// 修改回车创建新行逻辑
document.addEventListener('keydown', e => {
if (e.key === 'Enter' && e.target.matches('.input-field')) {
const currentRow = e.target.closest('.input-group');
const container = currentRow.closest('.sortable-container');
const isContentSection = container.id === 'work-content';
const newRow = currentRow.cloneNode(true);
// 添加删除事件绑定
newRow.querySelector('.delete-btn').addEventListener('click', function() {
this.closest('.input-group').remove();
});
// 移除非内容板块的日期选择器
if (!isContentSection) {
const datePicker = newRow.querySelector('.date-picker');
datePicker?.remove();
}
newRow.querySelector('.input-field').value = '';
currentRow.after(newRow);
updateStats(); // 新增统计更新
newRow.querySelector('.input-field').focus();
e.preventDefault();
}
});
// 导出功能优化
async function exportToWord() {
const btn = document.querySelector('.export-btn');
btn.disabled = true;
btn.querySelector('svg:not(.spinner)').style.display = 'none';
btn.querySelector('.spinner').style.display = 'block';
// 新增日期格式化函数
function formatDate(date) {
const month = (date.getMonth() + 1).toString();
const day = date.getDate().toString();
return `${month}.${day}`;
}
// 新增周范围计算函数
function getFormattedWeekRange() {
const now = new Date();
const day = now.getDay(); // 0=周日,1=周一...6=周六
const monday = new Date(now);
monday.setDate(now.getDate() - (day === 0 ? 6 : day - 1));
const friday = new Date(monday);
friday.setDate(monday.getDate() + 4);
function format(date) {
return [
date.getFullYear(),
(date.getMonth() + 1).toString().padStart(2, '0'),
date.getDate().toString().padStart(2, '0')
].join('');
}
return `${format(monday)}-${format(friday)}`;
}
try {
const { Document, Packer, Paragraph, TextRun, HeadingLevel } = docx;
const doc = new Document({
styles: {
paragraphStyles: [{
id: "Normal",
name: "Normal",
basedOn: "Normal",
next: "Normal",
run: {
font: "微软雅黑",
size: 24,
},
paragraph: {
spacing: { line: 240 },
indent: { left: 0 }
}
}],
// 新增标题样式
documentStyles: [{
id: "Heading",
name: "Heading",
basedOn: "Normal",
run: {
bold: true,
font: "微软雅黑",
size: 28
}
}]
},
sections: [{
properties: {
page: {
margin: {
top: 1440, // 2.54cm = 1440 Twip (1cm=567 Twip)
bottom: 1440, // 2.54cm
left: 1800, // 3.18cm = 1800 Twip
right: 1800 // 3.18cm
}
}
},
children: [
...Array.from(document.querySelectorAll('.section')).map(section => {
const title = section.querySelector('.section-title').textContent.trim();
const items = Array.from(section.querySelectorAll('.input-group')).map(group => {
// 添加空值安全判断
const dateInput = group.querySelector('.date-picker');
const textInput = group.querySelector('.input-field');
// 处理没有日期选择器的板块
const dateStr = dateInput?.value ?? '';
const date = dateStr ? formatDate(new Date(dateStr)) : '';
const text = textInput?.value.trim() || '';
// 处理空日期情况
return text ? (date ? `${date} ${text}` : text) : null;