Merge branch 'codeCheck' of https://git.mesalab.cn/nezha/nezha-fronted into codeCheck

This commit is contained in:
zhangyu
2020-07-27 18:27:13 +08:00
5 changed files with 97 additions and 103 deletions

View File

@@ -203,7 +203,7 @@
assetId: '' assetId: ''
}, },
alertRule: { alertRule: {
id: '', id: null,
alertName: '', alertName: '',
type: '', type: '',
linkObject: {id: '', name: ''}, linkObject: {id: '', name: ''},

View File

@@ -1,8 +1,8 @@
<template> <template>
<div class="right-box right-box-alert-config" v-clickoutside="clickOutside"> <div class="right-box right-box-alert-config" v-clickoutside="clickOutside" v-if="rightBox.show">
<!-- begin--顶部按钮--> <!-- begin--顶部按钮-->
<div class="right-box-top-btns"> <div class="right-box-top-btns">
<button type="button" v-if="alertRule.id" id="alert-box-del" @click="del" class="nz-btn nz-btn-size-normal nz-btn-size-alien nz-btn-style-light"> <button type="button" v-if="editAlertRule&&editAlertRule.id" id="alert-box-del" @click="del" class="nz-btn nz-btn-size-normal nz-btn-size-alien nz-btn-style-light">
<span class="right-box-top-btn-icon"><i class="el-icon-delete"></i></span> <span class="right-box-top-btn-icon"><i class="el-icon-delete"></i></span>
<span class="right-box-top-btn-txt">{{$t('overall.delete')}}</span> <span class="right-box-top-btn-txt">{{$t('overall.delete')}}</span>
</button> </button>
@@ -121,6 +121,9 @@
}, },
data() { data() {
return { return {
rightBox:{
show:false
},
promqlCount: 1, promqlCount: 1,
promqlKeys: [0], promqlKeys: [0],
expressions: [''], expressions: [''],
@@ -214,11 +217,16 @@
} }
}, },
methods: { methods: {
show:function(){
this.rightBox.show=true;
},
clickOutside() { clickOutside() {
this.esc(false); this.esc(false);
this.rightBox.show=false;
}, },
esc(refresh) { esc(refresh) {
this.$emit("close", refresh); this.$emit("close", refresh);
this.rightBox.show=false;
}, },
save() { save() {
this.editAlertRule.expr = this.expressions[0]; this.editAlertRule.expr = this.expressions[0];
@@ -279,11 +287,10 @@
watch: { watch: {
alertRule: { alertRule: {
deep: true, deep: true,
immediate: true,
handler(n, o) { handler(n, o) {
console.info(n) console.info(n)
this.editAlertRule = JSON.parse(JSON.stringify(n)); this.editAlertRule = JSON.parse(JSON.stringify(n));
if (this.editAlertRule.id) { if (this.editAlertRule&&this.editAlertRule.id) {
this.expressions = [this.editAlertRule.expr]; this.expressions = [this.editAlertRule.expr];
this.$nextTick(() => { this.$nextTick(() => {
this.expressions.forEach((ex, index) => { this.expressions.forEach((ex, index) => {

View File

@@ -103,7 +103,7 @@
</div> </div>
</left-menu> </left-menu>
<transition name="right-box"> <transition name="right-box">
<alert-config-box v-if="rightBox.show" :alert-rule="alertRule" @close="closeRightBox" ref="alertConfigBox"></alert-config-box> <alert-config-box :alert-rule="alertRule" @close="closeRightBox" ref="alertConfigBox"></alert-config-box>
</transition> </transition>
<element-set <element-set
v-if="tools.showElementSet" v-if="tools.showElementSet"
@@ -124,10 +124,6 @@
name: "alert-config", name: "alert-config",
data() { data() {
return { return {
//侧滑
rightBox: {
show: false,
},
/*二级页面相关*/ /*二级页面相关*/
bottomBox: { bottomBox: {
ruleDetail: {}, ruleDetail: {},
@@ -333,10 +329,9 @@
}, },
edit(u) { edit(u) {
this.alertRule = JSON.parse(JSON.stringify(u)); this.alertRule = JSON.parse(JSON.stringify(u));
this.rightBox.show = true; this.$refs.alertConfigBox.show();
}, },
closeRightBox(refresh) { closeRightBox(refresh) {
this.rightBox.show = false;
if (refresh) { if (refresh) {
this.getTableData(); this.getTableData();
} }
@@ -367,7 +362,7 @@
}, },
add() { add() {
this.alertRule = this.newAlertRule(); this.alertRule = this.newAlertRule();
this.rightBox.show = true; this.$refs.alertConfigBox.show();
}, },
newAlertRule() { newAlertRule() {
return JSON.parse(JSON.stringify(this.blankAlertRule)); return JSON.parse(JSON.stringify(this.blankAlertRule));

View File

@@ -54,14 +54,11 @@
</el-collapse-item> </el-collapse-item>
<el-collapse-item name="ping" :title="$t('asset.left.ping')"> <el-collapse-item name="ping" :title="$t('asset.left.ping')">
<el-checkbox-group v-model="pingCheckList" size="small" @change="changePingCheckBox"> <el-checkbox-group v-model="pingCheckList" size="small" @change="changePingCheckBox">
<el-checkbox class="sidebar-info-item" :class="{'sidebar-info-item-active': indOf(pingCheckList, item.key)}" v-for="(item, index) in pingData" :key="index" :label="item.value"> <el-checkbox class="sidebar-info-item" :class="{'sidebar-info-item-active': indOf(pingCheckList, item.key)}" v-for="(item, index) in pingData" :key="index" :label="item.label">
<div class="sidebar-info-item-txt"> <div class="sidebar-info-item-txt">
<el-popover v-if="item.value.length > 16" trigger="hover" placement="top-start" :content="item.value" > <span>{{item.label}}</span>
<span slot="reference">{{item.value}}</span>
</el-popover>
<span v-else>{{item.value}}</span>
</div> </div>
<el-tooltip :content="''+item.total" placement="top" effect="light" :disabled="item.total<99"> <el-tooltip :content="''+item.total" placement="top" effect="light" :disabled="item.total < 99">
<el-badge class="mark" :value="item.total" :max="99"/> <el-badge class="mark" :value="item.total" :max="99"/>
</el-tooltip> </el-tooltip>
</el-checkbox> </el-checkbox>
@@ -428,7 +425,7 @@
assetTypeCheckList: [], assetTypeCheckList: [],
vendorData: [], vendorData: [],
vendorCheckList: [], vendorCheckList: [],
pingData: this.$CONSTANTS.asset.pingData, pingData: [],
pingCheckList: [], pingCheckList: [],
pageObj: { pageObj: {
@@ -661,41 +658,6 @@
}) })
}); });
}, },
addNewData(type) {
if (type === 'IDC') {
this.$post('idc', this.addIdcData).then(res => {
if (res.code === 200) {
const h = this.$createElement;
this.$message({duration: 2000, type: 'success', message: this.$t("tip.saveSuccess")});
this.getDcData()
this.getTableData()
/*this.getLeftMenuList()
this.getAssetData()*/
} else {
this.$message.error(res.msg);
}
})
}
},
deleteData(data, item) {
this.$confirm(this.$t("tip.assetConfirmDelete"), {
confirmButtonText: this.$t("tip.yes"),
cancelButtonText: this.$t("tip.no"),
type: 'warning'
}).then(() => {
this.$delete(data + "?ids=" + item).then(response => {
if (response.code === 200) {
this.$message({duration: 2000, type: 'success', message: this.$t("tip.deleteSuccess")});
this.getTableData();
this.getDcData();
/*this.getAssetData();
this.getLeftMenuList();*/
} else {
this.$message.error(response.msg);
}
})
});
},
markOptionData(data) { markOptionData(data) {
data.forEach(item => { data.forEach(item => {
this.$set(item, 'isEdit', false); this.$set(item, 'isEdit', false);
@@ -705,26 +667,6 @@
this.$set(item, item.id + item.name, false) this.$set(item, item.id + item.name, false)
}) })
}, },
editOptionData(item) {
if (!item.isEdit) {
item.isEdit = true;
} else {
if (item.name !== item.oldName) {
item.isEdit = false;
} else {
item.isEdit = false;
}
}
},
delOptionData(data) {
},
tabControl(data) {
if (data === 'close') {
this.editUnitShow = false;
this.$refs['assetEditUnit'].tabView = false;
this.rightBox.show = false;
}
},
indOf(a, b) { indOf(a, b) {
let c = []; let c = [];
for (let i = 0; i < a.length; i++) { for (let i = 0; i < a.length; i++) {
@@ -920,38 +862,37 @@
/*} /*}
this.getAssetData();*/ this.getAssetData();*/
}, },
/*// 获取左侧菜单数据 // 获取左侧菜单数据
getLeftMenuList(){ getLeftMenuList(){
this.$get('asset/filter').then(response => { return new Promise(resolve => {
if (response.code === 200) { this.$get('asset/filter').then(response => {
//dc if (response.code === 200) {
this.checkListData = this.IDCOptionData = response.data.dc; //dc
this.markOptionData(this.IDCOptionData); this.dcData = response.data.dc;
// AssetType // AssetType
this.assetTypeCheckListData = response.data.assetType; this.assetTypeData = response.data.assetType;
// vendor // vendor
this.vendorCheckListData = response.data.vendor; this.vendorData = response.data.vendor;
// ping // ping
this.pingCheckListData= response.data.ping.map(item=>{ this.pingData = response.data.ping.map(item => {
item.label=item.name; item.label = item.name;
item.value=item.status; item.value = item.status;
return item return item;
}) });
} }
}) resolve();
},*/ });
}, });
created() { },
this.getUserData();
this.flushData();
this.getPingData();
}, },
mounted() { mounted() {
//初始化数据 //初始化数据
Promise.all([this.getVendorData(), this.getAssetTypeData(), this.getUserData(), this.getDcData()]).then(response => { /*Promise.all([this.getVendorData(), this.getAssetTypeData(), this.getUserData(), this.getDcData()]).then(response => {
this.getTableData();
});*/
this.getLeftMenuList().then(() => {
this.getTableData(); this.getTableData();
}); });
// this.getLeftMenuList()//获取左侧菜单列表
//是否存在分页缓存 //是否存在分页缓存
let pageSize = localStorage.getItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId); let pageSize = localStorage.getItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId);
if (pageSize != 'undefined' && pageSize != null) { if (pageSize != 'undefined' && pageSize != null) {

View File

@@ -18,6 +18,7 @@
size="mini" size="mini"
value-key="host" value-key="host"
style="width: 100%;" style="width: 100%;"
@input="assetChange"
> >
<template slot-scope="{ item }"> <template slot-scope="{ item }">
<div>{{ item.host }}</div> <div>{{ item.host }}</div>
@@ -83,7 +84,7 @@
<div class="mib-browser-ad-search-label">{{$t('login.password')}}</div> <div class="mib-browser-ad-search-label">{{$t('login.password')}}</div>
</el-col> </el-col>
<el-col :span="17"> <el-col :span="17">
<el-input class="input-x-mini-24" v-model.trim="searchParamPop.auth.password"></el-input> <el-input type="password" class="input-x-mini-24" v-model.trim="searchParamPop.auth.password"></el-input>
</el-col> </el-col>
</el-row> </el-row>
@@ -116,7 +117,7 @@
<div class="mib-browser-ad-search-label">{{$t('project.module.privPassword')}}</div> <div class="mib-browser-ad-search-label">{{$t('project.module.privPassword')}}</div>
</el-col> </el-col>
<el-col :span="17"> <el-col :span="17">
<el-input class="input-x-mini-24" v-model.trim="searchParamPop.auth.privPassword"></el-input> <el-input type="password" class="input-x-mini-24" v-model.trim="searchParamPop.auth.privPassword"></el-input>
</el-col> </el-col>
</el-row> </el-row>
</template> </template>
@@ -316,6 +317,7 @@
assetData: [], assetData: [],
typeData: ["OctetString", "Integer", "OID", "Gauge", "Counter32", "IpAddress", "TimeTicks", "Counter64", "UnsignedInteger", "BITS", "Float", "DateAndTime"], typeData: ["OctetString", "Integer", "OID", "Gauge", "Counter32", "IpAddress", "TimeTicks", "Counter64", "UnsignedInteger", "BITS", "Float", "DateAndTime"],
assetInputTimer:null,
} }
}, },
computed: { computed: {
@@ -450,6 +452,55 @@
clearResult() { clearResult() {
this.resultData = []; this.resultData = [];
}, },
resetSearchParam:function(){
this.searchParamPop={
host: '',
port: 161,
oid: '',
operation: 'get',
version: 2,
community: 'public',
auth: {
username: '',
password: '',
securityLevel: '',
authProtocol: '',
privProtocol: '',
privPassword: ''
}
}
},
assetChange:function(value){
clearTimeout(this.assetInputTimer)
this.assetInputTimer=setTimeout(()=>{
this.resetSearchParam();
let asset=this.assetData.find(item=>{
return item.host == value
})
if(asset&&asset.accounts&&asset.accounts.length>0){
let snmpAccount=asset.accounts.find(item=>{
return item.protocol == 'SNMP'
})
if(snmpAccount){
console.log(snmpAccount)
this.searchParamPop.port=snmpAccount.port;
this.searchParamPop.community=snmpAccount.params.community;
this.searchParamPop.version=snmpAccount.params.version;
if(this.searchParamPop.version == 3){
this.searchParamPop.auth.username=snmpAccount.params.user;
this.searchParamPop.auth.securityLevel=snmpAccount.params.securityLevel;
this.searchParamPop.auth.password=snmpAccount.params.password;
this.searchParamPop.auth.authProtocol=snmpAccount.params.authProtocol;
if(this.searchParamPop.auth.securityLevel=='authPriv')
this.searchParamPop.auth.privProtocol=snmpAccount.params.privProtocol;
this.searchParamPop.auth.privPassword=snmpAccount.params.privPassword;
}
}
}
},200)
},
assetSuggestion(queryString, callback) { assetSuggestion(queryString, callback) {
let data = []; let data = [];
if (!queryString) { if (!queryString) {