@@ -10,6 +10,9 @@ description: 扩展附件选择组件的选项卡 - attachment:selector:create
1010## 定义方式
1111
1212``` ts
13+ import { definePlugin , type AttachmentSelectProvider } from " @halo-dev/console-shared"
14+ import { markRaw } from " vue"
15+ import FooComponent from " ./src/FooComponent.vue"
1316export default definePlugin ({
1417 extensionPoints: {
1518 " attachment:selector:create" : (): AttachmentSelectProvider []| Promise <AttachmentSelectProvider []> => {
@@ -56,14 +59,16 @@ export interface AttachmentSelectProvider {
5659 }>();
5760 ` ` `
5861
62+ ` AttachmentLike ` 是一个复合类型,可以是 Halo 附件模型数据、文件链接字符串、或者简单类型对象,类型定义:
63+
5964` ` ` ts title="AttachmentLike"
60- export type AttachmentLike =
61- | Attachment
62- | string
63- | {
64- url: string;
65- type: string;
66- };
65+ type AttachmentLike = Attachment | AttachmentSimple | string;
66+ interface AttachmentSimple {
67+ url: string; // 文件链接
68+ mediaType?: string; // 文件类型,如 image/png、video/*,如不填写,将被作为链接插入到文章
69+ alt?: string; // 代替文本
70+ caption?: string; // 说明文本
71+ }
6772` ` `
6873
6974## 示例
@@ -97,6 +102,9 @@ export default definePlugin({
97102
98103` ` ` vue title="StickerSelectorProvider.vue"
99104<script lang="ts" setup>
105+ import type { AttachmentLike, AttachmentSimple } from '@halo-dev/console-shared';
106+ import { ref } from 'vue';
107+
100108const props = withDefaults(
101109 defineProps<{
102110 selected: AttachmentLike[];
@@ -110,19 +118,22 @@ const emit = defineEmits<{
110118 (event: "update:selected", attachments: AttachmentLike[]): void;
111119}>();
112120
113- const stickers = [
121+ const stickers: AttachmentSimple[] = [
114122 {
115123 url: "https://picsum.photos/200?random=1",
124+ mediaType: "image/*"
116125 },
117126 {
118127 url: "https://picsum.photos/200?random=2",
128+ mediaType: "image/*"
119129 },
120130 {
121131 url: "https://picsum.photos/200?random=3",
132+ mediaType: "image/*"
122133 },
123134];
124135
125- const selectedStickers = ref<Set<String >>(new Set());
136+ const selectedStickers = ref<Set<string >>(new Set());
126137
127138const handleSelect = async (url: string) => {
128139 if (selectedStickers.value.has(url)) {
@@ -143,4 +154,5 @@ const handleSelect = async (url: string) => {
143154
144155## 实现案例
145156
157+ - [https :// github.com/halo-sigs/plugin-image-stream](https://github.com/halo-sigs/plugin-image-stream)
146158- [https :// github.com/halo-sigs/plugin-unsplash](https://github.com/halo-sigs/plugin-unsplash)
0 commit comments