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/components/annotations-form.md.

AnnotationsForm

此组件用于提供统一的 Annotations 表单,可以根据 group 和 kind 属性自动渲染对应的表单项。

自 2.28.0 起,自定义注解使用 array 组件的折叠面板模式就地编辑,handleSubmit() 为异步方法:它会等待内置表单与自定义注解表单提交完成,并先提交尚未保存的注解条目,因此调用方需要 await,不再需要额外等待 nextTick。

使用示例

<script lang="ts" setup>
import { ref } from "vue";

const annotationsFormRef = ref();
const currentAnnotations = ref();

async function handleSubmit() {
  await annotationsFormRef.value?.handleSubmit();

  const { customAnnotations, annotations, customFormInvalid, specFormInvalid } =
    annotationsFormRef.value || {};

  // 表单验证不通过
  if (customFormInvalid || specFormInvalid) {
    return;
  }

  // 合并自定义数据和表单提供的数据
  const newAnnotations = {
    ...annotations,
    ...customAnnotations,
  };
}
</script>

<template>
  <AnnotationsForm
    ref="annotationsFormRef"
    :value="currentAnnotations"
    kind="Post"
    group="content.halo.run"
  />

  <VButton @click="handleSubmit">提交</VButton>
</template>

Props

属性名类型默认值描述
groupstring无,必填定义组件所属的分组。
kindstring无,必填定义组件的种类。
value{ [key: string]: string; } | null | null可选,包含键值对的对象或空值,用于存储数据。