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
@@ -1,116 +1,96 @@
<template>
<view class="post-card" @tap="$emit('tap')">
<image class="post-card__avatar" :src="post.user?.avatar || '/static/images/avatar.png'" mode="aspectFill"
@tap.stop="$emit('avatar-tap', post.user_id)" />
<view class="post-card__body">
<view class="post-card__main">
<!-- 头部昵称·时间 + 标签 -->
<view class="post-card__header">
<view class="post-card__user">
<text class="post-card__nickname">{{ post.user?.nickname || '匿名用户' }}</text>
<text class="post-card__dot">·</text>
<text class="post-card__time">{{ formatTime(post.create_time) }}</text>
</view>
<view class="post-card__badges">
<view v-if="post.is_paid" class="post-card__badge post-card__badge--paid">
<text>{{ post.price_points }}积分</text>
</view>
<view v-if="post.is_hot" class="post-card__badge post-card__badge--hot">
<text>热门</text>
</view>
<view v-if="post.is_top" class="post-card__badge post-card__badge--top">
<text>置顶</text>
</view>
</view>
</view>
<view v-if="post.is_paid && !post.is_unlocked" class="post-card__paid-notice">
<u-icon name="lock" size="25" color="#1468f5" />
<text>付费内容 · {{ post.price_points }} 积分</text>
</view>
<!-- 正文内容 -->
<view class="post-card__content">
<text class="post-card__text"
:class="{ 'post-card__text--locked': post.is_paid && !post.is_unlocked }">{{ post.content_short
|| post.content }}</text>
</view>
<view v-if="displayTranslatedText" class="post-card__translate">
<text class="post-card__translate-text">{{ displayTranslatedText }}</text>
</view>
<!-- 付费解锁 -->
<view v-if="post.is_paid && !post.is_unlocked" class="post-card__unlock" @tap.stop="$emit('unlock')">
<text class="post-card__unlock-text">{{ post.price_points }}积分解锁全文</text>
<view class="post-card__unlock-btn">
<text>解锁</text>
</view>
</view>
<!-- 图片 -->
<view v-if="
post.images &&
post.images.length > 0 &&
!(post.is_paid && !post.is_unlocked)
" class="post-card__images" :class="{ 'post-card__images--full': isLotteryPost }">
<template v-if="isLotteryPost">
<image v-for="(img, idx) in post.images" :key="idx" class="post-card__img post-card__img--full"
:src="img" mode="widthFix" @tap.stop="previewImage(idx)" />
</template>
<template v-else-if="trumpSourceUrl">
<view class="post-card__external-cover" @tap.stop="openSourceUrl">
<view class="post-card__external-cover-icon">
<text>T</text>
</view>
<view class="post-card__external-cover-body">
<text class="post-card__external-cover-title">Truth Social 图片暂不可直连</text>
<text class="post-card__external-cover-desc">点击查看原帖</text>
</view>
<view class="post-card__external-cover-btn">
<text>查看原帖</text>
</view>
</view>
</template>
<template v-else>
<image v-for="(img, idx) in post.images.slice(0, 3)" :key="idx" class="post-card__img"
:src="img" mode="aspectFill" @tap.stop="previewImage(idx)" />
<view v-if="post.images.length > 3" class="post-card__img-more" @tap.stop="previewImage(3)">
<text>+{{ post.images.length - 3 }}</text>
</view>
</template>
</view>
<!-- 话题标签 -->
<view v-if="post.tags && post.tags.length > 0" class="post-card__tags">
<view v-for="(t, i) in post.tags" :key="i" class="post-card__tag">
<text>#{{ t }}</text>
</view>
<view class="post-card__header">
<image class="post-card__avatar" :src="post.user?.avatar || '/static/images/avatar.png'" mode="aspectFill"
@tap.stop="$emit('avatar-tap', post.user_id)" />
<view class="post-card__author">
<view class="post-card__identity">
<text class="post-card__nickname">{{ post.user?.nickname || '匿名用户' }}</text>
<text v-if="post.is_top" class="post-card__pin">置顶</text>
</view>
<text class="post-card__time">{{ formatTime(post.create_time) }}</text>
</view>
<view class="post-card__status">
<text v-if="!post.is_paid || post.is_unlocked" class="post-card__free">免费</text>
<text v-else class="post-card__price">{{ post.price_points }} 积分</text>
<u-icon name="more-dot-fill" size="30" color="#8d96a3" />
</view>
</view>
<!-- 操作栏 -->
<view class="post-card__actions">
<view class="post-card__action" @tap.stop="$emit('view')">
<text class="post-card__action-icon">👁</text>
<text class="post-card__action-num">{{ formatCount(post.view_count) }}</text>
<view class="post-card__content">
<text v-if="contentTitle" class="post-card__title">{{ contentTitle }}</text>
<text class="post-card__summary" :class="{ 'post-card__summary--locked': post.is_paid && !post.is_unlocked }">
{{ contentSummary }}
</text>
</view>
<view v-if="displayTranslatedText" class="post-card__translation">
<text>AI 翻译</text>
<text class="post-card__translation-text">{{ displayTranslatedText }}</text>
</view>
<view v-if="post.is_paid && !post.is_unlocked" class="post-card__unlock" @tap.stop="$emit('unlock')">
<view>
<text class="post-card__unlock-title">深度内容待解锁</text>
<text class="post-card__unlock-desc">解锁后阅读完整分析与讨论</text>
</view>
<view class="post-card__unlock-btn">查看详情</view>
</view>
<view v-if="post.images?.length && !(post.is_paid && !post.is_unlocked)" class="post-card__images"
:class="{ 'post-card__images--full': isLotteryPost }">
<template v-if="isLotteryPost">
<image v-for="(image, index) in post.images" :key="index" class="post-card__image post-card__image--full"
:src="image" mode="widthFix" @tap.stop="previewImage(index)" />
</template>
<template v-else-if="trumpSourceUrl">
<view class="post-card__external-cover" @tap.stop="openSourceUrl">
<view class="post-card__external-cover-icon">T</view>
<view class="post-card__external-cover-copy">
<text>Truth Social 图片暂不可直连</text>
<text>点击查看原帖</text>
</view>
<u-icon name="arrow-right" size="26" color="#ffffff" />
</view>
<view class="post-card__action" @tap.stop="$emit('comment')">
<text class="post-card__action-icon">💬</text>
<text class="post-card__action-num">{{ formatCount(post.comment_count) }}</text>
</view>
<view class="post-card__action" :class="{ 'post-card__action--active': post.is_liked }"
@tap.stop="$emit('like')">
<text class="post-card__action-icon">👍</text>
<text class="post-card__action-num">{{ formatCount(post.like_count) }}</text>
</view>
<view v-if="isLiuhePost" class="post-card__action"
:class="{ 'post-card__action--loading': post._ai_loading }" @tap.stop="handleAiAnalysis">
<text class="post-card__action-icon">🤖</text>
<text class="post-card__action-num">{{
post._ai_loading ? '…' : (aiAnalyzed ? '已分析' : 'AI')
}}</text>
</view>
<view class="post-card__action" @tap.stop="handleShareTap">
<text class="post-card__action-icon">↗</text>
<text class="post-card__action-num">{{ post.share_count ? formatCount(post.share_count) : ''
}}</text>
</template>
<template v-else>
<image v-for="(image, index) in post.images.slice(0, 3)" :key="index" class="post-card__image"
:src="image" mode="aspectFill" @tap.stop="previewImage(index)" />
<view v-if="post.images.length > 3" class="post-card__image-more" @tap.stop="previewImage(3)">
<text>+{{ post.images.length - 3 }}</text>
</view>
</template>
</view>
<view v-if="post.tags?.length" class="post-card__tags">
<view v-for="(tag, index) in post.tags" :key="index" class="post-card__tag">{{ tag }}</view>
</view>
<view class="post-card__actions">
<view class="post-card__action" @tap.stop="$emit('tap')">
<u-icon name="eye" size="31" color="#7a8494" />
<text>{{ formatCount(post.view_count) }}</text>
</view>
<view class="post-card__action" @tap.stop="$emit('tap')">
<u-icon name="chat" size="30" color="#7a8494" />
<text>{{ formatCount(post.comment_count) }}</text>
</view>
<view class="post-card__action" :class="{ 'post-card__action--active': post.is_liked }" @tap.stop="$emit('like')">
<u-icon :name="post.is_liked ? 'thumb-up-fill' : 'thumb-up'" size="31" :color="post.is_liked ? '#1468f5' : '#7a8494'" />
<text>{{ formatCount(post.like_count) }}</text>
</view>
<view v-if="isLiuhePost" class="post-card__action" :class="{ 'post-card__action--loading': post._ai_loading }"
@tap.stop="handleAiAnalysis">
<text class="post-card__ai-icon">AI</text>
<text>{{ post._ai_loading ? '分析中' : (aiAnalyzed ? '已分析' : 'AI 分析') }}</text>
</view>
<view class="post-card__action post-card__action--share" @tap.stop="handleShareTap">
<u-icon name="share" size="31" color="#7a8494" />
</view>
</view>
@@ -126,68 +106,53 @@ import { translatePost } from '@/api/community'
import { getToken } from '@/utils/auth'
import SharePopup from '@/components/share-popup/share-popup.vue'
const props = defineProps<{
post: any
}>()
const emit = defineEmits(['tap', 'unlock', 'view', 'comment', 'like', 'avatar-tap', 'ai-analysis'])
const props = defineProps<{ post: any }>()
const emit = defineEmits(['tap', 'unlock', 'like', 'avatar-tap', 'ai-analysis'])
const showSharePopup = ref(false)
const handleShareTap = () => {
showSharePopup.value = true
}
const LIUHE_TAGS = ['旧澳六合', '新澳六合']
const translatedText = ref('')
const cachedContent = ref(props.post.translated_content || '')
const isLotteryPost = computed(
() => Array.isArray(props.post?.tags) && props.post.tags.includes('彩票')
)
const isLiuhePost = computed(() => {
const tags = Array.isArray(props.post?.tags) ? props.post.tags : []
return LIUHE_TAGS.some((tag) => tags.includes(tag))
const autoTranslateStarted = ref(false)
const LIUHE_TAGS = ['旧澳六合', '新澳六合']
const rawContent = computed(() => String(props.post?.content_short || props.post?.content || '').trim())
const contentParts = computed(() => {
const lines = rawContent.value.split('\n').map((line) => line.trim()).filter(Boolean)
const firstLine = lines[0] || ''
if (lines.length > 1 && firstLine.length <= 58) {
return { title: firstLine, summary: lines.slice(1).join('\n') }
}
return { title: '', summary: rawContent.value }
})
const isTrumpPost = computed(
() => Array.isArray(props.post?.tags) && props.post.tags.includes('特朗普')
)
const contentTitle = computed(() => contentParts.value.title)
const contentSummary = computed(() => contentParts.value.summary)
const isLotteryPost = computed(() => Array.isArray(props.post?.tags) && props.post.tags.includes('彩票'))
const isLiuhePost = computed(() => LIUHE_TAGS.some((tag) => props.post?.tags?.includes(tag)))
const isTrumpPost = computed(() => Array.isArray(props.post?.tags) && props.post.tags.includes('特朗普'))
const trumpSourceUrl = computed(() => {
if (props.post?.source_url) return props.post.source_url
const originId = props.post?.origin_id || ''
if (!originId.startsWith('truthsocial:')) return ''
const postId = originId.split(':')[1]
if (!postId) return ''
return `https://truthsocial.com/@realDonaldTrump/${postId}`
return postId ? `https://truthsocial.com/@realDonaldTrump/${postId}` : ''
})
const displayTranslatedText = computed(() => translatedText.value || cachedContent.value || props.post?.translated_content || '')
const autoTranslateStarted = ref(false)
const aiAnalyzed = computed(() => !!displayTranslatedText.value)
const openSourceUrl = () => {
if (!trumpSourceUrl.value) return
uni.navigateTo({
url: `/pages/webview/webview?url=${encodeURIComponent(trumpSourceUrl.value)}`
})
}
const handleShareTap = () => { showSharePopup.value = true }
const openSourceUrl = () => trumpSourceUrl.value && uni.navigateTo({ url: `/pages/webview/webview?url=${encodeURIComponent(trumpSourceUrl.value)}` })
const previewImage = (index: number) => {
const images = props.post?.images || []
if (!images.length) return
uni.previewImage({
urls: images,
current: images[index] || images[0],
})
if (images.length) uni.previewImage({ urls: images, current: images[index] || images[0] })
}
const requestTranslate = async () => {
try {
const res = await translatePost({ post_id: props.post.id })
if (res?.translated_content) {
cachedContent.value = res.translated_content
translatedText.value = res.translated_content
return
const result = await translatePost({ post_id: props.post.id })
if (result?.translated_content) {
cachedContent.value = result.translated_content
translatedText.value = result.translated_content
}
} catch (e: any) {
}
} catch (_error) { }
}
const handleAiAnalysis = () => {
@@ -199,384 +164,332 @@ const handleAiAnalysis = () => {
emit('ai-analysis', props.post)
}
watch(
() => props.post?.translated_content,
(value) => {
if (value) {
cachedContent.value = value
translatedText.value = value
}
},
{ immediate: true }
)
watch(
() => props.post?.id,
async () => {
autoTranslateStarted.value = false
cachedContent.value = props.post?.translated_content || ''
translatedText.value = props.post?.translated_content || ''
if (!isTrumpPost.value || cachedContent.value || autoTranslateStarted.value || !props.post?.content) return
autoTranslateStarted.value = true
if (getToken()) {
await requestTranslate()
}
},
{ immediate: true }
)
const formatTime = (ts: any) => {
if (!ts) return ''
let timestamp: number
if (typeof ts === 'string') {
timestamp = new Date(ts.replace(/-/g, '/')).getTime() / 1000
} else {
timestamp = ts
watch(() => props.post?.translated_content, (value) => {
if (value) {
cachedContent.value = value
translatedText.value = value
}
if (isNaN(timestamp)) return ''
const now = Date.now() / 1000
const diff = now - timestamp
if (diff < 60) return '刚刚'
if (diff < 3600) return Math.floor(diff / 60) + '分钟前'
if (diff < 86400) return Math.floor(diff / 3600) + '小时前'
if (diff < 2592000) return Math.floor(diff / 86400) + '天前'
const d = new Date(timestamp * 1000)
return `${d.getMonth() + 1}-${d.getDate()}`
}, { immediate: true })
watch(() => props.post?.id, async () => {
autoTranslateStarted.value = false
cachedContent.value = props.post?.translated_content || ''
translatedText.value = props.post?.translated_content || ''
if (!isTrumpPost.value || cachedContent.value || autoTranslateStarted.value || !props.post?.content) return
autoTranslateStarted.value = true
if (getToken()) await requestTranslate()
}, { immediate: true })
const formatTime = (value: any) => {
if (!value) return ''
const timestamp = typeof value === 'string' ? new Date(value.replace(/-/g, '/')).getTime() / 1000 : Number(value)
if (Number.isNaN(timestamp)) return ''
const seconds = Date.now() / 1000 - timestamp
if (seconds < 60) return '刚刚发布'
if (seconds < 3600) return `${Math.floor(seconds / 60)} 分钟前`
if (seconds < 86400) return `${Math.floor(seconds / 3600)} 小时前`
if (seconds < 2592000) return `${Math.floor(seconds / 86400)} 天前`
const date = new Date(timestamp * 1000)
return `${date.getMonth() + 1}-${date.getDate()}`
}
const formatCount = (count: any) => {
if (!count) return '0'
const n = Number(count)
if (n >= 10000) return (n / 10000).toFixed(1) + 'w'
if (n >= 1000) return (n / 1000).toFixed(1) + 'k'
return String(n)
const formatCount = (value: any) => {
const count = Number(value || 0)
if (count >= 10000) return `${(count / 10000).toFixed(1)}`
if (count >= 1000) return `${(count / 1000).toFixed(1)}k`
return String(count)
}
</script>
<style lang="scss" scoped>
.post-card {
display: flex;
gap: 20rpx;
padding: 28rpx;
position: relative;
margin: 0 26rpx 18rpx;
padding: 26rpx 26rpx 22rpx;
border: 1rpx solid rgba(225, 231, 240, 0.86);
border-radius: 24rpx;
background: #fff;
border-radius: 16rpx;
margin: 0 24rpx 16rpx;
box-shadow: 0 8rpx 24rpx rgba(31, 54, 89, 0.055);
box-sizing: border-box;
&__avatar {
width: 84rpx;
height: 84rpx;
border-radius: 12rpx;
flex-shrink: 0;
}
&__body {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 10rpx;
}
&__main {
display: flex;
flex-direction: column;
gap: 16rpx;
&__paid-notice {
display: inline-flex;
align-items: center;
gap: 8rpx;
margin: -2rpx 0 20rpx;
color: #1468f5;
font-size: 24rpx;
font-weight: 600;
}
&__header {
display: flex;
align-items: center;
justify-content: space-between;
}
&__user {
display: flex;
align-items: center;
gap: 0;
min-width: 0;
}
&__nickname {
font-size: 28rpx;
font-weight: 600;
color: #000;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&__avatar {
width: 78rpx;
height: 78rpx;
margin-right: 16rpx;
border-radius: 50%;
flex-shrink: 0;
background: #eef2f8;
}
&__dot {
font-size: 24rpx;
color: #666;
margin: 0 8rpx;
flex-shrink: 0;
&__author {
flex: 1;
min-width: 0;
}
&__identity,
&__status {
display: flex;
align-items: center;
}
&__identity { gap: 10rpx; }
&__nickname {
max-width: 250rpx;
overflow: hidden;
color: #202a3b;
font-size: 29rpx;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
&__pin,
&__free,
&__price {
padding: 4rpx 12rpx;
border-radius: 8rpx;
color: #1468f5;
font-size: 20rpx;
font-weight: 600;
background: #edf4ff;
}
&__time {
font-size: 24rpx;
color: #666;
white-space: nowrap;
display: block;
margin-top: 5rpx;
color: #9099a8;
font-size: 23rpx;
}
&__status {
gap: 15rpx;
margin-left: 14rpx;
flex-shrink: 0;
}
&__badges {
display: flex;
align-items: center;
gap: 8rpx;
flex-shrink: 0;
margin-left: 12rpx;
}
&__badge {
padding: 2rpx 10rpx;
border-radius: 6rpx;
font-size: 22rpx;
line-height: 1.2;
&--paid {
background: #e5edff;
text {
color: #185dff;
}
}
&--hot {
background: #ffe5e5;
text {
color: #ee3835;
}
}
&--top {
background: #e5edff;
text {
color: #185dff;
}
}
}
&__price { color: #7653d6; background: #f1edff; }
&__content {
line-height: 1.7;
display: flex;
flex-direction: column;
gap: 10rpx;
padding: 24rpx 0 0;
}
&__text {
font-size: 26rpx;
color: #000;
word-break: break-word;
display: -webkit-box;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
overflow: hidden;
&__title {
color: #172033;
font-size: 34rpx;
font-weight: 700;
line-height: 1.38;
}
&--locked {
-webkit-line-clamp: 2;
}
&__summary {
display: -webkit-box;
overflow: hidden;
color: #566173;
font-size: 28rpx;
line-height: 1.62;
white-space: pre-wrap;
word-break: break-word;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
&--locked { -webkit-line-clamp: 2; }
}
&__translation {
display: flex;
flex-direction: column;
gap: 8rpx;
margin-top: 16rpx;
padding: 16rpx 18rpx;
border-left: 4rpx solid #94bbff;
border-radius: 0 12rpx 12rpx 0;
background: #f5f8ff;
> text:first-child { color: #1468f5; font-size: 21rpx; font-weight: 700; }
}
&__translation-text {
display: -webkit-box;
overflow: hidden;
color: #59667a;
font-size: 25rpx;
line-height: 1.55;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
&__unlock {
display: flex;
align-items: center;
justify-content: space-between;
height: 120rpx;
padding: 0 24rpx;
background: #e5edff;
border-radius: 12rpx;
gap: 18rpx;
margin-top: 20rpx;
padding: 20rpx 22rpx;
border-radius: 16rpx;
background: linear-gradient(108deg, #f1f6ff, #f9fbff);
}
&__unlock-text {
font-size: 28rpx;
color: #185dff;
}
&__unlock-title { display: block; color: #1e4b9c; font-size: 27rpx; font-weight: 700; }
&__unlock-desc { display: block; margin-top: 5rpx; color: #7283a0; font-size: 22rpx; }
&__unlock-btn {
min-width: 142rpx;
height: 56rpx;
padding: 0 24rpx;
display: flex;
align-items: center;
justify-content: center;
background: #185dff;
border-radius: 12rpx;
text {
font-size: 28rpx;
color: #fff;
}
border: 2rpx solid #1468f5;
border-radius: 999rpx;
color: #1468f5;
font-size: 24rpx;
font-weight: 600;
box-sizing: border-box;
flex-shrink: 0;
}
&__images {
display: flex;
gap: 12rpx;
position: relative;
display: flex;
gap: 10rpx;
margin-top: 20rpx;
overflow: hidden;
border-radius: 16rpx;
&--full {
display: block;
}
&--full { display: block; }
}
&__img {
flex: 1;
height: 210rpx;
border-radius: 12rpx;
min-width: 0;
&__image {
width: calc((100% - 20rpx) / 3);
height: 184rpx;
border-radius: 14rpx;
background: #eef2f8;
&--full {
display: block;
width: 100%;
height: auto;
margin-bottom: 12rpx;
margin-bottom: 10rpx;
}
}
&__img-more {
&__image-more {
position: absolute;
right: 0;
top: 0;
width: 33.33%;
height: 210rpx;
border-radius: 12rpx;
background: rgba(0, 0, 0, 0.4);
width: calc((100% - 20rpx) / 3);
height: 184rpx;
display: flex;
align-items: center;
justify-content: center;
text {
font-size: 32rpx;
color: #fff;
font-weight: 600;
}
border-radius: 14rpx;
color: #fff;
font-size: 31rpx;
font-weight: 700;
background: rgba(18, 29, 48, 0.58);
}
&__external-cover {
width: 100%;
min-height: 210rpx;
border-radius: 12rpx;
padding: 24rpx;
background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
min-height: 176rpx;
display: flex;
align-items: center;
gap: 20rpx;
gap: 18rpx;
padding: 22rpx;
color: #fff;
background: linear-gradient(135deg, #172033, #34425a);
box-sizing: border-box;
}
&__external-cover-icon {
width: 76rpx;
height: 76rpx;
border-radius: 20rpx;
background: rgba(255, 255, 255, 0.12);
width: 64rpx;
height: 64rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
text {
font-size: 40rpx;
color: #fff;
font-weight: 700;
}
border-radius: 18rpx;
font-size: 33rpx;
font-weight: 700;
background: rgba(255, 255, 255, 0.16);
}
&__external-cover-body {
&__external-cover-copy {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 8rpx;
}
&__external-cover-title {
font-size: 28rpx;
color: #fff;
font-weight: 600;
}
&__external-cover-desc {
font-size: 24rpx;
color: rgba(255, 255, 255, 0.72);
}
&__external-cover-btn {
height: 60rpx;
padding: 0 20rpx;
border-radius: 999rpx;
background: #185dff;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
text {
font-size: 24rpx;
color: #fff;
font-weight: 600;
}
}
&__translate {
margin-top: 10rpx;
padding-left: 4rpx;
&-text {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
font-size: 28rpx;
color: #3f4a5a;
line-height: 1.75;
word-break: break-word;
white-space: pre-wrap;
}
text:first-child { font-size: 26rpx; font-weight: 600; }
text:last-child { color: rgba(255, 255, 255, 0.7); font-size: 22rpx; }
}
&__tags {
display: flex;
flex-wrap: wrap;
gap: 10rpx;
margin-top: 18rpx;
}
&__tag {
padding: 2rpx 10rpx;
border-radius: 6rpx;
background: #e5edff;
text {
font-size: 22rpx;
color: #185dff;
}
padding: 5rpx 13rpx;
border-radius: 8rpx;
color: #1468f5;
font-size: 22rpx;
background: #edf4ff;
}
&__actions {
display: flex;
align-items: center;
gap: 40rpx;
gap: 42rpx;
margin-top: 22rpx;
padding-top: 18rpx;
border-top: 1rpx solid #edf0f4;
}
&__action {
display: flex;
align-items: center;
gap: 6rpx;
&--active {
.post-card__action-icon,
.post-card__action-num {
color: #185dff;
}
}
}
&__action-icon {
font-size: 28rpx;
color: #262626;
line-height: 1;
}
&__action-num {
gap: 7rpx;
color: #7a8494;
font-size: 24rpx;
color: #262626;
line-height: 1;
&--active { color: #1468f5; }
&--share { margin-left: auto; }
&--loading { opacity: 0.6; }
}
&__ai-icon {
width: 29rpx;
height: 29rpx;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 8rpx;
color: #fff;
font-size: 17rpx;
font-weight: 800;
background: #1468f5;
}
}
</style>
+11 -479
View File
@@ -1,493 +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>
</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 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>
@@ -112,7 +112,7 @@ const handleCancel = () => {
if (pages.length > 1) {
uni.navigateBack()
} else {
uni.switchTab({ url: '/pages/empty/empty' })
uni.switchTab({ url: '/pages/community/community' })
}
}
@@ -159,7 +159,7 @@ const handlePublish = async () => {
if (pages.length > 1) {
uni.navigateBack()
} else {
uni.switchTab({ url: '/pages/empty/empty' })
uni.switchTab({ url: '/pages/community/community' })
}
}, 1200)
} catch (e) {