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

ListWithAddEditTemplate组件修改

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