From 11433c56279d667305b0b627e205000851bc0456 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期二, 25 六月 2024 15:34:55 +0800
Subject: [PATCH] 新增pdf预览功能

---
 src/views/readerPages/webHome.vue |  409 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 380 insertions(+), 29 deletions(-)

diff --git a/src/views/readerPages/webHome.vue b/src/views/readerPages/webHome.vue
index b8b0ceb..34bd1d5 100644
--- a/src/views/readerPages/webHome.vue
+++ b/src/views/readerPages/webHome.vue
@@ -117,20 +117,46 @@
               <div>鏁欏笀璧勬簮</div>
               <div :class="resourceType == 'teacher' ? 'text' : 'line'"></div>
             </div>
+            <hr class="hr" />
+            <div class="tabItem hover" @click="selectResourceType('collect')">
+              <div>鏀惰棌璧勬簮</div>
+              <div :class="resourceType == 'collect' ? 'text' : 'line'"></div>
+            </div>
           </div>
           <div v-if="activeMenu == '棰樺簱'" class="resourceTab">
-            <div class="tabItem hover" @click="selectExercisesType('exercises')" v-if="bookConfig.textbookComponents.indexOf('3D3B4F55') > -1">
+            <div
+              class="tabItem hover"
+              @click="selectExercisesType('exercises')"
+              v-if="bookConfig.textbookComponents.indexOf('3D3B4F55') > -1"
+            >
               <div>涔犻</div>
               <div :class="exercisesType == 'exercises' ? 'text' : 'line'"></div>
             </div>
-            <hr class="hr" v-if="bookConfig.textbookComponents.indexOf('AFC1A288') > -1"/>
-            <div class="tabItem hover" @click="selectExercisesType('wrong')" v-if="bookConfig.textbookComponents.indexOf('AFC1A288') > -1">
+            <hr class="hr" v-if="bookConfig.textbookComponents.indexOf('A4821F71') > -1" />
+            <div
+              class="tabItem hover"
+              @click="selectExercisesType('additional')"
+              v-if="bookConfig.textbookComponents.indexOf('A4821F71') > -1"
+            >
+              <div>闄勫姞棰�</div>
+              <div :class="exercisesType == 'additional' ? 'text' : 'line'"></div>
+            </div>
+            <hr class="hr" v-if="bookConfig.textbookComponents.indexOf('AFC1A288') > -1" />
+            <div
+              class="tabItem hover"
+              @click="selectExercisesType('wrong')"
+              v-if="bookConfig.textbookComponents.indexOf('AFC1A288') > -1"
+            >
               <div>閿欓鏈�</div>
               <div :class="exercisesType == 'wrong' ? 'text' : 'line'"></div>
             </div>
-            <hr class="hr" v-if="bookConfig.textbookComponents.indexOf('A434F2C0') > -1"/>
-            <div class="tabItem hover" @click="selectExercisesType('collection')" v-if="bookConfig.textbookComponents.indexOf('A434F2C0') > -1">
-              <div>鏀惰棌</div>
+            <hr class="hr" v-if="bookConfig.textbookComponents.indexOf('A434F2C0') > -1" />
+            <div
+              class="tabItem hover"
+              @click="selectExercisesType('collection')"
+              v-if="bookConfig.textbookComponents.indexOf('A434F2C0') > -1"
+            >
+              <div>鏀惰棌澶�</div>
               <div :class="exercisesType == 'collection' ? 'text' : 'line'"></div>
             </div>
           </div>
@@ -396,6 +422,12 @@
                             "
                             ><Download
                           /></el-icon>
+                          <!-- 鏀惰棌鎸夐挳 -->
+                           <img 
+                            :src="collectResourceList.findIndex(citem => citem.id == item.id) > -1 ? isHeart : heart  " 
+                            class="icon hover" 
+                            style="width: 15px;" 
+                            @click="handleCollectResource(item.id,item.md5 ? item.md5 : '',item.resourcePath ? item.resourcePath : '',item.resourceType,item.resourceType == '瑙嗛' || '闊抽' ? 'bits' : 'json',item.resourceName)" />
                         </div>
                       </div>
                     </div>
@@ -461,7 +493,10 @@
           </div>
         </div>
         <div class="questionList" v-if="activeMenu == '棰樺簱'" v-loading="listLoading">
-          <div class="resourceSearchBox">
+          <div
+            class="resourceSearchBox"
+            v-if="exercisesType !== 'collection' && exercisesType !== 'wrong'"
+          >
             <div class="inputBox">
               <el-input
                 class="custom-input"
