|
|
@@ -0,0 +1,227 @@ |
|
|
|
import { Button, Modal, Form, Input, Drawer, Popconfirm, TreeSelect } from 'antd'; |
|
|
|
import React, { useState, useRef, useEffect } from 'react'; |
|
|
|
import { PageContainer } from '@ant-design/pro-layout'; |
|
|
|
import ProTable from '@ant-design/pro-table'; |
|
|
|
import { DropboxOutlined, PlusOutlined } from '@ant-design/icons'; |
|
|
|
import api from './service'; |
|
|
|
import { message } from 'antd/lib'; |
|
|
|
const app = () => { |
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false); |
|
|
|
const [form] = Form.useForm(); |
|
|
|
//绑定 |
|
|
|
const actionRef = useRef(); |
|
|
|
const [current, setCurrent] = useState({}); |
|
|
|
|
|
|
|
|
|
|
|
const columns = [ |
|
|
|
{ |
|
|
|
title: '主键', |
|
|
|
dataIndex: 'id', |
|
|
|
tip: '规则名称是唯一的 key', |
|
|
|
hideInSearch: true, |
|
|
|
hideInTable: true |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '二维码', |
|
|
|
dataIndex: 'qrCode', |
|
|
|
ellipsis: { |
|
|
|
showTitle: false, |
|
|
|
}, |
|
|
|
valueType: 'textarea', |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '芯片码', |
|
|
|
dataIndex: 'chipCode', |
|
|
|
ellipsis: { |
|
|
|
showTitle: false, |
|
|
|
}, |
|
|
|
valueType: 'textarea', |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '状态', |
|
|
|
dataIndex: 'status', |
|
|
|
valueEnum: { |
|
|
|
0: { |
|
|
|
text: '正常', |
|
|
|
status: 'Processing', |
|
|
|
}, |
|
|
|
1: { |
|
|
|
text: '停用', |
|
|
|
status: 'Success', |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '是否绑定', |
|
|
|
dataIndex: 'isOccupy', |
|
|
|
valueEnum: { |
|
|
|
false: { |
|
|
|
text: '未绑定', |
|
|
|
status: 'Processing', |
|
|
|
}, |
|
|
|
true: { |
|
|
|
text: '已绑定', |
|
|
|
status: 'Success', |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '操作', |
|
|
|
dataIndex: 'option', |
|
|
|
valueType: 'option', |
|
|
|
key: 'operation', |
|
|
|
fixed: 'right', |
|
|
|
width: 150, |
|
|
|
render: (_, record) => [ |
|
|
|
<a |
|
|
|
key="config" |
|
|
|
onClick={() => { |
|
|
|
form.setFieldsValue(record); |
|
|
|
setCurrent(record); |
|
|
|
setIsModalOpen(true); |
|
|
|
}} |
|
|
|
> |
|
|
|
更新 |
|
|
|
</a>, |
|
|
|
<a |
|
|
|
key="config" |
|
|
|
onClick={() => { |
|
|
|
api.EnableDisable(record).then((re) => { |
|
|
|
if (re.data) { |
|
|
|
message.success('成功'); |
|
|
|
actionRef.current.reloadAndRest(); |
|
|
|
} else { |
|
|
|
message.error(re.errors ||'失败'); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
}} |
|
|
|
> |
|
|
|
{record.status==0?"停用":"正常"} |
|
|
|
</a>, |
|
|
|
<Popconfirm |
|
|
|
key="delete" |
|
|
|
title={`确定要删除吗?`} |
|
|
|
onConfirm={async () => { |
|
|
|
api.Del(record.id).then((re) => { |
|
|
|
if (re.data) { |
|
|
|
message.success('删除成功'); |
|
|
|
actionRef.current.reloadAndRest(); |
|
|
|
} else { |
|
|
|
message.error(re.errors ||'修改失败'); |
|
|
|
} |
|
|
|
}); |
|
|
|
}} |
|
|
|
okText="确定" |
|
|
|
cancelText="取消" |
|
|
|
> |
|
|
|
<a href="#">删除</a> |
|
|
|
</Popconfirm> |
|
|
|
], |
|
|
|
}, |
|
|
|
]; |
|
|
|
return ( |
|
|
|
<> |
|
|
|
<PageContainer header={{ title: '', breadcrumb: {} }}> |
|
|
|
<ProTable |
|
|
|
columns={columns} |
|
|
|
actionRef={actionRef} |
|
|
|
rowKey="id" |
|
|
|
pagination={{ |
|
|
|
pageSize: 10 |
|
|
|
}} |
|
|
|
scroll={{ |
|
|
|
x: 1300, |
|
|
|
}} |
|
|
|
toolBarRender={() => [ |
|
|
|
<Button |
|
|
|
type="primary" |
|
|
|
key="primary" |
|
|
|
onClick={() => { |
|
|
|
setCurrent({}); |
|
|
|
form.setFieldsValue({id:"",qrCode:"",chipCode:""}); |
|
|
|
setIsModalOpen(true); |
|
|
|
}} |
|
|
|
> |
|
|
|
<PlusOutlined /> 新建 |
|
|
|
</Button>, |
|
|
|
]} |
|
|
|
//数据绑定 |
|
|
|
request={async (params) => { |
|
|
|
|
|
|
|
var res = await api.Page(params); |
|
|
|
var datas = res.data.data; |
|
|
|
var total = res.data.total; |
|
|
|
return { |
|
|
|
data: datas, |
|
|
|
success: true, |
|
|
|
total: total, |
|
|
|
}; |
|
|
|
}}></ProTable> |
|
|
|
|
|
|
|
{/* 餐盘管理 */} |
|
|
|
<Modal |
|
|
|
title={current.id?"修改":"新增"} |
|
|
|
width={600} |
|
|
|
open={isModalOpen} |
|
|
|
onOk={() => { |
|
|
|
form.submit(); |
|
|
|
}} |
|
|
|
onCancel={() => { |
|
|
|
setIsModalOpen(false); |
|
|
|
}}> |
|
|
|
<Form |
|
|
|
form={form} |
|
|
|
labelCol={{ span: 4, }} |
|
|
|
wrapperCol={{ span: 16, }} |
|
|
|
style={{ maxWidth: 600, }} |
|
|
|
initialValues={{ remember: true }} |
|
|
|
onFinish={(value) => { |
|
|
|
if (value.id) { |
|
|
|
api.Update(value).then((re) => { |
|
|
|
if (re.data) { |
|
|
|
message.success('修改成功'); |
|
|
|
setIsModalOpen(false); |
|
|
|
actionRef.current.reloadAndRest(); |
|
|
|
} else { |
|
|
|
message.error(re.errors ||'修改失败'); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
api.Add(value).then((re) => { |
|
|
|
if (re.data) { |
|
|
|
setIsModalOpen(false); |
|
|
|
message.success('添加成功'); |
|
|
|
actionRef.current.reloadAndRest(); |
|
|
|
} else { |
|
|
|
message.error(re.errors || '添加失败'); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}} |
|
|
|
onFinishFailed={() => { }} |
|
|
|
autoComplete="off" > |
|
|
|
|
|
|
|
<Form.Item name="id" label="id" hidden> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item label="二维码" name="qrCode" |
|
|
|
rules={[{ required: true, message: '二维码不能为空', },]}> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item label="芯片码" name="chipCode" |
|
|
|
rules={[{ required: true, message: '芯片码不能为空', },]}> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
</Form> |
|
|
|
</Modal> |
|
|
|
</PageContainer> |
|
|
|
</> |
|
|
|
|
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
export default app; |