From ce814b938d8ac7070877fd34a3ecd4c2a4ffcef5 Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Wed, 23 Jul 2025 10:56:12 +0800 Subject: [PATCH] feat: enable image upload in comment editor --- .../src/components/CommentEditor.vue | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/open-isle-cli/src/components/CommentEditor.vue b/open-isle-cli/src/components/CommentEditor.vue index 09d790fed..c4e4f57dc 100644 --- a/open-isle-cli/src/components/CommentEditor.vue +++ b/open-isle-cli/src/components/CommentEditor.vue @@ -24,6 +24,8 @@ import { themeState } from '../utils/theme' import 'vditor/dist/index.css' import LoginOverlay from './LoginOverlay.vue' import { isMobile } from '../utils/screen' +import { API_BASE_URL } from '../main' +import { getToken } from '../utils/auth' export default { name: 'CommentEditor', @@ -97,10 +99,43 @@ export default { 'redo', '|', 'link', + 'upload' ], + upload: { + fieldName: 'file', + url: `${API_BASE_URL}/api/upload`, + accept: 'image/*,video/*', + multiple: false, + headers: { Authorization: `Bearer ${getToken()}` }, + format(files, responseText) { + const res = JSON.parse(responseText) + if (res.code === 0) { + return JSON.stringify({ + code: 0, + msg: '', + data: { + errFiles: [], + succMap: { [files[0].name]: res.data.url } + } + }) + } else { + return JSON.stringify({ + code: 1, + msg: '上传失败', + data: { errFiles: files.map(f => f.name), succMap: {} } + }) + } + } + }, toolbarConfig: { pin: true }, input(value) { text.value = value + }, + after() { + if (props.loading || props.disabled) { + vditorInstance.value.disabled() + } + applyTheme() } }) // applyTheme()