Files
schoolNews/schoolNewsWeb/src/views/user/resource-center/ResourceCenterView.vue

151 lines
3.7 KiB
Vue
Raw Normal View History

2025-10-16 18:03:46 +08:00
<template>
2025-10-20 18:28:38 +08:00
<div class="resource-center-view">
2025-10-21 17:59:34 +08:00
<CenterHead
title="资源中心"
2025-10-20 18:28:38 +08:00
:category-name="currentCategoryName"
:show-article-mode="showArticle"
/>
<div class="search-wrapper">
<Search @search="handleSearch" />
2025-10-16 18:03:46 +08:00
</div>
2025-10-20 18:28:38 +08:00
<div class="content-wrapper">
<div class="content-container">
<ResourceSideBar
2025-10-27 16:21:00 +08:00
:activeTagID="currentCategoryId"
2025-10-20 18:28:38 +08:00
@category-change="handleCategoryChange"
/>
<ResourceList
2025-10-27 13:42:34 +08:00
v-if="!showArticle"
2025-10-20 18:28:38 +08:00
ref="resourceListRef"
2025-10-27 16:21:00 +08:00
:tagID="currentCategoryId"
2025-10-20 18:28:38 +08:00
:search-keyword="searchKeyword"
@resource-click="handleResourceClick"
@list-updated="handleListUpdated"
/>
<ResourceArticle
2025-10-27 13:42:34 +08:00
v-if="showArticle"
2025-10-20 18:28:38 +08:00
:resource-id="currentResourceId"
2025-10-27 16:21:00 +08:00
:tagID="currentCategoryId"
2025-10-20 18:28:38 +08:00
:resource-list="resourceList"
@resource-change="handleResourceChange"
@navigate="handleArticleNavigate"
@back-to-list="backToList"
/>
</div>
2025-10-16 18:03:46 +08:00
</div>
</div>
</template>
<script setup lang="ts">
2025-10-20 18:28:38 +08:00
import { ref } from 'vue';
2025-10-21 17:59:34 +08:00
import { ResourceSideBar, ResourceList, ResourceArticle } from './components';
import { Search, CenterHead } from '@/components/base';
2025-10-27 16:21:00 +08:00
import type { Resource, Tag } from '@/types/resource';
2025-10-16 18:03:46 +08:00
2025-10-20 18:28:38 +08:00
const showArticle = ref(false);
const currentCategoryId = ref('party_history');
const currentCategoryName = ref('党史学习');
const currentResourceId = ref('');
const searchKeyword = ref('');
const resourceListRef = ref();
const resourceList = ref<Resource[]>([]);
2025-10-16 18:03:46 +08:00
2025-10-27 16:21:00 +08:00
function handleCategoryChange(category: Tag) {
currentCategoryId.value = category.tagID || category.id || '';
2025-10-20 18:28:38 +08:00
currentCategoryName.value = category.name || '';
searchKeyword.value = '';
showArticle.value = false;
}
2025-10-16 18:03:46 +08:00
2025-10-20 18:28:38 +08:00
function handleSearch(keyword: string) {
searchKeyword.value = keyword;
showArticle.value = false;
}
2025-10-16 18:03:46 +08:00
2025-10-20 18:28:38 +08:00
function handleListUpdated(list: Resource[]) {
resourceList.value = list;
}
2025-10-16 18:03:46 +08:00
2025-10-20 18:28:38 +08:00
function handleResourceClick(resource: Resource) {
currentResourceId.value = resource.resourceID || '';
showArticle.value = true;
2025-10-16 18:03:46 +08:00
}
2025-10-20 18:28:38 +08:00
function handleResourceChange(resourceId: string) {
currentResourceId.value = resourceId;
// ArticleShowView 会自动重新加载
2025-10-16 18:03:46 +08:00
}
2025-10-20 18:28:38 +08:00
function backToList() {
showArticle.value = false;
currentResourceId.value = '';
}
// 文章内前后切换时,靠近列表头部或尾部触发列表翻页
async function handleArticleNavigate(direction: 'prev' | 'next', resourceId: string) {
const list = resourceListRef.value?.getResources?.() || [];
const index = list.findIndex((r: any) => r.resourceID === resourceId);
if (index === -1) return;
const nearHead = index <= 2;
const nearTail = index >= list.length - 3;
if (nearHead && direction === 'prev') {
await resourceListRef.value?.loadPrevPage?.();
} else if (nearTail && direction === 'next') {
await resourceListRef.value?.loadNextPage?.();
2025-10-16 18:03:46 +08:00
}
2025-10-20 18:28:38 +08:00
}
</script>
<style scoped lang="scss">
.resource-center-view {
background: #F9F9F9;
}
.search-wrapper {
width: 100%;
display: flex;
justify-content: center;
padding: 20px 0;
2025-10-16 18:03:46 +08:00
2025-10-20 18:28:38 +08:00
:deep(.resource-search) {
width: 1200px;
height: 60px;
padding: 0;
2025-10-16 18:03:46 +08:00
2025-10-20 18:28:38 +08:00
.search-box {
height: 60px;
input {
font-size: 20px;
padding: 0 100px 0 40px;
}
.search-button {
width: 72px;
height: 60px;
img {
width: 24px;
height: 24px;
}
}
2025-10-16 18:03:46 +08:00
}
}
}
2025-10-20 18:28:38 +08:00
.content-wrapper {
width: 100%;
display: flex;
justify-content: center;
padding-bottom: 60px;
2025-10-16 18:03:46 +08:00
}
2025-10-20 18:28:38 +08:00
.content-container {
width: 1200px;
display: flex;
align-items: flex-start;
gap: 24px;
height: 100%;
}
</style>