fix: 修正搜索页路由跳转逻辑 #50
@ -124,6 +124,14 @@
|
|||||||
return localePath({ path: `/solutions/${slug}` });
|
return localePath({ path: `/solutions/${slug}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item.type === 'document') {
|
||||||
|
return localePath({ path: `/download/${slug}` });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.type === 'question') {
|
||||||
|
return localePath({ path: `/support/faq`, query: { focus: slug } });
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="question-list">
|
<div class="question-list">
|
||||||
<el-collapse class="question-collapse" accordion>
|
<el-collapse v-model="activeNames" class="question-collapse">
|
||||||
<el-collapse-item
|
<el-collapse-item
|
||||||
v-for="question in questions"
|
v-for="question in questions"
|
||||||
|
:id="`q-${question.id}`"
|
||||||
:key="question.id"
|
:key="question.id"
|
||||||
:title="question.title"
|
:title="question.title"
|
||||||
:name="question.id"
|
:name="question.id"
|
||||||
@ -14,12 +15,38 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
defineProps({
|
const props = defineProps({
|
||||||
questions: {
|
questions: {
|
||||||
type: Array as PropType<ProductQuestionView[]>,
|
type: Array as PropType<ProductQuestionView[]>,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
|
const activeNames = ref<(string | number)[]>([]);
|
||||||
|
|
||||||
|
// 当路由变化(包括初次挂载)时,检查是否需要聚焦
|
||||||
|
watch(
|
||||||
|
() => route.query.focus,
|
||||||
|
async (focusId) => {
|
||||||
|
if (!focusId) return;
|
||||||
|
if (!import.meta.client) return;
|
||||||
|
|
||||||
|
// 确保渲染完成后再操作 DOM
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
const target = props.questions.find((q) => q.id === Number(focusId));
|
||||||
|
if (!target) return;
|
||||||
|
|
||||||
|
// 展开目标项
|
||||||
|
activeNames.value = [target.id];
|
||||||
|
|
||||||
|
// 平滑滚动到对应位置
|
||||||
|
const el = document.querySelector(`#q-${target.id}`);
|
||||||
|
el?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@ -63,10 +63,11 @@ describe('converters', () => {
|
|||||||
title: 'User Manual',
|
title: 'User Manual',
|
||||||
products: ['Product A'],
|
products: ['Product A'],
|
||||||
product_types: ['Type A'],
|
product_types: ['Type A'],
|
||||||
|
fileUUID: 'TEST-UUID',
|
||||||
};
|
};
|
||||||
const result = converters.product_documents(item);
|
const result = converters.product_documents(item);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
id: 1,
|
id: 'TEST-UUID',
|
||||||
title: 'User Manual',
|
title: 'User Manual',
|
||||||
summary: undefined,
|
summary: undefined,
|
||||||
type: 'document',
|
type: 'document',
|
||||||
|
|||||||
@ -28,7 +28,7 @@ export const converters: {
|
|||||||
product_documents: (
|
product_documents: (
|
||||||
item: MeiliIndexMap['product_documents']
|
item: MeiliIndexMap['product_documents']
|
||||||
): SearchItemView => ({
|
): SearchItemView => ({
|
||||||
id: item.id,
|
id: item.fileUUID || item.id,
|
||||||
type: 'document',
|
type: 'document',
|
||||||
title: item.title,
|
title: item.title,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
export interface SearchItemView {
|
export interface SearchItemView {
|
||||||
/** 唯一标识符 **/
|
/** 唯一标识符 **/
|
||||||
id: number;
|
id: number | string;
|
||||||
|
|
||||||
/** 条目类型 **/
|
/** 条目类型 **/
|
||||||
type: 'product' | 'solution' | 'question' | 'document';
|
type: 'product' | 'solution' | 'question' | 'document';
|
||||||
|
|||||||
@ -73,6 +73,9 @@ export interface MeiliProductDocumentIndex {
|
|||||||
|
|
||||||
/** 相关产品类型 **/
|
/** 相关产品类型 **/
|
||||||
product_types: string[];
|
product_types: string[];
|
||||||
|
|
||||||
|
/** 文件UUID **/
|
||||||
|
fileUUID: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { SearchResponse } from 'meilisearch';
|
import type { SearchResponse } from 'meilisearch';
|
||||||
|
import type { MeiliSearchItemType } from './meili-index';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 原始搜索分段结果
|
* 原始搜索分段结果
|
||||||
|
|||||||
Reference in New Issue
Block a user