提交 331c5659 authored 作者: 王绍森's avatar 王绍森

ListWithAddEditTemplate组件修改

上级 6c500a23
...@@ -58,7 +58,7 @@ class ListWithAddEditTemplate extends React.Component { ...@@ -58,7 +58,7 @@ class ListWithAddEditTemplate extends React.Component {
isAdd: false, // 是新增还是编辑 isAdd: false, // 是新增还是编辑
selectedRows: [], selectedRows: [],
primaryKey: null, primaryKey: null,
showEdit: false, // 是否显示编辑区域 // showEdit: false, // 是否显示编辑区域
pageData: { pageData: {
list: [], list: [],
pagination: {}, pagination: {},
...@@ -114,12 +114,12 @@ class ListWithAddEditTemplate extends React.Component { ...@@ -114,12 +114,12 @@ class ListWithAddEditTemplate extends React.Component {
// 新增按钮事件 // 新增按钮事件
add = () => { add = () => {
const { headerList } = this.state; const { headerList } = this.state;
const showEdit = headerList.length >= 10; // const showEdit = headerList.length >= 10;
this.setState({ this.setState({
modalVisible: !showEdit, modalVisible: true,
formData: {}, formData: {},
isAdd: true, isAdd: true,
showEdit, // showEdit,
}); });
}; };
...@@ -127,18 +127,21 @@ class ListWithAddEditTemplate extends React.Component { ...@@ -127,18 +127,21 @@ class ListWithAddEditTemplate extends React.Component {
modify = record => { modify = record => {
const recordTemp = { ...record, update_time: Date.now() }; const recordTemp = { ...record, update_time: Date.now() };
const { headerList } = this.state; const { headerList } = this.state;
const showEdit = headerList.length >= 10; // const showEdit = headerList.length >= 10;
// 把record里明文key改成转换后的key,用于在模板表单中回显 // 把record里明文key改成转换后的key,用于在模板表单中回显
const headerMap = headerList.reduce((acc, header) => ({ ...acc, [header.name]: header }), {}); const headerMap = headerList.reduce((acc, header) => ({ ...acc, [header.name]: header }), {});
const formData = Object.keys(recordTemp).reduce( const formData = Object.keys(recordTemp).reduce(
(acc, key) => ({ ...acc, [headerMap[key].base52]: recordTemp[key] }), (acc, key) => {
if (!headerMap[key]) return acc;
return { ...acc, [headerMap[key].base52]: recordTemp[key] };
},
{} {}
); );
this.setState({ this.setState({
formData, formData,
modalVisible: !showEdit, modalVisible: true,
isAdd: false, isAdd: false,
showEdit, // showEdit,
}); });
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论