ChannelCodeViewDrawer.tsx
5.07 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, useEffect } from 'react';
import { Drawer, StatePlaceholder, Button, Tag } from '../../../packages/ui/src';
import { getChannelQRCodeDetail, type ChannelQRCodeDetail } from '../../api/channelCode';
interface ChannelCodeViewDrawerProps {
open: boolean;
qrcodeId: number | null;
onClose: () => void;
}
export function ChannelCodeViewDrawer({ open, qrcodeId, onClose }: ChannelCodeViewDrawerProps) {
const [qrcodeError, setQrcodeError] = useState(false);
const [loading, setLoading] = useState(false);
const [loadError, setLoadError] = useState(false);
const [detail, setDetail] = useState<ChannelQRCodeDetail | null>(null);
useEffect(() => {
if (!open) {
setQrcodeError(false);
setDetail(null);
setLoadError(false);
return;
}
if (!qrcodeId) {
setDetail(null);
return;
}
setLoading(true);
setLoadError(false);
getChannelQRCodeDetail(qrcodeId)
.then((data) => {
setDetail(data);
setLoading(false);
})
.catch(() => {
setLoadError(true);
setLoading(false);
});
}, [open, qrcodeId]);
const handleQrcodeError = () => {
setQrcodeError(true);
};
const handleRetry = () => {
if (!qrcodeId) return;
setLoading(true);
setLoadError(false);
getChannelQRCodeDetail(qrcodeId)
.then((data) => {
setDetail(data);
setLoading(false);
})
.catch(() => {
setLoadError(true);
setLoading(false);
});
};
if (!qrcodeId) return null;
const statusTag = detail?.status === 'enable'
? <Tag status="success">启用</Tag>
: <Tag status="warning">停用</Tag>;
return (
<Drawer
open={open}
title={detail?.qrcode_name ?? '渠道活码详情'}
onClose={onClose}
width={480}
footer={
<div className="flex items-center justify-end">
<Button variant="outline" onClick={onClose}>关闭</Button>
</div>
}
>
{loading ? (
<div className="flex items-center justify-center py-8">
<span className="text-sm text-[var(--gl-color-text-secondary)]">正在加载...</span>
</div>
) : loadError ? (
<StatePlaceholder
state="error"
title="加载失败"
description="渠道活码详情加载失败,请重试"
primaryAction={<Button size="small" onClick={handleRetry}>重试</Button>}
/>
) : detail ? (
<div className="grid gap-4">
<div className="grid gap-2">
<div className="grid grid-cols-[120px_1fr] gap-2 text-sm">
<span className="text-[var(--gl-color-text-secondary)]">对应岗位</span>
<span>{detail.position_name}</span>
</div>
<div className="grid grid-cols-[120px_1fr] gap-2 text-sm">
<span className="text-[var(--gl-color-text-secondary)]">渠道编码</span>
<span>{detail.channel_code}</span>
</div>
<div className="grid grid-cols-[120px_1fr] gap-2 text-sm">
<span className="text-[var(--gl-color-text-secondary)]">承接员工</span>
<span>{detail.employee_name}</span>
</div>
<div className="grid grid-cols-[120px_1fr] gap-2 text-sm">
<span className="text-[var(--gl-color-text-secondary)]">关联 Agent</span>
<div className="flex flex-wrap gap-1">
{(detail.agent_names ?? []).map((name) => (
<Tag key={name} status="info">{name}</Tag>
))}
</div>
</div>
<div className="grid grid-cols-[120px_1fr] gap-2 text-sm">
<span className="text-[var(--gl-color-text-secondary)]">状态</span>
<span className="inline-flex">{statusTag}</span>
</div>
<div className="grid grid-cols-[120px_1fr] gap-2 text-sm">
<span className="text-[var(--gl-color-text-secondary)]">活码描述</span>
<span>{detail.remark || '-'}</span>
</div>
<div className="grid grid-cols-[120px_1fr] gap-2 text-sm">
<span className="text-[var(--gl-color-text-secondary)]">自动欢迎语</span>
<span>{detail.welcome_message || '-'}</span>
</div>
</div>
<div className="border-t border-[var(--gl-color-border-secondary)] pt-4">
<span className="block mb-2 text-sm text-[var(--gl-color-text-secondary)]">二维码图片</span>
{qrcodeError ? (
<StatePlaceholder
state="error"
title="二维码加载失败"
description="二维码图片加载失败,请刷新重试"
/>
) : (
<img
alt="渠道活码二维码"
className="w-[200px] h-[200px] rounded-[var(--gl-radius-sm)] border border-[var(--gl-color-border-secondary)]"
src={detail.qrcode_url}
onError={handleQrcodeError}
/>
)}
</div>
</div>
) : null}
</Drawer>
);
}