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

perf: dictionary

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