bigfix
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { request } from '../../utils/request'
|
||||
import { request, AUTH_EXPIRED_CODES } from '../../utils/request'
|
||||
import { ClosetShareDetail } from '../../types/models'
|
||||
import { ShareStatus } from '../../utils/config'
|
||||
import { formatDateTime } from '../../utils/format'
|
||||
|
||||
Page({
|
||||
@@ -9,30 +10,86 @@ Page({
|
||||
expireText: '',
|
||||
loading: true,
|
||||
invalid: false,
|
||||
invalidTitle: '该分享已过期或已被取消',
|
||||
invalidDesc: '分享链接已失效',
|
||||
needLogin: false,
|
||||
},
|
||||
|
||||
onLoad(query: Record<string, string>) {
|
||||
const uuid = query.uuid || ''
|
||||
this.setData({ uuid })
|
||||
if (uuid) this.fetchDetail()
|
||||
if (!uuid) {
|
||||
// uuid 缺失时若不兜底,loading 会永久为 true,页面白屏且无法退出
|
||||
this.setInvalid('链接不完整', '缺少分享标识,无法打开')
|
||||
return
|
||||
}
|
||||
this.fetchDetail()
|
||||
},
|
||||
|
||||
fetchDetail() {
|
||||
request<ClosetShareDetail>({ url: `/closet-share/${this.data.uuid}`, showError: false })
|
||||
.then((detail) => {
|
||||
// 后端可能惰性过期:本地再校验一次状态与有效期,避免展示已失效内容
|
||||
if (this.checkInvalid(detail)) return
|
||||
|
||||
const expireText =
|
||||
detail.expire_time === 0 ? '长期有效' : `有效期至 ${formatDateTime(detail.expire_time)}`
|
||||
this.setData({ detail, expireText, loading: false })
|
||||
})
|
||||
.catch((e: any) => {
|
||||
this.setData({ loading: false })
|
||||
const code = e && e.code
|
||||
if (code === 90100 || code === 90101 || code === 90102) {
|
||||
this.setData({ invalid: true })
|
||||
if (AUTH_EXPIRED_CODES.indexOf(code) >= 0) {
|
||||
// 查看分享需登录:给「去登录」出口,登录成功后回到本页
|
||||
this.setData({
|
||||
loading: false,
|
||||
invalid: true,
|
||||
needLogin: true,
|
||||
invalidTitle: '请先登录',
|
||||
invalidDesc: '登录后即可查看好友分享的衣柜',
|
||||
})
|
||||
return
|
||||
}
|
||||
if (code === 90101) {
|
||||
this.setInvalid('分享已过期', '该分享链接已超过有效期')
|
||||
} else if (code === 90102) {
|
||||
this.setInvalid('分享已取消', '该分享已被创建者取消')
|
||||
} else if (code === 90100) {
|
||||
this.setInvalid('分享不存在', '该分享链接无效')
|
||||
} else {
|
||||
// 兜底:任何未知错误都不能停在空白页
|
||||
this.setInvalid('加载失败', '请稍后重试')
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 本地状态/有效期校验,返回 true 表示已置为失效态
|
||||
checkInvalid(detail: ClosetShareDetail): boolean {
|
||||
if (detail.status === ShareStatus.CANCELLED) {
|
||||
this.setInvalid('分享已取消', '该分享已被创建者取消')
|
||||
return true
|
||||
}
|
||||
if (detail.status === ShareStatus.BANNED) {
|
||||
this.setInvalid('分享已封禁', '该分享内容违规,已停止展示')
|
||||
return true
|
||||
}
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
if (detail.status === ShareStatus.EXPIRED || (detail.expire_time > 0 && detail.expire_time < now)) {
|
||||
this.setInvalid('分享已过期', '该分享链接已超过有效期')
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
|
||||
setInvalid(title: string, desc: string) {
|
||||
this.setData({
|
||||
loading: false,
|
||||
invalid: true,
|
||||
needLogin: false,
|
||||
invalidTitle: title,
|
||||
invalidDesc: desc,
|
||||
})
|
||||
},
|
||||
|
||||
onCancel() {
|
||||
wx.showModal({
|
||||
title: '取消分享',
|
||||
@@ -44,7 +101,7 @@ Page({
|
||||
request({ url: `/closet-share/${this.data.uuid}/cancel`, method: 'POST' })
|
||||
.then(() => {
|
||||
wx.showToast({ title: '已取消', icon: 'success' })
|
||||
setTimeout(() => wx.navigateBack(), 500)
|
||||
;(this as any).backTimer = setTimeout(() => wx.navigateBack(), 500)
|
||||
})
|
||||
.catch(() => {})
|
||||
},
|
||||
@@ -54,4 +111,28 @@ Page({
|
||||
onBackHome() {
|
||||
wx.switchTab({ url: '/pages/wardrobe/wardrobe' })
|
||||
},
|
||||
|
||||
onGoLogin() {
|
||||
const redirect = `/pages/closet-share-detail/closet-share-detail?uuid=${this.data.uuid}`
|
||||
wx.navigateTo({
|
||||
url: `/pages/login/login?redirect=${encodeURIComponent(redirect)}`,
|
||||
fail: () => wx.switchTab({ url: '/pages/profile/profile' }),
|
||||
})
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
const name = (this.data.detail && this.data.detail.owner_name) || '好友'
|
||||
return {
|
||||
title: `${name} 向你分享了 TA 的衣柜`,
|
||||
path: `/pages/closet-share-detail/closet-share-detail?uuid=${this.data.uuid}`,
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
const timer = (this as any).backTimer
|
||||
if (timer) {
|
||||
clearTimeout(timer)
|
||||
;(this as any).backTimer = null
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -2,10 +2,19 @@
|
||||
<navigation-bar title="分享详情" />
|
||||
|
||||
<empty-state
|
||||
wx:if="{{invalid}}"
|
||||
wx:if="{{invalid && needLogin}}"
|
||||
icon="icon-user"
|
||||
title="{{invalidTitle}}"
|
||||
desc="{{invalidDesc}}"
|
||||
buttonText="去登录"
|
||||
bind:action="onGoLogin"
|
||||
/>
|
||||
|
||||
<empty-state
|
||||
wx:elif="{{invalid}}"
|
||||
icon="icon-share"
|
||||
title="该分享已过期或已被取消"
|
||||
desc="分享链接已失效"
|
||||
title="{{invalidTitle}}"
|
||||
desc="{{invalidDesc}}"
|
||||
buttonText="返回首页"
|
||||
bind:action="onBackHome"
|
||||
/>
|
||||
@@ -35,6 +44,9 @@
|
||||
</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>
|
||||
|
||||
@@ -112,6 +112,21 @@
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
|
||||
.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;
|
||||
|
||||
Reference in New Issue
Block a user