fix:加载后台报错处理

This commit is contained in:
wangwenrui
2020-05-28 18:13:11 +08:00
parent 47c23b89c9
commit 2b8c406551
2 changed files with 36 additions and 29 deletions

View File

@@ -15,7 +15,7 @@ export default {
/*this.$http.get("config.json").then((result)=>{ /*this.$http.get("config.json").then((result)=>{
this.$axios.defaults.baseURL = result.body.baseUrl; this.$axios.defaults.baseURL = result.body.baseUrl;
});*/ });*/
this.$axios.defaults.baseURL = 'http://192.168.40.42:8080/nz-admin'; this.$axios.defaults.baseURL = 'http://192.168.40.41:8080/nz-admin';
} }
} }
</script> </script>

View File

@@ -571,7 +571,9 @@ export default {
}else{ }else{
step='30m'; step='30m';
} }
this.$refs.messageChart.startLoading(); if(this.$refs.messageChart){
this.$refs.messageChart.startLoading();
}
let axiosArr=[]; let axiosArr=[];
let paramStr = JSON.stringify(this.promQueryParamConvert(this.currentMsg)); let paramStr = JSON.stringify(this.promQueryParamConvert(this.currentMsg));
axiosArr.push(axios.get("/prom/api/v1/query_range?query="+paramStr.substring(1, paramStr.length-1).replace(/\+/g, "%2B").replace(/ /g, "%20").replace(/\\/g, "")+"&start="+this.$stringTimeParseToUnix(start)+"&end="+this.$stringTimeParseToUnix(end)+"&step="+step)); axiosArr.push(axios.get("/prom/api/v1/query_range?query="+paramStr.substring(1, paramStr.length-1).replace(/\+/g, "%2B").replace(/ /g, "%20").replace(/\\/g, "")+"&start="+this.$stringTimeParseToUnix(start)+"&end="+this.$stringTimeParseToUnix(end)+"&step="+step));
@@ -667,19 +669,21 @@ export default {
this.storedTableData.forEach((item) => { this.storedTableData.forEach((item) => {
item.labels = JSON.parse(item.labels); item.labels = JSON.parse(item.labels);
let paramStr = JSON.stringify(this.promQueryParamConvert(item)); let paramStr = JSON.stringify(this.promQueryParamConvert(item));
this.$get('/prom/api/v1/query?query=' + paramStr.substring(1, paramStr.length-1).replace(/\+/g, "%2B").replace(/ /g, "%20").replace(/\\/g, "")).then(response2 => { if(paramStr&& paramStr !=''){
let current = []; this.$get('/prom/api/v1/query?query=' + paramStr.substring(1, paramStr.length-1).replace(/\+/g, "%2B").replace(/ /g, "%20").replace(/\\/g, "")).then(response2 => {
if (response2.data && response2.data.result && response2.data.result.length > 0) { let current = [];
current = response2.data.result[0].value.map((item, i) => { if (response2.data && response2.data.result && response2.data.result.length > 0) {
if (i == 0) { current = response2.data.result[0].value.map((item, i) => {
return bus.computeTimezone(item); if (i == 0) {
} else { return bus.computeTimezone(item);
return parseFloat(item).toFixed(2); } else {
} return parseFloat(item).toFixed(2);
}); }
} });
this.$set(item, "current", current); }
}); this.$set(item, "current", current);
});
}
}); });
this.pageObj.total = response.data.total; this.pageObj.total = response.data.total;
this.isError = false; this.isError = false;
@@ -695,21 +699,24 @@ export default {
}); });
}, },
promQueryParamConvert(obj) { promQueryParamConvert(obj) {
return "(" + obj.alertRule.expr + ") and (" + function(){ if(obj){
let q = "{"; return "(" + obj.alertRule.expr + ") and (" + function(){
for (let k in obj.labels) { let q = "{";
if (k != 'alertname' && k != 'severity') { for (let k in obj.labels) {
q += k; if (k != 'alertname' && k != 'severity') {
q += "="; q += k;
q += ("'" + obj.labels[k] + "',"); q += "=";
q += ("'" + obj.labels[k] + "',");
}
};
if (q.length > 1) {
q = q.substring(0, q.length-1);
} }
}; q += "}";
if (q.length > 1) { return q;
q = q.substring(0, q.length-1); }() + ")";
} }
q += "}"; return '';
return q;
}() + ")";
}, },
elementsetShow(s, e) { elementsetShow(s, e) {
var eventfixed = { var eventfixed = {