CheckinDetailPage.vue
12.1 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
<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">
{{ 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="switchType(option.key)"
:class="['tab-item', { active: 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 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
}
}
/**
* 页面挂载时的初始化逻辑
*/
onMounted(async () => {
// 获取任务详情
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;
}
.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;
}
}
}
.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>