比赛
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { View, Text, Button, Image, ScrollView } from '@tarojs/components'
|
||||
import { View, Text, Button, Image, ScrollView, PageContainer } from '@tarojs/components'
|
||||
import Taro, { useLoad, useDidShow } from '@tarojs/taro'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { getCompetitionDetail, enrollCompetition, getMyCompetitionEnrollment, getProjects } from '../../api'
|
||||
import { getCompetitionDetail, enrollCompetition, getMyCompetitionEnrollment, getProjects, getComments } from '../../api'
|
||||
import MarkdownReader from '../../components/MarkdownReader'
|
||||
import './detail.scss'
|
||||
|
||||
@@ -12,6 +12,8 @@ export default function CompetitionDetail() {
|
||||
const [myProject, setMyProject] = useState<any>(null)
|
||||
const [activeTab, setActiveTab] = useState(0)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [showComments, setShowComments] = useState(false)
|
||||
const [comments, setComments] = useState<any[]>([])
|
||||
|
||||
useLoad((options) => {
|
||||
const { id } = options
|
||||
@@ -145,6 +147,20 @@ export default function CompetitionDetail() {
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
const fetchComments = async (projectId) => {
|
||||
Taro.showLoading({ title: '加载中' })
|
||||
try {
|
||||
const res = await getComments({ project: projectId })
|
||||
const list = res.results || res.data || res || []
|
||||
setComments(Array.isArray(list) ? list : [])
|
||||
setShowComments(true)
|
||||
} catch (e) {
|
||||
Taro.showToast({ title: '获取评语失败', icon: 'none' })
|
||||
} finally {
|
||||
Taro.hideLoading()
|
||||
}
|
||||
}
|
||||
|
||||
const handleEnroll = async () => {
|
||||
if (!detail) return
|
||||
try {
|
||||
@@ -231,6 +247,10 @@ export default function CompetitionDetail() {
|
||||
</View>
|
||||
{project.final_score > 0 && <Text className='score'>{project.final_score}分</Text>}
|
||||
</View>
|
||||
<Button size='mini' style={{ marginTop: '8px', fontSize: '12px', background: 'transparent', color: '#666', border: '1px solid #ddd' }} onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
fetchComments(project.id)
|
||||
}}>查看评语</Button>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
@@ -264,12 +284,22 @@ export default function CompetitionDetail() {
|
||||
<View className='footer-action'>
|
||||
{enrollment ? (
|
||||
myProject ? (
|
||||
<Button
|
||||
className='btn enrolled'
|
||||
onClick={() => Taro.navigateTo({ url: `/pages/competition/project?id=${myProject.id}` })}
|
||||
>
|
||||
我的作品 ({myProject.status === 'submitted' ? '已提交' : '草稿'})
|
||||
</Button>
|
||||
<View style={{ display: 'flex', width: '100%', gap: '10px' }}>
|
||||
<Button
|
||||
className='btn enrolled'
|
||||
style={{ flex: 1 }}
|
||||
onClick={() => Taro.navigateTo({ url: `/pages/competition/project?id=${myProject.id}` })}
|
||||
>
|
||||
我的作品 ({myProject.status === 'submitted' ? '已提交' : '草稿'})
|
||||
</Button>
|
||||
<Button
|
||||
className='btn'
|
||||
style={{ width: '80px', background: '#fff', color: '#333', border: '1px solid #ddd', fontSize: '12px', padding: 0, display: 'flex', alignItems: 'center', justifyContent: 'center' }}
|
||||
onClick={() => fetchComments(myProject.id)}
|
||||
>
|
||||
评语
|
||||
</Button>
|
||||
</View>
|
||||
) : (
|
||||
enrollment.status === 'approved' ? (
|
||||
<Button
|
||||
@@ -294,6 +324,24 @@ export default function CompetitionDetail() {
|
||||
</Button>
|
||||
)}
|
||||
</View>
|
||||
|
||||
<PageContainer show={showComments} onClickOverlay={() => setShowComments(false)} position='bottom' round>
|
||||
<View className='comments-container' style={{ padding: '20px', maxHeight: '60vh', background: '#fff', borderTopLeftRadius: '16px', borderTopRightRadius: '16px' }}>
|
||||
<Text style={{ fontSize: '18px', fontWeight: 'bold', marginBottom: '16px', display: 'block', textAlign: 'center' }}>评委评语</Text>
|
||||
<ScrollView scrollY style={{ height: '300px' }}>
|
||||
{comments.length > 0 ? comments.map((c: any) => (
|
||||
<View key={c.id} style={{ marginBottom: '16px', borderBottom: '1px solid #eee', paddingBottom: '8px' }}>
|
||||
<View style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '4px' }}>
|
||||
<Text style={{ fontWeight: 'bold', fontSize: '14px' }}>{c.judge_name || '评委'}</Text>
|
||||
<Text style={{ fontSize: '12px', color: '#999' }}>{c.created_at?.substring(0, 16)}</Text>
|
||||
</View>
|
||||
<Text style={{ display: 'block', color: '#333', fontSize: '14px', lineHeight: '1.5' }}>{c.content}</Text>
|
||||
</View>
|
||||
)) : <Text style={{ color: '#999', textAlign: 'center', display: 'block', marginTop: '20px' }}>暂无评语</Text>}
|
||||
</ScrollView>
|
||||
<Button onClick={() => setShowComments(false)} style={{ marginTop: '16px' }}>关闭</Button>
|
||||
</View>
|
||||
</PageContainer>
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user