Przeglądaj źródła

[skip ci] perf(web): improve little performance

Xwite 3 lat temu
rodzic
commit
e173e3196d

+ 6 - 5
modules/web/src/components/BookItems.vue

@@ -22,7 +22,7 @@
             <div class="author">
             <div class="author">
               {{ book.author }}
               {{ book.author }}
             </div>
             </div>
-            <div class="tags" v-show="isSearch">
+            <div class="tags" v-if="isSearch">
               <el-tag
               <el-tag
                 v-for="tag in book.kind?.split(',').slice(0, 2)"
                 v-for="tag in book.kind?.split(',').slice(0, 2)"
                 :key="tag"
                 :key="tag"
@@ -30,16 +30,16 @@
                 {{ tag }}
                 {{ tag }}
               </el-tag>
               </el-tag>
             </div>
             </div>
-            <div class="update-info" v-show="!isSearch">
+            <div class="update-info" v-if="!isSearch">
               <div class="dot">•</div>
               <div class="dot">•</div>
               <div class="size">共{{ book.totalChapterNum }}章</div>
               <div class="size">共{{ book.totalChapterNum }}章</div>
               <div class="dot">•</div>
               <div class="dot">•</div>
               <div class="date">{{ dateFormat(book.lastCheckTime) }}</div>
               <div class="date">{{ dateFormat(book.lastCheckTime) }}</div>
             </div>
             </div>
           </div>
           </div>
-          <div class="intro" v-show="isSearch">{{ book.intro }}</div>
+          <div class="intro" v-if="isSearch">{{ book.intro }}</div>
 
 
-          <div class="dur-chapter" v-show="!isSearch">
+          <div class="dur-chapter" v-if="!isSearch">
             已读:{{ book.durChapterTitle }}
             已读:{{ book.durChapterTitle }}
           </div>
           </div>
           <div class="last-chapter">最新:{{ book.latestChapterTitle }}</div>
           <div class="last-chapter">最新:{{ book.latestChapterTitle }}</div>
@@ -52,7 +52,7 @@
 import { dateFormat } from "../plugins/utils";
 import { dateFormat } from "../plugins/utils";
 const props = defineProps(["books", "isSearch"]);
 const props = defineProps(["books", "isSearch"]);
 const emit = defineEmits(["bookClick"]);
 const emit = defineEmits(["bookClick"]);
