Quellcode durchsuchen

feat(student): add batch download function for assignments, add i18n texts and jszip dependency

1. 新增批量下载作业功能,使用jszip打包学生作业文件
2. 为中英港三语言包添加批量下载相关文案
3. 修复选择题详情弹窗相关逻辑问题
lsc vor 4 Wochen
Ursprung
Commit
be7bea99cd

+ 3 - 2
package-lock.json

@@ -21,6 +21,7 @@
         "hfmath": "^0.0.2",
         "html-to-image": "^1.11.13",
         "html2canvas": "^1.4.1",
+        "jszip": "^3.10.1",
         "katex": "^0.16.22",
         "lodash": "^4.17.21",
         "markdown-it": "^14.1.1",
@@ -4563,7 +4564,7 @@
     },
     "node_modules/jszip": {
       "version": "3.10.1",
-      "resolved": "https://registry.npmmirror.com/jszip/-/jszip-3.10.1.tgz",
+      "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
       "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
       "dependencies": {
         "lie": "~3.3.0",
@@ -10172,7 +10173,7 @@
     },
     "jszip": {
       "version": "3.10.1",
-      "resolved": "https://registry.npmmirror.com/jszip/-/jszip-3.10.1.tgz",
+      "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
       "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
       "requires": {
         "lie": "~3.3.0",

+ 1 - 0
package.json

@@ -30,6 +30,7 @@
     "hfmath": "^0.0.2",
     "html-to-image": "^1.11.13",
     "html2canvas": "^1.4.1",
+    "jszip": "^3.10.1",
     "katex": "^0.16.22",
     "lodash": "^4.17.21",
     "markdown-it": "^14.1.1",

+ 80 - 0
src/views/Student/components/choiceQuestionDetailDialog.vue

@@ -349,6 +349,10 @@
           <span v-if="props.unsubmittedStudents.length > 0" @click.stop="viewUnsubmittedStudents()">{{
             lang.ssViewSubmitStatus2 }}</span>
         </div>
+        <div class="downloadBtn" @click.stop="downloadAll" :class="{ disabled: downloadLoading }" v-if="props.roleType == 1">
+          <IconDownload />
+          <span>{{ downloadLoading ? lang.ssDownloadLoading : lang.ssBatchDownload }}</span>
+        </div>
         <div class="c_t15_content" v-show="!lookWorkData">
           <div class="c_t15_c_item" v-for="item in processedWorkArray" :key="item.id"
             @click.stop="item.content && item.content.fileList.length > 0 ? lookWork(item.id) : ''">
@@ -863,6 +867,9 @@ const echartsArea1 = ref<any>(null)
 // 查看的作业详细id
 const lookWorkDetail = ref<string>('')
 
+// 下载加载状态
+const downloadLoading = ref(false)
+
 // 查看作业详细的数据
 const lookWorkData = computed(() => {
   let _result = null
@@ -2289,6 +2296,63 @@ watch(
 )
 
 
+// 批量下载
+const downloadAll = async () => {
+  if (!processedWorkArray.value || processedWorkArray.value.length === 0) {
+    return
+  }
+  if (downloadLoading.value) {
+    return
+  }
+  // 设置加载状态
+  downloadLoading.value = true
+
+  try {
+    // 动态导入 JSZip
+    const JSZip = (await import('jszip')).default
+    const { saveAs } = await import('file-saver')
+
+    const zip = new JSZip()
+
+    // 遍历所有学生
+    for (const student of processedWorkArray.value) {
+      if (!student.content || !student.content.fileList || student.content.fileList.length === 0) {
+        continue
+      }
+
+      // 遍历学生的所有照片
+      for (let i = 0; i < student.content.fileList.length; i++) {
+        const file = student.content.fileList[i]
+        const fileName = student.content.fileList.length > 1
+          ? `${student.name}${String(i + 1).padStart(2, '0')}.jpg`
+          : `${student.name}.jpg`
+
+        try {
+          // 获取图片数据
+          const response = await fetch(file.url)
+          const blob = await response.blob()
+          zip.file(fileName, blob)
+        }
+        catch (error) {
+          console.error(`下载 ${fileName} 失败:`, error)
+        }
+      }
+    }
+
+    // 生成压缩包并下载
+    const content = await zip.generateAsync({ type: 'blob' })
+    saveAs(content, `${lang.ssBatchDownload}.zip`)
+  }
+  catch (error) {
+    console.error('批量下载失败:', error)
+  }
+  finally {
+    // 重置加载状态
+    downloadLoading.value = false
+  }
+}
+
+
 
 
 // 组件卸载时清理ECharts实例
@@ -3381,4 +3445,20 @@ onUnmounted(() => {
   min-width: 65px;
   justify-content: center;
 }
+
+.downloadBtn{
+  display: flex;
+  align-items: center;
+  gap: 5px;
+  font-weight: 300;
+  font-size: 14px;
+  color: rgba(0, 0, 0, 0.7);
+  cursor: pointer;
+  margin-left: auto;
+  border-radius: 5px;
+  border: solid 1px rgba(252, 207, 0, .7);
+  padding: .5rem 0.6rem;
+  min-width: 65px;
+  justify-content: center;
+}
 </style>

+ 8 - 0
src/views/Student/index.vue

@@ -3693,6 +3693,13 @@ const getMessages = (msgObj: any) => {
   // 获取是否展开结果数组
   if (props.type == '2' && msgObj.type === 'isResultArray' && msgObj.courseid === props.courseid) {
     isResultArray.value = msgObj.isResultArray || []
+    if (isResultArray.value.length > 0 ) {
+      const result = isResultArray.value[slideIndex.value]
+      console.log('是否展开结果数组:', result)
+      if (!result.can && choiceQuestionDetailDialogOpenList.value.includes(slideIndex.value)) {
+        openChoiceQuestionDetail2(slideIndex.value)
+      }
+    }
   }
 
   // 投屏
@@ -3726,6 +3733,7 @@ const openChoiceQuestionDetail = (index:number) => {
 // 打开作业查看详细
 const openChoiceQuestionDetail2 = (index:number) => {
   if (!choiceQuestionDetailDialogOpenList.value.includes(index)) {
+    // choiceQuestionDetailDialogOpenList.value.push(index)
   }
   else {
     choiceQuestionDetailDialogOpenList.value = choiceQuestionDetailDialogOpenList.value.filter(i => i !== index)

+ 3 - 1
src/views/lang/cn.json

@@ -920,5 +920,7 @@
   "ssCastScreen": "投屏",
   "ssExitCastScreen": "退出投屏",
   "ssPasteCode": "粘贴代码",
-  "ssEditWebpage": "修改网页"
+  "ssEditWebpage": "修改网页",
+  "ssDownloadLoading": "下载中...",
+  "ssBatchDownload": "批量下载"
 }

+ 3 - 1
src/views/lang/en.json

@@ -920,5 +920,7 @@
   "ssCastScreen": "Cast Screen",
   "ssExitCastScreen": "Exit Cast Screen",
   "ssPasteCode": "Paste Code",
-  "ssEditWebpage": "Edit Webpage"
+  "ssEditWebpage": "Edit Webpage",
+  "ssDownloadLoading": "Downloading...",
+  "ssBatchDownload": "Batch Download"
 }

+ 3 - 1
src/views/lang/hk.json

@@ -920,5 +920,7 @@
   "ssCastScreen": "投屏",
   "ssExitCastScreen": "退出投屏",
   "ssPasteCode": "粘貼代碼",
-  "ssEditWebpage": "修改網頁"
+  "ssEditWebpage": "修改網頁",
+  "ssDownloadLoading": "下載中...",
+  "ssBatchDownload": "批量下載"
 }