fix(search): 修正路由跳转逻辑
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m5s

- 文档页跳转:当用户点击文档条目是跳转到download路由下的对应页面
- 问题页跳转:当用户点击问题条目时跳转到faq路由并使用focus query控制问题的展开
This commit is contained in:
2025-10-30 14:37:04 +08:00
7 changed files with 45 additions and 5 deletions

View File

@ -124,6 +124,14 @@
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;
};

View File

@ -1,8 +1,9 @@
<template>
<div class="question-list">
<el-collapse class="question-collapse" accordion>
<el-collapse v-model="activeNames" class="question-collapse">
<el-collapse-item
v-for="question in questions"
:id="`q-${question.id}`"
:key="question.id"
:title="question.title"
:name="question.id"
@ -14,12 +15,38 @@
</template>
<script setup lang="ts">
defineProps({
const props = defineProps({
questions: {
type: Array as PropType<ProductQuestionView[]>,
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>
<style scoped>

View File

@ -63,10 +63,11 @@ describe('converters', () => {
title: 'User Manual',
products: ['Product A'],
product_types: ['Type A'],
fileUUID: 'TEST-UUID',
};
const result = converters.product_documents(item);
expect(result).toEqual({
id: 1,
id: 'TEST-UUID',
title: 'User Manual',
summary: undefined,
type: 'document',

View File

@ -28,7 +28,7 @@ export const converters: {
product_documents: (
item: MeiliIndexMap['product_documents']
): SearchItemView => ({
id: item.id,
id: item.fileUUID || item.id,
type: 'document',
title: item.title,
}),

View File

@ -1,6 +1,6 @@
export interface SearchItemView {
/** 唯一标识符 **/
id: number;
id: number | string;
/** 条目类型 **/
type: 'product' | 'solution' | 'question' | 'document';

View File

@ -73,6 +73,9 @@ export interface MeiliProductDocumentIndex {
/** 相关产品类型 **/
product_types: string[];
/** 文件UUID **/
fileUUID: string;
}
/**

View File

@ -1,4 +1,5 @@
import type { SearchResponse } from 'meilisearch';
import type { MeiliSearchItemType } from './meili-index';
/**
* 原始搜索分段结果