fix: 动作详情GIF动图播放 + 收藏按钮避让胶囊

This commit is contained in:
2026-07-22 16:02:04 +08:00
parent 98126c62ec
commit 47c4801f34
9 changed files with 924 additions and 6 deletions

View File

@@ -7,10 +7,13 @@ const auth = require('../../utils/auth');
Page({
data: {
statusBarHeight: 20,
favRight: 8,
favTop: 20,
id: '',
planId: '',
exercise: null,
heroSrc: '',
heroGif: '',
heroError: false,
related: [],
loading: true,
@@ -20,7 +23,18 @@ Page({
onLoad(query) {
const id = query.id || '';
const planId = query.planId || '';
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20, id, planId });
// 收藏按钮需避让微信右上角胶囊按钮(···◯):用胶囊实际位置算出安全右/上边距
let favRight = 8;
let favTop = (app.globalData.statusBarHeight || 20) + 6;
try {
const menu = wx.getMenuButtonBoundingClientRect();
const win = (wx.getWindowInfo && wx.getWindowInfo()) || wx.getSystemInfoSync();
if (menu && win) {
favRight = Math.max(8, win.windowWidth - menu.left + 8);
favTop = menu.top + Math.max(0, (menu.height - 36) / 2);
}
} catch (e) {}
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20, favRight, favTop, id, planId });
// 防御id 缺失直接显示空态,避免请求 /api/exercises/ 导致错乱或 404
if (!id) {
this.setData({ loading: false });
@@ -37,9 +51,10 @@ Page({
load() {
this.setData({ loading: true });
svc.getExercise(this.data.id).then((ex) => {
// 详情大图优先用超分 JPG(720px 清晰)失败再降级到 GIF / 占位
// 海报用超分 JPG(720px 清晰)动图用原始 GIF由 gif-player 组件逐帧播放
const heroSrc = ex && (ex.image || ex.gifUrl) ? (ex.image || ex.gifUrl) : '';
this.setData({ exercise: ex, heroSrc, heroError: false, loading: false });
const heroGif = ex && ex.gifUrl ? ex.gifUrl : '';
this.setData({ exercise: ex, heroSrc, heroGif, heroError: false, loading: false });
if (ex && ex.target) {
svc.listExercises({ target: ex.target, pageSize: 6 }).then((res) => {
const related = ((res && res.items) || [])