diff --git a/pkg/views/src/components/publish/ArticleEditor.vue b/pkg/views/src/components/publish/ArticleEditor.vue index 95afd66..778fe88 100644 --- a/pkg/views/src/components/publish/ArticleEditor.vue +++ b/pkg/views/src/components/publish/ArticleEditor.vue @@ -28,6 +28,7 @@ label="Content" hint="The content supports markdown syntax" v-model="data.content" + @paste="pasteMedia" /> @@ -73,9 +74,7 @@

This article attached

-

- {{ data.attachments.length }} attachment(s) -

+

{{ data.attachments.length }} attachment(s)

@@ -88,7 +87,7 @@ - + Your article has been published. @@ -158,6 +157,22 @@ async function postArticle(evt: SubmitEvent) { } loading.value = false } + +const media = ref(null) + +function pasteMedia(evt: ClipboardEvent) { + const files = evt.clipboardData?.files + if (files) { + Array.from(files).forEach((item) => { + media.value.upload(item).then((meta: any) => { + if (meta) { + data.content += `\n![${item.name}](/api/attachments/o/${meta.info.file_id})` + } + }) + }) + evt.preventDefault() + } +} \ No newline at end of file diff --git a/pkg/views/src/components/publish/parts/Media.vue b/pkg/views/src/components/publish/parts/Media.vue index 17e1f2b..bb99a29 100644 --- a/pkg/views/src/components/publish/parts/Media.vue +++ b/pkg/views/src/components/publish/parts/Media.vue @@ -22,9 +22,7 @@ - + @@ -68,16 +66,20 @@ async function upload(file?: any) { headers: { Authorization: `Bearer ${getAtk()}` }, body: data }) + let meta: any; if (res.status !== 200) { error.value = await res.text() } else { - const data = await res.json() - emits("update:value", props.value.concat([data.info])) + meta = await res.json() + emits("update:value", props.value.concat([meta.info])) picked.value = [] } emits("update:uploading", false) + return meta } +defineExpose({ upload }) + function getFileName(item: any) { return item.filename.replace(/\.[^/.]+$/, "") }