This commit is contained in:
jeremygan2021
2026-02-12 19:40:59 +08:00
parent eb8957af91
commit 1f1516ae20
11 changed files with 772 additions and 20 deletions

View File

@@ -39,9 +39,18 @@ export const createTopic = (data: any) => request({ url: '/community/topics/', m
export const updateTopic = (id: number, data: any) => request({ url: `/community/topics/${id}/`, method: 'PATCH', data })
export const getReplies = (params: any) => request({ url: '/community/replies/', data: params })
export const createReply = (data: any) => request({ url: '/community/replies/', method: 'POST', data })
export const updateReply = (id: number, data: any) => request({ url: `/community/replies/${id}/`, method: 'PATCH', data })
export const deleteReply = (id: number) => request({ url: `/community/replies/${id}/`, method: 'DELETE' })
export const deleteTopic = (id: number) => request({ url: `/community/topics/${id}/`, method: 'DELETE' })
export const getStarUsers = () => request({ url: '/users/stars/' })
export const getAnnouncements = () => request({ url: '/community/announcements/' })
// Activities
export const getActivities = () => request({ url: '/community/activities/' })
export const getActivityDetail = (id: number) => request({ url: `/community/activities/${id}/` })
export const signupActivity = (id: number) => request({ url: `/community/activities/${id}/signup/`, method: 'POST' })
export const getMySignups = () => request({ url: '/community/activities/my_signups/' })
// Upload Media for Forum
export const uploadMedia = (filePath: string, type: 'image' | 'video') => {
const BASE_URL = process.env.TARO_APP_API_URL || 'https://market.quant-speed.com/api'

View File

@@ -27,7 +27,9 @@ export default defineAppConfig({
root: 'subpackages/forum',
pages: [
'detail/index',
'create/index'
'create/index',
'activity/index',
'activity/detail'
]
}
],

View File

@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'
import Taro, { usePullDownRefresh, useReachBottom } from '@tarojs/taro'
import React, { useState, useEffect, useRef } from 'react'
import Taro, { usePullDownRefresh, useReachBottom, useDidShow } from '@tarojs/taro'
import { View, Text, Image, Swiper, SwiperItem, ScrollView } from '@tarojs/components'
import { AtSearchBar, AtTabs, AtIcon, AtActivityIndicator } from 'taro-ui'
import { getTopics, getAnnouncements, getStarUsers } from '../../api'
@@ -14,6 +14,7 @@ const ForumList = () => {
const [page, setPage] = useState(1)
const [searchText, setSearchText] = useState('')
const [currentTab, setCurrentTab] = useState(0)
const isMounted = useRef(false)
const categories = [
{ title: '全部话题', key: 'all' },
@@ -45,8 +46,11 @@ const ForumList = () => {
const currentPage = reset ? 1 : page
const params: any = {
page: currentPage,
search: searchText,
category: categories[currentTab].key !== 'all' ? categories[currentTab].key : undefined
search: searchText
}
if (categories[currentTab].key !== 'all') {
params.category = categories[currentTab].key
}
const res = await getTopics(params)
@@ -74,9 +78,18 @@ const ForumList = () => {
}
}
useEffect(() => {
useDidShow(() => {
fetchList(true)
fetchExtraData()
})
useEffect(() => {
if (!isMounted.current) {
isMounted.current = true
return
}
fetchList(true)
// fetchExtraData is covered by useDidShow usually, but if tab change needs it? likely not.
}, [currentTab])
usePullDownRefresh(() => {
@@ -119,6 +132,12 @@ const ForumList = () => {
})
}
const navigateToActivity = () => {
Taro.navigateTo({
url: '/subpackages/forum/activity/index'
})
}
const getCategoryLabel = (cat) => {
const map = {
'help': '求助',
@@ -159,6 +178,10 @@ const ForumList = () => {
<AtIcon value='add' size='16' color='#fff' />
<Text style={{marginLeft: '4px'}}></Text>
</View>
<View className='create-btn' onClick={navigateToActivity} style={{marginLeft: '10px', background: 'rgba(255,255,255,0.2)'}}>
<AtIcon value='calendar' size='16' color='#fff' />
<Text style={{marginLeft: '4px'}}></Text>
</View>
</View>
</View>

View File

@@ -205,3 +205,157 @@
color: #333;
}
}
/* Login Modal Styles */
.login-modal-mask {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(5px);
z-index: 100;
display: flex;
align-items: center;
justify-content: center;
}
.login-modal-content {
width: 600px;
background: #1a1a1a;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 30px;
padding: 50px 40px;
display: flex;
flex-direction: column;
align-items: center;
box-shadow: 0 10px 40px rgba(0,0,0,0.5);
.modal-header {
margin-bottom: 60px;
text-align: center;
.modal-title {
display: block;
font-size: 40px;
font-weight: bold;
color: #fff;
margin-bottom: 16px;
}
.modal-subtitle {
font-size: 28px;
color: #888;
}
}
.modal-body {
width: 100%;
.btn-modal-login {
width: 100%;
height: 90px;
line-height: 90px;
border-radius: 45px;
font-size: 32px;
margin-bottom: 40px;
background: #333;
color: #888;
border: none;
&.primary {
background: linear-gradient(90deg, #00b96b 0%, #009959 100%);
color: #fff;
box-shadow: 0 8px 20px rgba(0, 185, 107, 0.3);
&:active {
transform: scale(0.98);
}
}
}
.agreement-box {
display: flex;
align-items: flex-start;
justify-content: center;
.agreement-checkbox {
transform: scale(0.7);
margin-top: -4px;
}
.agreement-text {
font-size: 24px;
color: #888;
line-height: 1.4;
.link {
color: #00b96b;
display: inline;
}
}
}
}
}
/* Agreement Detail Modal */
.agreement-modal-mask {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0.8);
z-index: 200;
display: flex;
align-items: center;
justify-content: center;
}
.agreement-content {
width: 600px;
height: 80vh;
background: #fff;
border-radius: 20px;
display: flex;
flex-direction: column;
overflow: hidden;
.agreement-title {
font-size: 36px;
font-weight: bold;
color: #333;
padding: 30px;
text-align: center;
border-bottom: 1px solid #eee;
}
.agreement-scroll {
flex: 1;
padding: 30px;
overflow-y: auto;
.p {
margin-bottom: 20px;
font-size: 28px;
color: #666;
line-height: 1.6;
}
}
.btn-close {
height: 100px;
line-height: 100px;
text-align: center;
background: #f5f5f5;
color: #00b96b;
font-size: 32px;
font-weight: bold;
border-radius: 0;
&:active {
background: #eee;
}
}
}

View File

@@ -1,10 +1,13 @@
import { View, Text, Image, Button } from '@tarojs/components'
import { View, Text, Image, Button, Checkbox, CheckboxGroup, RichText } from '@tarojs/components'
import Taro, { useDidShow } from '@tarojs/taro'
import { useState } from 'react'
import './index.scss'
export default function UserIndex() {
const [userInfo, setUserInfo] = useState<any>(null)
const [showLoginModal, setShowLoginModal] = useState(false)
const [isAgreed, setIsAgreed] = useState(false)
const [showAgreement, setShowAgreement] = useState(false) // For showing agreement content
useDidShow(() => {
const info = Taro.getStorageSync('userInfo')
@@ -23,7 +26,7 @@ export default function UserIndex() {
const token = Taro.getStorageSync('token')
if (token) {
await Taro.request({
url: 'https://market.quant-speed.com/api/wechat/update_user_info/',
url: 'https://market.quant-speed.com/api/wechat/update/',
method: 'POST',
header: {
'Authorization': `Bearer ${token}`,
@@ -46,6 +49,107 @@ export default function UserIndex() {
}
}
const handleAvatarClick = async () => {
if (!userInfo) return
try {
const { tempFilePaths } = await Taro.chooseImage({ count: 1, sizeType: ['compressed'], sourceType: ['album', 'camera'] })
if (!tempFilePaths.length) return
Taro.showLoading({ title: '上传中...' })
const token = Taro.getStorageSync('token')
const uploadRes = await Taro.uploadFile({
url: 'https://market.quant-speed.com/api/upload/image/',
filePath: tempFilePaths[0],
name: 'file',
header: {
'Authorization': `Bearer ${token}`
}
})
if (uploadRes.statusCode !== 200) {
throw new Error('上传失败')
}
const data = JSON.parse(uploadRes.data)
const newAvatarUrl = data.url
// 更新后端用户信息
await Taro.request({
url: 'https://market.quant-speed.com/api/wechat/update/',
method: 'POST',
header: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
data: {
avatar_url: newAvatarUrl
}
})
// 更新本地 userInfo
const updatedInfo = { ...userInfo, avatar_url: newAvatarUrl }
setUserInfo(updatedInfo)
Taro.setStorageSync('userInfo', updatedInfo)
Taro.hideLoading()
Taro.showToast({ title: '头像更新成功', icon: 'success' })
} catch (e) {
Taro.hideLoading()
Taro.showToast({ title: '头像更新失败', icon: 'none' })
console.error(e)
}
}
const handleNicknameClick = () => {
if (!userInfo) return
Taro.showModal({
title: '修改昵称',
content: userInfo.nickname || '',
// @ts-ignore
editable: true,
placeholderText: '请输入新昵称',
success: async function (res) {
if (res.confirm && (res as any).content) {
const newNickname = (res as any).content
if (newNickname === userInfo.nickname) return
try {
Taro.showLoading({ title: '更新中...' })
const token = Taro.getStorageSync('token')
await Taro.request({
url: 'https://market.quant-speed.com/api/wechat/update/',
method: 'POST',
header: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
data: {
nickname: newNickname
}
})
// 更新本地 userInfo
const updatedInfo = { ...userInfo, nickname: newNickname }
setUserInfo(updatedInfo)
Taro.setStorageSync('userInfo', updatedInfo)
Taro.hideLoading()
Taro.showToast({ title: '昵称已更新', icon: 'success' })
} catch (e) {
Taro.hideLoading()
Taro.showToast({ title: '更新失败', icon: 'none' })
console.error(e)
}
}
}
})
}
const handleLogout = () => {
Taro.showModal({
title: '提示',
@@ -120,6 +224,7 @@ export default function UserIndex() {
Taro.setStorageSync('token', res.data.token)
Taro.setStorageSync('userInfo', res.data)
setUserInfo(res.data)
setShowLoginModal(false) // Close modal on success
Taro.showToast({ title: '授权登录成功', icon: 'success' })
} else {
throw new Error(res.data.error || '登录失败')
@@ -162,32 +267,41 @@ export default function UserIndex() {
{ label: '优惠券', value: '0' }
]
const handleAgreementCheck = (e) => {
setIsAgreed(!!e.detail.value.length)
}
const handleShowAgreement = (e) => {
e.stopPropagation()
setShowAgreement(true)
}
const handleLoginBtnClick = () => {
if (!isAgreed) {
Taro.showToast({ title: '请先阅读并同意用户协议', icon: 'none' })
return
}
// If agreed, the button openType='getPhoneNumber' handles it.
}
return (
<View className='page-container'>
{/* Profile Card */}
<View className='profile-card'>
<View className='avatar-container'>
<View className='avatar-container' onClick={handleAvatarClick}>
<Image src={userInfo?.avatar_url || 'https://via.placeholder.com/150/00b96b/FFFFFF?text=USER'} className='avatar' />
{userInfo && <View className='online-dot' />}
</View>
<View className='info-col'>
<Text className='nickname'>{userInfo?.nickname || '未登录用户'}</Text>
<Text className='nickname' onClick={handleNicknameClick}>{userInfo?.nickname || '未登录用户'}</Text>
<Text className='uid'>ID: {userInfo ? (userInfo.phone_number || userInfo.id || '----') : '----'}</Text>
{!userInfo && (
<View className='login-btns'>
{/* <Button
className='btn-login'
onClick={login}
style={{ marginRight: '10px' }}
>
游客登录
</Button> */}
<Button
className='btn-login primary'
openType="getPhoneNumber"
onGetPhoneNumber={getPhoneNumber}
onClick={() => setShowLoginModal(true)}
>
</Button>
</View>
)}
@@ -229,6 +343,56 @@ export default function UserIndex() {
<Text>Quant Speed Market v1.0.0</Text>
<Text>Powered by Taro & React</Text>
</View>
{/* Login Modal */}
{showLoginModal && (
<View className='login-modal-mask' onClick={() => setShowLoginModal(false)}>
<View className='login-modal-content' onClick={e => e.stopPropagation()}>
<View className='modal-header'>
<Text className='modal-title'> Quant Speed</Text>
<Text className='modal-subtitle'></Text>
</View>
<View className='modal-body'>
<Button
className={`btn-modal-login ${isAgreed ? 'primary' : 'disabled'}`}
openType={isAgreed ? 'getPhoneNumber' : undefined}
onGetPhoneNumber={getPhoneNumber}
onClick={handleLoginBtnClick}
>
</Button>
<View className='agreement-box'>
<CheckboxGroup onChange={handleAgreementCheck}>
<Checkbox value='agree' checked={isAgreed} color='#00b96b' className='agreement-checkbox' />
</CheckboxGroup>
<Text className='agreement-text'>
<Text className='link' onClick={handleShowAgreement}></Text> <Text className='link' onClick={handleShowAgreement}></Text>
</Text>
</View>
</View>
</View>
</View>
)}
{/* Agreement Detail Modal */}
{showAgreement && (
<View className='agreement-modal-mask'>
<View className='agreement-content'>
<Text className='agreement-title'></Text>
<View className='agreement-scroll'>
<View className='p'><Text>1. </Text></View>
<View className='p'><Text>使使</Text></View>
<View className='p'><Text>2. </Text></View>
<View className='p'><Text>2.1 Quant SpeedQuant Speed</Text></View>
<View className='p'><Text>3. </Text></View>
<View className='p'><Text>3.1 使访使</Text></View>
</View>
<Button className='btn-close' onClick={() => setShowAgreement(false)}></Button>
</View>
</View>
)}
</View>
)
}

View File

@@ -0,0 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '活动详情'
})

View File

@@ -0,0 +1,79 @@
.activity-detail {
padding-bottom: 80px;
.cover {
width: 100%;
display: block;
}
.content {
padding: 20px;
.title {
font-size: 24px;
font-weight: bold;
display: block;
margin-bottom: 20px;
}
.meta-box {
background: #f9f9f9;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
.meta-row {
display: flex;
margin-bottom: 8px;
font-size: 14px;
color: #333;
.label {
color: #666;
width: 50px;
flex-shrink: 0;
}
&:last-child {
margin-bottom: 0;
}
}
}
.section-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
border-left: 4px solid #00b96b;
padding-left: 10px;
}
.description {
font-size: 16px;
line-height: 1.6;
color: #333;
}
}
.footer-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #fff;
padding: 10px 20px;
box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
padding-bottom: calc(10px + env(safe-area-inset-bottom));
.btn-signup {
width: 100%;
background: #00b96b;
border: none;
&[disabled] {
background: #ccc;
color: #fff;
}
}
}
}

View File

@@ -0,0 +1,112 @@
import React, { useState, useEffect } from 'react'
import Taro, { useRouter, useShareAppMessage } from '@tarojs/taro'
import { View, Text, Image, Button, RichText } from '@tarojs/components'
import { getActivityDetail, signupActivity } from '../../../api'
import { marked } from 'marked'
import './detail.scss'
const ActivityDetail = () => {
const router = useRouter()
const { id } = router.params
const [activity, setActivity] = useState<any>(null)
const [loading, setLoading] = useState(true)
const [submitting, setSubmitting] = useState(false)
const [htmlContent, setHtmlContent] = useState('')
useEffect(() => {
if (id) {
fetchDetail()
}
}, [id])
const fetchDetail = async () => {
try {
const res = await getActivityDetail(Number(id))
setActivity(res.data)
if (res.data.description) {
const html = marked.parse(res.data.description)
setHtmlContent((html as string).replace(/<img/g, '<img style="max-width:100%;border-radius:8px;"'))
}
} catch (error) {
console.error(error)
Taro.showToast({ title: '加载失败', icon: 'none' })
} finally {
setLoading(false)
}
}
const handleSignup = async () => {
const token = Taro.getStorageSync('token')
if (!token) {
Taro.showToast({ title: '请先登录', icon: 'none' })
return
}
setSubmitting(true)
try {
await signupActivity(Number(id))
Taro.showToast({ title: '报名成功', icon: 'success' })
fetchDetail() // Refresh status
} catch (error) {
console.error(error)
const msg = error.response?.data?.error || '报名失败'
Taro.showToast({ title: msg, icon: 'none' })
} finally {
setSubmitting(false)
}
}
useShareAppMessage(() => {
return {
title: activity?.title || '社区活动',
path: `/subpackages/forum/activity/detail?id=${id}`
}
})
if (loading) return <View>Loading...</View>
if (!activity) return <View></View>
return (
<View className='activity-detail'>
<Image src={activity.cover_image} mode='widthFix' className='cover' />
<View className='content'>
<Text className='title'>{activity.title}</Text>
<View className='meta-box'>
<View className='meta-row'>
<Text className='label'></Text>
<Text>{new Date(activity.start_time).toLocaleString()} ~ {new Date(activity.end_time).toLocaleString()}</Text>
</View>
<View className='meta-row'>
<Text className='label'></Text>
<Text>{activity.location || '线上活动'}</Text>
</View>
<View className='meta-row'>
<Text className='label'></Text>
<Text>{activity.current_signups} / {activity.max_participants > 0 ? activity.max_participants : '不限'}</Text>
</View>
</View>
<View className='description'>
<View className='section-title'></View>
<RichText nodes={htmlContent} />
</View>
</View>
<View className='footer-bar'>
<Button
className='btn-signup'
type='primary'
disabled={activity.has_signed_up || activity.status !== 'open' || submitting}
onClick={handleSignup}
>
{activity.has_signed_up ? '已报名' : (activity.status === 'open' ? '立即报名' : '无法报名')}
</Button>
</View>
</View>
)
}
export default ActivityDetail

View File

@@ -0,0 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '社区活动',
enablePullDownRefresh: true
})

View File

@@ -0,0 +1,109 @@
.activity-page {
min-height: 100vh;
background: #f5f5f5;
padding-bottom: 20px;
.tabs {
display: flex;
background: #fff;
padding: 10px 0;
position: sticky;
top: 0;
z-index: 10;
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
.tab {
flex: 1;
text-align: center;
font-size: 16px;
color: #666;
padding: 10px 0;
position: relative;
&.active {
color: #00b96b;
font-weight: bold;
&:after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 30px;
height: 3px;
background: #00b96b;
border-radius: 2px;
}
}
}
}
.list-container {
padding: 15px;
}
.empty {
text-align: center;
color: #999;
padding: 50px 0;
}
.activity-card {
background: #fff;
border-radius: 12px;
overflow: hidden;
margin-bottom: 15px;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
.cover {
width: 100%;
height: 150px;
}
.info {
padding: 15px;
.header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 10px;
.title {
font-size: 18px;
font-weight: bold;
flex: 1;
margin-right: 10px;
}
.status {
font-size: 12px;
padding: 2px 8px;
border-radius: 4px;
background: #eee;
color: #666;
&.open { background: #e6ffed; color: #00b96b; }
&.upcoming { background: #e6f7ff; color: #1890ff; }
&.ended { background: #f5f5f5; color: #999; }
}
}
.meta {
display: flex;
flex-direction: column;
gap: 5px;
font-size: 14px;
color: #666;
}
.signup-status {
margin-top: 10px;
text-align: right;
color: #00b96b;
font-size: 14px;
}
}
}
}

View File

@@ -0,0 +1,93 @@
import React, { useState, useEffect } from 'react'
import Taro, { usePullDownRefresh } from '@tarojs/taro'
import { View, Text, Image, Button } from '@tarojs/components'
import { getActivities, getMySignups } from '../../../api'
import './index.scss'
const ActivityList = () => {
const [activities, setActivities] = useState<any[]>([])
const [loading, setLoading] = useState(false)
const [tab, setTab] = useState<'all' | 'mine'>('all')
const [mySignups, setMySignups] = useState<any[]>([])
const fetchData = async () => {
setLoading(true)
try {
if (tab === 'all') {
const res = await getActivities()
setActivities(res.results || res.data || [])
} else {
const res = await getMySignups()
setMySignups(res.results || res.data || [])
}
} catch (error) {
console.error(error)
Taro.showToast({ title: '加载失败', icon: 'none' })
} finally {
setLoading(false)
Taro.stopPullDownRefresh()
}
}
useEffect(() => {
fetchData()
}, [tab])
usePullDownRefresh(() => {
fetchData()
})
const goDetail = (id) => {
Taro.navigateTo({ url: `/subpackages/forum/activity/detail?id=${id}` })
}
const getStatusText = (status) => {
const map = {
'upcoming': '即将开始',
'open': '报名中',
'ongoing': '进行中',
'ended': '已结束'
}
return map[status] || status
}
const renderList = (list) => {
if (list.length === 0 && !loading) return <View className='empty'></View>
return list.map(item => (
<View key={item.id} className='activity-card' onClick={() => goDetail(item.id)}>
<Image src={item.cover_image || 'https://via.placeholder.com/350x150'} mode='aspectFill' className='cover' />
<View className='info'>
<View className='header'>
<Text className='title'>{item.title}</Text>
<Text className={`status ${item.status}`}>{getStatusText(item.status)}</Text>
</View>
<View className='meta'>
<Text>📅 {new Date(item.start_time).toLocaleDateString()}</Text>
<Text>📍 {item.location || '线上活动'}</Text>
</View>
{tab === 'mine' && (
<View className='signup-status'>
<Text></Text>
</View>
)}
</View>
</View>
))
}
return (
<View className='activity-page'>
<View className='tabs'>
<View className={`tab ${tab === 'all' ? 'active' : ''}`} onClick={() => setTab('all')}></View>
<View className={`tab ${tab === 'mine' ? 'active' : ''}`} onClick={() => setTab('mine')}></View>
</View>
<View className='list-container'>
{renderList(tab === 'all' ? activities : mySignups)}
</View>
</View>
)
}
export default ActivityList