11wqe1 2 дней назад
Родитель
Сommit
42fc6cc52f
1 измененных файлов с 62 добавлено и 32 удалено
  1. 62 32
      src/components/main/courseSelect.vue

+ 62 - 32
src/components/main/courseSelect.vue

@@ -47,7 +47,9 @@
                 <!-- v-if="isupdateCourse" -->
                 <!-- v-if="isupdateCourse && item.courseType == '1'" -->
                 <el-popover v-if="isupdateCourse" placement="bottom" :width="210"
-                  trigger="click" :show-after="500" @hide="checked1 = false">
+                  trigger="click" :show-after="500"
+                  @show="openSelectAll(item.json.dataList)"
+                  @hide="checked1 = false">
                   <template #reference>
                     <img :src="DownloadImg" v-if="item.json.courseType == '2'" alt="">
                     <img :src="DownloadImg" v-else alt="" @click="getDate(item.json.dataId)">
@@ -56,7 +58,7 @@
                     <div>
                       <span>{{ lang.ssResList.replace(/\*/g, item.json.dataList.length) }}</span>
                       <el-checkbox style="position: relative;top: 0;left: 35px;height: 30px;" v-model="checked1"
-                        :label="lang.ssSelectAll" size="large" @click="checkedAll(item.json.dataId)" />
+                        :label="lang.ssSelectAll" size="large" @click="checkedAll(item.json.dataList)" />
                     </div>
                     <div v-if="item.json.dataList.length > 0">
                       <div class="div_hover" v-for="dataitem in item.json.dataList" :key="dataitem.dataId">
@@ -67,10 +69,10 @@
                           @click="downloadOne(dataitem.url, dataitem.name)">
                           <img :src="DownloadImg" alt="">
                         </span>
-                        <el-checkbox v-if="checked1" v-model="dataitem.checked" :label="lang.ssSelectAll" size="large" />
+                        <el-checkbox v-if="checked1" v-model="dataitem.checked" size="large" />
                       </div>
                       <el-button style="margin-top: 10px;" v-if="checked1"
-                        @click="DownloadProcessing()">{{ lang.ssBatchDown }}</el-button>
+                        @click="DownloadProcessing(item.json.dataList)">{{ lang.ssBatchDown }}</el-button>
                     </div>
                     <div v-else>
                       {{ lang.ssNoData }}
@@ -747,7 +749,7 @@ const getDate = async (id) => {
             const DatahapterData = dataChapterInfo.taskJson[k];
             for (let l = 0; l < DatahapterData.chapterData.length; l++) {
               const obj = DatahapterData.chapterData[l];
-              obj.checked = false;
+              obj.checked = true;
               dataList.push(obj);
             }
           }
@@ -790,7 +792,26 @@ const getUpdateCourse = async (dataList, id) => {
   getUpdateCourseId.value = id
 }
 
-const checkedAll = (id) => {
+const openSelectAll = (dataList) => {
+  checked1.value = true
+  dataList?.forEach(item => {
+    item.checked = true
+  })
+}
+
+const setListChecked = (dataList, checked) => {
+  dataList?.forEach(item => {
+    item.checked = checked
+  })
+}
+
+const checkedAll = (idOrList) => {
+  if (Array.isArray(idOrList)) {
+    setListChecked(idOrList, !checked1.value)
+    return
+  }
+
+  const id = idOrList
   let data = currentData.value
   if (volumes.value) {
     data.shang.map(x => {
@@ -859,7 +880,40 @@ const downloadOne = async (url, fileName) => {
     window.open(url, '_blank');
   }
 }
-const DownloadProcessing = async () => {
+const downloadCheckedFiles = async (urls) => {
+  try {
+    console.log("urls", [user.user.userid, getUpdateCourseId.value, '4', urls.length])
+    top.U.A.Request("https://pbl.cocorobo.cn/api/pbl/addOperationTimeT", [user.user.userid, getUpdateCourseId.value, '4', urls.length], function (res) {
+      console.log(res, '11111111111')
+    }, [], { "type": "POST", "withCredentials": true });
+  } catch (error) {
+    console.log(error);
+  }
+
+  for (let i = 0; i < urls.length; i++) {
+    fetch(urls[i].url)
+      .then(response => response.blob())  // 获取文件数据流
+      .then(blob => {
+        const url = window.URL.createObjectURL(blob);  // 生成文件在浏览器中的链接
+        const a = document.createElement('a');
+        a.href = url;
+        a.download = urls[i].name;  // 文件名
+        a.style.display = 'none';
+        document.body.appendChild(a);
+        a.click();
+        document.body.removeChild(a);
+        window.URL.revokeObjectURL(url);  // 清除文件链接
+      })
+      .catch(console.error);
+  }
+}
+
+const DownloadProcessing = async (dataList) => {
+  if (Array.isArray(dataList)) {
+    await downloadCheckedFiles(dataList.filter(m => m.checked))
+    return
+  }
+
   let data = currentData.value
   let urls = []
   if (volumes.value) {
@@ -886,31 +940,7 @@ const DownloadProcessing = async () => {
     })
   }
 
-  try {
-    console.log("urls", [user.user.userid, getUpdateCourseId.value, '4', urls.length])
-    top.U.A.Request("https://pbl.cocorobo.cn/api/pbl/addOperationTimeT", [user.user.userid, getUpdateCourseId.value, '4', urls.length], function (res) {
-      console.log(res, '11111111111')
-    }, [], { "type": "POST", "withCredentials": true });
-  } catch (error) {
-    console.log(error);
-  }
-
-  for (let i = 0; i < urls.length; i++) {
-    fetch(urls[i].url)
-      .then(response => response.blob())  // 获取文件数据流
-      .then(blob => {
-        const url = window.URL.createObjectURL(blob);  // 生成文件在浏览器中的链接
-        const a = document.createElement('a');
-        a.href = url;
-        a.download = urls[i].name;  // 文件名
-        a.style.display = 'none';
-        document.body.appendChild(a);
-        a.click();
-        document.body.removeChild(a);
-        window.URL.revokeObjectURL(url);  // 清除文件链接
-      })
-      .catch(console.error);
-  }
+  await downloadCheckedFiles(urls)
 }