增加 查询
This commit is contained in:
parent
f397b82111
commit
678720a74f
@ -11,14 +11,15 @@
|
||||
"dependencies": {
|
||||
"axios": "^1.6.2",
|
||||
"core-js": "^3.29.0",
|
||||
"event-source-polyfill": "^1.0.31",
|
||||
"md-editor-v3": "^4.8.3",
|
||||
"pinia": "^2.0.0",
|
||||
"pinia-plugin-persistedstate": "^3.2.0",
|
||||
"roboto-fontface": "*",
|
||||
"vue": "^3.2.0",
|
||||
"vue-axios": "^3.5.2",
|
||||
"vue-router": "^4.0.0",
|
||||
"vuetify": "^3.0.0",
|
||||
"md-editor-v3": "^4.8.3"
|
||||
"vuetify": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/types": "^7.21.4",
|
||||
|
@ -54,5 +54,5 @@ const library = new LibrariesApi(conf);
|
||||
|
||||
|
||||
export {
|
||||
document, library
|
||||
document, library, conf
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ const routes = [
|
||||
name: "library.documents",
|
||||
component: () => import("@/views/documents/List.vue"),
|
||||
},
|
||||
{
|
||||
path: "/library/:LibraryId/query",
|
||||
name: "library.query",
|
||||
component: () => import("@/views/libraries/Query.vue"),
|
||||
},
|
||||
{
|
||||
path: "/library/:LibraryId/documents/create",
|
||||
name: "library.documents.create",
|
||||
@ -39,7 +44,8 @@ const routes = [
|
||||
path: "/library/:LibraryId/documents/:DocumentId",
|
||||
name: "library.documents.view",
|
||||
component: () => import("@/views/documents/View.vue"),
|
||||
}
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div v-if="loading">
|
||||
<v-row justify="center">
|
||||
<v-col cols="12" md="4" xl="2" v-for="n in 3" :key="n">
|
||||
<v-row>
|
||||
<v-col cols="12" md="4" xl="2" v-for="n in 6" :key="n">
|
||||
<v-skeleton-loader
|
||||
v-for="n in 2"
|
||||
:key="n"
|
||||
@ -14,7 +14,10 @@
|
||||
</v-row>
|
||||
</div>
|
||||
<div v-else>
|
||||
<v-btn class="mb-3" @click="goto_create_document">创建</v-btn>
|
||||
<div class="mb-3">
|
||||
<v-btn @click="goto_create_document">创建</v-btn>
|
||||
<v-btn class="ml-2" @click="goto_query_library">查询</v-btn>
|
||||
</div>
|
||||
|
||||
<v-row>
|
||||
<v-col
|
||||
@ -34,14 +37,16 @@
|
||||
</v-card-subtitle>
|
||||
<v-card-text>{{ document.content }}</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn text color="primary" @click="goto_document(document.ID)">预览</v-btn>
|
||||
<v-btn text color="primary" @click="goto_document(document.ID)"
|
||||
>预览</v-btn
|
||||
>
|
||||
<v-btn text color="secondary">编辑</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</div>
|
||||
<div v-if="documents.Total == 0">
|
||||
<div v-if="documents.Total == 0" class="mt-5">
|
||||
<v-alert text="看样子你还没有创建任何文档。"></v-alert>
|
||||
</div>
|
||||
|
||||
@ -104,8 +109,16 @@ function goto_document(documentId) {
|
||||
name: "library.documents.view",
|
||||
params: {
|
||||
DocumentId: documentId,
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function goto_query_library() {
|
||||
router.push({
|
||||
name: "library.query",
|
||||
params: {
|
||||
LibraryId: libraryId,
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
@ -38,7 +38,7 @@ document
|
||||
<div v-else>
|
||||
<h2>{{ docu.Title }}</h2>
|
||||
|
||||
<MdPreview :theme="getTheme" :modelValue="docu.Content" />
|
||||
<MdPreview class="mt-3" :theme="getTheme" :modelValue="docu.Content" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
122
src/views/libraries/Query.vue
Normal file
122
src/views/libraries/Query.vue
Normal file
@ -0,0 +1,122 @@
|
||||
<script setup>
|
||||
import router from "@/router";
|
||||
import { ref } from "vue";
|
||||
import { MdPreview } from "md-editor-v3";
|
||||
import { useUserStore } from "@/store/user";
|
||||
import { EventSourcePolyfill } from "event-source-polyfill";
|
||||
import { library as libraryApi, conf } from "@/plugins/api";
|
||||
import getTheme from "@/plugins/getTheme";
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
const querying = ref(false);
|
||||
|
||||
const libraryId = parseInt(router.currentRoute.value.params.LibraryId);
|
||||
const library = ref({
|
||||
Id: "",
|
||||
Name: "",
|
||||
});
|
||||
|
||||
const question = ref("");
|
||||
const answer = ref("");
|
||||
|
||||
const sources = ref([]);
|
||||
|
||||
function query() {
|
||||
if (querying.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!question.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
querying.value = true;
|
||||
sources.value = [];
|
||||
answer.value = "";
|
||||
|
||||
console.log(conf.basePath);
|
||||
// build url
|
||||
const url = new URL(
|
||||
conf.basePath + "/library/" + String(libraryId) + "/query"
|
||||
);
|
||||
// url.searchParams.set("Token", <string>userStore.jwt_token)
|
||||
url.searchParams.set("Question", question.value);
|
||||
url.searchParams.set("LibraryId", String(libraryId));
|
||||
|
||||
let num = 0;
|
||||
|
||||
const eventSource = new EventSourcePolyfill(url.toString(), {
|
||||
headers: {
|
||||
Authorization: "Bearer " + userStore.jwt_token,
|
||||
},
|
||||
});
|
||||
|
||||
eventSource.onmessage = function (event) {
|
||||
// 处理接收到的数据
|
||||
console.log("New message:", event.data);
|
||||
|
||||
if (event.data == "stream_stop") {
|
||||
eventSource.close();
|
||||
querying.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (num === 0) {
|
||||
sources.value = JSON.parse(event.data).sources;
|
||||
console.log(sources.value);
|
||||
num++;
|
||||
return;
|
||||
} else {
|
||||
answer.value += event.data;
|
||||
}
|
||||
};
|
||||
|
||||
eventSource.onerror = function (error) {
|
||||
// 处理错误情况
|
||||
console.error("EventSource failed:", error);
|
||||
eventSource.close();
|
||||
querying.value = false;
|
||||
};
|
||||
}
|
||||
|
||||
libraryApi
|
||||
.librariesGet(libraryId)
|
||||
.then((res) => {
|
||||
library.value = res.data;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<h1>查询 {{ library.Name }}</h1>
|
||||
|
||||
<v-text-field class="mt-3" v-model="question" label="问题" required></v-text-field>
|
||||
|
||||
<v-btn
|
||||
@click="query"
|
||||
:disabled="querying == true"
|
||||
:loading="querying"
|
||||
>查询</v-btn>
|
||||
|
||||
<div v-if="answer" class="mt-3">
|
||||
<h2>结果</h2>
|
||||
<MdPreview :theme="getTheme" :modelValue="answer" />
|
||||
</div>
|
||||
|
||||
<div v-if="sources && sources.length" class="mt-3">
|
||||
<h2>文档源</h2>
|
||||
|
||||
<div v-for="s in sources">
|
||||
{{ s.title }}
|
||||
|
||||
<MdPreview :theme="getTheme" :modelValue="s.text" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
@ -1305,6 +1305,11 @@ esutils@^2.0.2:
|
||||
resolved "https://registry.npmmirror.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
|
||||
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
|
||||
|
||||
event-source-polyfill@^1.0.31:
|
||||
version "1.0.31"
|
||||
resolved "https://registry.npmmirror.com/event-source-polyfill/-/event-source-polyfill-1.0.31.tgz#45fb0a6fc1375b2ba597361ba4287ffec5bf2e0c"
|
||||
integrity sha512-4IJSItgS/41IxN5UVAVuAyczwZF7ZIEsM1XAoUzIHA6A+xzusEZUutdXz2Nr+MQPLxfTiCvqE79/C8HT8fKFvA==
|
||||
|
||||
fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
|
||||
version "3.1.3"
|
||||
resolved "https://registry.npmmirror.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
|
||||
|
Loading…
Reference in New Issue
Block a user