diff --git a/webui/src/api/program.ts b/webui/src/api/program.ts index 9bd7542b..52c2650a 100644 --- a/webui/src/api/program.ts +++ b/webui/src/api/program.ts @@ -31,10 +31,11 @@ export const apiProgram = { * 状态 */ async status() { - const { data } = await axios.get<{ status: 'running' | 'stop' }>( + const { data } = await axios.get<{ status: boolean; version: string }>( 'api/v1/status' ); - return data.status === 'running'; + + return data!; }, /** diff --git a/webui/src/components/layout/ab-topbar.vue b/webui/src/components/layout/ab-topbar.vue index 699ef9eb..7f62bc3d 100644 --- a/webui/src/components/layout/ab-topbar.vue +++ b/webui/src/components/layout/ab-topbar.vue @@ -9,14 +9,13 @@ import { } from '@icon-park/vue-next'; const { t, changeLocale } = useMyI18n(); +const { running, onUpdate, offUpdate } = useAppInfo(); const search = ref(''); const show = ref(false); const showAdd = ref(false); -const { onUpdate, offUpdate, start, pause, shutdown, restart, resetRule } = - useProgramStore(); -const { running } = storeToRefs(useProgramStore()); +const { start, pause, shutdown, restart, resetRule } = useProgramStore(); const items = [ { diff --git a/webui/src/hooks/useAppInfo.ts b/webui/src/hooks/useAppInfo.ts new file mode 100644 index 00000000..6bbba953 --- /dev/null +++ b/webui/src/hooks/useAppInfo.ts @@ -0,0 +1,35 @@ +export const useAppInfo = createSharedComposable(() => { + const { auth } = useAuth(); + const running = ref(false); + const version = ref(''); + + function getStatus() { + const { execute, onResult } = useApi(apiProgram.status); + + onResult((res) => { + running.value = res.status; + version.value = res.version; + }); + + if (auth.value !== '') { + execute(); + } + } + + const { pause: offUpdate, resume: onUpdate } = useIntervalFn( + getStatus, + 3000, + { + immediate: false, + immediateCallback: true, + } + ); + + return { + running, + version, + + onUpdate, + offUpdate, + }; +}); diff --git a/webui/src/pages/index/log.vue b/webui/src/pages/index/log.vue index 58141bb2..878d7c8a 100644 --- a/webui/src/pages/index/log.vue +++ b/webui/src/pages/index/log.vue @@ -1,6 +1,7 @@