CheckinDetailPage.vue
20.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
<template>
<div class="checkin-detail-page">
<!-- 页面内容 -->
<div class="page-content">
<!-- 作业描述 -->
<div class="section-wrapper">
<div class="section-title">作业描述</div>
<div class="section-content">
<div v-if="taskDetail.description" class="description-text" v-html="taskDetail.description">
</div>
<div v-else class="no-description">
暂无作业描述
</div>
</div>
</div>
<!-- 打卡内容区域 -->
<div class="section-wrapper">
<div class="section-title">打卡留言</div>
<div class="section-content">
<!-- 文本输入区域 -->
<div class="text-input-area">
<van-field
v-model="message"
rows="6"
autosize
type="textarea"
:placeholder="activeType === 'text' ? '请输入打卡留言,至少需要10个字符' : '请输入打卡留言(可选)'"
:maxlength="activeType === 'text' ? 500 : 200"
show-word-limit
/>
</div>
<!-- 打卡类型选项卡 -->
<div class="checkin-tabs">
<div class="tabs-header">
<div class="tab-title">选择打卡类型</div>
<div class="tabs-nav">
<div
v-for="option in attachmentTypeOptions"
:key="option.key"
@click="!isEditMode ? switchType(option.key) : null"
:class="['tab-item', {
active: activeType === option.key,
disabled: isEditMode && activeType !== option.key
}]"
>
<van-icon
:name="getIconName(option.key)"
size="1.2rem"
/>
<span class="tab-text">{{ option.value }}</span>
</div>
</div>
</div>
<!-- 文件上传区域 -->
<div v-if="activeType !== 'text'" class="upload-area">
<van-uploader
v-model="fileList"
:max-count="maxCount"
:max-size="20 * 1024 * 1024"
:before-read="beforeRead"
:after-read="afterRead"
@delete="onDelete"
multiple
:accept="getAcceptType()"
result-type="file"
:deletable="false"
/>
<!-- 文件列表显示 -->
<div v-if="fileList.length > 0" class="file-list">
<div v-for="(item, index) in fileList" :key="index" class="file-item">
<div class="file-info">
<van-icon :name="getFileIcon()" size="1rem" />
<span class="file-name">{{ item.name || item.file?.name }}</span>
<span class="file-status" :class="item.status">{{ item.message }}</span>
</div>
<van-icon
name="clear"
size="1rem"
@click="delItem(item)"
class="delete-icon"
/>
</div>
</div>
<div class="upload-tips">
<div class="tip-text">最多上传{{ maxCount }}个文件,每个不超过20M</div>
<div class="tip-text">{{ getUploadTips() }}</div>
</div>
</div>
</div>
</div>
</div>
<!-- 提交按钮 -->
<div v-if="!taskDetail.is_finish || route.query.status === 'edit'" class="submit-area">
<van-button
type="primary"
block
size="large"
:loading="uploading"
:disabled="!canSubmit"
@click="onSubmit"
>
{{ route.query.status === 'edit' ? '保存修改' : '提交打卡' }}
</van-button>
</div>
</div>
<!-- 上传加载遮罩 -->
<van-overlay :show="loading">
<div class="loading-wrapper" @click.stop>
<van-loading vertical color="#FFFFFF">上传中...</van-loading>
</div>
</van-overlay>
</div>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { getTaskDetailAPI } from "@/api/checkin"
import { getTeacherFindSettingsAPI } from '@/api/teacher'
import { useTitle } from '@vueuse/core'
import { useCheckin } from '@/composables/useCheckin'
import dayjs from 'dayjs'
const route = useRoute()
const router = useRouter()
useTitle('打卡详情')
// 使用打卡composable
const {
uploading,
loading,
message,
fileList,
activeType,
maxCount,
canSubmit,
beforeRead,
afterRead,
onDelete,
delItem,
onSubmit,
switchType,
initEditData
} = useCheckin()
// 任务详情数据
const taskDetail = ref({})
// 作品类型选项
const attachmentTypeOptions = ref([])
// 是否为编辑模式
const isEditMode = computed(() => route.query.status === 'edit')
/**
* 返回上一页
*/
const onClickLeft = () => {
router.back()
}
/**
* 根据打卡类型获取对应的图标名称
* @param {string} type - 打卡类型
* @returns {string} 图标名称
*/
const getIconName = (type) => {
const iconMap = {
'text': 'edit',
'image': 'photo',
'video': 'video',
'audio': 'music'
}
return iconMap[type] || 'edit'
}
/**
* 获取文件图标
* @returns {string} 文件图标名称
*/
const getFileIcon = () => {
const iconMap = {
'image': 'photo',
'video': 'video',
'audio': 'music'
}
return iconMap[activeType.value] || 'description'
}
/**
* 获取上传文件类型
* @returns {string} accept属性值
*/
const getAcceptType = () => {
const acceptMap = {
'image': 'image/*',
'video': 'video/*',
'audio': '.mp3,.wav,.aac'
}
return acceptMap[activeType.value] || '*'
}
/**
* 获取上传提示文本
* @returns {string} 提示文本
*/
const getUploadTips = () => {
const tipsMap = {
'image': '支持格式:jpg/jpeg/png',
'video': '支持格式:视频文件',
'audio': '支持格式:.mp3/.wav/.aac 音频文件'
}
return tipsMap[activeType.value] || ''
}
/**
* 获取任务详情
* @param {string} month - 月份
*/
const getTaskDetail = async (month) => {
const { code, data } = await getTaskDetailAPI({ i: route.query.id, month })
if (code) {
taskDetail.value = data
// TODO: 临时 mock 富文本数据,后续替换为真实数据
// if (!taskDetail.value.description) {
// taskDetail.value.description = `
// <div class="rich-content">
// <h2 style="color: #2563eb; margin-bottom: 16px; font-size: 20px; font-weight: 600;">📚 本周学习任务</h2>
// <p style="margin-bottom: 16px; line-height: 1.6; color: #374151;">
// 同学们好!本周我们将学习<strong style="color: #dc2626;">Vue3 组合式 API</strong>的核心概念。请大家认真完成以下任务:
// </p>
// <div style="background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%); padding: 16px; border-radius: 12px; margin: 16px 0; border-left: 4px solid #f59e0b;">
// <h3 style="color: #92400e; margin: 0 0 8px 0; font-size: 16px;">⚠️ 重要提醒</h3>
// <p style="margin: 0; color: #78350f;">请在截止日期前提交作业,逾期将影响成绩评定。</p>
// </div>
// <h3 style="color: #059669; margin: 24px 0 12px 0; font-size: 18px;">📋 具体要求:</h3>
// <ol style="margin: 16px 0; padding-left: 24px; color: #374151; line-height: 1.8;">
// <li style="margin-bottom: 8px;">
// <strong>理论学习:</strong>观看课程视频,理解 <code style="background: #f3f4f6; padding: 2px 6px; border-radius: 4px; color: #dc2626;">ref</code> 和 <code style="background: #f3f4f6; padding: 2px 6px; border-radius: 4px; color: #dc2626;">reactive</code> 的区别
// </li>
// <li style="margin-bottom: 8px;">
// <strong>实践操作:</strong>完成课后练习,创建一个简单的计数器组件
// </li>
// <li style="margin-bottom: 8px;">
// <strong>拓展思考:</strong>思考组合式 API 相比选项式 API 的优势
// </li>
// </ol>
// <div style="text-align: center; margin: 24px 0;">
// <img src="https://cdn.ipadbiz.cn/mlaj/images/vue3-composition-api.jpg"
// alt="Vue3 组合式 API 示意图"
// style="max-width: 100%; height: auto; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);" />
// <p style="margin-top: 8px; color: #6b7280; font-size: 14px; font-style: italic;">
// Vue3 组合式 API 架构图
// </p>
// </div>
// <div style="background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%); padding: 16px; border-radius: 12px; margin: 20px 0;">
// <h4 style="color: #1e40af; margin: 0 0 12px 0; font-size: 16px;">💡 学习提示</h4>
// <ul style="margin: 0; padding-left: 20px; color: #1e3a8a;">
// <li style="margin-bottom: 6px;">可以参考官方文档进行学习</li>
// <li style="margin-bottom: 6px;">建议先理解概念,再动手实践</li>
// <li style="margin-bottom: 6px;">遇到问题可以在群里讨论</li>
// </ul>
// </div>
// <blockquote style="border-left: 4px solid #10b981; background: #f0fdf4; padding: 16px; margin: 20px 0; border-radius: 0 8px 8px 0;">
// <p style="margin: 0; color: #065f46; font-style: italic; line-height: 1.6;">
// "学而时习之,不亦说乎?" —— 希望大家能够在实践中加深对知识的理解。
// </p>
// </blockquote>
// <div style="text-align: center; margin: 24px 0;">
// <img src="https://cdn.ipadbiz.cn/mlaj/images/coding-example.png"
// alt="代码示例"
// style="max-width: 100%; height: auto; border-radius: 8px; border: 2px solid #e5e7eb;" />
// </div>
// <div style="background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 16px; margin: 20px 0;">
// <h4 style="color: #dc2626; margin: 0 0 8px 0; font-size: 16px;">📅 截止时间</h4>
// <p style="margin: 0; color: #991b1b; font-weight: 500;">
// 2024年12月31日 23:59
// </p>
// </div>
// <p style="margin-top: 24px; color: #6b7280; text-align: center; font-size: 14px;">
// 祝大家学习愉快!有问题随时联系老师 👨🏫
// </p>
// </div>
// `
// }
}
}
/**
* 页面挂载时的初始化逻辑
*/
onMounted(async () => {
// 获取任务详情
const current_date = route.query.date;
if (current_date) {
getTaskDetail(dayjs(current_date).format('YYYY-MM'));
} else {
getTaskDetail(dayjs().format('YYYY-MM'));
}
// 获取作品类型数据
try {
const { code, data } = await getTeacherFindSettingsAPI()
if (code && data.task_attachment_type) {
attachmentTypeOptions.value = Object.entries(data.task_attachment_type).map(([key, value]) => ({
key,
value
}))
}
} catch (error) {
console.error('获取作品类型数据失败:', error)
}
// 初始化编辑数据
await initEditData()
})
</script>
<style lang="less" scoped>
.checkin-detail-page {
min-height: 100vh;
background: linear-gradient(to bottom right, #f0fdf4, #f0fdfa, #eff6ff);
padding-bottom: 100px;
}
.page-content {
padding: 1rem;
}
.section-wrapper {
background-color: #fff;
border-radius: 12px;
margin-bottom: 1rem;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.section-title {
font-size: 1.1rem;
font-weight: 600;
color: #4caf50;
padding: 1rem 1rem 0.5rem;
border-bottom: 1px solid #f0f0f0;
}
.section-content {
padding: 1rem;
}
.description-text {
color: #666;
line-height: 1.6;
font-size: 0.95rem;
// 富文本内容样式
// :deep(.rich-content) {
// h1, h2, h3, h4, h5, h6 {
// margin: 16px 0 12px 0;
// font-weight: 600;
// line-height: 1.4;
// }
// h2 {
// font-size: 20px;
// color: #2563eb;
// }
// h3 {
// font-size: 18px;
// color: #059669;
// }
// h4 {
// font-size: 16px;
// }
// p {
// margin: 12px 0;
// line-height: 1.6;
// color: #374151;
// }
// strong {
// font-weight: 600;
// color: #dc2626;
// }
// code {
// background: #f3f4f6;
// padding: 2px 6px;
// border-radius: 4px;
// color: #dc2626;
// font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
// font-size: 0.9em;
// }
// ol, ul {
// margin: 16px 0;
// padding-left: 24px;
// li {
// margin-bottom: 8px;
// line-height: 1.8;
// }
// }
// blockquote {
// border-left: 4px solid #10b981;
// background: #f0fdf4;
// padding: 16px;
// margin: 20px 0;
// border-radius: 0 8px 8px 0;
// p {
// margin: 0;
// color: #065f46;
// font-style: italic;
// }
// }
// img {
// max-width: 100%;
// height: auto;
// border-radius: 8px;
// margin: 12px 0;
// display: block;
// }
// // 特殊样式容器
// .warning-box {
// background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
// padding: 16px;
// border-radius: 12px;
// margin: 16px 0;
// border-left: 4px solid #f59e0b;
// }
// .info-box {
// background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
// padding: 16px;
// border-radius: 12px;
// margin: 20px 0;
// }
// .deadline-box {
// background: #fef2f2;
// border: 1px solid #fecaca;
// border-radius: 8px;
// padding: 16px;
// margin: 20px 0;
// }
// // 图片容器居中
// div[style*="text-align: center"] {
// text-align: center;
// img {
// margin: 12px auto;
// }
// p {
// color: #6b7280;
// font-size: 14px;
// font-style: italic;
// margin-top: 8px;
// }
// }
// }
}
.no-description {
color: #999;
font-style: italic;
text-align: center;
padding: 2rem 0;
}
.text-input-area {
margin-bottom: 1.5rem;
.van-field {
border-radius: 8px;
background-color: #f8f9fa;
border: 1px solid #e9ecef;
}
}
.checkin-tabs {
.tabs-header {
margin-bottom: 1rem;
}
.tab-title {
font-size: 1rem;
font-weight: 600;
color: #333;
margin-bottom: 0.8rem;
}
.tabs-nav {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 0.5rem;
}
.tab-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 0.8rem 0.5rem;
border: 2px solid #e8f5e8;
border-radius: 8px;
background-color: #fafffe;
cursor: pointer;
transition: all 0.3s ease;
&:hover {
border-color: #4caf50;
background-color: #f0fdf4;
}
&.active {
border-color: #4caf50;
background-color: #f0fdf4;
.van-icon {
color: #4caf50;
}
.tab-text {
color: #4caf50;
font-weight: 600;
}
}
&.disabled {
opacity: 0.5;
cursor: not-allowed;
&:hover {
border-color: #e8f5e8;
background-color: #fafffe;
}
}
}
.tab-text {
margin-top: 0.3rem;
font-size: 0.8rem;
color: #666;
text-align: center;
}
}
.upload-area {
margin-top: 1rem;
.van-uploader {
margin-bottom: 1rem;
}
}
.file-list {
margin: 1rem 0;
}
.file-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.8rem;
background-color: #f8f9fa;
border-radius: 8px;
margin-bottom: 0.5rem;
.file-info {
display: flex;
align-items: center;
flex: 1;
gap: 0.5rem;
}
.file-name {
flex: 1;
font-size: 0.9rem;
color: #333;
overflow: hidden;
text-overflow: ellipsis;
// white-space: nowrap;
}
.file-status {
font-size: 0.8rem;
padding: 0.2rem 0.5rem;
border-radius: 4px;
&.uploading {
color: #1890ff;
background-color: #e6f7ff;
}
&.done {
color: #52c41a;
background-color: #f6ffed;
}
&.failed {
color: #ff4d4f;
background-color: #fff2f0;
}
}
.delete-icon {
color: #999;
cursor: pointer;
&:hover {
color: #ff4d4f;
}
}
}
.upload-tips {
.tip-text {
font-size: 0.8rem;
color: #999;
margin-bottom: 0.3rem;
}
}
.finished-notice {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 3rem 1rem;
text-align: center;
}
.finished-text {
margin-top: 1rem;
font-size: 1.1rem;
color: #4caf50;
font-weight: 600;
}
.submit-area {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 1rem;
background-color: #fff;
border-top: 1px solid #f0f0f0;
z-index: 100;
}
.loading-wrapper {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
</style>