@adminforth/dashboard

中文文档
2.1.3发布于 2026/10/21MITTypeScriptES Module近 30 天下载 1743

Dashboard plugin for AdminForth

原始使用文档
文档目录6 节
  1. Access
  2. Agent approvals
  3. Dashboard Config Shape
  4. Widget Support Matrix
  5. Query Shape
  6. Runtime Structure

@adminforth/dashboard

Dashboard plugin for AdminForth.

It adds configurable dashboard pages backed by an AdminForth resource. Dashboard records define groups and widgets, the plugin renders them under /dashboard/:slug, contributes a Dashboards sidebar group, and exposes endpoints for editing groups and widgets from the AdminForth UI.

Full setup guide: https://adminforth.dev/docs/tutorial/Plugins/dashboard/

Access

Dashboard viewing and editing are limited to superadmin by default. Set editRoles to allow other roles to edit dashboards, and viewRoles to let roles view dashboards without editing them:

new DashboardPlugin({
  dashboardConfigsResourceId: 'dashboard_configs',
  editRoles: ['superadmin', 'developer'],
  viewRoles: ['manager'],
})

Agent approvals

By default, the AI agent asks the user for approval before it changes dashboard settings, group or widget configs, or removes groups and widgets. Set agentEditsRequireApproval: false to let it apply these changes without asking:

new DashboardPlugin({
  dashboardConfigsResourceId: 'dashboard_configs',
  agentEditsRequireApproval: false,
})

editRoles still applies, and MCP clients stop receiving the destructive hint for these tools.

Dashboard Config Shape

type DashboardConfig = {
  version: number
  groups: {
    id: string
    label: string
    order: number
  }[]
  widgets: DashboardWidgetConfig[]
}

Each widget has common fields:

FieldDescription
idPersisted widget id.
group_idGroup where the widget is rendered.
labelOptional widget title.
targetWidget type: table, chart, kpi_card, pivot_table, or gauge_card.
orderWidget order inside its group.
variablesOptional widget variables passed to widget data loading. Variables are not available inside query.calcs.
sizePreset width: small, medium, large, wide, or full.
width, height, min_width, max_widthOptional explicit layout constraints. Without height, charts, tables and pivot tables are 400px tall, and KPI and gauge cards fit their content.
queryData query definition.

Widget Support Matrix

Widget targetConfig fieldMain settingsData usage
tabletablepagination, page_size, columnsUses query to display raw or aggregate rows.
chartcharttype, x, y, label, value, series, buckets, color, colorsUses the same query shape for most chart types. Multi-resource charts use query.source: steps; add query.bucket for shared numeric buckets across resources.
kpi_cardcardvalue, subtitle, comparison, sparklineReads the first returned query row.
gauge_cardcardvalue, target, progress, colorReads the first returned query row.
pivot_tablepivotrows, columns, valuesUses query rows to build a pivot table.

Chart widget types:

Chart typeNotes
lineUses x and y; y may contain multiple fields in config.
pieUses label and value.
barUses x and y.
stacked_barUses x, y, and series.
funnelUses label, value, and optional colors. Data comes from the same query shapes as every other chart.
histogramUses x, y, and optional buckets. Current histogram runtime support is single-resource only: provide raw rows for the numeric field and let chart.buckets derive counts on the frontend. For multi-resource bucket distributions, use stacked_bar with query.source: steps and query.bucket.

Query Shape

type QueryConfig = {
  source?: 'resource'
  resource: string
  select?: Array<
    | { field: string; as?: string; grain?: 'day' | 'week' | 'month' | 'year' }
    | { agg: 'sum' | 'count' | 'count_distinct' | 'avg' | 'min' | 'max' | 'median'; field?: string; as: string; filters?: DashboardFilter | DashboardFilter[] }
    | { calc: string; as: string }
  >
  filters?: DashboardFilter | DashboardFilter[]
  group_by?: Array<string | { field: string; as?: string; grain?: 'day' | 'week' | 'month' | 'year'; timezone?: string }>
  order_by?: Array<{ field: string; direction?: 'asc' | 'desc' }>
  limit?: number
  offset?: number
  bucket?: { field: string; buckets: Array<{ label: string; min?: number; max?: number }> }
  calcs?: Array<{ calc: string; as: string }>
  formatting?: Record<string, JsonValue>
} | {
  source: 'steps'
  steps: Array<{
    name: string
    resource: string
    select: Array<{ agg: 'sum' | 'count' | 'count_distinct' | 'avg' | 'min' | 'max' | 'median'; field?: string; as: string; filters?: DashboardFilter | DashboardFilter[] }>
    filters?: DashboardFilter | DashboardFilter[]
  }>
  calcs?: Array<{ calc: string; as: string }>
  order_by?: Array<{ field: string; direction?: 'asc' | 'desc' }>
  limit?: number
  offset?: number
  formatting?: Record<string, JsonValue>
}

