From bbac4202345fa33622390b1547914a7f04d35738 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 5 Aug 2020 18:24:23 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/host/views.py | 5 ++++- spug_web/src/pages/host/Import.js | 15 +++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) 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}>