This commit is contained in:
@@ -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() {
|
||||
<Button size='mini' style={{ margin: 0, fontSize: '12px' }} onClick={handleUploadFile}>上传附件</Button>
|
||||
</View>
|
||||
<View className='file-list'>
|
||||
{project.files && project.files.map((file, index) => (
|
||||
<View key={index} className='file-item' style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '10px', background: '#f8f8f8', marginBottom: '8px', borderRadius: '4px' }}>
|
||||
{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' }} onClick={() => handlePreviewFile(file)}>
|
||||
<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>
|
||||
))}
|
||||
{(!project.files || project.files.length === 0) && <Text style={{ color: '#999', fontSize: '12px' }}>暂无附件 (PDF/PPT/视频)</Text>}
|
||||
|
||||
Reference in New Issue
Block a user