-const handleClick = (book) => emit("bookClick", toRaw(book));
+const handleClick = (book) => emit("bookClick", book);
 const getCover = (coverUrl) => {
 const getCover = (coverUrl) => {
   return /^data:/.test(coverUrl)
   return /^data:/.test(coverUrl)
     ? coverUrl
     ? coverUrl
@@ -64,6 +64,7 @@ const getCover = (coverUrl) => {
 const subJustify = computed(() =>
 const subJustify = computed(() =>
   props.isSearch ? "space-between" : "flex-start"
   props.isSearch ? "space-between" : "flex-start"
 );
 );
+
 </script>
 </script>
 
 
 <style lang="scss" scoped>
 <style lang="scss" scoped>

+ 2 - 7
modules/web/src/components/CatalogItem.vue

@@ -12,17 +12,12 @@
   </div>
   </div>
 </template>
 </template>
 <script setup>
 <script setup>
-const props = defineProps(["index", "source", "gotoChapter"]);
-
-const store = useBookStore();
-
-const index = computed(() => store.readingBook.index);
+const props = defineProps(["index", "source", "gotoChapter", "currentChapterIndex"]);
 
 
 const isSelected = (idx) => {
 const isSelected = (idx) => {
-  return idx == index.value;
+  return idx == props.currentChapterIndex;
 };
 };
 
 
-// 处理pc mobile
 const catas = computed(() => {
 const catas = computed(() => {
   return props.source?.catas ?? [props.source];
   return props.source?.catas ?? [props.source];
 });
 });

+ 6 - 6
modules/web/src/components/ChapterContent.vue

@@ -71,10 +71,10 @@ const scrollToReadedLength = (length) => {
 defineExpose({
 defineExpose({
   scrollToReadedLength,
   scrollToReadedLength,
 });
 });
-const observer = ref(null);
+let intersectionObserver = null;
 const emit = defineEmits(["readedLengthChange"]);
 const emit = defineEmits(["readedLengthChange"]);
 onMounted(() => {
 onMounted(() => {
-  observer.value = new IntersectionObserver(
+  intersectionObserver = new IntersectionObserver(
     (entries) => {
     (entries) => {
       for (let { target, isIntersecting } of entries) {
       for (let { target, isIntersecting } of entries) {
         if (isIntersecting) {
         if (isIntersecting) {
@@ -90,15 +90,15 @@ onMounted(() => {
       rootMargin: `0px 0px -${window.innerHeight - 24}px 0px`,
       rootMargin: `0px 0px -${window.innerHeight - 24}px 0px`,
     }
     }
   );
   );
-  observer.value.observe(titleRef.value);
+  intersectionObserver.observe(titleRef.value);
   paragraphRef.value.forEach((element) => {
   paragraphRef.value.forEach((element) => {
-    observer.value.observe(element);
+    intersectionObserver.observe(element);
   });
   });
 });
 });
 
 
 onUnmounted(() => {
 onUnmounted(() => {
-  observer.value?.disconnect();
-  observer.value = null;
+  intersectionObserver?.disconnect();
+  intersectionObserver = null;
 });
 });
 </script>
 </script>
 
 

+ 8 - 6
modules/web/src/components/PopCatalog.vue

@@ -14,7 +14,7 @@
       :data-sources="virtualListdata"
       :data-sources="virtualListdata"
       :data-component="CatalogItem"
       :data-component="CatalogItem"
       :estimate-size="40"
       :estimate-size="40"
-      :extra-props="{ gotoChapter }"
+      :extra-props="{ gotoChapter, currentChapterIndex }"
     />
     />
   </div>
   </div>
 </template>
 </template>
@@ -39,7 +39,7 @@ const popupTheme = computed(() => {
   };
   };
 });
 });
 
 
-const index = computed({
+const currentChapterIndex = computed({
   get: () => store.readingBook.index,
   get: () => store.readingBook.index,
   set: (value) => (store.readingBook.index = value),
   set: (value) => (store.readingBook.index = value),
 });
 });
@@ -65,16 +65,18 @@ const virtualListdata = computed(() => {
 
 
 const emit = defineEmits(["getContent"]);
 const emit = defineEmits(["getContent"]);
 const gotoChapter = (note) => {
 const gotoChapter = (note) => {
-  index.value = catalog.value.indexOf(note);
+  const chapterIndex = catalog.value.indexOf(note);
+  currentChapterIndex.value = chapterIndex;
   store.setPopCataVisible(false);
   store.setPopCataVisible(false);
   store.setContentLoading(true);
   store.setContentLoading(true);
-  emit("getContent", index.value);
+  emit("getContent", chapterIndex);
 };
 };
 
 
 const virtualListRef = ref();
 const virtualListRef = ref();
 const virtualListIndex = computed(() => {
 const virtualListIndex = computed(() => {
-  if (miniInterface.value) return index.value;
-  return Math.floor(index.value / 2);
+  let index = currentChapterIndex.value;
+  if (miniInterface.value) return index;
+  return Math.floor(index / 2);
 });
 });
 
 
 onUpdated(() => {
 onUpdated(() => {

+ 3 - 2
modules/web/src/components/SourceItem.vue

@@ -24,8 +24,9 @@ const handleSourceClick = (source) => {
   store.changeCurrentSource(source);
   store.changeCurrentSource(source);
 };
 };
 const isSaveError = computed(() => {
 const isSaveError = computed(() => {
-  if (savedSourcesMap.value.size == 0) return false;
-  return !savedSourcesMap.value.has(sourceUrl.value);
+  const map = savedSourcesMap.value;
+  if (map.size == 0) return false;
+  return !map.has(sourceUrl.value);
 });
 });
 </script>
 </script>
 <style lang="scss" scoped>
 <style lang="scss" scoped>

+ 10 - 8
modules/web/src/components/SourceList.vue

@@ -51,19 +51,19 @@ const store = useSourceStore();
 const sourceUrlSelect = ref([]);
 const sourceUrlSelect = ref([]);
 const searchKey = ref("");
 const searchKey = ref("");
 const { sources, sourcesMap } = storeToRefs(store);
 const { sources, sourcesMap } = storeToRefs(store);
-const isBookSource = computed(() => {
-  return /bookSource/.test(window.location.href);
-});
+
 const sourceSelect = computed(() => {
 const sourceSelect = computed(() => {
-  if (sourceUrlSelect.value.length == 0) return [];
-  return sourceUrlSelect.value.map(
+  const urls = sourceUrlSelect.value;
+  if (urls.length == 0) return [];
+  return urls.map(
     (sourceUrl) => sourcesMap.value.get(sourceUrl) ?? {}
     (sourceUrl) => sourcesMap.value.get(sourceUrl) ?? {}
   );
   );
 });
 });
 const deleteSelectSources = () => {
 const deleteSelectSources = () => {
-  API.deleteSource(sourceSelect.value).then(({ data }) => {
+  const sourceSelectValue = sourceSelect.value;
+  API.deleteSource(sourceSelectValue).then(({ data }) => {
     if (!data.isSuccess) return ElMessage.error(data.errorMsg);
     if (!data.isSuccess) return ElMessage.error(data.errorMsg);
-    store.deleteSources(sourceSelect.value);
+    store.deleteSources(sourceSelectValue);
     sourceUrlSelect.value = [];
     sourceUrlSelect.value = [];
   });
   });
 };
 };
@@ -107,13 +107,15 @@ const importSourceFile = () => {
   });
   });
   input.click();
   input.click();
 };
 };
+
+const isBookSource = /bookSource/.test(window.location.href);
 const outExport = () => {
 const outExport = () => {
   const exportFile = document.createElement("a");
   const exportFile = document.createElement("a");
   let sources =
   let sources =
       sourceUrlSelect.value.length === 0
       sourceUrlSelect.value.length === 0
         ? sourcesFiltered.value
         ? sourcesFiltered.value
         : sourceSelect.value,
         : sourceSelect.value,
-    sourceType = isBookSource.value ? "BookSource" : "RssSource";
+    sourceType = isBookSource ? "BookSource" : "RssSource";
 
 
   exportFile.download = `${sourceType}_${Date()
   exportFile.download = `${sourceType}_${Date()
     .replace(/.*?\s(\d+)\s(\d+)\s(\d+:\d+:\d+).*/, "$2$1$3")
     .replace(/.*?\s(\d+)\s(\d+)\s(\d+:\d+:\d+).*/, "$2$1$3")

+ 4 - 4
modules/web/src/components/SourceTabTools.vue

@@ -6,10 +6,10 @@
       :name="tab[0]"
       :name="tab[0]"
       :label="tab[1]"
       :label="tab[1]"
     >
     >
-      <source-json v-if="index == 0" />
-      <source-debug v-if="index == 1" />
-      <source-list v-if="index == 2" />
-      <source-help v-if="index == 3" />
+      <source-json v-show="index == 0" />
+      <source-debug v-show="index == 1" />
+      <source-list v-show="index == 2" />
+      <source-help v-show="index == 3" />
     </el-tab-pane>
     </el-tab-pane>
   </el-tabs>
   </el-tabs>
 </template>
 </template>