From c5f40976d5535d2e7579beeb2510c43cf0b4408a Mon Sep 17 00:00:00 2001 From: wangwenrui Date: Fri, 27 Mar 2020 14:49:29 +0800 Subject: [PATCH] =?UTF-8?q?perf:=E5=AE=8C=E5=96=84mib=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/common/language/en.js | 2 + .../src/components/common/rightBox/mibBox.vue | 84 ++++++++++++++----- .../src/components/page/config/mib.vue | 40 +++++++-- 3 files changed, 98 insertions(+), 28 deletions(-) diff --git a/nezha-fronted/src/components/common/language/en.js b/nezha-fronted/src/components/common/language/en.js index 0f7e8c6d5..8d4ca261f 100644 --- a/nezha-fronted/src/components/common/language/en.js +++ b/nezha-fronted/src/components/common/language/en.js @@ -501,6 +501,8 @@ const en = { mibFile:'Mib File', uploadTip:'please upload mib file', requiredMibFile:'mib file is required', + vendor:'Vendor', + type:'Type', } }, alert: { diff --git a/nezha-fronted/src/components/common/rightBox/mibBox.vue b/nezha-fronted/src/components/common/rightBox/mibBox.vue index 9dbd3c475..7d64e9899 100644 --- a/nezha-fronted/src/components/common/rightBox/mibBox.vue +++ b/nezha-fronted/src/components/common/rightBox/mibBox.vue @@ -27,7 +27,7 @@
{{currentMib.name}}
- +
{{currentMib.remark}}
- - + +
{{$t('config.mib.uploadTip')}} {{currentMib.fileName}} @@ -95,7 +95,7 @@ let $temp=this; return { currentMib: { - id: '', + id: null, name: '', remark:'', models:'', @@ -109,10 +109,7 @@ rules: { name: [ {required: true, message: this.$t('validate.required'), trigger: 'blur'} - ], - models:[ - {required: true, message: this.$t('validate.required'), trigger: 'blur'} - ], + ] }, checkMibFile : (rule, value, callback) => { setTimeout(() => { @@ -128,7 +125,16 @@ $temp.uploadErrorMsg=null; return callback(); } - }, 500); + }, 200); + }, + checkModels:(rule, value, callback)=>{ + setTimeout(() => { + if(!$temp.currentMib.models||$temp.currentMib.models == ''){ + return callback(new Error($temp.$t('validate.required'))) + }else{ + return callback(); + } + }, 200); }, selectedModels:[], modelOptions:[], @@ -202,14 +208,20 @@ this.$refs.mibForm.validateField('models') }, uploadChange:function(file,fileList){ + console.log('fileChange') if (fileList.length > 0) { this.uploadFileList = [fileList[fileList.length - 1]] + this.uploadFile = this.uploadFileList[0]; } - this.uploadFile = this.uploadFileList[0]; + this.validateFile(); + }, + afterClearFile:function(file, fileList){ + this.uploadFileList = []; + this.uploadFile = null; this.validateFile(); }, validateFile:function(){ - + this.$refs.mibForm.validateField('file') }, /*保存*/ save() { @@ -220,15 +232,28 @@ form.append('remark',this.currentMib.remark); form.append('models',this.currentMib.models); form.append('file',this.uploadFile&&this.uploadFile.raw?this.uploadFile.raw:null); - this.$post('/mib',form,{'Content-Type': 'multipart/form-data'}).then(response=>{ - if(response.code==200 && response.msg=='success'){ - this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")}); - this.esc(); - this.$emit('after'); - }else{ - this.$message.error(response.msg); - } - }) + if(!this.currentMib.id){ + this.$post('/mib',form,{'Content-Type': 'multipart/form-data'}).then(response=>{ + if(response.code==200 && response.msg=='success'){ + this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")}); + this.esc(); + this.$emit('after'); + }else{ + this.$message.error(response.msg); + } + }) + }else{ + form.append('id',this.currentMib.id); + this.$put('/mib',form,{'Content-Type': 'multipart/form-data'}).then(response=>{ + if(response.code==200 && response.msg=='success'){ + this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")}); + this.esc(); + this.$emit('after'); + }else{ + this.$message.error(response.msg); + } + }) + } } }) }, @@ -240,6 +265,19 @@ this.save(); } }, + clearData:function(){ + this.currentMib={ + id: null, + name: '', + remark:'', + file:'', + models:'', + } + this.uploadFile=null; + this.uploadFileList=[]; + this.selectedModels=[]; + this.uploadErrorMsg=null; + }, /*删除*/ del() { this.$confirm(this.$t("tip.confirmDelete"), { @@ -292,8 +330,14 @@