check-data.tsx
4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import React, { useEffect, useState } from 'react';
import { Button, Checkbox } from 'antd';
import { exportProgress, importDataCheck } from '@/pages/app-view/list/service';
import { handleDownload } from '@/libs/htmlHandle';
interface CheckDataProps {
changeNext: any;
taskId: string;
appCode: string;
funCode: string;
viewCode: string;
importWay: string;
current: number;
}
const CheckData: React.FC<CheckDataProps> = (props) => {
const {
changeNext = () => {},
taskId,
appCode,
funCode,
viewCode,
importWay,
current,
} = props;
const [status, setStatus] = useState<string>('loading');
const [dataStatus, setDataStatus] = useState<any>({
status: true,
finalMsg: '',
});
const [nextStatus, setNextStatus] = useState<boolean>(false);
const onChange = (e: any) => {
setNextStatus(e.target?.checked || false);
};
const exportData = (taskType: string) => {
// taskType: UPLOAD || EXPORT
exportProgress(appCode, funCode, viewCode, taskType)
.then((res) => {
if (res.status === 'PROCESSING') {
setTimeout(() => {
exportData('UPLOAD');
}, 6000);
} else if (res.status === 'SUCCESS') {
setDataStatus({
status: true,
finalMsg: res.finalMsg,
downloadUrl: res.downloadUrl || '',
});
if (!res.downloadUrl) {
changeNext(2);
} else {
setStatus('error');
}
} else {
}
})
.catch(() => {});
};
const getCheckData = () => {
importDataCheck(appCode, funCode, viewCode, taskId, importWay)
.then((res: any) => {
if (!res) {
return;
}
if (res.status === 'FAIL') {
// 文件上传不正确
setStatus('error');
setDataStatus({
status: false,
finalMsg: res.finalMsg || '文件上传不正确',
});
} else if (res.status === 'SUCCESS') {
setDataStatus({
status: true,
finalMsg: res.finalMsg,
downloadUrl: res.downloadUrl || '',
});
if (!res.downloadUrl) {
// 代表有错误信息
changeNext(2);
} else {
setStatus('error');
}
} else if (res.status === 'PROCESSING') {
setTimeout(() => {
exportData('UPLOAD');
}, 3000);
}
})
.catch(() => {});
};
useEffect(() => {
if (!taskId || current !== 1) {
return;
}
setStatus('loading');
setNextStatus(false);
getCheckData();
}, [current]);
const downloadError = () => {
handleDownload(dataStatus.downloadUrl, '错误文件.xlsx');
};
return (
<>
<div className={'qx-import-check'}>
{status === 'loading' && (
<div className={'qx-import-check-data'}>
<img src={require('./img/loading.png')} alt={'校验中'} />
<div className={'qx-import-check-loading check-describe'}>
<div>正在对数据进行校验,请等待</div>
<div className={'dot'}>
<div className={'dot-item dot1'} />
<div className={'dot-item dot2'} />
<div className={'dot-item dot3'} />
</div>
</div>
</div>
)}
{status === 'error' && (
<div className={'qx-import-check-error qx-import-check-data'}>
<img src={require('./img/error.png')} alt={'校验失败'} />
{dataStatus.status ? (
<>
<div className={'check-describe'}>
文件中有{' '}
<span style={{ color: '#FF4D4F' }}>
{dataStatus.finalMsg}条
</span>{' '}
错误数据,请{' '}
<span
style={{ color: '#3499FF', cursor: 'pointer' }}
onClick={downloadError}
>
下载错误文件
</span>{' '}
修改后{' '}
<span
style={{ color: '#3499FF', cursor: 'pointer' }}
onClick={() => changeNext(0)}
>
重新上传
</span>
</div>
<Checkbox onChange={onChange}>
跳过校验,错误数据不导入
</Checkbox>
</>
) : (
<div className={'check-describe'}>{dataStatus.finalMsg}</div>
)}
</div>
)}
</div>
<div className={'qx-import-button'}>
<Button onClick={() => changeNext(0)}>上一步</Button>
<Button
disabled={!nextStatus}
type="primary"
onClick={() => changeNext(2)}
>
下一步
</Button>
</div>
</>
);
};
export default CheckData;