diff --git a/src/axios/api.js b/src/axios/api.js
deleted file mode 100644
index 6c7fc45..0000000
--- a/src/axios/api.js
+++ /dev/null
@@ -1,88 +0,0 @@
-import axios from 'axios'
-
-// 创建axios实例
-const service = axios.create({
- baseURL: 'http://localhost:8080/api', // api的base_url
- timeout: 3000, // 请求超时时间
- headers: {
- 'Content-Type': 'application/json'
- }
- // withCredentials: true, // 跨域请求时是否需要使用凭证
-})
-
-// 请求拦截器 - 添加认证token
-service.interceptors.request.use(
- config => {
- const token = localStorage.getItem('token')
- if (token) {
- config.headers.Authorization = `Bearer ${token}`
- }
- return config
- },
- error => {
- return Promise.reject(error)
- }
-)
-
-// 响应拦截器 - 统一处理响应
-service.interceptors.response.use(
- response => {
- // 检查响应是否成功
- if (response.data && response.data.success) {
- return response.data
- } else {
- // 处理业务错误
- return Promise.reject(new Error(response.data?.message || '请求失败'))
- }
- },
- error => {
- // 处理HTTP错误
- console.error('API请求错误:', error)
- // 可以在这里添加全局错误处理,如显示错误提示
- return Promise.reject(error)
- }
-)
-
-// 文章相关API
-export const articleAPI = {
- // 获取所有文章
- getAllArticles: () => service.get('/articles'),
- // 获取单篇文章
- getArticleById: (id) => service.get(`/articles/${id}`),
- // 根据分类获取文章
- getArticlesByCategory: (categoryId) => service.get(`/articles/category/${categoryId}`),
- // 获取热门文章
- getPopularArticles: () => service.get('/articles/popular'),
- // 创建文章
- createArticle: (articleData) => service.post('/articles', articleData),
- // 更新文章
- updateArticle: (id, articleData) => service.put(`/articles/${id}`, articleData),
- // 删除文章
- deleteArticle: (id) => service.delete(`/articles/${id}`)
-}
-
-// 留言相关API
-export const messageAPI = {
- // 获取所有留言
- getAllMessages: () => service.get('/messages'),
- // 获取单条留言
- getMessageById: (id) => service.get(`/messages/${id}`),
- // 根据文章ID获取留言
- getMessagesByArticleId: (articleId) => service.get(`/messages/article/${articleId}`),
- // 获取根留言
- getRootMessages: () => service.get('/messages/root'),
- // 根据父留言ID获取回复
- getRepliesByParentId: (parentId) => service.get(`/messages/parent/${parentId}`),
- // 根据昵称搜索留言
- searchMessagesByNickname: (nickname) => service.get(`/messages/search?nickname=${nickname}`),
- // 获取文章评论数量
- getMessageCountByArticleId: (articleId) => service.get(`/messages/count/${articleId}`),
- // 创建留言
- saveMessage: (messageData) => service.post('/messages', messageData),
- // 删除留言
- deleteMessage: (id) => service.delete(`/messages/${id}`)
-}
-
-
-
-export default service
\ No newline at end of file
diff --git a/src/router/Router.js b/src/router/Router.js
index bec299a..b6f10e0 100644
--- a/src/router/Router.js
+++ b/src/router/Router.js
@@ -1,6 +1,6 @@
import { createWebHistory, createRouter } from 'vue-router'
// 导入视图组件
-import ArticleList from '../views/aericle.vue'
+import ArticleList from '../views/aericlelist.vue'
import HomePage from '../views/home.vue'
import NonsensePage from '../views/nonsense.vue'
import MessageBoardPage from '../views/messageboard.vue'
diff --git a/src/services/articleService.js b/src/services/articleService.js
index 19de966..976d83a 100644
--- a/src/services/articleService.js
+++ b/src/services/articleService.js
@@ -23,6 +23,15 @@ class ArticleService {
return apiService.get(`/articles/${id}`)
}
+ /**
+ * 根据属性ID获取文章列表
+ * @param {number} attributeId - 属性ID
+ * @returns {Promise}
+ */
+ getArticlesByAttributeId(attributeId) {
+ return apiService.get(`/articles/attribute/${attributeId}`)
+ }
+
/**
* 根据标题查询文章列表
* @param {string} title - 文章标题
@@ -68,7 +77,7 @@ class ArticleService {
deleteArticle(id) {
return apiService.delete(`/articles/${id}`)
}
-
+
/**
* 增加文章浏览量
* @param {number} id - 文章ID
@@ -77,6 +86,33 @@ class ArticleService {
incrementArticleViews(id) {
return apiService.post(`/articles/${id}/views`)
}
+
+ /**
+ * 根据分类ID获取文章(兼容旧接口)
+ * @param {number} categoryId - 分类ID
+ * @returns {Promise}
+ */
+ getArticlesByCategory(categoryId) {
+ return apiService.get(`/articles/category/${categoryId}`)
+ }
+
+ /**
+ * 根据属性ID获取文章
+ * @param {number} attributeId - 属性ID
+ * @returns {Promise}
+ */
+ getArticlesByAttribute(attributeId) {
+ return apiService.get(`/articles/attribute/${attributeId}`)
+ }
+
+ /**
+ * 根据属性ID获取最新文章
+ * @param {number} attributeId - 属性ID
+ * @returns {Promise}
+ */
+ getLatestArticlesByAttribute(attributeId) {
+ return apiService.get(`/articles/attribute/${attributeId}/latest`)
+ }
}
// 导出文章服务实例
diff --git a/src/services/categoryAttributeService.js b/src/services/categoryAttributeService.js
new file mode 100644
index 0000000..85d7ac2
--- /dev/null
+++ b/src/services/categoryAttributeService.js
@@ -0,0 +1,66 @@
+// 分类属性相关API服务
+import apiService from './apiService'
+
+/**
+ * 分类属性服务类
+ */
+class CategoryAttributeService {
+ /**
+ * 根据ID获取分类属性
+ * @param {number} id - 属性ID
+ * @returns {Promise}
+ */
+ getAttributeById(id) {
+ return apiService.get(`/category-attributes/${id}`)
+ }
+
+ /**
+ * 根据分类ID获取属性列表
+ * @param {number} categoryId - 分类ID
+ * @returns {Promise}
+ */
+ getAttributesByCategory(categoryId) {
+ return apiService.get(`/category-attributes/category/${categoryId}`)
+ }
+
+ /**
+ * 创建分类属性
+ * @param {Object} attributeData - 属性数据
+ * @returns {Promise}
+ */
+ createAttribute(attributeData) {
+ return apiService.post('/category-attributes', attributeData)
+ }
+
+ /**
+ * 更新分类属性
+ * @param {number} id - 属性ID
+ * @param {Object} attributeData - 属性数据
+ * @returns {Promise}
+ */
+ updateAttribute(id, attributeData) {
+ return apiService.put(`/category-attributes/${id}`, attributeData)
+ }
+
+ /**
+ * 删除分类属性
+ * @param {number} id - 属性ID
+ * @returns {Promise}
+ */
+ deleteAttribute(id) {
+ return apiService.delete(`/category-attributes/${id}`)
+ }
+
+ /**
+ * 检查分类下是否存在指定名称的属性
+ * @param {number} categoryId - 分类ID
+ * @param {string} attributeName - 属性名称
+ * @returns {Promise}
+ */
+ checkAttributeExists(categoryId, attributeName) {
+ return apiService.get(`/category-attributes/check-exists?categoryId=${categoryId}&attributeName=${encodeURIComponent(attributeName)}`)
+ }
+}
+
+// 导出分类属性服务实例
+export default new CategoryAttributeService()
\ No newline at end of file
diff --git a/src/services/categoryService.js b/src/services/categoryService.js
new file mode 100644
index 0000000..7058a4f
--- /dev/null
+++ b/src/services/categoryService.js
@@ -0,0 +1,54 @@
+import apiService from './apiService'
+
+/**
+ * 分类服务
+ */
+class CategoryService {
+ /**
+ * 获取所有分类
+ * @returns {Promise}
+ */
+ getAllCategories() {
+ return apiService.get('/categories')
+ }
+
+ /**
+ * 获取指定分类
+ * @param {number} id - 分类ID
+ * @returns {Promise}
+ */
+ getCategory(id) {
+ return apiService.get(`/categories/${id}`)
+ }
+
+ /**
+ * 创建新分类
+ * @param {Object} categoryData - 分类数据
+ * @returns {Promise}
+ */
+ createCategory(categoryData) {
+ return apiService.post('/categories', categoryData)
+ }
+
+ /**
+ * 更新分类
+ * @param {number} id - 分类ID
+ * @param {Object} categoryData - 分类数据
+ * @returns {Promise}
+ */
+ updateCategory(id, categoryData) {
+ return apiService.put(`/categories/${id}`, categoryData)
+ }
+
+ /**
+ * 删除分类
+ * @param {number} id - 分类ID
+ * @returns {Promise}
+ */
+ deleteCategory(id) {
+ return apiService.delete(`/categories/${id}`)
+ }
+}
+
+// 导出分类服务实例
+export default new CategoryService()
\ No newline at end of file
diff --git a/src/services/index.js b/src/services/index.js
index d555208..7edaf30 100644
--- a/src/services/index.js
+++ b/src/services/index.js
@@ -1,8 +1,17 @@
// 导出所有服务
import articleService from './articleService'
import messageService from './messageService'
+import categoryAttributeService from './categoryAttributeService'
+import categoryService from './categoryService'
+
+
+
+
export {
articleService,
- messageService
+ messageService,
+ categoryAttributeService,
+ categoryService
+
}
\ No newline at end of file
diff --git a/src/styles/MainLayout.css b/src/styles/MainLayout.css
index 00f1f58..af8b597 100644
--- a/src/styles/MainLayout.css
+++ b/src/styles/MainLayout.css
@@ -22,7 +22,7 @@
/* 内容区宽度和外边距 */
--content-width: 80%;
/* 主内容区宽度 */
- --content-margin: 0 5%;
+ --content-margin: 0 5% 0 5%;
/* 主内容区左右外边距 */
/* 左侧状态栏宽度 */
@@ -30,7 +30,7 @@
/* 左侧模块宽度 */
/* 疯言疯语标题区样式 */
- --nonsense-title-width: 76.5%;
+ --nonsense-title-width: 77.1%;
/* 疯言疯语标题区宽度 */
--nonsense-title-padding: 20px;
/* 疯言疯语标题区内边距 */
@@ -40,7 +40,7 @@
/* 疯言疯语标题区下边距 */
--nonsense-titleconst-padding: 1.5rem;
/* 疯言疯语标题内容区内边距 */
- --nonsenset-margin-top: 130px;
+ --nonsenset-margin-top: 150px;
/* 疯言疯语内容区顶部外边距 */
/* 分页背景色 */
@@ -62,7 +62,7 @@
/* 导航栏阴影 */
/* 字体颜色和菜单样式 */
- --font-color-title: #32325d;
+ --font-color-title: #AF7AC5;
/* 标题字体颜色 */
--font-size-menu: 20px;
/* 菜单字体大小 */
diff --git a/src/views/aericle.vue b/src/views/aericle.vue
deleted file mode 100644
index a719faa..0000000
--- a/src/views/aericle.vue
+++ /dev/null
@@ -1,309 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- 重新加载
-
-
-
-
-
-
-
-
- -
-
- ({{ category.sum }})
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/views/aericlelist.vue b/src/views/aericlelist.vue
new file mode 100644
index 0000000..a5cde9c
--- /dev/null
+++ b/src/views/aericlelist.vue
@@ -0,0 +1,422 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ 重新加载
+
+
+
+
+
+
文章分类如下,点击跳转
+
+
+
+
共 {{ categoryGroup.attributes.length }} 篇
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/views/articlecontents.vue b/src/views/articlecontents.vue
index c48b4d6..b8209b1 100644
--- a/src/views/articlecontents.vue
+++ b/src/views/articlecontents.vue
@@ -141,10 +141,10 @@ const fetchArticleDetail = async () => {
// 不阻止主流程
}
- // 获取相关文章(同分类下的其他文章)
+ // 获取相关文章(同属性下的其他文章)
if (article.value.categoryId) {
try {
- const relatedRes = await articleService.createArticle(article.value.categoryId)
+ const relatedRes = await articleService.getArticlesByCategory(article.value.categoryId)
// 过滤掉当前文章,并取前5篇作为相关文章
relatedArticles.value = relatedRes.data
? relatedRes.data.filter((item: Article) => item.id !== article.value?.id).slice(0, 5)
@@ -154,6 +154,17 @@ const fetchArticleDetail = async () => {
// 不阻止主流程
}
}
+ // 兼容旧的categoryId
+ else if (article.value.categoryId) {
+ try {
+ const relatedRes = await articleService.getArticlesByCategory(article.value.categoryId)
+ relatedArticles.value = relatedRes.data
+ ? relatedRes.data.filter((item: Article) => item.id !== article.value?.id).slice(0, 5)
+ : []
+ } catch (err) {
+ console.error('获取相关文章失败:', err)
+ }
+ }
} else {
throw new Error('文章不存在或已被删除')
}
diff --git a/src/views/commentDemo.vue b/src/views/commentDemo.vue
index 8780664..9333f35 100644
--- a/src/views/commentDemo.vue
+++ b/src/views/commentDemo.vue
@@ -1,21 +1,18 @@
+
嵌套留言Demo
- +