`source: 'steps'` returns one aggregate row per step by default. Each step supports aggregate `select` items plus optional `filters`; it does not support per-step `field` selects, `calc` selects, or `group_by`. Add `query.bucket` when multiple resources need the same numeric buckets, for example a stacked bar distribution by price range.

type DashboardFilter =
  | { and: DashboardFilter[] }
  | { or: DashboardFilter[] }
  | {
      field: string
      eq?: FilterValue
      neq?: FilterValue
      gt?: FilterValue
      gte?: FilterValue
      lt?: FilterValue
      lte?: FilterValue
      in?: FilterValue[]
      not_in?: FilterValue[]
      like?: FilterValue
      ilike?: FilterValue
    }

type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue }
type RelativeDateValue = { now: true } | { now_minus: `${number}${'h' | 'd' | 'w' | 'mo' | 'y'}` }
type FilterValue = JsonValue | RelativeDateValue

Use filters for rolling date ranges. Do not hard-code dates for dashboards that should move with time:

query:
  resource: orders
  filters:
    and:
      - field: created_at
        gte:
          now_minus: 30d
      - field: created_at
        lt:
          now: true

Multi-resource queries use source: steps. Each step uses select, even if it has only one aggregate:

target: chart
label: Average price by database
chart:
  type: bar
  title: Average price by database
  x:
    field: name
  y:
    field: value
query:
  source: steps
  steps:
    - name: SQLite
      resource: cars_sl
      select:
        - agg: avg
          field: price
          as: value
    - name: MySQL
      resource: cars_mysql
      select:
        - agg: avg
          field: price
          as: value

Bucketed multi-resource queries use query.bucket. The dashboard runs each step once per bucket and returns rows with label, name, resource, and the selected aggregate aliases:

target: chart
label: Cars by price range and database
chart:
  type: stacked_bar
  title: Cars by price range and database
  x:
    field: label
  y:
    field: count
  series:
    field: name
query:
  source: steps
  bucket:
    field: price
    buckets:
      - label: Budget
        max: 3500
      - label: Mid-range
        min: 3500
        max: 7000
      - label: Premium
        min: 7000
  steps:
    - name: SQLite
      resource: cars_sl
      select:
        - agg: count
          as: count
    - name: MySQL
      resource: cars_mysql
      select:
        - agg: count
          as: count

Cost calculation example:

target: chart
label: Model costs
chart:
  type: stacked_bar
  title: GPT-5.4 costs by day
  x:
    field: day
  y:
    - field: input_cost
    - field: output_cost
    - field: cached_cost
query:
  resource: model_usage
  filters:
    and:
      - field: model
        eq: gpt-5.4
      - field: used_at
        gte:
          now_minus: 7d
      - field: used_at
        lt:
          now: true
  select:
    - field: used_at
      as: day
      grain: day
    - agg: sum
      field: input_tokens
      as: input_tokens
    - agg: sum
      field: output_tokens
      as: output_tokens
    - agg: sum
      field: cached_tokens
      as: cached_tokens
  group_by:
    - field: used_at
      as: day
      grain: day
  calcs:
    - calc: input_tokens / 1000000 * 2.5
      as: input_cost
    - calc: output_tokens / 1000000 * 15
      as: output_cost
    - calc: cached_tokens / 1000000 * 0.25
      as: cached_cost

Runtime Structure

DashboardPage.vue
└── DashboardRuntime.vue
    └── DashboardGroup.vue
        └── WidgetShell.vue
            └── WidgetRenderer.vue
                ├── TableWidget.vue
                ├── ChartWidget.vue
                ├── KpiCardWidget.vue
                ├── PivotTableWidget.vue
                └── GaugeCardWidget.vue

DashboardPage.vue loads a dashboard by slug, DashboardRuntime.vue renders ordered groups, WidgetShell.vue provides the widget frame and editor actions, and WidgetRenderer.vue selects the widget component by target.

版本与发布记录

@adminforth/dashboard 共发布 54 个版本,首次发布于 2026/05/28;过去 12 个月发布了 54 个版本。

版本发布日期距今
2.1.3latest2026/10/2119 天前
2.1.22026/10/1921 天前
2.1.12026/10/1921 天前
2.1.02026/10/1922 天前
2.0.02026/10/1822 天前
1.23.02026/10/1624 天前

关于 @adminforth/dashboard 的常见问题

@adminforth/dashboard 是什么?

Dashboard plugin for AdminForth

如何安装 @adminforth/dashboard?

在项目目录运行 npm install @adminforth/dashboard,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:adminforth(^4.7.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adminforth/dashboard 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adminforth/dashboard 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adminforth/dashboard 可以商用吗?

@adminforth/dashboard 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adminforth/dashboard 的下载量有多少?

根据 npm 官方下载统计,@adminforth/dashboard 在 2026/10/05 – 2026/11/03 这 30 天内被下载 1,743 次,日均约 58 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adminforth/dashboard 还在维护吗?

最新版本 2.1.3 发布于 2026/10/21(19 天前);至今共发布 54 个版本,其中过去 12 个月发布了 54 个;首次发布于 2026/05/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。