导航栏特殊列
This commit is contained in:
@@ -37,11 +37,15 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { ref, onMounted, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { ResourceSideBar, ResourceList, ResourceArticle } from './components';
|
||||
import { Search, CenterHead } from '@/components/base';
|
||||
import type { Resource, Tag } from '@/types/resource';
|
||||
import { resourceApi } from '@/apis/resource';
|
||||
import { resourceApi, resourceTagApi } from '@/apis/resource';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const showArticle = ref(false);
|
||||
const currentCategoryId = ref('tag_article_001');
|
||||
@@ -51,16 +55,59 @@ const searchKeyword = ref('');
|
||||
const resourceListRef = ref();
|
||||
const resourceList = ref<Resource[]>([]);
|
||||
|
||||
// 组件加载时检查 URL 参数
|
||||
onMounted(async () => {
|
||||
const tagID = route.query.tagID as string;
|
||||
if (tagID) {
|
||||
await loadTagInfo(tagID);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听路由参数变化
|
||||
watch(() => route.query.tagID, async (newTagID) => {
|
||||
if (newTagID && typeof newTagID === 'string') {
|
||||
await loadTagInfo(newTagID);
|
||||
}
|
||||
});
|
||||
|
||||
// 加载标签信息
|
||||
async function loadTagInfo(tagID: string) {
|
||||
try {
|
||||
const res = await resourceTagApi.getTagsByType(1); // 1 = 文章分类标签
|
||||
if (res.success && res.dataList) {
|
||||
const tag = res.dataList.find((t: Tag) => t.tagID === tagID);
|
||||
if (tag) {
|
||||
currentCategoryId.value = tag.tagID || '';
|
||||
currentCategoryName.value = tag.name || '';
|
||||
searchKeyword.value = '';
|
||||
showArticle.value = false;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载标签信息失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function handleCategoryChange(category: Tag) {
|
||||
currentCategoryId.value = category.tagID || category.id || '';
|
||||
currentCategoryName.value = category.name || '';
|
||||
searchKeyword.value = '';
|
||||
showArticle.value = false;
|
||||
|
||||
// 清除 URL 中的 tagID 参数,确保 URL 与实际显示的分类一致
|
||||
if (route.query.tagID) {
|
||||
router.replace({ path: route.path, query: {} });
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch(keyword: string) {
|
||||
searchKeyword.value = keyword;
|
||||
showArticle.value = false;
|
||||
|
||||
// 清除 URL 中的 tagID 参数
|
||||
if (route.query.tagID) {
|
||||
router.replace({ path: route.path, query: {} });
|
||||
}
|
||||
}
|
||||
|
||||
function handleListUpdated(list: Resource[]) {
|
||||
|
||||
Reference in New Issue
Block a user