添加上传图片

This commit is contained in:
2025-06-15 21:53:50 +08:00
parent 4556eb71d8
commit 4caa3b061a
7 changed files with 63 additions and 5 deletions

View File

@@ -0,0 +1,35 @@
<template>
<MdEditor v-bind="props" v-model="modelValue" @upload-img="uploadImg" />
</template>
<script lang="ts" setup>
import { MdEditor } from "md-editor-v3"
//@ts-ignore
import "md-editor-v3/lib/style.css"
import { Helper } from "../../api"
import { useMessage } from "naive-ui"
const message = useMessage()
const modelValue = defineModel<string>()
const props = defineProps()
const uploadImg = async (files: File[], callback: (urls: string[]) => void) => {
try {
const res = await Promise.all(
files.map(async (file) => {
const path = await Helper.upload(file)
if (!path) {
message.error("图片上传失败")
return ""
}
return path
}),
)
callback(res.filter((url) => url !== ""))
} catch (err) {
message.error("图片上传失败")
callback([])
}
}
</script>