组件
AI 附件 AI Attachments
附件条目:按扩展名显示图标,并显示文件名和易读的大小,同时提供不突出的移除操作。上传中使用虚线样式,错误使用危险色。
#基础用法
colophon.png47.1 KBnotes.md1.0 KBwireframe.figdenied.exe64.0 KBa-very-long-document-name-that-keeps-going-and-going.pdf2.0 MB
Click a chip's × to remove it.
<script setup lang="ts">
import { AiAttachment, AiAttachments } from "@bysages/vue";
import { ref } from "vue";
// The files riding the prompt: every chip state, and the quiet way
// back off.
const files = ref([
{ name: "colophon.png", size: 48213, status: "ready" as "ready" | "uploading" | "error" },
{ name: "notes.md", size: 1024, status: "ready" as "ready" | "uploading" | "error" },
{ name: "wireframe.fig", status: "uploading" as "ready" | "uploading" | "error" },
{ name: "denied.exe", size: 65536, status: "error" as "ready" | "uploading" | "error" },
{
name: "a-very-long-document-name-that-keeps-going-and-going.pdf",
size: 2097152,
status: "ready" as "ready" | "uploading" | "error",
},
]);
const removed = ref("");
const remove = (name: string) => {
files.value = files.value.filter((f) => f.name !== name);
removed.value = name;
};
</script>
<template>
<div class="grid gap-4 w-full">
<AiAttachments>
<AiAttachment
v-for="file in files"
:key="file.name"
:name="file.name"
:size="file.size"
:status="file.status"
@remove="remove(file.name)"
/>
</AiAttachments>
<p class="m-0 text-tertiary text-sm">
{{ removed ? `Removed: ${removed}` : "Click a chip's × to remove it." }}
</p>
</div>
</template>
#属性
#AiAttachment
附件条目:按扩展名显示图标,并显示文件名和易读的大小,同时提供不突出的移除操作。上传中使用虚线样式,错误使用危险色。
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
name | String | 文件名;组件按扩展名选择图标 | |
size | Number | undefined | 文件大小,单位字节;已知时按易读格式显示 |
status | String as PropType<"uploading" | "ready" | "error"> | "ready" | 上传在传输中的状态 |
#AiAttachments
附件区域,把多个附件渲染为一行可换行的 Chip。
纯造型的部件——自身没有属性,沿用部件结构的共享样式。