Skip to content

Commit ed760da

Browse files
committed
fix(article): 修复部分情况下文章更新成功但是前端提示无权限问题
修复部分情况下文章更新成功但是前端提示无权限问题
1 parent ab5164f commit ed760da

4 files changed

Lines changed: 84 additions & 28 deletions

File tree

backend/src/main/java/xyz/lingview/dimstack/service/impl/EditArticleServiceImpl.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -217,32 +217,29 @@ public boolean updateArticle(UpdateArticleDTO updateArticleDTO, String sessionUs
217217
paramMap.put("status", updateArticleDTO.getStatus());
218218
paramMap.put("enable_comment", updateArticleDTO.getEnable_comment());
219219
paramMap.put("create_time", updateArticleDTO.getCreate_time());
220-
221-
int result = editArticleMapper.updateArticleWithCategory(paramMap);
220+
221+
editArticleMapper.updateArticleWithCategory(paramMap);
222222

223223
// 更新分类计数
224-
if (result > 0) {
225-
String newCategory = updateArticleDTO.getCategory();
226-
if (oldCategory != null && !oldCategory.equals(newCategory)) {
227-
CategoryPathUtil.CategoryPath oldPath = categoryPathUtil.parsePath(oldCategory);
228-
String oldFullPath = oldPath.getParentCategory() != null
229-
? oldPath.getParentCategory() + "/" + oldPath.getChildCategory()
230-
: oldPath.getChildCategory();
231-
articleCategoryMapper.decrementCount(oldFullPath);
232-
233-
if (newCategory != null) {
234-
CategoryPathUtil.CategoryPath newPath = categoryPathUtil.parsePath(newCategory);
235-
String newFullPath = newPath.getParentCategory() != null
236-
? newPath.getParentCategory() + "/" + newPath.getChildCategory()
237-
: newPath.getChildCategory();
238-
articleCategoryMapper.incrementCount(newFullPath);
239-
}
224+
String newCategory = updateArticleDTO.getCategory();
225+
if (oldCategory != null && !oldCategory.equals(newCategory)) {
226+
CategoryPathUtil.CategoryPath oldPath = categoryPathUtil.parsePath(oldCategory);
227+
String oldFullPath = oldPath.getParentCategory() != null
228+
? oldPath.getParentCategory() + "/" + oldPath.getChildCategory()
229+
: oldPath.getChildCategory();
230+
articleCategoryMapper.decrementCount(oldFullPath);
231+
232+
if (newCategory != null) {
233+
CategoryPathUtil.CategoryPath newPath = categoryPathUtil.parsePath(newCategory);
234+
String newFullPath = newPath.getParentCategory() != null
235+
? newPath.getParentCategory() + "/" + newPath.getChildCategory()
236+
: newPath.getChildCategory();
237+
articleCategoryMapper.incrementCount(newFullPath);
240238
}
241-
242-
articleService.clearArticleCache();
243239
}
244240

245-
return result > 0;
241+
articleService.clearArticleCache();
242+
return true;
246243

247244
} catch (Exception e) {
248245
log.error("更新文章失败", e);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12.82
1+
12.83

frontend/src/components/dashboard/ArticleInfoForm.jsx

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import apiClient from '../../utils/axios';
33
import { getConfig } from '../../utils/config';
44
import {showToast} from "../../utils/toastManager.jsx";
55

6-
export default function ArticleInfoForm({ articleData, onSave, onCancel, uploading }) {
6+
export default function ArticleInfoForm({ articleData, initialArticleData, onSave, onCancel, uploading }) {
77
const [formData, setFormData] = useState({
88
title: '',
99
cover: '',
@@ -16,6 +16,7 @@ export default function ArticleInfoForm({ articleData, onSave, onCancel, uploadi
1616
enable_comment: 1
1717
});
1818

19+
const [initialData, setInitialData] = useState(null);
1920
const [tags, setTags] = useState([]);
2021
const [categories, setCategories] = useState([]);
2122
const [coverUploading, setCoverUploading] = useState(false);
@@ -52,7 +53,7 @@ export default function ArticleInfoForm({ articleData, onSave, onCancel, uploadi
5253
createTime = articleData.create_time.slice(0, 16);
5354
}
5455

55-
setFormData({
56+
const initialFormData = {
5657
title: articleData.article_name || articleData.title || '',
5758
cover: articleData.article_cover || articleData.cover || '',
5859
excerpt: articleData.excerpt || '',
@@ -63,8 +64,13 @@ export default function ArticleInfoForm({ articleData, onSave, onCancel, uploadi
6364
create_time: createTime,
6465
enable_comment: articleData.enable_comment !== undefined && articleData.enable_comment !== null
6566
? articleData.enable_comment
66-
: 1
67-
});
67+
: 1,
68+
initialArticleName: articleData.initialArticleName || '',
69+
initialArticleContent: articleData.initialArticleContent || ''
70+
};
71+
72+
setFormData(initialFormData);
73+
setInitialData(initialFormData);
6874
}
6975
}, [articleData]);
7076

@@ -231,6 +237,40 @@ export default function ArticleInfoForm({ articleData, onSave, onCancel, uploadi
231237
return;
232238
}
233239

240+
// 检查文章信息是否有更改
241+
if (initialData) {
242+
const normalizeTags = (tags) => {
243+
if (!tags) return [];
244+
if (Array.isArray(tags)) return [...tags].sort();
245+
if (typeof tags === 'string') return tags.split(',').map(t => t.trim()).filter(Boolean).sort();
246+
return [];
247+
};
248+
249+
const currentArticleContent = articleData?.content || '';
250+
const currentArticleTitle = articleData?.title || '';
251+
252+
const hasEditorChanges =
253+
currentArticleTitle !== (initialData.initialArticleName || '') ||
254+
currentArticleContent !== (initialData.initialArticleContent || '');
255+
256+
const hasInfoChanges =
257+
formData.title !== initialData.title ||
258+
formData.cover !== initialData.cover ||
259+
formData.excerpt !== initialData.excerpt ||
260+
JSON.stringify(normalizeTags(formData.tags)) !== JSON.stringify(normalizeTags(initialData.tags)) ||
261+
formData.category !== initialData.category ||
262+
formData.alias !== initialData.alias ||
263+
formData.create_time !== initialData.create_time ||
264+
formData.enable_comment !== initialData.enable_comment ||
265+
(formData.password && formData.password.trim() !== '');
266+
267+
if (!hasEditorChanges && !hasInfoChanges) {
268+
showToast('您未进行更改');
269+
onCancel();
270+
return;
271+
}
272+
}
273+
234274
const saveData = {
235275
...articleData,
236276
title: formData.title,

frontend/src/components/dashboard/MarkdownEditor.jsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ export default function MarkdownEditor({ onSave, onCancel, initialData }) {
289289
return;
290290
}
291291

292+
if (initialData) {
293+
const initialTitle = initialData.article_name || '';
294+
const initialContent = initialData.article_content || '';
295+
296+
if (title === initialTitle && content === initialContent) {
297+
298+
}
299+
}
300+
292301
let defaultCover = initialData?.article_cover || '';
293302

294303
if (!initialData?.article_id && !defaultCover) {
@@ -315,7 +324,9 @@ export default function MarkdownEditor({ onSave, onCancel, initialData }) {
315324
create_time: initialData?.create_time || '',
316325
enable_comment: initialData?.enable_comment !== undefined && initialData?.enable_comment !== null
317326
? initialData.enable_comment
318-
: 1
327+
: 1,
328+
initialArticleName: initialData?.article_name || '',
329+
initialArticleContent: initialData?.article_content || ''
319330
});
320331
setShowArticleInfo(true);
321332
};
@@ -336,9 +347,16 @@ export default function MarkdownEditor({ onSave, onCancel, initialData }) {
336347
alias: info.alias || '',
337348
status: 2,
338349
enable_comment: info.enable_comment !== undefined && info.enable_comment !== null ? info.enable_comment : 1,
339-
...(info.id && { article_id: info.id })
340350
};
341351

352+
353+
const articleId = info.id || initialData?.article_id;
354+
if (articleId) {
355+
payload.article_id = articleId;
356+
}
357+
358+
console.log('保存文章 payload:', payload);
359+
342360
const isUpdate = initialData && initialData.article_id;
343361

344362
if (isUpdate) {
@@ -1189,6 +1207,7 @@ ${cleanText}
11891207
{showArticleInfo && (
11901208
<ArticleInfoForm
11911209
articleData={articleInfo}
1210+
initialArticleData={initialData}
11921211
onSave={handleArticleInfoSave}
11931212
onCancel={() => setShowArticleInfo(false)}
11941213
uploading={isSaving}

0 commit comments

Comments
 (0)