CheckinDetailPage.vue 32.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 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
<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.note" class="description-text" v-html="taskDetail.note">
                    </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"
                                @click-preview="onClickPreview"
                                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" @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 }}个文件,每个不超过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>

        <!-- 音频播放器弹窗 -->
        <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-show="isVideoPlaying"
                        ref="videoPlayerRef"
                        :video-url="videoUrl"
                        :video-id="videoTitle"
                        :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 } 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 AudioPlayer from '@/components/ui/AudioPlayer.vue'
import VideoPlayer from '@/components/ui/VideoPlayer.vue'
import { showToast } from 'vant'
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 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'
    }
    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>
        //     `
        // }
    }
}

/**
 * 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']
    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'));
    }

    // 获取作品类型数据
    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;
        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>