|
|
@@ -13,6 +13,13 @@ defineOptions({ name: 'Editor' })
|
|
|
|
|
|
type InsertFnType = (url: string, alt: string, href: string) => void
|
|
|
|
|
|
+const getUploadedFileUrl = (response: any): string => {
|
|
|
+ const data = response?.data ?? response
|
|
|
+ if (typeof data === 'string') return data
|
|
|
+ if (!data || typeof data !== 'object') return ''
|
|
|
+ return data.url || data.path || data.fileUrl || data.filePath || ''
|
|
|
+}
|
|
|
+
|
|
|
const localeStore = useLocaleStore()
|
|
|
|
|
|
const currentLocale = computed(() => localeStore.getCurrentLocale)
|
|
|
@@ -133,8 +140,10 @@ const editorConfig = computed((): IEditorConfig => {
|
|
|
onSuccess: () => {},
|
|
|
onError: () => {}
|
|
|
} as any)
|
|
|
- // 兼容前端直连上传和后端上传两种模式的返回格式
|
|
|
- const url = (res as any).data?.data || (res as any).data
|
|
|
+ const url = getUploadedFileUrl(res)
|
|
|
+ if (!url) {
|
|
|
+ throw new Error('上传接口未返回图片地址')
|
|
|
+ }
|
|
|
insertFn(url, 'image', url)
|
|
|
} catch (error: any) {
|
|
|
ElMessage.error(error.msg || '图片上传失败')
|
|
|
@@ -159,8 +168,10 @@ const editorConfig = computed((): IEditorConfig => {
|
|
|
onSuccess: () => {},
|
|
|
onError: () => {}
|
|
|
} as any)
|
|
|
- // 兼容前端直连上传和后端上传两种模式的返回格式
|
|
|
- const url = (res as any).data?.data || (res as any).data
|
|
|
+ const url = getUploadedFileUrl(res)
|
|
|
+ if (!url) {
|
|
|
+ throw new Error('上传接口未返回视频地址')
|
|
|
+ }
|
|
|
insertFn(url, 'mp4', url)
|
|
|
} catch (error: any) {
|
|
|
ElMessage.error(error.msg || '视频上传失败')
|