PositionAbilityArea.tsx
5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { useState } from 'react';
import type { PositionTab, Agent, MediaType } from '../types/home';
import { AgentCard } from './AgentCard';
import { QrcodeModal } from './QrcodeModal';
export interface PositionAbilityAreaProps {
tab: PositionTab;
currentAgent: Agent | undefined;
currentAgentIndex: number;
onAgentSelect: (index: number) => void;
onOpenQrcodeModal: () => void;
qrcodeModalOpen: boolean;
onCloseQrcodeModal: () => void;
}
export function PositionAbilityArea({
tab,
currentAgent,
currentAgentIndex,
onAgentSelect,
onOpenQrcodeModal,
qrcodeModalOpen,
onCloseQrcodeModal,
}: PositionAbilityAreaProps) {
const [mediaError, setMediaError] = useState(false);
const shouldScrollAgentList = tab.agents.length > 4;
const [titlePrefix = '', ...titleSuffixParts] = tab.main_title.split('—');
const titleSuffix = titleSuffixParts.join('—').trim();
const handleMediaError = () => {
setMediaError(true);
};
const renderMedia = (mediaUrl: string | null, mediaType: MediaType | null) => {
if (!mediaUrl || !mediaType || mediaError) {
return (
<div className="w-full h-full bg-surface-container flex items-center justify-center">
<span className="text-on-surface-variant">素材不可用</span>
</div>
);
}
if (mediaType === 'mp4' || mediaType === 'mov') {
return (
<video
src={mediaUrl}
data-testid="agent-video"
className="w-full h-full object-contain bg-surface-container"
autoPlay
loop
muted
playsInline
onError={handleMediaError}
/>
);
}
return (
<img
src={mediaUrl}
data-testid="agent-image"
alt="Agent 素材"
className="w-full h-full object-contain"
onError={handleMediaError}
/>
);
};
return (
<section className="pt-stack-md tablet:pt-stack-lg pb-20 bg-surface" data-testid="position-ability-area">
<div className="max-w-container-max mx-auto px-margin-mobile tablet:px-margin-desktop">
<div className="grid grid-cols-1 tablet:grid-cols-[minmax(0,1.35fr)_minmax(320px,1fr)] gap-8 tablet:gap-10 items-start">
<div
data-testid="left-mockup"
className="overflow-hidden rounded-[28px] shadow-[0_20px_50px_rgba(27,87,181,0.12)] bg-white"
>
<div
data-testid="agent-media-frame"
className="aspect-[1.04/0.82] w-full overflow-hidden rounded-[28px] bg-gradient-to-br from-[#5ea0f0] via-[#94c0ff] to-[#d5e6ff]"
>
<div className="h-full w-full overflow-hidden rounded-[28px] bg-surface-container relative">
{currentAgent ? (
renderMedia(currentAgent.media_url, currentAgent.media_type)
) : (
<div className="w-full h-full bg-surface-container flex items-center justify-center">
<span className="text-on-surface-variant">暂无 Agent 素材</span>
</div>
)}
</div>
</div>
</div>
<div className="space-y-6 tablet:pt-1">
<div className="inline-flex items-start gap-3">
<span className="mt-2 h-10 w-1 rounded-full bg-primary shrink-0" />
<div>
<p className="mb-1 text-label-sm font-medium text-primary">核心能力</p>
<div className="text-headline-md leading-tight">
<span>{titlePrefix.trim()}</span>
{titleSuffix ? (
<>
{' '}
<span className="text-primary">— {titleSuffix}</span>
</>
) : null}
</div>
<p className="mt-3 text-body-md text-on-surface-variant leading-relaxed">
{tab.sub_title}
</p>
</div>
</div>
{tab.agents.length > 0 && (
<div
data-testid="agent-card-list"
className={`space-y-2.5 ${shouldScrollAgentList ? 'max-h-[370px] overflow-y-auto pr-1.5' : ''}`}
>
{tab.agents.map((agent, index) => (
<AgentCard
key={agent.agent_id}
agent={agent}
isSelected={index === currentAgentIndex}
onClick={() => onAgentSelect(index)}
/>
))}
</div>
)}
</div>
</div>
<div className="mt-12 flex justify-center">
<button
onClick={onOpenQrcodeModal}
className="inline-flex items-center justify-center gap-2 rounded-full bg-primary px-12 py-4 text-white text-[22px] leading-none shadow-[0_12px_28px_rgba(0,84,220,0.24)] transition-transform active:scale-95"
>
立即体验 <span className="text-[22px]">↗</span>
</button>
</div>
</div>
<QrcodeModal
isOpen={qrcodeModalOpen}
onClose={onCloseQrcodeModal}
positionName={tab.position_name}
qrcodeUrl={tab.qrcode_url}
qrcodeStatus={tab.qrcode_status}
/>
</section>
);
}