fix:bug

This commit is contained in:
2026-09-13 23:32:35 +08:00
parent 323f520d7b
commit 1a11816839
14 changed files with 701 additions and 46 deletions
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar",
"empty-state": "/components/empty-state/empty-state"
}
}
@@ -0,0 +1,159 @@
import { request, AUTH_EXPIRED_CODES } from '../../utils/request'
import { OutfitShareDetail, OutfitItem } from '../../types/models'
import { ShareStatus } from '../../utils/config'
import { logger } from '../../utils/logger'
// 日志模块名
const LOG = 'outfit-share-detail'
Page({
data: {
uuid: '',
detail: null as OutfitShareDetail | null,
outfit: { items: [] } as OutfitItem,
loading: true,
invalid: false,
invalidTitle: '该分享已取消',
invalidDesc: '分享链接已失效',
needLogin: false,
},
onLoad(query: Record<string, string>) {
const uuid = query.uuid || ''
logger.debug(LOG, 'onLoad, uuid=', uuid)
this.setData({ uuid })
if (!uuid) {
// uuid 缺失时若不兜底,loading 会永久为 true,页面白屏且无法退出
logger.warn(LOG, 'onLoad 缺少 uuid 参数')
this.setInvalid('链接不完整', '缺少分享标识,无法打开')
return
}
this.fetchDetail()
},
fetchDetail() {
request<OutfitShareDetail>({ url: `/outfit-share/${this.data.uuid}`, showError: false })
.then((detail) => {
logger.debug(LOG, '详情加载成功, status=', detail && detail.status)
if (this.checkInvalid(detail)) return
this.setData({ detail, outfit: detail.outfit, loading: false })
})
.catch((e: any) => {
const code = e && e.code
logger.warn(LOG, '详情加载失败, code=', code)
if (AUTH_EXPIRED_CODES.indexOf(code) >= 0) {
// 查看分享需登录:给「去登录」出口,登录成功后回到本页
this.setData({
loading: false,
invalid: true,
needLogin: true,
invalidTitle: '请先登录',
invalidDesc: '登录后即可查看好友分享的穿搭',
})
return
}
if (code === 90104) {
this.setInvalid('分享已取消', '该分享已被创建者取消')
} else if (code === 90103) {
this.setInvalid('分享已失效', '该分享链接无效或对应穿搭已不可见')
} else {
// 兜底:任何未知错误都不能停在空白页
this.setInvalid('加载失败', '请稍后重试')
}
})
},
// 本地状态校验,返回 true 表示已置为失效态
checkInvalid(detail: OutfitShareDetail): boolean {
if (detail.status === ShareStatus.CANCELLED) {
this.setInvalid('分享已取消', '该分享已被创建者取消')
return true
}
return false
},
setInvalid(title: string, desc: string) {
this.setData({
loading: false,
invalid: true,
needLogin: false,
invalidTitle: title,
invalidDesc: desc,
})
},
onItemTap(e: WechatMiniprogram.TouchEvent) {
const uuid = e.currentTarget.dataset.uuid as string
// 只读查看:携带 share_uuid,后端据此放行非属主读取衣物详情
logger.debug(LOG, '点击衣物, uuid=', uuid)
wx.navigateTo({
url: `/pages/clothes-detail/clothes-detail?uuid=${uuid}&share_uuid=${this.data.uuid}`,
fail: (err) => logger.warn(LOG, 'navigateTo 单品详情失败, err=', err && err.errMsg),
})
},
onCancel() {
wx.showModal({
title: '取消分享',
content: '取消后该分享链接将失效',
confirmText: '取消分享',
confirmColor: '#FF3B30',
success: (res) => {
if (!res.confirm) return
request({ url: `/outfit-share/${this.data.uuid}/cancel`, method: 'POST' })
.then(() => {
logger.info(LOG, '取消分享成功')
wx.showToast({ title: '已取消', icon: 'success' })
;(this as any).backTimer = setTimeout(
() =>
wx.navigateBack({
fail: (e: any) => logger.warn(LOG, 'navigateBack 失败, err=', e && e.errMsg),
}),
500,
)
})
.catch((e: any) => logger.warn(LOG, '取消分享失败, code=', e && e.code))
},
fail: (e: any) => logger.warn(LOG, '取消分享弹窗失败, err=', e && e.errMsg),
})
},
onBackHome() {
wx.switchTab({
url: '/pages/wardrobe/wardrobe',
fail: (e: any) => logger.warn(LOG, 'switchTab 衣橱失败, err=', e && e.errMsg),
})
},
onGoLogin() {
const redirect = `/pages/outfit-share-detail/outfit-share-detail?uuid=${this.data.uuid}`
const loginUrl = `/pages/login/login?redirect=${encodeURIComponent(redirect)}`
wx.navigateTo({
url: loginUrl,
fail: () => {
wx.redirectTo({
url: loginUrl,
fail: () => wx.switchTab({ url: '/pages/profile/profile' }),
})
},
})
},
onShareAppMessage() {
const name = (this.data.outfit && this.data.outfit.outfit_name) || '好友的穿搭'
const owner = (this.data.detail && this.data.detail.owner_name) || '好友'
logger.debug(LOG, '转发分享, uuid=', this.data.uuid)
return {
title: `${owner} 向你分享了穿搭「${name}」`,
path: `/pages/outfit-share-detail/outfit-share-detail?uuid=${this.data.uuid}`,
}
},
onUnload() {
const timer = (this as any).backTimer
if (timer) {
clearTimeout(timer)
;(this as any).backTimer = null
}
},
})
@@ -0,0 +1,87 @@
<view class="page detail-page">
<navigation-bar title="穿搭分享" />
<empty-state
wx:if="{{invalid && needLogin}}"
icon="icon-user"
title="{{invalidTitle}}"
desc="{{invalidDesc}}"
buttonText="去登录"
bind:action="onGoLogin"
/>
<empty-state
wx:elif="{{invalid}}"
icon="icon-shirt"
title="{{invalidTitle}}"
desc="{{invalidDesc}}"
buttonText="返回首页"
bind:action="onBackHome"
/>
<scroll-view wx:else scroll-y class="scroll-body">
<!-- 分享者信息 -->
<view class="card owner-card">
<view class="avatar">
<image wx:if="{{detail.owner_avatar}}" class="avatar-img" src="{{detail.owner_avatar}}" mode="aspectFill" />
<view wx:else class="icon icon-user avatar-placeholder"></view>
</view>
<view class="owner-info">
<view class="owner-name">{{detail.owner_name || '好友'}} 分享了穿搭</view>
<view class="owner-expire">共 {{outfit.items.length}} 件单品</view>
</view>
</view>
<!-- 拼图封面 -->
<view class="cover">
<view
class="cover-item cover-{{index}}"
wx:for="{{outfit.items}}"
wx:key="clothes_uuid"
wx:if="{{index < 5}}"
>
<image wx:if="{{item.processed_image}}" class="cover-img" src="{{item.processed_image}}" mode="aspectFit" />
<view wx:else class="icon icon-hanger cover-placeholder"></view>
</view>
<view wx:if="{{!outfit.items.length}}" class="cover-empty">
<view class="icon icon-hanger"></view>
</view>
</view>
<!-- 信息卡片 -->
<view class="card info-card">
<view class="title-row">
<text class="title">{{outfit.outfit_name}}</text>
</view>
<view class="tag-row">
<text wx:if="{{outfit.scene}}" class="tag tag-gray">{{outfit.scene}}</text>
<text class="tag {{outfit.source === 2 ? 'tag-indigo' : 'tag-gray'}}">{{outfit.source === 2 ? 'AI 推荐' : '自建'}}</text>
</view>
<view class="desc" wx:if="{{outfit.outfit_desc}}">{{outfit.outfit_desc}}</view>
<!-- 包含衣物(点击只读查看) -->
<view class="items-title">包含衣物</view>
<scroll-view scroll-x class="items-scroll" show-scrollbar="{{false}}">
<view class="items-row">
<view
class="item-chip"
wx:for="{{outfit.items}}"
wx:key="clothes_uuid"
data-uuid="{{item.clothes_uuid}}"
bindtap="onItemTap"
>
<image wx:if="{{item.processed_image}}" class="item-img" src="{{item.processed_image}}" mode="aspectFill" />
<view wx:else class="item-img item-img-empty"><view class="icon icon-hanger"></view></view>
</view>
</view>
</scroll-view>
</view>
<!-- 转发出口 -->
<button class="share-btn" open-type="share">分享给好友</button>
<!-- 属主取消 -->
<view wx:if="{{detail.is_owner}}" class="cancel-btn btn-danger-text" bindtap="onCancel">取消分享</view>
<view class="footer-space"></view>
</scroll-view>
</view>
@@ -0,0 +1,201 @@
.detail-page {
height: 100vh;
display: flex;
flex-direction: column;
}
.scroll-body {
flex: 1;
height: 0;
}
/* 分享者信息 */
.owner-card {
margin: 24rpx;
display: flex;
align-items: center;
}
.avatar {
width: 96rpx;
height: 96rpx;
border-radius: 50%;
background: #F2F2F7;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
color: #C7C7CC;
flex-shrink: 0;
}
.avatar-img {
width: 100%;
height: 100%;
}
.avatar-placeholder {
width: 56rpx;
height: 56rpx;
}
.owner-info {
margin-left: 24rpx;
}
.owner-name {
font-size: 30rpx;
font-weight: 600;
color: #000;
}
.owner-expire {
font-size: 24rpx;
color: #8E8E93;
margin-top: 8rpx;
}
/* 封面 */
.cover {
margin: 0 24rpx 24rpx;
height: 480rpx;
background: #fff;
border-radius: 32rpx;
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
}
.cover-item {
position: absolute;
width: 200rpx;
height: 260rpx;
background: #F8F8FA;
border-radius: 20rpx;
border: 1rpx solid #E5E5EA;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.cover-0 { left: 30rpx; top: 80rpx; transform: rotate(-6deg); }
.cover-1 { left: 120rpx; top: 140rpx; transform: rotate(2deg); }
.cover-2 { left: 220rpx; top: 70rpx; transform: rotate(5deg); }
.cover-3 { left: 320rpx; top: 150rpx; transform: rotate(-2deg); }
.cover-4 { left: 420rpx; top: 90rpx; transform: rotate(7deg); }
.cover-img {
width: 100%;
height: 100%;
}
.cover-placeholder {
width: 80rpx;
height: 80rpx;
color: #C7C7CC;
}
.cover-empty {
color: #C7C7CC;
}
.cover-empty .icon {
width: 120rpx;
height: 120rpx;
}
/* 信息卡 */
.info-card {
margin: 0 24rpx 24rpx;
}
.title {
font-size: 40rpx;
font-weight: 700;
color: #000;
}
.tag-row {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
margin-top: 20rpx;
}
.desc {
font-size: 28rpx;
color: #3C3C43;
margin-top: 20rpx;
line-height: 1.6;
}
.items-title {
font-size: 28rpx;
font-weight: 600;
color: #000;
margin-top: 32rpx;
}
.items-scroll {
margin-top: 20rpx;
white-space: nowrap;
}
.items-row {
display: inline-flex;
}
.item-chip {
display: flex;
flex-direction: column;
align-items: center;
width: 140rpx;
margin-right: 20rpx;
}
.item-img {
width: 120rpx;
height: 120rpx;
border-radius: 20rpx;
background: #F2F2F7;
}
.item-img-empty {
display: flex;
align-items: center;
justify-content: center;
color: #C7C7CC;
}
.item-img-empty .icon {
width: 56rpx;
height: 56rpx;
}
/* 转发出口 */
.share-btn {
margin: 32rpx 24rpx 0;
height: 88rpx;
line-height: 88rpx;
font-size: 30rpx;
font-weight: 500;
color: var(--color-primary, #000);
background: #fff;
border-radius: 24rpx;
}
.share-btn::after {
border: none;
}
.cancel-btn {
text-align: center;
padding: 32rpx 0;
}
.footer-space {
height: 40rpx;
}