Browse Source

feat: 滚动加载

sunxiao 10 months ago
parent
commit
57a5bdf0fb

+ 20 - 0
package-lock.json

@@ -14,6 +14,7 @@
         "highlight.js": "^11.9.0",
         "load-awesome": "^1.1.0",
         "markdown-it": "^14.1.0",
+        "markdown-it-katex": "^2.0.3",
         "markdown-it-latex": "^0.2.0",
         "markdown-it-link-attributes": "^4.0.1",
         "naive-ui": "^2.38.2",
@@ -4189,6 +4190,25 @@
         "markdown-it": "bin/markdown-it.mjs"
       }
     },
+    "node_modules/markdown-it-katex": {
+      "version": "2.0.3",
+      "resolved": "https://registry.npmmirror.com/markdown-it-katex/-/markdown-it-katex-2.0.3.tgz",
+      "integrity": "sha512-nUkkMtRWeg7OpdflamflE/Ho/pWl64Lk9wNBKOmaj33XkQdumhXAIYhI0WO03GeiycPCsxbmX536V5NEXpC3Ng==",
+      "dependencies": {
+        "katex": "^0.6.0"
+      }
+    },
+    "node_modules/markdown-it-katex/node_modules/katex": {
+      "version": "0.6.0",
+      "resolved": "https://registry.npmmirror.com/katex/-/katex-0.6.0.tgz",
+      "integrity": "sha512-rS4mY3SvHYg5LtQV6RBcK0if7ur6plyEukAOV+jGGPqFImuzu8fHL6M752iBmRGoUyF0bhZbAPoezehn7xYksA==",
+      "dependencies": {
+        "match-at": "^0.1.0"
+      },
+      "bin": {
+        "katex": "cli.js"
+      }
+    },
     "node_modules/markdown-it-latex": {
       "version": "0.2.0",
       "resolved": "https://registry.npmmirror.com/markdown-it-latex/-/markdown-it-latex-0.2.0.tgz",

+ 1 - 0
package.json

@@ -17,6 +17,7 @@
     "highlight.js": "^11.9.0",
     "load-awesome": "^1.1.0",
     "markdown-it": "^14.1.0",
+    "markdown-it-katex": "^2.0.3",
     "markdown-it-latex": "^0.2.0",
     "markdown-it-link-attributes": "^4.0.1",
     "naive-ui": "^2.38.2",

+ 3 - 2
src/components/Chat/ChatAnswer.vue

@@ -6,7 +6,8 @@ import MarkdownIt from 'markdown-it';
 import hljs from 'highlight.js';
 import mila from 'markdown-it-link-attributes';
 // import markdownItLatex from 'markdown-it-latex'
-import mdKatex from '@traptitech/markdown-it-katex';
+// import mdKatex from '@traptitech/markdown-it-katex';
+import mdKatex from 'markdown-it-katex';
 import { SvgIcon } from '@/components';
 import { chatApi } from "@/api/chat"
 
@@ -14,7 +15,7 @@ import { chatApi } from "@/api/chat"
 
 const props = defineProps({
   id: {
-    type: String || Number,
+    type: [String, Number],
     default: ''
   },
   content: {

+ 4 - 4
src/composables/useInfinite.js

@@ -9,7 +9,7 @@ export const useInfinite = props => {
   const counter = ref(0);
   const noMore = ref(false);
 
-  const isMore = computed(() => recordList.value.length < counter.value);
+  const isMore = computed(() => pageParams.page * pageParams.pageSize < counter.value);
 
   const addHistoryRecord = record => {
     recordList.value.unshift(...record);
@@ -23,10 +23,10 @@ export const useInfinite = props => {
 
     const { rows, total } = await initRecordData();
     
+    recordList.value.push(...rows);
+
     counter.value = total;
 
-    recordList.value.push(...rows);
- 
     if (unref(isMore)) {
       pageParams.page ++;
     } else {
@@ -41,7 +41,7 @@ export const useInfinite = props => {
 
     recordList.value = rows;
     counter.value = total;
-    noMore.value = unref(isMore);
+    noMore.value = !unref(isMore);
   }
 
   const initRecordData = async () => {

+ 2 - 2
src/router/index.js

@@ -1,4 +1,4 @@
-import { createRouter, createWebHistory } from 'vue-router'
+import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
 
 const constantRouterMap = [
   {
@@ -43,7 +43,7 @@ const constantRouterMap = [
 ]
 
 const router = createRouter({
-  history: createWebHistory(import.meta.env.BASE_URL),
+  history: createWebHashHistory(import.meta.env.BASE_URL),
   routes: constantRouterMap,
   scrollBehavior: () => ({ left: 0, top: 0 })
 })

+ 1 - 0
vite.config.ts

@@ -9,6 +9,7 @@ import path from 'path'
 
 // https://vitejs.dev/config/
 export default defineConfig({
+  base: './',
   plugins: [
     vue(),
     vueJsx(),

File diff suppressed because it is too large
+ 0 - 40
vite.config.ts.timestamp-1716464418959-219f4ec820431.mjs


Some files were not shown because too many files changed in this diff