2020-03-26 19:58:09 +08:00
|
|
|
|
<template>
|
2021-01-18 18:58:57 +08:00
|
|
|
|
<div class="right-box right-box-mib" v-clickoutside="{obj:editMib,func:clickOutside}" >
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!-- begin--顶部按钮-->
|
2020-10-15 14:27:46 +08:00
|
|
|
|
<div class="right-box-top-btns right-box-form-delete">
|
2020-12-08 21:53:37 +08:00
|
|
|
|
<button @click="del" class="nz-btn nz-btn-size-normal nz-btn-size-alien" id="mib-del" type="button" v-has="'snmp_file_delete'" v-if="editMib.id">
|
2020-09-10 17:00:32 +08:00
|
|
|
|
<span class="right-box-top-btn-icon"><i class="nz-icon nz-icon-delete"></i></span>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<span class="right-box-top-btn-txt">{{$t('overall.delete')}}</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<!-- end--顶部按钮-->
|
2020-03-26 19:58:09 +08:00
|
|
|
|
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!-- begin--标题-->
|
|
|
|
|
|
<div class="right-box-title">{{editMib.id ? ($t("config.mib.editMib") + " ID:" + editMib.id) : $t("config.mib.createMib")}}</div>
|
|
|
|
|
|
<!-- end--标题-->
|
2020-03-26 19:58:09 +08:00
|
|
|
|
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!-- begin--表单-->
|
2020-12-14 20:25:24 +08:00
|
|
|
|
<div class="right-box-form-box">
|
2021-02-09 15:14:19 +08:00
|
|
|
|
<el-form class="right-box-form right-box-form-left" :model="editMib" label-position = "top" label-width="120px" :rules="rules" ref="mibForm">
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<el-form-item :label='$t("config.mib.models")' prop="models" :rules="[{validator:checkModels,trigger:'change'}]" >
|
|
|
|
|
|
<el-cascader
|
2021-02-04 11:21:00 +08:00
|
|
|
|
id="mib-input-selected-models"
|
2020-07-24 19:22:52 +08:00
|
|
|
|
:options="modelOptions"
|
|
|
|
|
|
:props="modelProps"
|
|
|
|
|
|
:show-all-levels="false"
|
|
|
|
|
|
v-model="selectedModels"
|
|
|
|
|
|
@change="selectedModelChange"
|
|
|
|
|
|
ref="modelSelector"
|
|
|
|
|
|
collapse-tags
|
|
|
|
|
|
:placeholder="$t('config.mib.modelTip')"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
class="right-box-form-row"
|
|
|
|
|
|
clearable></el-cascader>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item :label="$t('config.mib.remark')" prop="remark">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<el-input maxlength="512" rows="4" show-word-limit type="textarea" placeholder="" v-model="editMib.remark" size="small" id="mib-box-input-remark"></el-input>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item :label="$t('config.mib.mibFiles')" prop="file" :rules="[{validator:checkMibFile,trigger:'change'}]" :class="{'add-required':!editMib.id}">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<el-upload drag :multiple="false" action="" :file-list="uploadFileList" :on-change="uploadChange" :auto-upload="false" accept="" :on-remove="afterClearFile" ref="mibFileUpload" class="mib-upload right-box-form-row" id="mib-box-input-file">
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<div slot="tip" class="el-upload__tip" >
|
|
|
|
|
|
<span v-if="editMib.fileName">{{editMib.fileName}}</span>
|
|
|
|
|
|
<span v-if="uploadErrorMsg" style="color: #F56C6C"><br>{{uploadErrorMsg}}</span>
|
2020-03-26 19:58:09 +08:00
|
|
|
|
</div>
|
2020-09-10 17:00:32 +08:00
|
|
|
|
<i class="nz-icon nz-icon-upload"></i>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<div class="el-upload__text">{{$t('overall.dragFileTip')}},{{$t('overall.or')}} <em>{{$t('overall.clickUpload')}}</em></div>
|
|
|
|
|
|
</el-upload>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
2020-12-14 20:25:24 +08:00
|
|
|
|
</div>
|
2020-03-26 19:58:09 +08:00
|
|
|
|
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!--底部按钮-->
|
|
|
|
|
|
<div class="right-box-bottom-btns">
|
2021-01-18 18:58:57 +08:00
|
|
|
|
<button v-cancel="{obj:editMib,func:esc}" id="model-box-esc" class="nz-btn nz-btn-size-normal-new nz-btn-style-light-new">
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<span>{{$t('overall.cancel')}}</span>
|
|
|
|
|
|
</button>
|
2021-01-21 17:29:29 +08:00
|
|
|
|
<button :class="{'nz-btn-disabled':prevent_opt.save}" :disabled="prevent_opt.save" @click="save" class="nz-btn nz-btn-size-normal-new nz-btn-style-normal-new" id="model-box-save">
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<span>{{$t('overall.save')}}</span>
|
|
|
|
|
|
</button>
|
2020-03-26 19:58:09 +08:00
|
|
|
|
</div>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
|
|
|
|
|
|
</div>
|
2020-03-26 19:58:09 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: "modelBox",
|
|
|
|
|
|
props: {
|
|
|
|
|
|
mib: Object
|
|
|
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
|
|
|
let $temp=this;
|
|
|
|
|
|
return {
|
2020-07-24 19:22:52 +08:00
|
|
|
|
editMib: {},
|
2020-03-26 19:58:09 +08:00
|
|
|
|
rules: {
|
|
|
|
|
|
name: [
|
|
|
|
|
|
{required: true, message: this.$t('validate.required'), trigger: 'blur'}
|
2020-03-27 14:49:29 +08:00
|
|
|
|
]
|
2020-03-26 19:58:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
checkMibFile : (rule, value, callback) => {
|
|
|
|
|
|
setTimeout(() => {
|
2020-07-24 19:22:52 +08:00
|
|
|
|
if(!$temp.editMib.id){
|
2020-03-26 19:58:09 +08:00
|
|
|
|
if(!$temp.uploadFile || !$temp.uploadFile.raw){
|
|
|
|
|
|
$temp.uploadErrorMsg=$temp.$t('config.mib.requiredMibFile');
|
|
|
|
|
|
return callback(new Error(' '));
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$temp.uploadErrorMsg=null;
|
|
|
|
|
|
return callback()
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$temp.uploadErrorMsg=null;
|
|
|
|
|
|
return callback();
|
|
|
|
|
|
}
|
2020-03-27 14:49:29 +08:00
|
|
|
|
}, 200);
|
|
|
|
|
|
},
|
|
|
|
|
|
checkModels:(rule, value, callback)=>{
|
|
|
|
|
|
setTimeout(() => {
|
2020-07-24 19:22:52 +08:00
|
|
|
|
if(!$temp.editMib.models||$temp.editMib.models == ''){
|
2020-04-13 18:00:41 +08:00
|
|
|
|
// return callback(new Error($temp.$t('validate.required')))
|
|
|
|
|
|
return callback();
|
2020-03-27 14:49:29 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
return callback();
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 200);
|
2020-03-26 19:58:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
selectedModels:[],
|
|
|
|
|
|
modelOptions:[],
|
|
|
|
|
|
modelProps: { multiple: true ,emitPath:false},
|
|
|
|
|
|
uploadFileList:[],
|
|
|
|
|
|
uploadFile:null,
|
|
|
|
|
|
uploadErrorMsg:null,
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2020-07-24 19:22:52 +08:00
|
|
|
|
clickOutside() {
|
|
|
|
|
|
this.esc(false);
|
2020-03-26 19:58:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
/*关闭弹框*/
|
2020-07-24 19:22:52 +08:00
|
|
|
|
esc(refresh) {
|
|
|
|
|
|
this.$emit("close", refresh);
|
2020-03-26 19:58:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
queryModelInfos:function(){
|
|
|
|
|
|
this.$get('model?pageSize=-1').then(response=>{
|
|
|
|
|
|
if(response.code == 200){
|
|
|
|
|
|
let modelInfos=response.data.list;
|
|
|
|
|
|
let sortModels={};
|
|
|
|
|
|
modelInfos.forEach((item)=>{
|
|
|
|
|
|
if(!sortModels[item.type.value]){//没有这个assetType
|
|
|
|
|
|
sortModels[item.type.value]={}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!sortModels[item.type.value][item.vendor.value]){
|
|
|
|
|
|
sortModels[item.type.value][item.vendor.value]=[];
|
|
|
|
|
|
}
|
|
|
|
|
|
item.label=item.name;
|
|
|
|
|
|
item.value=item.id;
|
|
|
|
|
|
sortModels[item.type.value][item.vendor.value].push(item);
|
|
|
|
|
|
})
|
|
|
|
|
|
for (let assetType of Object.keys(sortModels)){
|
|
|
|
|
|
let option={
|
|
|
|
|
|
label:assetType,
|
|
|
|
|
|
value:assetType,
|
|
|
|
|
|
children:[]
|
|
|
|
|
|
}
|
|
|
|
|
|
for(let vendor of Object.keys(sortModels[assetType])){
|
|
|
|
|
|
let child={
|
|
|
|
|
|
label:vendor,
|
|
|
|
|
|
value:vendor,
|
|
|
|
|
|
children: sortModels[assetType][vendor]
|
|
|
|
|
|
}
|
|
|
|
|
|
option.children.push(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.modelOptions.push(option);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
selectedModelChange:function(nodes){
|
|
|
|
|
|
let selectedNodes=this.selectedModels;
|
|
|
|
|
|
if(selectedNodes && selectedNodes.length>0){
|
|
|
|
|
|
let models='';
|
|
|
|
|
|
for(let node of selectedNodes){
|
|
|
|
|
|
models+=node+',';
|
|
|
|
|
|
}
|
2020-07-24 19:22:52 +08:00
|
|
|
|
this.editMib.models=models.substr(0,models.length-1);
|
2020-03-26 19:58:09 +08:00
|
|
|
|
}else{
|
2020-07-24 19:22:52 +08:00
|
|
|
|
this.editMib.models='';
|
2020-03-26 19:58:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
this.$refs.mibForm.validateField('models')
|
|
|
|
|
|
},
|
2020-07-24 19:22:52 +08:00
|
|
|
|
uploadChange(file,fileList) {
|
2020-03-26 19:58:09 +08:00
|
|
|
|
if (fileList.length > 0) {
|
2020-07-24 19:22:52 +08:00
|
|
|
|
this.uploadFileList = [fileList[fileList.length - 1]];
|
2020-03-27 14:49:29 +08:00
|
|
|
|
this.uploadFile = this.uploadFileList[0];
|
2020-03-26 19:58:09 +08:00
|
|
|
|
}
|
2020-03-27 14:49:29 +08:00
|
|
|
|
this.validateFile();
|
|
|
|
|
|
},
|
2020-07-24 19:22:52 +08:00
|
|
|
|
afterClearFile(file, fileList) {
|
2020-03-27 14:49:29 +08:00
|
|
|
|
this.uploadFileList = [];
|
|
|
|
|
|
this.uploadFile = null;
|
2020-03-26 19:58:09 +08:00
|
|
|
|
this.validateFile();
|
|
|
|
|
|
},
|
|
|
|
|
|
validateFile:function(){
|
2020-03-27 14:49:29 +08:00
|
|
|
|
this.$refs.mibForm.validateField('file')
|
2020-03-26 19:58:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
/*保存*/
|
|
|
|
|
|
save() {
|
|
|
|
|
|
this.$refs.mibForm.validate((valid) => {
|
|
|
|
|
|
if (valid) {
|
2020-12-21 13:56:36 +08:00
|
|
|
|
this.prevent_opt.save=true;
|
2020-03-26 19:58:09 +08:00
|
|
|
|
let form = new FormData();
|
2020-07-24 19:22:52 +08:00
|
|
|
|
form.append('name',this.editMib.name);
|
|
|
|
|
|
form.append('remark',this.editMib.remark);
|
|
|
|
|
|
form.append('models',this.editMib.models);
|
|
|
|
|
|
form.append('file', this.uploadFile && this.uploadFile.raw ? this.uploadFile.raw : null);
|
|
|
|
|
|
if(!this.editMib.id){
|
|
|
|
|
|
this.$post('/mib', form, {'Content-Type': 'multipart/form-data'}).then(response=>{
|
|
|
|
|
|
if(response.code==200 && response.msg == 'success'){
|
2020-03-27 14:49:29 +08:00
|
|
|
|
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
|
2020-07-24 19:22:52 +08:00
|
|
|
|
this.esc(true);
|
2020-03-27 14:49:29 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
this.$message.error(response.msg);
|
|
|
|
|
|
}
|
2020-12-21 13:56:36 +08:00
|
|
|
|
this.prevent_opt.save=false;
|
2020-03-27 14:49:29 +08:00
|
|
|
|
})
|
|
|
|
|
|
}else{
|
2020-07-24 19:22:52 +08:00
|
|
|
|
form.append('id',this.editMib.id);
|
2020-03-27 14:49:29 +08:00
|
|
|
|
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")});
|
2020-07-24 19:22:52 +08:00
|
|
|
|
this.esc(true);
|
2020-03-27 14:49:29 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
this.$message.error(response.msg);
|
|
|
|
|
|
}
|
2020-12-21 13:56:36 +08:00
|
|
|
|
this.prevent_opt.save=false;
|
2020-03-27 14:49:29 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2020-12-21 13:56:36 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
this.prevent_opt.save=false;
|
2020-03-26 19:58:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
/*删除*/
|
|
|
|
|
|
del() {
|
|
|
|
|
|
this.$confirm(this.$t("tip.confirmDelete"), {
|
|
|
|
|
|
confirmButtonText: this.$t("tip.yes"),
|
|
|
|
|
|
cancelButtonText: this.$t("tip.no"),
|
|
|
|
|
|
type: 'warning'
|
|
|
|
|
|
}).then(() => {
|
2020-07-24 19:22:52 +08:00
|
|
|
|
this.$delete("mib?ids=" + this.editMib.id).then(response => {
|
2020-03-26 19:58:09 +08:00
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
this.$message({duration: 1000, type: 'success', message: this.$t("tip.deleteSuccess")});
|
2020-07-24 19:22:52 +08:00
|
|
|
|
this.esc(true);
|
2020-03-26 19:58:09 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.$message.error(response.msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted() {
|
|
|
|
|
|
this.queryModelInfos();
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
mib: {
|
|
|
|
|
|
immediate: true,
|
2020-07-24 19:22:52 +08:00
|
|
|
|
deep: true,
|
2020-03-26 19:58:09 +08:00
|
|
|
|
handler(n, o) {
|
2020-07-24 19:22:52 +08:00
|
|
|
|
this.editMib = JSON.parse(JSON.stringify(n));
|
|
|
|
|
|
if(this.editMib.models){
|
|
|
|
|
|
this.selectedModels = this.editMib.models.split(',');
|
2020-03-26 19:58:09 +08:00
|
|
|
|
}else{
|
2020-07-24 19:22:52 +08:00
|
|
|
|
this.selectedModels = [];
|
2020-03-26 19:58:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
.right-box-mib .right-box-form-row{
|
2020-03-27 14:49:29 +08:00
|
|
|
|
margin-top:0;
|
2020-03-26 19:58:09 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
}
|
2020-03-27 14:49:29 +08:00
|
|
|
|
.add-required .el-form-item__label:before{
|
|
|
|
|
|
content: '*';
|
|
|
|
|
|
color: #F56C6C;
|
|
|
|
|
|
margin-right: 4px;
|
|
|
|
|
|
}
|
2020-04-08 19:18:30 +08:00
|
|
|
|
.mib-upload .el-upload{
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
}
|
|
|
|
|
|
.mib-upload /deep/.el-upload-dragger{
|
|
|
|
|
|
width: 100% !important;
|
|
|
|
|
|
}
|
2020-03-26 19:58:09 +08:00
|
|
|
|
</style>
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
/*去除上传文件动画start*/
|
|
|
|
|
|
/*.upload-demo {*/
|
|
|
|
|
|
/* display: flex;*/
|
|
|
|
|
|
/*}*/
|
|
|
|
|
|
/deep/ .el-list-enter-active,
|
|
|
|
|
|
/deep/ .el-list-leave-active {
|
|
|
|
|
|
transition: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
.nz-tab {
|
|
|
|
|
|
margin-bottom: 22px;
|
|
|
|
|
|
margin-left: 13px;
|
|
|
|
|
|
}
|
|
|
|
|
|
/deep/ .el-list-enter,
|
|
|
|
|
|
/deep/ .el-list-leave-active {
|
|
|
|
|
|
opacity: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
/deep/ .el-upload-list {
|
|
|
|
|
|
height: 40px;
|
|
|
|
|
|
}
|
2020-09-17 10:46:47 +08:00
|
|
|
|
.el-upload .nz-icon-upload{
|
|
|
|
|
|
font-size: 67px;
|
|
|
|
|
|
color: #c0c4cc;
|
|
|
|
|
|
margin: 40px 0 16px;
|
|
|
|
|
|
line-height: 50px;
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
}
|
2020-03-26 19:58:09 +08:00
|
|
|
|
/*去除上传文件动画end*/
|
|
|
|
|
|
</style>
|