For AI agents: the complete documentation index is available at https://docs.halo.run/llms.txt, the full documentation bundle is available at https://docs.halo.run/llms-full.txt, and this page is available as Markdown at https://docs.halo.run/developer-guide/plugin/api-reference/ui/base-components/entity.md.

VEntity 实体

VEntity 表示列表中的一行数据,通常与 VEntityContainer 和 VEntityField 一起使用,构成 Halo Console 中常见的列表界面。

引入

import { VEntity, VEntityContainer, VEntityField } from "@halo-dev/components";

示例

基础用法

<script lang="ts" setup>
import { VEntity, VEntityContainer, VEntityField } from "@halo-dev/components";

const items = [
  { id: 1, name: "第一篇文档", description: "更新于 2 分钟前" },
  { id: 2, name: "第二篇文档", description: "更新于 1 小时前" },
  { id: 3, name: "第三篇文档", description: "更新于昨天" },
];
</script>

<template>
  <VEntityContainer>
    <VEntity v-for="item in items" :key="item.id">
      <template #start>
        <VEntityField :title="item.name" :description="item.description" />
      </template>
      <template #end>
        <span class="text-xs text-gray-500">已发布</span>
      </template>
    </VEntity>
  </VEntityContainer>
</template>

选中状态

<script lang="ts" setup>
import { ref } from "vue";
import { VEntity, VEntityContainer, VEntityField } from "@halo-dev/components";

const selectedId = ref(1);

const items = [
  { id: 1, name: "第一篇文档" },
  { id: 2, name: "第二篇文档" },
  { id: 3, name: "第三篇文档" },
];
</script>

<template>
  <VEntityContainer>
    <VEntity
      v-for="item in items"
      :key="item.id"
      :is-selected="selectedId === item.id"
      class="cursor-pointer"
      @click="selectedId = item.id"
    >
      <template #checkbox>
        <input
          type="checkbox"
          :checked="selectedId === item.id"
          @click.stop
          @change="selectedId = item.id"
        />
      </template>
      <template #start>
        <VEntityField :title="item.name" />
      </template>
    </VEntity>
  </VEntityContainer>
</template>

行内操作菜单

dropdownItems 插槽会自动生成右侧的更多操作菜单。

<script lang="ts" setup>
import {
  Toast,
  VDropdownItem,
  VEntity,
  VEntityContainer,
  VEntityField,
} from "@halo-dev/components";

const items = [
  { id: 1, name: "第一篇文档" },
  { id: 2, name: "第二篇文档" },
];
</script>

<template>
  <VEntityContainer>
    <VEntity v-for="item in items" :key="item.id">
      <template #start>
        <VEntityField :title="item.name" />
      </template>
      <template #dropdownItems>
        <VDropdownItem @click="Toast.success(`编辑 ${item.name}`)">
          编辑
        </VDropdownItem>
        <VDropdownItem
          type="danger"
          @click="Toast.success(`删除 ${item.name}`)"
        >
          删除
        </VDropdownItem>
      </template>
    </VEntity>
  </VEntityContainer>
</template>

VEntity Props

属性类型默认值说明
isSelectedbooleanfalse是否处于选中状态

VEntityContainer Props

VEntityContainer 没有属性,只提供默认插槽,内部会渲染为表格结构。

VEntityField Props

属性类型默认值说明
titlestringundefined标题
descriptionstringundefined描述文本
routeRouteLocationRawundefined标题点击后跳转的路由
widthstring | numberundefined固定宽度,数字会按像素处理
maxWidthstring | numberundefined最大宽度,数字会按像素处理

Emits

组件事件参数说明
VEntityFieldclick-点击标题时触发

Slots

组件插槽说明
VEntityprepend显示在行最左侧的内容
VEntitycheckbox选择框区域
VEntitystart行左侧的主要内容
VEntityend行右侧的内容
VEntitydropdownItems更多操作菜单中的内容
VEntityfooter行下方的附加内容
VEntityContainerdefault实体行列表
VEntityFieldtitle自定义标题
VEntityFieldextra标题旁的附加内容
VEntityFielddescription自定义描述