feat: redesign community tab page

This commit is contained in:
hajimi
2026-08-02 00:42:11 +08:00
parent 07a366cf3a
commit 0b46d497ae
8 changed files with 988 additions and 1383 deletions
+617
View File
@@ -0,0 +1,617 @@
<template>
<view class="community-page">
<view class="community-header" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="community-header__bar">
<image class="community-header__logo" src="/static/images/logo.png" mode="aspectFit" />
<view class="community-header__search" @tap="goSearch">
<u-icon name="search" size="32" color="#7a8494" />
<text>搜索话题球队作者</text>
</view>
<AiAssistantEntry size="compact" variant="orb" />
</view>
<view class="community-header__tools">
<view class="community-wallet" @tap="openPoints">
<view class="community-wallet__coin">
<u-icon name="coupon" size="28" color="#1468f5" />
</view>
<text>积分 {{ userPointsText }}</text>
<u-icon name="arrow-right" size="22" color="#1468f5" />
</view>
</view>
</view>
<view class="community-nav">
<view v-for="item in feedTabs" :key="item.key" class="community-nav__item"
:class="{ 'community-nav__item--active': activeFeed === item.key }" @tap="switchFeed(item.key)">
<text>{{ item.label }}</text>
</view>
</view>
<view class="community-topics">
<scroll-view scroll-x class="community-topics__scroll" show-scrollbar="false">
<view class="community-topics__list">
<view v-for="tag in featuredTags" :key="tag.id" class="community-topic"
:class="{ 'community-topic--active': activeTagId === tag.id }" @tap="selectTag(tag)">
<text class="community-topic__icon" :style="{ color: tag.theme.color }">{{ tag.theme.icon }}</text>
<text>{{ tag.name }}</text>
</view>
<view v-if="tagList.length > featuredTags.length" class="community-topic community-topic--more"
@tap="switchFeed('topic')">
<u-icon name="more-circle" size="26" color="#667085" />
<text>更多话题</text>
</view>
</view>
</scroll-view>
</view>
<scroll-view scroll-y class="community-list" :lower-threshold="120" @scrolltolower="loadMore">
<view class="community-list__heading">
<view>
<text class="community-list__eyebrow">SPORTS COMMUNITY</text>
<text class="community-list__title">{{ feedTitle }}</text>
</view>
<text v-if="activeTagName" class="community-list__selected"># {{ activeTagName }}</text>
</view>
<view v-if="loading && postList.length === 0" class="community-loading">
<u-loading mode="circle" />
<text>正在加载讨论</text>
</view>
<post-card v-for="post in postList" :key="post.id" :post="post" @tap="goDetail(post.id)"
@unlock="handleUnlock(post)" @avatar-tap="goUserProfile" @like="handleLike(post)"
@ai-analysis="handleAiAnalysis" />
<view v-if="!loading && postList.length === 0" class="community-empty">
<u-empty :text="activeFeed === 'follow' ? '关注的作者暂未发布内容' : '暂时没有相关讨论'" mode="data" />
</view>
<view v-if="loadingMore" class="community-loadmore">
<u-loading mode="circle" size="28" />
<text>加载中...</text>
</view>
<view v-else-if="finished && postList.length > 0" class="community-loadmore">
<text>已经到底了去发布一个新话题吧</text>
</view>
</scroll-view>
<view class="community-fab" @tap="goPublish">
<u-icon name="edit-pen" size="40" color="#fff" />
<text>发布</text>
</view>
</view>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { getCommunityPosts, getCommunityUserStats, getTagLists, purchasePost, toggleLike } from '@/api/community'
import { useUserStore } from '@/stores/user'
import { getToken } from '@/utils/auth'
import AiAssistantEntry from '@/components/ai-assistant-entry/ai-assistant-entry.vue'
import PostCard from '@/packages_community/components/post-card.vue'
type FeedKey = 'recommend' | 'follow' | 'hot' | 'topic'
const userStore = useUserStore()
const COMMUNITY_ACTIVE_TAG_KEY = 'community_active_tag'
const statusBarHeight = ref(0)
const activeFeed = ref<FeedKey>('recommend')
const activeTagId = ref(0)
const tagList = ref<any[]>([])
const postList = ref<any[]>([])
const userPoints = ref<number | null>(null)
const loading = ref(false)
const loadingMore = ref(false)
const finished = ref(false)
const page = ref(1)
const needRefresh = ref(false)
const fetchRequestId = ref(0)
const pageSize = 15
const feedTabs: Array<{ key: FeedKey; label: string }> = [
{ key: 'recommend', label: '推荐' },
{ key: 'follow', label: '关注' },
{ key: 'hot', label: '热门' },
{ key: 'topic', label: '话题' }
]
const isLogin = computed(() => userStore.isLogin)
const userPointsText = computed(() => (isLogin.value ? String(userPoints.value ?? 0) : '登录'))
const feedTitle = computed(() => ({ recommend: '精选讨论', follow: '关注动态', hot: '热门话题', topic: '话题广场' }[activeFeed.value]))
const activeTagName = computed(() => tagList.value.find((tag) => tag.id === activeTagId.value)?.name || '')
const TOPIC_THEMES = [
{ icon: '⚽', color: '#1468f5' },
{ icon: '🏀', color: '#ff7518' },
{ icon: '📈', color: '#21b573' },
{ icon: '↔', color: '#8b5cf6' },
{ icon: '🎮', color: '#596bff' }
]
const featuredTags = computed(() => {
return tagList.value.slice(0, 5).map((tag, index) => ({
...tag,
theme: TOPIC_THEMES[index % TOPIC_THEMES.length]
}))
})
const getSavedActiveTag = () => {
const tagId = Number(uni.getStorageSync(COMMUNITY_ACTIVE_TAG_KEY))
return Number.isFinite(tagId) && tagId > 0 ? tagId : 0
}
const goSearch = () => uni.navigateTo({ url: '/pages/search/search' })
const openPoints = () => {
if (!getToken()) {
uni.navigateTo({ url: '/pages/login/login' })
return
}
uni.navigateTo({ url: '/packages/pages/points_log/points_log' })
}
const loadUserPoints = async () => {
if (!getToken()) {
userPoints.value = null
return
}
try {
const stats = await getCommunityUserStats()
userPoints.value = Number(stats?.user_points || 0)
} catch (_error) {
userPoints.value = 0
}
}
const fetchTags = async () => {
try {
tagList.value = (await getTagLists()) || []
if (activeTagId.value && !tagList.value.some((tag) => tag.id === activeTagId.value)) {
activeTagId.value = 0
}
} catch (_error) {
tagList.value = []
}
}
const shouldHidePost = (post: any) => {
const tags = Array.isArray(post?.tags) ? post.tags : []
const images = Array.isArray(post?.images) ? post.images : []
const content = typeof post?.content === 'string' ? post.content.trim() : ''
const contentShort = typeof post?.content_short === 'string' ? post.content_short.trim() : ''
return tags.includes('特朗普') && images.length > 0 && !content && !contentShort
}
const isAbortError = (error: any) => String(error?.errMsg || error?.message || error || '').includes('abort')
const rankHotPosts = (items: any[]) => [...items].sort((left, right) => {
const leftScore = (Number(left.is_hot) * 1000000) + Number(left.view_count || 0) + Number(left.like_count || 0) * 8 + Number(left.comment_count || 0) * 12
const rightScore = (Number(right.is_hot) * 1000000) + Number(right.view_count || 0) + Number(right.like_count || 0) * 8 + Number(right.comment_count || 0) * 12
return rightScore - leftScore
})
const fetchPosts = async (reset = false) => {
if (reset) {
page.value = 1
finished.value = false
}
if (finished.value) return
const requestId = ++fetchRequestId.value
if (page.value === 1) loading.value = true
else loadingMore.value = true
try {
const params: Record<string, any> = { page_no: page.value, page_size: pageSize }
if (activeFeed.value === 'follow') params.follow = 1
if (activeTagId.value > 0) params.tag_id = activeTagId.value
const response = await getCommunityPosts(params)
const rawList = response?.lists || []
if (requestId !== fetchRequestId.value) return
const list = rawList.filter((item: any) => !shouldHidePost(item))
const normalizedList = activeFeed.value === 'hot' ? rankHotPosts(list) : list
postList.value = reset || page.value === 1 ? normalizedList : [...postList.value, ...normalizedList]
if (rawList.length < pageSize) finished.value = true
page.value++
} catch (error) {
if (requestId === fetchRequestId.value && !isAbortError(error)) {
uni.showToast({ title: '加载失败,请重试', icon: 'none' })
}
} finally {
if (requestId === fetchRequestId.value) {
loading.value = false
loadingMore.value = false
}
}
}
const switchFeed = (feed: FeedKey) => {
if (feed === 'follow' && !getToken()) {
uni.showModal({
title: '登录后查看关注动态',
content: '登录后可查看已关注作者的最新讨论。',
confirmText: '去登录',
success: (result) => result.confirm && uni.navigateTo({ url: '/pages/login/login' })
})
return
}
if (activeFeed.value === feed && (feed !== 'topic' || activeTagId.value === 0)) return
activeFeed.value = feed
if (feed !== 'topic') activeTagId.value = 0
fetchPosts(true)
}
const selectTag = (tag: any) => {
activeFeed.value = 'topic'
activeTagId.value = tag.id
uni.setStorageSync(COMMUNITY_ACTIVE_TAG_KEY, tag.id)
fetchPosts(true)
}
const loadMore = () => {
if (!finished.value && !loadingMore.value) fetchPosts()
}
const goDetail = (id: number) => uni.navigateTo({ url: `/packages_community/pages/post_detail?id=${id}` })
const goUserProfile = (userId: number) => userId && uni.navigateTo({ url: `/packages_community/pages/user_profile?user_id=${userId}` })
const goPublish = () => {
if (!getToken()) {
uni.showModal({
title: '提示',
content: '发布内容需要登录,是否前往登录?',
confirmText: '去登录',
success: (result) => result.confirm && uni.navigateTo({ url: '/pages/login/login' })
})
return
}
needRefresh.value = true
uni.navigateTo({ url: '/packages_community/pages/publish' })
}
const checkLogin = () => {
if (getToken()) return true
uni.showModal({
title: '提示',
content: '该操作需要登录,是否前往登录?',
confirmText: '去登录',
success: (result) => result.confirm && uni.navigateTo({ url: '/pages/login/login' })
})
return false
}
const handleUnlock = async (post: any) => {
if (!checkLogin()) return
try {
const result = await purchasePost({ post_id: post.id, confirm: 0 })
if (result?.content) {
post.is_unlocked = 1
post.content = result.content
post.content_short = result.content
return
}
if (result?.needs_payment) {
uni.showModal({
title: '解锁内容',
content: `确认花费 ${result.cost || post.price_points} 积分解锁此内容?`,
confirmText: '确认解锁',
confirmColor: '#1468f5',
success: async (modalResult) => {
if (!modalResult.confirm) return
try {
const paidResult = await purchasePost({ post_id: post.id, confirm: 1 })
post.is_unlocked = 1
if (paidResult?.content) {
post.content = paidResult.content
post.content_short = paidResult.content
}
needRefresh.value = true
loadUserPoints()
uni.showToast({ title: '解锁成功', icon: 'success' })
} catch (_error) { }
}
})
}
} catch (_error) { }
}
const handleLike = async (post: any) => {
if (!checkLogin()) return
try {
const result = await toggleLike({ target_id: post.id, target_type: 1 })
const liked = !!result?.is_liked
post.is_liked = liked
post.like_count = Math.max(0, Number(post.like_count || 0) + (liked ? 1 : -1))
} catch (_error) { }
}
const handleAiAnalysis = (post: any) => {
const tags = Array.isArray(post?.tags) ? post.tags : []
if (!tags.includes('旧澳六合') && !tags.includes('新澳六合')) return
const title = encodeURIComponent(String(post?.content || '帖子AI分析').split('\n')[0].trim().slice(0, 28) || '帖子AI分析')
uni.navigateTo({ url: `/pages/ai_analysis/ai_analysis?type=post&id=${post.id}&title=${title}` })
}
onMounted(() => {
const systemInfo = uni.getSystemInfoSync()
// #ifdef APP-PLUS || MP
statusBarHeight.value = systemInfo.statusBarHeight || 44
// #endif
activeTagId.value = getSavedActiveTag()
if (activeTagId.value) activeFeed.value = 'topic'
fetchTags()
fetchPosts(true)
loadUserPoints()
})
onShow(() => {
loadUserPoints()
if (!needRefresh.value) return
needRefresh.value = false
fetchPosts(true)
})
</script>
<style lang="scss" scoped>
.community-page {
min-height: 100vh;
height: 100vh;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
color: #172033;
background: #f5f7fb;
}
.community-header {
flex-shrink: 0;
padding: 14rpx 28rpx 0;
background: #fff;
&__bar {
display: flex;
align-items: center;
gap: 18rpx;
}
&__logo {
width: 82rpx;
height: 62rpx;
flex-shrink: 0;
}
&__search {
flex: 1;
min-width: 0;
height: 72rpx;
display: flex;
align-items: center;
gap: 12rpx;
padding: 0 24rpx;
border-radius: 999rpx;
color: #798391;
background: #f2f4f7;
text {
font-size: 27rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
&__tools {
display: flex;
justify-content: flex-end;
padding: 16rpx 0 14rpx;
}
}
.community-wallet {
height: 56rpx;
display: inline-flex;
align-items: center;
gap: 8rpx;
padding: 0 18rpx 0 10rpx;
border: 1rpx solid #bdd5ff;
border-radius: 999rpx;
color: #1468f5;
background: #fafdff;
box-sizing: border-box;
&__coin {
width: 38rpx;
height: 38rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #e8f1ff;
}
text {
font-size: 25rpx;
font-weight: 600;
}
}
.community-nav {
height: 90rpx;
display: flex;
align-items: flex-end;
gap: 62rpx;
padding: 0 42rpx;
flex-shrink: 0;
background: #fff;
box-sizing: border-box;
&__item {
position: relative;
height: 90rpx;
display: flex;
align-items: center;
justify-content: center;
color: #667085;
text {
font-size: 31rpx;
font-weight: 500;
}
&--active {
color: #1468f5;
text {
font-weight: 700;
}
&::after {
position: absolute;
bottom: 0;
left: 50%;
width: 46rpx;
height: 5rpx;
border-radius: 99rpx;
content: '';
background: #1468f5;
transform: translateX(-50%);
}
}
}
}
.community-topics {
flex-shrink: 0;
padding: 18rpx 0 20rpx;
background: #fff;
border-top: 1rpx solid #f4f5f7;
&__scroll {
white-space: nowrap;
}
&__list {
display: inline-flex;
gap: 16rpx;
padding: 0 28rpx;
}
}
.community-topic {
height: 62rpx;
display: inline-flex;
align-items: center;
gap: 10rpx;
padding: 0 22rpx;
border: 1rpx solid #e2e7ef;
border-radius: 999rpx;
color: #3e4a5d;
background: #fff;
box-sizing: border-box;
text {
font-size: 26rpx;
font-weight: 500;
}
&__icon {
font-size: 31rpx !important;
line-height: 1;
}
&--active {
border-color: #1468f5;
color: #1468f5;
background: #f1f6ff;
box-shadow: 0 5rpx 14rpx rgba(20, 104, 245, 0.1);
}
&--more {
color: #667085;
}
}
.community-list {
flex: 1;
height: 0;
min-height: 0;
}
.community-list__heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
padding: 30rpx 30rpx 20rpx;
}
.community-list__eyebrow {
display: block;
margin-bottom: 5rpx;
color: #8b96a8;
font-size: 18rpx;
font-weight: 700;
letter-spacing: 1.5rpx;
}
.community-list__title {
color: #182235;
font-size: 35rpx;
font-weight: 700;
}
.community-list__selected {
max-width: 260rpx;
overflow: hidden;
color: #1468f5;
font-size: 24rpx;
text-overflow: ellipsis;
white-space: nowrap;
}
.community-loading,
.community-empty {
display: flex;
flex-direction: column;
align-items: center;
gap: 16rpx;
padding: 100rpx 24rpx;
color: #8b96a8;
font-size: 24rpx;
}
.community-loadmore {
display: flex;
align-items: center;
justify-content: center;
gap: 12rpx;
padding: 24rpx 0 178rpx;
color: #98a2b3;
font-size: 24rpx;
}
.community-fab {
position: fixed;
right: 30rpx;
bottom: 152rpx;
width: 112rpx;
height: 112rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 1rpx;
border-radius: 50%;
color: #fff;
background: linear-gradient(145deg, #2478ff, #0753de);
box-shadow: 0 14rpx 30rpx rgba(20, 104, 245, 0.32);
z-index: 20;
text {
font-size: 22rpx;
font-weight: 600;
}
}
</style>
+11 -481
View File
@@ -1,495 +1,25 @@
<template>
<view class="community-page">
<view class="community-header" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="community-header__bar">
<image v-if="websiteLogo" class="community-header__logo" :src="websiteLogo" mode="aspectFill" />
<view class="community-header__search" @tap="goSearch">
<text class="community-header__search-icon">🔍</text>
<text class="community-header__search-text">搜索世博头条</text>
</view>
<AiAssistantEntry size="large" />
</view>
</view>
<view class="community-tags">
<scroll-view scroll-x class="community-tags__scroll">
<view class="community-tags__item" :class="{ 'community-tags__item--active': activeTag === 0 }"
@tap="switchTag(0)">
<text>全部</text>
</view>
<view v-if="isLogin" class="community-tags__item"
:class="{ 'community-tags__item--active': activeTag === -1 }" @tap="switchTag(-1)">
<text>关注</text>
</view>
<view v-for="tag in tagList" :key="tag.id" class="community-tags__item"
:class="{ 'community-tags__item--active': activeTag === tag.id }" @tap="switchTag(tag.id)">
<text>{{ tag.name }}</text>
<text v-if="tag.is_hot" class="community-tags__hot"></text>
</view>
</scroll-view>
</view>
<scroll-view scroll-y class="community-list" @scrolltolower="loadMore">
<view v-if="loading && postList.length === 0" class="community-loading">
<u-loading mode="circle" />
</view>
<post-card v-for="post in postList" :key="post.id" :post="post" @tap="goDetail(post.id)"
@unlock="handleUnlock(post)" @avatar-tap="goUserProfile" @like="handleLike(post)"
@share="handleShare(post)" @ai-analysis="handleAiAnalysis" />
<view v-if="!loading && postList.length === 0" class="community-empty">
<u-empty text="暂无帖子" mode="data" />
</view>
<view v-if="loadingMore" class="community-loadmore">
<u-loading mode="circle" size="32" />
<text>加载中...</text>
</view>
<view v-if="finished && postList.length > 0" class="community-loadmore">
<text>没有更多了</text>
</view>
</scroll-view>
<view class="community-fab" @tap="goPublish">
<u-icon name="edit-pen" size="44" color="#fff" />
</view>
<share-popup v-if="showSharePopup" v-model:show="showSharePopup" page-type="post" :page-id="sharePostId"
:title="sharePostTitle || '帖子'" />
<view class="legacy-community-page">
<text>正在前往社区</text>
</view>
</template>
<script lang="ts" setup>
import { ref, computed, onMounted } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { getCommunityPosts, getTagLists, purchasePost, toggleLike } from '@/api/community'
import { useAppStore } from '@/stores/app'
import { useUserStore } from '@/stores/user'
import { getToken } from '@/utils/auth'
import AiAssistantEntry from '@/components/ai-assistant-entry/ai-assistant-entry.vue'
import PostCard from '@/packages_community/components/post-card.vue'
import SharePopup from '@/components/share-popup/share-popup.vue'
<script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app'
const appStore = useAppStore()
const userStore = useUserStore()
const COMMUNITY_ACTIVE_TAG_KEY = 'community_active_tag'
const isLogin = computed(() => userStore.isLogin)
const websiteLogo = computed(() => {
const logo = appStore.config?.website?.shop_logo
if (!logo) return ''
if (logo.startsWith('http')) return logo
return (appStore.config?.domain || '') + logo
onLoad(() => {
uni.reLaunch({ url: '/pages/community/community' })
})
const goSearch = () => {
uni.navigateTo({ url: '/pages/search/search' })
}
const statusBarHeight = ref(0)
const activeTag = ref(0)
const tagList = ref<any[]>([])
const postList = ref<any[]>([])
const loading = ref(false)
const loadingMore = ref(false)
const finished = ref(false)
const page = ref(1)
const pageSize = 15
const needRefresh = ref(false)
const fetchRequestId = ref(0)
const getSavedActiveTag = () => {
const tagId = Number(uni.getStorageSync(COMMUNITY_ACTIVE_TAG_KEY))
if (!Number.isFinite(tagId)) return 0
if (tagId === -1 && !getToken()) return 0
return tagId
}
onMounted(() => {
const sysInfo = uni.getSystemInfoSync()
// #ifdef APP-PLUS || MP
statusBarHeight.value = sysInfo.statusBarHeight || 44
// #endif
// #ifdef H5
statusBarHeight.value = 0
// #endif
activeTag.value = getSavedActiveTag()
fetchTags()
fetchPosts(true)
needRefresh.value = false
})
onShow(() => {
if (needRefresh.value) {
needRefresh.value = false
page.value = 1
finished.value = false
fetchPosts(true)
}
})
const fetchTags = async () => {
try {
const res = await getTagLists()
tagList.value = res || []
} catch (e) {
console.warn('fetchTags error', e)
}
}
const shouldHidePost = (post: any) => {
const tags = Array.isArray(post?.tags) ? post.tags : []
const images = Array.isArray(post?.images) ? post.images : []
const content = typeof post?.content === 'string' ? post.content.trim() : ''
const contentShort = typeof post?.content_short === 'string' ? post.content_short.trim() : ''
return tags.includes('特朗普') && images.length > 0 && !content && !contentShort
}
const isAbortError = (error: any) => {
const message = String(error?.errMsg || error?.message || error || '')
return message.includes('abort')
}
const fetchPosts = async (reset = false) => {
if (reset) {
page.value = 1
finished.value = false
}
if (finished.value) return
const requestId = ++fetchRequestId.value
if (page.value === 1) {
loading.value = true
} else {
loadingMore.value = true
}
try {
const params: Record<string, any> = {
page_no: page.value,
page_size: pageSize
}
if (activeTag.value === -1) {
params.follow = 1
} else if (activeTag.value > 0) {
params.tag_id = activeTag.value
}
const res = await getCommunityPosts(params)
const rawList = res?.lists || []
const list = rawList.filter((item: any) => !shouldHidePost(item))
if (requestId !== fetchRequestId.value) return
if (reset || page.value === 1) {
postList.value = list
} else {
postList.value.push(...list)
}
if (rawList.length < pageSize) {
finished.value = true
}
page.value++
} catch (e) {
if (requestId === fetchRequestId.value && !isAbortError(e)) {
uni.showToast({ title: '加载失败,请重试', icon: 'none' })
}
} finally {
if (requestId === fetchRequestId.value) {
loading.value = false
loadingMore.value = false
}
}
}
const loadMore = () => {
if (finished.value || loadingMore.value) return
fetchPosts()
}
const switchTag = (id: number) => {
if (activeTag.value === id) return
activeTag.value = id
uni.setStorageSync(COMMUNITY_ACTIVE_TAG_KEY, id)
postList.value = []
fetchPosts(true)
}
const goDetail = (id: number) => {
uni.navigateTo({ url: `/packages_community/pages/post_detail?id=${id}` })
}
const goUserProfile = (userId: number) => {
if (!userId) return
uni.navigateTo({ url: `/packages_community/pages/user_profile?user_id=${userId}` })
}
const goPublish = () => {
if (!getToken()) {
uni.showModal({
title: '提示',
content: '发布内容需要登录,是否前往登录?',
confirmText: '去登录',
success: (res) => {
if (res.confirm) {
uni.navigateTo({ url: '/pages/login/login' })
}
}
})
return
}
needRefresh.value = true
uni.navigateTo({ url: '/packages_community/pages/publish' })
}
const checkLogin = () => {
if (!getToken()) {
uni.showModal({
title: '提示',
content: '该操作需要登录,是否前往登录?',
confirmText: '去登录',
success: (res) => {
if (res.confirm) {
uni.navigateTo({ url: '/pages/login/login' })
}
}
})
return false
}
return true
}
const handleUnlock = async (post: any) => {
if (!getToken()) {
uni.showModal({
title: '提示',
content: '解锁内容需要登录,是否前往登录?',
confirmText: '去登录',
success: (res) => {
if (res.confirm) {
uni.navigateTo({ url: '/pages/login/login' })
}
}
})
return
}
try {
const res = await purchasePost({ post_id: post.id, confirm: 0 })
if (res?.content) {
post.is_unlocked = 1
post.content = res.content
post.content_short = res.content
return
}
if (res?.needs_payment) {
uni.showModal({
title: '解锁内容',
content: `确认花费 ${res.cost || post.price_points} 积分解锁此内容?`,
confirmText: '确认解锁',
confirmColor: '#185dff',
success: async (modalRes) => {
if (modalRes.confirm) {
try {
const payRes = await purchasePost({ post_id: post.id, confirm: 1 })
post.is_unlocked = 1
if (payRes?.content) {
post.content = payRes.content
post.content_short = payRes.content
}
needRefresh.value = true
uni.showToast({ title: '解锁成功', icon: 'success' })
} catch (_e) {
// 请求层已自动提示错误信息
}
}
}
})
}
} catch (_e) {
// 请求层已自动提示错误信息
}
}
const handleLike = async (post: any) => {
if (!checkLogin()) return
try {
const res = await toggleLike({ target_id: post.id, target_type: 1 })
const nextLiked = !!res?.is_liked
const currentCount = Number(post.like_count || 0)
post.is_liked = nextLiked
post.like_count = Math.max(0, currentCount + (nextLiked ? 1 : -1))
} catch (_e) {
// 请求层已自动提示错误信息
}
}
// 分享弹窗
const showSharePopup = ref(false)
const sharePostId = ref(0)
const sharePostTitle = ref('')
const handleShare = (post: any) => {
sharePostId.value = post.id
sharePostTitle.value = post.content?.substring(0, 50) || ''
showSharePopup.value = true
}
const handleAiAnalysis = (post: any) => {
const tags = Array.isArray(post?.tags) ? post.tags : []
if (!tags.includes('旧澳六合') && !tags.includes('新澳六合')) {
return
}
const title = encodeURIComponent(String(post?.content || '帖子AI分析').split('\n')[0].trim().slice(0, 28) || '帖子AI分析')
uni.navigateTo({ url: `/pages/ai_analysis/ai_analysis?type=post&id=${post.id}&title=${title}` })
}
</script>
<style lang="scss" scoped>
.community-page {
height: 100vh;
min-height: 0;
display: flex;
flex-direction: column;
background: #fff;
overflow: hidden;
}
.community-header {
background: #fff;
padding: 0 24rpx 16rpx;
flex-shrink: 0;
&__bar {
display: flex;
align-items: center;
gap: 16rpx;
padding-top: 16rpx;
}
&__logo {
width: 68rpx;
height: 68rpx;
border-radius: 12rpx;
flex-shrink: 0;
}
&__search {
flex: 1;
height: 76rpx;
display: flex;
align-items: center;
gap: 12rpx;
padding: 0 24rpx;
background: #f4f5f7;
border-radius: 12rpx;
}
&__search-icon {
font-size: 28rpx;
color: #808080;
line-height: 1;
}
&__search-text {
font-size: 28rpx;
color: #808080;
}
}
.community-tags {
background: #fff;
padding: 0;
margin-bottom: 0;
flex-shrink: 0;
&__scroll {
white-space: nowrap;
display: block;
padding: 16rpx 24rpx 12rpx;
font-size: 0;
line-height: 0;
}
&__item {
display: inline-flex;
align-items: center;
gap: 6rpx;
height: 64rpx;
padding: 0 24rpx;
margin-right: 12rpx;
vertical-align: top;
border-radius: 12rpx;
font-size: 28rpx;
color: #666;
background: #f4f5f7;
&--active {
background: #e5edff;
color: #185dff;
}
}
&__hot {
font-size: 20rpx;
color: #ee3835;
background: #ffe5e5;
padding: 2rpx 6rpx;
border-radius: 6rpx;
margin-left: 2rpx;
line-height: 1;
}
&__item--active &__hot {
color: #ee3835;
background: #ffe5e5;
}
}
.community-list {
flex: 1;
height: 0;
min-height: 0;
box-sizing: border-box;
display: block;
margin-top: 0;
padding-top: 0;
background: #fff;
}
.community-loading {
display: flex;
justify-content: center;
padding: 60rpx 24rpx;
}
.community-empty {
padding: 120rpx 24rpx;
}
.community-loadmore {
.legacy-community-page {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
gap: 12rpx;
padding: 24rpx 0 48rpx;
font-size: 24rpx;
color: #999;
}
.community-fab {
position: fixed;
right: 32rpx;
bottom: 180rpx;
width: 100rpx;
height: 100rpx;
border-radius: 50%;
background: linear-gradient(135deg, #185dff, #ff6b5a);
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 24rpx rgba(229, 77, 66, 0.4);
z-index: 999;
color: #98a2b3;
font-size: 26rpx;
background: #f5f7fb;
}
</style>