ChannelCodeViewDrawer.tsx
3.87 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
import { useState, useEffect } from 'react';
import { Drawer, StatePlaceholder, Button, Tag } from '../../../packages/ui/src';
import { type ChannelCodeMockItem } from '../../../packages/contracts/channel-code-mock';
interface ChannelCodeViewDrawerProps {
open: boolean;
code: ChannelCodeMockItem | null;
onClose: () => void;
}
export function ChannelCodeViewDrawer({ open, code, onClose }: ChannelCodeViewDrawerProps) {
const [qrcodeError, setQrcodeError] = useState(false);
useEffect(() => {
if (!open) {
setQrcodeError(false);
}
}, [open]);
if (!code) return null;
const handleQrcodeError = () => {
setQrcodeError(true);
};
const statusText = code.status === 'enable' ? '启用' : '停用';
const statusClass = code.status === 'enable'
? 'inline-flex items-center rounded-full bg-[var(--gl-color-success-bg)] px-2 py-0.5 text-xs text-[var(--gl-color-success-text)]'
: 'inline-flex items-center rounded-full bg-[var(--gl-color-warning-bg)] px-2 py-0.5 text-xs text-[var(--gl-color-warning-text)]';
return (
<Drawer
open={open}
title={code.code_name}
onClose={onClose}
width={480}
footer={
<div className="flex items-center justify-end">
<Button variant="outline" onClick={onClose}>关闭</Button>
</div>
}
>
<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>{code.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>{code.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>{code.employee_name}({code.employee_role_text})</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">
{code.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={statusClass}>{statusText}</span>
</div>
<div className="grid grid-cols-[120px_1fr] gap-2 text-sm">
<span className="text-[var(--gl-color-text-secondary)]">活码描述</span>
<span>{code.description || '-'}</span>
</div>
<div className="grid grid-cols-[120px_1fr] gap-2 text-sm">
<span className="text-[var(--gl-color-text-secondary)]">自动欢迎语</span>
<span>{code.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 || code.qrcode_load_error ? (
<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={code.qrcode_url}
onError={handleQrcodeError}
/>
)}
</div>
</div>
</Drawer>
);
}