Skip to content

Commit 10c9d3e

Browse files
committed
fix: uptime frontend
1 parent 7506159 commit 10c9d3e

File tree

6 files changed

+47
-22
lines changed

6 files changed

+47
-22
lines changed

frontend/src/api/uptime.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,40 @@ interface UptimeLinksResp {
1313
links: number
1414
}
1515

16-
export async function getUptimeRecent(asn: number) {
17-
const res = await axios.get(`${ApiHost}/api/bgp/uptime/${asn}/recent`)
16+
export async function getUptimeRecent(grName: string, asn: number) {
17+
const res = await axios.get(
18+
`${ApiHost}/api/bgp/${grName}/uptime/${asn}/recent`,
19+
)
1820
const data = res.data as Resp<UptimeRecent>
1921
if (data.code !== 0) {
2022
throw new Error(data.msg)
2123
}
2224
return data.data
2325
}
2426

25-
export async function getUptimeLinks(asn: number,time: string,window: string) {
26-
const res = await axios.get(`${ApiHost}/api/bgp/uptime/${asn}/links`,{
27-
params: {
28-
time,
29-
window
30-
}
31-
})
27+
export async function getUptimeLinks(
28+
grName: string,
29+
asn: number,
30+
time: string,
31+
window: string,
32+
) {
33+
const res = await axios.get(
34+
`${ApiHost}/api/bgp/${grName}/uptime/${asn}/links`,
35+
{
36+
params: {
37+
time,
38+
window,
39+
},
40+
},
41+
)
3242
const data = res.data as Resp<Array<UptimeLinksResp>>
3343
if (data.code !== 0) {
3444
throw new Error(data.msg)
3545
}
3646
return data.data.map((item) => {
3747
return {
3848
time: new Date(item.time),
39-
links: item.links
49+
links: item.links,
4050
}
4151
})
42-
}
52+
}

frontend/src/components/BGP.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,12 @@ onBeforeRouteLeave(() => {
457457

458458
<template>
459459
<Transition name="fade" appear>
460-
<BGPUptime class="uptime" v-if="uptime_asn !== 0" :asn="uptime_asn" />
460+
<BGPUptime
461+
class="uptime"
462+
v-if="uptime_asn !== 0"
463+
:asn="uptime_asn"
464+
:grName="name"
465+
/>
461466
</Transition>
462467
</template>
463468

frontend/src/components/uptime/BGPLatestStatus.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import { ref, onUnmounted } from 'vue'
33
import { getUptimeRecent } from '@/api/uptime'
44
5-
const { asn } = defineProps<{
5+
const { grName, asn } = defineProps<{
6+
grName: string
67
asn: number
78
}>()
89
@@ -20,7 +21,7 @@ const uptime10 = ref([
2021
])
2122
2223
const update = async () => {
23-
const uptimes = await getUptimeRecent(asn)
24+
const uptimes = await getUptimeRecent(grName, asn)
2425
uptime10.value = uptimes.slice(0, 10)
2526
}
2627
update()

frontend/src/components/uptime/BGPUptime.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script setup lang="ts">
2-
import { useASMeta } from '@/state/meta';
2+
import { useASMeta } from '@/state/meta'
33
import { ref } from 'vue'
44
5-
const { asn } = defineProps<{
5+
const { grName, asn } = defineProps<{
6+
grName: string
67
asn: number
78
}>()
89
9-
const ASMeta = useASMeta();
10+
const ASMeta = useASMeta()
1011
1112
const graph_mode = ref('24h')
1213
</script>
@@ -21,15 +22,20 @@ const graph_mode = ref('24h')
2122
: `AS ${asn}`
2223
}}
2324
</div>
24-
<BGPLatestStatus class="status-bar" :asn="asn" />
25+
<BGPLatestStatus :grName="grName" class="status-bar" :asn="asn" />
2526
</div>
2627
<div class="uptime-body">
2728
<div class="wrap-graph">
2829
<el-select class="graph-selecter" v-model="graph_mode" placeholder="">
2930
<el-option value="24h" label="1 day" />
3031
<el-option value="168h" label="7 days" />
3132
</el-select>
32-
<LinksHistory class="links-graph" :asn="asn" :time="graph_mode" />
33+
<LinksHistory
34+
class="links-graph"
35+
:grName="grName"
36+
:asn="asn"
37+
:time="graph_mode"
38+
/>
3339
</div>
3440
</div>
3541
</div>

frontend/src/components/uptime/LatestStatus.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const props = defineProps<{
1010
<template>
1111
<div class="squares">
1212
<div
13-
v-for="d in props.data"
13+
v-for="(d, index) in props.data"
14+
:key="index"
1415
class="square"
1516
:style="{
1617
backgroundColor: d ? upColor : downColor,

frontend/src/components/uptime/LinksHistory.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- eslint-disable @typescript-eslint/no-explicit-any -->
12
<script setup lang="ts">
23
import { getUptimeLinks, UptimeLinks } from '@/api/uptime'
34
import { ref, reactive, onUnmounted, computed, watch } from 'vue'
@@ -13,7 +14,8 @@ import { use } from 'echarts/core'
1314
import { parseDuration } from '@/utils/time'
1415
import { useDark } from '@vueuse/core'
1516
import { fontColor } from '@/state/font'
16-
const { asn, time } = defineProps<{
17+
const { grName, asn, time } = defineProps<{
18+
grName: string
1719
asn: number
1820
time: string
1921
}>()
@@ -103,7 +105,7 @@ const option: any = reactive({
103105
})
104106
105107
const refreshData = async () => {
106-
data.value = await getUptimeLinks(asn, time, window.value)
108+
data.value = await getUptimeLinks(grName, asn, time, window.value)
107109
option.series[0].data = data.value.map((d) => d.links)
108110
option.xAxis.data = data.value.map(
109111
(d) =>

0 commit comments

Comments
 (0)