From c4a189b86db7328d537a7218d5c5a8cb0c95a320 Mon Sep 17 00:00:00 2001
From: YM <479443481@qq.com>
Date: 星期三, 15 五月 2024 21:24:52 +0800
Subject: [PATCH] 目录与搜索

---
 src/views/home.vue |  360 +++++++++++++++++++++--------------------------------------
 1 files changed, 131 insertions(+), 229 deletions(-)

diff --git a/src/views/home.vue b/src/views/home.vue
index 56b9623..00fc423 100644
--- a/src/views/home.vue
+++ b/src/views/home.vue
@@ -92,9 +92,9 @@
       <div class="menuContent" v-if="menuState.open">
         <div class="searchBox">
           <div class="inputBox" v-if="activeMenu !== 2">
-            <el-input class="custom-input" placeholder="璇疯緭鍏ュ唴瀹�" v-model="searchText">
+            <el-input class="custom-input" placeholder="璇疯緭鍏ュ唴瀹�" v-model="searchText" @keyup.enter="searchBook">
               <template #prefix>
-                <el-icon @click="searchBook"><Search /></el-icon>
+                <el-icon><Search /></el-icon>
               </template>
             </el-input>
           </div>
@@ -113,12 +113,18 @@
         <!-- 鐩綍 -->
         <div class="menuList" v-if="activeMenu == 0">
           <el-tree
+            ref="catalogTree"
             style="max-width: 600px"
             default-expand-all="true"
             :data="catalogueData"
             :props="defaultProps"
+            v-if="catalogueData.length > 0"
             @node-click="handleNodeClick"
+            :filter-node-method="filterNode"
           />
+          <div v-if="catalogueData.length == 0">
+            <el-empty :image-size="60" description="鏆傛棤鏁版嵁" />
+          </div>
         </div>
         <!-- 绗旇 -->
         <div class="notesBox" v-if="activeMenu == 1">
@@ -155,7 +161,7 @@
                   </div>
                   <div
                     class="noteText hover 123456"
-                    @click="jumpContent('note' + index)"
+                    @click="jumpContent(item)"
                     :style="{
                       background:
                         item.color == '#F5E12A'
@@ -171,7 +177,7 @@
                                   : item.color
                     }"
                   >
-                    <div class="con hover" @click="jumpContent('note' + index)">
+                    <div class="con hover">
                       {{ item.note }}
                     </div>
                   </div>
@@ -324,7 +330,7 @@
           </div>
         </div>
         <!-- 寰簲鐢ㄧ洅瀛� -->
-        <div class="pageBox-content" @scroll="pageScroll">
+        <div class="pageBox-content">
           <div class="content-box">
             <div
               id="container"
@@ -735,17 +741,17 @@
         v-for="item in colorSelectList"
         :key="item.key"
         class="flex1 hover"
-        @click="clickSelect(item)"
+        @click="clickSelectColor(item)"
       >
         <div :style="{ background: item.key }" class="scribeItem">
-          <img :src="xuanzhong" v-if="item.key == colorActive" />
+          <img :src="xuanzhong" v-if="item.key == noteColorActive" />
         </div>
       </div>
     </div>
     <template #footer>
       <span class="dialog-footer">
         <el-button @click="handleClose">鍙� 娑�</el-button>
-        <el-button type="primary" @click="addNote">纭� 瀹�</el-button>
+        <el-button type="primary" @click="addUserKey">纭� 瀹�</el-button>
       </span>
     </template>
   </el-dialog>
@@ -775,7 +781,9 @@
     <template #footer>
       <span class="dialog-footer">
         <el-button @click="screenshotClose">鍙� 娑�</el-button>
-        <el-button type="primary" @click="addScreenshot">纭� 瀹�</el-button>
+        <el-button type="primary" @click="addScreenshot" :loading="screenshotLoading"
+          >纭� 瀹�</el-button
+        >
       </span>
     </template>
   </el-dialog>
@@ -964,6 +972,7 @@
     },
     singular: true
   })