@@ -482,14 +517,20 @@
               <div v-for="(item, index) in questionList" :key="index" class="reMarkItem">
                 <div
                   class="questionCon hover"
-                  @click="JumpPosition(item)"
+                  @click="clickQuestion(exercisesType, item)"
                   :title="item.resourceName"
                 >
                   {{ item.resourceName }}
                 </div>
               </div>
             </div>
-            <div v-else>
+            <div
+              v-if="
+                questionList.length == 0 &&
+                exercisesType !== 'collection' &&
+                exercisesType !== 'wrong'
+              "
+            >
               <el-empty :image-size="60" description="鏆傛棤鏁版嵁" />
             </div>
           </div>
@@ -1177,17 +1218,34 @@
       <newWord :resourceUrl="resourceUrl" />
     </div>
   </el-dialog>
-  <el-dialog title="閿欓鏈�" align-center v-model="wrongQuestionVisble" width="800" class="myDialogs">
+  <el-dialog
+    title="閿欓鏈�"
+    align-center
+    v-model="wrongQuestionVisble"
+    width="800"
+    class="myDialogs"
+  >
     <div class="wendabox">
-      <wrongQuestion  />
+      <wrongQuestion />
     </div>
   </el-dialog>
+  <!-- 绛旈鍣� -->
+  <examination
+    ref="examinationRef"
+    :activeBook="bookConfig"
+    :info="examinationData.info"
+    :type="examinationData.type"
+    :infoType="examinationData.infoType"
+  />
 </template>
 
 <script setup lang="ts">
+import heart from '@/assets/images/examination/collectIcon.png'
+import isHeart from '@/assets/images/examination/collectClickIcon.png'
 import { ref, reactive, watch, onMounted, onBeforeMount, onBeforeUnmount, inject } from 'vue'
 import { useRouter, useRoute } from 'vue-router'
 import useClipboard from 'vue-clipboard3'
+import examination from '../examination/index.vue'
 const { toClipboard } = useClipboard()
 const MG: any = inject('MG')
 const toolClass = inject('toolClass')
@@ -1297,6 +1355,7 @@
 
 import { loadMicroApp } from 'qiankun'
 import { microApps } from '@/child.ts'
+import { open } from 'fs'
 let token = localStorage.getItem('token')
 const canvasWith = ref(1000)
 const canvasheight = ref(3000)
@@ -1543,7 +1602,11 @@
     {
       name: '棰樺簱',
       icon: question,
-      isShow: bookConfig.value.textbookComponents.indexOf('3D3B4F55') > -1 || bookConfig.value.textbookComponents.indexOf('AFC1A288') > -1 || bookConfig.value.textbookComponents.indexOf('A434F2C0') > -1
+      isShow:
+        bookConfig.value.textbookComponents.indexOf('3D3B4F55') > -1 ||
+        bookConfig.value.textbookComponents.indexOf('AFC1A288') > -1 ||
+        bookConfig.value.textbookComponents.indexOf('A434F2C0') > -1 ||
+        bookConfig.value.textbookComponents.indexOf('A4821F71') > -1
     }
   ]
   teachToolsMenuData = [
@@ -1759,6 +1822,7 @@
 const showHandle = ref(null)
 const playIndex = ref(null) //闊抽鎾斁
 const audioPlayer = ref(null)
+const collectResourceList = ref([])
 const getResourceData = () => {
   if (token) {
     imgPreviewList.value = []
@@ -1943,6 +2007,8 @@
       })
       .catch(function (error) {
         console.log(error)
+        resourceDataList.value = []
+        classifySelectList.value = []
         listLoading.value = false
       })
   } else {
@@ -1953,7 +2019,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {})
   }
