From d62c51f14039eeffd61f153cf2c77dc606366e67 Mon Sep 17 00:00:00 2001 From: nepiedg Date: Sat, 4 Apr 2026 02:52:50 +0800 Subject: [PATCH] feat: add image upload component with backend proxy and auto thumbnail - Create reusable ImageUpload.vue component (drag-drop, preview, progress) - Replace URL input fields with ImageUpload in category and template dialogs - Upload via backend proxy to avoid OSS CORS issues - Auto-fill thumbnail_url and image dimensions on template image upload Made-with: Cursor --- src/api/marketing.js | 17 +++ src/components/ImageUpload.vue | 183 +++++++++++++++++++++++++++++++++ src/views/marketing/index.vue | 46 +++++++-- 3 files changed, 239 insertions(+), 7 deletions(-) create mode 100644 src/components/ImageUpload.vue diff --git a/src/api/marketing.js b/src/api/marketing.js index 7cb97b7..8d9fb93 100644 --- a/src/api/marketing.js +++ b/src/api/marketing.js @@ -1,5 +1,22 @@ import request from '../utils/request' +export async function uploadToOSS(file) { + const formData = new FormData() + formData.append('file', file) + + const res = await request({ + url: '/api/admin/marketing/upload', + method: 'post', + data: formData, + headers: { 'Content-Type': 'multipart/form-data' }, + timeout: 60000 + }) + return { + url: res.data.url, + thumbnailUrl: res.data.thumbnail_url || res.data.url + } +} + export function getMarketingStats() { return request({ url: '/api/admin/marketing/stats', diff --git a/src/components/ImageUpload.vue b/src/components/ImageUpload.vue new file mode 100644 index 0000000..5b29d54 --- /dev/null +++ b/src/components/ImageUpload.vue @@ -0,0 +1,183 @@ + + + + + diff --git a/src/views/marketing/index.vue b/src/views/marketing/index.vue index e1d95b7..7eab911 100644 --- a/src/views/marketing/index.vue +++ b/src/views/marketing/index.vue @@ -161,8 +161,14 @@ - - + + @@ -191,11 +197,24 @@ - - + + - - + + @@ -221,6 +240,7 @@