import api from "@/api"
import MyTable from "@/components/MyTable"
import { RootState } from "@/store"
import { getTime } from "@/utils"
import { getBaseUrl } from "@/utils/axios"
import { InboxOutlined } from "@ant-design/icons"
import { Button, Drawer, Form, Input, Popconfirm, Tooltip, notification } from "antd"
import TextArea from "antd/lib/input/TextArea"
import Dragger from "antd/lib/upload/Dragger"
import { title } from "process"
import React, { useRef, useState } from "react"
import { useSelector } from "react-redux"
const BUZZUPNews = () => {
const { userInfo } = useSelector((state: RootState) => state.storeData)
const [visible, setVisible] = useState(false)
const [form] = Form.useForm()
const currentType = useRef('' as 'create' | 'update')
const currentItem = useRef({} as any)
const tableRef = useRef(null)
const columns = [
{
title: '图片',
dataIndex: 'image',
width: 300,
render: (logo) => {
return (
}>
)
}
},
{
title: '标题',
width: 300,
dataIndex: "title",
render: (title) => {
return (
') }}>
}>
') }}>
)
}
},
{
title: '链接',
dataIndex: 'url',
width: 300
},
{
title: '创建时间',
dataIndex: 'time',
render: (time) => (
{getTime(time * 1000)}
)
},
{
title: 'options',
fixed: 'right',
width: 100,
render: (item) => (
deleteSystemMsg(item)}>
)
}
]
const deleteSystemMsg = async (item) => {
const res: any = await api.delete_new_message({
id: item.id
})
if (res.code === 0) {
tableRef.current.update()
notification.success({
message: '删除成功'
})
}
}
const onClose = () => setVisible(false)
const onFinish = async (values) => {
const parmas = {
...values
}
console.log(parmas);
if (currentType.current === 'update') {
parmas.id = currentItem.current.id
}
let res: any;
if (currentType.current === 'create') {
res = await api.add_news_message(parmas)
} else {
res = await api.updata_news_message(parmas)
}
if (res.code === 0) {
setVisible(false)
tableRef.current.update()
form.resetFields()
notification.success({
message: currentType.current === 'create' ? '添加成功' : '修改成功'
})
}
}
const uploadProps = {
name: 'img',
action: `${getBaseUrl()}/admin/uploadImg`,
headers: {
Token: userInfo.token,
},
}
const onChange = (info: any) => {
if (info.file.status === 'removed') {
form.setFieldsValue({
image: ''
})
}
if (info.file.status === 'done') {
if (info.file.response && info.file.response.code === 0) {
form.setFieldsValue({
image: info.file.response.data.url
})
notification.success({
message: `图片上传成功`
})
}
} else if (info.file.status === 'error') {
notification.error({
message: `图片上传失败`
});
}
}
return (
}
/>
prevValues.title !== currentValues.title}>
{({ getFieldValue }) => (
') }}>
)}
点击或拖拽文件进行上传
Support for a single or bulk upload. Strictly prohibited from uploading company data or other
banned files.
)
}
export default BUZZUPNews