Commit 61e4e69a authored by 陈前坚's avatar 陈前坚

perf: dictionary

parent 056df20a
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
color:rgba(0,0,0,0.85); color:rgba(0,0,0,0.85);
} }
.ant-table-content{ .ant-table-content{
height:calc(100vh - 500px); height:calc(100vh - 520px);
border-right: white; border-right: white;
overflow: auto !important; overflow: auto !important;
} }
......
...@@ -10,19 +10,23 @@ import { ...@@ -10,19 +10,23 @@ import {
Popconfirm, Popconfirm,
notification, notification,
message, message,
Row,
Col,
} from 'antd'; } from 'antd';
import { get } from '@/services/index'; import { get } from '@/services/index';
import styles from './WebDic.less'; import styles from './WebDic.less';
const WebDic = () => { const WebDic = () => {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [level, setLevel] = useState(1); const [level, setLevel] = useState(0); // 设置基本,一级1,二级2
const [addVisible, setAddVisible] = useState(false); const [addVisible, setAddVisible] = useState(false);
const [editVisible, setEditVisible] = useState(false); const [editVisible, setEditVisible] = useState(false);
const [data, setData] = useState([]); // 一级条目 const [data, setData] = useState([]); // 一级条目
const [subData, setSubData] = useState([]); // 二级条目 const [subData, setSubData] = useState([]); // 二级条目
const [select, setSelect] = useState({}); // 当前选中条目,可以是一级/二级条目,修改/删除时设置 const [select, setSelect] = useState({}); // 当前选中一级条目,修改/删除时设置
const [selectID, setSelectID] = useState('-1'); // 当前选中一级条目的ID,添加条目时使用 const [subSelect, setSubSelect] = useState({}); // 当前选中二级条目,修改/删除时设置
const [selectID, setSelectID] = useState('-1'); // 当前选中一级条目的ID,添加二级条目时使用
const [first, setFirst] = useState(true); // 是否第一次加载
const [addForm] = Form.useForm(); const [addForm] = Form.useForm();
const [editForm] = Form.useForm(); const [editForm] = Form.useForm();
...@@ -31,7 +35,7 @@ const WebDic = () => { ...@@ -31,7 +35,7 @@ const WebDic = () => {
title: '名称', title: '名称',
dataIndex: 'nodeName', dataIndex: 'nodeName',
key: 'nodeName', key: 'nodeName',
width: 300, width: 220,
}, },
{ {
title: '值', title: '值',
...@@ -47,7 +51,7 @@ const WebDic = () => { ...@@ -47,7 +51,7 @@ const WebDic = () => {
{ {
title: '操作', title: '操作',
key: 'action', key: 'action',
width: 200, width: 130,
render: record => ( render: record => (
<Space> <Space>
<Button <Button
...@@ -55,10 +59,14 @@ const WebDic = () => { ...@@ -55,10 +59,14 @@ const WebDic = () => {
size="small" size="small"
onClick={e => { onClick={e => {
e.stopPropagation(); e.stopPropagation();
setSelect(record); if (record.parentID === '-1') {
setSelect(record);
} else {
setSubSelect(record);
}
setEditVisible(true); setEditVisible(true);
editForm.setFieldsValue({ editForm.setFieldsValue({
nodeName: record.nodeName, nodeName1: record.nodeName,
nodeValue: record.nodeValue, nodeValue: record.nodeValue,
}); });
}} }}
...@@ -76,7 +84,11 @@ const WebDic = () => { ...@@ -76,7 +84,11 @@ const WebDic = () => {
danger danger
onClick={e => { onClick={e => {
e.stopPropagation(); e.stopPropagation();
setSelect(record); if (record.parentID === '-1') {
setSelect(record);
} else {
setSubSelect(record);
}
}} }}
> >
删除 删除
...@@ -109,16 +121,26 @@ const WebDic = () => { ...@@ -109,16 +121,26 @@ const WebDic = () => {
} }
// value为 -1 时获取一级条目数据,否则获取二级条目数据 // value为 -1 时获取一级条目数据,否则获取二级条目数据
if (value === '-1') { if (value === '-1') {
setData(res); // 设置一级条目 setData(res); // 设置一级条目数据
setSelect(res[0]); // 默认当前选中一级条目第一条 if (first) {
setSelectID(res[0].nodeID); // 设置选中的一级条目ID,用于添加二级条目 setSelect(res[0]); // 默认当前选中一级条目第一条
setSelectID(res[0].nodeID); // 设置选中的一级条目ID,用于添加二级条目
// setSelectColor(res[0]);
setFirst(false);
// 获取二级条目数据,默认一级条目第一条,递归一次(条件parentID === '-1')
if (res[0] && res[0].parentID === '-1') {
getData(res[0].nodeID);
}
}
// if (level === 0) {
// setSelect(res[0]); // 默认当前选中一级条目第一条
// setSelectID(res[0].nodeID); // 设置选中的一级条目ID,用于添加二级条目
// } else if (level === 1) {
// setSelect({ nodeID: value2 });
// }
} else if (value) { } else if (value) {
setSubData(res); // 设置二级条目,res为空[]时也要设置 setSubData(res); // 设置二级条目,res为空[]时也要设置
} }
// 获取二级条目数据,默认一级条目第一条,递归一次(条件parentID === '-1')
if (res && res[0] && res[0].parentID === '-1') {
getData(res[0].nodeID);
}
} else { } else {
notification.error({ notification.error({
message: '获取失败', message: '获取失败',
...@@ -137,14 +159,14 @@ const WebDic = () => { ...@@ -137,14 +159,14 @@ const WebDic = () => {
// 提交-添加 // 提交-添加
const submitAdd = value => { const submitAdd = value => {
const nodeName = addForm.getFieldValue('nodeName'); const nodeName1 = addForm.getFieldValue('nodeName1');
const nodeValue = addForm.getFieldValue('nodeValue'); const nodeValue = addForm.getFieldValue('nodeValue');
if (nodeName) { if (nodeName1) {
get(`/Cityinterface/rest/services/OMS.svc/D_AddDataDictionary`, { get(`/Cityinterface/rest/services/OMS.svc/D_AddDataDictionary`, {
_version: 9999, _version: 9999,
_dc: new Date().getTime(), _dc: new Date().getTime(),
nodeID: value, nodeID: value,
nodeName, nodeName: nodeName1,
nodeValue, nodeValue,
}) })
.then(res => { .then(res => {
...@@ -175,16 +197,22 @@ const WebDic = () => { ...@@ -175,16 +197,22 @@ const WebDic = () => {
}); });
} }
}; };
// 提交-编辑 // 提交-修改
const submitEdit = () => { const submitEdit = () => {
const nodeName = editForm.getFieldValue('nodeName'); const nodeName1 = editForm.getFieldValue('nodeName1');
const nodeValue = editForm.getFieldValue('nodeValue'); const nodeValue = editForm.getFieldValue('nodeValue');
if (nodeName) { let nodeID = '';
if (select.parentID === '-1') {
nodeID = { ...select };
} else {
nodeID = { ...subSelect };
}
if (nodeName1) {
get(`/Cityinterface/rest/services/OMS.svc/D_EditDataDictionary`, { get(`/Cityinterface/rest/services/OMS.svc/D_EditDataDictionary`, {
_version: 9999, _version: 9999,
_dc: new Date().getTime(), _dc: new Date().getTime(),
nodeID: select.nodeID, nodeID,
nodeName, nodeName: nodeName1,
nodeValue, nodeValue,
}) })
.then(res => { .then(res => {
...@@ -211,7 +239,7 @@ const WebDic = () => { ...@@ -211,7 +239,7 @@ const WebDic = () => {
}); });
} }
}; };
// 提交-删除
const submitDelete = () => { const submitDelete = () => {
get(`/Cityinterface/rest/services/OMS.svc/D_DeleteDataDictionary`, { get(`/Cityinterface/rest/services/OMS.svc/D_DeleteDataDictionary`, {
_version: 9999, _version: 9999,
...@@ -235,77 +263,68 @@ const WebDic = () => { ...@@ -235,77 +263,68 @@ const WebDic = () => {
message.error(err); message.error(err);
}); });
}; };
const setItem = value => {
setLevel(value);
setAddVisible(true);
addForm.resetFields();
// addForm.setFieldsValue({ nodeName1: '', nodeValue: '' });
};
const pagenation = {
showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`,
pageSizeOptions: [10, 20, 50, 100],
defaultPageSize: '20',
showQuickJumper: true,
showSizeChanger: true,
};
return ( return (
<div className={styles.WebDic}> <div className={styles.WebDic}>
<Spin spinning={loading} tip="loading..."> <Spin spinning={loading} tip="loading...">
<div style={{ marginBottom: '10px', fontSize: '16px' }}> <Row style={{ background: 'white' }}>
<span style={{ padding: '0 10px' }}>一级条目</span> <Col span={12}>
<Button <div style={{ marginBottom: '10px', fontSize: '16px' }}>
type="primary" <span style={{ padding: '0 10px' }}>一级条目</span>
size="small" <Button type="primary" size="small" onClick={() => setItem(1)}>
onClick={() => { 添加
setLevel(1); </Button>
setAddVisible(true); </div>
addForm.resetFields(); {/* 一级条目 表格 */}
}} <Table
> size="small"
添加 bordered
</Button> columns={columns}
</div> dataSource={data}
{/* 一级条目 表格 */} scroll={{ x: 'max-content' }}
<Table rowClassName={setRowClassName}
size="small" onRow={record => ({
bordered onClick: () => {
columns={columns} getData(record.nodeID);
dataSource={data} setSelect(record);
scroll={{ x: 'max-content' }} // setSelectColor(record);
rowClassName={setRowClassName} setSelectID(record.nodeID);
onRow={record => ({ },
onClick: () => { })}
getData(record.nodeID); pagination={pagenation}
setSelect(record); />
setSelectID(record.nodeID); </Col>
}, <Col span={12}>
})} <div style={{ marginBottom: '10px', fontSize: '16px' }}>
pagination={{ <span style={{ padding: '0 10px' }}>二级条目</span>
showTotal: (total, range) => <Button type="primary" size="small" onClick={() => setItem(2)}>
`第${range[0]}-${range[1]} 条/共 ${total} 条`, 添加
pageSizeOptions: [10, 20, 50, 100], </Button>
showQuickJumper: true, </div>
showSizeChanger: true, {/* 二级条目 表格 */}
}} <Table
/> size="small"
<hr color="#cfe7fd" /> bordered
<div style={{ marginBottom: '10px', fontSize: '16px' }}> columns={columns}
<span style={{ padding: '0 10px' }}>二级条目</span> dataSource={subData}
<Button scroll={{ x: 'max-content' }}
type="primary" pagination={pagenation}
size="small" />
onClick={() => { </Col>
setLevel(2); </Row>
setAddVisible(true);
addForm.resetFields();
}}
>
添加
</Button>
</div>
{/* 二级条目 表格 */}
<Table
size="small"
bordered
columns={columns}
dataSource={subData}
scroll={{ x: 'max-content' }}
pagination={{
showTotal: (total, range) =>
`第${range[0]}-${range[1]} 条/共 ${total} 条`,
pageSizeOptions: [10, 20, 50, 100],
showQuickJumper: true,
showSizeChanger: true,
}}
/>
</Spin> </Spin>
{/* 添加 */} {/* 添加 */}
...@@ -327,7 +346,7 @@ const WebDic = () => { ...@@ -327,7 +346,7 @@ const WebDic = () => {
> >
<Form form={addForm} labelCol={{ span: 3 }}> <Form form={addForm} labelCol={{ span: 3 }}>
<Form.Item <Form.Item
name="nodeName" name="nodeName1"
label="名称" label="名称"
rules={[{ required: true, message: '不能为空' }]} rules={[{ required: true, message: '不能为空' }]}
> >
...@@ -351,7 +370,7 @@ const WebDic = () => { ...@@ -351,7 +370,7 @@ const WebDic = () => {
> >
<Form form={editForm} labelCol={{ span: 3 }}> <Form form={editForm} labelCol={{ span: 3 }}>
<Form.Item <Form.Item
name="nodeName" name="nodeName1"
label="名称" label="名称"
rules={[{ required: true, message: '不能为空' }]} rules={[{ required: true, message: '不能为空' }]}
> >
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
color:rgba(0,0,0,0.85); color:rgba(0,0,0,0.85);
} }
.ant-table-content{ .ant-table-content{
height:calc(100vh - 488px); height:calc(100vh - 268px);
border-right: white; border-right: white;
overflow: auto !important; overflow: auto !important;
} }
...@@ -35,10 +35,8 @@ ...@@ -35,10 +35,8 @@
border-top: 1px solid #f0eded; border-top: 1px solid #f0eded;
} }
.ant-table-pagination{ .ant-table-pagination{
padding-right: 12px; padding-top: 10px;
background: white; background: white;
margin: 1px 0;
padding:8px;
padding-right: 20px; padding-right: 20px;
} }
} }
\ No newline at end of file
...@@ -11,7 +11,7 @@ const dictionary = () => { ...@@ -11,7 +11,7 @@ const dictionary = () => {
<PageContainer> <PageContainer>
<Card> <Card>
<Tabs defaultActiveKey="1" type="card"> <Tabs defaultActiveKey="1" type="card">
<TabPane tab="web数据字典" key="1"> <TabPane tab="通用数据字典" key="1">
<WebDic /> <WebDic />
</TabPane> </TabPane>
<TabPane tab="app数据字典" key="2" type="card"> <TabPane tab="app数据字典" key="2" type="card">
......
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