Commit 624cb4c1 authored by 陈前坚's avatar 陈前坚

perf: dictionary

parent 945c34ea
...@@ -12,15 +12,17 @@ import { ...@@ -12,15 +12,17 @@ import {
} from 'antd'; } from 'antd';
import { get } from '@/services/index'; import { get } from '@/services/index';
import styles from './WebDic.less'; import styles from './WebDic.less';
import AddForm from '@/pages/webConfig/menuconfig/AddForm';
const WebDic = () => { const WebDic = () => {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [level, setLevel] = useState(1);
const [addVisible, setAddVisible] = useState(false);
const [editVisible, setEditVisible] = useState(false); const [editVisible, setEditVisible] = useState(false);
// const [editValue, setEditValue] = useState(''); const [data, setData] = useState([]); // 一级条目
// const [description, setDescription] = useState(''); const [subData, setSubData] = useState([]); // 二级条目
const [data, setData] = useState([]); const [select, setSelect] = useState({}); // 当前选中条目
const [subData, setSubData] = useState([]); const [addForm] = Form.useForm();
const [select, setSelect] = useState({});
const [editForm] = Form.useForm(); const [editForm] = Form.useForm();
const columns = [ const columns = [
...@@ -34,6 +36,12 @@ const WebDic = () => { ...@@ -34,6 +36,12 @@ const WebDic = () => {
title: '值', title: '值',
dataIndex: 'nodeValue', dataIndex: 'nodeValue',
key: 'nodeValue', key: 'nodeValue',
render: record => {
if (!record) {
return '-';
}
return record;
},
}, },
{ {
title: '操作', title: '操作',
...@@ -61,7 +69,7 @@ const WebDic = () => { ...@@ -61,7 +69,7 @@ const WebDic = () => {
title="是否删除该数据?" title="是否删除该数据?"
okText="确认" okText="确认"
cancelText="取消" cancelText="取消"
// onConfirm={submitDelete} onConfirm={submitDelete}
> >
<Button <Button
size="small" size="small"
...@@ -91,13 +99,14 @@ const WebDic = () => { ...@@ -91,13 +99,14 @@ const WebDic = () => {
key: '', key: '',
}) })
.then(res => { .then(res => {
if (res.length > 0) { if (res && res.length > 0) {
res.map(item => { res.map(item => {
item.key = item.nodeID; item.key = item.nodeID;
return item; return item;
}); });
if (value === '-1') { if (value === '-1') {
setData(res); // 设置一级条目 setData(res); // 设置一级条目
setSelect(res[0]); // 默认当前选中一级条目第一条
} else if (value) { } else if (value) {
setSubData(res); // 设置二级条目 setSubData(res); // 设置二级条目
} }
...@@ -121,13 +130,104 @@ const WebDic = () => { ...@@ -121,13 +130,104 @@ const WebDic = () => {
const setRowClassName = record => const setRowClassName = record =>
record.nodeID === select.nodeID ? styles.clickRowStyle : ''; record.nodeID === select.nodeID ? styles.clickRowStyle : '';
// 提交-添加
const submitAdd = value => {
const nodeName = addForm.getFieldValue('nodeName');
const nodeValue = addForm.getFieldValue('nodeValue');
get(`/Cityinterface/rest/services/OMS.svc/D_AddDataDictionary`, {
_version: 9999,
_dc: new Date().getTime(),
nodeID: value,
nodeName,
nodeValue,
})
.then(res => {
if (res.success) {
setAddVisible(false);
getData('-1');
notification.success({
message: '提交成功',
});
} else {
notification.error({
message: '提交失败',
description: res.message,
});
}
})
.catch(err => {
message.error(err);
});
};
// 提交-编辑
const submitEdit = () => { const submitEdit = () => {
const nodeName = editForm.getFieldValue('nodeName'); const nodeName = editForm.getFieldValue('nodeName');
const nodeValue = editForm.getFieldValue('nodeValue'); const nodeValue = editForm.getFieldValue('nodeValue');
get(`/Cityinterface/rest/services/OMS.svc/D_EditDataDictionary`, {
_version: 9999,
_dc: new Date().getTime(),
nodeID: select.nodeID,
nodeName,
nodeValue,
})
.then(res => {
if (res.success) {
setEditVisible(false);
getData(select.parentID);
notification.success({
message: '提交成功',
});
} else {
notification.error({
message: '提交失败',
description: res.message,
});
}
})
.catch(err => {
message.error(err);
});
};
const submitDelete = () => {
get(`/Cityinterface/rest/services/OMS.svc/D_DeleteDataDictionary`, {
_version: 9999,
_dc: new Date().getTime(),
nodeID: select.nodeID,
})
.then(res => {
if (res.success) {
getData(select.parentID);
notification.success({
message: '删除成功',
});
} else {
notification.error({
message: '删除失败',
description: res.message,
});
}
})
.catch(err => {
message.error(err);
});
}; };
return ( return (
<div className={styles.WebDic}> <div className={styles.WebDic}>
<div style={{ marginBottom: '10px', fontSize: '16px' }}>
<span style={{ padding: '0 10px' }}>一级条目</span>
<Button
type="primary"
size="small"
onClick={() => {
setLevel(1);
setAddVisible(true);
}}
>
添加
</Button>
</div>
<Table <Table
size="small" size="small"
bordered bordered
...@@ -149,6 +249,20 @@ const WebDic = () => { ...@@ -149,6 +249,20 @@ const WebDic = () => {
showSizeChanger: true, showSizeChanger: true,
}} }}
/> />
<hr color="#cfe7fd" />
<div style={{ marginBottom: '10px', fontSize: '16px' }}>
<span style={{ padding: '0 10px' }}>二级条目</span>
<Button
type="primary"
size="small"
onClick={() => {
setLevel(2);
setAddVisible(true);
}}
>
添加
</Button>
</div>
<Table <Table
size="small" size="small"
bordered bordered
...@@ -163,6 +277,36 @@ const WebDic = () => { ...@@ -163,6 +277,36 @@ const WebDic = () => {
showSizeChanger: true, showSizeChanger: true,
}} }}
/> />
{/* 添加 */}
<Modal
title={level === 1 ? '添加一级条目' : '添加二级条目'}
visible={addVisible}
onOk={() => {
if (level === 1) {
submitAdd('-1');
} else {
// submitAdd(select.nodeID);
}
}}
onCancel={() => {
setAddVisible(false);
}}
okText="确认"
cancelText="取消"
>
<Form form={addForm} labelCol={{ span: 3 }}>
<Form.Item
name="nodeName"
label="名称"
rules={[{ required: true, message: '不能为空' }]}
>
<Input placeholder="请输入名称" />
</Form.Item>
<Form.Item name="nodeValue" label="值">
<Input placeholder="请输入值" />
</Form.Item>
</Form>
</Modal>
{/* 修改 */} {/* 修改 */}
<Modal <Modal
title={select.parentID === '-1' ? '修改一级条目' : '修改二级条目'} title={select.parentID === '-1' ? '修改一级条目' : '修改二级条目'}
...@@ -182,15 +326,9 @@ const WebDic = () => { ...@@ -182,15 +326,9 @@ const WebDic = () => {
> >
<Input placeholder="请输入名称" /> <Input placeholder="请输入名称" />
</Form.Item> </Form.Item>
{select.nodeID !== '-1' && ( <Form.Item name="nodeValue" label="值">
<Form.Item
name="nodeValue"
label="值"
rules={[{ required: true, message: '不能为空' }]}
>
<Input placeholder="请输入值" /> <Input placeholder="请输入值" />
</Form.Item> </Form.Item>
)}
</Form> </Form>
</Modal> </Modal>
</div> </div>
......
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
} }
.ant-table-tbody{ .ant-table-tbody{
.clickRowStyle{ .clickRowStyle{
background: #74bafc; background: #cfe7fd;
} }
.clickRowStyle:hover>td{ .clickRowStyle:hover>td{
background: #aed8fa; background: #aed8fa;
} }
} }
.ant-card-body{
padding: 10px !important;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment