CN-747: http请求支持取消
This commit is contained in:
@@ -10,8 +10,9 @@
|
|||||||
<div class="calendar-popover-text" v-else>
|
<div class="calendar-popover-text" v-else>
|
||||||
{{ showDetail }}
|
{{ showDetail }}
|
||||||
</div>
|
</div>
|
||||||
<div class="calendar-popover-text calendar-popover__small"><i class="cn-icon cn-icon-dropdown"
|
<div class="calendar-popover-text calendar-popover__small">
|
||||||
:class="dropdownFlag ? 'cn-icon-up' : ''"></i></div>
|
<i class="cn-icon cn-icon-dropdown" :class="dropdownFlag ? 'cn-icon-up' : ''"></i>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<transition name="el-zoom-in-top">
|
<transition name="el-zoom-in-top">
|
||||||
<div v-if="dropdownFlag" class="date-range-panel">
|
<div v-if="dropdownFlag" class="date-range-panel">
|
||||||
@@ -82,6 +83,7 @@ import { ref, computed } from 'vue'
|
|||||||
import MyDatePicker from '../MyDatePicker'
|
import MyDatePicker from '../MyDatePicker'
|
||||||
import { storageKey } from '@/utils/constants'
|
import { storageKey } from '@/utils/constants'
|
||||||
import { getMillisecond } from '@/utils/date-util'
|
import { getMillisecond } from '@/utils/date-util'
|
||||||
|
import { useStore } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'DateTimeRange',
|
name: 'DateTimeRange',
|
||||||
@@ -112,6 +114,7 @@ export default {
|
|||||||
},
|
},
|
||||||
setup (props, ctx) {
|
setup (props, ctx) {
|
||||||
// data
|
// data
|
||||||
|
const store = useStore()
|
||||||
const myStartTime = ref(props.startTime)
|
const myStartTime = ref(props.startTime)
|
||||||
const myEndTime = ref(props.endTime)
|
const myEndTime = ref(props.endTime)
|
||||||
const timeArr = ref([myStartTime.value, myEndTime.value])
|
const timeArr = ref([myStartTime.value, myEndTime.value])
|
||||||
@@ -233,6 +236,7 @@ export default {
|
|||||||
returnValue()
|
returnValue()
|
||||||
}
|
}
|
||||||
const returnValue = () => {
|
const returnValue = () => {
|
||||||
|
cancelHttp()
|
||||||
rangeHistory.value.unshift({
|
rangeHistory.value.unshift({
|
||||||
start: myStartTime.value,
|
start: myStartTime.value,
|
||||||
end: myEndTime.value
|
end: myEndTime.value
|
||||||
@@ -241,6 +245,16 @@ export default {
|
|||||||
ctx.emit('change', myStartTime.value, myEndTime.value, dateRangeValue)
|
ctx.emit('change', myStartTime.value, myEndTime.value, dateRangeValue)
|
||||||
dropdownFlag.value = false
|
dropdownFlag.value = false
|
||||||
}
|
}
|
||||||
|
const cancelHttp = () => {
|
||||||
|
const cancelList = store.state.panel.httpCancel
|
||||||
|
// console.log('DateTimeRange.vue------cancelHttp------查看终止数量', cancelList, cancelList.length)
|
||||||
|
if (cancelList.length > 0) {
|
||||||
|
cancelList.forEach((cancel, index) => {
|
||||||
|
cancel()
|
||||||
|
delete cancelList[index]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
myStartTime,
|
myStartTime,
|
||||||
myEndTime,
|
myEndTime,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<div v-if="dropdownShow" class="refresh-list">
|
<div v-if="dropdownShow" class="refresh-list">
|
||||||
<div v-for="(item, index) in refreshArr" :key="index" @click="setRefresh(item)" class="refresh-list-item" :class="item.value==interval ? 'active' : ''">
|
<div v-for="(item, index) in refreshArr" :key="index" @click="setRefresh(item)" class="refresh-list-item" :class="item.value==interval ? 'active' : ''">
|
||||||
{{ item.label }}
|
{{ item.label }}
|
||||||
<i v-if="item.value==interval" class="cn-icon cn-icon-check"></i>
|
<i v-if="item.value===interval" class="cn-icon cn-icon-check"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
@@ -103,7 +103,16 @@ export default {
|
|||||||
this.interLabel = val.value == -1 ? '' : val.label
|
this.interLabel = val.value == -1 ? '' : val.label
|
||||||
this.dropdownShow = false
|
this.dropdownShow = false
|
||||||
const now = window.$dayJs.tz().valueOf()
|
const now = window.$dayJs.tz().valueOf()
|
||||||
if (val && val.value != -1) {
|
if (val && val.value !== -1) {
|
||||||
|
// 切换轮询请求时间频率时,发现有未结束的请求,终止请求
|
||||||
|
const cancelList = this.$store.state.panel.httpCancel
|
||||||
|
// console.log('timeRefresh.vue------setRefresh------查看终止数量', cancelList, cancelList.length)
|
||||||
|
if (cancelList.length > 0) {
|
||||||
|
cancelList.forEach((cancel, index) => {
|
||||||
|
cancel()
|
||||||
|
delete cancelList[index]
|
||||||
|
})
|
||||||
|
}
|
||||||
// 向地址栏添加自动刷新频率
|
// 向地址栏添加自动刷新频率
|
||||||
const dateParam = {
|
const dateParam = {
|
||||||
refreshTime: val.value
|
refreshTime: val.value
|
||||||
@@ -121,7 +130,7 @@ export default {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (val && val.value == -1) {
|
if (val && val.value === -1) {
|
||||||
// 清除定时器
|
// 清除定时器
|
||||||
clearInterval(this.intervalTimer)
|
clearInterval(this.intervalTimer)
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ const panel = {
|
|||||||
npmLocationCountry: '', // npm location的查询条件--国家
|
npmLocationCountry: '', // npm location的查询条件--国家
|
||||||
npmLocationSide: 'server', // npm location的查询条件--方向
|
npmLocationSide: 'server', // npm location的查询条件--方向
|
||||||
refreshTime: null, // 自动刷新时间的秒数
|
refreshTime: null, // 自动刷新时间的秒数
|
||||||
refreshFlag: true // 关闭自动刷新标志,true为off,false即开启自动刷新
|
refreshFlag: true, // 关闭自动刷新标志,true为off,false即开启自动刷新
|
||||||
|
httpCancel: null // 终止http请求
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setShowRightBox (state, flag) {
|
setShowRightBox (state, flag) {
|
||||||
@@ -146,6 +147,9 @@ const panel = {
|
|||||||
},
|
},
|
||||||
setRefreshFlag (state, flag) {
|
setRefreshFlag (state, flag) {
|
||||||
state.refreshFlag = flag
|
state.refreshFlag = flag
|
||||||
|
},
|
||||||
|
setHttpCancel (state, cancel) {
|
||||||
|
state.httpCancel = cancel
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
|
|||||||
@@ -1,8 +1,20 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { storageKey } from '@/utils/constants'
|
import { storageKey } from '@/utils/constants'
|
||||||
|
import store from '@/store'
|
||||||
|
|
||||||
|
const CancelToken = axios.CancelToken
|
||||||
|
|
||||||
axios.interceptors.request.use(config => {
|
axios.interceptors.request.use(config => {
|
||||||
const token = localStorage.getItem(storageKey.token)
|
const token = localStorage.getItem(storageKey.token)
|
||||||
|
|
||||||
|
// 添加http请求终止方法
|
||||||
|
const arr = []
|
||||||
|
const cancelToken = new CancelToken(function executor (c) {
|
||||||
|
arr.push(c)
|
||||||
|
store.commit('setHttpCancel', arr)
|
||||||
|
})
|
||||||
|
|
||||||
|
config.cancelToken = cancelToken
|
||||||
if (token) {
|
if (token) {
|
||||||
config.headers['Cn-Authorization'] = token // 请求头token
|
config.headers['Cn-Authorization'] = token // 请求头token
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ import { getTypeCategory } from '@/views/charts/charts/tools'
|
|||||||
import { computeScore, urlParamsHandler, overwriteUrl } from '@/utils/tools'
|
import { computeScore, urlParamsHandler, overwriteUrl } from '@/utils/tools'
|
||||||
import ChartList from '@/views/charts2/ChartList'
|
import ChartList from '@/views/charts2/ChartList'
|
||||||
import { get } from '@/utils/http'
|
import { get } from '@/utils/http'
|
||||||
|
import { useStore } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Panel',
|
name: 'Panel',
|
||||||
@@ -156,6 +157,19 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
setup (props, ctx) {
|
setup (props, ctx) {
|
||||||
|
// todo 目前在panel页面测试,后续会挪到router里
|
||||||
|
const store = useStore()
|
||||||
|
const cancelList = store.state.panel.httpCancel
|
||||||
|
|
||||||
|
// 进入页面时,发现有未结束的请求,终止请求
|
||||||
|
// console.log('panel.vue------setup------查看http终止情况', cancelList, cancelList.length)
|
||||||
|
if (cancelList.length > 0) {
|
||||||
|
cancelList.forEach((cancel, index) => {
|
||||||
|
cancel()
|
||||||
|
delete cancelList[index]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const panel = ref({})
|
const panel = ref({})
|
||||||
let panelType = 1 // 取得panel的type
|
let panelType = 1 // 取得panel的type
|
||||||
const { params, query } = useRoute()
|
const { params, query } = useRoute()
|
||||||
|
|||||||
@@ -223,7 +223,6 @@ export default {
|
|||||||
})
|
})
|
||||||
this.linkData = sorted
|
this.linkData = sorted
|
||||||
|
|
||||||
// todo 此处去重不优美,后续再处理
|
|
||||||
let directionArr = []
|
let directionArr = []
|
||||||
nextHopData.forEach((item) => {
|
nextHopData.forEach((item) => {
|
||||||
if (item.egressLinkDirection !== '' && item.ingressLinkDirection !== '') {
|
if (item.egressLinkDirection !== '' && item.ingressLinkDirection !== '') {
|
||||||
|
|||||||
Reference in New Issue
Block a user