+
   window.qiankunActions.onGlobalStateChange((state, prev) => {
     console.log('鐖跺眰state鍙樺寲', state)
     bookName.value = state.bookName
@@ -1025,7 +1034,7 @@
   axios
     .get(resourceUrl + '/1/information.json?t=123')
     .then(function (response) {
-      console.log(response.data);
+      console.log(response.data)
       var json = response.data
       // 澶勭悊鑾峰彇鍒扮殑json鏁版嵁
       catalogueData.value = json.data
@@ -1038,8 +1047,15 @@
   children: 'children',
   label: 'label'
 }
+const filterNode = (value, data) => {
+  if (!value) return true
+  return data.label.indexOf(value) !== -1
+}
+
 const handleNodeClick = (data) => {
-  document.getElementById(data.id).scrollIntoView()
+  console.log(data)
+  if (window.qiankunState && window.qiankunState.gotoPage)
+    window.qiankunState.gotoPage(data.chapter, data.start)
 }
 
 //鑾峰彇璧勬簮
@@ -1276,7 +1292,11 @@
   }
   getNotesList()
 }
+const catalogTree = ref()
 const searchBook = async () => {
+  if (activeMenu.value == 0) {
+    if (catalogTree) catalogTree.value.filter(searchText.value)
+  }
   if (activeMenu.value == 1) {
     getNotesList()
   }
@@ -1492,8 +1512,10 @@
 const confirmDialog = ref<Boolean>(false)
 const screenshotVisble = ref<Boolean>(false)
 const nameData = ref('') //鎴浘鍚嶇О
+const screenshotLoading = ref(false)
 const urlData = ref('') //鎴浘base64
 const screenshotList = ref([])
+const screenshotData = ref([])
 
 //娴獥宸ュ叿鏍忕偣鍑讳簨浠�
 const floatItemHandle = (item) => {
@@ -1503,7 +1525,10 @@
       canvasShow.value = true
       toolSelectData.activeTool = 'huabi'
       break
+    case '鏍囨敞':
+      break
     case '鏍囩':
+      reMark()
       break
     case '鎴睆':
       jitT()
@@ -1578,9 +1603,11 @@
   toolSelectData.fontSizeActive = str
 }
 
-//鏍囩鏄剧ず闅愯棌
+//鏍囨敞鏄剧ず闅愯棌
 const labelShow = (str) => {}
 
+//鏍囩
+const reMark = () => {}
 //鎴浘
 //鎴浘浜嬩欢
 function jitT() {
@@ -1601,13 +1628,15 @@
   console.log(base64)
   floatingToolData.activeToolData = ''
 }
+//淇濆瓨鎴浘
 const addScreenshot = () => {
   if (nameData.value) {
-    screenshotList.value.push({
+    screenshotData.value.push({
       createDate: new Date(),
       imgUrl: urlData.value,
       name: nameData.value
     })
+    screenshotLoading.value = true
     request({
       url: '/identity/api/ApiAppUserSetKey',
       method: 'post',
@@ -1616,17 +1645,22 @@
           {
             domain: 'screenshot',
             key: bookId.value,
-            value: JSON.stringify(screenshotList.value)
+            value: JSON.stringify(screenshotData.value)
           }
         ]
       }
-    }).then((res) => {
-      getScreenshotList()
-      nameData.value = ''
-      urlData.value = ''
-      floatingToolData.activeToolData = ''
-      screenshotVisble.value = false
     })
+      .then((res) => {
+        screenshotLoading.value = false
+        getScreenshotList()
+        nameData.value = ''
+        urlData.value = ''
+        floatingToolData.activeToolData = ''
+        screenshotVisble.value = false
+      })
+      .catch(function (error) {
+        screenshotLoading.value = false
+      })
   } else {
     ElMessage.error('鎴浘鍚嶇О涓嶈兘涓虹┖!')
   }
@@ -1646,12 +1680,37 @@
   }).then((res) => {
     if (res && res.length > 0 && res[0].value) {
       screenshotList.value = JSON.parse(res[0].value)
+      screenshotData.value = JSON.parse(res[0].value)
     }
   })
 }
