2 Commits 4d1f239e8f ... 8665978ca4

Author SHA1 Message Date
  wlf 8665978ca4 Merge branch 'dev' of ssh://git.cestong.com.cn:8162/cecf/observe-front into dev 9 months ago
  wlf 34c5e60077 添加多个api 9 months ago
5 changed files with 177 additions and 22 deletions
  1. 1 0
      .env.development
  2. 2 1
      src/api/trace.js
  3. 1 1
      src/utils/request.js
  4. 127 0
      src/utils/requestOther.js
  5. 46 20
      src/views/latency/components/TopoTree.vue

+ 1 - 0
.env.development

@@ -6,4 +6,5 @@ ENV = 'development'
 #  本地:http://192.168.31.230:6301
 # VUE_APP_BASE_API = 'http://192.168.31.230:6301'
 VUE_APP_BASE_API = 'http://observe-server.cestong.com.cn'
+VUE_APP_ANOTHER_BASE_URL = 'http://app.cestong.com.cn'
 

+ 2 - 1
src/api/trace.js

@@ -1,4 +1,5 @@
 import request from '@/utils/request'
+import requestOther from "@/utils/requestOther"
 
 // /api/v1/trace/list  框选后的trace列表
 // {
@@ -61,7 +62,7 @@ export function dbslowtop(query) {
 
 //用于span
 export function networkSpans(data){
-    return request({
+    return requestOther({
       url: '/v1/stats/querier/network-spans',
       method: 'post',
       data: data

+ 1 - 1
src/utils/request.js

@@ -118,4 +118,4 @@ service.interceptors.response.use(
   }
 )
 
-export default service
+export default service

+ 127 - 0
src/utils/requestOther.js

@@ -0,0 +1,127 @@
+import axios from 'axios'
+import { MessageBox, Message } from 'element-ui'
+import store from '@/store'
+import { getToken } from '@/utils/auth'
+
+
+// let url = window.location.host +"/re"
+// create an axios instance
+// const service = axios.create({
+//   baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
+//   // withCredentials: true, // send cookies when cross-domain requests
+//   timeout: 30000 // request timeout
+// })
+
+const serviceAnother = axios.create({
+  baseURL: process.env.VUE_APP_ANOTHER_BASE_URL, // url = base url + request url
+  // withCredentials: true, // send cookies when cross-domain requests
+  timeout: 30000 // request timeout
+})
+
+// request interceptor
+serviceAnother.interceptors.request.use(
+  config => {
+    // do something before request is sent
+
+    if (store.getters.token) {
+      // let each request carry token
+      // ['X-Token'] is a custom headers key
+      // please modify it according to the actual situation
+      config.headers['Authorization'] = 'Bearer ' + getToken()
+      config.headers['Content-Type'] = 'application/json'
+    }
+    return config
+  },
+  error => {
+    // do something with request error
+    console.log(error) // for debug
+    return Promise.reject(error)
+  }
+)
+
+// response interceptor
+serviceAnother.interceptors.response.use(
+  /**
+   * If you want to get http information such as headers or status
+   * Please return  response => response
+  */
+
+  /**
+   * Determine the request status by custom code
+   * Here is just an example
+   * You can also judge the status by HTTP Status Code
+   */
+  response => {
+    const code = response.data.code
+    if (code === 401) {
+      store.dispatch('user/resetToken')
+      if (location.href.indexOf('login') !== -1) {
+        location.reload() // 为了重新实例化vue-router对象 避免bug
+      } else {
+        MessageBox.confirm(
+          '登录状态已过期,您可以继续留在该页面,或者重新登录',
+          '系统提示',
+          {
+            confirmButtonText: '重新登录',
+            cancelButtonText: '取消',
+            type: 'warning'
+          }
+        ).then(() => {
+          location.reload() // 为了重新实例化vue-router对象 避免bug
+        })
+      }
+    } else if (code === 6401) {
+      store.dispatch('user/resetToken')
+      MessageBox.confirm(
+        '登录状态已过期,您可以继续留在该页面,或者重新登录',
+        '系统提示',
+        {
+          confirmButtonText: '重新登录',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }
+      ).then(() => {
+        location.reload() // 为了重新实例化vue-router对象 避免bug
+      })
+      return false
+    } else if (code === 400 || code === 403) {
+      Message({
+        message: response.data.msg,
+        type: 'error',
+        duration: 5 * 1000
+      })
+    } else if (code > 200) {
+      // Notification.error({
+      //   title: response.data.msg
+      // })
+      Message({
+        message: response.data.msg,
+        type: 'error'
+      })
+      return Promise.reject('error')
+    } else {
+      return response.data
+    }
+  },
+  error => {
+    if (error.message === 'Network Error') {
+      Message({
+        message: '服务器连接异常,请检查服务器!',
+        type: 'error',
+        duration: 5 * 1000
+      })
+      return
+    }
+    console.log('err' + error) // for debug
+
+    Message({
+      message: error.message,
+      type: 'error',
+      duration: 5 * 1000
+    })
+
+    return Promise.reject(error)
+  }
+)
+
+export default serviceAnother

+ 46 - 20
src/views/latency/components/TopoTree.vue

@@ -1015,41 +1015,67 @@ export default {
         if(source != ''){
           this.networkQuery.parent_span_id = source;
           this.networkQuery.span_id = target;
+          // networkSpans(this.networkQuery).then(res=>{
+          //   console.log(res,'network-spans网络拓扑')
+
+          //   if(res.OPT_STATUS.length!=0){
+          //     let optList = this.handleData(res.OPT_STATUS);
+          //     let newOptList = this.buildNestedTree(optList);
+
+          //     newFirstNode.children = newOptList;
+
+
+          //     let firstList =[newFirstNode];
+
+          //     let resultList = this.addDataToTree(firstList,newLastNode)
+
+          //     topoData = resultList[0]
+
+
+          //     this.networkOpen = true;
+          //     this.flag = true;
+          //     setTimeout(()=>{
+          //       this.initGraphNetwork(topoData,'networkContainer')
+          //     },300)
+
+
+          //   }else{
+          //     this.$message('暂无数据')
+          //   }
+          // })
           this.$http({
               // url: 'http://df-app.cestong.com.cn/v1/stats/querier/network-spans',
               url:'http://app.cestong.com.cn/v1/stats/querier/network-spans',
               method: 'post',
               data:this.networkQuery
-            }).then(res=>{
-              console.log(res.data.OPT_STATUS,'network-spans网络拓扑')
+          }).then(res=>{
+            console.log(res.data.OPT_STATUS,'network-spans网络拓扑')
 
-              if(res.data.OPT_STATUS.length!=0){
-                let optList = this.handleData(res.data.OPT_STATUS);
-                let newOptList = this.buildNestedTree(optList);
+            if(res.data.OPT_STATUS.length!=0){
+              let optList = this.handleData(res.data.OPT_STATUS);
+              let newOptList = this.buildNestedTree(optList);
 
-                newFirstNode.children = newOptList;
+              newFirstNode.children = newOptList;
 
 
-                let firstList =[newFirstNode];
+              let firstList =[newFirstNode];
 
-                let resultList = this.addDataToTree(firstList,newLastNode)
+              let resultList = this.addDataToTree(firstList,newLastNode)
 
-                topoData = resultList[0]
+              topoData = resultList[0]
 
 
-                // _this.$emit('changeNetwork',this.topoData);
-                this.networkOpen = true;
-                this.flag = true;
-                setTimeout(()=>{
-                  this.initGraphNetwork(topoData,'networkContainer')
-                  // this.initGraph(this.topoData,'networkContainer')
-                },300)
+              this.networkOpen = true;
+              this.flag = true;
+              setTimeout(()=>{
+                this.initGraphNetwork(topoData,'networkContainer')
+              },300)
 
 
-              }else{
-                this.$message('暂无数据')
-              }
-            })
+            }else{
+              this.$message('暂无数据')
+            }
+          })
         }
       });
       // 双击节点进行跳转