425 行
9.7 KiB
Vue
425 行
9.7 KiB
Vue
<template>
|
||
<view class="user-detail fc-page">
|
||
<!-- 统一沉浸式深绿质感导航栏 -->
|
||
<fc-navbar :title="pageTitle" theme="gradient" :show-back="true" />
|
||
|
||
<!-- 骨架屏占位态 -->
|
||
<view v-if="loading && !loaded" class="user-detail__skeleton">
|
||
<view class="fc-card user-detail__skeleton-hero">
|
||
<view class="fc-skeleton user-detail__sk-avatar"></view>
|
||
<view class="user-detail__sk-meta">
|
||
<view class="fc-skeleton" style="width: 220rpx; height: 36rpx;"></view>
|
||
<view class="fc-skeleton" style="width: 160rpx; height: 26rpx; margin-top: 16rpx;"></view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 真实内容视图 -->
|
||
<view v-else class="user-detail__body">
|
||
<!-- 1. 个人形象主卡片 -->
|
||
<view class="fc-card user-detail__hero-card">
|
||
<view class="user-detail__hero-top">
|
||
<image
|
||
v-if="user.avatar"
|
||
class="user-detail__avatar user-detail__avatar--img"
|
||
:src="assetUrl(user.avatar)"
|
||
mode="aspectFill"
|
||
/>
|
||
<view v-else class="user-detail__avatar user-detail__avatar--char">
|
||
{{ (user.nickname || '同').slice(0, 1) }}
|
||
</view>
|
||
|
||
<view class="user-detail__hero-info">
|
||
<view class="user-detail__title-row">
|
||
<text class="user-detail__name">{{ user.nickname || '同城用户' }}</text>
|
||
<text v-if="user.isMerchant" class="user-detail__tag user-detail__tag--merchant">
|
||
认证商家
|
||
</text>
|
||
<text v-else class="user-detail__tag user-detail__tag--person">个人实名</text>
|
||
</view>
|
||
<text class="user-detail__sub">
|
||
{{ user.createdAt ? user.createdAt.slice(0, 10) : '近期' }} 加入同城平台
|
||
</text>
|
||
</view>
|
||
|
||
<!-- 关注按钮(非本人展示) -->
|
||
<view
|
||
v-if="!user.isSelf"
|
||
class="user-detail__follow-btn"
|
||
:class="{ 'user-detail__follow-btn--active': user.followed }"
|
||
@click="toggleFollow"
|
||
>
|
||
<text>{{ user.followed ? '已关注' : '+ 关注' }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 商家认证关联提示(若该用户也是认证商家,可一键跳转商家门店主页) -->
|
||
<view v-if="user.isMerchant && user.merchantId" class="user-detail__merchant-banner" @click="goMerchantShop">
|
||
<view class="user-detail__mb-left">
|
||
<image class="fc-icon fc-icon--sm" :src="iconUrl('shield')" mode="aspectFit" />
|
||
<text class="user-detail__mb-txt">该用户已开通官方认证门店:{{ user.merchantName || '点击查看' }}</text>
|
||
</view>
|
||
<text class="user-detail__mb-link">进店逛逛 ›</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 2. TA 发布的同城信息列表 -->
|
||
<view class="user-detail__posts-wrap">
|
||
<view class="user-detail__posts-head">
|
||
<text class="user-detail__section-title">TA 的全部发布 ({{ postTotal }})</text>
|
||
</view>
|
||
|
||
<!-- 列表 -->
|
||
<view v-if="posts && posts.length" class="user-detail__posts-list">
|
||
<fc-post-card
|
||
v-for="p in posts"
|
||
:key="p.id"
|
||
:post="p"
|
||
@click="goPostDetail(p)"
|
||
/>
|
||
|
||
<view class="user-detail__more">
|
||
<text v-if="loadingMore">加载中…</text>
|
||
<text v-else-if="!hasMore">— 已经到底了 —</text>
|
||
<text v-else @click="loadMore">点击加载更多</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 空状态 -->
|
||
<fc-empty v-else text="该用户暂未发布其他信息" />
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
/**
|
||
* 用户个人公开档案与信息主页
|
||
* 展示普通用户的个人信息、历史发帖列表,支持关注/取消关注及查看发帖详情
|
||
*/
|
||
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
|
||
import FcPostCard from '@/components/fc-post-card/fc-post-card.vue'
|
||
import FcEmpty from '@/components/fc-empty/fc-empty.vue'
|
||
import userApi from '@/common/api/user.js'
|
||
import favoriteApi from '@/common/api/favorite.js'
|
||
import { iconUrl, loadUiConfig } from '@/common/store/ui.js'
|
||
import { assetUrl } from '@/common/utils/format.js'
|
||
|
||
export default {
|
||
components: { FcNavbar, FcPostCard, FcEmpty },
|
||
data() {
|
||
return {
|
||
userId: 0,
|
||
loading: true,
|
||
loaded: false,
|
||
user: {},
|
||
posts: [],
|
||
page: 1,
|
||
size: 10,
|
||
postTotal: 0,
|
||
hasMore: false,
|
||
loadingMore: false,
|
||
}
|
||
},
|
||
computed: {
|
||
/**
|
||
* 页面顶部导航栏标题
|
||
* @returns {string}
|
||
*/
|
||
pageTitle() {
|
||
return (this.user && this.user.nickname) ? `${this.user.nickname}的个人主页` : '个人主页'
|
||
},
|
||
},
|
||
onLoad(query) {
|
||
this.userId = Number(query.id || query.userId || 0)
|
||
loadUiConfig()
|
||
this.loadDetail()
|
||
},
|
||
onPullDownRefresh() {
|
||
this.loadDetail(true).finally(() => {
|
||
uni.stopPullDownRefresh()
|
||
})
|
||
},
|
||
onReachBottom() {
|
||
this.loadMore()
|
||
},
|
||
methods: {
|
||
iconUrl,
|
||
assetUrl,
|
||
/**
|
||
* 加载用户主档案及首屏发帖
|
||
* @param {boolean} refresh 是否下拉刷新重载
|
||
*/
|
||
async loadDetail(refresh = false) {
|
||
if (!this.userId) {
|
||
uni.showToast({ title: '参数错误', icon: 'none' })
|
||
return
|
||
}
|
||
if (!refresh) this.loading = true
|
||
try {
|
||
const data = await userApi.detail(this.userId)
|
||
if (data) {
|
||
this.user = data
|
||
this.posts = Array.isArray(data.posts) ? data.posts : []
|
||
this.postTotal = data.postCount || this.posts.length
|
||
this.hasMore = !!data.hasMorePosts
|
||
this.page = 1
|
||
this.loaded = true
|
||
}
|
||
} catch (e) {
|
||
uni.showToast({ title: (e && e.message) || '用户主页加载失败', icon: 'none' })
|
||
} finally {
|
||
this.loading = false
|
||
}
|
||
},
|
||
/**
|
||
* 分页加载更多 TA 发布的信息
|
||
*/
|
||
async loadMore() {
|
||
if (!this.hasMore || this.loadingMore) return
|
||
this.loadingMore = true
|
||
try {
|
||
const nextPage = this.page + 1
|
||
const res = await userApi.posts(this.userId, {
|
||
page: nextPage,
|
||
size: this.size,
|
||
})
|
||
if (res && Array.isArray(res.list)) {
|
||
this.posts = this.posts.concat(res.list)
|
||
this.page = nextPage
|
||
this.hasMore = !!res.hasMore
|
||
if (res.total != null) this.postTotal = res.total
|
||
}
|
||
} catch (e) {
|
||
uni.showToast({ title: '加载更多失败', icon: 'none' })
|
||
} finally {
|
||
this.loadingMore = false
|
||
}
|
||
},
|
||
/**
|
||
* 关注 / 取消关注
|
||
*/
|
||
async toggleFollow() {
|
||
const prev = this.user.followed
|
||
this.user.followed = !prev
|
||
try {
|
||
const res = await favoriteApi.follow({ userId: this.userId })
|
||
this.user.followed = !!(res && res.followed)
|
||
uni.showToast({ title: this.user.followed ? '已关注' : '已取消关注', icon: 'none' })
|
||
} catch (e) {
|
||
this.user.followed = prev
|
||
uni.showToast({ title: (e && e.message) || '操作失败', icon: 'none' })
|
||
}
|
||
},
|
||
/**
|
||
* 若是认证商家,跳转其门店主页
|
||
*/
|
||
goMerchantShop() {
|
||
if (!this.user.merchantId) return
|
||
uni.navigateTo({
|
||
url: `/pages/merchant/detail?id=${this.user.merchantId}`,
|
||
})
|
||
},
|
||
/**
|
||
* 跳转到帖子详情
|
||
* @param {Object} p 帖子项
|
||
*/
|
||
goPostDetail(p) {
|
||
if (!p || !p.id) return
|
||
uni.navigateTo({
|
||
url: `/pages/detail/detail?id=${p.id}`,
|
||
})
|
||
},
|
||
},
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.user-detail {
|
||
min-height: 100vh;
|
||
background: $fc-bg;
|
||
padding-bottom: 50rpx;
|
||
}
|
||
|
||
.user-detail__body {
|
||
padding: 16rpx 20rpx 40rpx;
|
||
}
|
||
|
||
.user-detail__hero-card {
|
||
padding: 30rpx 24rpx;
|
||
margin: 16rpx 4rpx;
|
||
border-radius: $fc-radius-lg;
|
||
background: #ffffff;
|
||
border: 1rpx solid #e2f4ea;
|
||
box-shadow: 0 4rpx 20rpx rgba(4, 48, 30, 0.04);
|
||
}
|
||
|
||
.user-detail__hero-top {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.user-detail__avatar {
|
||
width: 110rpx;
|
||
height: 110rpx;
|
||
border-radius: 50%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
|
||
&--img {
|
||
background: #f0f0f0;
|
||
}
|
||
|
||
&--char {
|
||
background: linear-gradient(135deg, #00e070 0%, #00b85c 100%);
|
||
color: #04301e;
|
||
font-size: 42rpx;
|
||
font-weight: 700;
|
||
}
|
||
}
|
||
|
||
.user-detail__hero-info {
|
||
flex: 1;
|
||
min-width: 0;
|
||
margin-left: 20rpx;
|
||
}
|
||
|
||
.user-detail__title-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.user-detail__name {
|
||
font-size: 34rpx;
|
||
font-weight: 700;
|
||
color: #04291c;
|
||
}
|
||
|
||
.user-detail__tag {
|
||
font-size: 20rpx;
|
||
padding: 2rpx 12rpx;
|
||
border-radius: 6rpx;
|
||
font-weight: 600;
|
||
|
||
&--merchant {
|
||
background: #e6f9ef;
|
||
color: #04874a;
|
||
}
|
||
|
||
&--person {
|
||
background: #edf6f1;
|
||
color: #436b56;
|
||
}
|
||
}
|
||
|
||
.user-detail__sub {
|
||
display: block;
|
||
font-size: 24rpx;
|
||
color: #64748b;
|
||
margin-top: 10rpx;
|
||
}
|
||
|
||
.user-detail__follow-btn {
|
||
padding: 12rpx 32rpx;
|
||
border-radius: 36rpx;
|
||
font-size: 26rpx;
|
||
font-weight: 700;
|
||
background: #edfbf3;
|
||
color: #04874a;
|
||
border: 1rpx solid #b7edd4;
|
||
flex-shrink: 0;
|
||
cursor: pointer;
|
||
transition: all 0.2s ease;
|
||
|
||
&--active {
|
||
background: #f8faf8;
|
||
color: #94a3b8;
|
||
border-color: #e2e8f0;
|
||
}
|
||
}
|
||
|
||
.user-detail__merchant-banner {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
background: #f6fdf9;
|
||
border-radius: 14rpx;
|
||
padding: 16rpx 20rpx;
|
||
margin-top: 24rpx;
|
||
border: 1rpx solid #d4f5e2;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.user-detail__mb-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10rpx;
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.user-detail__mb-txt {
|
||
font-size: 24rpx;
|
||
color: #04874a;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.user-detail__mb-link {
|
||
font-size: 24rpx;
|
||
color: #04874a;
|
||
font-weight: 700;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
/* 列表区 */
|
||
.user-detail__posts-wrap {
|
||
margin-top: 24rpx;
|
||
}
|
||
|
||
.user-detail__posts-head {
|
||
padding: 10rpx 8rpx 16rpx;
|
||
}
|
||
|
||
.user-detail__section-title {
|
||
font-size: 30rpx;
|
||
font-weight: 700;
|
||
color: #04291c;
|
||
}
|
||
|
||
.user-detail__posts-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 16rpx;
|
||
}
|
||
|
||
.user-detail__more {
|
||
text-align: center;
|
||
font-size: 24rpx;
|
||
color: #94a3b8;
|
||
padding: 24rpx 0;
|
||
}
|
||
|
||
/* 骨架屏 */
|
||
.user-detail__skeleton {
|
||
padding: 16rpx 20rpx;
|
||
}
|
||
.user-detail__skeleton-hero {
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 30rpx 24rpx;
|
||
margin: 16rpx 4rpx;
|
||
}
|
||
.user-detail__sk-avatar {
|
||
width: 110rpx;
|
||
height: 110rpx;
|
||
border-radius: 50%;
|
||
}
|
||
.user-detail__sk-meta {
|
||
margin-left: 20rpx;
|
||
flex: 1;
|
||
}
|
||
</style>
|