@@ -2006,7 +2078,6 @@
 
 //璧勬簮璺宠浆鍒版寚瀹氫綅缃�
 const JumpPosition = (data) => {
-  console.log(data, '璺宠浆')
   if (window.qiankunState && window.qiankunState.gotoPage) {
     window.qiankunState.gotoPage(Number(data.chapterNum), Number(data.pagination))
   }
@@ -2016,14 +2087,23 @@
 const selectResourceType = (type) => {
   resourceType.value = type
   searchText.value = ''
-  getResourceData()
+  if (type == 'collect') {
+    getCollectResource()
+  } else {
+    getResourceData()
+  }
 }
 //璧勬簮绫诲瀷鍥剧墖/瑙嗛/闊抽/涔犻/鍏朵粬
 const classifyClick = (item) => {
   activeClassify.value = item.key
   resourceDataList.value = []
   searchText.value = ''
-  getResourceData()
+  if(resourceType.value == 'collect') {
+    getCollectResource()
+  } else {
+    getResourceData()
+  }
+  
 }
 const searchBtn = () => {
   if (searchShow.value) {
@@ -2033,9 +2113,150 @@
   }
 }
 
+// 鑾峰彇鏀惰棌鐨勮祫婧�
+const getCollectResource = () => {
+  if(token) {
+    MG.identity
+    .getUserKey({
+      domain: 'collectResource',
+      keys: [bookConfig.value.bookId]
+    })
+    .then((res) => {
+      if (res.length) {
+        collectResourceList.value = JSON.parse(res[0].value)
+        console.log('鏀惰棌璧勬簮鍒楄〃', collectResourceList.value)
+        if(collectResourceList.value.length > 0) {
+            let imgCount = 0
+            let audioCount = 0
+            let videoCount = 0
+            let exercisesCount = 0
+            let otherCount = 0
+            resourceDataList.value = []
+            collectResourceList.value.forEach((resItem) => {
+              if (resItem.resourceType == '鍥剧墖') {
+                if (resItem.resourcePath) {
+                  resItem.resourcePath = bookConfig.value.resourceUrl + '/' + resItem.resourcePath
+                } else {
+                  resItem.resourcePath =
+                    bookConfig.value.requestCtx + '/file/GetPreViewImage?md5=' + resItem.md5
+                }
+
+                imgPreviewList.value.push(resItem.resourcePath)
+                if (activeClassify.value == 'image') {
+                  resourceDataList.value.push(resItem)
+                }
+                imgCount++
+              } else if (resItem.resourceType == '闊抽') {
+                if (activeClassify.value == 'audio') {
+                  resourceDataList.value.push(resItem)
+                }
+                audioCount++
+              } else if (resItem.resourceType == '瑙嗛') {
+                if (activeClassify.value == 'video') {
+                  resourceDataList.value.push(resItem)
+                }
+                videoCount++
+              } else {
+                if (activeClassify.value == 'other') {
+                  resourceDataList.value.push(resItem)
+                }
+                otherCount++
+              }
+            })
+            classifySelectList.value = []
+            if (imgCount > 0) {
+              classifySelectList.value.push({
+                title: '鍥剧墖',
+                count: imgCount,
+                key: 'image'
+              })
+            }
+            if (audioCount > 0) {
+              classifySelectList.value.push({
+                title: '闊抽',
+                count: audioCount,
+                key: 'audio'
+              })
+            }
+            if (videoCount > 0) {
+              classifySelectList.value.push({
+                title: '瑙嗛',
+                count: videoCount,
+                key: 'video'
+              })
+            }
+            if (otherCount > 0) {
+              classifySelectList.value.push({
+                title: '鍏朵粬',
+                count: otherCount,
+                key: 'other'
+              })
+            }
+            if (!activeClassify.value) {
+              activeClassify.value = classifySelectList.value[0].key
+              collectResourceList.value.forEach((resItem1) => {
+                if (resItem1.resourceType == classifySelectList.value[0].title) {
+                  resourceDataList.value.push(resItem1)
+                }
+              })
+            }
+        }
+      }
+    })
+  } else {
+    ElMessageBox.confirm('璇峰厛鐧诲綍锛�', {
+      confirmButtonText: '鍘荤櫥褰�',
+      cancelButtonText: '鍙栨秷',
+      autofocus: false,
+      type: 'warning'
+    })
+      .then(() => {
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
+      })
+      .catch(() => {})
+  }
+}
+// 鏀惰棌鎸夐挳
+const handleCollectResource = (id,md5,resourcePath,resourceType,source,resourceName) => {
+    if(collectResourceList.value.findIndex(item => item.id == id) > -1) {
+      collectResourceList.value = collectResourceList.value.filter(item => item.id != id)
+    } else {
+      collectResourceList.value.push({
+        id,
+        md5,
+        resourcePath:resourcePath.replace(bookConfig.value.resourceUrl + '/',''),
+        resourceType,
+        source,
+        resourceName
+      })
+    }
+    MG.identity.setUserKey({
+    setKeyRequests: [
+      {
+        domain: "collectResource",
+        key:bookConfig.value.bookId,
+        value: JSON.stringify(collectResourceList.value),
+      },
+    ],
+  })
+}
+
 //涔犻
 const exercisesType = ref('exercises') //涔犻绫诲瀷
 const questionList = ref([])
+const examinationRef = ref() // 绛旈鍣ㄥ疄渚�
+const examinationData = reactive({
+  type: '', // 绛旈绫诲瀷  option 娴嬭瘯
+  infoType: '', // 鏁版嵁鏉ユ簮  bits 姣旂壒鍚庡彴  json  鍋囨暟鎹�
+  info: {} // 杩欏棰樼殑淇℃伅
+})
+// 鑾峰彇涔犻
 const getExercisesList = () => {
   if (token) {
     listLoading.value = true
@@ -2072,6 +2293,44 @@
       type: 'warning'
     })
       .then(() => {
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
+      })
+      .catch(() => {})
+  }
+}
+
+// 鑾峰彇闄勫姞棰�
+const getAdditionalList = () => {
+  if (token) {
+    listLoading.value = true
+    questionList.value = []
+    axios
+      .get(bookConfig.value.resourceUrl + '/bits-question.json')
+      .then((res) => {
+        // 澶勭悊鑾峰彇鍒扮殑json鏁版嵁
+        if (res.data.data.length > 0) {
+          questionList.value = res.data.data
+          examinationData.infoType = res.data.type
+        }
+        listLoading.value = false
+      })
+      .catch(() => {
+        listLoading.value = false
+      })
+  } else {
+    ElMessageBox.confirm('璇峰厛鐧诲綍锛�', {
+      confirmButtonText: '鍘荤櫥褰�',
+      cancelButtonText: '鍙栨秷',
+      autofocus: false,
+      type: 'warning'
+    })
+      .then(() => {
         router.push('/login')
       })
       .catch(() => {})
@@ -2085,10 +2344,34 @@
   searchText.value = ''
   if (type == 'exercises') {
     getExercisesList()
-  } else if(type == 'wrong'){
+  } else if (type == 'additional') {
+    getAdditionalList()
+  } else if (type == 'wrong') {
+    openExaminationDialog(true, {}, 'errorQuestion')
     questionList.value = []
-  }else{
+  } else {
+    openExaminationDialog(true, {}, 'collectQuestion')
     questionList.value = []
+  }
+}
+// 棰樺垪琛ㄧ偣鍑�
+const clickQuestion = (type: string, data: any) => {
+  switch (type) {
+    case 'exercises':
+      JumpPosition(data)
+      break
+    case 'additional':
+      openExaminationDialog(true, data, 'option')
+      break
+    default:
+      break
+  }
+}
+const openExaminationDialog = (isSHow: boolean, data: any, type: string) => {
+  if (examinationRef.value) {
+    examinationRef.value.handleExaminationDialog(isSHow)
+    examinationData.type = type
+    examinationData.info = data
   }
 }
 
@@ -2444,7 +2727,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {})
   }