+//鏌ョ湅鎴浘
 const getCapture = (item) => {
   imgUrl.value = item.imgUrl
   confirmDialog.value = true
+}
+//鍒犻櫎鎴浘
+const deleteScreenshot = (item) => {
+  let list = screenshotList.value.filter((itemData) => itemData.imgUrl !== item.imgUrl)
+  request({
+    url: '/identity/api/ApiAppUserSetKey',
+    method: 'post',
+    data: {
+      setKeyRequests: [
+        {
+          domain: 'screenshot',
+          key: bookId.value,
+          value: JSON.stringify(list)
+        }
+      ]
+    }
+  }).then((res) => {
+    ElMessage({
+      message: '鍒犻櫎鎴浘鎴愬姛!',
+      type: 'success'
+    })
+    getScreenshotList()
+  })
 }
 
 //閫変腑鏂囧瓧宸ュ叿鏍�
@@ -1680,22 +1739,9 @@
   }
 }
 
-const pageScroll = (e) => {
-  // window.qiankunActions.setGlobalState({
-  //   gotoPage: (t, s) => {
-  //     // 缁戝畾瀛愬簲鐢ㄩ�夋嫨鐩戝惉浜嬩欢
-  //     console.log(t, s, '瀛愬簲鐢ㄦ粴鍔�')
-  //   }
-  // })
-  showToolBox.value = false
-  lineDelete.showLineDelete = false
-  // let scroll = e.target.scrollTop
-  // let offsetHeight = document.getElementById('container').offsetHeight
-  // headerData.process = Math.round((scroll / offsetHeight) * 100)
-}
-
 const toolActive = ref('')
 const colorActive = ref('')
+const noteColorActive = ref('')
 const dialogToolList = reactive([
   { icon: gaoliang, activeIcon: gaoliang1, name: '楂樹寒' },
   { icon: huaxian, activeIcon: huaxian1, name: '鍒掔嚎' },
@@ -1862,6 +1908,10 @@
   colorActive.value = item.key
   addUserKey()
 }
+//绗旇閫夐鑹�
+const clickSelectColor = (item) => {
+  noteColorActive.value = item.key
+}
 
 const addUserKey = () => {
   let dom = ''
@@ -1889,6 +1939,29 @@
         color: colorActive.value
       })
       break
+    case '绗旇':
+      if (!formData.desc.replace(/^\s*|\s*$/g, '')) {
+        ElMessage.error('绗旇鍐呭涓嶈兘涓虹┖!')
+        return
+      }
+      if (!noteColorActive.value) {
+        ElMessage.error('璇烽�夋嫨绗旇棰滆壊!')
+        return
+      }
+      dom = 'notes-' + bookId.value
+      data =
+        dialogToolData.notesList.length != 0 ? dialogToolData.notesList[dialogToolData.chapter] : []
+      data.push({
+        id: toolClass.uuid(8),
+        txt: dialogToolData.txt,
+        page: dialogToolData.page,
+        type: 'Note',
+        color: noteColorActive.value,
+        createDate: new Date(),
+        note: formData.desc.replace(/^\s*|\s*$/g, '')
+      })
+
+      break
   }
   request({
     url: '/identity/api/ApiAppUserSetKey',
@@ -1905,6 +1978,7 @@
   }).then((res) => {
     showToolBox.value = false
     colorActive.value = ''
+    noteColorActive.value = ''
     toolActive.value = ''
     getSignData()
   })
@@ -1936,7 +2010,6 @@
     }
   }).then((res) => {})
 }
-const lock = ref(false)
 
 const getSignData = () => {
   request({
@@ -1985,176 +2058,25 @@
       }
     }
   })
