hookehuyr

refactor(attachment): 使用工具函数规范化附件类型显示逻辑

在CollapsibleCalendar和taskHomePage组件中,将硬编码的附件类型映射逻辑替换为统一的工具函数normalizeAttachmentTypeConfig,提高代码复用性和可维护性
...@@ -121,6 +121,7 @@ ...@@ -121,6 +121,7 @@
121 import { ref, computed, watch, onMounted } from 'vue' 121 import { ref, computed, watch, onMounted } from 'vue'
122 import { useScroll } from '@vueuse/core' 122 import { useScroll } from '@vueuse/core'
123 import dayjs from 'dayjs' 123 import dayjs from 'dayjs'
124 +import { normalizeAttachmentTypeConfig } from '@/utils/tools'
124 125
125 // Props定义 126 // Props定义
126 const props = defineProps({ 127 const props = defineProps({
...@@ -243,14 +244,10 @@ const formattedRules = computed(() => { ...@@ -243,14 +244,10 @@ const formattedRules = computed(() => {
243 const cycleText = cycleMap[data.cycle] || data.cycle || '每日' 244 const cycleText = cycleMap[data.cycle] || data.cycle || '每日'
244 245
245 let attachmentText = '文本' 246 let attachmentText = '文本'
246 - if (Array.isArray(data.attachment_type)) { 247 + if (Array.isArray(data.attachment_type) || (data.attachment_type && typeof data.attachment_type === 'object')) {
247 - const typeMap = { 248 + const { options } = normalizeAttachmentTypeConfig(data.attachment_type)
248 - 'text': '文本', 249 + const text = options.map(item => item.value || item.key).join('/')
249 - 'image': '图片', 250 + attachmentText = text || '文本'
250 - 'video': '视频',
251 - 'audio': '音频'
252 - }
253 - attachmentText = data.attachment_type.map(t => typeMap[t] || t).join('/')
254 } else if (data.attachment_type) { 251 } else if (data.attachment_type) {
255 attachmentText = data.attachment_type 252 attachmentText = data.attachment_type
256 } 253 }
......
1 <!-- 1 <!--
2 * @Date: 2025-11-19 21:00:00 2 * @Date: 2025-11-19 21:00:00
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-12-18 21:54:18 4 + * @LastEditTime: 2026-01-21 13:56:29
5 * @FilePath: /mlaj/src/views/teacher/taskHomePage.vue 5 * @FilePath: /mlaj/src/views/teacher/taskHomePage.vue
6 * @Description: 教师端作业主页(头部介绍、统计、日历与学生完成情况) 6 * @Description: 教师端作业主页(头部介绍、统计、日历与学生完成情况)
7 --> 7 -->
...@@ -131,6 +131,7 @@ import { useTitle } from '@vueuse/core' ...@@ -131,6 +131,7 @@ import { useTitle } from '@vueuse/core'
131 import checkCorner from '@/assets/images/dui.png' 131 import checkCorner from '@/assets/images/dui.png'
132 import { getTeacherTaskDetailAPI } from '@/api/teacher' 132 import { getTeacherTaskDetailAPI } from '@/api/teacher'
133 import { getCheckinTeacherCheckedDatesAPI } from '@/api/checkin' 133 import { getCheckinTeacherCheckedDatesAPI } from '@/api/checkin'
134 +import { normalizeAttachmentTypeConfig } from '@/utils/tools'
134 import dayjs from 'dayjs' 135 import dayjs from 'dayjs'
135 import { showToast } from 'vant' 136 import { showToast } from 'vant'
136 137
...@@ -314,14 +315,10 @@ const formatTaskDetails = (data) => { ...@@ -314,14 +315,10 @@ const formatTaskDetails = (data) => {
314 const cycleText = cycleMap[data.cycle] || data.cycle || '每日' 315 const cycleText = cycleMap[data.cycle] || data.cycle || '每日'
315 316
316 let attachmentText = '文本' 317 let attachmentText = '文本'
317 - if (Array.isArray(data.attachment_type)) { 318 + if (Array.isArray(data.attachment_type) || (data.attachment_type && typeof data.attachment_type === 'object')) {
318 - const typeMap = { 319 + const { options } = normalizeAttachmentTypeConfig(data.attachment_type)
319 - 'text': '文本', 320 + const text = options.map(item => item.value || item.key).join('/')
320 - 'image': '图片', 321 + attachmentText = text || '文本'
321 - 'video': '视频',
322 - 'audio': '音频'
323 - }
324 - attachmentText = data.attachment_type.map(t => typeMap[t] || t).join('/')
325 } else if (data.attachment_type) { 322 } else if (data.attachment_type) {
326 attachmentText = data.attachment_type 323 attachmentText = data.attachment_type
327 } 324 }
......