diff --git a/spug_api/apps/host/views.py b/spug_api/apps/host/views.py index 3d497b1..d2a4d5b 100644 --- a/spug_api/apps/host/views.py +++ b/spug_api/apps/host/views.py @@ -98,7 +98,7 @@ def post_import(request): password = request.POST.get('password') file = request.FILES['file'] ws = load_workbook(file, read_only=True)['Sheet1'] - summary = {'invalid': [], 'skip': [], 'fail': [], 'network': [], 'repeat': [], 'success': []} + summary = {'invalid': [], 'skip': [], 'fail': [], 'network': [], 'repeat': [], 'success': [], 'error': []} for i, row in enumerate(ws.rows): if i == 0: # 第1行是表头 略过 continue @@ -128,6 +128,9 @@ def post_import(request): except socket.error: summary['network'].append(i) continue + except Exception: + summary['error'].append(i) + continue if Host.objects.filter(name=data.name, deleted_by_id__isnull=True).exists(): summary['repeat'].append(i) continue diff --git a/spug_web/src/pages/host/Import.js b/spug_web/src/pages/host/Import.js index 6c0b254..20d7cbc 100644 --- a/spug_web/src/pages/host/Import.js +++ b/spug_web/src/pages/host/Import.js @@ -46,15 +46,21 @@ class ComImport extends React.Component { {res['repeat'].length > 0 && {res['repeat'].length} } + {res['error'].length > 0 && + {res['error'].length} + } }) }) .finally(() => this.setState({loading: false})) }; - beforeUpload = (file) => { - this.setState({fileList: [file]}); - return false + handleUpload = (v) => { + if (v.fileList.length === 0) { + this.setState({fileList: []}) + } else { + this.setState({fileList: [v.file]}) + } }; render() { @@ -83,7 +89,8 @@ class ComImport extends React.Component { placeholder="请输入默认主机密码"/> - + false} + onChange={this.handleUpload}>