import api from "@/api"
import MyTable from "@/components/MyTable"
import { getTime } from "@/utils"
import { DeleteFilled, EditOutlined } from "@ant-design/icons"
import { Button, Form, Input, Modal, Popconfirm, Switch, Tooltip, notification } from "antd"
import React, { useEffect, useRef, useState } from "react"
const SystemNofify = () => {
const tableRef = useRef(null)
const [visbleModel, setVisibleModal] = useState(false)
const [form] = Form.useForm()
const currentType = useRef('')
const currentItem = useRef({} as any)
const columns = [
{
title: '操作',
width: 100,
render: (row) => {
return (
updateNotify(row)} />
deleteNotify(row)}>
);
}
},
{
"dataIndex": "title", "title": "标题", width: 340, render: (text) => (
{text}
)
},
{
"dataIndex": "content", "title": "内容", width: 340, render: (text) => (
{text}
)
},
{ "dataIndex": "status", "title": "状态" },
{ "dataIndex": "time", "title": "时间", render: (time) => ({getTime(time * 1000)}
) },
]
const updateNotify = async (item) => {
currentType.current = 'update';
currentItem.current = item;
setVisibleModal(true)
form.setFieldsValue({
title: item.title,
content: item.content,
status_code: item.status_code === 1 ? true : false
})
}
const deleteNotify = async (item) => {
const res: any = await api.delete_nofity({
id: item.id
})
if (res.code === 0) {
notification.success({
message: '删除成功'
})
tableRef.current.update()
}
}
const onFinish = async (values) => {
setVisibleModal(false)
const params = {
...values,
status_code: values.status_code ? 1 : 2
}
let res: any = {};
if (currentType.current === 'update') {
params.id = currentItem.current.id
res = await api.update_nofity({
...params
})
} else {
res = await api.add_nofity({
...params
})
}
if (res.code === 0) {
notification.success({
message: currentType.current === 'update' ? '修改成功' : '添加成功'
})
tableRef.current.update()
form.resetFields()
}
}
return (
}
/>
{
currentType.current = 'add';
setVisibleModal(false)
}}
footer={() => null}
>
)
}
export default SystemNofify