Skip to content

Status Bar ​

Vue 已实现 · 还原验收 0/1 · 上游演示 · 固定版本源码

预览 ​

48 days of status
APIOperational
Aug 21Oct 7
WebsiteOperational
Aug 21Oct 7
  • Operational
  • Degraded
  • Outage

用法 ​

vue
<script setup lang="ts">
import { StatusBar } from 'beui-vue'
import { computed, ref } from 'vue'

const incident = ref(false), replay = ref(0)
const statuses = [
  { id: 'operational', label: 'Operational', color: '#059669' },
  { id: 'degraded', label: 'Degraded', color: '#d97706' },
  { id: 'outage', label: 'Outage', color: '#e11d48' },
]
const history = Array.from({ length: 48 }, (_, day) => {
  const date = new Date(Date.UTC(2026, 7, day + 21))
  return { id: date.toISOString().slice(0, 10), label: date.toLocaleDateString('en', { month: 'short', day: 'numeric', timeZone: 'UTC' }),
    status: day === 8 ? 'degraded' : 'operational', description: day === 8 ? 'Elevated response times for 12 minutes.' : 'All checks passed.' }
})
const website = history.map(datum => ({ ...datum, status: 'operational', description: 'All checks passed.' }))
const api = computed(() => history.map((datum, day) => incident.value && day >= 45 ? {
  ...datum, status: day === 46 ? 'outage' : 'degraded', description: day === 46 ? 'Requests failed for 4 minutes.' : 'Elevated response times.',
} : datum))
</script>

<template>
  <div class="chart-demo" style="max-width:42rem"><header><span>48 days of status</span><div><button type="button" @click="replay++">Replay</button><button type="button" @click="incident = !incident">{{ incident ? 'Resolve incident' : 'Simulate incident' }}</button></div></header>
    <div class="line"><strong>API</strong><span>{{ incident ? 'Degraded' : 'Operational' }}</span></div>
    <StatusBar :key="`api-${replay}`" label="API status" :data="api" :statuses="statuses" hide-legend />
    <div class="line website"><strong>Website</strong><span>Operational</span></div>
    <StatusBar :key="`site-${replay}`" label="Website status" :data="website" :statuses="statuses" />
  </div>
</template>
<style scoped>
.chart-demo { width: 100%; min-width: 0; margin-inline: auto; }
.chart-demo > header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 20px; }
.chart-demo header strong { font-size: 14px; font-weight: 500; }
.chart-demo header p, .chart-demo > p { margin: 4px 0 0; color: var(--beui-muted-foreground); font-size: 12px; line-height: 16px; }
.chart-demo header button,.chart-demo fieldset button { padding: 6px 12px; background: transparent; border: 0; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; }
.chart-demo header button:hover,.chart-demo fieldset button[aria-pressed=true] { background: var(--beui-muted); }
.chart-demo > footer { margin-top: 24px; text-align: center; color: var(--beui-muted-foreground); font-size: 11px; }
.chart-demo .sim { margin-left: 6px; border: 1px solid var(--beui-border); padding: 2px 5px; border-radius: 3px; text-transform: uppercase; font-size: 9px; letter-spacing: .05em; color: var(--beui-muted-foreground); }
</style>
<style scoped>.line { display:flex;justify-content:space-between;margin-bottom:8px;font-size:14px; }.line span,header > span {color:var(--beui-muted-foreground)}.website { margin-top:24px;padding-top:24px;border-top:1px solid var(--beui-border); }</style>

API ​

data 提供时间观测,statuses 自定义状态颜色和名称,v-model:active-id 同步检查位置,可用 #tooltip 自定义读数。

还原验收 ​

基于 beUI 的独立 Vue 移植,依 MIT 许可证分发。