diff --git a/activitylink/.env.development b/activitylink/.env.development index 40cb689..123b1ff 100644 --- a/activitylink/.env.development +++ b/activitylink/.env.development @@ -2,5 +2,6 @@ VITE_ENV = 'development' VITE_OUTPUT_DIR = 'dev' VITE_PUBLIC_PATH = '/testBack/' VITE_APP_BASE_API = 'https://dbqb.nfdxy.net/devLotApi/' +# VITE_APP_BASE_API = 'http://localhost:12699/' VITE_USE_MOCK = true -VITE_UPLOAD_URL=http://39.101.133.168:8828/hljw/api/aws/upload \ No newline at end of file +VITE_UPLOAD_URL='/hljw/api/aws/upload' \ No newline at end of file diff --git a/activitylink/.env.production b/activitylink/.env.production index b4c1ecc..7ad2e01 100644 --- a/activitylink/.env.production +++ b/activitylink/.env.production @@ -4,4 +4,5 @@ VITE_PUBLIC_PATH = '/testBack/' VITE_USE_MOCK = true VITE_BUILD_COMPRESS = 'none' VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false -VITE_APP_BASE_API = 'https://dbqb.nfdxy.net/devLotApi/' \ No newline at end of file +VITE_UPLOAD_URL='https://api.homilychart.com/hljw/api/aws/upload' + diff --git a/activitylink/package.json b/activitylink/package.json index 557f07f..b2fe597 100644 --- a/activitylink/package.json +++ b/activitylink/package.json @@ -5,7 +5,8 @@ "type": "module", "scripts": { "dev": "vite --host", - "build": "vite build", + "build:test": "vite build --mode test", + "build:prod": "vite build --mode production", "preview": "vite preview" }, "dependencies": { diff --git a/activitylink/src/utils/request.js b/activitylink/src/utils/request.js index c0fa594..fc242c9 100644 --- a/activitylink/src/utils/request.js +++ b/activitylink/src/utils/request.js @@ -29,11 +29,8 @@ service.interceptors.response.use( export const uploadFile = (file) => { const formData = new FormData(); formData.append('file', file); - - return service.post(import.meta.env.VITE_UPLOAD_URL, formData, { - headers: { - 'Content-Type': 'multipart/form-data' - } + return service.post('/api/upload/hljw/api/aws/upload', formData, { + headers: {'Content-Type': 'multipart/form-data'} }); }; export default service \ No newline at end of file diff --git a/activitylink/src/views/zhongchou/gift/index.vue b/activitylink/src/views/zhongchou/gift/index.vue index 829fa1a..d528bbd 100644 --- a/activitylink/src/views/zhongchou/gift/index.vue +++ b/activitylink/src/views/zhongchou/gift/index.vue @@ -48,7 +48,7 @@ - @@ -143,7 +143,7 @@ const editForm = ref({ gradeId: '', imageUrl: null }) -const uploadUrl = '/hljw/api/aws/upload'; +const uploadUrl = ref('/upload') const formRef = ref(null) const uploadRef = ref(null) @@ -239,7 +239,7 @@ const submitAdd = async () => { } // 删除 const deleteGift = (row) => { - ElMessageBox.confirm('确定要删除该等级吗?', '提示', { + ElMessageBox.confirm('确定要删除该礼品吗?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' @@ -304,7 +304,30 @@ const goToimportFixedList = (row) => { } }); } +const customUpload = async (options) => { + try { + const formData = new FormData(); + formData.append('file', options.file); + + const response = await axios.post(import.meta.env.VITE_UPLOAD_URL, formData, { + headers: { + 'Content-Type': 'multipart/form-data', + 'Authorization': `Bearer ${localStorage.getItem('token')}` + } + }); + if (response.data.code === 200 && response.data.data) { + // 传递原始文件对象和响应数据 + handleUploadSuccess(response.data, options.file); + ElMessage.success('上传成功'); + } else { + ElMessage.error(response.data.msg || '上传失败'); + } + } catch (error) { + console.error('上传错误:', error); + ElMessage.error(`上传失败: ${error.response?.data?.message || error.message}`); + } +}; const goToimportUsers = () => { router.push({ name: 'importUsers' }); } diff --git a/activitylink/vite.config.js b/activitylink/vite.config.js index 26441e2..c23f85b 100644 --- a/activitylink/vite.config.js +++ b/activitylink/vite.config.js @@ -19,6 +19,11 @@ export default defineConfig({ rewrite: (path) => path.replace(/^\/api/, ''), // 移除 /api 前缀 // 或者更精确的重写(根据后端路径调整): // rewrite: (path) => path.replace(/^\/api\/admin/, '/admin'), + }, + '/upload': { + target: 'http://39.101.133.168:8828', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/upload/, ''), } }, },