refactor(前端): 重构前端代码结构并优化功能
重构路由配置和API调用逻辑,统一分页处理方式 优化分类和标签模块的交互,提取蒙版组件到主布局 调整样式和布局,增强响应式设计 更新接口字段名以保持前后端一致性 添加网站运行时间显示功能
This commit is contained in:
@@ -51,13 +51,13 @@
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<a href="#" class="stat-link" @click.prevent="showCategories">
|
||||
<a href="#" class="stat-link" @click.prevent="showCategoriesModel">
|
||||
<span class="site-state-item-count">{{ categoryCount }}</span>
|
||||
<span class="site-state-item-name">分类</span>
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<a href="#" class="stat-link" @click.prevent="showAttributes">
|
||||
<a href="#" class="stat-link" @click.prevent="showAttributesModel">
|
||||
<span class="site-state-item-count">{{ AttributeCount }}</span>
|
||||
<span class="site-state-item-name">标签</span>
|
||||
</a>
|
||||
@@ -70,49 +70,7 @@
|
||||
</el-tabs>
|
||||
</div>
|
||||
|
||||
<!-- 分类蒙板组件 -->
|
||||
<Transition name="modal">
|
||||
<div v-if="showCategoryModal" class="category-modal" @click.self="closeCategoryModal">
|
||||
<div class="category-modal-content">
|
||||
<div class="category-modal-header">
|
||||
<h3>所有分类</h3>
|
||||
<button class="category-modal-close" @click="closeCategoryModal">×</button>
|
||||
</div>
|
||||
<div class="category-modal-body">
|
||||
<button
|
||||
v-for="category in categories"
|
||||
:key="category.typeid"
|
||||
class="category-button"
|
||||
@click="handleCategoryClick(category)"
|
||||
>
|
||||
{{ category.typename }} <span class="category-button-count">({{ category.count || 0 }})</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
|
||||
<!-- 标签蒙板组件 -->
|
||||
<Transition name="modal">
|
||||
<div v-if="showAttributeModal" class="category-modal" @click.self="closeAttributeModal">
|
||||
<div class="category-modal-content">
|
||||
<div class="category-modal-header">
|
||||
<h3>所有标签</h3>
|
||||
<button class="category-modal-close" @click="closeAttributeModal">×</button>
|
||||
</div>
|
||||
<div class="category-modal-body">
|
||||
<button
|
||||
v-for="attribute in attributes"
|
||||
:key="attribute.attributeid"
|
||||
class="category-button"
|
||||
@click="handleAttributeClick(attribute)"
|
||||
>
|
||||
{{ attribute.attributename }} <span class="category-button-count">({{ attribute.count || 0 }})</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -120,8 +78,6 @@
|
||||
import { reactive, ref, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { articleService, categoryService, categoryAttributeService } from "@/services";
|
||||
import { useGlobalStore } from '@/store/globalStore'
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
// 当前激活菜单
|
||||
const activeIndex = ref('/:type')
|
||||
@@ -134,13 +90,10 @@ const state = reactive({
|
||||
})
|
||||
|
||||
// 分类相关状态
|
||||
const categories = ref<any[]>([])
|
||||
const showCategoryModal = ref(false)
|
||||
// defineEmits
|
||||
const emit = defineEmits(['update-data', 'CategoryModal', 'AttributeModal'])
|
||||
|
||||
// 标签相关状态
|
||||
const attributes = ref<any[]>([])
|
||||
const showAttributeModal = ref(false)
|
||||
|
||||
// 处理菜单选择跳转
|
||||
const handleSelect = (key: string) => {
|
||||
router.push({ path: key })
|
||||
@@ -171,6 +124,9 @@ const fetchArticleCount = async () => {
|
||||
|
||||
// 获取分类数据
|
||||
const fetchCategories = async () => {
|
||||
|
||||
// 分类数据状态
|
||||
const categories = ref<any[]>([])
|
||||
try {
|
||||
const response = await categoryService.getAllCategories();
|
||||
// 如果API返回的数据结构不包含count属性,我们可以模拟一些数据
|
||||
@@ -179,7 +135,7 @@ const fetchCategories = async () => {
|
||||
count: 0
|
||||
})) || [];
|
||||
categories.value.forEach(async (category: any) => {
|
||||
const attributeResponse = await categoryAttributeService.getAttributesByCategory(category.typeid)
|
||||
const attributeResponse = await categoryAttributeService.getAttributesByCategory(category.categoryid)
|
||||
if (attributeResponse.data?.length) {
|
||||
category.count = attributeResponse.data?.length || 0
|
||||
}
|
||||
@@ -194,10 +150,13 @@ const fetchCategories = async () => {
|
||||
];
|
||||
categoryCount.value = categories.value.length
|
||||
}
|
||||
return categories.value
|
||||
}
|
||||
|
||||
// 获取标签数据
|
||||
const fetchAttributes = async () => {
|
||||
// 标签数据状态
|
||||
const attributes = ref<any[]>([])
|
||||
try {
|
||||
const response = await categoryAttributeService.getAllAttributes();
|
||||
// 如果API返回的数据结构不包含count属性,我们可以模拟一些数据
|
||||
@@ -216,56 +175,27 @@ const fetchAttributes = async () => {
|
||||
console.error('获取标签失败:', error)
|
||||
// 如果API调用失败,使用模拟数据
|
||||
attributes.value = [
|
||||
|
||||
];
|
||||
AttributeCount.value = attributes.value.length
|
||||
}
|
||||
return attributes.value
|
||||
}
|
||||
|
||||
// 显示分类蒙板
|
||||
const showCategories = () => {
|
||||
showCategoryModal.value = true
|
||||
// 向父组件传递标签数据
|
||||
const sendData = () => {
|
||||
const data = { fetchAttributes: fetchAttributes(), fetchCategories: fetchCategories() }
|
||||
emit('update-data', data)
|
||||
}
|
||||
|
||||
// 关闭分类蒙板
|
||||
const closeCategoryModal = () => {
|
||||
showCategoryModal.value = false
|
||||
// 显示标签蒙版
|
||||
const showAttributesModel = () => {
|
||||
emit('AttributeModal', { ifmodal: true })
|
||||
}
|
||||
// 显示分类蒙版
|
||||
const showCategoriesModel = () => {
|
||||
emit('CategoryModal', { ifmodal: true })
|
||||
}
|
||||
|
||||
// 处理分类点击
|
||||
const handleCategoryClick = (category: any) => {
|
||||
// 这里可以根据实际需求跳转到对应分类的文章列表页
|
||||
console.log('点击了分类:', category.typename)
|
||||
// 示例:router.push(`/article-list?category=${category.typeid}`)
|
||||
closeCategoryModal()
|
||||
}
|
||||
|
||||
// 显示标签蒙板
|
||||
const showAttributes = () => {
|
||||
showAttributeModal.value = true
|
||||
}
|
||||
|
||||
// 关闭标签蒙板
|
||||
const closeAttributeModal = () => {
|
||||
showAttributeModal.value = false
|
||||
}
|
||||
|
||||
// 处理标签点击
|
||||
const handleAttributeClick = (attribute: any) => {
|
||||
// 重置全局属性状态
|
||||
globalStore.removeValue('attribute')
|
||||
|
||||
globalStore.setValue('attribute', {
|
||||
id: attribute.attributeid,
|
||||
name: attribute.attributename
|
||||
})
|
||||
console.log(attribute)
|
||||
router.push({
|
||||
path: '/home/aericletype',
|
||||
|
||||
})
|
||||
closeAttributeModal()
|
||||
}
|
||||
|
||||
// 控制底部模块吸顶效果
|
||||
const scrollY = ref(false)
|
||||
@@ -277,8 +207,7 @@ const handleScroll = () => {
|
||||
onMounted(() => {
|
||||
window.addEventListener('scroll', handleScroll)
|
||||
fetchArticleCount() // 组件挂载时获取文章数量
|
||||
fetchCategories() // 组件挂载时获取分类数据
|
||||
fetchAttributes() // 组件挂载时获取标签数据
|
||||
sendData() // 组件挂载时获取标签数据和分类数据
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
@@ -314,15 +243,17 @@ onUnmounted(() => {
|
||||
|
||||
/* 内容区域样式 */
|
||||
#cont {
|
||||
padding:0 0 10px 0;
|
||||
padding: 0 0 10px 0;
|
||||
border-radius: 10px;
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
/* 白色半透明背景 */
|
||||
}
|
||||
#cont .cont1{
|
||||
|
||||
#cont .cont1 {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
#cont .cont2{
|
||||
|
||||
#cont .cont2 {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
@@ -349,16 +280,12 @@ onUnmounted(() => {
|
||||
background-color: rgba(0, 0, 0, 0);
|
||||
/* 白色半透明背景 */
|
||||
}
|
||||
|
||||
.cont2 .el-menu-vertical-demo li {
|
||||
font-size: 14px;
|
||||
height: 35px;
|
||||
}
|
||||
|
||||
.cont2 .el-menu-vertical-demo .el-menu-item:nth-child(3) {
|
||||
/* border-radius: 0 0 10px 10px; */
|
||||
/* margin-bottom: 10px; */
|
||||
}
|
||||
|
||||
.cont2 .el-menu-vertical-demo .el-menu-item:hover {
|
||||
background-color: rgba(64, 158, 255, 0.9);
|
||||
}
|
||||
@@ -429,6 +356,7 @@ onUnmounted(() => {
|
||||
/* 白色半透明背景 */
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.site-state-item-count {
|
||||
display: block;
|
||||
text-align: center;
|
||||
@@ -444,9 +372,11 @@ onUnmounted(() => {
|
||||
margin-left: 100px;
|
||||
padding: 10px 20px;
|
||||
}
|
||||
|
||||
.mylogo_name {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.mylogo_description {
|
||||
font-size: 13px;
|
||||
opacity: 0.8;
|
||||
@@ -508,145 +438,6 @@ onUnmounted(() => {
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
/* 分类蒙板样式 */
|
||||
.category-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
/* 确保在任何情况下都能居中显示 */
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.category-modal-content {
|
||||
background-color: white;
|
||||
border-radius: 10px;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
max-height: 80vh;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
||||
/* 确保内容块在父容器中完美居中 */
|
||||
}
|
||||
|
||||
.category-modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px 20px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.category-modal-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.category-modal-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: #999;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.category-modal-close:hover {
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.category-modal-body {
|
||||
padding: 20px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
||||
gap: 12px;
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.category-button {
|
||||
background-color: rgba(102, 161, 216, 0.1);
|
||||
border: 1px solid rgba(102, 161, 216, 0.3);
|
||||
border-radius: 6px;
|
||||
padding: 10px 15px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.category-button:hover {
|
||||
background-color: rgba(102, 161, 216, 0.3);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 2px 8px rgba(102, 161, 216, 0.2);
|
||||
}
|
||||
|
||||
.category-button-count {
|
||||
font-size: 12px;
|
||||
color: #66a1d8;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 蒙板动画 */
|
||||
.modal-enter-active,
|
||||
.modal-leave-active {
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-enter-from,
|
||||
.modal-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.modal-enter-active .category-modal-content,
|
||||
.modal-leave-active .category-modal-content {
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-enter-from .category-modal-content {
|
||||
transform: scale(0.9);
|
||||
}
|
||||
|
||||
.modal-leave-to .category-modal-content {
|
||||
transform: scale(0.9);
|
||||
}
|
||||
|
||||
/* 滚动条样式 */
|
||||
.category-modal-body::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.category-modal-body::-webkit-scrollbar-track {
|
||||
background: #f1f1f1;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.category-modal-body::-webkit-scrollbar-thumb {
|
||||
background: #ccc;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.category-modal-body::-webkit-scrollbar-thumb:hover {
|
||||
background: #999;
|
||||
}
|
||||
</style>
|
||||
@@ -63,18 +63,54 @@
|
||||
|
||||
<!-- 左侧模块 -->
|
||||
<div class="leftmodluecontainer" v-if="isleftmodluecontainer">
|
||||
<LeftModule class="leftmodluepage" :class="{ 'nonsensetmargintop': classmoduleorrouter }" v-if="windowwidth" />
|
||||
<LeftModule class="leftmodluepage" @update-data="updateData" @CategoryModal="CategoryModal"
|
||||
@AttributeModal="AttributeModal" :class="{ 'nonsensetmargintop': classmoduleorrouter }" v-if="windowwidth" />
|
||||
</div>
|
||||
|
||||
<!-- 内容模块 -->
|
||||
<RouterView class="RouterViewpage"
|
||||
:class="{ 'forbidwidth': !isleftmodluecontainer, 'nonsensetmargintop': classmoduleorrouter }" />
|
||||
</div>
|
||||
|
||||
<!-- 分页区域 -->
|
||||
<Establish class="establish-container" v-if="Login" />
|
||||
<div class="RouterViewpage">
|
||||
<RouterView :class="{ 'forbidwidth': !isleftmodluecontainer, 'nonsensetmargintop': classmoduleorrouter }" />
|
||||
<!-- 页脚 -->
|
||||
<Footer class="footer-container" v-if="windowwidth" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- 分类蒙板组件 -->
|
||||
<Transition name="modal">
|
||||
<div v-if="showCategoryModal" class="category-modal" @click.self="closeCategoryModal">
|
||||
<div class="category-modal-content">
|
||||
<div class="category-modal-header">
|
||||
<h3>所有分类</h3>
|
||||
<button class="category-modal-close" @click="closeCategoryModal">×</button>
|
||||
</div>
|
||||
<div class="category-modal-body">
|
||||
<button v-for="category in categories" :key="category.typeid" class="category-button"
|
||||
@click="handleCategoryClick(category)">
|
||||
{{ category.typename }} <span class="category-button-count">({{ category.count || 0 }})</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
|
||||
<!-- 标签蒙板组件 -->
|
||||
<Transition name="modal">
|
||||
<div v-if="showAttributeModal" class="category-modal" @click.self="closeAttributeModal">
|
||||
<div class="category-modal-content">
|
||||
<div class="category-modal-header">
|
||||
<h3>所有标签</h3>
|
||||
<button class="category-modal-close" @click="closeAttributeModal">×</button>
|
||||
</div>
|
||||
<div class="category-modal-body">
|
||||
<button v-for="attribute in attributes" :key="attribute.attributeid" class="category-button"
|
||||
@click="handleAttributeClick(attribute)">
|
||||
{{ attribute.attributename }} <span class="category-button-count">({{ attribute.count || 0 }})</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
<!-- 管理员 -->
|
||||
<Establish class="establish-container" v-if="Login" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -96,7 +132,6 @@ const globalStore = useGlobalStore();
|
||||
const Login = computed(() => globalStore.Login);
|
||||
|
||||
// ========== 响应式状态定义 ==========
|
||||
|
||||
// 页面标题和样式相关状态
|
||||
const Cardtitle = ref('');
|
||||
const classmoduleorrouter = ref(false);
|
||||
@@ -137,6 +172,96 @@ const heroText = ref('');
|
||||
let heroIndex = 0;
|
||||
let heroTimer: number | undefined;
|
||||
|
||||
// 蒙版相关状态
|
||||
const categories = ref<any[]>([])
|
||||
const showCategoryModal = ref(false)
|
||||
const attributes = ref<any[]>([])
|
||||
const showAttributeModal = ref(false)
|
||||
// 显示分类蒙板
|
||||
const openCategoryModal = () => {
|
||||
showCategoryModal.value = true;
|
||||
}
|
||||
// 关闭分类蒙板
|
||||
const closeCategoryModal = () => {
|
||||
showCategoryModal.value = false;
|
||||
}
|
||||
// 显示标签蒙板
|
||||
const openAttributeModal = () => {
|
||||
showAttributeModal.value = true;
|
||||
}
|
||||
// 关闭标签蒙板
|
||||
const closeAttributeModal = () => {
|
||||
showAttributeModal.value = false;
|
||||
}
|
||||
// 左侧状态栏传值
|
||||
const updateData = (data: any) => {
|
||||
// 处理异步数据
|
||||
if (data.fetchCategories && typeof data.fetchCategories.then === 'function') {
|
||||
data.fetchCategories.then(result => {
|
||||
categories.value = result || []
|
||||
})
|
||||
} else {
|
||||
categories.value = data.fetchCategories || []
|
||||
}
|
||||
if (data.fetchAttributes && typeof data.fetchAttributes.then === 'function') {
|
||||
data.fetchAttributes.then(result => {
|
||||
attributes.value = result || []
|
||||
})
|
||||
} else {
|
||||
attributes.value = data.fetchAttributes || []
|
||||
}
|
||||
}
|
||||
// 分类相关状态
|
||||
const CategoryModal = async (data: any) => {
|
||||
if (data.ifmodal) {
|
||||
openCategoryModal()
|
||||
// console.log('打开分类蒙板')
|
||||
} else {
|
||||
closeCategoryModal()
|
||||
// console.log('关闭分类蒙板')
|
||||
}
|
||||
}
|
||||
// 标签相关状态
|
||||
const AttributeModal = async (data: any) => {
|
||||
if (data.ifmodal) {
|
||||
openAttributeModal()
|
||||
// console.log('打开标签蒙板')
|
||||
} else {
|
||||
closeAttributeModal()
|
||||
// console.log('关闭标签蒙板')
|
||||
}
|
||||
}
|
||||
// ========== 蒙版事件 ==========
|
||||
|
||||
// 处理分类点击
|
||||
const handleCategoryClick = (category: any) => {
|
||||
// 这里可以根据实际需求跳转到对应分类的文章列表页
|
||||
// 重置全局属性状态
|
||||
globalStore.removeValue('category')
|
||||
|
||||
globalStore.setValue('category', {
|
||||
id: category.categoryid,
|
||||
name: category.categoryname
|
||||
})
|
||||
console.log(category)
|
||||
router.push('/home/aericlecategory',)
|
||||
closeCategoryModal()
|
||||
}
|
||||
|
||||
// 处理标签点击
|
||||
const handleAttributeClick = (attribute: any) => {
|
||||
// 重置全局属性状态
|
||||
globalStore.removeValue('attribute')
|
||||
|
||||
globalStore.setValue('attribute', {
|
||||
id: attribute.attributeid,
|
||||
name: attribute.attributename
|
||||
})
|
||||
console.log(attribute)
|
||||
router.push('/home/aericletype',)
|
||||
closeAttributeModal()
|
||||
}
|
||||
|
||||
// ========== 打字机效果模块 ==========
|
||||
|
||||
/**
|
||||
@@ -226,15 +351,14 @@ const updatePageState = () => {
|
||||
*/
|
||||
const updateArticleTitle = () => {
|
||||
let articledata: any = null;
|
||||
|
||||
// 根据不同路由参数获取文章标题数据
|
||||
if (rpsliturl[2] === 'aericletype') {
|
||||
if (rpsliturl[2] === 'aericleattribute') {
|
||||
// 按属性类型获取
|
||||
articledata = globalStore.getValue('attribute')?.name;
|
||||
}
|
||||
else if (rpsliturl[2] === 'aericletitle') {
|
||||
// 按标题搜索获取
|
||||
articledata = globalStore.getValue('title')?.name;
|
||||
articledata = globalStore.getValue('articleserarch')?.name;
|
||||
}
|
||||
else if (rpsliturl[1] === 'nonsense') {
|
||||
// 疯言疯语页面特殊处理
|
||||
@@ -244,7 +368,7 @@ const updateArticleTitle = () => {
|
||||
// 确定标题区域的显示状态
|
||||
const shouldHideTitle =
|
||||
// 特殊页面不需要显示标题
|
||||
(rpsliturl[1] === 'article-list' ||
|
||||
(rpsliturl[1] === 'articlelist' ||
|
||||
rpsliturl[1] === 'message' ||
|
||||
rpsliturl[1] === 'about') ||
|
||||
// 在主页且无标题数据时,不显示标题
|
||||
@@ -304,11 +428,12 @@ const closeSearchBoxWithDelay = () => {
|
||||
const performSearch = () => {
|
||||
// 验证搜索关键词不为空
|
||||
if (searchKeyword.value.trim()) {
|
||||
// 清除全局搜索关键词
|
||||
globalStore.removeValue('articleserarch');
|
||||
// 存储搜索关键词到全局状态
|
||||
globalStore.setValue('articleserarch', {
|
||||
name: searchKeyword.value
|
||||
});
|
||||
|
||||
// 跳转到搜索结果页面
|
||||
router.push({ path: `/home/aericletitle` });
|
||||
}
|
||||
@@ -326,6 +451,7 @@ const performSearch = () => {
|
||||
* 根据屏幕宽度调整布局和内容显示
|
||||
*/
|
||||
const handleResize = () => {
|
||||
|
||||
// 更新窗口宽度状态
|
||||
windowwidth.value = window.innerWidth > 768;
|
||||
|
||||
@@ -333,6 +459,8 @@ const handleResize = () => {
|
||||
if (rpsliturl[1] === localhome) {
|
||||
iscontentvisible.value = window.innerWidth <= 768;
|
||||
}
|
||||
// 移动端首页默认显示内容区,桌面端初始隐藏
|
||||
iscontentvisible.value = window.innerWidth <= 768;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -340,18 +468,28 @@ const handleResize = () => {
|
||||
* 根据滚动位置调整导航栏样式和内容显示动画
|
||||
*/
|
||||
const handleScroll = () => {
|
||||
let scrollY = 0;
|
||||
scrollY = window.scrollY;
|
||||
// 小屏幕设备只切换导航栏样式
|
||||
if (window.innerWidth < 768) {
|
||||
updateNavbarStyle(window.scrollY);
|
||||
if (window.innerWidth <= 768) {
|
||||
updateNavbarStyle(scrollY);
|
||||
return;
|
||||
}
|
||||
|
||||
// 大屏幕设备完整处理
|
||||
updateNavbarStyle(window.scrollY);
|
||||
|
||||
updateNavbarStyle(scrollY);
|
||||
// 仅在首页根路径应用滚动动画
|
||||
if (rpsliturl[1] === localhome && rpsliturl[2] == undefined) {
|
||||
const scrollY = window.scrollY;
|
||||
// 首页滚动动画处理
|
||||
if (scrollY <= 350) {
|
||||
HeroState(scrollY);
|
||||
}
|
||||
// 控制左侧模块的滚动状态
|
||||
isScrollingleftmodlue.value = scrollY > 600;
|
||||
}
|
||||
};
|
||||
// ========== 首页滚动动画模块 ==========
|
||||
const HeroState = (scrollY: number) => {
|
||||
const windowHeight = window.innerHeight;
|
||||
// 计算滚动距离与窗口高度的比例,用于内容渐显
|
||||
const contentScrollRatio = Math.min(scrollY / windowHeight, 1);
|
||||
@@ -364,27 +502,24 @@ const handleScroll = () => {
|
||||
heroTransform.value = `translateY(${translateYValue}px)`;
|
||||
// 当滚动超过100px时开始显示,滚动到一屏高度时完全显示
|
||||
iscontentvisible.value = scrollY > 100;
|
||||
// 当滚动超过287px时logo被顶出屏幕
|
||||
// 当滚动超过287px时logo被顶出屏幕,触发移动状态
|
||||
if (scrollY > 287) {
|
||||
heroPosition.value = 'moving';
|
||||
const translateYValue = Math.min(heroTransformValue - (heroTransformValue * contentScrollRatio * 5), 0);
|
||||
heroTransform.value = `translateY(${translateYValue / 2}px)`;
|
||||
}
|
||||
// 控制左侧模块的滚动状态
|
||||
isScrollingleftmodlue.value = scrollY > 600;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据滚动位置更新导航栏样式
|
||||
* @param {number} scrollY - 当前滚动位置
|
||||
*/
|
||||
const updateNavbarStyle = (scrollY: number) => {
|
||||
// 根据滚动位置设置导航栏样式
|
||||
if (scrollY > 1200) {
|
||||
// 当滚动超过1200px且屏幕宽度大于768px时隐藏导航栏
|
||||
if (scrollY > 1200 && window.innerWidth > 768) {
|
||||
elrowtop.value = 'hide'; // 隐藏导航栏
|
||||
} else {
|
||||
elrowtop.value = scrollY > 100 ? 'solid' : 'transparent'; // 固定或透明样式
|
||||
elrowtop.value = scrollY > 50 ? 'solid' : 'transparent'; // 固定或透明样式
|
||||
}
|
||||
};
|
||||
|
||||
@@ -397,7 +532,6 @@ const updateNavbarStyle = (scrollY: number) => {
|
||||
const handleRouteChange = () => {
|
||||
// 重新解析路由路径
|
||||
rpsliturl = route.path.split('/');
|
||||
console.log(rpsliturl);
|
||||
// 更新页面相关状态
|
||||
updatePageState();
|
||||
setActiveIndex(rpsliturl[1]);
|
||||
@@ -416,8 +550,6 @@ const handleRouteChange = () => {
|
||||
heroTransform.value = `translateY(${heroTransformValue}px)`;
|
||||
heroIsMoving.value = false;
|
||||
heroPosition.value = 'static';
|
||||
// 移动端首页默认显示内容区,桌面端初始隐藏
|
||||
iscontentvisible.value = window.innerWidth <= 768;
|
||||
} else {
|
||||
iscontentvisible.value = true;
|
||||
startTypewriter(fullHeroText);
|
||||
@@ -572,6 +704,135 @@ watch(
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
/* 搜索框样式 */
|
||||
/* ... 现有搜索框样式 ... */
|
||||
|
||||
/* 蒙版样式 */
|
||||
.category-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.category-modal-content {
|
||||
background-color: white;
|
||||
border-radius: 10px;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
max-height: 80vh;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.category-modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px 20px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.category-modal-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.category-modal-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: #999;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.category-modal-close:hover {
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.category-modal-body {
|
||||
padding: 20px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
||||
gap: 12px;
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.category-button {
|
||||
background-color: rgba(102, 161, 216, 0.1);
|
||||
border: 1px solid rgba(102, 161, 216, 0.3);
|
||||
border-radius: 6px;
|
||||
padding: 10px 15px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.category-button:hover {
|
||||
background-color: rgba(102, 161, 216, 0.3);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 2px 8px rgba(102, 161, 216, 0.2);
|
||||
}
|
||||
|
||||
.category-button-count {
|
||||
font-size: 12px;
|
||||
color: #66a1d8;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 蒙板动画 */
|
||||
.modal-enter-active,
|
||||
.modal-leave-active {
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-enter-from,
|
||||
.modal-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.modal-enter-active .category-modal-content,
|
||||
.modal-leave-active .category-modal-content {
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-enter-from .category-modal-content {
|
||||
transform: scale(0.9);
|
||||
}
|
||||
|
||||
.modal-leave-to .category-modal-content {
|
||||
transform: scale(0.9);
|
||||
}
|
||||
|
||||
/* 页脚样式 */
|
||||
.footer-container {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
/* 防止搜索框在小屏幕上重叠 */
|
||||
@media screen and (max-width: 1200px) {
|
||||
.search-box-container.open {
|
||||
|
||||
@@ -25,10 +25,16 @@ const routes = [
|
||||
meta: { title: '首页' },
|
||||
children: [
|
||||
{
|
||||
path: 'aericletype',
|
||||
name: 'homeByType',
|
||||
path: 'aericleattribute',
|
||||
name: 'homeByAttribute',
|
||||
component: HomePage
|
||||
},
|
||||
{
|
||||
path: 'aericlecategory',
|
||||
name: 'homeByCategory',
|
||||
component: HomePage
|
||||
},
|
||||
|
||||
{
|
||||
path: 'aericletitle',
|
||||
name: 'homeByTitle',
|
||||
|
||||
@@ -13,10 +13,17 @@ class ArticleService {
|
||||
* @param size 每页大小(可选,默认为10,最大为100)
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Article[]>>}
|
||||
*/
|
||||
getArticles(params = {}) {
|
||||
return api.get(`/articles/status/page/${params.status}/${params.page}/${params.size}`, { params })
|
||||
getPagedArticles(params = {}) {
|
||||
return api.get(`/articles/status/page?title=${params.title || ''}&categoryid=${params.categoryid || 0}&attributeid=${params.attributeid || 0}&status=${params.status || 1}&page=${params.page || 0}&size=${params.size || 10}`)
|
||||
}
|
||||
/**
|
||||
* 获取分页文章数量
|
||||
* @param {number} status - 文章状态(0:未发表 1:已发表 2:已删除)
|
||||
* @returns {Promise<import('../types').ApiResponse<number>>}
|
||||
*/
|
||||
getArticleCountByStatus(status) {
|
||||
return api.get(`/articles/count/status/${status || 1}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已发布文章列表
|
||||
* @param {import('../types').PaginationParams} params - 查询参数
|
||||
|
||||
@@ -14,11 +14,11 @@ class CategoryService {
|
||||
|
||||
/**
|
||||
* 获取指定分类
|
||||
* @param {number} typeid - 分类ID
|
||||
* @param {number} Categoryid - 分类ID
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Category>>}
|
||||
*/
|
||||
getCategory(typeid) {
|
||||
return api.get(`/categories/${typeid}`)
|
||||
getCategory(Categoryid) {
|
||||
return api.get(`/categories/${Categoryid}`)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,21 +32,21 @@ class CategoryService {
|
||||
|
||||
/**
|
||||
* 更新分类
|
||||
* @param {number} typeid - 分类ID
|
||||
* @param {number} Categoryid - 分类ID
|
||||
* @param {import('../types').CategoryDto} categoryData - 分类数据
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Category>>}
|
||||
*/
|
||||
updateCategory(typeid, categoryData) {
|
||||
return api.put(`/categories/${typeid}`, categoryData)
|
||||
updateCategory(Categoryid, categoryData) {
|
||||
return api.put(`/categories/${Categoryid}`, categoryData)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* @param {number} typeid - 分类ID
|
||||
* @param {number} Categoryid - 分类ID
|
||||
* @returns {Promise<import('../types').ApiResponse<boolean>>}
|
||||
*/
|
||||
deleteCategory(typeid) {
|
||||
return api.delete(`/categories/${typeid}`)
|
||||
deleteCategory(Categoryid) {
|
||||
return api.delete(`/categories/${Categoryid}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,29 @@ class MessageService {
|
||||
return apiService.get(`/messages/${messageid}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取留言数量
|
||||
* @param {number} articleid - 文章ID
|
||||
* @returns {Promise<import('../types').ApiResponse<number>>}
|
||||
*/
|
||||
getMessageCountByArticleId(articleid) {
|
||||
return apiService.get(`/messages/count?articleid=${articleid}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分页留言
|
||||
* @param {number} articleid - 文章ID
|
||||
* @param {number} pagenum - 页码
|
||||
* @param {number} pagesize - 每页数量
|
||||
* @returns {Promise<import('../types').ApiResponse<import('../types').Message[]>>}
|
||||
*/
|
||||
getMessagesByPage(articleid, pagenum, pagesize) {
|
||||
// 如果文章ID不存在,查询所有留言
|
||||
if (!articleid) {
|
||||
return apiService.get(`/messages/page?pageNum=${pagenum}&pageSize=${pagesize}`)
|
||||
}
|
||||
return apiService.get(`/messages/page?articleid=${articleid}&pageNum=${pagenum}&pageSize=${pagesize}`)
|
||||
}
|
||||
/**
|
||||
* 根据文章ID获取留言
|
||||
* @param {number} articleid - 文章ID
|
||||
@@ -57,15 +80,6 @@ class MessageService {
|
||||
return apiService.get(`/messages/search?nickname=${nickname}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章评论数量
|
||||
* @param {number} articleid - 文章ID
|
||||
* @returns {Promise<import('../types').ApiResponse<number>>}
|
||||
*/
|
||||
getMessageCountByArticleId(articleid) {
|
||||
return apiService.get(`/messages/count/article/${articleid}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建留言
|
||||
* @param {import('../types').MessageDto} messageData - 留言数据
|
||||
|
||||
@@ -70,7 +70,7 @@ export interface MessageDto {
|
||||
* 分类类型接口
|
||||
*/
|
||||
export interface Category {
|
||||
typeid: number
|
||||
Categoryid: number
|
||||
typename: string
|
||||
description?: string
|
||||
createdAt?: string
|
||||
@@ -162,7 +162,7 @@ export interface ApiResponse<T = any> {
|
||||
* 分页参数接口
|
||||
*/
|
||||
export interface PaginationParams {
|
||||
page?: number
|
||||
size?: number
|
||||
pagenum?: number
|
||||
pagesize?: number
|
||||
status?: number
|
||||
}
|
||||
@@ -1,30 +1,136 @@
|
||||
<!-- 页脚 -->
|
||||
<template>
|
||||
|
||||
<div class="footer">
|
||||
<div class="footer-content">
|
||||
<p>© 2023 我的网站. 所有权利保留.</p>
|
||||
<p>联系我们:<a href="mailto:xxxx@exxxx.com">xxxx@exxxx.com</a></p>
|
||||
<!-- 备案 -->
|
||||
<p>
|
||||
备案号:<a href="https://beian.miit.gov.cn/" target="_blank">
|
||||
皖ICP备2025105428号-1
|
||||
<!-- 备案信息 -->
|
||||
<p class="footer-beian">
|
||||
备案号:
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer">
|
||||
皖ICP备2025105428号-1 || 皖公网安备34120202001634号
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- 版权信息 -->
|
||||
<p class="footer-copyright">
|
||||
网站所有权利保留 © {{ new Date().getFullYear() }} 清疯不颠
|
||||
</p>
|
||||
|
||||
<!-- 运行时间 -->
|
||||
<p class="footer-runtime">
|
||||
运行时间:<span>{{ runtime }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.footer {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
|
||||
// 运行时间响应式状态
|
||||
const runtime = ref('计算中...')
|
||||
// 网站上线时间 (时间戳)
|
||||
const LAUNCH_DATE = new Date('2025-12-01T00:00:00').getTime()
|
||||
// 定时器引用
|
||||
let runtimeTimer: number | null = null
|
||||
|
||||
/**
|
||||
* 更新网站运行时间
|
||||
*/
|
||||
const updateRuntime = () => {
|
||||
const now = Date.now()
|
||||
const diff = now - LAUNCH_DATE
|
||||
|
||||
// 计算天、时、分、秒
|
||||
const days = Math.floor(diff / 86400000)
|
||||
const hours = Math.floor((diff % 86400000) / 3600000)
|
||||
const minutes = Math.floor((diff % 3600000) / 60000)
|
||||
const seconds = Math.floor((diff % 60000) / 1000)
|
||||
|
||||
// 更新运行时间显示
|
||||
runtime.value = `${days} 天 ${hours} 小时 ${minutes} 分钟 ${seconds} 秒`
|
||||
}
|
||||
|
||||
// 组件挂载时初始化
|
||||
onMounted(() => {
|
||||
// 立即更新一次
|
||||
updateRuntime()
|
||||
// 每秒更新一次
|
||||
runtimeTimer = window.setInterval(updateRuntime, 1000)
|
||||
})
|
||||
|
||||
// 组件卸载时清理定时器
|
||||
onUnmounted(() => {
|
||||
if (runtimeTimer) {
|
||||
clearInterval(runtimeTimer)
|
||||
runtimeTimer = null
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 页脚容器 */
|
||||
.footer {
|
||||
text-align: center;
|
||||
margin-top: 3rem;
|
||||
padding: 2rem 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* 页脚内容 */
|
||||
.footer-content {
|
||||
width: 80%;
|
||||
margin: 0 auto;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 10px;
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem 2rem;
|
||||
box-shadow: 0 2px 15px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
/* 通用段落样式 */
|
||||
.footer-content p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 0.9rem;
|
||||
color: #666;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* 备案信息 */
|
||||
.footer-beian a {
|
||||
color: #409eff;
|
||||
text-decoration: none;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.footer-beian a:hover {
|
||||
color: #66b1ff;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* 版权信息 */
|
||||
.footer-copyright {
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* 运行时间 */
|
||||
.footer-runtime {
|
||||
font-family: 'Courier New', monospace;
|
||||
color: #67c23a;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.footer {
|
||||
margin-top: 2rem;
|
||||
padding: 1rem 0;
|
||||
}
|
||||
|
||||
.footer-content {
|
||||
padding: 1rem;
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.footer-content p {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -18,16 +18,16 @@
|
||||
<div v-else-if="categories.length > 0" class="article-content" id="category-list">
|
||||
<p><strong></strong></p>
|
||||
<div class="alert alert-primary"><strong><span class="alert-inner-text">文章分类如下,点击跳转</span> </strong></div>
|
||||
<div v-for="categoryGroup in categories" :key="categoryGroup.typeid" class="category-group-container">
|
||||
<div v-for="categoryGroup in categories" :key="categoryGroup.Categoryid" class="category-group-container">
|
||||
<div v-if="categoryGroup.attributes.length > 0 && categoryGroup.attributes.some(cat => cat.articles && cat.articles.length > 0)">
|
||||
<h2 id="header-id-1">{{ categoryGroup.typename }}</h2>
|
||||
<!-- 计算该分类组中实际有文章的属性数量 -->
|
||||
<span class="badge badge-primary">共 {{ categoryGroup.attributes.reduce((total, cat) => total + (cat.articles && cat.articles.length ? cat.articles.length : 0), 0) }} 篇</span>
|
||||
<ul class="category-item-list">
|
||||
<div v-for="category in categoryGroup.attributes" :key="category.attributeid">
|
||||
<li v-if="category.articles && category.articles.length > 0">
|
||||
<a class="category-link" @click="handleCategoryClick(category)"><kbd>{{ category.attributename}}</kbd></a>
|
||||
— —({{ category.articles.length }})
|
||||
<div v-for="attribute in categoryGroup.attributes" :key="attribute.attributeid">
|
||||
<li v-if="attribute.articles && attribute.articles.length > 0">
|
||||
<a class="category-link" @click="handleCategoryClick(attribute)"><kbd>{{ attribute.attributename}}</kbd></a>
|
||||
— —({{ attribute.articles.length }})
|
||||
</li>
|
||||
</div>
|
||||
</ul>
|
||||
@@ -78,7 +78,7 @@ const fetchCategories = async () => {
|
||||
// 使用Promise.all等待所有异步操作完成
|
||||
await Promise.all(
|
||||
processedCategories.map(async category => {
|
||||
const attributes = await categoryAttributeService.getAttributesByCategory(category.typeid);
|
||||
const attributes = await categoryAttributeService.getAttributesByCategory(category.categoryid);
|
||||
if (attributes.code === 200 && Array.isArray(attributes.data)) {
|
||||
const processedAttributes = await Promise.all(
|
||||
attributes.data.map(async item => {
|
||||
@@ -116,11 +116,10 @@ const handleCategoryClick = (attribute: any) => {
|
||||
globalStore.removeValue('attribute')
|
||||
globalStore.setValue('attribute', {
|
||||
id: attribute.attributeid,
|
||||
name: attribute.typename
|
||||
name: attribute.attributename
|
||||
})
|
||||
// console.log(attribute)
|
||||
router.push({
|
||||
path: '/home/aericletype',
|
||||
path: '/home/aericleattribute',
|
||||
|
||||
})
|
||||
}
|
||||
@@ -385,7 +384,6 @@ onMounted(() => {
|
||||
|
||||
.article-content {
|
||||
padding: 15px;
|
||||
height: 600px;
|
||||
}
|
||||
|
||||
.category-group-container {
|
||||
|
||||
@@ -483,18 +483,17 @@ onMounted(() => {
|
||||
.error-state-container,
|
||||
.empty-state-container {
|
||||
padding: 20px;
|
||||
margin: 0 15px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.article-main-title {
|
||||
font-size: 1.5rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.article-actions-group {
|
||||
/* 文章操作按钮组 - 右对齐 */
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.article-meta-info {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<!-- 文章列表 -->
|
||||
<transition-group name="article-item" tag="div" class="article-list-content" v-else>
|
||||
<div class="article-card" v-for="article in displayedArticles" :key="article.articleId"
|
||||
<div class="article-card" v-for="article in articleList" :key="article.articleId"
|
||||
@click="handleArticleClick(article)">
|
||||
<h6 class="article-title">{{ article.title }}</h6>
|
||||
<div v-if="article.marked" class="article-special-tag">标记文章</div>
|
||||
@@ -28,7 +28,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- 分页区域 -->
|
||||
<PaginationComponent class="pagination-container" :list="articleList" :pageSize="10" @changePage="handleCurrentDataUpdate" :key="'pagination'" />
|
||||
<el-pagination size="medium" background :layout="pageLayout" v-model:current-page="pageNum" hide-on-single-page="true" @current-change="changePage" :page-size="pageSize" :page-count="totalPages" class="mt-4" />
|
||||
</transition-group>
|
||||
<!-- 空状态 -->
|
||||
<div v-if="!loading && articleList.length === 0" class="empty-state-container">
|
||||
@@ -55,22 +55,24 @@ const globalStore = useGlobalStore()
|
||||
// 路由相关
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
// 分页属性
|
||||
const pageNum = ref(1) // 当前页码
|
||||
const pageSize = ref(10) // 每页数量
|
||||
const totalPages = ref(0) // 总页数
|
||||
const pageLayout = ref('pager, next')// 分页布局
|
||||
|
||||
// 响应式状态
|
||||
const articleList = ref([])
|
||||
const displayedArticles = ref([])
|
||||
const loading = ref(false)
|
||||
|
||||
|
||||
|
||||
// ========== 分页数据处理 ==========
|
||||
|
||||
/**
|
||||
* 处理分页组件的数据更新
|
||||
* @param {Array} data - 分页组件传递的当前页数据
|
||||
*/
|
||||
const handleCurrentDataUpdate = (data) => {
|
||||
displayedArticles.value = data
|
||||
// console.log('更新后的当前页数据:', data)
|
||||
}
|
||||
|
||||
// ========== 文章数据获取模块 ==========
|
||||
|
||||
@@ -84,22 +86,27 @@ const getArticlesByRoute = async () => {
|
||||
// console.log('当前路由分段:', pathSegment)
|
||||
|
||||
switch (pathSegment) {
|
||||
case 'aericletype':
|
||||
case 'aericleattribute':
|
||||
// 按属性类型获取文章
|
||||
const attributeData = globalStore.getValue('attribute')
|
||||
return await articleService.getArticlesByAttributeId(attributeData?.id)
|
||||
return await articleService.getPagedArticles({attributeid: attributeData?.id}, pageNum.value, pageSize.value)
|
||||
case 'aericlecategory':
|
||||
// 按分类类型获取文章
|
||||
const categoryData = globalStore.getValue('category')
|
||||
return await articleService.getPagedArticles({categoryid: categoryData?.id}, pageNum.value, pageSize.value)
|
||||
case 'aericletitle':
|
||||
// 按标题搜索文章
|
||||
const titleData = globalStore.getValue('articleserarch')
|
||||
return await articleService.getArticlesByTitle(titleData?.name)
|
||||
console.log('按标题搜索文章:', titleData.name)
|
||||
return await articleService.getPagedArticles({title: titleData?.name}, pageNum.value, pageSize.value)
|
||||
case 'aericlestatus':
|
||||
// 按状态获取文章
|
||||
const statusData = globalStore.getValue('articlestatus')
|
||||
return await articleService.getArticlesByStatus(statusData?.status)
|
||||
return await articleService.getPagedArticles({status: statusData?.status}, pageNum.value, pageSize.value)
|
||||
default:
|
||||
// 默认获取所有文章
|
||||
// console.log('获取所有文章列表')
|
||||
return await articleService.getAllArticles()
|
||||
return await articleService.getPagedArticles({status: 1}, pageNum.value, pageSize.value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,14 +155,6 @@ const enrichArticlesWithExtraInfo = async (articles) => {
|
||||
return enrichedArticles
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化显示文章列表
|
||||
* @param {Array} articles - 完整文章列表
|
||||
*/
|
||||
const initializeDisplayedArticles = (articles) => {
|
||||
// 初始显示前3条数据
|
||||
displayedArticles.value = articles.slice(0, 3)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章列表主函数
|
||||
@@ -168,28 +167,23 @@ const fetchArticles = async () => {
|
||||
|
||||
// 1. 根据路由获取文章列表
|
||||
response = await getArticlesByRoute()
|
||||
// console.log('更新后的文章列表:', response)
|
||||
|
||||
// 2. 确保数据存在
|
||||
if (!response.data || !Array.isArray(response.data)) {
|
||||
if (!response.data.content || !Array.isArray(response.data.content)) {
|
||||
articleList.value = []
|
||||
displayedArticles.value = []
|
||||
return
|
||||
}
|
||||
|
||||
// 3. 为文章列表补充额外信息
|
||||
const enrichedArticles = await enrichArticlesWithExtraInfo(response.data)
|
||||
const enrichedArticles = await enrichArticlesWithExtraInfo(response.data.content)
|
||||
|
||||
// 4. 更新文章列表
|
||||
articleList.value = enrichedArticles
|
||||
|
||||
// 5. 初始化显示的文章
|
||||
initializeDisplayedArticles(enrichedArticles)
|
||||
|
||||
} catch (error) {
|
||||
console.error('获取文章列表失败:', error)
|
||||
ElMessage.error('获取文章列表失败,请稍后重试')
|
||||
} finally {
|
||||
// console.log('最终文章列表数据:', articleList.value)
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
@@ -222,7 +216,24 @@ const handleArticleClick = (article) => {
|
||||
ElMessage.error('操作失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理分页变化事件
|
||||
* @param {number} newPage - 新的页码
|
||||
*/
|
||||
const changePage = (newPage) => {
|
||||
fetchArticles()
|
||||
// 根据当前页码优化分页布局
|
||||
if (page === 1) {
|
||||
// 第一页只显示页码和下一页按钮
|
||||
pageLayout.value = 'pager, next'
|
||||
} else if (page === totalPages.value) {
|
||||
// 最后一页只显示上一页按钮和页码
|
||||
pageLayout.value = 'prev, pager'
|
||||
} else {
|
||||
// 中间页显示完整的上一页、页码、下一页
|
||||
pageLayout.value = 'prev, pager, next'
|
||||
}
|
||||
}
|
||||
// ========== 生命周期和监听器 ==========
|
||||
|
||||
/**
|
||||
@@ -237,11 +248,6 @@ const handleRouteChange = () => {
|
||||
* 处理文章列表变化的回调函数
|
||||
* @param {Array} newList - 新的文章列表
|
||||
*/
|
||||
const handleArticleListChange = (newList) => {
|
||||
if (newList && newList.length > 0) {
|
||||
displayedArticles.value = newList.slice(0, 3)
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载时获取数据
|
||||
onMounted(() => {
|
||||
@@ -260,7 +266,6 @@ watch(
|
||||
// 监听原始文章列表变化,确保初始数据正确显示
|
||||
watch(
|
||||
() => articleList.value,
|
||||
handleArticleListChange,
|
||||
{ deep: true }
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
<div class="comment-header-info">
|
||||
<!-- 头像 -->
|
||||
<div class="avatar-container">
|
||||
<img v-if="getAvatarUrl(comment.messageimg)" :src="getAvatarUrl(comment.messageimg)" class="user-avatar" alt="头像">
|
||||
<div v-else class="letter-avatar" :style="getLetterAvatarStyle(comment.displayName || comment.nickname)">
|
||||
<img v-if="getAvatarUrl(comment.messageimg)" :src="getAvatarUrl(comment.messageimg)"
|
||||
class="user-avatar" alt="头像">
|
||||
<div v-else class="letter-avatar"
|
||||
:style="getLetterAvatarStyle(comment.displayName || comment.nickname)">
|
||||
{{ getInitialLetter(comment.displayName || comment.nickname) }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -43,8 +45,10 @@
|
||||
<div v-for="reply in comment.replies" :key="reply.messageid" class="reply-item-wrapper">
|
||||
<div class="reply-header-info">
|
||||
<div class="avatar-container">
|
||||
<img v-if="getAvatarUrl(reply.messageimg)" :src="getAvatarUrl(reply.messageimg)" class="user-avatar" alt="头像">
|
||||
<div v-else class="letter-avatar" :style="getLetterAvatarStyle(reply.displayName || reply.nickname)">
|
||||
<img v-if="getAvatarUrl(reply.messageimg)" :src="getAvatarUrl(reply.messageimg)"
|
||||
class="user-avatar" alt="头像">
|
||||
<div v-else class="letter-avatar"
|
||||
:style="getLetterAvatarStyle(reply.displayName || reply.nickname)">
|
||||
{{ getInitialLetter(reply.displayName || reply.nickname) }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -75,7 +79,10 @@
|
||||
还没有留言,快来抢沙发吧!
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 分页按钮 -->
|
||||
<div class="pagination-controls" v-if="totalPages > 1">
|
||||
<el-pagination size="medium" background :layout="pageLayout" v-model:current-page="pageNum" hide-on-single-page="true" @current-change="changePage" :page-size="pageSize" :page-count="totalPages" class="mt-4" />
|
||||
</div>
|
||||
<!-- 留言输入区 -->
|
||||
<div class="comment-form-section">
|
||||
<h2 class="comment-form-title">发送评论(请正确填写邮箱地址,否则将会当成垃圾评论处理)</h2>
|
||||
@@ -133,7 +140,6 @@ import { useGlobalStore } from '@/store/globalStore'
|
||||
import { formatDate } from '@/utils/dateUtils'
|
||||
|
||||
// ============================== 组件初始化 ==============================
|
||||
|
||||
// 定义组件属性
|
||||
const props = defineProps({
|
||||
comments: {
|
||||
@@ -158,7 +164,11 @@ const formRef = ref() // 表单引用
|
||||
const captchaHint = ref('') // 验证码提示
|
||||
const captchaAnswer = ref('') // 验证码答案
|
||||
const showCaptchaHint = ref(false) // 是否显示验证码提示
|
||||
|
||||
// 分页状态
|
||||
const pageNum = ref(1) // 当前页码
|
||||
const pageSize = ref(5) // 每页数量
|
||||
const totalPages = ref(0) // 总页数
|
||||
const pageLayout = ref('pager, next')// 分页布局
|
||||
// 表单数据
|
||||
const form = reactive({
|
||||
parentid: null, // 父留言ID
|
||||
@@ -169,7 +179,6 @@ const form = reactive({
|
||||
email: '', // 邮箱
|
||||
captcha: '' // 验证码
|
||||
})
|
||||
|
||||
// ============================== 表单验证规则 ==============================
|
||||
|
||||
const rules = {
|
||||
@@ -398,7 +407,24 @@ const processReplyDisplayName = (reply, allReplies) => {
|
||||
}
|
||||
|
||||
// ============================== API调用模块 ==============================
|
||||
|
||||
/**
|
||||
* 切换分页
|
||||
* @param {number} page - 目标页码
|
||||
*/
|
||||
const changePage = (page) => {
|
||||
fetchMessages()
|
||||
// 根据当前页码优化分页布局
|
||||
if (page === 1) {
|
||||
// 第一页只显示页码和下一页按钮
|
||||
pageLayout.value = 'pager, next'
|
||||
} else if (page === totalPages.value) {
|
||||
// 最后一页只显示上一页按钮和页码
|
||||
pageLayout.value = 'prev, pager'
|
||||
} else {
|
||||
// 中间页显示完整的上一页、页码、下一页
|
||||
pageLayout.value = 'prev, pager, next'
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 从后端获取留言列表
|
||||
* 根据articleid决定获取文章留言还是全局留言
|
||||
@@ -411,13 +437,13 @@ const fetchMessages = async () => {
|
||||
// 获取文章ID(优先使用props,其次使用全局状态)
|
||||
const articleid = getArticleId()
|
||||
form.articleid = articleid
|
||||
|
||||
// 根据是否有文章ID选择不同的API调用
|
||||
res = await (articleid
|
||||
? messageService.getMessagesByArticleId(articleid)
|
||||
: fetchAllMessages()
|
||||
)
|
||||
|
||||
// 获取留言数量
|
||||
messageService.getMessageCountByArticleId(articleid).then(res => {
|
||||
if (res.code === 200) {
|
||||
totalPages.value = Math.ceil(res.data / pageSize.value)
|
||||
}
|
||||
})
|
||||
res = await (messageService.getMessagesByPage(articleid, pageNum.value - 1, pageSize.value))
|
||||
// 验证响应结果
|
||||
if (!res || !res.data) {
|
||||
handleEmptyResponse()
|
||||
@@ -426,6 +452,18 @@ const fetchMessages = async () => {
|
||||
|
||||
// 处理留言数据
|
||||
messageBoardData.value = processMessageData(res.data)
|
||||
|
||||
// 根据当前页码更新分页布局
|
||||
if (pageNum.value === 1) {
|
||||
// 第一页只显示页码和下一页按钮
|
||||
pageLayout.value = 'pager, next'
|
||||
} else if (pageNum.value === totalPages.value) {
|
||||
// 最后一页只显示上一页按钮和页码
|
||||
pageLayout.value = 'prev, pager'
|
||||
} else {
|
||||
// 中间页显示完整的上一页、页码、下一页
|
||||
pageLayout.value = 'prev, pager, next'
|
||||
}
|
||||
} catch (error) {
|
||||
handleFetchError(error)
|
||||
} finally {
|
||||
@@ -461,6 +499,7 @@ const fetchAllMessages = async () => {
|
||||
const res = await messageService.getAllMessages()
|
||||
// 过滤掉articleid不为空的留言,只保留articleid为空或不存在的留言
|
||||
if (res && res.data) {
|
||||
|
||||
res.data = res.data.filter(msg => !msg.articleid || msg.articleid === '')
|
||||
}
|
||||
return res
|
||||
@@ -642,7 +681,7 @@ const handleMessageSubmission = async () => {
|
||||
if (res.success) {
|
||||
// 提交成功
|
||||
ElMessage.success(form.parentid ? '回复成功' : '留言成功')
|
||||
await fetchMessages() // 重新获取列表
|
||||
await fetchMessages(0) // 重新获取列表
|
||||
resetForm()
|
||||
|
||||
// 如果是回复模式,取消回复状态
|
||||
@@ -968,6 +1007,64 @@ onMounted(() => {
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
/* 分页控件样式优化 */
|
||||
.pagination-controls {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin: 30px 0;
|
||||
padding: 16px;
|
||||
background-color: rgba(255, 255, 255, 0.85);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.pagination-controls .el-pagination {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.pagination-controls .el-pagination.is-background .el-pager li {
|
||||
margin: 0 4px;
|
||||
background-color: rgba(102, 161, 216, 0.1);
|
||||
border: 1px solid rgba(102, 161, 216, 0.3);
|
||||
color: #333;
|
||||
border-radius: 6px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.pagination-controls .el-pagination.is-background .el-pager li:hover {
|
||||
background-color: rgba(102, 161, 216, 0.3);
|
||||
border-color: rgba(102, 161, 216, 0.5);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.pagination-controls .el-pagination.is-background .el-pager li.is-active {
|
||||
background-color: rgba(102, 161, 216, 0.8);
|
||||
border-color: rgba(102, 161, 216, 0.8);
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.pagination-controls .el-pagination.is-background .btn-prev,
|
||||
.pagination-controls .el-pagination.is-background .btn-next {
|
||||
background-color: rgba(102, 161, 216, 0.1);
|
||||
border: 1px solid rgba(102, 161, 216, 0.3);
|
||||
color: #333;
|
||||
border-radius: 6px;
|
||||
transition: all 0.3s ease;
|
||||
padding: 0 12px;
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
.pagination-controls .el-pagination.is-background .btn-prev:hover,
|
||||
.pagination-controls .el-pagination.is-background .btn-next:hover {
|
||||
background-color: rgba(102, 161, 216, 0.3);
|
||||
border-color: rgba(102, 161, 216, 0.5);
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* 评论表单区域 */
|
||||
.comment-form-section {
|
||||
background-color: rgba(255, 255, 255, 0.85);
|
||||
@@ -1064,20 +1161,28 @@ onMounted(() => {
|
||||
.comment-form-section {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.el-form-item {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form-input-row {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-input-row--inline .el-form-item {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.comment-header-info,
|
||||
.reply-header-info {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.form-submit-button {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.user-avatar {
|
||||
margin-right: 0;
|
||||
margin-bottom: 8px;
|
||||
|
||||
@@ -30,8 +30,8 @@ export default defineConfig({
|
||||
proxy: {
|
||||
// 配置API代理
|
||||
'/api': {
|
||||
target: 'http://www.qf1121.top',
|
||||
// target: 'http://localhost:7071',
|
||||
// target: 'http://www.qf1121.top',
|
||||
target: 'http://localhost:7071',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user