From 8b422de2d0c45cea08ca44d2f2d003c7466b975c Mon Sep 17 00:00:00 2001 From: zhangyu Date: Tue, 19 Apr 2022 18:17:49 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9stat=E7=9A=84?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/chart/panelChart.vue | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/nezha-fronted/src/components/chart/panelChart.vue b/nezha-fronted/src/components/chart/panelChart.vue index 6f4e0bf6f..771142426 100644 --- a/nezha-fronted/src/components/chart/panelChart.vue +++ b/nezha-fronted/src/components/chart/panelChart.vue @@ -310,7 +310,17 @@ export default { end: endTime, resultType: 'matrix' } - this.$get('/stat', params).then(res => { + // this.$get('/stat', params).then(res => { + // if (res.code === 200) { + // chartData.push(res.data.result) + // } else { + // chartData.push({ error: res.msg || res.error || res }) + // this.isError = true + // } + // this.chartData = chartData + // this.loading = false + // }) + this.sendAjax('/stat', params).then(res => { if (res.code === 200) { chartData.push(res.data.result) } else { @@ -463,6 +473,42 @@ export default { this.$message.error(res.msg) } }) + }, + sendAjax (url, params) { + // 构造表单数据 + return new Promise(resolve => { + let nowUrl = url + Object.keys(params).forEach((key, index) => { + if (index == 0) { + nowUrl += '?' + key + '=' + params[key] + } else { + nowUrl += '&' + key + '=' + params[key] + } + }) + const formData = new FormData() + formData.append('username', 'johndoe') + formData.append('id', 123456) + // 创建xhr对象 + const xhr = new XMLHttpRequest() + // 设置xhr请求的超时时间 + xhr.timeout = 3000 + // 设置响应返回的数据格式 + xhr.responseType = '' + // 创建一个 post 请求,采用异步 + xhr.open('get', 'http://192.168.44.100/' + nowUrl, true) + xhr.setRequestHeader('Authorization', localStorage.getItem('nz-token')); + // 注册相关事件回调处理函数 + xhr.onload = function (e) { + if (this.status == 200 || this.status == 304) { + // alert(this.responseText) + console.log(this, this.responseText) + resolve(JSON.parse(this.responseText)) + } + } + xhr.onerror = function(e) { console.log(e) }; + // 发送数据 + xhr.send() + }) } }, watch: {