hookehuyr

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

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