-}
-
-const addNote = () => {
-  const obj = {
-    desc: formData.desc
-  }
-  if (!colorActive.value) {
-    ElMessage.error('璇烽�夋嫨绗旇棰滆壊!')
-    return
-  }
-  if (!lock.value) {
-    lock.value = true
-    if (formData.desc.replace(/^\s*|\s*$/g, '')) {
-      dialogToolData.notesList.push({
-        selectNode: selectNode.value,
-        selectText: selectText.value,
-        color: colorActive.value,
-        selectPage: selectPage.value,
-        chapter: dialogToolData.chapter,
-        createDate: new Date(),
-        note: formData.desc.replace(/^\s*|\s*$/g, '')
-      })
-      request({
-        url: '/identity/api/ApiAppUserSetKey',
-        method: 'post',
-        data: {
-          setKeyRequests: [
-            {
-              domain: 'notes',
-              key: bookId.value,
-              value: JSON.stringify(dialogToolData.notesList)
-            }
-          ]
-        }
-      }).then((res) => {
-        showToolBox.value = false
-        addNoteVisble.value = false
-        colorActive.value = ''
-        toolActive.value = ''
-        getNotesList()
-        setTimeout(() => {
-          lock.value = false
-        }, 1000)
-      })
-    } else {
-      ElMessage.error('绗旇鍐呭涓嶈兘涓虹┖!')
-      lock.value = false
-    }
-  }
-}
-//绗旇
-const getNotesList = () => {
-  scribeData.noteList = []
-  scribeData.loading = true
   request({
     url: '/identity/api/ApiGetAppUserKey',
     method: 'post',
     data: {
-      domain: 'notes',
-      keys: [bookId.value]
+      domain: 'note-' + bookId.value,
+      keys: activeCatalog.value.map((item) => item + '')
     }
   }).then((res) => {
-    if (res && res.length > 0 && res[0].value) {
-      dialogToolData.notesList = JSON.parse(res[0].value)
-      let list = JSON.parse(res[0].value)
-      let textDom1 = document.querySelector('.temp-book')
-      if (list.length > 0) {
-        list.forEach((item, index) => {
-          item.createDate = moment(item.createDate).format('YYYY-MM-DD')
-          if (searchText.value) {
-            searchText.value = searchText.value.replace(/^\s*|\s*$/g, '')
-            let text = searchText.value.replace(/^\s*|\s*$/g, '')
-            if (item.text.indexOf(text) > -1) {
-              if (menuState.notesColor == 'all') {
-                scribeData.noteList.push(item)
-              } else if (menuState.notesColor == item.color) {
-                scribeData.noteList.push(item)
-              }
-            }
-          } else {
-            if (menuState.notesColor == 'all') {
-              scribeData.noteList.push(item)
-            } else if (menuState.notesColor == item.color) {
-              scribeData.noteList.push(item)
-            }
-          }
-          //椤甸潰娣诲姞绗旇
-          let rReg1 = new RegExp(`${item.selectText}`, 'ig')
-          let text1 = textDom1.innerHTML
-          let nHtmlText1 = item.selectNode
-
-          let nHtml1 = ''
-          nHtml1 = nHtmlText1.replace(
-            rReg1,
-            `<span style="padding-bottom:2px; border-bottom: 2px solid;border-bottom-color:${item.color}" class="notesline">${item.selectText}</span><img src="${biji1}" style="cursor: pointer" onclick="notesVisbleShow('${item.selectText}')"/>`
-          )
-          let rHtml1 = ''
-          rHtml1 = text1.replace(nHtmlText1, nHtml1)
-          textDom1.innerHTML = rHtml1
-        })
-      }
-    }
-    scribeData.loading = false
-  })
-}
-//鍒掔嚎
-const getScribeList = () => {
-  scribeData.scribeDataList = []
-  request({
-    url: '/identity/api/ApiGetAppUserKey',
-    method: 'post',
-    data: {
-      domain: 'underline',
-      keys: [bookId.value]
-    }
-  }).then((res) => {
-    if (res && res.length > 0 && res[0].value) {
-      dialogToolData.scribeList = JSON.parse(res[0].value)
-      scribeData.scribeDataList = JSON.parse(res[0].value)
-      let textDom1 = document.querySelector('.temp-book')
-      if (scribeData.scribeDataList.length > 0) {
-        for (let i = 0; i < scribeData.scribeDataList.length; i++) {
-          let item = scribeData.scribeDataList[i]
-          let rReg1 = new RegExp(`${item.selectText}`, 'ig')
-          let text1 = textDom1.innerHTML
-          let nHtmlText1 = item.selectNode
-
-          let nHtml1 = ''
-          nHtml1 = nHtmlText1.replace(
-            rReg1,
-            `<span style="text-decoration:underline;text-decoration-style: wavy;text-underline-thickness:2px;text-decoration-color:${item.color};cursor: pointer" class="underline" onclick="deleteScribeShow('${item.selectText}')">${item.selectText}</span>`
-          )
-          let rHtml1 = ''
-          rHtml1 = text1.replace(nHtmlText1, nHtml1)
-          textDom1.innerHTML = rHtml1
-        }
-      }
-    }
-  })
-}
-//楂樹寒
-const getlineHeightList = () => {
-  scribeData.lineHeightList = []
-  request({
-    url: '/identity/api/ApiGetAppUserKey',
-    method: 'post',
-    data: {
-      domain: 'highLight',
-      keys: [bookId.value]
-    }
-  }).then((res) => {
-    if (res && res.length > 0 && res[0].value) {
-      dialogToolData.lineHeight = JSON.parse(res[0].value)
-      scribeData.lineHeightList = JSON.parse(res[0].value)
-      let textDom = document.querySelector('.temp-book')
-      if (scribeData.lineHeightList.length > 0) {
-        for (let i = 0; i < scribeData.lineHeightList.length; i++) {
-          let item = scribeData.lineHeightList[i]
-          let rReg = new RegExp(`${item.selectText}`, 'ig')
-          let text = textDom.innerHTML
-          let nHtmlText = item.selectNode
-          let nHtml = ''
-          nHtml = nHtmlText.replace(
-            rReg,
-            `<span style="background: ${item.color};padding:3px;cursor: pointer" class="highLight" onclick="deletelineHeightShow('${item.selectText}')">${item.selectText}</span>`
-          )
-          // nHtmlText = nHtml
-          let rHtml = ''
-          rHtml = text.replace(nHtmlText, nHtml)
-          textDom.innerHTML = rHtml
+    if (res && res.length > 0) {
+      for (let i = 0; i < res.length; i++) {
+        const item = res[i]
+        const data = JSON.parse(item.value)
+        // 鍌ㄥ��
+        dialogToolData.notesList[item.key] = data
+        // 娓叉煋
+        for (let j = 0; j < data.length; j++) {
+          const citem = data[j]
+          if (window.qiankunState && window.qiankunState.renderSign)
+            window.qiankunState.renderSign(citem.type, citem)
         }
       }
     }
@@ -2171,8 +2093,8 @@
 })
 
 // 鍒掔嚎銆佺瑪璁般�侀珮浜偣鍑诲洖璋�
-window.signClick = (type, id)=>{
-  console.log("signClick鐐瑰嚮浜嬩欢鍥炶皟鐨勫疄渚�", type, id);
+window.signClick = (type, id) => {
+  console.log('signClick鐐瑰嚮浜嬩欢鍥炶皟鐨勫疄渚�', type, id)
 }
 
 window.notesVisbleShow = function (txt) {
@@ -2260,19 +2182,22 @@
   }
 }
 
-const jumpContent = (id) => {
+//绗旇璺宠浆
+const jumpContent = (item) => {
+  console.log(item)
   if (window.qiankunState && window.qiankunState.gotoPage) window.qiankunState.gotoPage(5, 100)
 }
 
+//绗旇缂栬緫
 const update = (item, type) => {
   dialogToolData.notesList.splice(
     dialogToolData.notesList.findIndex((itemData) => itemData.selectText == item.selectText),
     1
   )
-  selectNode.value = item.selectNode
-  selectText.value = item.selectText
-  selectPage.value = item.selectPage
-  colorActive.value = item.color
+  dialogToolData.txt = item.txt
+  dialogToolData.page = item.page
+  dialogToolData.chapter = item.chapterNum
+  noteColorActive.value = item.color
   dialogToolData.chapter = item.chapter
   formData.desc = item.note
   addNoteVisble.value = true
@@ -2314,29 +2239,6 @@
   }
 }
 
-//鍒犻櫎鎴浘
-const deleteScreenshot = (item) => {
-  let list = screenshotList.value.filter((itemData) => itemData.imgUrl !== item.imgUrl)
-  request({
-    url: '/identity/api/ApiAppUserSetKey',
-    method: 'post',
-    data: {
-      setKeyRequests: [
-        {
-          domain: 'screenshot',
-          key: bookId.value,
-          value: JSON.stringify(list)
-        }
-      ]
-    }
-  }).then((res) => {
-    ElMessage({
-      message: '鍒犻櫎鎴浘鎴愬姛!',
-      type: 'success'
-    })
-    getScreenshotList()
-  })
-}
 //鍐呭鍖哄煙椤堕儴鏄剧ず
 
 const headerData = reactive({

--
Gitblit v1.9.1