Files
sundynix-pets/pets-fe/pages/community/community.wxml
T
Blizzard 7093e6517d perf(fe): 修复 token 过期白屏、请求翻倍与失败伪装成空态
token 过期后小程序静默白屏(影响所有用户)
- JWT 有效期 7 天,过期后 40100 只 clearToken 不重新登录,而
  store.ready 的 promise 已缓存不会重跑,加上 23 处静默 catch,
  用户看到的是「什么都没有、也没有任何提示」,只能重启小程序
- request 层加 token 失效钩子:自动重新登录并重试一次(只重试一次,
  防止登录接口本身故障时死循环);store 注册钩子重置引导缓存
- 补 15s 请求超时、60s 上传超时,超时给明确文案(原先默认 60s 卡住无反馈)

请求翻倍
- 每个 tab 页同时用 store.subscribe 和 onShow→ready().then() 加载,
  而 ready() 内部 loadPets 会 notify 触发 subscriber,首次进入请求翻倍
- subscriber 改为只处理「切换宠物 / 数据变更」,首次加载交给 onShow
- 首页 bind:save 与组件实际触发的 saved 事件名不一致,onSheetSave
  从未生效;一并修正,并去掉关闭弹层时的全量重载

失败伪装成空态
- 社区请求失败时显示「还没有帖子,来发第一条吧」,把故障说成没数据。
  改为区分「加载失败(可点击重试)」「关注 tab 为空」「确实没有帖子」
- 新增 utils/ui.js 统一错误提示(同文案 3 秒内去重,避免并发失败刷屏),
  首页与记录页主数据加载失败不再静默

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-28 17:56:35 +08:00

57 lines
2.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<wxs module="im">
module.exports.isUrl = function (s) { return s && s.indexOf('http') === 0; }
</wxs>
<nav-bar title="宠友圈"></nav-bar>
<scroll-view class="page-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
<view class="page-body">
<view class="page-title">
<view class="pt-h2">宠友圈</view>
<view class="pt-p">和宠友交流、晒宠、求助与经验分享。</view>
</view>
<scroll-view class="feed-tabs" scroll-x="true" enhanced="{{true}}" show-scrollbar="{{false}}">
<view wx:for="{{feedTabs}}" wx:key="*this"
class="feed-tab {{feedIdx === index ? 'active' : ''}}" data-index="{{index}}" bindtap="switchFeedTab">{{item}}</view>
</scroll-view>
<view class="compose-card">
<button class="btn btn-primary btn-block" bindtap="openSheet" data-type="createPost"> 发布图文</button>
</view>
<view wx:for="{{posts}}" wx:key="id" class="post-card" bindlongpress="onLongPressPost" data-index="{{index}}">
<view class="post-head">
<view class="post-avatar">{{item.author_emoji}}</view>
<view class="post-user"><text class="pu-b">{{item.author_name}}<text wx:if="{{item.is_ai}}" class="ai-tag">AI</text></text><text class="pu-s">宠友</text></view>
<view wx:if="{{!item.is_self && item.user_id}}" class="follow-btn {{item.followed ? 'on' : ''}}"
catchtap="toggleFollow" data-index="{{index}}">{{item.followed ? '已关注' : '+ 关注'}}</view>
<view wx:if="{{item.tag}}" class="tag {{item.tagClass}}">{{item.tag}}</view>
</view>
<view class="post-content">{{item.content}}</view>
<view wx:if="{{item.images.length}}" class="photo-grid">
<block wx:for="{{item.images}}" wx:for-item="img" wx:key="*this">
<image wx:if="{{im.isUrl(img)}}" class="photo-tile" src="{{img}}" mode="aspectFill"></image>
<view wx:else class="photo-tile">{{img}}</view>
</block>
</view>
<view class="post-actions">
<view class="pa-btn {{item.liked ? 'liked' : ''}}" data-index="{{index}}" bindtap="likePost">{{item.liked ? '♥' : '♡'}} {{item.like_count}}</view>
<view class="pa-btn" data-id="{{item.id}}" bindtap="openComments">💬 {{item.comment_count}}</view>
<button class="pa-btn pa-share" open-type="share" data-content="{{item.content}}">↗ 分享</button>
</view>
</view>
<view wx:if="{{loadErr}}" class="empty-hint">
{{loadErr}}
<view class="retry-btn" bindtap="loadPosts">点击重试</view>
</view>
<view wx:elif="{{loaded && posts.length === 0}}" class="empty-hint">
{{feedTabs[feedIdx] === '关注' ? '还没有关注的人,去「推荐」里关注几个宠友吧 🐾' : '还没有帖子,来发第一条吧 🐾'}}
</view>
</view>
</scroll-view>
<fab bind:tap="onFab"></fab>
<bottom-sheet show="{{sheetShow}}" type="{{sheetType}}" post-id="{{sheetPostId}}"
bind:close="closeSheet" bind:posted="onPosted" bind:commented="onCommented"></bottom-sheet>