Browse Source

feature 1001555

章节搜索默认传入的关键词列表搜索实现
Kevin Jiang 2 years ago
parent
commit
92b3b2333b

+ 3 - 3
src/client/chapterSearch.client.ts

@@ -1,11 +1,11 @@
 import httpClient from "@/services/httpClient";
 import type { Response } from "@/types/response.types"
-import type { ChapterSearchReqeust, ChapterSearchResponse } from "@/types/search.types";
+import type { ChapterSearchRequest, ChapterSearchResponse } from "@/types/search.types";
 import * as urlHelper from "@/helpers/url.helper"
 
-const _url = urlHelper.withPrefix("/gw/chapter/search")
+const _url = urlHelper.withPrefix("/gw/search/chapter/search")
 
-export async function search(request: ChapterSearchReqeust): Promise<ChapterSearchResponse> {
+export async function search(request: ChapterSearchRequest): Promise<ChapterSearchResponse> {
   const resp = await httpClient.post<Response<ChapterSearchResponse>>(_url(), request);
   return resp.data.data;
 }

+ 2 - 2
src/services/chapterSearch.service.ts

@@ -1,6 +1,6 @@
 import * as chapterSearchClient from "@/client/chapterSearch.client"
-import type { ChapterSearchReqeust, ChapterSearchResponse } from "@/types/search.types"
+import type { ChapterSearchRequest, ChapterSearchResponse } from "@/types/search.types"
 
-export async function search(request: ChapterSearchReqeust): Promise<ChapterSearchResponse> {
+export async function search(request: ChapterSearchRequest): Promise<ChapterSearchResponse> {
   return chapterSearchClient.search(request);
 }

+ 12 - 3
src/types/search.types.ts

@@ -34,19 +34,28 @@ export type Sort = 'Relevance' | 'DateDesc' | 'DateAsc' | 'CitedDesc';
 
 export type ResultMode = 'brief' | 'detail';
 
-export interface ChapterSearchReqeust {
-  from: number;
-  size: number;
+export interface ChapterSearchRequest {
+  from?: number;
+  size?: number;
   keywords: string[];
 }
 
+export interface UnitScholar {
+  unitName: string;
+  unitScholarName: string;
+  scholarName: string;
+}
+
 export interface ChapterSearchDocResponse {
   id: string;
   score: number;
   filename: string;
   section: string;
   parentSearch: string;
+  title: string;
+  keywords: string[];
   content: string;
+  unitScholars: UnitScholar[];
   page: number;
   orderNum: number;
 }

+ 1 - 1
src/views/report/components/ChapterEditor.vue

@@ -128,7 +128,7 @@ function searchReference() {
       </a-space>
     </div>
   </div>
-  <ReferenceDraw :keywords="keywords" ref="referenceDraw" />
+  <ReferenceDraw :keywords="data.keywords || []" ref="referenceDraw" />
 </template>
 
 <style scoped lang="scss">

+ 35 - 20
src/views/report/components/reference/ReferenceDraw.vue

@@ -4,9 +4,12 @@
 import { ref, type Ref } from "vue";
 import ReferenceSearchBox from "./ReferenceSearchBox.vue";
 import ReferenceSearchResultItem from "./ReferenceSearchResultItem.vue";
-import type { RefereceSearchResultItem } from "./reference.type";
+import type { ChapterSearchDocResponse, ChapterSearchRequest } from "@/types/search.types"
+import * as chapterSearchService from "@/services/chapterSearch.service"
+import { CompLog } from "@/helpers/log.helper";
+import SpinComponent from "@/components/SpinComponent.vue";
 
-defineProps({
+const props = defineProps({
   keywords: {
     type: Array<String>,
     required: true,
@@ -14,21 +17,26 @@ defineProps({
 });
 
 const visible = ref<boolean>(false);
+// 章节搜索结果总数量
+const total = ref(0)
+// 章节搜索结果
+const referenceSearchResult: Ref<ChapterSearchDocResponse[]> = ref([]);
+// 章节搜索状态
+const loading = ref(false)
 
-const referenceSearchResult: Ref<RefereceSearchResultItem[]> = ref([
-  {
-    title: '标题',
-    author: '作者',
-    unit: '作者单位',
-    content: '内容'
-  },
-  {
-    title: '标题',
-    author: '作者',
-    unit: '作者单位',
-    content: '内容'
-  },
-]);
+function search(keywords: string[]) {
+  loading.value = true
+  const request: ChapterSearchRequest = { keywords }
+  chapterSearchService.search(request).then((resp) => {
+    console.log(resp)
+    loading.value = false
+    total.value = resp.total
+    referenceSearchResult.value = resp.items
+  }).catch((err) => {
+    CompLog.logErr("ReferenceDraw")(err)
+    loading.value = false
+  })
+}
 
 const onClose = () => {
   visible.value = false;
@@ -36,6 +44,11 @@ const onClose = () => {
 
 const show = () => {
   visible.value = true;
+  const keywords = props.keywords
+  console.log('keywords', keywords)
+  if (keywords && keywords.length > 0) {
+    search(keywords as string[])
+  }
 };
 
 defineExpose({
@@ -55,10 +68,12 @@ defineExpose({
   >
     <ReferenceSearchBox />
     <a-divider />
-    <div v-for="(item, index) in referenceSearchResult" :key="index">
-      <ReferenceSearchResultItem :data="item" />
-      <a-divider class="result-item-divider" v-if="index < referenceSearchResult.length - 1" />
-    </div>
+    <SpinComponent :spinning="loading">
+      <div v-for="(item, index) in referenceSearchResult" :key="index">
+        <ReferenceSearchResultItem :data="item" />
+        <a-divider class="result-item-divider" v-if="index < referenceSearchResult.length - 1" />
+      </div>
+    </SpinComponent>
   </a-drawer>
 </template>
 

+ 6 - 4
src/views/report/components/reference/ReferenceSearchResultItem.vue

@@ -1,10 +1,10 @@
 <script setup lang="ts">
+import type { ChapterSearchDocResponse } from "@/types/search.types";
 import type { PropType } from "vue";
-import type { RefereceSearchResultItem } from "./reference.type";
 
 defineProps({
   data: {
-    type: Object as PropType<RefereceSearchResultItem>,
+    type: Object as PropType<ChapterSearchDocResponse>,
     required: true
   }
 });
@@ -12,10 +12,12 @@ defineProps({
 
 <template>
   <h3>{{ data.title }}</h3>
+  <h4>{{ data.section }}</h4>
   <div class="meta">
     <a-space>
-      <span>{{ data.author }}</span>
-      <span>{{ data.unit }}</span>
+      <span v-for="(item, index) in data.unitScholars" :key="index">
+        {{ item.scholarName }} {{ item.unitName }}
+      </span>
     </a-space>
   </div>
   <div class="content">

+ 0 - 7
src/views/report/components/reference/reference.type.ts

@@ -1,7 +0,0 @@
-
-export interface RefereceSearchResultItem {
-  title: string;
-  author: string;
-  unit: string;
-  content: string;
-}