Browse Source

添加学科知识图谱service和types

Kevin Jiang 3 years ago
parent
commit
3edfe01101

+ 1 - 1
src/router/index.ts

@@ -63,7 +63,7 @@ const router = createRouter({
         {
           path: "search",
           name: "KnowledgeGraph",
-          component: () => import("../views/knowledge-grapn/KnowLedgeGraphView.vue")
+          component: () => import("../views/knowledge-grapn/KnowledgeGraphView.vue")
         }
       ]
     },

+ 13 - 0
src/services/knowledgeGraph.service.ts

@@ -0,0 +1,13 @@
+import type { AxiosResponse } from "axios";
+import httpClient from "./httpClient";
+import type { Response } from "@/types/response.types";
+import type { Property } from "@/types/knowledgeGraph.types";
+
+/**
+ * 根据学科ID查询学科属性
+ * @param id 学科ID
+ * @returns 学科属性
+ */
+export function fetchProperty(id: number): Promise<AxiosResponse<Response<Property>>> {
+  return httpClient.get(`/knowledgeGraph/property/${id}`);
+}

+ 1 - 5
src/services/search.service.ts

@@ -3,11 +3,7 @@ import type { Response } from "@/types/response.types";
 import type { AxiosResponse } from "axios";
 import httpClient from "./httpClient";
 
-function search(query: string): Promise<AxiosResponse<Response<SearchResult>>> {
+export function search(query: string): Promise<AxiosResponse<Response<SearchResult>>> {
   const params = { query };
   return httpClient.post("/search", params);
 }
-
-export default {
-  search,
-}

+ 31 - 0
src/stores/knowledge-graph.ts

@@ -0,0 +1,31 @@
+import { ref, type Ref } from "vue";
+import { defineStore } from "pinia";
+import * as kgService from "@/services/knowledgeGraph.service";
+import * as searchService from "@/services/search.service";
+import type { Property } from "@/types/knowledgeGraph.types";
+import type { SearchResult } from "@/types/search.types";
+
+export const useKnowledgeGraphStore = defineStore('knowledge-graph', () => {
+  const property: Ref<Property> = ref({} as Property);
+
+  const searchResult: Ref<SearchResult | null> = ref(null);
+
+  function fetchProperty(id: number) {
+    kgService.fetchProperty(id).then((resp) => {
+      property.value = resp.data.data;
+    })
+  }
+
+  function search(name: string) {
+    searchService.search(`TP=("${name}")`).then((resp) => {
+      searchResult.value = resp.data.data;
+    });
+  }
+
+  return {
+    property,
+    searchResult,
+    fetchProperty,
+    search,
+  }
+});

+ 5 - 0
src/types/knowledgeGraph.types.ts

@@ -0,0 +1,5 @@
+export interface Property {
+  name: string,
+  docCount: number,
+  keywords: {[index: string]: number}
+}

+ 1 - 1
src/views/knowledge-grapn/KnowLedgeGraphView.vue

@@ -95,7 +95,7 @@ onMounted(() => {
 <template>
   <div class="search-box">
     <a-input-search
-      :value="keyword"
+      v-model:value="keyword"
       placeholder="请输入关键词进行搜索"
       enter-button="查&nbsp;&nbsp;询"
       size="large"

+ 1 - 1
src/views/search/SearchResultView.vue

@@ -2,7 +2,7 @@
 import { onUnmounted, ref, type Ref, onMounted } from "vue";
 import { useRoute, useRouter } from "vue-router";
 import { useSideBarStore } from "@/stores/side-bar";
-import searchService from "@/services/search.service";
+import * as searchService from "@/services/search.service";
 import type { SearchResult } from "@/types/search.types";
 import SearchBox from "./components/SearchBox.vue";
 import SearchResultToolbar from "./components/SearchResultToolbar.vue";