Skip to content

Commit e17c06e

Browse files
committed
feat(system): 前端数据接口支持新版后端数据格式
前端数据接口支持新版后端数据格式
1 parent b8b223d commit e17c06e

12 files changed

Lines changed: 26 additions & 26 deletions

frontend/src/Api.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export const fetchStatistics = async () => {
4242

4343
return {
4444
stats: [
45-
{ label: '文章', value: articleCount, icon: 'article' },
46-
{ label: '用户', value: userCount, icon: 'user' },
47-
{ label: '评论', value: commentCount, icon: 'comment' },
48-
{ label: '浏览量', value: browseCount, icon: 'view' }
45+
{ label: '文章', value: articleCount.data, icon: 'article' },
46+
{ label: '用户', value: userCount.data, icon: 'user' },
47+
{ label: '评论', value: commentCount.data, icon: 'comment' },
48+
{ label: '浏览量', value: browseCount.data, icon: 'view' }
4949
]
5050
};
5151
} catch (error) {

frontend/src/components/ArticleList.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export default function ArticleList() {
7575
}
7676

7777
if (!abortController.signal.aborted) {
78-
setArticles(Array.isArray(result.data) ? result.data : []);
79-
setTotalPages(result.total_pages || 1);
78+
setArticles(Array.isArray(result.data?.data) ? result.data.data : []);
79+
setTotalPages(result.data?.total_pages || 1);
8080
}
8181
} catch (error) {
8282
if (error.name === 'AbortError' || error.code === 'ERR_CANCELED') {

frontend/src/components/CategorySidebar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function CategorySidebar({ selectedCategory }) {
1717
try {
1818
setLoading(true);
1919
const data = await apiClient.get('/categoriesandcount');
20-
setCategories(data);
20+
setCategories(Array.isArray(data.data) ? data.data : []);
2121
setError(null);
2222
} catch (err) {
2323
console.error('获取分类数据失败:', err);

frontend/src/components/CommentSection.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const CommentSection = ({ articleAlias }) => {
4444
try {
4545
setLoading(true);
4646
const response = await apiClient.get(`/comments/article/${articleAlias}`);
47-
setComments(response || []);
47+
setComments(response.data || []);
4848
} catch (err) {
4949
// setError('获取评论失败');
5050
console.error(err);

frontend/src/components/Header.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export default function Header() {
129129
const fetchMenus = async () => {
130130
try {
131131
const response = await apiClient.get('/frontendgetmenus')
132-
if (response && Array.isArray(response)) {
133-
const escapedMenus = response.map(menu => ({
132+
if (response && Array.isArray(response.data)) {
133+
const escapedMenus = response.data.map(menu => ({
134134
...menu,
135135
menus_name: escapeHtml(menu.menus_name) || '',
136136
menus_url: escapeHtml(menu.menus_url) || ''

frontend/src/components/TagSidebar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function TagSidebar({ selectedTag }) {
1717
try {
1818
setLoading(true);
1919
const data = await apiClient.get('/tags');
20-
setTags(data);
20+
setTags(Array.isArray(data.data) ? data.data : []);
2121
setError(null);
2222
} catch (err) {
2323
console.error('获取标签数据失败:', err);

frontend/src/components/dashboard/AnnouncementManager.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function AnnouncementManager() {
6565
headers: { 'Content-Type': 'multipart/form-data' }
6666
});
6767

68-
const fileUrl = response.fileUrl || '';
68+
const fileUrl = response.data?.fileUrl || '';
6969
if (fileUrl) {
7070
const imgTag = `<img src="${fileUrl}" alt="" />`;
7171
const textarea = textareaRef.current;

frontend/src/components/dashboard/ArticleInfoForm.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export default function ArticleInfoForm({ articleData, initialArticleData, onSav
9595
apiClient.get('/user/has-permission', { params: { codes: ['system:tags:management'] } })
9696
]);
9797

98-
setTags(Array.isArray(tagsRes) ? tagsRes : []);
99-
setCategories(Array.isArray(categoriesRes) ? categoriesRes : []);
98+
setTags(Array.isArray(tagsRes.data) ? tagsRes.data : []);
99+
setCategories(Array.isArray(categoriesRes.data) ? categoriesRes.data : []);
100100

101101
setCanCreateCategories(catPermRes.data?.hasPermission === true);
102102
setCanCreateTags(tagPermRes.data?.hasPermission === true);
@@ -204,7 +204,7 @@ export default function ArticleInfoForm({ articleData, initialArticleData, onSav
204204

205205
setFormData(prev => ({
206206
...prev,
207-
cover: response.fileUrl || ''
207+
cover: response.data?.fileUrl || ''
208208
}));
209209
} catch (error) {
210210
console.error('封面上传失败:', error);

frontend/src/components/dashboard/AvatarUpload.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export default function AvatarUpload({ currentAvatar, onAvatarUpdate }) {
6666
}
6767
});
6868

69-
if (response && response.fileUrl) {
70-
const fullUrl = getFullImageUrl(response.fileUrl);
69+
if (response && response.data?.fileUrl) {
70+
const fullUrl = getFullImageUrl(response.data.fileUrl);
7171
onAvatarUpdate(fullUrl);
7272
setPreview(fullUrl);
7373
} else {

frontend/src/components/dashboard/GlobalAttachmentsManager.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const GlobalAttachmentsManager = () => {
2929
setUserLoading(true);
3030
try {
3131
const response = await apiClient.get('/user/listall');
32-
if (response && Array.isArray(response)) {
33-
setUsers(response);
32+
if (response && Array.isArray(response.data)) {
33+
setUsers(response.data);
3434
}
3535
} catch (error) {
3636
console.error('获取用户列表失败:', error);

0 commit comments

Comments
 (0)