knowledge-graph.ts 884 B

1234567891011121314151617181920212223242526272829303132
  1. import { ref, type Ref } from "vue";
  2. import { defineStore } from "pinia";
  3. import * as kgService from "@/services/knowledgeGraph.service";
  4. import * as searchService from "@/services/search.service";
  5. import type { Property } from "@/types/knowledgeGraph.types";
  6. import type { SearchResult } from "@/types/search.types";
  7. export const useKnowledgeGraphStore = defineStore('knowledge-graph', () => {
  8. const property: Ref<Property> = ref({} as Property);
  9. const searchResult: Ref<SearchResult | null> = ref(null);
  10. function fetchProperty(id: number) {
  11. kgService.fetchProperty(id).then((resp) => {
  12. property.value = resp.data.data;
  13. })
  14. }
  15. function search(name: string) {
  16. searchService.search(`TP=("${name}")`).then((resp) => {
  17. searchResult.value = resp.data.data;
  18. });
  19. }
  20. return {
  21. property,
  22. searchResult,
  23. fetchProperty,
  24. search,
  25. }
  26. });