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

This commit is contained in:
jeremygan2021
2026-03-22 22:23:09 +08:00
parent 41d6991d5c
commit 431ddaf67c
3 changed files with 79 additions and 24 deletions

View File

@@ -1,5 +1,6 @@
from rest_framework import viewsets, permissions, status, filters, serializers
from rest_framework.decorators import action, api_view, permission_classes, csrf_exempt
from django.views.decorators.csrf import csrf_exempt
from rest_framework.decorators import action, api_view, permission_classes
from rest_framework.response import Response
from rest_framework.views import APIView
from django.db.models import Q

View File

@@ -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

View File

@@ -125,22 +125,71 @@ export default function ProjectEdit() {
Taro.hideLoading()
Taro.showToast({ title: '上传成功', icon: 'success' })
} catch (e) {
} catch (e: any) {
Taro.hideLoading()
console.error(e)
Taro.showToast({ title: '上传失败', icon: 'none' })
const errorMsg = e.response?.error || e.message || '上传失败'
Taro.showToast({ title: errorMsg, 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.
// Ideally we should have deleteProjectFile API.
// But user only asked to "optimize upload".
const handleDeleteFile = async (fileId) => {
try {
await Taro.showModal({
title: '确认删除',
content: '确定要删除这个文件吗?',
confirmColor: '#ff4d4f'
}).then(res => {
if (!res.confirm) throw new Error('cancel')
})
Taro.showLoading({ title: '删除中...' })
await deleteProjectFile(fileId)
setProject(prev => ({
...prev,
files: prev.files.filter(f => f.id !== fileId)
}))
Taro.hideLoading()
Taro.showToast({ title: '删除成功', icon: 'success' })
} catch (e: any) {
Taro.hideLoading()
if (e.message !== 'cancel') {
const errorMsg = e.response?.error || e.message || '删除失败'
Taro.showToast({ title: errorMsg, icon: 'none' })
}
}
}
const handlePreviewFile = (file) => {
const fileUrl = file.file_url || file.file_url_display || ''
if (!fileUrl) {
Taro.showToast({ title: '文件地址无效', icon: 'none' })
return
}
const fileType = file.file_type || ''
if (fileType === 'image') {
Taro.previewImage({
urls: [fileUrl]
})
} else {
Taro.downloadFile({
url: fileUrl,
success: (res) => {
if (res.statusCode === 200) {
Taro.openDocument({
filePath: res.tempFilePath,
fileType: fileType === 'pdf' ? 'pdf' : fileType === 'ppt' ? 'ppt' : undefined
})
}
},
fail: () => {
Taro.showToast({ title: '打开文件失败', icon: 'none' })
}
})
}
}
const handleSave = async (submit = false) => {
@@ -262,9 +311,14 @@ export default function ProjectEdit() {
</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' }}>
<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 className='delete' style={{ color: '#ff4d4f', marginLeft: '10px', fontSize: '14px' }} onClick={(e) => { e.stopPropagation(); handleDeleteFile(file.id) }}></Text>
</View>
))}
{(!project.files || project.files.length === 0) && <Text style={{ color: '#999', fontSize: '12px' }}> (PDF/PPT/)</Text>}