@quantabit/segment-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/index.cjs +1317 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.esm.js +1285 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/styles.css +1 -0
- package/package.json +83 -0
- package/types/index.d.ts +40 -0
|
@@ -0,0 +1,1285 @@
|
|
|
1
|
+
import { BaseApiClient } from '@quantabit/sdk-config';
|
|
2
|
+
import React, { useState, useCallback, useMemo, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Segment SDK - API 客户端
|
|
6
|
+
* 用户分群系统后端接口封装
|
|
7
|
+
*
|
|
8
|
+
* 使用 BaseApiClient 基类简化代码
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 用户分群 API 客户端
|
|
14
|
+
*/
|
|
15
|
+
class SegmentApiClient extends BaseApiClient {
|
|
16
|
+
constructor(config = {}) {
|
|
17
|
+
super('/segment', config);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ============ 分群管理 ============
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 获取分群列表
|
|
24
|
+
* @param {Object} params - 查询参数
|
|
25
|
+
*/
|
|
26
|
+
async getSegments(params = {}) {
|
|
27
|
+
return this.get('/list', params);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 获取分群详情
|
|
32
|
+
* @param {string} segmentId - 分群 ID
|
|
33
|
+
*/
|
|
34
|
+
async getSegment(segmentId) {
|
|
35
|
+
return this.get(`/${segmentId}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 创建分群(管理员)
|
|
40
|
+
* @param {Object} data - 分群数据
|
|
41
|
+
*/
|
|
42
|
+
async createSegment(data) {
|
|
43
|
+
return this.post('/', data);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 更新分群(管理员)
|
|
48
|
+
* @param {string} segmentId - 分群 ID
|
|
49
|
+
* @param {Object} updates - 更新数据
|
|
50
|
+
*/
|
|
51
|
+
async updateSegment(segmentId, updates) {
|
|
52
|
+
return this.put(`/${segmentId}`, updates);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 删除分群(管理员)
|
|
57
|
+
* @param {string} segmentId - 分群 ID
|
|
58
|
+
*/
|
|
59
|
+
async deleteSegment(segmentId) {
|
|
60
|
+
return this.delete(`/${segmentId}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ============ 分群规则 ============
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 获取分群规则
|
|
67
|
+
* @param {string} segmentId - 分群 ID
|
|
68
|
+
*/
|
|
69
|
+
async getSegmentRules(segmentId) {
|
|
70
|
+
return this.get(`/${segmentId}/rules`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 更新分群规则(管理员)
|
|
75
|
+
* @param {string} segmentId - 分群 ID
|
|
76
|
+
* @param {Object} rules - 规则配置
|
|
77
|
+
*/
|
|
78
|
+
async updateSegmentRules(segmentId, rules) {
|
|
79
|
+
return this.put(`/${segmentId}/rules`, rules);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 预估分群规模
|
|
84
|
+
* @param {Object} rules - 规则配置
|
|
85
|
+
*/
|
|
86
|
+
async estimateSize(rules) {
|
|
87
|
+
return this.post('/estimate', rules);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ============ 分群用户 ============
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 获取分群用户
|
|
94
|
+
* @param {string} segmentId - 分群 ID
|
|
95
|
+
* @param {Object} params - 查询参数
|
|
96
|
+
*/
|
|
97
|
+
async getSegmentUsers(segmentId, params = {}) {
|
|
98
|
+
return this.get(`/${segmentId}/users`, params);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 手动添加用户到分群(管理员)
|
|
103
|
+
* @param {string} segmentId - 分群 ID
|
|
104
|
+
* @param {string[]} userIds - 用户 ID 列表
|
|
105
|
+
*/
|
|
106
|
+
async addUsersToSegment(segmentId, userIds) {
|
|
107
|
+
return this.post(`/${segmentId}/users`, {
|
|
108
|
+
user_ids: userIds
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 从分群移除用户(管理员)
|
|
114
|
+
* @param {string} segmentId - 分群 ID
|
|
115
|
+
* @param {string[]} userIds - 用户 ID 列表
|
|
116
|
+
*/
|
|
117
|
+
async removeUsersFromSegment(segmentId, userIds) {
|
|
118
|
+
return this.post(`/${segmentId}/users/remove`, {
|
|
119
|
+
user_ids: userIds
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 检查用户是否在分群中
|
|
125
|
+
* @param {string} segmentId - 分群 ID
|
|
126
|
+
* @param {string} userId - 用户 ID
|
|
127
|
+
*/
|
|
128
|
+
async checkUserInSegment(segmentId, userId) {
|
|
129
|
+
return this.get(`/${segmentId}/users/${userId}/check`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ============ 分群同步 ============
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 刷新分群(重新计算)
|
|
136
|
+
* @param {string} segmentId - 分群 ID
|
|
137
|
+
*/
|
|
138
|
+
async refreshSegment(segmentId) {
|
|
139
|
+
return this.post(`/${segmentId}/refresh`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 获取刷新状态
|
|
144
|
+
* @param {string} segmentId - 分群 ID
|
|
145
|
+
*/
|
|
146
|
+
async getRefreshStatus(segmentId) {
|
|
147
|
+
return this.get(`/${segmentId}/refresh/status`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ============ 我的分群 ============
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 获取我所属的分群
|
|
154
|
+
*/
|
|
155
|
+
async getMySegments() {
|
|
156
|
+
return this.get('/my');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ============ 统计 ============
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 获取分群统计
|
|
163
|
+
* @param {string} segmentId - 分群 ID
|
|
164
|
+
* @param {Object} params - 统计参数
|
|
165
|
+
*/
|
|
166
|
+
async getSegmentStats(segmentId, params = {}) {
|
|
167
|
+
return this.get(`/${segmentId}/stats`, params);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 获取分群趋势
|
|
172
|
+
* @param {string} segmentId - 分群 ID
|
|
173
|
+
* @param {Object} params - 查询参数
|
|
174
|
+
*/
|
|
175
|
+
async getSegmentTrend(segmentId, params = {}) {
|
|
176
|
+
return this.get(`/${segmentId}/trend`, params);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 导出分群用户
|
|
181
|
+
* @param {string} segmentId - 分群 ID
|
|
182
|
+
* @param {Object} options - 导出选项
|
|
183
|
+
*/
|
|
184
|
+
async exportSegmentUsers(segmentId, options = {}) {
|
|
185
|
+
return this.post(`/${segmentId}/export`, options);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ============ 兼容方法 ============
|
|
189
|
+
|
|
190
|
+
async estimate(rules) {
|
|
191
|
+
return this.estimateSize(rules);
|
|
192
|
+
}
|
|
193
|
+
async cloneSegment(segmentId, data) {
|
|
194
|
+
return this.post(`/${segmentId}/clone`, data);
|
|
195
|
+
}
|
|
196
|
+
async getProperties() {
|
|
197
|
+
return this.get('/properties');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// 创建默认实例
|
|
202
|
+
const segmentApi = new SegmentApiClient();
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Segment SDK - 类型定义
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
// 分群类型
|
|
209
|
+
const SegmentType = {
|
|
210
|
+
STATIC: 'static',
|
|
211
|
+
// 静态分群
|
|
212
|
+
DYNAMIC: 'dynamic',
|
|
213
|
+
// 动态分群
|
|
214
|
+
REALTIME: 'realtime' // 实时分群
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// 属性类型
|
|
218
|
+
const PropertyType = {
|
|
219
|
+
USER: 'user',
|
|
220
|
+
BEHAVIOR: 'behavior',
|
|
221
|
+
TRANSACTION: 'transaction',
|
|
222
|
+
DEVICE: 'device'
|
|
223
|
+
};
|
|
224
|
+
const ConditionOperator = {};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Segment SDK - 国际化
|
|
228
|
+
* 用户分群多语言支持
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];
|
|
232
|
+
const messages = {
|
|
233
|
+
zh: {
|
|
234
|
+
// 分群基础
|
|
235
|
+
segment: '分群',
|
|
236
|
+
segments: '用户分群',
|
|
237
|
+
createSegment: '创建分群',
|
|
238
|
+
editSegment: '编辑分群',
|
|
239
|
+
deleteSegment: '删除分群',
|
|
240
|
+
segmentName: '分群名称',
|
|
241
|
+
segmentDesc: '分群描述',
|
|
242
|
+
// 分群类型
|
|
243
|
+
static: '静态分群',
|
|
244
|
+
dynamic: '动态分群',
|
|
245
|
+
realtime: '实时分群',
|
|
246
|
+
// 条件
|
|
247
|
+
condition: '条件',
|
|
248
|
+
conditions: '条件',
|
|
249
|
+
addCondition: '添加条件',
|
|
250
|
+
removeCondition: '移除条件',
|
|
251
|
+
and: '且',
|
|
252
|
+
or: '或',
|
|
253
|
+
// 属性
|
|
254
|
+
property: '属性',
|
|
255
|
+
userProperty: '用户属性',
|
|
256
|
+
eventProperty: '事件属性',
|
|
257
|
+
// 运算符
|
|
258
|
+
equals: '等于',
|
|
259
|
+
notEquals: '不等于',
|
|
260
|
+
contains: '包含',
|
|
261
|
+
notContains: '不包含',
|
|
262
|
+
startsWith: '开头是',
|
|
263
|
+
endsWith: '结尾是',
|
|
264
|
+
greaterThan: '大于',
|
|
265
|
+
lessThan: '小于',
|
|
266
|
+
between: '介于',
|
|
267
|
+
in: '在列表中',
|
|
268
|
+
notIn: '不在列表中',
|
|
269
|
+
isSet: '已设置',
|
|
270
|
+
isNotSet: '未设置',
|
|
271
|
+
// 时间
|
|
272
|
+
inLast: '在过去',
|
|
273
|
+
days: '天',
|
|
274
|
+
weeks: '周',
|
|
275
|
+
months: '月',
|
|
276
|
+
// 行为
|
|
277
|
+
didEvent: '执行过事件',
|
|
278
|
+
didNotEvent: '未执行事件',
|
|
279
|
+
eventCount: '事件次数',
|
|
280
|
+
firstTime: '首次',
|
|
281
|
+
lastTime: '最近',
|
|
282
|
+
// 分群结果
|
|
283
|
+
users: '用户数',
|
|
284
|
+
percentage: '占比',
|
|
285
|
+
estimated: '预估',
|
|
286
|
+
calculating: '计算中...',
|
|
287
|
+
// 操作
|
|
288
|
+
save: '保存',
|
|
289
|
+
cancel: '取消',
|
|
290
|
+
preview: '预览',
|
|
291
|
+
refresh: '刷新',
|
|
292
|
+
export: '导出',
|
|
293
|
+
clone: '复制',
|
|
294
|
+
// 使用场景
|
|
295
|
+
useFor: '用于',
|
|
296
|
+
marketing: '营销活动',
|
|
297
|
+
analytics: '数据分析',
|
|
298
|
+
targeting: '精准投放',
|
|
299
|
+
// 状态
|
|
300
|
+
active: '活跃',
|
|
301
|
+
inactive: '未激活',
|
|
302
|
+
processing: '处理中',
|
|
303
|
+
ready: '就绪',
|
|
304
|
+
// 提示
|
|
305
|
+
noResults: '暂无结果',
|
|
306
|
+
loading: '加载中...',
|
|
307
|
+
error: '加载失败',
|
|
308
|
+
saved: '保存成功',
|
|
309
|
+
deleted: '删除成功',
|
|
310
|
+
// 预设分群
|
|
311
|
+
allUsers: '全部用户',
|
|
312
|
+
newUsers: '新用户',
|
|
313
|
+
activeUsers: '活跃用户',
|
|
314
|
+
churned: '流失用户',
|
|
315
|
+
highValue: '高价值用户',
|
|
316
|
+
atRisk: '流失风险用户'
|
|
317
|
+
},
|
|
318
|
+
en: {
|
|
319
|
+
segment: 'Segment',
|
|
320
|
+
segments: 'Segments',
|
|
321
|
+
createSegment: 'Create Segment',
|
|
322
|
+
editSegment: 'Edit Segment',
|
|
323
|
+
deleteSegment: 'Delete Segment',
|
|
324
|
+
segmentName: 'Segment Name',
|
|
325
|
+
segmentDesc: 'Description',
|
|
326
|
+
static: 'Static',
|
|
327
|
+
dynamic: 'Dynamic',
|
|
328
|
+
realtime: 'Realtime',
|
|
329
|
+
condition: 'Condition',
|
|
330
|
+
conditions: 'Conditions',
|
|
331
|
+
addCondition: 'Add Condition',
|
|
332
|
+
removeCondition: 'Remove',
|
|
333
|
+
and: 'AND',
|
|
334
|
+
or: 'OR',
|
|
335
|
+
property: 'Property',
|
|
336
|
+
userProperty: 'User Property',
|
|
337
|
+
eventProperty: 'Event Property',
|
|
338
|
+
equals: 'equals',
|
|
339
|
+
notEquals: 'not equals',
|
|
340
|
+
contains: 'contains',
|
|
341
|
+
notContains: 'not contains',
|
|
342
|
+
startsWith: 'starts with',
|
|
343
|
+
endsWith: 'ends with',
|
|
344
|
+
greaterThan: 'greater than',
|
|
345
|
+
lessThan: 'less than',
|
|
346
|
+
between: 'between',
|
|
347
|
+
in: 'in',
|
|
348
|
+
notIn: 'not in',
|
|
349
|
+
isSet: 'is set',
|
|
350
|
+
isNotSet: 'is not set',
|
|
351
|
+
inLast: 'in last',
|
|
352
|
+
days: 'days',
|
|
353
|
+
weeks: 'weeks',
|
|
354
|
+
months: 'months',
|
|
355
|
+
didEvent: 'did event',
|
|
356
|
+
didNotEvent: 'did not event',
|
|
357
|
+
eventCount: 'event count',
|
|
358
|
+
firstTime: 'first time',
|
|
359
|
+
lastTime: 'last time',
|
|
360
|
+
users: 'Users',
|
|
361
|
+
percentage: 'Percentage',
|
|
362
|
+
estimated: 'Estimated',
|
|
363
|
+
calculating: 'Calculating...',
|
|
364
|
+
save: 'Save',
|
|
365
|
+
cancel: 'Cancel',
|
|
366
|
+
preview: 'Preview',
|
|
367
|
+
refresh: 'Refresh',
|
|
368
|
+
export: 'Export',
|
|
369
|
+
clone: 'Clone',
|
|
370
|
+
useFor: 'Use for',
|
|
371
|
+
marketing: 'Marketing',
|
|
372
|
+
analytics: 'Analytics',
|
|
373
|
+
targeting: 'Targeting',
|
|
374
|
+
active: 'Active',
|
|
375
|
+
inactive: 'Inactive',
|
|
376
|
+
processing: 'Processing',
|
|
377
|
+
ready: 'Ready',
|
|
378
|
+
noResults: 'No Results',
|
|
379
|
+
loading: 'Loading...',
|
|
380
|
+
error: 'Error',
|
|
381
|
+
saved: 'Saved',
|
|
382
|
+
deleted: 'Deleted',
|
|
383
|
+
allUsers: 'All Users',
|
|
384
|
+
newUsers: 'New Users',
|
|
385
|
+
activeUsers: 'Active Users',
|
|
386
|
+
churned: 'Churned',
|
|
387
|
+
highValue: 'High Value',
|
|
388
|
+
atRisk: 'At Risk'
|
|
389
|
+
},
|
|
390
|
+
ja: {
|
|
391
|
+
segment: 'セグメント',
|
|
392
|
+
segments: 'セグメント',
|
|
393
|
+
createSegment: 'セグメントを作成',
|
|
394
|
+
editSegment: 'セグメントを編集',
|
|
395
|
+
deleteSegment: 'セグメントを削除',
|
|
396
|
+
segmentName: 'セグメント名',
|
|
397
|
+
segmentDesc: '説明',
|
|
398
|
+
static: '静的',
|
|
399
|
+
dynamic: '動的',
|
|
400
|
+
realtime: 'リアルタイム',
|
|
401
|
+
condition: '条件',
|
|
402
|
+
conditions: '条件',
|
|
403
|
+
addCondition: '条件を追加',
|
|
404
|
+
removeCondition: '削除',
|
|
405
|
+
and: 'かつ',
|
|
406
|
+
or: 'または',
|
|
407
|
+
property: 'プロパティ',
|
|
408
|
+
userProperty: 'ユーザープロパティ',
|
|
409
|
+
eventProperty: 'イベントプロパティ',
|
|
410
|
+
equals: '等しい',
|
|
411
|
+
notEquals: '等しくない',
|
|
412
|
+
contains: '含む',
|
|
413
|
+
notContains: '含まない',
|
|
414
|
+
startsWith: 'で始まる',
|
|
415
|
+
endsWith: 'で終わる',
|
|
416
|
+
greaterThan: 'より大きい',
|
|
417
|
+
lessThan: 'より小さい',
|
|
418
|
+
between: 'の間',
|
|
419
|
+
in: 'に含まれる',
|
|
420
|
+
notIn: 'に含まれない',
|
|
421
|
+
isSet: '設定済み',
|
|
422
|
+
isNotSet: '未設定',
|
|
423
|
+
inLast: '過去',
|
|
424
|
+
days: '日間',
|
|
425
|
+
weeks: '週間',
|
|
426
|
+
months: 'ヶ月間',
|
|
427
|
+
didEvent: 'イベント実行済み',
|
|
428
|
+
didNotEvent: 'イベント未実行',
|
|
429
|
+
eventCount: 'イベント回数',
|
|
430
|
+
firstTime: '初回',
|
|
431
|
+
lastTime: '最終',
|
|
432
|
+
users: 'ユーザー数',
|
|
433
|
+
percentage: '割合',
|
|
434
|
+
estimated: '推定',
|
|
435
|
+
calculating: '計算中...',
|
|
436
|
+
save: '保存',
|
|
437
|
+
cancel: 'キャンセル',
|
|
438
|
+
preview: 'プレビュー',
|
|
439
|
+
refresh: '更新',
|
|
440
|
+
export: 'エクスポート',
|
|
441
|
+
clone: '複製',
|
|
442
|
+
useFor: '用途',
|
|
443
|
+
marketing: 'マーケティング',
|
|
444
|
+
analytics: '分析',
|
|
445
|
+
targeting: 'ターゲティング',
|
|
446
|
+
active: 'アクティブ',
|
|
447
|
+
inactive: '非アクティブ',
|
|
448
|
+
processing: '処理中',
|
|
449
|
+
ready: '準備完了',
|
|
450
|
+
noResults: '結果なし',
|
|
451
|
+
loading: '読み込み中...',
|
|
452
|
+
error: 'エラー',
|
|
453
|
+
saved: '保存しました',
|
|
454
|
+
deleted: '削除しました',
|
|
455
|
+
allUsers: '全ユーザー',
|
|
456
|
+
newUsers: '新規ユーザー',
|
|
457
|
+
activeUsers: 'アクティブユーザー',
|
|
458
|
+
churned: '離脱ユーザー',
|
|
459
|
+
highValue: '高価値ユーザー',
|
|
460
|
+
atRisk: 'リスクユーザー'
|
|
461
|
+
},
|
|
462
|
+
ko: {
|
|
463
|
+
segment: '세그먼트',
|
|
464
|
+
segments: '세그먼트',
|
|
465
|
+
createSegment: '세그먼트 생성',
|
|
466
|
+
editSegment: '세그먼트 편집',
|
|
467
|
+
deleteSegment: '세그먼트 삭제',
|
|
468
|
+
segmentName: '세그먼트 이름',
|
|
469
|
+
segmentDesc: '설명',
|
|
470
|
+
static: '정적',
|
|
471
|
+
dynamic: '동적',
|
|
472
|
+
realtime: '실시간',
|
|
473
|
+
condition: '조건',
|
|
474
|
+
conditions: '조건',
|
|
475
|
+
addCondition: '조건 추가',
|
|
476
|
+
removeCondition: '제거',
|
|
477
|
+
and: '그리고',
|
|
478
|
+
or: '또는',
|
|
479
|
+
property: '속성',
|
|
480
|
+
userProperty: '사용자 속성',
|
|
481
|
+
eventProperty: '이벤트 속성',
|
|
482
|
+
equals: '같음',
|
|
483
|
+
notEquals: '같지 않음',
|
|
484
|
+
contains: '포함',
|
|
485
|
+
notContains: '포함하지 않음',
|
|
486
|
+
startsWith: '로 시작',
|
|
487
|
+
endsWith: '로 끝남',
|
|
488
|
+
greaterThan: '보다 큼',
|
|
489
|
+
lessThan: '보다 작음',
|
|
490
|
+
between: '사이',
|
|
491
|
+
in: '포함됨',
|
|
492
|
+
notIn: '포함되지 않음',
|
|
493
|
+
isSet: '설정됨',
|
|
494
|
+
isNotSet: '설정되지 않음',
|
|
495
|
+
inLast: '최근',
|
|
496
|
+
days: '일',
|
|
497
|
+
weeks: '주',
|
|
498
|
+
months: '개월',
|
|
499
|
+
didEvent: '이벤트 수행',
|
|
500
|
+
didNotEvent: '이벤트 미수행',
|
|
501
|
+
eventCount: '이벤트 횟수',
|
|
502
|
+
firstTime: '처음',
|
|
503
|
+
lastTime: '마지막',
|
|
504
|
+
users: '사용자 수',
|
|
505
|
+
percentage: '비율',
|
|
506
|
+
estimated: '예상',
|
|
507
|
+
calculating: '계산 중...',
|
|
508
|
+
save: '저장',
|
|
509
|
+
cancel: '취소',
|
|
510
|
+
preview: '미리보기',
|
|
511
|
+
refresh: '새로고침',
|
|
512
|
+
export: '내보내기',
|
|
513
|
+
clone: '복제',
|
|
514
|
+
useFor: '용도',
|
|
515
|
+
marketing: '마케팅',
|
|
516
|
+
analytics: '분석',
|
|
517
|
+
targeting: '타겟팅',
|
|
518
|
+
active: '활성',
|
|
519
|
+
inactive: '비활성',
|
|
520
|
+
processing: '처리 중',
|
|
521
|
+
ready: '준비 완료',
|
|
522
|
+
noResults: '결과 없음',
|
|
523
|
+
loading: '로딩 중...',
|
|
524
|
+
error: '오류',
|
|
525
|
+
saved: '저장됨',
|
|
526
|
+
deleted: '삭제됨',
|
|
527
|
+
allUsers: '전체 사용자',
|
|
528
|
+
newUsers: '신규 사용자',
|
|
529
|
+
activeUsers: '활성 사용자',
|
|
530
|
+
churned: '이탈 사용자',
|
|
531
|
+
highValue: '고가치 사용자',
|
|
532
|
+
atRisk: '위험 사용자'
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
let currentLanguage = 'zh';
|
|
536
|
+
function setLanguage(lang) {
|
|
537
|
+
if (SUPPORTED_LANGUAGES.includes(lang)) currentLanguage = lang;
|
|
538
|
+
}
|
|
539
|
+
function getLanguage() {
|
|
540
|
+
return currentLanguage;
|
|
541
|
+
}
|
|
542
|
+
function t(key) {
|
|
543
|
+
return (messages[currentLanguage] || messages.en)[key] || key;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Segment SDK - React Hooks
|
|
548
|
+
* 用户分群相关的状态管理
|
|
549
|
+
*/
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* 获取分群列表
|
|
554
|
+
*/
|
|
555
|
+
function useSegments(params = {}) {
|
|
556
|
+
const [segments, setSegments] = useState([]);
|
|
557
|
+
const [loading, setLoading] = useState(true);
|
|
558
|
+
const [error, setError] = useState(null);
|
|
559
|
+
const fetchSegments = useCallback(async () => {
|
|
560
|
+
try {
|
|
561
|
+
setLoading(true);
|
|
562
|
+
const response = await segmentApi.getSegments(params);
|
|
563
|
+
setSegments(response.data || []);
|
|
564
|
+
setError(null);
|
|
565
|
+
} catch (err) {
|
|
566
|
+
setError(err.message);
|
|
567
|
+
} finally {
|
|
568
|
+
setLoading(false);
|
|
569
|
+
}
|
|
570
|
+
}, [params]);
|
|
571
|
+
useEffect(() => {
|
|
572
|
+
fetchSegments();
|
|
573
|
+
}, []);
|
|
574
|
+
return {
|
|
575
|
+
segments,
|
|
576
|
+
loading,
|
|
577
|
+
error,
|
|
578
|
+
refresh: fetchSegments
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* 获取单个分群详情
|
|
584
|
+
*/
|
|
585
|
+
function useSegment(segmentId) {
|
|
586
|
+
const [segment, setSegment] = useState(null);
|
|
587
|
+
const [loading, setLoading] = useState(true);
|
|
588
|
+
const [error, setError] = useState(null);
|
|
589
|
+
const fetchSegment = useCallback(async () => {
|
|
590
|
+
if (!segmentId) return;
|
|
591
|
+
try {
|
|
592
|
+
setLoading(true);
|
|
593
|
+
const response = await segmentApi.getSegment(segmentId);
|
|
594
|
+
setSegment(response);
|
|
595
|
+
setError(null);
|
|
596
|
+
} catch (err) {
|
|
597
|
+
setError(err.message);
|
|
598
|
+
} finally {
|
|
599
|
+
setLoading(false);
|
|
600
|
+
}
|
|
601
|
+
}, [segmentId]);
|
|
602
|
+
useEffect(() => {
|
|
603
|
+
fetchSegment();
|
|
604
|
+
}, [fetchSegment]);
|
|
605
|
+
return {
|
|
606
|
+
segment,
|
|
607
|
+
loading,
|
|
608
|
+
error,
|
|
609
|
+
refresh: fetchSegment
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* 分群预估
|
|
615
|
+
*/
|
|
616
|
+
function useSegmentEstimate(conditions) {
|
|
617
|
+
const [estimate, setEstimate] = useState(null);
|
|
618
|
+
const [loading, setLoading] = useState(false);
|
|
619
|
+
const [error, setError] = useState(null);
|
|
620
|
+
const calculateEstimate = useCallback(async () => {
|
|
621
|
+
if (!conditions || conditions.length === 0) {
|
|
622
|
+
setEstimate(null);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
try {
|
|
626
|
+
setLoading(true);
|
|
627
|
+
const response = await segmentApi.estimate({
|
|
628
|
+
conditions
|
|
629
|
+
});
|
|
630
|
+
setEstimate(response);
|
|
631
|
+
setError(null);
|
|
632
|
+
} catch (err) {
|
|
633
|
+
setError(err.message);
|
|
634
|
+
} finally {
|
|
635
|
+
setLoading(false);
|
|
636
|
+
}
|
|
637
|
+
}, [conditions]);
|
|
638
|
+
useEffect(() => {
|
|
639
|
+
const debounce = setTimeout(() => {
|
|
640
|
+
calculateEstimate();
|
|
641
|
+
}, 500);
|
|
642
|
+
return () => clearTimeout(debounce);
|
|
643
|
+
}, [calculateEstimate]);
|
|
644
|
+
return {
|
|
645
|
+
estimate,
|
|
646
|
+
loading,
|
|
647
|
+
error,
|
|
648
|
+
refresh: calculateEstimate
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* 分群用户列表
|
|
654
|
+
*/
|
|
655
|
+
function useSegmentUsers(segmentId, options = {}) {
|
|
656
|
+
const [users, setUsers] = useState([]);
|
|
657
|
+
const [loading, setLoading] = useState(true);
|
|
658
|
+
const [error, setError] = useState(null);
|
|
659
|
+
const [pagination, setPagination] = useState({
|
|
660
|
+
page: 1,
|
|
661
|
+
pageSize: options.pageSize || 20,
|
|
662
|
+
total: 0
|
|
663
|
+
});
|
|
664
|
+
const fetchUsers = useCallback(async (page = 1) => {
|
|
665
|
+
if (!segmentId) return;
|
|
666
|
+
try {
|
|
667
|
+
setLoading(true);
|
|
668
|
+
const response = await segmentApi.getSegmentUsers(segmentId, {
|
|
669
|
+
page,
|
|
670
|
+
pageSize: pagination.pageSize
|
|
671
|
+
});
|
|
672
|
+
setUsers(response.data || []);
|
|
673
|
+
setPagination(prev => ({
|
|
674
|
+
...prev,
|
|
675
|
+
page,
|
|
676
|
+
total: response.total || 0
|
|
677
|
+
}));
|
|
678
|
+
setError(null);
|
|
679
|
+
} catch (err) {
|
|
680
|
+
setError(err.message);
|
|
681
|
+
} finally {
|
|
682
|
+
setLoading(false);
|
|
683
|
+
}
|
|
684
|
+
}, [segmentId, pagination.pageSize]);
|
|
685
|
+
useEffect(() => {
|
|
686
|
+
fetchUsers(1);
|
|
687
|
+
}, [segmentId]);
|
|
688
|
+
return {
|
|
689
|
+
users,
|
|
690
|
+
loading,
|
|
691
|
+
error,
|
|
692
|
+
pagination,
|
|
693
|
+
fetchPage: fetchUsers,
|
|
694
|
+
refresh: () => fetchUsers(pagination.page)
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* 分群操作(创建、更新、删除)
|
|
700
|
+
*/
|
|
701
|
+
function useSegmentActions() {
|
|
702
|
+
const [loading, setLoading] = useState(false);
|
|
703
|
+
const [error, setError] = useState(null);
|
|
704
|
+
const createSegment = useCallback(async data => {
|
|
705
|
+
try {
|
|
706
|
+
setLoading(true);
|
|
707
|
+
setError(null);
|
|
708
|
+
const result = await segmentApi.createSegment(data);
|
|
709
|
+
return result;
|
|
710
|
+
} catch (err) {
|
|
711
|
+
setError(err.message);
|
|
712
|
+
throw err;
|
|
713
|
+
} finally {
|
|
714
|
+
setLoading(false);
|
|
715
|
+
}
|
|
716
|
+
}, []);
|
|
717
|
+
const updateSegment = useCallback(async (segmentId, data) => {
|
|
718
|
+
try {
|
|
719
|
+
setLoading(true);
|
|
720
|
+
setError(null);
|
|
721
|
+
const result = await segmentApi.updateSegment(segmentId, data);
|
|
722
|
+
return result;
|
|
723
|
+
} catch (err) {
|
|
724
|
+
setError(err.message);
|
|
725
|
+
throw err;
|
|
726
|
+
} finally {
|
|
727
|
+
setLoading(false);
|
|
728
|
+
}
|
|
729
|
+
}, []);
|
|
730
|
+
const deleteSegment = useCallback(async segmentId => {
|
|
731
|
+
try {
|
|
732
|
+
setLoading(true);
|
|
733
|
+
setError(null);
|
|
734
|
+
await segmentApi.deleteSegment(segmentId);
|
|
735
|
+
} catch (err) {
|
|
736
|
+
setError(err.message);
|
|
737
|
+
throw err;
|
|
738
|
+
} finally {
|
|
739
|
+
setLoading(false);
|
|
740
|
+
}
|
|
741
|
+
}, []);
|
|
742
|
+
const cloneSegment = useCallback(async (segmentId, newName) => {
|
|
743
|
+
try {
|
|
744
|
+
setLoading(true);
|
|
745
|
+
setError(null);
|
|
746
|
+
const result = await segmentApi.cloneSegment(segmentId, {
|
|
747
|
+
name: newName
|
|
748
|
+
});
|
|
749
|
+
return result;
|
|
750
|
+
} catch (err) {
|
|
751
|
+
setError(err.message);
|
|
752
|
+
throw err;
|
|
753
|
+
} finally {
|
|
754
|
+
setLoading(false);
|
|
755
|
+
}
|
|
756
|
+
}, []);
|
|
757
|
+
return {
|
|
758
|
+
loading,
|
|
759
|
+
error,
|
|
760
|
+
createSegment,
|
|
761
|
+
updateSegment,
|
|
762
|
+
deleteSegment,
|
|
763
|
+
cloneSegment
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* 条件构建器状态管理
|
|
769
|
+
*/
|
|
770
|
+
function useConditionBuilder(initialConditions = []) {
|
|
771
|
+
const [conditions, setConditions] = useState(initialConditions);
|
|
772
|
+
const addCondition = useCallback(condition => {
|
|
773
|
+
setConditions(prev => [...prev, {
|
|
774
|
+
id: Date.now().toString(),
|
|
775
|
+
...condition
|
|
776
|
+
}]);
|
|
777
|
+
}, []);
|
|
778
|
+
const updateCondition = useCallback((id, updates) => {
|
|
779
|
+
setConditions(prev => prev.map(c => c.id === id ? {
|
|
780
|
+
...c,
|
|
781
|
+
...updates
|
|
782
|
+
} : c));
|
|
783
|
+
}, []);
|
|
784
|
+
const removeCondition = useCallback(id => {
|
|
785
|
+
setConditions(prev => prev.filter(c => c.id !== id));
|
|
786
|
+
}, []);
|
|
787
|
+
const clearConditions = useCallback(() => {
|
|
788
|
+
setConditions([]);
|
|
789
|
+
}, []);
|
|
790
|
+
const moveCondition = useCallback((fromIndex, toIndex) => {
|
|
791
|
+
setConditions(prev => {
|
|
792
|
+
const result = [...prev];
|
|
793
|
+
const [removed] = result.splice(fromIndex, 1);
|
|
794
|
+
result.splice(toIndex, 0, removed);
|
|
795
|
+
return result;
|
|
796
|
+
});
|
|
797
|
+
}, []);
|
|
798
|
+
return {
|
|
799
|
+
conditions,
|
|
800
|
+
setConditions,
|
|
801
|
+
addCondition,
|
|
802
|
+
updateCondition,
|
|
803
|
+
removeCondition,
|
|
804
|
+
clearConditions,
|
|
805
|
+
moveCondition
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* 获取可用属性
|
|
811
|
+
*/
|
|
812
|
+
function useSegmentProperties() {
|
|
813
|
+
const [properties, setProperties] = useState({
|
|
814
|
+
user: [],
|
|
815
|
+
event: []
|
|
816
|
+
});
|
|
817
|
+
const [loading, setLoading] = useState(true);
|
|
818
|
+
const [error, setError] = useState(null);
|
|
819
|
+
useEffect(() => {
|
|
820
|
+
const fetchProperties = async () => {
|
|
821
|
+
try {
|
|
822
|
+
const response = await segmentApi.getProperties();
|
|
823
|
+
setProperties(response);
|
|
824
|
+
setError(null);
|
|
825
|
+
} catch (err) {
|
|
826
|
+
setError(err.message);
|
|
827
|
+
} finally {
|
|
828
|
+
setLoading(false);
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
fetchProperties();
|
|
832
|
+
}, []);
|
|
833
|
+
return {
|
|
834
|
+
properties,
|
|
835
|
+
loading,
|
|
836
|
+
error
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* 预设分群
|
|
842
|
+
*/
|
|
843
|
+
function usePresetSegments() {
|
|
844
|
+
const presets = useMemo(() => [{
|
|
845
|
+
id: 'all',
|
|
846
|
+
name: 'allUsers',
|
|
847
|
+
icon: '👥'
|
|
848
|
+
}, {
|
|
849
|
+
id: 'new',
|
|
850
|
+
name: 'newUsers',
|
|
851
|
+
icon: '🆕'
|
|
852
|
+
}, {
|
|
853
|
+
id: 'active',
|
|
854
|
+
name: 'activeUsers',
|
|
855
|
+
icon: '✅'
|
|
856
|
+
}, {
|
|
857
|
+
id: 'churned',
|
|
858
|
+
name: 'churned',
|
|
859
|
+
icon: '👋'
|
|
860
|
+
}, {
|
|
861
|
+
id: 'highValue',
|
|
862
|
+
name: 'highValue',
|
|
863
|
+
icon: '💎'
|
|
864
|
+
}, {
|
|
865
|
+
id: 'atRisk',
|
|
866
|
+
name: 'atRisk',
|
|
867
|
+
icon: '⚠️'
|
|
868
|
+
}], []);
|
|
869
|
+
return {
|
|
870
|
+
presets
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Segment SDK - React 组件
|
|
876
|
+
* 用户分群可视化组件
|
|
877
|
+
*/
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* 分群卡片
|
|
882
|
+
*/
|
|
883
|
+
function SegmentCard({
|
|
884
|
+
segment,
|
|
885
|
+
onClick,
|
|
886
|
+
onEdit,
|
|
887
|
+
onDelete,
|
|
888
|
+
onClone
|
|
889
|
+
}) {
|
|
890
|
+
const statusClass = segment.status === 'active' ? 'active' : 'inactive';
|
|
891
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
892
|
+
className: "eco-segment-card",
|
|
893
|
+
onClick: () => onClick?.(segment)
|
|
894
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
895
|
+
className: "eco-segment-card-header"
|
|
896
|
+
}, /*#__PURE__*/React.createElement("h4", {
|
|
897
|
+
className: "eco-segment-card-title"
|
|
898
|
+
}, segment.name), /*#__PURE__*/React.createElement("span", {
|
|
899
|
+
className: `eco-segment-status eco-segment-status-${statusClass}`
|
|
900
|
+
}, t(segment.status))), segment.description && /*#__PURE__*/React.createElement("p", {
|
|
901
|
+
className: "eco-segment-card-desc"
|
|
902
|
+
}, segment.description), /*#__PURE__*/React.createElement("div", {
|
|
903
|
+
className: "eco-segment-card-stats"
|
|
904
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
905
|
+
className: "eco-segment-stat"
|
|
906
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
907
|
+
className: "eco-segment-stat-value"
|
|
908
|
+
}, segment.userCount?.toLocaleString() || 0), /*#__PURE__*/React.createElement("span", {
|
|
909
|
+
className: "eco-segment-stat-label"
|
|
910
|
+
}, t('users'))), /*#__PURE__*/React.createElement("div", {
|
|
911
|
+
className: "eco-segment-stat"
|
|
912
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
913
|
+
className: "eco-segment-stat-value"
|
|
914
|
+
}, segment.conditionCount || 0), /*#__PURE__*/React.createElement("span", {
|
|
915
|
+
className: "eco-segment-stat-label"
|
|
916
|
+
}, t('conditions')))), /*#__PURE__*/React.createElement("div", {
|
|
917
|
+
className: "eco-segment-card-type"
|
|
918
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
919
|
+
className: `eco-segment-type-badge eco-segment-type-${segment.type}`
|
|
920
|
+
}, t(segment.type))), /*#__PURE__*/React.createElement("div", {
|
|
921
|
+
className: "eco-segment-card-actions",
|
|
922
|
+
onClick: e => e.stopPropagation()
|
|
923
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
924
|
+
className: "eco-segment-action-btn",
|
|
925
|
+
onClick: () => onEdit?.(segment)
|
|
926
|
+
}, "\u270F\uFE0F"), /*#__PURE__*/React.createElement("button", {
|
|
927
|
+
className: "eco-segment-action-btn",
|
|
928
|
+
onClick: () => onClone?.(segment)
|
|
929
|
+
}, "\uD83D\uDCCB"), /*#__PURE__*/React.createElement("button", {
|
|
930
|
+
className: "eco-segment-action-btn danger",
|
|
931
|
+
onClick: () => onDelete?.(segment)
|
|
932
|
+
}, "\uD83D\uDDD1\uFE0F")));
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* 分群列表
|
|
937
|
+
*/
|
|
938
|
+
function SegmentList({
|
|
939
|
+
onSelect,
|
|
940
|
+
onEdit,
|
|
941
|
+
onDelete
|
|
942
|
+
}) {
|
|
943
|
+
const {
|
|
944
|
+
segments,
|
|
945
|
+
loading,
|
|
946
|
+
error
|
|
947
|
+
} = useSegments();
|
|
948
|
+
const {
|
|
949
|
+
presets
|
|
950
|
+
} = usePresetSegments();
|
|
951
|
+
if (loading) {
|
|
952
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
953
|
+
className: "eco-segment-loading"
|
|
954
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
955
|
+
className: "eco-segment-spinner"
|
|
956
|
+
}), /*#__PURE__*/React.createElement("span", null, t('loading')));
|
|
957
|
+
}
|
|
958
|
+
if (error) {
|
|
959
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
960
|
+
className: "eco-segment-error"
|
|
961
|
+
}, error);
|
|
962
|
+
}
|
|
963
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
964
|
+
className: "eco-segment-list"
|
|
965
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
966
|
+
className: "eco-segment-presets"
|
|
967
|
+
}, /*#__PURE__*/React.createElement("h4", null, t('segments')), /*#__PURE__*/React.createElement("div", {
|
|
968
|
+
className: "eco-segment-preset-grid"
|
|
969
|
+
}, presets.map(preset => /*#__PURE__*/React.createElement("button", {
|
|
970
|
+
key: preset.id,
|
|
971
|
+
className: "eco-segment-preset-btn",
|
|
972
|
+
onClick: () => onSelect?.({
|
|
973
|
+
id: preset.id,
|
|
974
|
+
name: t(preset.name)
|
|
975
|
+
})
|
|
976
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
977
|
+
className: "eco-segment-preset-icon"
|
|
978
|
+
}, preset.icon), /*#__PURE__*/React.createElement("span", null, t(preset.name)))))), /*#__PURE__*/React.createElement("div", {
|
|
979
|
+
className: "eco-segment-custom"
|
|
980
|
+
}, /*#__PURE__*/React.createElement("h4", null, t('segments')), segments.length === 0 ? /*#__PURE__*/React.createElement("div", {
|
|
981
|
+
className: "eco-segment-empty"
|
|
982
|
+
}, t('noResults')) : /*#__PURE__*/React.createElement("div", {
|
|
983
|
+
className: "eco-segment-grid"
|
|
984
|
+
}, segments.map(segment => /*#__PURE__*/React.createElement(SegmentCard, {
|
|
985
|
+
key: segment.id,
|
|
986
|
+
segment: segment,
|
|
987
|
+
onClick: onSelect,
|
|
988
|
+
onEdit: onEdit,
|
|
989
|
+
onDelete: onDelete
|
|
990
|
+
})))));
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* 条件选择器
|
|
995
|
+
*/
|
|
996
|
+
function ConditionSelector({
|
|
997
|
+
condition,
|
|
998
|
+
onChange,
|
|
999
|
+
onRemove,
|
|
1000
|
+
properties
|
|
1001
|
+
}) {
|
|
1002
|
+
const operators = [{
|
|
1003
|
+
id: 'equals',
|
|
1004
|
+
label: t('equals')
|
|
1005
|
+
}, {
|
|
1006
|
+
id: 'notEquals',
|
|
1007
|
+
label: t('notEquals')
|
|
1008
|
+
}, {
|
|
1009
|
+
id: 'contains',
|
|
1010
|
+
label: t('contains')
|
|
1011
|
+
}, {
|
|
1012
|
+
id: 'greaterThan',
|
|
1013
|
+
label: t('greaterThan')
|
|
1014
|
+
}, {
|
|
1015
|
+
id: 'lessThan',
|
|
1016
|
+
label: t('lessThan')
|
|
1017
|
+
}, {
|
|
1018
|
+
id: 'between',
|
|
1019
|
+
label: t('between')
|
|
1020
|
+
}, {
|
|
1021
|
+
id: 'in',
|
|
1022
|
+
label: t('in')
|
|
1023
|
+
}, {
|
|
1024
|
+
id: 'isSet',
|
|
1025
|
+
label: t('isSet')
|
|
1026
|
+
}, {
|
|
1027
|
+
id: 'isNotSet',
|
|
1028
|
+
label: t('isNotSet')
|
|
1029
|
+
}];
|
|
1030
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1031
|
+
className: "eco-segment-condition"
|
|
1032
|
+
}, /*#__PURE__*/React.createElement("select", {
|
|
1033
|
+
className: "eco-segment-select",
|
|
1034
|
+
value: condition.propertyType || 'user',
|
|
1035
|
+
onChange: e => onChange({
|
|
1036
|
+
...condition,
|
|
1037
|
+
propertyType: e.target.value
|
|
1038
|
+
})
|
|
1039
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
1040
|
+
value: "user"
|
|
1041
|
+
}, t('userProperty')), /*#__PURE__*/React.createElement("option", {
|
|
1042
|
+
value: "event"
|
|
1043
|
+
}, t('eventProperty'))), /*#__PURE__*/React.createElement("select", {
|
|
1044
|
+
className: "eco-segment-select",
|
|
1045
|
+
value: condition.property || '',
|
|
1046
|
+
onChange: e => onChange({
|
|
1047
|
+
...condition,
|
|
1048
|
+
property: e.target.value
|
|
1049
|
+
})
|
|
1050
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
1051
|
+
value: ""
|
|
1052
|
+
}, t('property')), (properties?.[condition.propertyType] || []).map(prop => /*#__PURE__*/React.createElement("option", {
|
|
1053
|
+
key: prop.id,
|
|
1054
|
+
value: prop.id
|
|
1055
|
+
}, prop.name))), /*#__PURE__*/React.createElement("select", {
|
|
1056
|
+
className: "eco-segment-select",
|
|
1057
|
+
value: condition.operator || 'equals',
|
|
1058
|
+
onChange: e => onChange({
|
|
1059
|
+
...condition,
|
|
1060
|
+
operator: e.target.value
|
|
1061
|
+
})
|
|
1062
|
+
}, operators.map(op => /*#__PURE__*/React.createElement("option", {
|
|
1063
|
+
key: op.id,
|
|
1064
|
+
value: op.id
|
|
1065
|
+
}, op.label))), !['isSet', 'isNotSet'].includes(condition.operator) && /*#__PURE__*/React.createElement("input", {
|
|
1066
|
+
type: "text",
|
|
1067
|
+
className: "eco-segment-input",
|
|
1068
|
+
value: condition.value || '',
|
|
1069
|
+
onChange: e => onChange({
|
|
1070
|
+
...condition,
|
|
1071
|
+
value: e.target.value
|
|
1072
|
+
}),
|
|
1073
|
+
placeholder: "Value"
|
|
1074
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
1075
|
+
className: "eco-segment-remove-btn",
|
|
1076
|
+
onClick: onRemove
|
|
1077
|
+
}, "\u2715"));
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* 分群构建器
|
|
1082
|
+
*/
|
|
1083
|
+
function SegmentBuilder({
|
|
1084
|
+
initialData = null,
|
|
1085
|
+
onSave,
|
|
1086
|
+
onCancel
|
|
1087
|
+
}) {
|
|
1088
|
+
const [name, setName] = useState(initialData?.name || '');
|
|
1089
|
+
const [description, setDescription] = useState(initialData?.description || '');
|
|
1090
|
+
const [type, setType] = useState(initialData?.type || 'dynamic');
|
|
1091
|
+
const {
|
|
1092
|
+
conditions,
|
|
1093
|
+
addCondition,
|
|
1094
|
+
updateCondition,
|
|
1095
|
+
removeCondition
|
|
1096
|
+
} = useConditionBuilder(initialData?.conditions || []);
|
|
1097
|
+
const {
|
|
1098
|
+
estimate,
|
|
1099
|
+
loading: estimating
|
|
1100
|
+
} = useSegmentEstimate(conditions);
|
|
1101
|
+
const {
|
|
1102
|
+
properties,
|
|
1103
|
+
loading: loadingProps
|
|
1104
|
+
} = useSegmentProperties();
|
|
1105
|
+
const {
|
|
1106
|
+
loading: saving,
|
|
1107
|
+
createSegment,
|
|
1108
|
+
updateSegment
|
|
1109
|
+
} = useSegmentActions();
|
|
1110
|
+
const handleSave = async () => {
|
|
1111
|
+
try {
|
|
1112
|
+
const data = {
|
|
1113
|
+
name,
|
|
1114
|
+
description,
|
|
1115
|
+
type,
|
|
1116
|
+
conditions
|
|
1117
|
+
};
|
|
1118
|
+
if (initialData?.id) {
|
|
1119
|
+
await updateSegment(initialData.id, data);
|
|
1120
|
+
} else {
|
|
1121
|
+
await createSegment(data);
|
|
1122
|
+
}
|
|
1123
|
+
onSave?.();
|
|
1124
|
+
} catch (err) {
|
|
1125
|
+
console.error('Save error:', err);
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
const handleAddCondition = () => {
|
|
1129
|
+
addCondition({
|
|
1130
|
+
propertyType: 'user',
|
|
1131
|
+
property: '',
|
|
1132
|
+
operator: 'equals',
|
|
1133
|
+
value: ''
|
|
1134
|
+
});
|
|
1135
|
+
};
|
|
1136
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1137
|
+
className: "eco-segment-builder"
|
|
1138
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1139
|
+
className: "eco-segment-builder-header"
|
|
1140
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
1141
|
+
type: "text",
|
|
1142
|
+
className: "eco-segment-name-input",
|
|
1143
|
+
placeholder: t('segmentName'),
|
|
1144
|
+
value: name,
|
|
1145
|
+
onChange: e => setName(e.target.value)
|
|
1146
|
+
}), /*#__PURE__*/React.createElement("textarea", {
|
|
1147
|
+
className: "eco-segment-desc-input",
|
|
1148
|
+
placeholder: t('segmentDesc'),
|
|
1149
|
+
value: description,
|
|
1150
|
+
onChange: e => setDescription(e.target.value),
|
|
1151
|
+
rows: 2
|
|
1152
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1153
|
+
className: "eco-segment-type-selector"
|
|
1154
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
1155
|
+
className: type === 'static' ? 'active' : ''
|
|
1156
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
1157
|
+
type: "radio",
|
|
1158
|
+
value: "static",
|
|
1159
|
+
checked: type === 'static',
|
|
1160
|
+
onChange: () => setType('static')
|
|
1161
|
+
}), t('static')), /*#__PURE__*/React.createElement("label", {
|
|
1162
|
+
className: type === 'dynamic' ? 'active' : ''
|
|
1163
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
1164
|
+
type: "radio",
|
|
1165
|
+
value: "dynamic",
|
|
1166
|
+
checked: type === 'dynamic',
|
|
1167
|
+
onChange: () => setType('dynamic')
|
|
1168
|
+
}), t('dynamic')), /*#__PURE__*/React.createElement("label", {
|
|
1169
|
+
className: type === 'realtime' ? 'active' : ''
|
|
1170
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
1171
|
+
type: "radio",
|
|
1172
|
+
value: "realtime",
|
|
1173
|
+
checked: type === 'realtime',
|
|
1174
|
+
onChange: () => setType('realtime')
|
|
1175
|
+
}), t('realtime'))), /*#__PURE__*/React.createElement("div", {
|
|
1176
|
+
className: "eco-segment-conditions"
|
|
1177
|
+
}, /*#__PURE__*/React.createElement("h4", null, t('conditions')), conditions.length === 0 ? /*#__PURE__*/React.createElement("div", {
|
|
1178
|
+
className: "eco-segment-empty-conditions"
|
|
1179
|
+
}, t('addCondition')) : /*#__PURE__*/React.createElement("div", {
|
|
1180
|
+
className: "eco-segment-condition-list"
|
|
1181
|
+
}, conditions.map((condition, index) => /*#__PURE__*/React.createElement("div", {
|
|
1182
|
+
key: condition.id,
|
|
1183
|
+
className: "eco-segment-condition-row"
|
|
1184
|
+
}, index > 0 && /*#__PURE__*/React.createElement("span", {
|
|
1185
|
+
className: "eco-segment-logic"
|
|
1186
|
+
}, t('and')), /*#__PURE__*/React.createElement(ConditionSelector, {
|
|
1187
|
+
condition: condition,
|
|
1188
|
+
onChange: updated => updateCondition(condition.id, updated),
|
|
1189
|
+
onRemove: () => removeCondition(condition.id),
|
|
1190
|
+
properties: properties
|
|
1191
|
+
})))), /*#__PURE__*/React.createElement("button", {
|
|
1192
|
+
className: "eco-segment-add-condition-btn",
|
|
1193
|
+
onClick: handleAddCondition
|
|
1194
|
+
}, "+ ", t('addCondition'))), /*#__PURE__*/React.createElement("div", {
|
|
1195
|
+
className: "eco-segment-estimate"
|
|
1196
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1197
|
+
className: "eco-segment-estimate-content"
|
|
1198
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
1199
|
+
className: "eco-segment-estimate-label"
|
|
1200
|
+
}, t('estimated'), " ", t('users'), ":"), /*#__PURE__*/React.createElement("span", {
|
|
1201
|
+
className: "eco-segment-estimate-value"
|
|
1202
|
+
}, estimating ? t('calculating') : estimate?.userCount?.toLocaleString() || 0)), estimate?.percentage && /*#__PURE__*/React.createElement("span", {
|
|
1203
|
+
className: "eco-segment-estimate-percentage"
|
|
1204
|
+
}, "(", (estimate.percentage * 100).toFixed(1), "% ", t('percentage'), ")")), /*#__PURE__*/React.createElement("div", {
|
|
1205
|
+
className: "eco-segment-builder-actions"
|
|
1206
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
1207
|
+
className: "eco-segment-btn",
|
|
1208
|
+
onClick: onCancel
|
|
1209
|
+
}, t('cancel')), /*#__PURE__*/React.createElement("button", {
|
|
1210
|
+
className: "eco-segment-btn eco-segment-btn-secondary",
|
|
1211
|
+
onClick: handleAddCondition
|
|
1212
|
+
}, t('preview')), /*#__PURE__*/React.createElement("button", {
|
|
1213
|
+
className: "eco-segment-btn eco-segment-btn-primary",
|
|
1214
|
+
onClick: handleSave,
|
|
1215
|
+
disabled: saving || !name
|
|
1216
|
+
}, saving ? t('loading') : t('save'))));
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* 分群选择下拉框
|
|
1221
|
+
*/
|
|
1222
|
+
function SegmentSelect({
|
|
1223
|
+
value,
|
|
1224
|
+
onChange,
|
|
1225
|
+
placeholder
|
|
1226
|
+
}) {
|
|
1227
|
+
const {
|
|
1228
|
+
segments,
|
|
1229
|
+
loading
|
|
1230
|
+
} = useSegments();
|
|
1231
|
+
const {
|
|
1232
|
+
presets
|
|
1233
|
+
} = usePresetSegments();
|
|
1234
|
+
return /*#__PURE__*/React.createElement("select", {
|
|
1235
|
+
className: "eco-segment-dropdown",
|
|
1236
|
+
value: value || '',
|
|
1237
|
+
onChange: e => onChange(e.target.value),
|
|
1238
|
+
disabled: loading
|
|
1239
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
1240
|
+
value: ""
|
|
1241
|
+
}, placeholder || t('segment')), /*#__PURE__*/React.createElement("optgroup", {
|
|
1242
|
+
label: t('segments')
|
|
1243
|
+
}, presets.map(preset => /*#__PURE__*/React.createElement("option", {
|
|
1244
|
+
key: preset.id,
|
|
1245
|
+
value: preset.id
|
|
1246
|
+
}, preset.icon, " ", t(preset.name)))), segments.length > 0 && /*#__PURE__*/React.createElement("optgroup", {
|
|
1247
|
+
label: t('segments')
|
|
1248
|
+
}, segments.map(segment => /*#__PURE__*/React.createElement("option", {
|
|
1249
|
+
key: segment.id,
|
|
1250
|
+
value: segment.id
|
|
1251
|
+
}, segment.name))));
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* 用户数量显示
|
|
1256
|
+
*/
|
|
1257
|
+
function UserCountBadge({
|
|
1258
|
+
segmentId
|
|
1259
|
+
}) {
|
|
1260
|
+
const {
|
|
1261
|
+
estimate,
|
|
1262
|
+
loading
|
|
1263
|
+
} = useSegmentEstimate([{
|
|
1264
|
+
segmentId
|
|
1265
|
+
}]);
|
|
1266
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
1267
|
+
className: "eco-segment-user-count"
|
|
1268
|
+
}, loading ? '...' : estimate?.userCount?.toLocaleString() || 0, " ", t('users'));
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
/**
|
|
1272
|
+
* @quantabit/segment-sdk
|
|
1273
|
+
* User Segmentation SDK - Full Version
|
|
1274
|
+
*/
|
|
1275
|
+
|
|
1276
|
+
const getSegments = params => segmentApi.getSegments(params);
|
|
1277
|
+
const getSegment = segmentId => segmentApi.getSegment(segmentId);
|
|
1278
|
+
const createSegment = data => segmentApi.createSegment(data);
|
|
1279
|
+
const updateSegment = (segmentId, updates) => segmentApi.updateSegment(segmentId, updates);
|
|
1280
|
+
const deleteSegment = segmentId => segmentApi.deleteSegment(segmentId);
|
|
1281
|
+
const estimate = rules => segmentApi.estimate(rules);
|
|
1282
|
+
const getSegmentUsers = (segmentId, params) => segmentApi.getSegmentUsers(segmentId, params);
|
|
1283
|
+
|
|
1284
|
+
export { ConditionOperator, ConditionSelector, PropertyType, SUPPORTED_LANGUAGES, SegmentApiClient, SegmentBuilder, SegmentCard, SegmentList, SegmentSelect, SegmentType, UserCountBadge, createSegment, deleteSegment, estimate, getLanguage, getSegment, getSegmentUsers, getSegments, messages, segmentApi, setLanguage, t, updateSegment, useConditionBuilder, usePresetSegments, useSegment, useSegmentActions, useSegmentEstimate, useSegmentProperties, useSegmentUsers, useSegments };
|
|
1285
|
+
//# sourceMappingURL=index.esm.js.map
|