|
|
@@ -79,9 +79,10 @@
|
|
|
<el-form :model="editForm" label-width="60px" size="small">
|
|
|
<el-form-item label="分类">
|
|
|
<el-select
|
|
|
- v-model="editForm.categoryId"
|
|
|
+ v-model="editForm.categoryIds"
|
|
|
placeholder="请选择分类"
|
|
|
style="width: 100%"
|
|
|
+ multiple
|
|
|
>
|
|
|
<el-option
|
|
|
v-for="category in categories"
|
|
|
@@ -160,6 +161,7 @@ const loading = ref(false)
|
|
|
// Edit state
|
|
|
const editingNewsId = ref<number | null>(null)
|
|
|
const editForm = ref({
|
|
|
+ categoryIds: [],
|
|
|
categoryId: 0,
|
|
|
digest: '',
|
|
|
})
|
|
|
@@ -228,6 +230,7 @@ const fetchCategories = async () => {
|
|
|
const startEdit = (news: NewsItem) => {
|
|
|
editingNewsId.value = news.articleId
|
|
|
editForm.value = {
|
|
|
+ categoryIds:[news.categoryId],
|
|
|
categoryId: news.categoryId,
|
|
|
digest: news.digest,
|
|
|
}
|
|
|
@@ -236,12 +239,16 @@ const startEdit = (news: NewsItem) => {
|
|
|
|
|
|
const saveEdit = async () => {
|
|
|
if (!editingNewsId.value) return
|
|
|
-
|
|
|
+ if (editingNewsId.value && editForm.value.categoryIds.length === 0) {
|
|
|
+ ElMessage.warning('请选择分类')
|
|
|
+ return
|
|
|
+ }
|
|
|
try {
|
|
|
const params = {
|
|
|
articleId: editingNewsId.value,
|
|
|
...editForm.value,
|
|
|
}
|
|
|
+ params.categoryIds = editForm.value.categoryIds ? Object.values(editForm.value.categoryIds) : []
|
|
|
await newsApi.updateNews(params)
|
|
|
ElMessage.success('资讯更新成功')
|
|
|
editingNewsId.value = null
|