CheckinDetailPage.vue
45.3 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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
<!--
* @Date: 2025-09-30 17:05
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-22 22:11:29
* @FilePath: /mlaj/src/views/checkin/CheckinDetailPage.vue
* @Description: 用户打卡详情页
-->
<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="displayTaskNote" class="description-text" v-html="displayTaskNote">
</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="mb-4">
<!-- 编辑模式下直接显示文本 -->
<div v-if="isEditMode" class="bg-gray-50 rounded-lg p-3 border border-gray-100 flex items-center justify-between">
<span class="text-gray-700 font-medium">当前作业</span>
<span class="text-gray-900 font-bold">{{ selectedTaskText }}</span>
</div>
<!-- 非编辑模式下显示选择框 -->
<template v-else>
<van-field v-model="selectedTaskText" is-link readonly label="选择作业" placeholder="请选择本次打卡的作业"
@click="showTaskPicker = true" class="rounded-lg border border-gray-100" />
<van-popup v-model:show="showTaskPicker" round position="bottom">
<van-picker :columns="taskOptions" @cancel="showTaskPicker = false"
@confirm="onConfirmTask" />
</van-popup>
</template>
</div>
<!-- 计数对象 -->
<CheckinTargetList
v-if="taskType === 'count' && selectedTaskValue && selectedTaskValue.length > 0"
:dynamic-field-text="dynamicFieldText"
:target-list="targetList"
:selected-targets="selectedTargets"
@add="openAddTargetDialog"
@toggle="toggleTarget"
@edit="handleTargetEdit"
@delete="handleTargetDelete"
/>
<!-- 计数次数 -->
<div v-if="taskType === 'count'"
class="mb-4 flex items-center justify-between bg-gray-50 p-3 rounded-lg">
<div class="text-sm font-bold text-gray-700">{{ dynamicFieldText }}次数</div>
<van-stepper v-model="countValue" min="1" integer input-width="80px" button-size="28px" />
</div>
<!-- 新增计数对象弹框 -->
<AddTargetDialog
v-model:show="showAddTargetDialog"
:title="editingTarget ? (isConfirmMode ? `确认${dynamicFieldText}项` : `编辑${dynamicFieldText}项`) : `添加${dynamicFieldText}项`"
:fields="dynamicFormFields"
:initial-values="editingTarget"
@confirm="confirmAddTarget"
/>
<!-- 文本输入区域 -->
<div class="text-input-area">
<van-field v-model="message" rows="6" autosize type="textarea"
:placeholder="taskType === 'count' ? '请输入留言(可选)' : (activeType === 'text' ? '请输入留言,至少需要10个字符' : '请输入留言(可选)')"
:maxlength="activeType === 'text' && taskType !== 'count' ? 500 : 200" show-word-limit />
</div>
<!-- 类型选项卡 -->
<div class="checkin-tabs" v-if="selectedTaskValue.length > 0">
<div class="tabs-header">
<div class="tab-title">{{ taskType === 'count' ? '附件类型(可选)' : '附件类型' }}</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 !== '' && activeType !== 'text'" class="upload-area">
<van-uploader v-model="fileList" :max-count="maxCount" :max-size="maxFileSizeBytes"
:before-read="beforeRead" :after-read="afterRead" @delete="onDelete"
@click-preview="onClickPreview" multiple :accept="getAcceptType()" result-type="file"
:deletable="true" upload-icon="plus" />
<!-- 文件列表显示 -->
<!-- <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" @click="previewFile(item)">
<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 }}个文件,每个不超过{{ maxFileSizeMb }}MB</div>
<div class="tip-text">{{ getUploadTips() }}</div>
</div>
</div>
</div>
</div>
</div>
<!-- 提交按钮 -->
<div v-if="!taskDetail.is_finish || isEditMode" class="submit-area">
<van-button type="primary" block size="large" :loading="uploading" :disabled="isSubmitDisabled" @click="handleSubmit">
{{ isEditMode ? '保存修改' : '提交' }}
</van-button>
</div>
</div>
<!-- 上传加载遮罩 -->
<van-overlay :show="loading" z-index="9999">
<div class="loading-wrapper" @click.stop>
<van-loading vertical color="#FFFFFF">上传中...</van-loading>
</div>
</van-overlay>
<!-- 音频播放器弹窗 -->
<van-popup v-model:show="audioShow" position="bottom" round closeable :style="{ height: '60%', width: '100%' }">
<div class="p-4">
<h3 class="text-lg font-medium mb-4 text-center">{{ audioTitle }}</h3>
<AudioPlayer v-if="audioShow && audioUrl" :songs="[{ title: audioTitle, url: audioUrl }]"
class="w-full" />
</div>
</van-popup>
<!-- 视频播放器弹窗 -->
<van-popup v-model:show="videoShow" position="center" round closeable
:style="{ width: '95%', maxHeight: '80vh' }" @close="stopVideoPlay">
<div class="p-4">
<h3 class="text-lg font-medium mb-4 text-center">视频预览</h3>
<div class="relative w-full bg-black rounded-lg overflow-hidden" style="aspect-ratio: 16/9;">
<!-- 视频封面 -->
<div v-show="!isVideoPlaying"
class="absolute inset-0 flex items-center justify-center cursor-pointer"
@click="startVideoPlay">
<img :src="videoCover || 'https://cdn.ipadbiz.cn/mlaj/images/cover_video_2.png'"
:alt="videoTitle" class="w-full h-full object-cover" />
<div class="absolute inset-0 flex items-center justify-center bg-black/20">
<div
class="w-16 h-16 rounded-full bg-black/50 flex items-center justify-center hover:bg-black/70 transition-colors">
<van-icon name="play-circle-o" class="text-white" size="40" />
</div>
</div>
</div>
<!-- 视频播放器 -->
<VideoPlayer v-if="isVideoPlaying" ref="videoPlayerRef" :video-url="videoUrl"
:video-id="videoTitle" :use-native-on-ios="false" :autoplay="false" class="w-full h-full" @play="handleVideoPlay"
@pause="handleVideoPause" />
</div>
</div>
</van-popup>
<!-- 图片预览弹窗 -->
<van-image-preview v-model:show="imageShow" :images="imageList" :start-position="imageIndex" :show-index="true" />
</div>
</template>
<script setup>
import { ref, computed, onMounted, nextTick, reactive, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { getTaskDetailAPI, getUploadTaskInfoAPI, getSubtaskListAPI, reuseGratitudeFormAPI } from "@/api/checkin"
import { useTitle } from '@vueuse/core'
import { useCheckin } from '@/composables/useCheckin'
import { normalizeAttachmentTypeConfig } from '@/utils/tools'
import AudioPlayer from '@/components/media/AudioPlayer.vue'
import VideoPlayer from '@/components/media/VideoPlayer.vue'
import AddTargetDialog from '@/components/count/AddTargetDialog.vue'
import CheckinTargetList from '@/components/count/CheckinTargetList.vue'
import { showToast, showLoadingToast } from 'vant'
import dayjs from 'dayjs'
const route = useRoute()
const router = useRouter()
useTitle('提交作业')
// 使用打卡composable
const {
uploading,
loading,
message,
fileList,
activeType,
subTaskId,
selectedTaskText,
selectedTaskValue,
isMakeup,
maxCount,
maxFileSizeMb,
canSubmit,
setMaxFileSizeMbMap,
beforeRead,
afterRead,
onDelete,
delItem,
onSubmit,
switchType,
initEditData,
gratitudeCount,
gratitudeFormList
} = useCheckin()
// 动态字段文字
const dynamicFieldText = ref('感恩')
// 任务详情数据
const taskDetail = ref({})
const maxFileSizeBytes = computed(() => {
const size = Number(maxFileSizeMb.value || 0)
if (!Number.isFinite(size) || size <= 0) return 20 * 1024 * 1024
return Math.floor(size * 1024 * 1024)
})
// 显示的作业描述
const displayTaskNote = computed(() => {
const selected_subtask_id = selectedTaskValue.value?.[0]
if (selected_subtask_id) {
const option = taskOptions.value.find(o => o.value === selected_subtask_id)
return option?.note || taskDetail.value?.note || ''
}
return taskDetail.value?.note || ''
})
// 打卡类型
const taskType = computed(() => route.query.task_type)
// 作业选择相关
const showTaskPicker = ref(false)
const taskOptions = ref([])
// 上次打卡的感恩表单数据
const lastUsedTargetList = ref([])
const fetchTargetList = async (subtask_id) => {
const { code, data } = await reuseGratitudeFormAPI({ subtask_id })
if (code === 1) {
targetList.value = data.gratitude_form_list || []
lastUsedTargetList.value = data.last_used_list || []
// 自动选中上次使用的对象
if (lastUsedTargetList.value.length > 0) {
// 找出 lastUsedTargetList 中存在于 targetList 的项(并获取 targetList 中的完整对象引用)
const validTargets = []
lastUsedTargetList.value.forEach(lastItem => {
const targetItem = targetList.value.find(t =>
(lastItem.id && t.id && t.id == lastItem.id) ||
(!lastItem.id && lastItem.name === t.name)
)
if (targetItem) {
// 标记为已确认,避免再次弹出确认框
targetItem.has_confirmed = true
validTargets.push(targetItem)
}
})
// 将这些项加入 selectedTargets(去重)
validTargets.forEach(item => {
const exists = selectedTargets.value.some(t =>
(item.id && t.id && t.id == item.id) ||
(!item.id && t.name === item.name)
)
if (!exists) {
selectedTargets.value.push(item)
}
})
}
}
}
// 动态表单字段 (默认值,实际会根据选择的作业动态更新)
const dynamicFormFields = ref([])
const personType = ref('') // 动态表单字段中的person_type
/**
* 更新动态表单字段
* @description 根据选中的作业选项更新动态表单字段配置
* @param {Object} option - 选中的作业选项
*/
const updateDynamicFormFields = (option) => {
if (option.field_list && Array.isArray(option.field_list)) {
// 处理动态表单字段
dynamicFormFields.value = option.field_list.map(field => {
return {
id: field.field || field.field_name || field.name || field.id, // 兼容多种字段名
label: field.label || '未命名',
type: field.type || 'text', // 默认类型,如果后端有类型字段可替换
required: true // 默认必填,如果后端有必填字段可替换
}
})
// 确保如果有city字段,类型为textarea
const cityField = dynamicFormFields.value.find(f => f.id === 'city')
if (cityField) {
cityField.type = 'textarea'
}
// 确保如果有unit字段,类型为textarea
const unitField = dynamicFormFields.value.find(f => f.id === 'unit')
if (unitField) {
unitField.type = 'textarea'
}
} else {
// 如果没有配置字段,使用默认字段
dynamicFormFields.value = [
{ id: 'name', label: '姓名', type: 'text', required: true },
{ id: 'city', label: '城市', type: 'textarea', required: true },
{ id: 'unit', label: '单位', type: 'textarea', required: true },
]
}
}
/**
* 确认作业选择
* @description 处理作业选择器的确认事件,更新相关状态
* @param {Object} param0 - 选择器返回对象
* @param {Array} param0.selectedOptions - 选中的选项数组
*/
const onConfirmTask = async ({ selectedOptions }) => {
const option = selectedOptions[0]
selectedTaskText.value = option.text
selectedTaskValue.value = [option.value]
isMakeup.value = !!option.is_makeup
showTaskPicker.value = false
personType.value = option.person_type
// 更新动态表单字段
updateDynamicFormFields(option)
// 更新附件类型选项
if (option.attachment_type) {
updateAttachmentTypeOptions(option.attachment_type)
} else {
// 如果小作业没有配置附件类型,尝试使用大作业的默认配置
updateAttachmentTypeOptions(taskDetail.value.attachment_type)
}
// 如果是计数打卡,根据选中的作业ID查询计数对象
if (taskType.value === 'count') {
// 切换作业时,清空之前选中的对象,避免混淆
selectedTargets.value = []
await fetchTargetList(selectedTaskValue.value[0])
}
}
// 监听作业选择变化, 当选中的作业ID变化时, 查询对应的计数对象
// watch(selectedTaskValue, async (newVal) => {
// if (taskType.value === 'count' && newVal && newVal.length > 0) {
// // fetchTargetList(newVal[0])
// console.warn('选中的作业ID:', newVal[0]);
// }
// })
// 计数打卡相关逻辑
const countValue = ref(1)
const selectedTargets = ref([])
// Mock 老师数据
const targetList = ref([])
const showAddTargetDialog = ref(false)
const editingTarget = ref(null)
const isConfirmMode = ref(false) // 是否为确认模式(首次点击选中)
const toggleTarget = (item) => {
// 优先使用id匹配,如果id不存在,则使用name匹配
const index = selectedTargets.value.findIndex(t => (item.id ? t.id === item.id : t.name === item.name))
if (index > -1) {
// 取消选中
selectedTargets.value.splice(index, 1)
} else {
// 选中逻辑:如果是第一次选中(未确认过),则弹出确认框
if (!item.has_confirmed) {
editingTarget.value = item
isConfirmMode.value = true
showAddTargetDialog.value = true
} else {
// 已确认过,直接选中
selectedTargets.value.push(item)
}
}
}
/**
* 打开新增计数对象弹窗
* @description 重置编辑状态并显示弹窗
*/
const openAddTargetDialog = () => {
editingTarget.value = null; // 重置编辑对象
isConfirmMode.value = false;
showAddTargetDialog.value = true;
}
/**
* 确认添加/编辑计数对象
* @description 处理弹窗确认事件,更新本地列表和选中状态
* @param {Array} formFields - 表单字段数组,包含字段ID和值
*/
const confirmAddTarget = async (formFields) => {
// 将表单字段数组转换为对象
const formData = formFields.reduce((acc, field) => {
if (field.id) {
acc[field.id] = field.value
}
return acc
}, {})
if (editingTarget.value) {
// 编辑模式或确认模式
const index = targetList.value.findIndex(t => t === editingTarget.value)
if (index > -1) {
// 更新对象 (使用 Object.assign 保持引用)
Object.assign(targetList.value[index], formData)
if (isConfirmMode.value) {
targetList.value[index].has_confirmed = true // 标记为已确认
}
// 检查是否在选中列表中
const selectedIndex = selectedTargets.value.findIndex(t =>
(editingTarget.value.id && t.id && t.id == editingTarget.value.id) ||
(!editingTarget.value.id && t.name === editingTarget.value.name)
)
// 如果是确认模式,确认后自动加入选中列表
if (isConfirmMode.value && selectedIndex === -1) {
selectedTargets.value.push(targetList.value[index])
}
showToast(isConfirmMode.value ? '确认成功' : '修改成功')
}
} else {
// 新增成功,更新本地列表
const newTarget = {
...formData,
has_confirmed: true // 新增的对象默认已确认
}
targetList.value.push(newTarget)
// 默认勾选新增的对象
selectedTargets.value.push(newTarget)
showToast('新增成功')
}
showAddTargetDialog.value = false;
}
/**
* 处理计数对象编辑
* @description 打开弹窗并填充当前对象数据进行编辑
* @param {Object} item - 待编辑的计数对象
*/
const handleTargetEdit = (item) => {
editingTarget.value = item
isConfirmMode.value = false // 明确设置为非确认模式
showAddTargetDialog.value = true
}
/**
* 处理计数对象删除
* @description 从本地列表和选中列表中移除对象(暂未调用后端接口)
* @param {Object} item - 待删除的计数对象
*/
const handleTargetDelete = async (item) => {
// 屏蔽删除功能, 那个接口也是不存在的
// const { code } = await gratitudeDeleteAPI({ id: item.id })
// if (code === 1) {
// // 删除成功,更新本地列表
// const targetIndex = targetList.value.findIndex(t => t.id === item.id)
// if (targetIndex > -1) {
// targetList.value.splice(targetIndex, 1)
// }
// // 从选中列表中也删除
// const selectedIndex = selectedTargets.value.findIndex(t => t.id === item.id)
// if (selectedIndex > -1) {
// selectedTargets.value.splice(selectedIndex, 1)
// }
// showToast('删除成功')
// }
}
/**
* 是否禁用提交按钮
* @description 根据打卡类型(计数/普通)和必填项(文本/文件/选中对象)判断是否可提交
* @returns {boolean}
*/
const isSubmitDisabled = computed(() => {
// 1. 校验作业选择
if (!selectedTaskValue.value || selectedTaskValue.value.length === 0) return true
// 2. 计数打卡特定校验
if (taskType.value === 'count') {
// 必须选择至少一个对象
if (selectedTargets.value.length === 0) return true
// 次数必须大于0
if (!countValue.value || countValue.value <= 0) return true
return false
}
// 3. 普通打卡校验
if (activeType.value === 'text') {
// 文本打卡:必须填写内容且长度不少于10个字符
return !message.value.trim() || message.value.trim().length < 10
} else {
// 其他类型:必须有文件
return fileList.value.length === 0
}
})
/**
* 提交打卡
* @description 校验表单数据(作业选择、计数对象、必填项等),构建提交数据,调用 useCheckin 的 onSubmit 方法
* @returns {Promise<void>}
*/
const handleSubmit = async () => {
// 计数打卡校验
if (taskType.value === 'count') {
if (selectedTaskValue.value.length === 0) {
const taskText = taskOptions.value.find(t => t.value === selectedTaskValue.value[0])?.text || '作业'
showToast(`请选择${taskText}`)
return
}
if (selectedTargets.value.length === 0) {
const targetText = dynamicFieldText.value || '对象'
showToast(`请选择${targetText}`)
return
}
}
const extraData = {
subtask_id: selectedTaskValue.value.length > 0 ? selectedTaskValue.value[0] : ''
}
// 如果是计数打卡,添加选中的计数对象列表, 并添加次数
if (taskType.value === 'count') {
extraData.gratitude_form_list = selectedTargets.value
extraData.gratitude_count = countValue.value
}
await onSubmit(extraData)
}
// 作品类型选项
const attachmentTypeOptions = ref([])
// 是否为编辑模式
const isEditMode = computed(() => route.query.status === 'edit')
// 预览相关变量
const audioShow = ref(false)
const audioTitle = ref('')
const audioUrl = ref('')
const videoShow = ref(false)
const videoTitle = ref('')
const videoUrl = ref('')
const videoCover = ref('')
const isVideoPlaying = ref(false)
const videoPlayerRef = ref(null)
const imageShow = ref(false)
const imageList = ref([])
const imageIndex = ref(0)
/**
* 返回上一页
*/
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,.flac,.ogg,.wma,.m4a'
}
return acceptMap[activeType.value] || '*'
}
/**
* 获取上传提示文本
* @returns {string} 提示文本
*/
const getUploadTips = () => {
const tipsMap = {
'image': '支持格式:.jpg/.jpeg/.png',
'video': '支持格式:视频文件',
'audio': '支持格式:.mp3/.wav/.aac/.flac/.ogg/.wma/.m4a'
}
return tipsMap[activeType.value] || ''
}
/**
* 获取任务详情
* @param {string} month - 月份
*/
const getTaskDetail = async (month) => {
const { code, data } = await getTaskDetailAPI({ i: route.query.task_id, month })
if (code === 1) {
taskDetail.value = data
}
}
/**
* 更新附件类型选项
* @param {Array|Object} attachmentType - 附件类型数据
*/
const updateAttachmentTypeOptions = (attachmentType) => {
const { options, upload_size_limit_mb_map } = normalizeAttachmentTypeConfig(attachmentType)
attachmentTypeOptions.value = options
// 设置最大文件大小映射
if (upload_size_limit_mb_map) {
setMaxFileSizeMbMap(upload_size_limit_mb_map)
}
// 如果是计数打卡(count),过滤掉文本(text)类型
if (taskType.value === 'count') {
attachmentTypeOptions.value = attachmentTypeOptions.value.filter(option => option.key !== 'text')
}
// 设置默认选中类型(非计数打卡模式下)
if (taskType.value !== 'count' && attachmentTypeOptions.value.length > 0) {
// 如果当前选中的类型不在新的选项中,则重置为第一个
if (!activeType.value || !attachmentTypeOptions.value.find(o => o.key === activeType.value)) {
activeType.value = attachmentTypeOptions.value[0].key
}
}
}
/**
* van-uploader点击预览事件处理
* @param {Object} file - 文件对象
* @param {Object} detail - 详细信息
*/
const onClickPreview = (file, detail) => {
console.log('onClickPreview - file:', file)
console.log('onClickPreview - detail:', detail)
console.log('file对象的所有属性:', Object.keys(file))
const fileName = file.name || file.file?.name || ''
// 尝试多种方式获取文件URL
let fileUrl = ''
// 方式1: 直接从file对象获取
if (file.url) {
fileUrl = file.url
console.log('从file.url获取URL:', fileUrl)
}
// 方式2: 从file.content获取
else if (file.content) {
fileUrl = file.content
console.log('从file.content获取URL:', fileUrl)
}
// 方式3: 从file.objectURL获取
else if (file.objectURL) {
fileUrl = file.objectURL
console.log('从file.objectURL获取URL:', fileUrl)
}
// 方式4: 从file.file获取
else if (file.file) {
if (file.file.url) {
fileUrl = file.file.url
console.log('从file.file.url获取URL:', fileUrl)
} else {
// 创建临时URL
try {
fileUrl = URL.createObjectURL(file.file)
console.log('通过URL.createObjectURL创建URL:', fileUrl)
} catch (error) {
console.error('创建ObjectURL失败:', error)
}
}
}
// 方式5: 检查是否有其他可能的URL字段
else {
const possibleUrlFields = ['src', 'path', 'value', 'href', 'link']
for (const field of possibleUrlFields) {
if (file[field]) {
fileUrl = file[field]
console.log(`从file.${field}获取URL:`, fileUrl)
break
}
}
}
console.log('最终提取的文件名:', fileName)
console.log('最终提取的文件URL:', fileUrl)
if (!fileUrl) {
console.warn('文件URL不存在,文件对象完整结构:', JSON.stringify(file, null, 2))
showToast('无法获取文件URL,请检查文件是否上传成功')
return
}
// 根据打卡类型或文件扩展名判断文件类型
if (activeType.value === 'audio' || isAudioFile(fileName)) {
console.log('准备播放音频:', fileName, fileUrl)
showAudio(fileName, fileUrl)
} else if (activeType.value === 'video' || isVideoFile(fileName)) {
console.log('准备播放视频:', fileName, fileUrl)
showVideo(fileName, fileUrl)
} else if (activeType.value === 'image' || isImageFile(fileName)) {
console.log('图片预览由van-uploader组件处理,跳过文件列表点击预览')
// 图片预览由van-uploader的@click-preview事件处理,避免重复弹出
return
} else {
console.log('该文件类型不支持预览,文件名:', fileName, '类型:', activeType.value)
showToast('该文件类型不支持预览')
}
}
/**
* 预览文件
* @param {Object} item - 文件项
*/
// const previewFile = (item) => {
// console.log('previewFile - item:', item)
// console.log('previewFile - item对象的所有属性:', Object.keys(item))
// const fileName = item.name || item.file?.name || ''
// // 尝试多种方式获取文件URL
// let fileUrl = ''
// // 方式1: 直接从item对象获取
// if (item.url) {
// fileUrl = item.url
// console.log('从item.url获取URL:', fileUrl)
// }
// // 方式2: 从item.value获取
// else if (item.value) {
// fileUrl = item.value
// console.log('从item.value获取URL:', fileUrl)
// }
// // 方式3: 从item.content获取
// else if (item.content) {
// fileUrl = item.content
// console.log('从item.content获取URL:', fileUrl)
// }
// // 方式4: 从item.objectURL获取
// else if (item.objectURL) {
// fileUrl = item.objectURL
// console.log('从item.objectURL获取URL:', fileUrl)
// }
// // 方式5: 从item.file获取
// else if (item.file) {
// if (item.file.url) {
// fileUrl = item.file.url
// console.log('从item.file.url获取URL:', fileUrl)
// } else {
// // 创建临时URL
// try {
// fileUrl = URL.createObjectURL(item.file)
// console.log('通过URL.createObjectURL创建URL:', fileUrl)
// } catch (error) {
// console.error('创建ObjectURL失败:', error)
// }
// }
// }
// // 方式6: 检查是否有其他可能的URL字段
// else {
// const possibleUrlFields = ['src', 'path', 'href', 'link', 'downloadUrl', 'previewUrl']
// for (const field of possibleUrlFields) {
// if (item[field]) {
// fileUrl = item[field]
// console.log(`从item.${field}获取URL:`, fileUrl)
// break
// }
// }
// }
// console.log('最终提取的文件名:', fileName)
// console.log('最终提取的文件URL:', fileUrl)
// if (!fileUrl) {
// console.warn('文件URL不存在,文件对象完整结构:', JSON.stringify(item, null, 2))
// showToast('无法获取文件URL,请检查文件是否上传成功')
// return
// }
// // 根据打卡类型或文件扩展名判断文件类型
// if (activeType.value === 'audio' || isAudioFile(fileName)) {
// console.log('准备播放音频:', fileName, fileUrl)
// showAudio(fileName, fileUrl)
// } else if (activeType.value === 'video' || isVideoFile(fileName)) {
// console.log('准备播放视频:', fileName, fileUrl)
// showVideo(fileName, fileUrl)
// } else if (activeType.value === 'image' || isImageFile(fileName)) {
// console.log('准备预览图片:', fileName, fileUrl)
// showImage(fileUrl)
// } else {
// console.log('该文件类型不支持预览,文件名:', fileName, '打卡类型:', activeType.value)
// showToast('该文件类型不支持预览')
// }
// }
/**
* 判断是否为音频文件
* @param {string} fileName - 文件名
* @returns {boolean}
*/
const isAudioFile = (fileName) => {
const audioExtensions = ['.mp3', '.wav', '.ogg', '.aac', '.m4a', '.flac', '.wma']
return audioExtensions.some(ext => fileName.toLowerCase().includes(ext))
}
/**
* 判断是否为视频文件
* @param {string} fileName - 文件名
* @returns {boolean}
*/
const isVideoFile = (fileName) => {
const videoExtensions = ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.webm', '.mkv']
return videoExtensions.some(ext => fileName.toLowerCase().includes(ext))
}
/**
* 判断是否为图片文件
* @param {string} fileName - 文件名
* @returns {boolean}
*/
const isImageFile = (fileName) => {
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg']
return imageExtensions.some(ext => fileName.toLowerCase().includes(ext))
}
/**
* 显示音频播放器
* @param {string} title - 音频标题
* @param {string} url - 音频URL
*/
const showAudio = (title, url) => {
audioTitle.value = title
audioUrl.value = url
audioShow.value = true
}
/**
* 显示视频播放器
* @param {string} title - 视频标题
* @param {string} url - 视频URL
* @param {string} cover - 视频封面URL(可选)
*/
const showVideo = (title, url, cover = '') => {
videoTitle.value = title
videoUrl.value = url
videoCover.value = cover
videoShow.value = true
isVideoPlaying.value = false // 重置播放状态
}
/**
* 显示图片预览
* @param {string} url - 图片URL
* @param {number} index - 图片索引(可选)
*/
const showImage = (url, index = 0) => {
imageList.value = [url]
imageIndex.value = index
imageShow.value = true
}
/**
* 开始播放视频
*/
const startVideoPlay = async () => {
isVideoPlaying.value = true
await nextTick()
if (videoPlayerRef.value) {
videoPlayerRef.value.play()
}
}
/**
* 处理视频播放事件
*/
const handleVideoPlay = () => {
isVideoPlaying.value = true
}
/**
* 处理视频暂停事件
*/
const handleVideoPause = () => {
// 保持视频播放器可见,只在初始状态显示封面
}
/**
* 停止视频播放
*/
const stopVideoPlay = () => {
if (videoPlayerRef.value && typeof videoPlayerRef.value.pause === 'function') {
videoPlayerRef.value.pause()
// 重置视频播放进度到开始位置
const player = videoPlayerRef.value.getPlayer()
if (player && typeof player.currentTime === 'function') {
player.currentTime(0)
}
}
isVideoPlaying.value = false
}
/**
* 页面挂载时的初始化逻辑
*/
onMounted(async () => {
// 获取任务详情
const current_date = route.query.date;
if (current_date) {
getTaskDetail(dayjs(current_date).format('YYYY-MM'));
} else {
getTaskDetail(dayjs().format('YYYY-MM'));
}
// 初始化选中的子任务ID
selectedTaskValue.value = route.query.subtask_id ? [+route.query.subtask_id] : []
// 获取小作业列表
const subtask_list = await getSubtaskListAPI({ task_id: route.query.task_id, date: current_date })
if (subtask_list.code === 1) {
taskOptions.value = [...subtask_list.data.map(item => ({
text: item.is_makeup ? '补卡:' + item.title : item.title,
value: item.id,
note: item.note, // 作业描述
is_makeup: item.is_makeup, // 是否为补录
field_list: item.field_list, // 动态字段列表
person_type: item.person_type, // 打卡对象类型
attachment_type: item.attachment_type, // 附件类型
}))
]
}
// 如果有默认选中值,且非编辑模式(编辑模式下由initEditData统一处理,避免逻辑重复)
if (selectedTaskValue.value.length > 0 && !isEditMode.value) {
const option = taskOptions.value.find(o => o.value === selectedTaskValue.value[0])
if (option) {
selectedTaskText.value = option.text
isMakeup.value = !!option.is_makeup
personType.value = option.person_type
// 初始化动态表单字段
updateDynamicFormFields(option)
// 更新附件类型选项
if (option.attachment_type) {
updateAttachmentTypeOptions(option.attachment_type)
} else {
updateAttachmentTypeOptions(taskDetail.value.attachment_type)
}
}
// 如果是计数打卡,根据选中的作业ID查询计数对象
if (taskType.value === 'count') {
await fetchTargetList(selectedTaskValue.value[0])
}
}
// 初始化编辑数据
await initEditData(taskOptions.value, {
onTaskFound: (option) => {
updateDynamicFormFields(option)
// 更新附件类型选项
if (option.attachment_type) {
updateAttachmentTypeOptions(option.attachment_type)
} else {
updateAttachmentTypeOptions(taskDetail.value.attachment_type)
}
},
ensureTargetList: async (id) => {
if (targetList.value.length === 0) {
await fetchTargetList(id)
}
},
// setTargets: (list) => {
// // 只有当 list 不为空时才覆盖,避免覆盖掉 fetchTargetList 中设置的默认选中项
// if (list && list.length > 0) {
// selectedTargets.value = list
// }
// },
setCount: (val) => {
countValue.value = val
}
})
})
</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;
overflow: hidden;
}
.description-text {
color: #666;
line-height: 1.6;
font-size: 0.95rem;
word-break: break-word;
overflow-wrap: break-word;
width: 100%;
box-sizing: border-box;
overflow: hidden;
:deep(*) {
max-width: 100% !important;
box-sizing: border-box;
}
:deep(img) {
max-width: 100% !important;
height: auto;
display: block;
}
:deep(p) {
margin: 0.5rem 0;
}
:deep(table) {
max-width: 100% !important;
border-collapse: collapse;
overflow-x: auto;
display: table;
width: 100%;
}
:deep(pre) {
max-width: 100% !important;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
}
// 富文本内容样式
// :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;
cursor: pointer;
padding: 0.5rem;
border-radius: 0.5rem;
transition: background-color 0.2s;
&:hover {
background-color: #f5f5f5;
}
}
.file-name {
flex: 1;
font-size: 0.9rem;
color: #333;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
word-wrap: break-word;
// 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>