@@ -2683,7 +2972,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {})
   }
@@ -2723,7 +3018,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {})
   }
@@ -2797,7 +3098,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {})
   }
@@ -2902,7 +3209,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {})
   }
@@ -3103,7 +3416,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {
         showToolBox.value = false
@@ -3203,7 +3522,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {})
   }
@@ -3287,7 +3612,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {})
   }
@@ -3368,7 +3699,13 @@
       type: 'warning'
     })
       .then(() => {
-        router.push('/login')
+        if (sessionStorage.getItem('loginCtx')) {
+          window.open(sessionStorage.getItem('loginCtx'))
+        } else {
+          router.replace({
+            path: '/login'
+          })
+        }
       })
       .catch(() => {})
   }
@@ -3648,11 +3985,25 @@
 const layoutBtn = () => {
   localStorage.removeItem('token')
   localStorage.removeItem('userInfo')
-  router.push('/login')
+  // router.push('/login')
+  if (sessionStorage.getItem('loginCtx')) {
+    window.open(sessionStorage.getItem('loginCtx'))
+  } else {
+    router.replace({
+      path: '/login'
+    })
+  }
 }
 const goLogin = () => {
   localStorage.removeItem('userInfo')
-  router.push('/login')
+  // router.push('/login')
+  if (sessionStorage.getItem('loginCtx')) {
+    window.open(sessionStorage.getItem('loginCtx'))
+  } else {
+    router.replace({
+      path: '/login'
+    })
+  }
 }
 </script>
 

--
Gitblit v1.9.1