feat: add employee management, backend health check, and UI improvements
This commit is contained in:
47
web/src/composables/useBackendHealth.js
Normal file
47
web/src/composables/useBackendHealth.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { fetchBackendHealth } from '../services/system.js'
|
||||
|
||||
const backendHealthy = ref(true)
|
||||
const backendChecking = ref(false)
|
||||
const backendError = ref('')
|
||||
let lastCheckedAt = 0
|
||||
|
||||
export async function checkBackendHealth(options = {}) {
|
||||
const force = Boolean(options.force)
|
||||
const now = Date.now()
|
||||
|
||||
if (!force && now - lastCheckedAt < 5000) {
|
||||
return backendHealthy.value
|
||||
}
|
||||
|
||||
backendChecking.value = true
|
||||
|
||||
try {
|
||||
const payload = await fetchBackendHealth()
|
||||
const ok = payload?.status === 'ok'
|
||||
|
||||
backendHealthy.value = ok
|
||||
backendError.value = ok
|
||||
? ''
|
||||
: payload?.database?.error || '后端服务尚未准备完成。'
|
||||
lastCheckedAt = now
|
||||
return ok
|
||||
} catch (error) {
|
||||
backendHealthy.value = false
|
||||
backendError.value = error?.message || '无法连接后端服务。'
|
||||
lastCheckedAt = now
|
||||
return false
|
||||
} finally {
|
||||
backendChecking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
export function useBackendHealth() {
|
||||
return {
|
||||
backendHealthy,
|
||||
backendChecking,
|
||||
backendError,
|
||||
checkBackendHealth
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user