﻿# Empty 空状态 {#empty}

用于展示数据为空、网络异常、暂无权限等状态，保留旧版八类插画和插槽。可使用右上角菜单切换组件主题和语言。

## 内置类型 {#types}

### 内置类型
```vue
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 20px">
  <nf-empty type="data" :image-size="120" />
  <nf-empty type="internet" :image-size="120" />
  <nf-empty type="message" :image-size="120" />
  <nf-empty type="server" :image-size="120" />
  <nf-empty type="loading" :image-size="120" />
  <nf-empty type="authority" :image-size="120" />
  <nf-empty type="call" :image-size="120" />
  <nf-empty type="seat" :image-size="120" />
</div>
```

## 图片与尺寸 {#custom}

### 图片与尺寸
```vue
<div style="display: flex; flex-wrap: wrap; gap: 20px">
  <nf-empty :image-size="80" border />
  <nf-empty :image-size="145" description="自定义描述" />
  <nf-empty :image-size="100" image="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Ccircle cx='60' cy='60' r='50' fill='%2317f'/%3E%3C/svg%3E" />
</div>
```

## 描述与底部操作 {#slots}

### 描述与底部操作
```vue
<nf-empty description="自定义描述">
  <template #description><strong>描述插槽优先显示</strong></template>
  <nf-button type="primary">重试</nf-button>
</nf-empty>
```

## 交互体验 {#interactive}


See expanded example example-4 (EmptyExamples).


## 按需引入 {#installation}

```ts
import { createApp } from 'vue'
import NfEmpty from '@94ai-plus/nf-empty'
import '@94ai-plus/nf-theme-chalk/nf-empty.css'

const app = createApp(App)
app.use(NfEmpty)
```

支持独立安装、总包具名导出和 resolver 自动导入。Chalk/OEM 插画随统一主题实时切换，默认文案随语言切换；自定义文案和插槽由业务控制。

## 属性 {#props}

| 属性 | 说明 | 类型／可选值 | 默认值 |
| --- | --- | --- | --- |
| image | 自定义图片地址，优先于内置插画 | string | `''` |
| type | 空状态类型 | data / internet / message / server / loading / authority / call / seat | data |
| border | 显示边框 | boolean | false |
| image-size | 图片宽度（px），0 保留默认尺寸 | number | undefined |
| description | 自定义文案，空值使用对应语言的默认文案 | string | `''` |

## Slots {#slot-api}

| Slot | 说明 |
| --- | --- |
| description | 自定义描述，优先于 description 属性 |
| default | 底部操作内容 |

## 迁移说明 {#migration}

修复旧版 seat 默认文案缺失、OEM seat/server 图片映射反向及 imageSize 默认值错误。不再使用 window.$agentCustomization；使用 NfConfigProvider theme 或 data-nf-theme。原始 SVG 内联分发，SSR 不依赖 window。

## Expanded component examples

### EmptyExamples

Source: docs/.vitepress/theme/components/EmptyExamples.vue

```vue
<script setup lang="ts">
import { ref } from 'vue'
import { NfEmpty, NfButton, type EmptyType } from '@94ai-plus/common-ui'
import { useDocsLanguage } from '../locale'

const { locale } = useDocsLanguage()
const types: EmptyType[] = ['data', 'internet', 'message', 'server', 'loading', 'authority', 'call', 'seat']
const type = ref<EmptyType>('data')
const imageSize = ref(140)
const description = ref('')
const border = ref(false)
const customImage = ref(false)
const useDescriptionSlot = ref(false)
const count = ref(0)
const image = 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="120" height="120"%3E%3Ccircle cx="60" cy="60" r="50" fill="%2317f"/%3E%3C/svg%3E'
</script>

<template>
  <section class="empty-examples" data-testid="empty-examples">
    <div class="empty-controls">
      <label>type <select v-model="type" data-testid="empty-type"><option v-for="item in types" :key="item">{{ item }}</option></select></label>
      <label>imageSize <input v-model.number="imageSize" data-testid="empty-size" type="number" min="0" max="300"></label>
      <label>description <input v-model="description" data-testid="empty-description"></label>
      <label><input v-model="border" data-testid="empty-border" type="checkbox">border</label>
      <label><input v-model="customImage" data-testid="empty-custom-image" type="checkbox">image</label>
      <label><input v-model="useDescriptionSlot" data-testid="empty-description-slot" type="checkbox">description slot</label>
    </div>
    <NfEmpty data-testid="interactive-empty" :type="type" :image="customImage ? image : ''" :image-size="imageSize" :description="description" :border="border">
      <template v-if="useDescriptionSlot" #description><strong data-testid="empty-slot-text">{{ locale === 'zh-CN' ? '自定义描述插槽' : 'Custom description slot' }}</strong></template>
      <NfButton type="primary" data-testid="empty-retry" @click="count++">{{ locale === 'zh-CN' ? '重试' : 'Retry' }} {{ count }}</NfButton>
    </NfEmpty>
  </section>
</template>

<style scoped>
.empty-controls { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.empty-controls label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.empty-controls input:not([type='checkbox']) { width: 120px; }
.empty-controls input, .empty-controls select { border: 1px solid var(--site-border); border-radius: 4px; padding: 4px; background: var(--site-background); color: var(--site-text); }
.empty-examples > .nf-empty { padding: 16px; }
</style>
```

