perf:完善mib配置

This commit is contained in:
wangwenrui
2020-03-27 14:49:29 +08:00
parent bb472c2a8d
commit c5f40976d5
3 changed files with 98 additions and 28 deletions

View File

@@ -501,6 +501,8 @@ const en = {
mibFile:'Mib File', mibFile:'Mib File',
uploadTip:'please upload mib file', uploadTip:'please upload mib file',
requiredMibFile:'mib file is required', requiredMibFile:'mib file is required',
vendor:'Vendor',
type:'Type',
} }
}, },
alert: { alert: {

View File

@@ -27,7 +27,7 @@
<div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{currentMib.name}}</div> <div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{currentMib.name}}</div>
</el-form-item> </el-form-item>
<el-form-item :label='$t("config.mib.models")' prop="models"> <el-form-item :label='$t("config.mib.models")' prop="models" :rules="[{validator:checkModels,trigger:'change'}]" class="add-required">
<el-cascader <el-cascader
v-if="rightBox.isEdit" v-if="rightBox.isEdit"
:options="modelOptions" :options="modelOptions"
@@ -54,8 +54,8 @@
<el-input maxlength="512" rows="4" show-word-limit v-if="rightBox.isEdit" type="textarea" placeholder="" v-model.trim="currentMib.remark" size="small"></el-input> <el-input maxlength="512" rows="4" show-word-limit v-if="rightBox.isEdit" type="textarea" placeholder="" v-model.trim="currentMib.remark" size="small"></el-input>
<div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{currentMib.remark}}</div> <div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{currentMib.remark}}</div>
</el-form-item> </el-form-item>
<el-form-item :label="$t('config.mib.mibFile')" prop="file" :rules="!currentMib.id?[{validator:checkMibFile,trigger:'change'},{required: true,message:' ',trigger: 'blur'}]:[{validator:checkMibFile,trigger:'change'}]"> <el-form-item :label="$t('config.mib.mibFile')" prop="file" :rules="[{validator:checkMibFile,trigger:'change'}]" :class="{'add-required':!currentMib.id}">
<el-upload v-if="rightBox.isEdit" :multiple="false" action="" :file-list="uploadFileList" :on-change="uploadChange" :auto-upload="false" accept=""> <el-upload v-if="rightBox.isEdit" :multiple="false" action="" :file-list="uploadFileList" :on-change="uploadChange" :auto-upload="false" accept="" :on-remove="afterClearFile" ref="mibFileUpload">
<div slot="tip" class="el-upload__tip" > <div slot="tip" class="el-upload__tip" >
<span v-if="!currentMib.fileName">{{$t('config.mib.uploadTip')}}</span> <span v-if="!currentMib.fileName">{{$t('config.mib.uploadTip')}}</span>
<span v-else>{{currentMib.fileName}}</span> <span v-else>{{currentMib.fileName}}</span>
@@ -95,7 +95,7 @@
let $temp=this; let $temp=this;
return { return {
currentMib: { currentMib: {
id: '', id: null,
name: '', name: '',
remark:'', remark:'',
models:'', models:'',
@@ -109,10 +109,7 @@
rules: { rules: {
name: [ name: [
{required: true, message: this.$t('validate.required'), trigger: 'blur'} {required: true, message: this.$t('validate.required'), trigger: 'blur'}
], ]
models:[
{required: true, message: this.$t('validate.required'), trigger: 'blur'}
],
}, },
checkMibFile : (rule, value, callback) => { checkMibFile : (rule, value, callback) => {
setTimeout(() => { setTimeout(() => {
@@ -128,7 +125,16 @@
$temp.uploadErrorMsg=null; $temp.uploadErrorMsg=null;
return callback(); 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:[], selectedModels:[],
modelOptions:[], modelOptions:[],
@@ -202,14 +208,20 @@
this.$refs.mibForm.validateField('models') this.$refs.mibForm.validateField('models')
}, },
uploadChange:function(file,fileList){ uploadChange:function(file,fileList){
console.log('fileChange')
if (fileList.length > 0) { if (fileList.length > 0) {
this.uploadFileList = [fileList[fileList.length - 1]] 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(); this.validateFile();
}, },
validateFile:function(){ validateFile:function(){
this.$refs.mibForm.validateField('file')
}, },
/*保存*/ /*保存*/
save() { save() {
@@ -220,15 +232,28 @@
form.append('remark',this.currentMib.remark); form.append('remark',this.currentMib.remark);
form.append('models',this.currentMib.models); form.append('models',this.currentMib.models);
form.append('file',this.uploadFile&&this.uploadFile.raw?this.uploadFile.raw:null); form.append('file',this.uploadFile&&this.uploadFile.raw?this.uploadFile.raw:null);
this.$post('/mib',form,{'Content-Type': 'multipart/form-data'}).then(response=>{ if(!this.currentMib.id){
if(response.code==200 && response.msg=='success'){ this.$post('/mib',form,{'Content-Type': 'multipart/form-data'}).then(response=>{
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")}); if(response.code==200 && response.msg=='success'){
this.esc(); this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
this.$emit('after'); this.esc();
}else{ this.$emit('after');
this.$message.error(response.msg); }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(); this.save();
} }
}, },
clearData:function(){
this.currentMib={
id: null,
name: '',
remark:'',
file:'',
models:'',
}
this.uploadFile=null;
this.uploadFileList=[];
this.selectedModels=[];
this.uploadErrorMsg=null;
},
/*删除*/ /*删除*/
del() { del() {
this.$confirm(this.$t("tip.confirmDelete"), { this.$confirm(this.$t("tip.confirmDelete"), {
@@ -292,8 +330,14 @@
<style> <style>
.right-box-mib .right-box-form-row{ .right-box-mib .right-box-form-row{
margin-top:0;
width: 100%; width: 100%;
} }
.add-required .el-form-item__label:before{
content: '*';
color: #F56C6C;
margin-right: 4px;
}
</style> </style>
<style scoped> <style scoped>
/*去除上传文件动画start*/ /*去除上传文件动画start*/

View File

@@ -44,12 +44,35 @@
<span class="clickable" @click="downloadMib(scope.row.id)">{{scope.row[item.prop]}}</span> <span class="clickable" @click="downloadMib(scope.row.id)">{{scope.row[item.prop]}}</span>
</template> </template>
<template v-else-if="item.prop == 'modelsDetail' && scope.row['modelsDetail'] && scope.row['modelsDetail'].length >0"> <template v-else-if="item.prop == 'modelsDetail' && scope.row['modelsDetail'] && scope.row['modelsDetail'].length >0">
<span v-for="(n,i) in scope.row['modelsDetail']" :key="n.name+'-'+n.id+'-'+i" > <div style="max-height: 100px">
<template v-if="i < scope.row['modelsDetail'].length-1"> <el-scrollbar style="height: 100%">
{{n.name}} <span v-for="(n,i) in scope.row['modelsDetail']" :key="n.name+'-'+n.id+'-'+i" >
</template> <el-popover trigger="hover" placement="right" >
<template v-else>{{n.name}}</template> <div>
</span> <div>
<span>{{$t('overall.name')}}:</span>
<span>{{n.name}}</span>
</div>
<div>
<span>{{$t('config.mib.vendor')}}:</span>
<span>{{n.vendor}}</span>
</div>
<div>
<span>{{$t('config.mib.type')}}:</span>
<span>{{n.type}}</span>
</div>
</div>
<template slot="reference">
<template v-if="i < scope.row['modelsDetail'].length-1">
{{n.name}}
<el-divider></el-divider>
</template>
<template v-else>{{n.name}}</template>
</template>
</el-popover>
</span>
</el-scrollbar>
</div>
</template> </template>
<div v-else-if="item.prop == 'option'" class="content-right-options"> <div v-else-if="item.prop == 'option'" class="content-right-options">
<span :title="$t('overall.view')" @click="detail(scope.row)" class="content-right-option" :id="'mib-detail-'+scope.row.id"><i class="nz-icon nz-icon-view"></i></span> <span :title="$t('overall.view')" @click="detail(scope.row)" class="content-right-option" :id="'mib-detail-'+scope.row.id"><i class="nz-icon nz-icon-view"></i></span>
@@ -94,7 +117,7 @@
tableId: 'mibTable', //需要分页的table的id用于记录每页数量 tableId: 'mibTable', //需要分页的table的id用于记录每页数量
showTopBtn: false, showTopBtn: false,
mib: { mib: {
id: '', id: null,
name: '', name: '',
remark:'', remark:'',
models:'', models:'',
@@ -294,13 +317,14 @@
}, },
cleanMib() { cleanMib() {
this.mib = { this.mib = {
id: '', id: null,
name: '', name: '',
remark:'', remark:'',
file:'', file:'',
models:'', models:'',
file:null, file:null,
}; };
this.$refs.mibBox.clearData();
} }
}, },
mounted: function () { mounted: function () {