提交 66b8e6f4 authored 作者: 钟是志's avatar 钟是志

23792 【元数据】导入时第一列数据在验证模版上没有显示

上级 d06980af
...@@ -11,349 +11,362 @@ const Step = Steps.Step; ...@@ -11,349 +11,362 @@ const Step = Steps.Step;
const TabPane = Tabs.TabPane; const TabPane = Tabs.TabPane;
const exportExcel = CLIENT_TYPE == 'mobile' ? null : require('xlsx-oc').exportExcel; const exportExcel = CLIENT_TYPE == 'mobile' ? null : require('xlsx-oc').exportExcel;
let tempCallback = () => {}; let tempCallback = () => {
};
@connect(({ DataObj, loading }) => ({ @connect(({ DataObj, loading }) => ({
DataObj, DataObj,
loading: loading.models.DataObj, loading: loading.models.DataObj,
})) }))
export default class ImportUtil extends React.PureComponent { export default class ImportUtil extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
tempCallback = this.props.callback; tempCallback = this.props.callback;
// const exportTemplateUrl = encodeURI( // const exportTemplateUrl = encodeURI(
// `${config.httpServer}/DataObjApi/importTemplateDownload?objId=${this.props.objId}&name=${ // `${config.httpServer}/DataObjApi/importTemplateDownload?objId=${this.props.objId}&name=${
// props.fileName // props.fileName
// }`, // }`,
// ); // );
this.state = { this.state = {
ch: false, ch: false,
currentKey: '1', currentKey: '1',
visible: false, visible: false,
current: 0, current: 0,
isShow: true, isShow: true,
filekey: '', filekey: '',
sucData: [], sucData: [],
errData: [], errData: [],
column: [], column: [],
confirmLoading: false, confirmLoading: false,
// exportTemplateUrl, // exportTemplateUrl,
isNextDisabled: false, isNextDisabled: false,
}; };
} }
showModal = () => { showModal = () => {
this.setState({ this.setState({
visible: true, visible: true,
}); });
}; };
handleOk = (e) => { handleOk = (e) => {
this.setState({ this.setState({
visible: false, visible: false,
}); });
}; };
handleCancel = (e) => { handleCancel = (e) => {
this.setState({ this.setState({
visible: false, visible: false,
}); });
}; };
next() { next() {
const current = this.state.current + 1; const current = this.state.current + 1;
if (current === 2) { if (current === 2) {
this.setState({ this.setState({
current: current, current: current,
isShow: false, isShow: false,
}); });
if (this.state.errData.lenth > 0) { if (this.state.errData.lenth > 0) {
message.error('请检查数据'); message.error('请检查数据');
return; return;
} else { } else {
this.import(); this.import();
} }
} }
if (current === 3) { if (current === 3) {
console.log('current === 3'); console.log('current === 3');
this.setState({ this.setState({
current: current, current: current,
isShow: true, isShow: true,
},()=>{ }, () => {
if (tempCallback && typeof tempCallback === 'function') { if (tempCallback && typeof tempCallback === 'function') {
tempCallback(); tempCallback();
tempCallback = null; tempCallback = null;
} }
}); });
} }
} }
prev() { prev() {
const current = this.state.current - 1; const current = this.state.current - 1;
this.setState({ current }); this.setState({ current });
} }
import() { import() {
const { dispatch, importParams, importConfig } = this.props; const { dispatch, importParams, importConfig } = this.props;
dispatch({ dispatch({
type: 'DataObj/importExecute', type: 'DataObj/importExecute',
payload: { payload: {
...(importParams || {}), ...(importParams || {}),
cacheKey: this.state.filekey, cacheKey: this.state.filekey,
objId: this.props.objId, objId: this.props.objId,
}, },
callback: (res) => { callback: (res) => {
this.next(); this.next();
message.success('导入成功'); message.success('导入成功');
this.setState({ this.setState({
current: 3, current: 3,
isShow: true, isShow: true,
visible: false, visible: false,
}); });
// if (typeof tempCallback === 'function') { // if (typeof tempCallback === 'function') {
// tempCallback(); // tempCallback();
// tempCallback = null; // tempCallback = null;
// } // }
}, },
}); });
} }
getCachKey = (filePath) => { getCachKey = (filePath) => {
const { dispatch, importParams, importConfig } = this.props; const { dispatch, importParams, importConfig } = this.props;
dispatch({ dispatch({
type: 'DataObj/importAnalyse', type: 'DataObj/importAnalyse',
payload: { payload: {
...(importParams || {}), ...(importParams || {}),
isLocal: false, isLocal: false,
filePath, filePath,
importConfig: importConfig ? JSON.stringify(importConfig) : null, importConfig: importConfig ? JSON.stringify(importConfig) : null,
objId: this.props.objId, objId: this.props.objId,
}, },
callback: (res) => { callback: (res) => {
this.setState({ this.setState({
filekey: res.cacheKey, filekey: res.cacheKey,
}); });
this.queryFile(res.cacheKey); this.queryFile(res.cacheKey);
}, },
}); });
}; };
queryFile = (cacheKey) => { queryFile = (cacheKey) => {
const { dispatch, importParams } = this.props; const { dispatch, importParams } = this.props;
dispatch({ dispatch({
type: 'DataObj/importDataQuery', type: 'DataObj/importDataQuery',
payload: { payload: {
...(importParams || {}), ...(importParams || {}),
cacheKey, cacheKey,
objId: this.props.objId, objId: this.props.objId,
}, },
callback: (res) => { callback: (res) => {
this.setState({ this.setState({
current: 1, current: 1,
isShow: false, isShow: false,
sucData: res.pass, sucData: res.pass,
errData: res.noPass, errData: res.noPass,
column: res.column, column: res.column,
}); });
if (res.noPass && res.noPass.length == 0) { if (res.noPass && res.noPass.length == 0) {
if (res.pass.length == 0) { if (res.pass.length == 0) {
message.error('当前没有验证成功的数据,无法导入。'); message.error('当前没有验证成功的数据,无法导入。');
this.setState({ this.setState({
currentKey: '1', currentKey: '1',
ch: !this.state.ch, ch: !this.state.ch,
isNextDisabled: true, isNextDisabled: true,
}); });
} else { } else {
message.success('所有数据验证通过,请确认后点击下一步。'); message.success('所有数据验证通过,请确认后点击下一步。');
this.setState({ this.setState({
currentKey: '2', currentKey: '2',
ch: !this.state.ch, ch: !this.state.ch,
isNextDisabled: false, isNextDisabled: false,
}); });
} }
} else { } else {
message.error('当前存在未验证通过的数据,请按错误提示检测更正导入文件'); message.error('当前存在未验证通过的数据,请按错误提示检测更正导入文件');
this.setState({ this.setState({
currentKey: '1', currentKey: '1',
ch: !this.state.ch, ch: !this.state.ch,
isNextDisabled: true, isNextDisabled: true,
}); });
} }
}, },
}); });
}; };
changePane = (activeKey) => { changePane = (activeKey) => {
this.setState({ currentKey: activeKey }); this.setState({ currentKey: activeKey });
}; };
exportError = (column, dataSource) => { exportError = (column, dataSource) => {
if (exportExcel == null) { if (exportExcel == null) {
message.info('当前终端暂不支持此功能'); message.info('当前终端暂不支持此功能');
return; return;
} }
var _headers = []; var _headers = [];
for (var i = 0; i < column.length; i++) { for (var i = 0; i < column.length; i++) {
_headers.push({ k: column[i].dataIndex, v: column[i].title }); _headers.push({ k: column[i].dataIndex, v: column[i].title });
} }
for (var j = 0; j < dataSource.length; j++) { for (var j = 0; j < dataSource.length; j++) {
dataSource[j].index = j + 1; dataSource[j].index = j + 1;
} }
exportExcel(_headers, dataSource); exportExcel(_headers, dataSource);
}; };
downloadFile = () => { downloadFile = () => {
this.setState({ confirmLoading: true }); this.setState({ confirmLoading: true });
const { objId, fileName, importParams, importConfig } = this.props; const { objId, fileName, importParams, importConfig } = this.props;
const params = { const params = {
...importParams, ...importParams,
importConfig: importConfig ? JSON.stringify(importConfig) : null, importConfig: importConfig ? JSON.stringify(importConfig) : null,
objId, objId,
fileName, fileName,
token: getToken(), token: getToken(),
}; };
fetch(`${config.httpServer}/DataObjApi/importTemplateDownload`, { fetch(`${config.httpServer}/DataObjApi/importTemplateDownload`, {
method: 'POST', method: 'POST',
body: FormdataWrapper(params), body: FormdataWrapper(params),
}) })
.then((res) => { .then((res) => {
if (res.status != '200') { if (res.status != '200') {
return res.json(); return res.json();
} else { } else {
return res.blob(); return res.blob();
} }
}) })
.then((data) => { .then((data) => {
if (data instanceof Blob) { if (data instanceof Blob) {
let a = document.createElement('a'); let a = document.createElement('a');
let url = window.URL.createObjectURL(data); let url = window.URL.createObjectURL(data);
let filename = let filename =
(this.props.fileName ? this.props.fileName : '导入模板.') + (this.props.ext || 'xlsx'); (this.props.fileName ? this.props.fileName : '导入模板.') + (this.props.ext || 'xlsx');
a.href = url; a.href = url;
a.download = filename; a.download = filename;
a.click(); a.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
a = null; a = null;
} else { } else {
message.error(`文件导出错误`); message.error(`文件导出错误`);
} }
}) })
.catch((err) => { .catch((err) => {
message.error(`网络请求超时`); message.error(`网络请求超时`);
}) })
.finally(() => { .finally(() => {
this.setState({ confirmLoading: false }); this.setState({ confirmLoading: false });
}); });
}; };
render() {
const props = {
name: 'file',
action: config.uploadUrl,
headers: { render() {
authorization: 'authorization-text', const props = {
}, name: 'file',
accept: '.xlsx', action: config.uploadUrl,
showUploadList: false,
onChange: (info) => {
if (info.file.status !== 'uploading') {
}
if (info.file.status === 'done') {
message.success(`${info.file.name} 上传成功`);
let x = info.file.response;
this.getCachKey(x); headers: {
} else if (info.file.status === 'error') { authorization: 'authorization-text',
message.error(`${info.file.name} 上传失败`); },
} accept: '.xlsx',
}, showUploadList: false,
}; onChange: (info) => {
const steps = [ if (info.file.status !== 'uploading') {
{ }
title: '上传Excel', if (info.file.status === 'done') {
}, message.success(`${info.file.name} 上传成功`);
{ let x = info.file.response;
title: '验证数据',
},
{
title: '数据导入',
},
{
title: '导入完成',
},
];
const { current } = this.state; this.getCachKey(x);
const { name, loading } = this.props; } else if (info.file.status === 'error') {
const column1 = this.state.column message.error(`${info.file.name} 上传失败`);
? [ }
{ },
title: '序号', };
dataIndex: 'index', const steps = [
fixed: 'left', {
width: 50, title: '上传Excel',
render: (v, r, i) => i + 1, },
}, {
...this.state.column, title: '验证数据',
] },
: []; {
var column2 = this.state.column ? [...this.state.column] : []; title: '数据导入',
if (column1.length > 1) },
column1[1].render = (val) => <span style={{ color: 'red' }}>{val}</span>; {
title: '导入完成',
},
];
const { current } = this.state;
const { name } = this.props;
const column1 = this.state.column
? [
{
title: '序号',
dataIndex: 'index',
fixed: 'left',
width: 50,
render: (v, r, i) => i + 1,
},
...this.state.column,
]
: [];
let column2 = this.state.column ? [...this.state.column] : [];
if (column1.length > 1) {
column1[1].render = (val) => <span style={{ color: 'red' }}>{val}</span>;
}
column2.splice(0, 1); if (column2) {
column2 = [{ title: '序号', fixed: 'left', width: 50, render: (v, r, i) => i + 1 }, ...column2]; let xuhao = column2.find((g) => g.dataIndex === '序号');
if (!xuhao) {
column2.unshift({
title: '序号',
fixed: 'left',
width: 50,
render: (v, r, i) => i + 1,
dataIndex: '序号',
});
}
}
const btn = { const btn = {
name: name || '批量导入', name: name || '批量导入',
type: 'default', type: 'default',
className: 'defaultBlue', className: 'defaultBlue',
...(this.props.btn ? this.props.btn : {}), ...(this.props.btn ? this.props.btn : {}),
}; };
return ( return (
<span> <span>
<ButtonDiy {...btn} handleClick={this.showModal} /> <ButtonDiy {...btn} handleClick={this.showModal} />
<Modal <Modal
visible={this.state.visible} visible={this.state.visible}
onOk={this.handleOk} onOk={this.handleOk}
maskClosable={false} maskClosable={false}
destroyOnClose destroyOnClose
onCancel={this.handleCancel} onCancel={this.handleCancel}
title={null} title={null}
footer={null} footer={null}
width={'80%'}> width={'80%'}>
<div className={styles.nomal}> <div className={styles.nomal}>
<p className={styles.import}>EXCEL导入向导</p> <p className={styles.import}>EXCEL导入向导</p>
<div style={{ margin: 'auto 23px' }}> <div style={{ margin: 'auto 23px' }}>
<Steps current={current}> <Steps current={current}>
{steps.map((item) => ( {steps.map((item) => (
<Step key={item.title} title={item.title} /> <Step key={item.title} title={item.title} />
))} ))}
</Steps> </Steps>
<div className="steps-content">{steps[this.state.current].content}</div> <div className='steps-content'>{steps[this.state.current].content}</div>
<div className={styles.button}> <div className={styles.button}>
{this.state.current < steps.length - 1 && {this.state.current < steps.length - 1 &&
this.state.current !== 0 && ( this.state.current !== 0 && (
<ButtonDiy <ButtonDiy
name={this.state.current == 3 ? '确认导入' : '下一步'} name={this.state.current == 3 ? '确认导入' : '下一步'}
type="primary" type='primary'
disabled={this.state.current != 3 && this.state.isNextDisabled} disabled={this.state.current != 3 && this.state.isNextDisabled}
// className='primaryBlue' // className='primaryBlue'
handleClick={() => this.next()} handleClick={() => this.next()}
/> />
)} )}
{this.state.current > 0 && ( {this.state.current > 0 && (
<ButtonDiy <ButtonDiy
style={{ marginLeft: 8 }} style={{ marginLeft: 8 }}
name="上一步" name='上一步'
className="defaultBlue" className='defaultBlue'
handleClick={() => this.prev()} handleClick={() => this.prev()}
/> />
)} )}
</div> </div>
</div> </div>
...@@ -365,90 +378,90 @@ export default class ImportUtil extends React.PureComponent { ...@@ -365,90 +378,90 @@ export default class ImportUtil extends React.PureComponent {
</span> </span>
</p> </p>
</div> </div>
{this.state.isShow ? ( {this.state.isShow ? (
<div className={styles.buttonDown}> <div className={styles.buttonDown}>
<Upload {...props}> <Upload {...props}>
<Button> <Button>
<Icon type="upload" /> <Icon type='upload' />
点击上传 点击上传
</Button> </Button>
</Upload> </Upload>
<ButtonDiy <ButtonDiy
name={'下载模板'} name={'下载模板'}
type="primary" type='primary'
// className='primaryBlue' // className='primaryBlue'
handleClick={() => this.downloadFile()} handleClick={() => this.downloadFile()}
loading={this.state.confirmLoading} loading={this.state.confirmLoading}
/> />
</div> </div>
) : ( ) : (
<Upload {...props}> <Upload {...props}>
<Button> <Button>
<Icon type="upload" /> <Icon type='upload' />
重新上传 重新上传
</Button> </Button>
</Upload> </Upload>
)} )}
{this.state.isShow ? ( {this.state.isShow ? (
<div className={styles.attentionItem}> <div className={styles.attentionItem}>
<p>导入事项</p> <p>导入事项</p>
<p>1. 导入操作一次只能上传 1 EXCEL文件。</p> <p>1. 导入操作一次只能上传 1 EXCEL文件。</p>
<p>2. 导入文件最大文件大小上传 1 GB</p> <p>2. 导入文件最大文件大小上传 1 GB</p>
<p>3. 只能上传EXCEL文件(XLS, XLSX) 默认支持EXCEL 2003EXCEL 2007</p> <p>3. 只能上传EXCEL文件(XLS, XLSX) 默认支持EXCEL 2003EXCEL 2007</p>
<p>4. 请将EXCEL文件的所有单元格格式设置为“文本”格式</p> <p>4. 请将EXCEL文件的所有单元格格式设置为“文本”格式</p>
</div> </div>
) : ( ) : (
<div className={styles.error} style={{ marginTop: 20 }}> <div className={styles.error} style={{ marginTop: 20 }}>
<Tabs <Tabs
activeKey={this.state.currentKey} activeKey={this.state.currentKey}
key={this.state.ch} key={this.state.ch}
onChange={this.changePane} onChange={this.changePane}
type="card"> type='card'>
{this.state.errData && this.state.errData.length == 0 ? ( {this.state.errData && this.state.errData.length == 0 ? (
'' ''
) : ( ) : (
<TabPane tab={<span style={{ color: 'red' }}>验证错误列表</span>} key="1"> <TabPane tab={<span style={{ color: 'red' }}>验证错误列表</span>} key='1'>
<Button <Button
style={{ marginTop: 5, marginBottom: 5 }} style={{ marginTop: 5, marginBottom: 5 }}
type="danger" type='danger'
onClick={this.exportError.bind(this, column1, this.state.errData)}> onClick={this.exportError.bind(this, column1, this.state.errData)}>
导出错误信息 导出错误信息
</Button> </Button>
<Table <Table
columns={column1} columns={column1}
size="small" size='small'
style={{ overflow: 'auto' }} style={{ overflow: 'auto' }}
dataSource={this.state.errData} dataSource={this.state.errData}
bordered={true} bordered={true}
scroll={{ x: 'max-content' }} scroll={{ x: 'max-content' }}
/> />
</TabPane> </TabPane>
)} )}
<TabPane tab={<span style={{ color: 'green' }}>验证成功列表</span>} key="2"> <TabPane tab={<span style={{ color: 'green' }}>验证成功列表</span>} key='2'>
<Button <Button
style={{ marginTop: 5, marginBottom: 5 }} style={{ marginTop: 5, marginBottom: 5 }}
type="primary" type='primary'
onClick={this.exportError.bind(this, column2, this.state.sucData)}> onClick={this.exportError.bind(this, column2, this.state.sucData)}>
导出正确信息 导出正确信息
</Button> </Button>
<Table <Table
columns={column2} columns={column2}
size="small" size='small'
style={{ overflow: 'auto' }} style={{ overflow: 'auto' }}
dataSource={this.state.sucData} dataSource={this.state.sucData}
bordered={true} bordered={true}
scroll={{ x: 'max-content' }} scroll={{ x: 'max-content' }}
/> />
</TabPane> </TabPane>
</Tabs> </Tabs>
</div> </div>
)} )}
</div> </div>
</Modal> </Modal>
</span> </span>
); );
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论