officialSiteTab.ts
6.97 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
import { apiClient, type PaginatedResponse } from './client';
export type OfficialSiteTabStatus = 'enable' | 'disable';
export type ChannelQRCodeStatus = 'enable' | 'disable';
export interface OfficialSiteTabListItem extends Record<string, unknown> {
tab_id: number;
position_code: string;
position_name: string;
main_title: string;
sub_title: string;
qrcode_id: number;
qrcode_name: string;
qrcode_url: string;
qrcode_status: ChannelQRCodeStatus;
channel_code: string;
qrcode_employee_name: string;
display_status: OfficialSiteTabStatus;
sort_order: number;
agent_count: number;
created_at: string;
operations?: string[];
}
export interface OfficialSiteTabListQuery {
keyword?: string;
display_status?: OfficialSiteTabStatus;
page: number;
page_size: number;
}
export interface OfficialSiteTabListResponse extends PaginatedResponse<OfficialSiteTabListItem> {}
export interface CreateOfficialSiteTabPayload {
position_code: string;
position_name: string;
qrcode_id: string;
main_title: string;
sub_title: string;
display_status: OfficialSiteTabStatus;
sort_order: number;
}
export interface CreateOfficialSiteTabResponse {
tab_id: string;
position_code: string;
position_name: string;
qrcode_id: string;
main_title: string;
sub_title: string;
created_at: string;
}
export interface UpdateOfficialSiteTabPayload {
position_code: string;
position_name: string;
qrcode_id: string;
main_title: string;
sub_title: string;
display_status: OfficialSiteTabStatus;
sort_order: number;
}
export interface UpdateOfficialSiteTabResponse {
success: boolean;
updated_at: string;
}
export interface DeleteOfficialSiteTabResponse {
success: boolean;
deleted_at: string;
cleaned_agent_configs: number;
}
export interface UpdateOfficialSiteTabStatusPayload {
display_status: OfficialSiteTabStatus;
reason?: string;
}
export interface UpdateOfficialSiteTabStatusResponse {
success: boolean;
previous_status: OfficialSiteTabStatus;
updated_at: string;
}
export interface AvailableOfficialSiteQRCodeQuery {
position_code?: string;
}
export interface AvailableOfficialSiteQRCodeItem {
qrcode_id: number;
qrcode_name: string;
channel_code: string;
employee_name: string;
position_name: string;
status: ChannelQRCodeStatus;
}
export interface AvailableOfficialSiteQRCodeResponse {
list: AvailableOfficialSiteQRCodeItem[];
}
export interface OfficialSiteTabDetail {
tab_id: number;
position_code: string;
position_name: string;
qrcode_id: number;
qrcode_name: string;
channel_code: string;
employee_name: string;
qrcode_employee_name: string;
employee_role_text: string;
main_title: string;
sub_title: string;
display_status: OfficialSiteTabStatus;
sort_order: number;
}
interface RawTabDetailResponse {
tab_id?: number;
position_code?: string;
position_name?: string;
qrcode_id?: number;
qrcode_name?: string;
channel_qrcode_name?: string;
channel_code?: string;
employee_name?: string;
qrcode_employee_name?: string;
employee_role_text?: string;
steward_name?: string;
steward_role?: string;
main_title?: string;
sub_title?: string;
display_status?: OfficialSiteTabStatus;
sort_order?: number;
}
function adaptTabDetailResponse(raw: RawTabDetailResponse): OfficialSiteTabDetail {
return {
tab_id: raw.tab_id ?? 0,
position_code: raw.position_code ?? '',
position_name: raw.position_name ?? '',
qrcode_id: raw.qrcode_id ?? 0,
qrcode_name: raw.qrcode_name ?? raw.channel_qrcode_name ?? '',
channel_code: raw.channel_code ?? '',
employee_name: raw.employee_name ?? raw.steward_name ?? '',
qrcode_employee_name: raw.qrcode_employee_name ?? '',
employee_role_text: raw.employee_role_text ?? raw.steward_role ?? '',
main_title: raw.main_title ?? '',
sub_title: raw.sub_title ?? '',
display_status: raw.display_status ?? 'disable',
sort_order: raw.sort_order ?? 0,
};
}
/**
* 根据展示状态推断可用操作
* - enable 状态: 可上架、编辑、下架
* - disable 状态: 可编辑、上架、删除
*/
function inferTabOperations(displayStatus: OfficialSiteTabStatus): string[] {
return displayStatus === 'enable'
? ['disable']
: ['enable'];
}
/**
* 为列表项填充默认的 operations 字段
* 如果后端返回空数组,前端也会根据状态推断
*/
function fillTabListItem(item: Partial<OfficialSiteTabListItem>): OfficialSiteTabListItem {
const displayStatus = item.display_status ?? 'enable';
const operations = Array.isArray(item.operations) && item.operations.length > 0
? item.operations
: inferTabOperations(displayStatus);
return {
tab_id: item.tab_id ?? 0,
position_code: item.position_code ?? '',
position_name: item.position_name ?? '',
main_title: item.main_title ?? '',
sub_title: item.sub_title ?? '',
qrcode_id: item.qrcode_id ?? 0,
qrcode_name: item.qrcode_name ?? '',
qrcode_url: item.qrcode_url ?? '',
qrcode_status: item.qrcode_status ?? 'enable',
channel_code: item.channel_code ?? '',
qrcode_employee_name: item.qrcode_employee_name ?? '',
display_status: displayStatus,
sort_order: item.sort_order ?? 0,
agent_count: item.agent_count ?? 0,
created_at: item.created_at ?? '',
operations,
};
}
export async function getOfficialSiteTabList(query: OfficialSiteTabListQuery): Promise<OfficialSiteTabListResponse> {
const response = await apiClient.get<OfficialSiteTabListResponse>('/official-site/tabs', { params: query });
return {
...response,
list: response.list.map(fillTabListItem),
};
}
export async function createOfficialSiteTab(payload: CreateOfficialSiteTabPayload): Promise<CreateOfficialSiteTabResponse> {
return apiClient.post<CreateOfficialSiteTabResponse>('/official-site/tabs', payload);
}
export async function updateOfficialSiteTab(tabId: number, payload: UpdateOfficialSiteTabPayload): Promise<UpdateOfficialSiteTabResponse> {
return apiClient.put<UpdateOfficialSiteTabResponse>(`/official-site/tabs/${tabId}`, payload);
}
export async function deleteOfficialSiteTab(tabId: number): Promise<DeleteOfficialSiteTabResponse> {
return apiClient.delete<DeleteOfficialSiteTabResponse>(`/official-site/tabs/${tabId}`, undefined);
}
export async function updateOfficialSiteTabStatus(tabId: number, payload: UpdateOfficialSiteTabStatusPayload): Promise<UpdateOfficialSiteTabStatusResponse> {
return apiClient.put<UpdateOfficialSiteTabStatusResponse>(`/official-site/tabs/${tabId}/status`, payload);
}
export async function getAvailableQRCodes(query?: AvailableOfficialSiteQRCodeQuery): Promise<AvailableOfficialSiteQRCodeResponse> {
const params = query?.position_code ? { params: query } : undefined;
return apiClient.get<AvailableOfficialSiteQRCodeResponse>('/official-site/tabs/qrcodes/available', params);
}
export async function getOfficialSiteTabDetail(tabId: number): Promise<OfficialSiteTabDetail> {
const raw = await apiClient.get<RawTabDetailResponse>(`/official-site/tabs/${tabId}`);
return adaptTabDetailResponse(raw);
}