Source: docs/.vitepress/theme/locale.ts

```ts
import { computed, inject, type InjectionKey, type Ref } from 'vue'
import { withBase } from 'vitepress'
import { localizePath, type LocaleName } from '../../../packages/common-locale/src/languages'
import { additionalMessages } from '../locales/ui'
export { languageDefinitions, localeFromPath, isLocaleName } from '../../../packages/common-locale/src/languages'

export type DocsLanguage = LocaleName
export const languageStorageKey = 'common-ui-plus:docs-language'
export const docsLanguageKey: InjectionKey<Ref<DocsLanguage>> = Symbol('docs-language')

const zh = {
  brand: '94智能通用组件库', home: '94智能公共组件库首页', skip: '跳至正文',
  toggleSidebar: '切换侧边导航', closeNav: '关闭导航', navigation: '顶部导航', sidebar: '文档导航', outline: '当前页面目录',
  guide: '指南', packages: '分包集合', theme: '主题', language: '语言', links: '边缘库',
  chalk: 'Chalk 默认主题', oem: 'OEM 定制主题', playground: '演练场',
  dark: '切换为暗色模式', light: '切换为亮色模式',
  search: '搜索文档', searchPlaceholder: '搜索文档，索引至标题，定位至组件', noResults: '没有匹配结果',
  example: '示例', loadingDemo: '正在加载示例…', preview: '实时预览', actions: '示例操作',
  edit: '在线编辑', editTitle: '在演练场中编辑', copy: '复制代码', copied: '代码已复制',
  expand: '展开代码', collapse: '收起代码', switchJs: '切换为 JS', switchTs: '切换为 TS',
  editor: '示例代码编辑器', switchFailed: '语言切换失败，代码未更改：',
  manualCopy: '请展开代码后手动复制。', copyFailed: '无法访问剪贴板，请在展开的编辑器中手动复制。',
}
const en: typeof zh = {
  brand: '94AI Common UI', home: '94AI Common UI home', skip: 'Skip to content',
  toggleSidebar: 'Toggle sidebar', closeNav: 'Close navigation', navigation: 'Top navigation', sidebar: 'Documentation navigation', outline: 'On this page',
  guide: 'Guide', packages: 'Packages', theme: 'Theme', language: 'Language', links: 'Links',
  chalk: 'Chalk default theme', oem: 'OEM custom theme', playground: 'Playground',
  dark: 'Switch to dark mode', light: 'Switch to light mode',
  search: 'Search docs', searchPlaceholder: 'Search docs, headings and components', noResults: 'No matching results',
  example: 'Example', loadingDemo: 'Loading example…', preview: ' live preview', actions: 'Example actions',
  edit: 'Edit online', editTitle: 'Edit in playground', copy: 'Copy code', copied: 'Code copied',
  expand: 'Expand code', collapse: 'Collapse code', switchJs: 'Switch to JS', switchTs: 'Switch to TS',
  editor: 'Example code editor', switchFailed: 'Language switch failed; code unchanged: ',
  manualCopy: 'Expand the code and copy it manually.', copyFailed: 'Clipboard unavailable. Copy the code manually from the editor.',
}
export const docsMessages: Record<DocsLanguage, typeof zh> = { 'zh-CN': zh, 'en-US': en, ...additionalMessages }

export function localizedPath(path: string, locale: DocsLanguage): string {
  return localizePath(path, locale)
}

export function useDocsLanguage() {
  const locale = inject(docsLanguageKey)!
  const english = computed(() => locale.value !== 'zh-CN')
  const ui = computed(() => docsMessages[locale.value])
  const docLink = (path: string) => withBase(localizedPath(path, locale.value))
  return { locale, english, ui, docLink }
}
```
