fixed: 新闻编辑无法删除

This commit is contained in:
LittleBoy 2024-12-23 22:39:35 +08:00 committed by Coding
parent 800c14a4f8
commit 6abc6ab3d1
5 changed files with 29 additions and 21 deletions

View File

@ -1,19 +1,17 @@
import {App} from "antd"; import {App} from "antd";
import {showToast} from "@/components/message.ts"; import {showToast} from "@/components/message.ts";
import {useState} from "react"; import {useState} from "react";
import {push2article} from "@/service/api/news.ts";
import {IconDelete} from "@/components/icons"; import {IconDelete} from "@/components/icons";
import {useNavigate} from "react-router-dom"; import {deleteByIds} from "@/service/api/article.ts";
export default function ButtonDeleteBatch(props: { ids: Id[];onSuccess?: () => void; }) { export default function ButtonDeleteBatch(props: { ids: Id[];onSuccess?: () => void; }) {
const {modal} = App.useApp(); const {modal} = App.useApp();
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const navigate = useNavigate();
const handlePush = () => { const handlePush = () => {
setLoading(true) setLoading(true)
push2article(props.ids).then(() => { deleteByIds(props.ids).then(() => {
props.onSuccess?.();
showToast('删除成功', 'success') showToast('删除成功', 'success')
navigate('/edit')
}).catch(() => { }).catch(() => {
showToast('删除失败', 'error') showToast('删除失败', 'error')
}).finally(() => { }).finally(() => {
@ -27,8 +25,8 @@ export default function ButtonDeleteBatch(props: { ids: Id[];onSuccess?: () => v
return return
} }
modal.confirm({ modal.confirm({
title: '操作提示', title: `你确定要删除选择的 ${props.ids.length} 条新闻吗?`,
content: '是否确定删除选中的新闻?', content: '删除后需从新闻素材中重新选择',
onOk: handlePush, onOk: handlePush,
centered: true centered: true
}) })

View File

@ -1,10 +1,10 @@
import {Checkbox, Space} from "antd"; import {Checkbox, Popconfirm, Space} from "antd";
import React, {useRef, useState} from "react"; import React, {useRef, useState} from "react";
import {useRequest} from "ahooks"; import {useRequest} from "ahooks";
import {formatTime} from "@/util/strings.ts"; import {formatTime} from "@/util/strings.ts";
import ArticleEditModal from "@/components/article/edit-modal.tsx"; import ArticleEditModal from "@/components/article/edit-modal.tsx";
import {getList} from "@/service/api/article.ts"; import {deleteByIds, getList} from "@/service/api/article.ts";
import EditSearchForm from "@/pages/news/components/edit-search-form.tsx"; import EditSearchForm from "@/pages/news/components/edit-search-form.tsx";
import ButtonPush2Video from "@/pages/news/components/button-push2video.tsx"; import ButtonPush2Video from "@/pages/news/components/button-push2video.tsx";
@ -14,6 +14,7 @@ import {IconDelete, IconEdit} from "@/components/icons";
import {clsx} from "clsx"; import {clsx} from "clsx";
import ButtonToTop from "@/components/scoller/button-to-top.tsx"; import ButtonToTop from "@/components/scoller/button-to-top.tsx";
import ButtonDeleteBatch from "@/pages/news/components/button-delete-batch.tsx"; import ButtonDeleteBatch from "@/pages/news/components/button-delete-batch.tsx";
import {showErrorToast, showToast} from "@/components/message.ts";
export default function NewEdit() { export default function NewEdit() {
@ -58,7 +59,12 @@ export default function NewEdit() {
} }
} }
const scrollerRef = useRef<InfiniteScrollerRef|null>(null) const scrollerRef = useRef<InfiniteScrollerRef|null>(null)
const handleDelete = (id)=>{
deleteByIds([id]).then(()=>{
refresh()
showToast('删除成功','success')
}).catch(showErrorToast)
}
return (<div className="container pb-5 news-edit"> return (<div className="container pb-5 news-edit">
<div className="search-panel-container my-5"> <div className="search-panel-container my-5">
@ -109,13 +115,13 @@ export default function NewEdit() {
</div> </div>
</div> </div>
<div className="col source"> <div className="col source">
<div className="text-sm">{item.media_name}</div> <div className="text-sm">{item.data_source_name}</div>
</div> </div>
<div className="col count-picture"> <div className="col count-picture">
<div className="text-sm">{item.picture_count||'-'}</div> <div className="text-sm">{item.img_num}</div>
</div> </div>
<div className="col count-words"> <div className="col count-words">
<div className="text-sm">{item.words_count||'-'}</div> <div className="text-sm">{item.content_word_count}</div>
</div> </div>
<div className="col time"> <div className="col time">
<div <div
@ -123,7 +129,11 @@ export default function NewEdit() {
</div> </div>
<div className="col operations"> <div className="col operations">
<span className="icon-btn" onClick={() => setEditId(item.id)}><IconEdit/></span> <span className="icon-btn" onClick={() => setEditId(item.id)}><IconEdit/></span>
<span className="icon-btn"><IconDelete/></span> <Popconfirm title={'确认删除此新闻吗?'} description={'删除后需从新闻素材中重新选择'} onConfirm={()=>{
handleDelete(item.id)
}}>
<span className="icon-btn"><IconDelete/></span>
</Popconfirm>
<Checkbox checked={checked} <Checkbox checked={checked}
onChange={e => handleItemChecked(e.target.checked, item)}/> onChange={e => handleItemChecked(e.target.checked, item)}/>
</div> </div>

View File

@ -164,8 +164,8 @@ export default function NewsIndex() {
<div className="line-clamp-1">: <span>{item.data_source_name}</span></div> <div className="line-clamp-1">: <span>{item.data_source_name}</span></div>
<div className="extras flex items-center justify-between gap-3"> <div className="extras flex items-center justify-between gap-3">
<div><span>{formatTime(item.publish_time,'min')}</span></div> <div><span>{formatTime(item.publish_time,'min')}</span></div>
<div><span>: {item.picture_count || '-'}</span></div> <div><span>: {item.img_num}</span></div>
<div><span>: {item.words_count || '-'}</span></div> <div><span>: {item.content_word_count}</span></div>
<div <div
className={`checkbox mt-1`}> className={`checkbox mt-1`}>
{item.internal_article_id > 0 ? {item.internal_article_id > 0 ?

View File

@ -12,9 +12,8 @@ export function getList(data: ApiArticleSearchParams) {
* *
* @param id * @param id
*/ */
export function deleteById(id: Id) { export function deleteByIds(article_ids: Id[]) {
throw new Error('Not implement') return post('/article/remove',{article_ids})
return post<{ article: any }>({url: '/article/delete/' + id})
} }
export function getById(id: Id) { export function getById(id: Id) {

5
src/types/api.d.ts vendored
View File

@ -60,8 +60,9 @@ interface BasicArticleInfo {
summary: string; summary: string;
publish_time: string; publish_time: string;
media_name: string; media_name: string;
picture_count?: number; data_source_name?: string;
words_count?: number; img_num?: number;
content_word_count?: number;
media_id: number; media_id: number;
fanwen_column_id: number; fanwen_column_id: number;
} }