This commit is contained in:
jeremygan2021
2026-02-12 16:54:16 +08:00
parent 1919ab2227
commit 5a7043fa1c
17 changed files with 384 additions and 51 deletions

View File

@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react'
import Taro, { useRouter, useShareAppMessage } from '@tarojs/taro'
import { View, Text, Image, Video, RichText, Input, Button } from '@tarojs/components'
import Taro, { useRouter, useShareAppMessage, useDidShow } from '@tarojs/taro'
import { View, Text, Image, Video, RichText, Input, ScrollView } from '@tarojs/components'
import { AtActivityIndicator, AtIcon } from 'taro-ui'
import { getTopicDetail, createReply, uploadMedia } from '../../../api'
import { marked } from 'marked'
@@ -15,6 +15,7 @@ const ForumDetail = () => {
const [replyContent, setReplyContent] = useState('')
const [sending, setSending] = useState(false)
const [htmlContent, setHtmlContent] = useState('')
const [userInfo, setUserInfo] = useState<any>(null)
const fetchDetail = async () => {
try {
@@ -37,11 +38,20 @@ const ForumDetail = () => {
}
useEffect(() => {
const info = Taro.getStorageSync('userInfo')
if (info) setUserInfo(info)
if (id) {
fetchDetail()
}
}, [id])
useDidShow(() => {
if (id && !loading) {
fetchDetail()
}
})
useShareAppMessage(() => {
return {
title: topic?.title || '技术社区',
@@ -53,6 +63,12 @@ const ForumDetail = () => {
setReplyContent(e.detail.value)
}
const handleEdit = () => {
Taro.navigateTo({
url: `/subpackages/forum/create/index?id=${id}`
})
}
const handleUpload = async () => {
try {
const res = await Taro.chooseMedia({
@@ -125,6 +141,8 @@ const ForumDetail = () => {
return (
<View className='forum-detail-page'>
<ScrollView scrollY style={{height: '100vh'}}>
<View style={{paddingBottom: 80}}>
<View className='topic-card'>
<View className='header'>
{topic.is_pinned && <Text style={{color: '#ff4d4f', marginRight: 5, fontSize: 12, border: '1px solid #ff4d4f', padding: '0 4px', borderRadius: 4}}></Text>}
@@ -140,6 +158,13 @@ const ForumDetail = () => {
<Text>{new Date(topic.created_at).toLocaleDateString()}</Text>
<Text></Text>
<Text>{topic.view_count} </Text>
{userInfo && topic.author === userInfo.id && (
<View onClick={handleEdit} style={{display: 'flex', alignItems: 'center', marginLeft: 'auto', padding: '4px 8px', background: 'rgba(255,255,255,0.1)', borderRadius: 4}}>
<AtIcon value='edit' size='14' color='#00b96b' />
<Text style={{fontSize: 12, color: '#00b96b', marginLeft: 4}}></Text>
</View>
)}
</View>
</View>
@@ -177,6 +202,8 @@ const ForumDetail = () => {
</View>
))}
</View>
</View>
</ScrollView>
<View className='reply-bar'>
<View className='action-btn' onClick={handleUpload}>