|
|
@@ -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>
|
|
|
|