fix: 修正搜索页路由跳转逻辑 #50

Manually merged
remilia merged 2 commits from fix/search-route into master 2025-10-30 14:37:26 +08:00
7 changed files with 45 additions and 5 deletions
Showing only changes of commit cea67404ed - Show all commits

View File

@ -128,6 +128,10 @@
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>