diff --git a/backend/config/settings.py b/backend/config/settings.py index fb4a058..d7cd9f8 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -119,16 +119,16 @@ if DB_HOST: } -# DB_HOST = os.environ.get('DB_HOST', '121.43.104.161') -# if DB_HOST: -# DATABASES['default'] = { -# 'ENGINE': 'django.db.backends.postgresql', -# 'NAME': os.environ.get('DB_NAME', 'market'), -# 'USER': os.environ.get('DB_USER', 'market'), -# 'PASSWORD': os.environ.get('DB_PASSWORD', '123market'), -# 'HOST': DB_HOST, -# 'PORT': os.environ.get('DB_PORT', '6433'), -# } +DB_HOST = os.environ.get('DB_HOST', '121.43.104.161') +if DB_HOST: + DATABASES['default'] = { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': os.environ.get('DB_NAME', 'market'), + 'USER': os.environ.get('DB_USER', 'market'), + 'PASSWORD': os.environ.get('DB_PASSWORD', '123market'), + 'HOST': DB_HOST, + 'PORT': os.environ.get('DB_PORT', '6433'), + } # Password validation diff --git a/miniprogram/src/api/index.ts b/miniprogram/src/api/index.ts index 682015c..7980538 100644 --- a/miniprogram/src/api/index.ts +++ b/miniprogram/src/api/index.ts @@ -94,10 +94,14 @@ export const uploadProjectFile = (filePath: string, projectId: number, fileName? 'Authorization': `Bearer ${Taro.getStorageSync('token')}` } }).then(res => { + console.log('Upload response:', res) if (res.statusCode >= 200 && res.statusCode < 300) { - return JSON.parse(res.data) + const data = JSON.parse(res.data) + console.log('Upload success, data:', data) + return data } - throw new Error('Upload failed') + console.error('Upload failed:', res) + throw new Error(`Upload failed: ${res.statusCode}`) }) } diff --git a/miniprogram/src/pages/competition/project.tsx b/miniprogram/src/pages/competition/project.tsx index 87a6ec7..80765cf 100644 --- a/miniprogram/src/pages/competition/project.tsx +++ b/miniprogram/src/pages/competition/project.tsx @@ -89,12 +89,20 @@ export default function ProjectEdit() { Taro.showLoading({ title: '上传中...' }) + console.log('Uploading cover image:', tempFilePaths[0]) const res = await uploadMedia(tempFilePaths[0], 'image') - handleInput('cover_image_url', res.file) // 假设返回 { file: 'url...' } + console.log('Cover upload result:', res) + + // res.file is the OSS URL + const coverUrl = res.file || res.file_url || res.url + console.log('Cover URL:', coverUrl) + handleInput('cover_image_url', coverUrl) Taro.hideLoading() + Taro.showToast({ title: '上传成功', icon: 'success' }) } catch (e) { Taro.hideLoading() + console.error('Cover upload error:', e) Taro.showToast({ title: '上传失败', icon: 'none' }) } } @@ -112,25 +120,52 @@ export default function ProjectEdit() { Taro.showLoading({ title: '上传中...' }) const file = tempFiles[0] + console.log('Uploading file:', file.name, 'path:', file.path) // @ts-ignore const result = await uploadProjectFile(file.path, project.id, file.name) + console.log('Upload result:', result) - // Update file list + // Update file list - use file_url_display or file_url + const fileUrl = result.file_url_display || result.file_url || '' setProject(prev => ({ ...prev, - files: [...(prev.files || []), result] + files: [...(prev.files || []), { + ...result, + url: fileUrl + }] })) Taro.hideLoading() Taro.showToast({ title: '上传成功', icon: 'success' }) } catch (e) { Taro.hideLoading() - console.error(e) + console.error('Upload error:', e) Taro.showToast({ title: '上传失败', icon: 'none' }) } } + const handlePreviewFile = (file: any) => { + const url = file.url || file.file_url_display || file.file_url + if (!url) { + Taro.showToast({ title: '文件链接无效', icon: 'none' }) + return + } + Taro.downloadFile({ + url: url, + success: (res: any) => { + if (res.statusCode === 200) { + Taro.openDocument({ filePath: res.tempFilePath }).catch(() => { + Taro.showToast({ title: '无法打开文件', icon: 'none' }) + }) + } + }, + fail: () => { + Taro.showToast({ title: '无法打开文件', icon: 'none' }) + } + }) + } + const handleDeleteFile = (fileId) => { // API call to delete file not implemented yet? Or just remove from list? // Usually we should call delete API. For now just remove from UI. @@ -260,10 +295,10 @@ export default function ProjectEdit() { - {project.files && project.files.map((file, index) => ( - + {project.files && project.files.map((file: any, index: number) => ( + handlePreviewFile(file)}> {file.name || '未知文件'} - {/* handleDeleteFile(file.id)}>删除 */} + 点击查看 ))} {(!project.files || project.files.length === 0) && 暂无附件 (PDF/PPT/视频)}