OfficialSiteAgentDisplayConfigPage.tsx
9.9 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import { useCallback, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { BusinessTable, StatePlaceholder, type BusinessTableColumn } from '@gl/business-components';
import { Button } from 'tdesign-react';
import {
getAvailableAgents,
type OfficialSiteAvailableAgent,
type DisplayStatus,
type AgentStatus,
} from '../../api/officialSiteAgentDisplay';
import { getOfficialSiteTabDetail, type OfficialSiteTabDetail } from '../../api/officialSiteTab';
import { useTrackPageView } from '../../api/tracking';
import { useDeferredEffect } from '../../hooks/useDeferredEffect';
import { IndependentPageBody, IndependentPageHeader, IndependentPageLayout } from '../components/IndependentPageLayout';
import { AgentDisplayConfigEditModal } from './AgentDisplayConfigEditModal';
function mapAgentStatusToText(status: AgentStatus): string {
return status === 'enable' ? '已上架' : '已停用';
}
function getDisplayStatusTextForList(agentStatus: AgentStatus, displayStatus: DisplayStatus): string {
if (agentStatus === 'disable') return '-';
return displayStatus === 'enable' ? '展示中' : '不展示';
}
export function OfficialSiteAgentDisplayConfigPage() {
const navigate = useNavigate();
const params = useParams();
const tabId = Number(params.tabId);
const [loading, setLoading] = useState(true);
const [loadError, setLoadError] = useState(false);
const [tabDetail, setTabDetail] = useState<OfficialSiteTabDetail | null>(null);
const [items, setItems] = useState<OfficialSiteAvailableAgent[]>([]);
const [editingDisplayId, setEditingDisplayId] = useState<number | null>(null);
const [notice, setNotice] = useState<{ type: 'success' | 'error'; message: string } | null>(null);
useTrackPageView('official_site_agent_display_config', { loaded: !loading && !loadError && tabDetail !== null });
const fetchData = useCallback(async () => {
setLoading(true);
setLoadError(false);
try {
const [detail, agentsResponse] = await Promise.all([
getOfficialSiteTabDetail(tabId),
getAvailableAgents(tabId),
]);
setTabDetail(detail);
setItems(agentsResponse.available_agents);
setLoading(false);
} catch {
setLoadError(true);
setLoading(false);
}
}, [tabId]);
useDeferredEffect(() => {
fetchData();
}, [fetchData]);
const goBackToList = () => {
navigate('/official-site/job-tabs');
};
const handleEditAgent = (agent: OfficialSiteAvailableAgent) => {
setEditingDisplayId(agent.display_id);
};
// Loading state
if (loading) {
return (
<IndependentPageLayout>
<IndependentPageHeader>
<div aria-label="页面标题" className="min-w-0 flex-1">
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">Agent展示配置页</h2>
</div>
<div aria-label="页面操作" className="flex shrink-0 items-center gap-2">
<Button variant="outline" onClick={goBackToList}>返回</Button>
</div>
</IndependentPageHeader>
<IndependentPageBody className="grid gap-4 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] p-6">
<p className="text-sm text-[var(--gl-color-text-secondary)]">加载中...</p>
</IndependentPageBody>
</IndependentPageLayout>
);
}
const columns: BusinessTableColumn<OfficialSiteAvailableAgent>[] = [
{
title: 'Agent名称',
colKey: 'agent_name',
cell: ({ row }) => <span className="font-medium">{row.agent_name}</span>,
},
{
title: 'Agent概述',
colKey: 'speech_content',
ellipsisTooltip: true,
tooltipValue: ({ speech_content }) => speech_content || '-',
},
{
title: '图标',
colKey: 'icon_url',
cell: ({ row: item }) => {
const url = item.icon_url;
if (!url) {
return <span className="text-[var(--gl-color-text-secondary)]">-</span>;
}
return (
<img
data-testid={`agent-icon-${item.agent_id}`}
src={url}
alt={item.agent_name}
className="w-8 h-8 rounded object-cover"
/>
);
},
},
// 展示素材列已移除,编辑弹窗仍保留展示素材字段
{
title: '状态',
colKey: 'agent_status',
cell: ({ row }) => {
const status = row.agent_status;
const text = mapAgentStatusToText(status);
return status === 'enable'
? <span className="inline-flex items-center rounded-full bg-[var(--gl-color-success-bg)] px-2 py-1 text-xs text-[var(--gl-color-success-text)]">{text}</span>
: <span className="inline-flex items-center rounded-full bg-[var(--gl-color-warning-bg)] px-2 py-1 text-xs text-[var(--gl-color-warning-text)]">{text}</span>;
},
},
{
title: '展示状态',
colKey: 'display_status_display',
cell: ({ row: item }) => {
const text = getDisplayStatusTextForList(item.agent_status, item.display_status);
if (text === '-') {
return <span className="text-[var(--gl-color-text-secondary)]">-</span>;
}
return item.display_status === 'enable'
? <span className="inline-flex items-center rounded-full bg-[var(--gl-color-success-bg)] px-2 py-1 text-xs text-[var(--gl-color-success-text)]">{text}</span>
: <span className="inline-flex items-center rounded-full bg-[var(--gl-color-warning-bg)] px-2 py-1 text-xs text-[var(--gl-color-warning-text)]">{text}</span>;
},
},
{
title: '操作',
colKey: 'actions',
cell: ({ row: item }) => {
if (item.agent_status !== 'enable') {
return null;
}
return (
<span className="flex flex-wrap gap-1">
<Button
aria-label={`编辑配置-${item.agent_name}`}
size="small"
theme="primary"
variant="text"
onClick={() => handleEditAgent(item)}
>
编辑配置
</Button>
</span>
);
},
},
];
return (
<IndependentPageLayout>
<IndependentPageHeader>
<div aria-label="页面标题" className="min-w-0 flex-1">
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">
{tabDetail?.position_name ?? '-'} Agent展示配置页
</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
配置该岗位下 Agent 在官网的展示素材和状态
</p>
</div>
<div aria-label="页面操作" className="flex shrink-0 items-center gap-2">
<Button variant="outline" onClick={goBackToList}>返回</Button>
</div>
</IndependentPageHeader>
<IndependentPageBody className="grid gap-6">
{notice ? (
<div
className={`rounded-[var(--gl-radius-sm)] border px-4 py-3 text-sm ${
notice.type === 'error'
? 'border-[var(--gl-color-danger-border)] bg-[var(--gl-color-danger-bg)] text-[var(--gl-color-danger-text)]'
: 'border-[var(--gl-color-success-border)] bg-[var(--gl-color-success-bg)] text-[var(--gl-color-success-text)]'
}`}
role={notice.type === 'error' ? 'alert' : 'status'}
aria-label={notice.message}
>
{notice.message}
</div>
) : null}
{/* Tab context info */}
{tabDetail ? (
<div className="grid gap-4 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6">
<div className="grid gap-4 text-sm">
<div className="flex items-center gap-2">
<span className="shrink-0 min-w-[80px] text-[var(--gl-color-text-secondary)]">关联渠道活码:</span>
<span>{tabDetail.qrcode_name || '-'}</span>
</div>
<div className="flex items-center gap-2">
<span className="shrink-0 min-w-[80px] text-[var(--gl-color-text-secondary)]">渠道编码:</span>
<span>{tabDetail.position_code || '-'}</span>
</div>
<div className="flex items-center gap-2">
<span className="shrink-0 min-w-[80px] text-[var(--gl-color-text-secondary)]">承接员工:</span>
<span>{tabDetail.qrcode_employee_name || '-'}</span>
</div>
</div>
</div>
) : null}
{/* Agent list table */}
<div className="grid gap-4 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] p-6">
<p className="text-sm text-[var(--gl-color-text-secondary)]">
Agent 数据源来自该岗位关联的渠道活码。管家 Agent 不参与官网展示。
Agent 列表不可增删,仅可编辑展示配置。
</p>
{loadError ? (
<BusinessTable
rowKey="agent_id"
columns={columns}
data={items}
error
errorState={{
onRetry: fetchData,
}}
/>
) : items.length === 0 ? (
<div className="grid gap-4 py-10">
<StatePlaceholder state="empty" title="当前无可配置 Agent" />
</div>
) : (
<BusinessTable
rowKey="agent_id"
columns={columns}
data={items}
/>
)}
</div>
</IndependentPageBody>
{/* Edit modal */}
<AgentDisplayConfigEditModal
open={Boolean(editingDisplayId)}
displayId={editingDisplayId}
onCancel={() => setEditingDisplayId(null)}
onSaveSuccess={() => {
setEditingDisplayId(null);
setNotice({ type: 'success', message: '保存成功' });
fetchData();
}}
/>
</IndependentPageLayout>
);
}