upload
All checks were successful
Deploy to Server / deploy (push) Successful in 14s

This commit is contained in:
jeremygan2021
2026-03-22 22:10:21 +08:00
parent 2104e7b7dc
commit 94333b61b6
3 changed files with 58 additions and 19 deletions

View File

@@ -119,16 +119,16 @@ if DB_HOST:
} }
# DB_HOST = os.environ.get('DB_HOST', '121.43.104.161') DB_HOST = os.environ.get('DB_HOST', '121.43.104.161')
# if DB_HOST: if DB_HOST:
# DATABASES['default'] = { DATABASES['default'] = {
# 'ENGINE': 'django.db.backends.postgresql', 'ENGINE': 'django.db.backends.postgresql',
# 'NAME': os.environ.get('DB_NAME', 'market'), 'NAME': os.environ.get('DB_NAME', 'market'),
# 'USER': os.environ.get('DB_USER', 'market'), 'USER': os.environ.get('DB_USER', 'market'),
# 'PASSWORD': os.environ.get('DB_PASSWORD', '123market'), 'PASSWORD': os.environ.get('DB_PASSWORD', '123market'),
# 'HOST': DB_HOST, 'HOST': DB_HOST,
# 'PORT': os.environ.get('DB_PORT', '6433'), 'PORT': os.environ.get('DB_PORT', '6433'),
# } }
# Password validation # Password validation

View File

@@ -94,10 +94,14 @@ export const uploadProjectFile = (filePath: string, projectId: number, fileName?
'Authorization': `Bearer ${Taro.getStorageSync('token')}` 'Authorization': `Bearer ${Taro.getStorageSync('token')}`
} }
}).then(res => { }).then(res => {
console.log('Upload response:', res)
if (res.statusCode >= 200 && res.statusCode < 300) { 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}`)
}) })
} }

View File

@@ -89,12 +89,20 @@ export default function ProjectEdit() {
Taro.showLoading({ title: '上传中...' }) Taro.showLoading({ title: '上传中...' })
console.log('Uploading cover image:', tempFilePaths[0])
const res = await uploadMedia(tempFilePaths[0], 'image') 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.hideLoading()
Taro.showToast({ title: '上传成功', icon: 'success' })
} catch (e) { } catch (e) {
Taro.hideLoading() Taro.hideLoading()
console.error('Cover upload error:', e)
Taro.showToast({ title: '上传失败', icon: 'none' }) Taro.showToast({ title: '上传失败', icon: 'none' })
} }
} }
@@ -112,25 +120,52 @@ export default function ProjectEdit() {
Taro.showLoading({ title: '上传中...' }) Taro.showLoading({ title: '上传中...' })
const file = tempFiles[0] const file = tempFiles[0]
console.log('Uploading file:', file.name, 'path:', file.path)
// @ts-ignore // @ts-ignore
const result = await uploadProjectFile(file.path, project.id, file.name) 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 => ({ setProject(prev => ({
...prev, ...prev,
files: [...(prev.files || []), result] files: [...(prev.files || []), {
...result,
url: fileUrl
}]
})) }))
Taro.hideLoading() Taro.hideLoading()
Taro.showToast({ title: '上传成功', icon: 'success' }) Taro.showToast({ title: '上传成功', icon: 'success' })
} catch (e) { } catch (e) {
Taro.hideLoading() Taro.hideLoading()
console.error(e) console.error('Upload error:', e)
Taro.showToast({ title: '上传失败', icon: 'none' }) 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) => { const handleDeleteFile = (fileId) => {
// API call to delete file not implemented yet? Or just remove from list? // 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. // Usually we should call delete API. For now just remove from UI.
@@ -260,10 +295,10 @@ export default function ProjectEdit() {
<Button size='mini' style={{ margin: 0, fontSize: '12px' }} onClick={handleUploadFile}></Button> <Button size='mini' style={{ margin: 0, fontSize: '12px' }} onClick={handleUploadFile}></Button>
</View> </View>
<View className='file-list'> <View className='file-list'>
{project.files && project.files.map((file, index) => ( {project.files && project.files.map((file: any, index: number) => (
<View key={index} className='file-item' style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '10px', background: '#f8f8f8', marginBottom: '8px', borderRadius: '4px' }}> <View key={index} className='file-item' style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '10px', background: '#f8f8f8', marginBottom: '8px', borderRadius: '4px' }} onClick={() => handlePreviewFile(file)}>
<Text className='file-name' style={{ flex: 1, fontSize: '14px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{file.name || '未知文件'}</Text> <Text className='file-name' style={{ flex: 1, fontSize: '14px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{file.name || '未知文件'}</Text>
{/* <Text className='delete' style={{ color: 'red', marginLeft: '10px' }} onClick={() => handleDeleteFile(file.id)}>删除</Text> */} <Text style={{ color: '#1890ff', fontSize: '12px', marginLeft: '10px' }}></Text>
</View> </View>
))} ))}
{(!project.files || project.files.length === 0) && <Text style={{ color: '#999', fontSize: '12px' }}> (PDF/PPT/)</Text>} {(!project.files || project.files.length === 0) && <Text style={{ color: '#999', fontSize: '12px' }}> (PDF/PPT/)</Text>}