feat: 性能优化与余额扣费系统集成

主要更新:
- 🚀 模板详情页性能优化:添加缓存机制、图片预加载、请求中断控制
- 💰 集成余额检查与扣费功能到表单提交流程
- 🔄 添加错误重试机制,提升用户体验
- 🎨 重构动态表单字段为独立组件 (DynamicFormField)
- 🔧 修复类型错误,优化样式结构

技术细节:
- 实现5分钟缓存策略减少API调用
- 使用 AbortController 管理请求生命周期
- React.memo 优化列表项渲染性能
- 图片预缓存提升加载体验

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
imeepos
2025-11-11 18:11:05 +08:00
parent eee280d9b3
commit d22ca2a85c
11 changed files with 822 additions and 582 deletions

View File

@@ -1,6 +1,6 @@
import { ThemedText } from '@/components/themed-text';
import { VideoView, useVideoPlayer } from 'expo-video';
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
ActivityIndicator,
Dimensions,
@@ -43,10 +43,15 @@ export function FullscreenVideoModal({
hasNext = false,
hasPrevious = false,
}: FullscreenVideoModalProps) {
const player = useVideoPlayer(
{
uri: videoUrl,
},
// 使用useRef存储player实例避免无限循环
const playerRef = useRef<any>(null);
// 稳定videoUrl使用useMemo
const stableVideoUrl = useMemo(() => ({ uri: videoUrl }), [videoUrl]);
// 始终调用useVideoPlayer但只在videoUrl变化时更新player
const newPlayer = useVideoPlayer(
stableVideoUrl,
(player) => {
player.loop = isLooping;
player.muted = isMuted;
@@ -56,6 +61,14 @@ export function FullscreenVideoModal({
}
);
// 只有当newPlayer变化时才更新player
useEffect(() => {
playerRef.current = newPlayer;
}, [newPlayer]);
// 获取当前的player实例
const player = playerRef.current || newPlayer;
const [isLoading, setIsLoading] = useState(true);
// 重置状态当模态框打开/关闭时
@@ -63,8 +76,9 @@ export function FullscreenVideoModal({
if (visible) {
setIsLoading(true);
} else {
if (player) {
player.pause();
const currentPlayer = playerRef.current;
if (currentPlayer) {
currentPlayer.pause();
}
}
}, [visible, autoPlay]);
@@ -73,7 +87,8 @@ export function FullscreenVideoModal({
const handleVideoReady = () => {
setIsLoading(false);
if (autoPlay) {
player?.play();
const currentPlayer = playerRef.current;
currentPlayer?.play();
}
};
@@ -160,9 +175,8 @@ export function FullscreenVideoModal({
<VideoView
player={player}
style={styles.video}
contentFit="contain" as any
contentFit="contain"
nativeControls={false}
onError={handleVideoError}
/>
)}