Skip to content

Commit

Permalink
kubeconfig change
Browse files Browse the repository at this point in the history
  • Loading branch information
weibaohui committed Nov 21, 2023
1 parent f423e3d commit 4cfa565
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
22 changes: 19 additions & 3 deletions src/frontend/Header.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script setup lang="ts">
import { TimerUtils } from '@backend/utils/TimerUtils'
import { K8sService } from '@frontend/service/k8s/K8sService'
import {
StackExchange,
} from '@vicons/fa'
import type { Component } from 'vue'
import { h, ref } from 'vue'
import { h, onBeforeUnmount, onMounted, ref } from 'vue'
import { RouterLink } from 'vue-router'
import {
Expand All @@ -12,7 +14,7 @@ import {
} from 'naive-ui'
import type { MenuOption } from 'naive-ui'
const containerRef = ref<HTMLElement>()
const currentContext = ref<string>()
const headerMenuOptions: MenuOption[] = [
{
label: () =>
Expand All @@ -33,6 +35,20 @@ const headerMenuOptions: MenuOption[] = [
function renderIcon(icon: Component) {
return () => h(NIcon, null, { default: () => h(icon) })
}
async function getCurrentContext() {
currentContext.value = await K8sService.playService.clientControllerCurrentContext()
}
let intervalId: number
onBeforeUnmount(() => {
clearInterval(intervalId)
})
onMounted(() => {
getCurrentContext()
intervalId = TimerUtils.everyTwoSeconds(() => {
getCurrentContext()
})
})
</script>

<template>
Expand All @@ -48,7 +64,7 @@ function renderIcon(icon: Component) {
<NMenu
mode="horizontal" :options="headerMenuOptions"
/>
<NButton>Oops!</NButton>
<NButton>{{ currentContext }}</NButton>
</NSpace>
</div>
</NCol>
Expand Down
13 changes: 9 additions & 4 deletions src/frontend/components/KubeConfig/KubeConfigView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import type { Cluster } from '@backend/model/KubeConfig'
import { K8sService } from '@frontend/service/k8s/K8sService'
import { Star } from '@vicons/fa'
import { NCard, NIcon, NIconWrapper, NSpace } from 'naive-ui'
import { ref } from 'vue'
import { NButton, NCard, NIcon, NIconWrapper, NSpace } from 'naive-ui'
import { onMounted, ref } from 'vue'
const props = defineProps({

Check warning on line 8 in src/frontend/components/KubeConfig/KubeConfigView.vue

View workflow job for this annotation

GitHub Actions / lint

'props' is assigned a value but never used. Allowed unused vars must match /^_/u
x: String,
Expand All @@ -15,11 +15,13 @@ async function getConfigs() {
currentContext.value = await K8sService.playService.clientControllerCurrentContext()
}
function handleCheckedChange(name: string) {
console.log(name)
K8sService.playService.clientControllerSetContext({ name })
getConfigs()
}
getConfigs()
onMounted(() => {
getConfigs()
})
</script>

<template>
Expand All @@ -31,6 +33,9 @@ getConfigs()
<NIcon :component="Star" />
</NIconWrapper>
{{ c.server }}
<NButton @click="handleCheckedChange(c.name)">
切换
</NButton>
</NCard>
</div>
</NSpace>
Expand Down

0 comments on commit 4cfa565

Please sign in to comment.