2021-04-14 19:17:16 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="right-box right-box-credential" v-clickoutside="{obj:editCredential,func:clickOutside}">
|
|
|
|
|
<!-- begin--标题-->
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="right-box__header">
|
2021-05-11 10:37:58 +08:00
|
|
|
<div class="header__title">{{editCredential.id ? ($t("config.mib.credential.edit")) : $t("config.mib.credential.create")}}</div>
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="header__operation">
|
|
|
|
|
<span v-cancel="{obj: editCredential, func: esc}"><i class="nz-icon nz-icon-close"></i></span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-04-14 19:17:16 +08:00
|
|
|
<!-- begin--表单-->
|
2021-04-29 10:56:41 +08:00
|
|
|
<div class="right-box__container">
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="container__form">
|
|
|
|
|
<el-form label-width="120px" size="small" :model="editCredential" label-position = "top" :rules="rules" ref="credentialForm">
|
|
|
|
|
<el-form-item :label='$t("overall.name")' prop="name">
|
|
|
|
|
<el-input placeholder="" maxlength="64" show-word-limit v-model="editCredential.name" size="small" id="credential-box-input-name"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label='$t("config.mib.credential.remark")' prop="remark">
|
|
|
|
|
<el-input placeholder="" v-model="editCredential.remark" size="small" id="credential-box-input-remark"></el-input>
|
|
|
|
|
</el-form-item>
|
2021-04-30 15:12:34 +08:00
|
|
|
<el-form-item :label='$t("config.mib.credential.type")' prop="type">
|
|
|
|
|
<el-select v-model="editCredential.type" placeholder="" id="credential-box-input-type" class="right-box__select" popper-class="right-box-select-dropdown prevent-clickoutside" @change="typeChange">
|
2021-04-30 12:59:36 +08:00
|
|
|
<el-option v-for="item in $CONSTANTS.snmpProtocolTypes" :key="item.value" :label="item.label" :value="item.value">
|
|
|
|
|
<span class="panel-dropdown-label-txt" >{{item.label}}</span>
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
2021-04-30 15:12:34 +08:00
|
|
|
<el-form-item :label='$t("config.mib.credential.port")' prop="port" >
|
2021-04-30 12:59:36 +08:00
|
|
|
<el-input placeholder="" v-model.number="editCredential.port" size="small" id="credential-box-input-port"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label='Read community' prop="readCommunity" v-if="editCredential.type ===1 || editCredential.type === 2">
|
2021-05-13 17:13:01 +08:00
|
|
|
<el-input placeholder="" autocomplete="new-password" v-model="editCredential.config.readCommunity" size="small" id="credential-box-input-readCommunity"></el-input>
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label='Write community' prop="writeCommunity" v-if="editCredential.type ===1 || editCredential.type === 2">
|
2021-05-13 17:13:01 +08:00
|
|
|
<el-input placeholder="" autocomplete="new-password" v-model="editCredential.config.writeCommunity" size="small" id="credential-box-input-writeCommunity" type="password" show-password></el-input>
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-form-item>
|
2021-04-30 15:12:34 +08:00
|
|
|
<el-form-item label="Username" prop="username" v-if="editCredential.type === 3">
|
2021-04-30 12:59:36 +08:00
|
|
|
<el-input placeholder="" v-model="editCredential.config.username" size="small" id="credential-box-input-username"></el-input>
|
|
|
|
|
</el-form-item>
|
2021-04-30 15:12:34 +08:00
|
|
|
<el-form-item label="Content name" prop="contextname" v-if="editCredential.type === 3">
|
2021-04-30 12:59:36 +08:00
|
|
|
<el-input placeholder="" v-model="editCredential.config.contextname" size="small" id="credential-box-input-contextname"></el-input>
|
|
|
|
|
</el-form-item>
|
2021-04-14 19:17:16 +08:00
|
|
|
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="right-box-sub-title" v-if="editCredential.type === 3">{{$t('config.mib.credential.auth')}}</div>
|
|
|
|
|
<div style="margin-bottom: 20px;width: 100%"></div>
|
2021-04-14 19:17:16 +08:00
|
|
|
|
2021-04-30 15:12:34 +08:00
|
|
|
<el-form-item :label='$t("config.mib.credential.method")' prop="authProtocol" v-if="editCredential.type === 3">
|
|
|
|
|
<el-select v-model="editCredential.config.authProtocol" placeholder="" id="credential-box-input-type" class="right-box__select" popper-class="right-box-select-dropdown prevent-clickoutside">
|
2021-04-30 12:59:36 +08:00
|
|
|
<el-option v-for="item in $CONSTANTS.snmpAuthMethod" :key="item.value" :label="item.label" :value="item.value">
|
|
|
|
|
<span class="panel-dropdown-label-txt" >{{item.label}}</span>
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
2021-04-30 15:12:34 +08:00
|
|
|
<el-form-item :label='$t("config.mib.credential.pin")' prop="authPin" v-if="editCredential.type === 3">
|
2021-05-13 17:13:01 +08:00
|
|
|
<el-input placeholder="" autocomplete="new-password" v-model="editCredential.config.authPin" size="small" id="credential-box-input-authPin" type="password" show-password></el-input>
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-form-item>
|
2021-04-14 19:17:16 +08:00
|
|
|
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="right-box-sub-title" v-if="editCredential.type === 3">{{$t('config.mib.credential.encryption')}}</div>
|
|
|
|
|
<div style="margin-bottom: 20px;width: 100%"></div>
|
2021-04-14 19:17:16 +08:00
|
|
|
|
2021-04-30 15:12:34 +08:00
|
|
|
<el-form-item :label='$t("config.mib.credential.method")' prop="privProtocol" v-if="editCredential.type === 3">
|
|
|
|
|
<el-select v-model="editCredential.config.privProtocol" placeholder="" id="credential-box-input-type" class="right-box__select" popper-class="right-box-select-dropdown prevent-clickoutside" :disabled="!editCredential.config.authProtocol || editCredential.config.authProtocol === ''">
|
2021-04-30 12:59:36 +08:00
|
|
|
<el-option v-for="item in $CONSTANTS.snmpEncryptionMethod" :key="item.value" :label="item.label" :value="item.value">
|
|
|
|
|
<span class="panel-dropdown-label-txt" >{{item.label}}</span>
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
2021-04-30 15:12:34 +08:00
|
|
|
<el-form-item :label='$t("config.mib.credential.pin")' prop="privPin" v-if="editCredential.type === 3">
|
2021-05-13 17:13:01 +08:00
|
|
|
<el-input placeholder="" autocomplete="new-password" v-model="editCredential.config.privPin" size="small" id="credential-box-input-privPin" :disabled="!editCredential.config.authProtocol || editCredential.config.authProtocol === ''" type="password" show-password></el-input>
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
2021-04-14 19:17:16 +08:00
|
|
|
</div>
|
|
|
|
|
<!--底部按钮-->
|
2021-05-11 10:37:58 +08:00
|
|
|
<div class="right-box__footer">
|
|
|
|
|
<button v-cancel="{obj:editCredential,func:esc}" id="credential-box-esc" class="footer__btn footer__btn--light">
|
2021-04-14 19:17:16 +08:00
|
|
|
<span>{{$t('overall.cancel')}}</span>
|
|
|
|
|
</button>
|
2021-05-11 10:37:58 +08:00
|
|
|
<button :class="{'nz-btn-disabled':prevent_opt.save}" :disabled="prevent_opt.save" @click="save" class="footer__btn" id="credential-box-save">
|
2021-04-14 19:17:16 +08:00
|
|
|
<span>{{$t('overall.save')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
2021-04-15 11:47:44 +08:00
|
|
|
import { port } from '../js/validate'
|
2021-04-14 19:17:16 +08:00
|
|
|
|
2021-04-15 11:47:44 +08:00
|
|
|
export default {
|
2021-04-14 19:17:16 +08:00
|
|
|
name: 'credentialBox',
|
|
|
|
|
|
|
|
|
|
props: {
|
2021-04-15 11:47:44 +08:00
|
|
|
credential: Object
|
2021-04-14 19:17:16 +08:00
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
editCredential: {},
|
|
|
|
|
|
|
|
|
|
rules: {
|
|
|
|
|
name: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
remark: [
|
2021-04-23 20:06:58 +08:00
|
|
|
// { required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
2021-04-14 19:17:16 +08:00
|
|
|
],
|
2021-04-15 11:47:44 +08:00
|
|
|
type: [
|
2021-04-14 19:17:16 +08:00
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
],
|
2021-04-15 11:47:44 +08:00
|
|
|
port: [
|
2021-04-14 19:17:16 +08:00
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' },
|
|
|
|
|
{ validator: port, trigger: 'blur' }
|
|
|
|
|
]
|
2021-04-15 11:47:44 +08:00
|
|
|
}
|
2021-04-14 19:17:16 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
/* 关闭弹框 */
|
|
|
|
|
esc (refresh) {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
this.$emit('close', refresh)
|
|
|
|
|
},
|
|
|
|
|
clickOutside () {
|
|
|
|
|
this.esc(false)
|
|
|
|
|
},
|
|
|
|
|
|
2021-04-15 11:47:44 +08:00
|
|
|
typeChange: function (type) {
|
|
|
|
|
if (type === 1 || type === 2) {
|
|
|
|
|
this.$set(this.editCredential, 'config', {
|
|
|
|
|
readCommunity: '',
|
|
|
|
|
writeCommunity: ''
|
2021-04-14 19:17:16 +08:00
|
|
|
})
|
2021-04-15 11:47:44 +08:00
|
|
|
} else {
|
|
|
|
|
this.$set(this.editCredential, 'config', {
|
|
|
|
|
username: '',
|
|
|
|
|
contextname: '',
|
|
|
|
|
securityLevel: '',
|
|
|
|
|
authProtocol: '',
|
|
|
|
|
authPin: '',
|
|
|
|
|
privProtocol: '',
|
|
|
|
|
privPin: ''
|
2021-04-14 19:17:16 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/* 保存 */
|
|
|
|
|
save: function () {
|
|
|
|
|
if (this.prevent_opt.save) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.prevent_opt.save = true
|
|
|
|
|
this.$refs.credentialForm.validate((valid) => {
|
|
|
|
|
if (valid) {
|
2021-04-15 11:47:44 +08:00
|
|
|
if (this.editCredential.type === 3) {
|
|
|
|
|
if (this.editCredential.config.authProtocol && !this.editCredential.config.privProtocol) {
|
2021-04-14 19:17:16 +08:00
|
|
|
this.editCredential.securityLevel = 'authNoPriv'
|
2021-04-15 11:47:44 +08:00
|
|
|
} else if (this.editCredential.config.authProtocol && this.editCredential.config.privProtocol) {
|
2021-04-14 19:17:16 +08:00
|
|
|
this.editCredential.securityLevel = 'authPriv'
|
2021-04-15 11:47:44 +08:00
|
|
|
} else {
|
2021-04-14 19:17:16 +08:00
|
|
|
this.editCredential.securityLevel = 'noAuthNoPriv'
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-15 11:47:44 +08:00
|
|
|
const param = JSON.parse(JSON.stringify(this.editCredential))
|
2021-04-14 19:17:16 +08:00
|
|
|
param.config = JSON.stringify(param.config)
|
|
|
|
|
if (this.editCredential.id) {
|
2021-04-15 11:47:44 +08:00
|
|
|
this.$put('/snmp/credential', param).then(response => {
|
2021-04-14 19:17:16 +08:00
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
}
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
})
|
|
|
|
|
} else {
|
2021-04-15 11:47:44 +08:00
|
|
|
this.$post('/snmp/credential', param).then(response => {
|
2021-04-14 19:17:16 +08:00
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
}
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/* 删除 */
|
|
|
|
|
del () {
|
|
|
|
|
if (this.prevent_opt.save) { return } ;
|
|
|
|
|
this.prevent_opt.save = true
|
|
|
|
|
this.$confirm(this.$t('tip.confirmDelete'), {
|
|
|
|
|
confirmButtonText: this.$t('tip.yes'),
|
|
|
|
|
cancelButtonText: this.$t('tip.no'),
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(() => {
|
|
|
|
|
this.$delete('/snmp/credential?ids=' + this.editCredential.id).then(response => {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.deleteSuccess') })
|
|
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
})
|
2021-04-15 11:47:44 +08:00
|
|
|
}
|
2021-04-14 19:17:16 +08:00
|
|
|
},
|
|
|
|
|
mounted () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
credential: {
|
|
|
|
|
immediate: true,
|
|
|
|
|
deep: true,
|
|
|
|
|
handler (n, o) {
|
|
|
|
|
this.editCredential = JSON.parse(JSON.stringify(n))
|
2021-05-13 17:13:01 +08:00
|
|
|
if (this.editCredential.config) {
|
|
|
|
|
this.editCredential.config = JSON.parse(this.editCredential.config)
|
|
|
|
|
}
|
2021-04-14 19:17:16 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<style scoped>
|
|
|
|
|
.right-box-credential .half-form-item {
|
|
|
|
|
width: calc(50% - 20px);
|
|
|
|
|
}
|
|
|
|
|
.right-box-credential .half-form-item:nth-child(odd) {
|
|
|
|
|
width: calc(50% - 15px);
|
|
|
|
|
margin-left: 15px;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
</style>
|