@reglow/reglow 0.6.0 → 0.8.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/README.md +3 -1
- package/dist/reglow/common/errors.d.ts +1 -0
- package/dist/reglow/common/errors.js +1 -0
- package/dist/reglow/common/errors.js.map +1 -1
- package/dist/reglow/core/config.js +2 -2
- package/dist/reglow/core/config.js.map +1 -1
- package/dist/reglow/core/entities.d.ts +20 -0
- package/dist/reglow/core/models.d.ts +2 -0
- package/dist/reglow/core/models.js +1 -0
- package/dist/reglow/core/models.js.map +1 -1
- package/dist/reglow/modules/customer_service/controller.js +6 -0
- package/dist/reglow/modules/customer_service/controller.js.map +1 -1
- package/dist/reglow/modules/customer_service/repository.js +10 -0
- package/dist/reglow/modules/customer_service/repository.js.map +1 -1
- package/dist/reglow/modules/customer_service/schema.d.ts +20 -0
- package/dist/reglow/modules/customer_service/schema.js +21 -0
- package/dist/reglow/modules/customer_service/schema.js.map +1 -1
- package/dist/reglow/modules/customer_service/sdk_template.html +1523 -221
- package/dist/reglow/modules/customer_service/service.d.ts +10 -0
- package/dist/reglow/modules/customer_service/service.js +130 -1
- package/dist/reglow/modules/customer_service/service.js.map +1 -1
- package/dist/reglow/modules/region/controller.d.ts +6 -0
- package/dist/reglow/modules/region/controller.js +77 -0
- package/dist/reglow/modules/region/controller.js.map +1 -0
- package/dist/reglow/modules/region/controller_admin.d.ts +6 -0
- package/dist/reglow/modules/region/controller_admin.js +126 -0
- package/dist/reglow/modules/region/controller_admin.js.map +1 -0
- package/dist/reglow/modules/region/data/pcas.json +1 -0
- package/dist/reglow/modules/region/model.d.ts +22 -0
- package/dist/reglow/modules/region/model.js +9 -0
- package/dist/reglow/modules/region/model.js.map +1 -0
- package/dist/reglow/modules/region/repository.d.ts +22 -0
- package/dist/reglow/modules/region/repository.js +75 -0
- package/dist/reglow/modules/region/repository.js.map +1 -0
- package/dist/reglow/modules/region/router.d.ts +16 -0
- package/dist/reglow/modules/region/router.js +11 -0
- package/dist/reglow/modules/region/router.js.map +1 -0
- package/dist/reglow/modules/region/schema.d.ts +38 -0
- package/dist/reglow/modules/region/schema.js +33 -0
- package/dist/reglow/modules/region/schema.js.map +1 -0
- package/dist/reglow/modules/region/seed.d.ts +2 -0
- package/dist/reglow/modules/region/seed.js +101 -0
- package/dist/reglow/modules/region/seed.js.map +1 -0
- package/dist/reglow/modules/region/service.d.ts +28 -0
- package/dist/reglow/modules/region/service.js +88 -0
- package/dist/reglow/modules/region/service.js.map +1 -0
- package/dist/reglow/modules/user/controller.js +31 -6
- package/dist/reglow/modules/user/controller.js.map +1 -1
- package/dist/reglow/modules/user/controller_client.js +2 -0
- package/dist/reglow/modules/user/controller_client.js.map +1 -1
- package/dist/reglow/modules/user/repository.d.ts +2 -0
- package/dist/reglow/modules/user/repository.js +11 -0
- package/dist/reglow/modules/user/repository.js.map +1 -1
- package/dist/reglow/modules/user/schema.d.ts +21 -0
- package/dist/reglow/modules/user/schema.js +20 -0
- package/dist/reglow/modules/user/schema.js.map +1 -1
- package/dist/reglow/modules/user/service.d.ts +3 -1
- package/dist/reglow/modules/user/service.js +43 -0
- package/dist/reglow/modules/user/service.js.map +1 -1
- package/dist/reglow/scripts/init-data.js +1535 -222
- package/dist/reglow/scripts/init-data.js.map +1 -1
- package/dist/reglow/scripts/remove-business-menu.js +3 -3
- package/dist/reglow/scripts/remove-business-menu.js.map +1 -1
- package/dist/reglow/scripts/schema.js +23 -8
- package/dist/reglow/scripts/schema.js.map +1 -1
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.js +2 -2
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,15 +1,878 @@
|
|
|
1
|
-
<!-- ReglowAdmin 智能客服 SDK(
|
|
1
|
+
<!-- ReglowAdmin 智能客服 SDK(v5:单悬浮按钮 + 工具组合卡片 + 可拖拽聊天窗 + 知识库左伸缩文章/右聊天 + 反馈/返回顶部) -->
|
|
2
|
+
<style>
|
|
3
|
+
/* ========== 客服 SDK 作用域样式(rgl- 前缀,避免与宿主页面冲突) ========== */
|
|
4
|
+
#reglow-cs-bar,
|
|
5
|
+
#reglow-cs-bar *,
|
|
6
|
+
#reglow-cs-chat,
|
|
7
|
+
#reglow-cs-chat * {
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
font-family:
|
|
10
|
+
system-ui,
|
|
11
|
+
-apple-system,
|
|
12
|
+
"PingFang SC",
|
|
13
|
+
"Microsoft YaHei",
|
|
14
|
+
sans-serif;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* ========== 单个悬浮按钮 + 工具组合卡片 + 返回顶部 ========== */
|
|
18
|
+
#reglow-cs-bar {
|
|
19
|
+
position: fixed;
|
|
20
|
+
right: 16px;
|
|
21
|
+
bottom: 16px;
|
|
22
|
+
width: 56px;
|
|
23
|
+
height: 122px; /* 返回顶部槽位(56) + 间距(10) + 主按钮(56):主按钮下方始终预留一个自身大小的位置 */
|
|
24
|
+
z-index: 100000;
|
|
25
|
+
user-select: none;
|
|
26
|
+
touch-action: none;
|
|
27
|
+
--rgl-primary: #4f46e5;
|
|
28
|
+
}
|
|
29
|
+
.rgl-fab-main {
|
|
30
|
+
position: absolute;
|
|
31
|
+
left: 0;
|
|
32
|
+
bottom: 66px;
|
|
33
|
+
width: 56px;
|
|
34
|
+
height: 56px;
|
|
35
|
+
border-radius: 50%;
|
|
36
|
+
background: var(--rgl-primary, #4f46e5);
|
|
37
|
+
color: #fff;
|
|
38
|
+
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
border: none;
|
|
44
|
+
padding: 0;
|
|
45
|
+
transition:
|
|
46
|
+
transform 0.15s ease,
|
|
47
|
+
box-shadow 0.15s ease;
|
|
48
|
+
}
|
|
49
|
+
.rgl-fab-main:hover {
|
|
50
|
+
transform: scale(1.06);
|
|
51
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
|
|
52
|
+
}
|
|
53
|
+
/* 悬浮按钮流光效果:高光沿整个按钮面流动(常显,非 hover 触发) */
|
|
54
|
+
.rgl-fab-main::before {
|
|
55
|
+
content: "";
|
|
56
|
+
position: absolute;
|
|
57
|
+
inset: 0;
|
|
58
|
+
border-radius: 50%;
|
|
59
|
+
z-index: 0;
|
|
60
|
+
pointer-events: none;
|
|
61
|
+
background: conic-gradient(
|
|
62
|
+
from 0deg,
|
|
63
|
+
rgba(255, 255, 255, 0) 0deg,
|
|
64
|
+
rgba(255, 255, 255, 0) 265deg,
|
|
65
|
+
rgba(255, 255, 255, 0.55) 335deg,
|
|
66
|
+
rgba(255, 255, 255, 0) 360deg
|
|
67
|
+
);
|
|
68
|
+
animation: rglFabShine 30s linear infinite; /* 30 秒一圈 */
|
|
69
|
+
transition: opacity 0.25s ease;
|
|
70
|
+
}
|
|
71
|
+
/* 点击打开(显示 ×)时隐藏流光 */
|
|
72
|
+
.rgl-fab-main.rgl-open::before {
|
|
73
|
+
animation: none;
|
|
74
|
+
opacity: 0;
|
|
75
|
+
}
|
|
76
|
+
/* 图标保持在流光之上(红点保持 absolute 定位不变) */
|
|
77
|
+
#rgl-fab-icon {
|
|
78
|
+
position: relative;
|
|
79
|
+
z-index: 1;
|
|
80
|
+
}
|
|
81
|
+
.rgl-fab-badge {
|
|
82
|
+
z-index: 1;
|
|
83
|
+
}
|
|
84
|
+
@keyframes rglFabShine {
|
|
85
|
+
to {
|
|
86
|
+
transform: rotate(360deg);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
@media (prefers-reduced-motion: reduce) {
|
|
90
|
+
.rgl-fab-main::before {
|
|
91
|
+
animation: none;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/* 返回顶部(白底,滚动到页面底部时出现,占主按钮下方的预留槽位) */
|
|
95
|
+
.rgl-backtop {
|
|
96
|
+
position: absolute;
|
|
97
|
+
left: 0;
|
|
98
|
+
bottom: 0;
|
|
99
|
+
width: 56px;
|
|
100
|
+
height: 56px;
|
|
101
|
+
border-radius: 50%;
|
|
102
|
+
background: #fff;
|
|
103
|
+
color: var(--rgl-primary, #4f46e5);
|
|
104
|
+
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.16);
|
|
105
|
+
cursor: pointer;
|
|
106
|
+
display: none;
|
|
107
|
+
align-items: center;
|
|
108
|
+
justify-content: center;
|
|
109
|
+
border: none;
|
|
110
|
+
padding: 0;
|
|
111
|
+
transition:
|
|
112
|
+
transform 0.15s ease,
|
|
113
|
+
box-shadow 0.15s ease;
|
|
114
|
+
}
|
|
115
|
+
.rgl-backtop:hover {
|
|
116
|
+
transform: scale(1.06);
|
|
117
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.24);
|
|
118
|
+
}
|
|
119
|
+
.rgl-fab-badge {
|
|
120
|
+
position: absolute;
|
|
121
|
+
top: -4px;
|
|
122
|
+
right: -4px;
|
|
123
|
+
min-width: 18px;
|
|
124
|
+
height: 18px;
|
|
125
|
+
border-radius: 9px;
|
|
126
|
+
background: #ef4444;
|
|
127
|
+
color: #fff;
|
|
128
|
+
font-size: 11px;
|
|
129
|
+
font-weight: 600;
|
|
130
|
+
line-height: 18px;
|
|
131
|
+
text-align: center;
|
|
132
|
+
padding: 0 5px;
|
|
133
|
+
display: none;
|
|
134
|
+
}
|
|
135
|
+
/* 工具组合卡片(气泡卡片) */
|
|
136
|
+
.rgl-fab-pop {
|
|
137
|
+
position: absolute;
|
|
138
|
+
right: 0;
|
|
139
|
+
bottom: 136px; /* 容器高122 + 间距14,卡片紧贴主按钮上方 */
|
|
140
|
+
width: 168px; /* 主菜单窄;子视图(扫码/联系/反馈)由 JS 加宽到 248px */
|
|
141
|
+
background: #fff;
|
|
142
|
+
border-radius: 14px;
|
|
143
|
+
box-shadow: 0 14px 44px rgba(0, 0, 0, 0.2);
|
|
144
|
+
display: none;
|
|
145
|
+
overflow: hidden;
|
|
146
|
+
animation: rglPopUp 0.16s ease;
|
|
147
|
+
z-index: 100001;
|
|
148
|
+
}
|
|
149
|
+
.rgl-fab-pop::after {
|
|
150
|
+
content: "";
|
|
151
|
+
position: absolute;
|
|
152
|
+
right: 20px;
|
|
153
|
+
bottom: -6px;
|
|
154
|
+
transform: rotate(45deg);
|
|
155
|
+
width: 12px;
|
|
156
|
+
height: 12px;
|
|
157
|
+
background: #fff;
|
|
158
|
+
box-shadow: -2px 3px 5px rgba(0, 0, 0, 0.06);
|
|
159
|
+
}
|
|
160
|
+
@keyframes rglPopUp {
|
|
161
|
+
from {
|
|
162
|
+
opacity: 0;
|
|
163
|
+
transform: translateY(8px) scale(0.97);
|
|
164
|
+
}
|
|
165
|
+
to {
|
|
166
|
+
opacity: 1;
|
|
167
|
+
transform: none;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
.rgl-fab-pop-head {
|
|
171
|
+
padding: 12px 14px;
|
|
172
|
+
background: var(--rgl-primary, #4f46e5);
|
|
173
|
+
color: #fff;
|
|
174
|
+
display: flex;
|
|
175
|
+
align-items: center;
|
|
176
|
+
justify-content: space-between;
|
|
177
|
+
font-size: 14px;
|
|
178
|
+
font-weight: 600;
|
|
179
|
+
}
|
|
180
|
+
.rgl-fab-pop-close {
|
|
181
|
+
background: transparent;
|
|
182
|
+
border: none;
|
|
183
|
+
color: #fff;
|
|
184
|
+
font-size: 18px;
|
|
185
|
+
cursor: pointer;
|
|
186
|
+
line-height: 1;
|
|
187
|
+
padding: 0 4px;
|
|
188
|
+
opacity: 0.9;
|
|
189
|
+
}
|
|
190
|
+
.rgl-fab-pop-close:hover {
|
|
191
|
+
opacity: 1;
|
|
192
|
+
}
|
|
193
|
+
.rgl-fab-pop-body {
|
|
194
|
+
padding: 8px;
|
|
195
|
+
}
|
|
196
|
+
.rgl-fab-row {
|
|
197
|
+
display: flex;
|
|
198
|
+
align-items: center;
|
|
199
|
+
gap: 10px;
|
|
200
|
+
width: 100%;
|
|
201
|
+
padding: 10px 12px;
|
|
202
|
+
border: none;
|
|
203
|
+
background: transparent;
|
|
204
|
+
cursor: pointer;
|
|
205
|
+
border-radius: 9px;
|
|
206
|
+
font-size: 13.5px;
|
|
207
|
+
color: #333;
|
|
208
|
+
text-align: left;
|
|
209
|
+
transition: background 0.12s ease;
|
|
210
|
+
}
|
|
211
|
+
.rgl-fab-row:hover {
|
|
212
|
+
background: #f2f4f8;
|
|
213
|
+
}
|
|
214
|
+
.rgl-fab-row .rgl-fab-row-ico {
|
|
215
|
+
width: 30px;
|
|
216
|
+
height: 30px;
|
|
217
|
+
border-radius: 8px;
|
|
218
|
+
background: color-mix(in srgb, var(--rgl-primary, #4f46e5) 10%, #fff);
|
|
219
|
+
color: var(--rgl-primary, #4f46e5);
|
|
220
|
+
display: flex;
|
|
221
|
+
align-items: center;
|
|
222
|
+
justify-content: center;
|
|
223
|
+
flex-shrink: 0;
|
|
224
|
+
}
|
|
225
|
+
.rgl-fab-row .rgl-fab-row-label {
|
|
226
|
+
flex: 1;
|
|
227
|
+
}
|
|
228
|
+
.rgl-fab-row .rgl-fab-row-chevron {
|
|
229
|
+
color: #c3c7d0;
|
|
230
|
+
flex-shrink: 0;
|
|
231
|
+
}
|
|
232
|
+
.rgl-fab-pop-divider {
|
|
233
|
+
height: 1px;
|
|
234
|
+
background: #f0f1f4;
|
|
235
|
+
margin: 4px 8px;
|
|
236
|
+
}
|
|
237
|
+
.rgl-fab-back {
|
|
238
|
+
display: flex;
|
|
239
|
+
align-items: center;
|
|
240
|
+
gap: 6px;
|
|
241
|
+
border: none;
|
|
242
|
+
background: transparent;
|
|
243
|
+
color: var(--rgl-primary, #4f46e5);
|
|
244
|
+
font-size: 12.5px;
|
|
245
|
+
cursor: pointer;
|
|
246
|
+
padding: 6px 8px;
|
|
247
|
+
border-radius: 8px;
|
|
248
|
+
margin-bottom: 4px;
|
|
249
|
+
}
|
|
250
|
+
.rgl-fab-back:hover {
|
|
251
|
+
background: color-mix(in srgb, var(--rgl-primary, #4f46e5) 10%, #fff);
|
|
252
|
+
}
|
|
253
|
+
.rgl-fab-qr {
|
|
254
|
+
text-align: center;
|
|
255
|
+
padding: 6px 4px 10px;
|
|
256
|
+
}
|
|
257
|
+
.rgl-fab-qr img {
|
|
258
|
+
width: 148px;
|
|
259
|
+
height: 148px;
|
|
260
|
+
border-radius: 10px;
|
|
261
|
+
border: 1px solid #ececf0;
|
|
262
|
+
object-fit: contain;
|
|
263
|
+
background: #fff;
|
|
264
|
+
}
|
|
265
|
+
.rgl-fab-qr-title {
|
|
266
|
+
font-size: 14px;
|
|
267
|
+
font-weight: 600;
|
|
268
|
+
color: #222;
|
|
269
|
+
margin-top: 10px;
|
|
270
|
+
}
|
|
271
|
+
.rgl-fab-qr-desc {
|
|
272
|
+
font-size: 12.5px;
|
|
273
|
+
color: #777;
|
|
274
|
+
margin-top: 4px;
|
|
275
|
+
line-height: 1.6;
|
|
276
|
+
}
|
|
277
|
+
.rgl-contact-row {
|
|
278
|
+
display: flex;
|
|
279
|
+
align-items: flex-start;
|
|
280
|
+
gap: 10px;
|
|
281
|
+
text-align: left;
|
|
282
|
+
padding: 9px 4px;
|
|
283
|
+
border-bottom: 1px solid #f0f1f4;
|
|
284
|
+
}
|
|
285
|
+
.rgl-contact-row:last-child {
|
|
286
|
+
border-bottom: none;
|
|
287
|
+
}
|
|
288
|
+
.rgl-contact-row .rgl-contact-ico {
|
|
289
|
+
width: 30px;
|
|
290
|
+
height: 30px;
|
|
291
|
+
border-radius: 8px;
|
|
292
|
+
background: color-mix(in srgb, var(--rgl-primary, #4f46e5) 10%, #fff);
|
|
293
|
+
color: var(--rgl-primary, #4f46e5);
|
|
294
|
+
display: flex;
|
|
295
|
+
align-items: center;
|
|
296
|
+
justify-content: center;
|
|
297
|
+
flex-shrink: 0;
|
|
298
|
+
}
|
|
299
|
+
.rgl-contact-row .rgl-contact-label {
|
|
300
|
+
font-size: 11.5px;
|
|
301
|
+
color: #999;
|
|
302
|
+
}
|
|
303
|
+
.rgl-contact-row .rgl-contact-val {
|
|
304
|
+
font-size: 13px;
|
|
305
|
+
color: #222;
|
|
306
|
+
margin-top: 2px;
|
|
307
|
+
word-break: break-all;
|
|
308
|
+
}
|
|
309
|
+
.rgl-contact-row a.rgl-contact-val {
|
|
310
|
+
color: var(--rgl-primary, #4f46e5);
|
|
311
|
+
text-decoration: none;
|
|
312
|
+
}
|
|
313
|
+
/* 反馈 */
|
|
314
|
+
.rgl-fb-hd {
|
|
315
|
+
font-size: 13.5px;
|
|
316
|
+
color: #333;
|
|
317
|
+
font-weight: 600;
|
|
318
|
+
margin: 4px 0 12px;
|
|
319
|
+
text-align: center;
|
|
320
|
+
}
|
|
321
|
+
.rgl-fb-stars {
|
|
322
|
+
display: flex;
|
|
323
|
+
justify-content: center;
|
|
324
|
+
gap: 6px;
|
|
325
|
+
margin-bottom: 8px;
|
|
326
|
+
}
|
|
327
|
+
.rgl-fb-star {
|
|
328
|
+
cursor: pointer;
|
|
329
|
+
color: #d1d5db;
|
|
330
|
+
font-size: 26px;
|
|
331
|
+
line-height: 1;
|
|
332
|
+
transition:
|
|
333
|
+
transform 0.12s ease,
|
|
334
|
+
color 0.12s ease;
|
|
335
|
+
}
|
|
336
|
+
.rgl-fb-star:hover {
|
|
337
|
+
transform: scale(1.18);
|
|
338
|
+
}
|
|
339
|
+
.rgl-fb-star.on {
|
|
340
|
+
color: #f5a623;
|
|
341
|
+
}
|
|
342
|
+
.rgl-fb-labels {
|
|
343
|
+
display: flex;
|
|
344
|
+
justify-content: space-between;
|
|
345
|
+
font-size: 11px;
|
|
346
|
+
color: #aaa;
|
|
347
|
+
margin-bottom: 12px;
|
|
348
|
+
}
|
|
349
|
+
.rgl-fb-submit {
|
|
350
|
+
width: 100%;
|
|
351
|
+
padding: 8px 0;
|
|
352
|
+
border: none;
|
|
353
|
+
border-radius: 8px;
|
|
354
|
+
background: var(--rgl-primary, #4f46e5);
|
|
355
|
+
color: #fff;
|
|
356
|
+
font-size: 13px;
|
|
357
|
+
cursor: pointer;
|
|
358
|
+
}
|
|
359
|
+
.rgl-fb-submit:disabled {
|
|
360
|
+
opacity: 0.5;
|
|
361
|
+
cursor: not-allowed;
|
|
362
|
+
}
|
|
363
|
+
.rgl-fb-done {
|
|
364
|
+
text-align: center;
|
|
365
|
+
color: #2e7d32;
|
|
366
|
+
font-size: 14px;
|
|
367
|
+
padding: 26px 0;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/* ========== 聊天窗口(可拖拽,知识库向左伸缩不推移聊天) ========== */
|
|
371
|
+
#reglow-cs-chat {
|
|
372
|
+
position: fixed;
|
|
373
|
+
width: 400px;
|
|
374
|
+
max-width: calc(100vw - 24px);
|
|
375
|
+
height: 620px;
|
|
376
|
+
max-height: calc(100vh - 24px);
|
|
377
|
+
background: #fff;
|
|
378
|
+
border-radius: 16px;
|
|
379
|
+
box-shadow: 0 14px 48px rgba(0, 0, 0, 0.22);
|
|
380
|
+
display: none;
|
|
381
|
+
flex-direction: column;
|
|
382
|
+
overflow: hidden;
|
|
383
|
+
z-index: 100000;
|
|
384
|
+
--rgl-primary: #4f46e5;
|
|
385
|
+
}
|
|
386
|
+
.rgl-header {
|
|
387
|
+
padding: 10px 14px;
|
|
388
|
+
background: var(--rgl-primary, #4f46e5);
|
|
389
|
+
color: #fff;
|
|
390
|
+
display: flex;
|
|
391
|
+
align-items: center;
|
|
392
|
+
gap: 10px;
|
|
393
|
+
flex-shrink: 0;
|
|
394
|
+
cursor: grab;
|
|
395
|
+
touch-action: none;
|
|
396
|
+
user-select: none;
|
|
397
|
+
}
|
|
398
|
+
.rgl-header:active {
|
|
399
|
+
cursor: grabbing;
|
|
400
|
+
}
|
|
401
|
+
.rgl-header-avatar {
|
|
402
|
+
width: 34px;
|
|
403
|
+
height: 34px;
|
|
404
|
+
border-radius: 50%;
|
|
405
|
+
background: rgba(255, 255, 255, 0.25);
|
|
406
|
+
display: flex;
|
|
407
|
+
align-items: center;
|
|
408
|
+
justify-content: center;
|
|
409
|
+
font-size: 15px;
|
|
410
|
+
font-weight: 600;
|
|
411
|
+
flex-shrink: 0;
|
|
412
|
+
overflow: hidden;
|
|
413
|
+
background-size: cover;
|
|
414
|
+
background-position: center;
|
|
415
|
+
}
|
|
416
|
+
.rgl-header-info {
|
|
417
|
+
min-width: 0;
|
|
418
|
+
flex: 1;
|
|
419
|
+
}
|
|
420
|
+
.rgl-header-title {
|
|
421
|
+
font-size: 15px;
|
|
422
|
+
font-weight: 600;
|
|
423
|
+
line-height: 1.3;
|
|
424
|
+
white-space: nowrap;
|
|
425
|
+
overflow: hidden;
|
|
426
|
+
text-overflow: ellipsis;
|
|
427
|
+
}
|
|
428
|
+
.rgl-header-sub {
|
|
429
|
+
font-size: 11px;
|
|
430
|
+
opacity: 0.88;
|
|
431
|
+
line-height: 1.3;
|
|
432
|
+
white-space: nowrap;
|
|
433
|
+
overflow: hidden;
|
|
434
|
+
text-overflow: ellipsis;
|
|
435
|
+
}
|
|
436
|
+
.rgl-header-actions {
|
|
437
|
+
display: flex;
|
|
438
|
+
align-items: center;
|
|
439
|
+
gap: 2px;
|
|
440
|
+
flex-shrink: 0;
|
|
441
|
+
}
|
|
442
|
+
.rgl-icon-btn {
|
|
443
|
+
width: 30px;
|
|
444
|
+
height: 30px;
|
|
445
|
+
border-radius: 8px;
|
|
446
|
+
background: transparent;
|
|
447
|
+
border: none;
|
|
448
|
+
color: #fff;
|
|
449
|
+
cursor: pointer;
|
|
450
|
+
display: flex;
|
|
451
|
+
align-items: center;
|
|
452
|
+
justify-content: center;
|
|
453
|
+
opacity: 0.92;
|
|
454
|
+
transition: background 0.15s ease;
|
|
455
|
+
}
|
|
456
|
+
.rgl-icon-btn:hover {
|
|
457
|
+
background: rgba(255, 255, 255, 0.18);
|
|
458
|
+
opacity: 1;
|
|
459
|
+
}
|
|
460
|
+
.rgl-icon-btn.active {
|
|
461
|
+
background: rgba(255, 255, 255, 0.3);
|
|
462
|
+
opacity: 1;
|
|
463
|
+
}
|
|
464
|
+
.rgl-body {
|
|
465
|
+
flex: 1;
|
|
466
|
+
display: flex;
|
|
467
|
+
min-height: 0;
|
|
468
|
+
}
|
|
469
|
+
/* 聊天列(固定 400px,知识库在左侧伸缩,不推移聊天) */
|
|
470
|
+
.rgl-chat-col {
|
|
471
|
+
width: 400px;
|
|
472
|
+
min-width: 0;
|
|
473
|
+
flex-shrink: 0;
|
|
474
|
+
display: flex;
|
|
475
|
+
flex-direction: column;
|
|
476
|
+
}
|
|
477
|
+
.rgl-msgs {
|
|
478
|
+
flex: 1;
|
|
479
|
+
overflow-y: auto;
|
|
480
|
+
padding: 16px;
|
|
481
|
+
background: #f5f6f8;
|
|
482
|
+
}
|
|
483
|
+
.rgl-msgs::-webkit-scrollbar {
|
|
484
|
+
width: 5px;
|
|
485
|
+
}
|
|
486
|
+
.rgl-msgs::-webkit-scrollbar-thumb {
|
|
487
|
+
background: rgba(0, 0, 0, 0.18);
|
|
488
|
+
border-radius: 4px;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/* ========== 知识库面板(左侧,展开/收起) ========== */
|
|
492
|
+
.rgl-kb-pane {
|
|
493
|
+
width: 340px;
|
|
494
|
+
min-width: 0;
|
|
495
|
+
flex-shrink: 0;
|
|
496
|
+
border-right: 1px solid #ececf0;
|
|
497
|
+
background: #fafbfc;
|
|
498
|
+
display: none;
|
|
499
|
+
flex-direction: column;
|
|
500
|
+
min-height: 0;
|
|
501
|
+
}
|
|
502
|
+
.rgl-kb-toolbar {
|
|
503
|
+
padding: 10px 12px;
|
|
504
|
+
border-bottom: 1px solid #ececf0;
|
|
505
|
+
background: #fff;
|
|
506
|
+
flex-shrink: 0;
|
|
507
|
+
}
|
|
508
|
+
.rgl-kb-title {
|
|
509
|
+
font-size: 13px;
|
|
510
|
+
font-weight: 600;
|
|
511
|
+
color: #333;
|
|
512
|
+
display: block;
|
|
513
|
+
margin-bottom: 8px;
|
|
514
|
+
}
|
|
515
|
+
.rgl-kb-search {
|
|
516
|
+
width: 100%;
|
|
517
|
+
border: 1px solid #e3e4e8;
|
|
518
|
+
border-radius: 8px;
|
|
519
|
+
padding: 7px 10px;
|
|
520
|
+
font-size: 12px;
|
|
521
|
+
outline: none;
|
|
522
|
+
background: #f7f8fa;
|
|
523
|
+
}
|
|
524
|
+
.rgl-kb-search:focus {
|
|
525
|
+
border-color: var(--rgl-primary, #4f46e5);
|
|
526
|
+
background: #fff;
|
|
527
|
+
}
|
|
528
|
+
.rgl-kb-list {
|
|
529
|
+
flex: 1;
|
|
530
|
+
overflow-y: auto;
|
|
531
|
+
padding: 8px;
|
|
532
|
+
display: flex;
|
|
533
|
+
flex-direction: column;
|
|
534
|
+
gap: 2px;
|
|
535
|
+
}
|
|
536
|
+
.rgl-kb-list::-webkit-scrollbar,
|
|
537
|
+
.rgl-kb-detail-scroll::-webkit-scrollbar {
|
|
538
|
+
width: 4px;
|
|
539
|
+
}
|
|
540
|
+
.rgl-kb-list::-webkit-scrollbar-thumb,
|
|
541
|
+
.rgl-kb-detail-scroll::-webkit-scrollbar-thumb {
|
|
542
|
+
background: rgba(0, 0, 0, 0.16);
|
|
543
|
+
border-radius: 4px;
|
|
544
|
+
}
|
|
545
|
+
.rgl-kb-item {
|
|
546
|
+
display: block;
|
|
547
|
+
width: 100%;
|
|
548
|
+
text-align: left;
|
|
549
|
+
border: none;
|
|
550
|
+
background: transparent;
|
|
551
|
+
font-size: 12.5px;
|
|
552
|
+
line-height: 1.5;
|
|
553
|
+
color: #444;
|
|
554
|
+
cursor: pointer;
|
|
555
|
+
padding: 8px 10px;
|
|
556
|
+
border-radius: 8px;
|
|
557
|
+
transition:
|
|
558
|
+
background 0.15s ease,
|
|
559
|
+
color 0.15s ease;
|
|
560
|
+
overflow: hidden;
|
|
561
|
+
}
|
|
562
|
+
.rgl-kb-item-title {
|
|
563
|
+
font-weight: 500;
|
|
564
|
+
color: #333;
|
|
565
|
+
display: block;
|
|
566
|
+
}
|
|
567
|
+
.rgl-kb-item-snip {
|
|
568
|
+
font-size: 11.5px;
|
|
569
|
+
color: #999;
|
|
570
|
+
margin-top: 2px;
|
|
571
|
+
display: -webkit-box;
|
|
572
|
+
-webkit-line-clamp: 2;
|
|
573
|
+
-webkit-box-orient: vertical;
|
|
574
|
+
overflow: hidden;
|
|
575
|
+
}
|
|
576
|
+
.rgl-kb-item:hover {
|
|
577
|
+
background: #eef0f4;
|
|
578
|
+
}
|
|
579
|
+
.rgl-kb-item:hover .rgl-kb-item-title {
|
|
580
|
+
color: var(--rgl-primary, #4f46e5);
|
|
581
|
+
}
|
|
582
|
+
.rgl-kb-empty {
|
|
583
|
+
font-size: 12px;
|
|
584
|
+
color: #999;
|
|
585
|
+
text-align: center;
|
|
586
|
+
padding: 24px 10px;
|
|
587
|
+
}
|
|
588
|
+
.rgl-kb-detail {
|
|
589
|
+
flex: 1;
|
|
590
|
+
min-height: 0;
|
|
591
|
+
display: none;
|
|
592
|
+
flex-direction: column;
|
|
593
|
+
background: #fff;
|
|
594
|
+
}
|
|
595
|
+
.rgl-kb-back {
|
|
596
|
+
align-self: flex-start;
|
|
597
|
+
margin: 8px 12px 0;
|
|
598
|
+
border: none;
|
|
599
|
+
background: transparent;
|
|
600
|
+
color: var(--rgl-primary, #4f46e5);
|
|
601
|
+
font-size: 12px;
|
|
602
|
+
cursor: pointer;
|
|
603
|
+
padding: 4px 6px;
|
|
604
|
+
border-radius: 6px;
|
|
605
|
+
}
|
|
606
|
+
.rgl-kb-back:hover {
|
|
607
|
+
background: color-mix(in srgb, var(--rgl-primary, #4f46e5) 10%, #fff);
|
|
608
|
+
}
|
|
609
|
+
.rgl-kb-detail-scroll {
|
|
610
|
+
flex: 1;
|
|
611
|
+
overflow-y: auto;
|
|
612
|
+
padding: 8px 16px 16px;
|
|
613
|
+
}
|
|
614
|
+
.rgl-kb-detail-title {
|
|
615
|
+
font-size: 15px;
|
|
616
|
+
font-weight: 600;
|
|
617
|
+
color: #222;
|
|
618
|
+
line-height: 1.5;
|
|
619
|
+
margin-bottom: 10px;
|
|
620
|
+
}
|
|
621
|
+
.rgl-kb-detail-content {
|
|
622
|
+
font-size: 13.5px;
|
|
623
|
+
line-height: 1.8;
|
|
624
|
+
color: #444;
|
|
625
|
+
word-break: break-word;
|
|
626
|
+
}
|
|
627
|
+
.rgl-kb-detail-content img {
|
|
628
|
+
max-width: 100%;
|
|
629
|
+
border-radius: 8px;
|
|
630
|
+
}
|
|
631
|
+
.rgl-kb-ask {
|
|
632
|
+
margin-top: 14px;
|
|
633
|
+
width: 100%;
|
|
634
|
+
padding: 8px 0;
|
|
635
|
+
border: 1px solid var(--rgl-primary, #4f46e5);
|
|
636
|
+
border-radius: 8px;
|
|
637
|
+
background: #fff;
|
|
638
|
+
color: var(--rgl-primary, #4f46e5);
|
|
639
|
+
font-size: 13px;
|
|
640
|
+
cursor: pointer;
|
|
641
|
+
transition: background 0.15s ease;
|
|
642
|
+
}
|
|
643
|
+
.rgl-kb-ask:hover {
|
|
644
|
+
background: color-mix(in srgb, var(--rgl-primary, #4f46e5) 10%, #fff);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/* ========== 消息气泡 ========== */
|
|
648
|
+
.rgl-msg {
|
|
649
|
+
margin-bottom: 12px;
|
|
650
|
+
display: flex;
|
|
651
|
+
align-items: flex-start;
|
|
652
|
+
gap: 8px;
|
|
653
|
+
}
|
|
654
|
+
.rgl-msg.user {
|
|
655
|
+
justify-content: flex-end;
|
|
656
|
+
}
|
|
657
|
+
.rgl-msg-avatar {
|
|
658
|
+
width: 32px;
|
|
659
|
+
height: 32px;
|
|
660
|
+
border-radius: 50%;
|
|
661
|
+
flex-shrink: 0;
|
|
662
|
+
display: flex;
|
|
663
|
+
align-items: center;
|
|
664
|
+
justify-content: center;
|
|
665
|
+
font-size: 13px;
|
|
666
|
+
font-weight: 600;
|
|
667
|
+
color: #fff;
|
|
668
|
+
overflow: hidden;
|
|
669
|
+
background-size: cover;
|
|
670
|
+
background-position: center;
|
|
671
|
+
}
|
|
672
|
+
.rgl-msg-col {
|
|
673
|
+
min-width: 0;
|
|
674
|
+
max-width: 78%;
|
|
675
|
+
display: flex;
|
|
676
|
+
flex-direction: column;
|
|
677
|
+
}
|
|
678
|
+
.rgl-msg.user .rgl-msg-col {
|
|
679
|
+
align-items: flex-end;
|
|
680
|
+
}
|
|
681
|
+
.rgl-msg-meta {
|
|
682
|
+
font-size: 10px;
|
|
683
|
+
color: #9aa0aa;
|
|
684
|
+
line-height: 1.3;
|
|
685
|
+
margin-bottom: 2px;
|
|
686
|
+
white-space: nowrap;
|
|
687
|
+
}
|
|
688
|
+
.rgl-bubble {
|
|
689
|
+
width: fit-content;
|
|
690
|
+
max-width: 100%;
|
|
691
|
+
padding: 10px 14px;
|
|
692
|
+
border-radius: 12px;
|
|
693
|
+
font-size: 14px;
|
|
694
|
+
line-height: 1.6;
|
|
695
|
+
word-break: break-word;
|
|
696
|
+
}
|
|
697
|
+
.rgl-msg.user .rgl-bubble {
|
|
698
|
+
background: var(--rgl-primary, #4f46e5);
|
|
699
|
+
color: #fff;
|
|
700
|
+
}
|
|
701
|
+
.rgl-msg.bot .rgl-bubble,
|
|
702
|
+
.rgl-msg.agent .rgl-bubble {
|
|
703
|
+
background: #fff;
|
|
704
|
+
color: #333;
|
|
705
|
+
border: 1px solid #e0e2e8;
|
|
706
|
+
}
|
|
707
|
+
.rgl-bubble img {
|
|
708
|
+
max-width: 100%;
|
|
709
|
+
border-radius: 8px;
|
|
710
|
+
display: block;
|
|
711
|
+
cursor: pointer;
|
|
712
|
+
}
|
|
713
|
+
.rgl-msg-system {
|
|
714
|
+
text-align: center;
|
|
715
|
+
margin: 8px 0;
|
|
716
|
+
}
|
|
717
|
+
.rgl-msg-system > span {
|
|
718
|
+
display: inline-block;
|
|
719
|
+
background: #e8eaef;
|
|
720
|
+
padding: 6px 14px;
|
|
721
|
+
border-radius: 12px;
|
|
722
|
+
font-size: 12px;
|
|
723
|
+
color: #666;
|
|
724
|
+
max-width: 90%;
|
|
725
|
+
}
|
|
726
|
+
.rgl-typing {
|
|
727
|
+
display: flex;
|
|
728
|
+
align-items: center;
|
|
729
|
+
gap: 6px;
|
|
730
|
+
padding: 10px 14px;
|
|
731
|
+
border-radius: 12px;
|
|
732
|
+
background: #fff;
|
|
733
|
+
border: 1px solid #e0e2e8;
|
|
734
|
+
width: fit-content;
|
|
735
|
+
font-size: 13px;
|
|
736
|
+
color: #999;
|
|
737
|
+
}
|
|
738
|
+
.rgl-typing i {
|
|
739
|
+
width: 6px;
|
|
740
|
+
height: 6px;
|
|
741
|
+
border-radius: 50%;
|
|
742
|
+
background: #c3c7d0;
|
|
743
|
+
display: inline-block;
|
|
744
|
+
animation: rglBlink 1.2s infinite;
|
|
745
|
+
}
|
|
746
|
+
.rgl-typing i:nth-child(2) {
|
|
747
|
+
animation-delay: 0.2s;
|
|
748
|
+
}
|
|
749
|
+
.rgl-typing i:nth-child(3) {
|
|
750
|
+
animation-delay: 0.4s;
|
|
751
|
+
}
|
|
752
|
+
@keyframes rglBlink {
|
|
753
|
+
0%,
|
|
754
|
+
80%,
|
|
755
|
+
100% {
|
|
756
|
+
opacity: 0.25;
|
|
757
|
+
}
|
|
758
|
+
40% {
|
|
759
|
+
opacity: 1;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
.rgl-quick-transfer {
|
|
763
|
+
margin-top: 8px;
|
|
764
|
+
font-size: 12px;
|
|
765
|
+
color: var(--rgl-primary, #4f46e5);
|
|
766
|
+
cursor: pointer;
|
|
767
|
+
text-align: right;
|
|
768
|
+
}
|
|
769
|
+
.rgl-rating {
|
|
770
|
+
text-align: center;
|
|
771
|
+
margin: 10px 0;
|
|
772
|
+
}
|
|
773
|
+
.rgl-rating-card {
|
|
774
|
+
display: inline-block;
|
|
775
|
+
background: #fff;
|
|
776
|
+
border: 1px solid #e0e2e8;
|
|
777
|
+
border-radius: 12px;
|
|
778
|
+
padding: 10px 16px;
|
|
779
|
+
max-width: 90%;
|
|
780
|
+
}
|
|
781
|
+
.rgl-rating-card .rgl-star {
|
|
782
|
+
cursor: pointer;
|
|
783
|
+
font-size: 22px;
|
|
784
|
+
color: #d1d5db;
|
|
785
|
+
}
|
|
786
|
+
.rgl-preview {
|
|
787
|
+
display: none;
|
|
788
|
+
padding: 0 12px 6px;
|
|
789
|
+
border-top: 1px solid #eef0f3;
|
|
790
|
+
}
|
|
791
|
+
.rgl-preview-inner {
|
|
792
|
+
position: relative;
|
|
793
|
+
display: inline-block;
|
|
794
|
+
margin: 6px 4px 0;
|
|
795
|
+
}
|
|
796
|
+
.rgl-preview-inner img {
|
|
797
|
+
max-height: 80px;
|
|
798
|
+
max-width: 200px;
|
|
799
|
+
border-radius: 8px;
|
|
800
|
+
border: 1px solid #ddd;
|
|
801
|
+
display: block;
|
|
802
|
+
}
|
|
803
|
+
.rgl-preview-close {
|
|
804
|
+
position: absolute;
|
|
805
|
+
top: -6px;
|
|
806
|
+
right: -6px;
|
|
807
|
+
width: 18px;
|
|
808
|
+
height: 18px;
|
|
809
|
+
border-radius: 50%;
|
|
810
|
+
background: #ef4444;
|
|
811
|
+
color: #fff;
|
|
812
|
+
font-size: 12px;
|
|
813
|
+
line-height: 18px;
|
|
814
|
+
text-align: center;
|
|
815
|
+
cursor: pointer;
|
|
816
|
+
}
|
|
817
|
+
.rgl-footer {
|
|
818
|
+
padding: 8px 12px 12px;
|
|
819
|
+
border-top: 1px solid #eef0f3;
|
|
820
|
+
display: flex;
|
|
821
|
+
gap: 8px;
|
|
822
|
+
align-items: center;
|
|
823
|
+
flex-shrink: 0;
|
|
824
|
+
}
|
|
825
|
+
.rgl-attach {
|
|
826
|
+
cursor: pointer;
|
|
827
|
+
display: flex;
|
|
828
|
+
align-items: center;
|
|
829
|
+
flex-shrink: 0;
|
|
830
|
+
background: none;
|
|
831
|
+
border: none;
|
|
832
|
+
padding: 4px;
|
|
833
|
+
color: #666;
|
|
834
|
+
}
|
|
835
|
+
.rgl-input {
|
|
836
|
+
flex: 1;
|
|
837
|
+
min-width: 0;
|
|
838
|
+
padding: 10px 14px;
|
|
839
|
+
border: 1px solid #dde0e6;
|
|
840
|
+
border-radius: 8px;
|
|
841
|
+
font-size: 14px;
|
|
842
|
+
outline: none;
|
|
843
|
+
background: #fff;
|
|
844
|
+
}
|
|
845
|
+
.rgl-input:focus {
|
|
846
|
+
border-color: var(--rgl-primary, #4f46e5);
|
|
847
|
+
}
|
|
848
|
+
.rgl-send {
|
|
849
|
+
padding: 10px 16px;
|
|
850
|
+
background: var(--rgl-primary, #4f46e5);
|
|
851
|
+
color: #fff;
|
|
852
|
+
border: none;
|
|
853
|
+
border-radius: 8px;
|
|
854
|
+
cursor: pointer;
|
|
855
|
+
font-size: 14px;
|
|
856
|
+
flex-shrink: 0;
|
|
857
|
+
}
|
|
858
|
+
.rgl-send:disabled {
|
|
859
|
+
opacity: 0.6;
|
|
860
|
+
cursor: not-allowed;
|
|
861
|
+
}
|
|
862
|
+
</style>
|
|
2
863
|
<script>
|
|
3
864
|
(function () {
|
|
4
|
-
// ==================== 配置(优先级:window.CS_SDK_CONFIG > 后端生成默认值) ====================
|
|
865
|
+
// ==================== 配置(优先级:window.CS_SDK_CONFIG > 运行时后端拉取 > 后端生成默认值) ====================
|
|
5
866
|
var _cfg = window.CS_SDK_CONFIG || {};
|
|
6
867
|
var APP_ID = _cfg.app_id || '{{APP_ID}}';
|
|
7
868
|
var WELCOME = _cfg.welcome_message || '{{WELCOME}}';
|
|
8
869
|
var API_BASE = _cfg.api_base || {{API_BASE_JS}};
|
|
9
|
-
var
|
|
870
|
+
var SERVER_CFG = {{CONFIG_JSON}}; // 后端生成时注入的默认 SDK 展示配置
|
|
871
|
+
var AGENT_KEY = _cfg.agent_key || '';
|
|
10
872
|
var VISITOR_NAME = _cfg.visitor_name || '';
|
|
11
|
-
var PRIMARY = _cfg.primary_color || '#4f46e5';
|
|
873
|
+
var PRIMARY = _cfg.primary_color || SERVER_CFG.primary_color || '#4f46e5';
|
|
12
874
|
var STORAGE_KEY = 'reglow_cs_session_' + APP_ID;
|
|
875
|
+
var POS_KEY = 'reglow_cs_pos3_' + APP_ID; // v7:弹窗默认右侧垂直居中显示
|
|
13
876
|
|
|
14
877
|
// ==================== 状态 ====================
|
|
15
878
|
var sessionId = null;
|
|
@@ -17,36 +880,89 @@
|
|
|
17
880
|
var agentName = null;
|
|
18
881
|
var agentAvatar = null;
|
|
19
882
|
var isOpen = false;
|
|
20
|
-
var
|
|
883
|
+
var kbOpen = false; // 知识库分栏是否展开(左侧伸缩,聊天保持原位)
|
|
884
|
+
var activeFaqId = null;
|
|
885
|
+
var unreadCount = 0;
|
|
21
886
|
var pendingImageUrl = null;
|
|
22
887
|
var ws = null;
|
|
23
888
|
var wsConnected = false;
|
|
24
889
|
|
|
25
|
-
try {
|
|
26
|
-
|
|
27
|
-
|
|
890
|
+
try { sessionId = localStorage.getItem(STORAGE_KEY) || null; } catch (e) { sessionId = null; }
|
|
891
|
+
|
|
892
|
+
// 合并后的展示配置(二维码 / 联系方式 / 常见问题)
|
|
893
|
+
var S = {
|
|
894
|
+
qr: null,
|
|
895
|
+
contact: null,
|
|
896
|
+
faqEnabled: true,
|
|
897
|
+
faqTitle: '常见问题',
|
|
898
|
+
faqs: [],
|
|
899
|
+
appName: '',
|
|
900
|
+
welcome: WELCOME,
|
|
901
|
+
};
|
|
28
902
|
|
|
29
903
|
// ==================== 去重 ====================
|
|
30
|
-
var
|
|
31
|
-
if (
|
|
904
|
+
var oldBar = document.getElementById('reglow-cs-bar');
|
|
905
|
+
if (oldBar) oldBar.remove();
|
|
32
906
|
var oldChat = document.getElementById('reglow-cs-chat');
|
|
33
907
|
if (oldChat) oldChat.remove();
|
|
34
908
|
|
|
35
|
-
// ====================
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
909
|
+
// ==================== 图标(内联 SVG) ====================
|
|
910
|
+
var ICON_CHAT = '<svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/></svg>';
|
|
911
|
+
// 客服(耳机带麦克风)图标:悬浮按钮未点击状态
|
|
912
|
+
var ICON_AGENT = '<svg width="28" height="28" viewBox="0 0 1114 1024" xmlns="http://www.w3.org/2000/svg"><path d="M610.605176 965.180235c218.895059-15.36 394.601412-200.944941 409.901177-433.995294l31.171765-33.008941c0 275.124706-210.642824 498.145882-470.497883 498.145882l29.424941-31.141647z m409.901177-433.995294l31.171765-33.008941c0 275.124706-210.642824 498.145882-470.497883 498.145882l29.424941-31.141647c218.895059-15.36 394.601412-200.944941 409.901177-433.995294zM170.947765 498.145882C170.947765 255.578353 355.388235 60.235294 581.180235 60.235294 806.972235 60.235294 991.472941 255.548235 991.472941 498.145882h60.235294C1051.678118 223.051294 841.035294 0 581.180235 0 321.355294 0 110.712471 223.021176 110.712471 498.145882h60.235294z" fill="currentColor" p-id="15541"></path><path d="M221.394824 498.145882v110.712471a110.712471 110.712471 0 0 1-221.394824 0v-110.682353a110.712471 110.712471 0 0 1 221.394824 0z" fill="currentColor" p-id="15542"></path><path d="M110.712471 447.698824c-27.888941 0-50.477176 22.588235-50.477177 50.477176v110.682353a50.477176 50.477176 0 0 0 100.924235 0v-110.682353c0-27.888941-22.588235-50.477176-50.447058-50.477176z" fill="transparent" p-id="15543"></path><path d="M996.321882 387.463529a110.712471 110.712471 0 0 1 110.712471 110.712471v110.682353a110.712471 110.712471 0 0 1-221.424941 0v-110.682353a110.712471 110.712471 0 0 1 110.71247-110.712471z" fill="currentColor" p-id="15544"></path><path d="M996.321882 447.698824c-27.858824 0-50.477176 22.588235-50.477176 50.477176v110.682353a50.477176 50.477176 0 0 0 100.954353 0v-110.682353c0-27.888941-22.588235-50.477176-50.477177-50.477176z" fill="transparent" p-id="15545"></path><path d="M539.557647 553.502118c23.973647 0 41.411765-23.160471 41.411765-48.911059v-120.982588c0-28.310588-19.606588-48.911059-41.411765-48.911059-21.775059 0-41.381647 23.160471-41.381647 48.911059v120.982588c0 25.750588 17.408 48.911059 41.381647 48.911059z m235.369412-51.501177v-120.982588c0-28.310588-19.606588-48.911059-41.411765-48.911059s-41.411765 23.190588-41.411765 48.911059v121.012706c0 28.310588 19.606588 48.911059 41.411765 48.911059s41.411765-20.600471 41.411765-48.911059zM652.197647 928.466824a41.502118 41.502118 0 0 1 0 83.004235h-98.695529a41.502118 41.502118 0 1 1 0-83.004235h98.695529z" fill="currentColor" p-id="15546"></path></svg>';
|
|
913
|
+
var ICON_CLOSE_X = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg>';
|
|
914
|
+
var ICON_QR = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><path d="M14 14h3v3h-3zM20 14h1M14 20h1M18 18h3"/></svg>';
|
|
915
|
+
var ICON_PHONE = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/></svg>';
|
|
916
|
+
var ICON_MAIL = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="m22 7-10 6L2 7"/></svg>';
|
|
917
|
+
var ICON_ONLINE = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/></svg>';
|
|
918
|
+
var ICON_PIN = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0z"/><circle cx="12" cy="10" r="3"/></svg>';
|
|
919
|
+
var ICON_FEEDBACK = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M2 12C2 6.48 6.48 2 12 2s10 4.48 10 10-4.48 10-10 10c-5.52 0-10-4.48-10-10z"/><path d="M8.5 9.5h.01M15.5 9.5h.01M8.5 14.5c1 1.2 2.2 1.8 3.5 1.8s2.5-.6 3.5-1.8"/></svg>';
|
|
920
|
+
var ICON_TOP = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M17.5 14.5 12 9l-5.5 5.5"/></svg>';
|
|
921
|
+
var ICON_FAQ = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><path d="M12 17h.01"/></svg>';
|
|
922
|
+
var ICON_BACK = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 18l-6-6 6-6"/></svg>';
|
|
923
|
+
var ICON_CHEVRON = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M9 18l6-6-6-6"/></svg>';
|
|
924
|
+
|
|
925
|
+
// ==================== 构建单个悬浮按钮 + 工具组合卡片 ====================
|
|
926
|
+
var bar = document.createElement('div');
|
|
927
|
+
bar.id = 'reglow-cs-bar';
|
|
928
|
+
bar.style.setProperty('--rgl-primary', PRIMARY);
|
|
929
|
+
bar.innerHTML =
|
|
930
|
+
'<button class="rgl-fab-main" id="rgl-fab-main" title="智能客服">' +
|
|
931
|
+
'<span id="rgl-fab-icon">' + ICON_AGENT + '</span>' +
|
|
932
|
+
'<span class="rgl-fab-badge" id="rgl-fab-badge"></span>' +
|
|
933
|
+
'</button>' +
|
|
934
|
+
'<button class="rgl-backtop" id="rgl-backtop" title="返回顶部">' + ICON_TOP + '</button>' +
|
|
935
|
+
'<div class="rgl-fab-pop" id="rgl-fab-pop">' +
|
|
936
|
+
'<div class="rgl-fab-pop-head">' +
|
|
937
|
+
'<span id="rgl-fab-pop-title">智能客服</span>' +
|
|
938
|
+
'<button class="rgl-fab-pop-close" id="rgl-fab-pop-close" title="关闭">×</button>' +
|
|
939
|
+
'</div>' +
|
|
940
|
+
'<div class="rgl-fab-pop-body" id="rgl-fab-pop-body"></div>' +
|
|
941
|
+
'</div>';
|
|
942
|
+
document.body.appendChild(bar);
|
|
943
|
+
|
|
944
|
+
var fabMain = bar.querySelector('#rgl-fab-main');
|
|
945
|
+
var unreadBadge = bar.querySelector('#rgl-fab-badge');
|
|
946
|
+
var backTopBtn = bar.querySelector('#rgl-backtop');
|
|
947
|
+
var popEl = bar.querySelector('#rgl-fab-pop');
|
|
948
|
+
var popBodyEl = bar.querySelector('#rgl-fab-pop-body');
|
|
949
|
+
var popTitleEl = bar.querySelector('#rgl-fab-pop-title');
|
|
950
|
+
|
|
951
|
+
// ==================== 返回顶部(滚动到页面底部时出现) ====================
|
|
952
|
+
function updateBackTop() {
|
|
953
|
+
var doc = document.documentElement;
|
|
954
|
+
var scrollable = doc.scrollHeight > window.innerHeight;
|
|
955
|
+
var atBottom = doc.scrollHeight - (window.pageYOffset + window.innerHeight) < 100;
|
|
956
|
+
backTopBtn.style.display = (scrollable && atBottom) ? 'flex' : 'none';
|
|
957
|
+
}
|
|
958
|
+
backTopBtn.onclick = function (e) {
|
|
959
|
+
e.stopPropagation();
|
|
960
|
+
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
961
|
+
};
|
|
962
|
+
window.addEventListener('scroll', updateBackTop, { passive: true });
|
|
963
|
+
window.addEventListener('resize', updateBackTop, { passive: true });
|
|
964
|
+
|
|
48
965
|
function updateUnread() {
|
|
49
|
-
if (!unreadBadge) return;
|
|
50
966
|
if (unreadCount > 0 && !isOpen) {
|
|
51
967
|
unreadBadge.style.display = 'block';
|
|
52
968
|
unreadBadge.textContent = unreadCount > 99 ? '99+' : String(unreadCount);
|
|
@@ -54,79 +970,255 @@
|
|
|
54
970
|
unreadBadge.style.display = 'none';
|
|
55
971
|
}
|
|
56
972
|
}
|
|
57
|
-
function clearUnread() {
|
|
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
|
-
|
|
973
|
+
function clearUnread() { unreadCount = 0; updateUnread(); }
|
|
974
|
+
function closePop() {
|
|
975
|
+
popEl.style.display = 'none';
|
|
976
|
+
setFabIcon(false);
|
|
977
|
+
}
|
|
978
|
+
// 悬浮按钮图标:未点击=客服耳机带麦;打开工具卡=×(并隐藏流光)
|
|
979
|
+
function setFabIcon(open) {
|
|
980
|
+
var iconEl = bar.querySelector('#rgl-fab-icon');
|
|
981
|
+
if (iconEl) iconEl.innerHTML = open ? ICON_CLOSE_X : ICON_AGENT;
|
|
982
|
+
var btn = bar.querySelector('#rgl-fab-main');
|
|
983
|
+
if (btn) btn.classList.toggle('rgl-open', !!open);
|
|
984
|
+
}
|
|
985
|
+
function popHasContact() {
|
|
986
|
+
var c = S.contact || {};
|
|
987
|
+
return c.phone || c.email || c.online_url || c.address;
|
|
988
|
+
}
|
|
989
|
+
function popHasQr() { return S.qr && S.qr.url; }
|
|
990
|
+
|
|
991
|
+
// 工具组合主菜单(窄卡片 168px)
|
|
992
|
+
function renderMenu() {
|
|
993
|
+
popTitleEl.textContent = S.appName || '智能客服';
|
|
994
|
+
popEl.style.width = '168px';
|
|
995
|
+
var rows = '';
|
|
996
|
+
rows += menuRow('chat', ICON_CHAT, '在线客服');
|
|
997
|
+
if (S.faqEnabled) rows += menuRow('book', ICON_FAQ, '常见问题');
|
|
998
|
+
if (popHasQr()) rows += menuRow('qr', ICON_QR, '扫码咨询');
|
|
999
|
+
if (popHasContact()) rows += menuRow('contact', ICON_PHONE, '联系方式');
|
|
1000
|
+
rows += menuRow('feedback', ICON_FEEDBACK, '反馈');
|
|
1001
|
+
popBodyEl.innerHTML = rows;
|
|
1002
|
+
popBodyEl.setAttribute('data-view', 'menu');
|
|
1003
|
+
}
|
|
1004
|
+
function menuRow(action, icon, label) {
|
|
1005
|
+
return '<button class="rgl-fab-row" data-action="' + action + '">' +
|
|
1006
|
+
'<span class="rgl-fab-row-ico">' + icon + '</span>' +
|
|
1007
|
+
'<span class="rgl-fab-row-label">' + escHtml(label) + '</span>' +
|
|
1008
|
+
'<span class="rgl-fab-row-chevron">' + ICON_CHEVRON + '</span>' +
|
|
1009
|
+
'</button>';
|
|
1010
|
+
}
|
|
1011
|
+
// 子视图(二维码 / 联系方式 / 反馈):加宽卡片到 248px
|
|
1012
|
+
function renderSub(backLabel, contentHtml) {
|
|
1013
|
+
popEl.style.width = '248px';
|
|
1014
|
+
popBodyEl.innerHTML = '<button class="rgl-fab-back" data-action="back">' + ICON_BACK + ' ' + escHtml(backLabel) + '</button>' + contentHtml;
|
|
1015
|
+
popBodyEl.setAttribute('data-view', 'sub');
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// 菜单点击(事件委托)
|
|
1019
|
+
popBodyEl.addEventListener('click', function (e) {
|
|
1020
|
+
e.stopPropagation(); // 阻止冒泡:子视图会替换卡片内容,冒泡到 document 会导致卡片被误关
|
|
1021
|
+
var row = e.target.closest('[data-action]');
|
|
1022
|
+
if (!row) return;
|
|
1023
|
+
var action = row.getAttribute('data-action');
|
|
1024
|
+
if (action === 'chat') { kbOpen = false; closePop(); openChat('chat'); }
|
|
1025
|
+
else if (action === 'book') { kbOpen = true; closePop(); openChat('chat'); }
|
|
1026
|
+
else if (action === 'qr') renderQrView();
|
|
1027
|
+
else if (action === 'contact') renderContactView();
|
|
1028
|
+
else if (action === 'feedback') renderFeedbackView();
|
|
1029
|
+
else if (action === 'back') renderMenu();
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
function renderQrView() {
|
|
1033
|
+
if (!popHasQr()) return;
|
|
1034
|
+
renderSub('返回', '<div class="rgl-fab-qr">' +
|
|
1035
|
+
'<img src="' + escHtml(resolveUrl(S.qr.url)) + '" alt="二维码" />' +
|
|
1036
|
+
'<div class="rgl-fab-qr-title">' + escHtml(S.qr.title || '扫码咨询') + '</div>' +
|
|
1037
|
+
(S.qr.desc ? '<div class="rgl-fab-qr-desc">' + escHtml(S.qr.desc) + '</div>' : '') +
|
|
1038
|
+
'</div>');
|
|
1039
|
+
}
|
|
1040
|
+
function renderContactView() {
|
|
1041
|
+
var c = S.contact || {};
|
|
1042
|
+
var rows = '';
|
|
1043
|
+
if (c.phone) rows += contactRow('phone', '服务热线', '<a class="rgl-contact-val" href="tel:' + escHtml(c.phone) + '">' + escHtml(c.phone) + '</a>');
|
|
1044
|
+
if (c.email) rows += contactRow('mail', '联系邮箱', '<a class="rgl-contact-val" href="mailto:' + escHtml(c.email) + '">' + escHtml(c.email) + '</a>');
|
|
1045
|
+
if (c.online_url) rows += contactRow('chat', '在线咨询', '<a class="rgl-contact-val" href="' + escHtml(c.online_url) + '" target="_blank" rel="noreferrer">点击发起在线咨询</a>');
|
|
1046
|
+
if (c.address) rows += contactRow('pin', '联系地址', '<span class="rgl-contact-val">' + escHtml(c.address) + '</span>');
|
|
1047
|
+
renderSub('返回', rows || '<div style="color:#999;font-size:12px;text-align:center;padding:16px;">暂无联系方式</div>');
|
|
1048
|
+
}
|
|
1049
|
+
function contactRow(type, label, valHtml) {
|
|
1050
|
+
var ico = '';
|
|
1051
|
+
if (type === 'phone') ico = ICON_PHONE;
|
|
1052
|
+
else if (type === 'mail') ico = ICON_MAIL;
|
|
1053
|
+
else if (type === 'chat') ico = ICON_ONLINE;
|
|
1054
|
+
else ico = ICON_PIN;
|
|
1055
|
+
return '<div class="rgl-contact-row">' +
|
|
1056
|
+
'<div class="rgl-contact-ico">' + ico + '</div>' +
|
|
1057
|
+
'<div style="min-width:0;"><div class="rgl-contact-label">' + escHtml(label) + '</div>' + valHtml + '</div>' +
|
|
1058
|
+
'</div>';
|
|
1059
|
+
}
|
|
1060
|
+
// 反馈(星级评分)
|
|
1061
|
+
var fbRating = 0;
|
|
1062
|
+
function renderFeedbackView() {
|
|
1063
|
+
fbRating = 0;
|
|
1064
|
+
var stars = '';
|
|
1065
|
+
for (var i = 1; i <= 5; i++) {
|
|
1066
|
+
stars += '<span class="rgl-fb-star" data-v="' + i + '">★</span>';
|
|
1067
|
+
}
|
|
1068
|
+
renderSub('返回',
|
|
1069
|
+
'<div class="rgl-fb-hd">您对当前页面的整体感受是否满意?</div>' +
|
|
1070
|
+
'<div class="rgl-fb-stars">' + stars + '</div>' +
|
|
1071
|
+
'<div class="rgl-fb-labels"><span>非常不满意</span><span>非常满意</span></div>' +
|
|
1072
|
+
'<button class="rgl-fb-submit" data-fb-submit disabled>提交反馈</button>');
|
|
1073
|
+
var starEls = popBodyEl.querySelectorAll('.rgl-fb-star');
|
|
1074
|
+
for (var j = 0; j < starEls.length; j++) {
|
|
1075
|
+
starEls[j].addEventListener('click', function () {
|
|
1076
|
+
fbRating = parseInt(this.getAttribute('data-v'), 10);
|
|
1077
|
+
for (var k = 0; k < starEls.length; k++) {
|
|
1078
|
+
starEls[k].classList.toggle('on', k < fbRating);
|
|
1079
|
+
}
|
|
1080
|
+
popBodyEl.querySelector('[data-fb-submit]').disabled = false;
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
popBodyEl.querySelector('[data-fb-submit]').onclick = function () {
|
|
1084
|
+
submitFeedback(fbRating);
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
function submitFeedback(rating) {
|
|
1088
|
+
// 有会话则作为本次人工服务评分落库;无会话则本地提示
|
|
1089
|
+
if (sessionId) {
|
|
1090
|
+
try {
|
|
1091
|
+
fetch(API_BASE + '/api/v1/cs/rating', {
|
|
1092
|
+
method: 'POST',
|
|
1093
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1094
|
+
body: JSON.stringify({ session_id: sessionId, rating: rating })
|
|
1095
|
+
}).catch(function () {});
|
|
1096
|
+
} catch (e) {}
|
|
1097
|
+
}
|
|
1098
|
+
popBodyEl.innerHTML = '<button class="rgl-fab-back" data-action="back">' + ICON_BACK + ' 返回</button>' +
|
|
1099
|
+
'<div class="rgl-fb-done">✓ 感谢您的反馈,我们会做得更好</div>';
|
|
1100
|
+
fbRating = 0;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// 悬浮按钮:支持拖拽(拖拽后不触发打开卡片)
|
|
1104
|
+
var fabHasDragged = false;
|
|
1105
|
+
var fabDragState = null;
|
|
1106
|
+
fabMain.addEventListener('pointerdown', function (e) {
|
|
1107
|
+
fabDragState = { sx: e.clientX, sy: e.clientY, ox: bar.offsetLeft || 0, oy: bar.offsetTop || 0 };
|
|
1108
|
+
fabHasDragged = false;
|
|
1109
|
+
e.preventDefault();
|
|
1110
|
+
});
|
|
1111
|
+
document.addEventListener('pointermove', function (e) {
|
|
1112
|
+
if (!fabDragState) return;
|
|
1113
|
+
var dx = e.clientX - fabDragState.sx, dy = e.clientY - fabDragState.sy;
|
|
1114
|
+
if (Math.abs(dx) > 4 || Math.abs(dy) > 4) fabHasDragged = true;
|
|
1115
|
+
var bw = bar.offsetWidth || 56, bh = bar.offsetHeight || 122;
|
|
1116
|
+
var left = Math.max(8, Math.min(window.innerWidth - bw - 8, fabDragState.ox + dx));
|
|
1117
|
+
var top = Math.max(8, Math.min(window.innerHeight - bh - 8, fabDragState.oy + dy));
|
|
1118
|
+
bar.style.left = left + 'px';
|
|
1119
|
+
bar.style.top = top + 'px';
|
|
1120
|
+
bar.style.right = 'auto';
|
|
1121
|
+
bar.style.bottom = 'auto';
|
|
1122
|
+
});
|
|
1123
|
+
document.addEventListener('pointerup', function () { fabDragState = null; });
|
|
1124
|
+
|
|
1125
|
+
fabMain.addEventListener('click', function (e) {
|
|
1126
|
+
e.stopPropagation();
|
|
1127
|
+
if (fabHasDragged) return;
|
|
1128
|
+
if (popEl.style.display === 'block') { closePop(); return; }
|
|
1129
|
+
renderMenu();
|
|
1130
|
+
popEl.style.display = 'block';
|
|
1131
|
+
setFabIcon(true);
|
|
1132
|
+
});
|
|
1133
|
+
bar.querySelector('#rgl-fab-pop-close').addEventListener('click', function (e) {
|
|
1134
|
+
e.stopPropagation();
|
|
1135
|
+
closePop();
|
|
1136
|
+
});
|
|
1137
|
+
// 点击页面其它区域关闭卡片
|
|
1138
|
+
document.addEventListener('click', function (e) {
|
|
1139
|
+
if (!bar.contains(e.target) && !chatBox.contains(e.target)) closePop();
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
// ==================== 构建聊天窗口(可拖拽,右侧聊天保持原位) ====================
|
|
90
1143
|
var chatBox = document.createElement('div');
|
|
91
1144
|
chatBox.id = 'reglow-cs-chat';
|
|
92
|
-
chatBox.style.
|
|
93
|
-
chatBox.innerHTML =
|
|
94
|
-
<div
|
|
95
|
-
<
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
<
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
1145
|
+
chatBox.style.setProperty('--rgl-primary', PRIMARY);
|
|
1146
|
+
chatBox.innerHTML =
|
|
1147
|
+
'<div class="rgl-header" id="rgl-header">' +
|
|
1148
|
+
'<div class="rgl-header-avatar" id="rgl-header-avatar"></div>' +
|
|
1149
|
+
'<div class="rgl-header-info">' +
|
|
1150
|
+
'<div class="rgl-header-title" id="rgl-header-title">在线客服</div>' +
|
|
1151
|
+
'<div class="rgl-header-sub" id="rgl-header-sub"></div>' +
|
|
1152
|
+
'</div>' +
|
|
1153
|
+
'<div class="rgl-header-actions">' +
|
|
1154
|
+
'<button class="rgl-icon-btn" id="rgl-hdr-kb" title="常见问题" style="display:none;">' + ICON_FAQ + '</button>' +
|
|
1155
|
+
'<button class="rgl-icon-btn" id="rgl-close" title="关闭">' +
|
|
1156
|
+
'<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 6L6 18M6 6l12 12"/></svg>' +
|
|
1157
|
+
'</button>' +
|
|
1158
|
+
'</div>' +
|
|
1159
|
+
'</div>' +
|
|
1160
|
+
'<div class="rgl-body">' +
|
|
1161
|
+
'<div class="rgl-kb-pane" id="rgl-kb-pane">' +
|
|
1162
|
+
'<div class="rgl-kb-toolbar">' +
|
|
1163
|
+
'<span class="rgl-kb-title" id="rgl-kb-title">常见问题</span>' +
|
|
1164
|
+
'<input class="rgl-kb-search" id="rgl-kb-search" type="text" placeholder="搜索问题..." />' +
|
|
1165
|
+
'</div>' +
|
|
1166
|
+
'<div class="rgl-kb-list" id="rgl-kb-list"></div>' +
|
|
1167
|
+
'<div class="rgl-kb-detail" id="rgl-kb-detail">' +
|
|
1168
|
+
'<button class="rgl-kb-back" id="rgl-kb-back">← 返回列表</button>' +
|
|
1169
|
+
'<div class="rgl-kb-detail-scroll">' +
|
|
1170
|
+
'<div class="rgl-kb-detail-title" id="rgl-kb-detail-title"></div>' +
|
|
1171
|
+
'<div class="rgl-kb-detail-content" id="rgl-kb-detail-content"></div>' +
|
|
1172
|
+
'<button class="rgl-kb-ask" id="rgl-kb-ask">在聊天中提问</button>' +
|
|
1173
|
+
'</div>' +
|
|
1174
|
+
'</div>' +
|
|
1175
|
+
'</div>' +
|
|
1176
|
+
'<div class="rgl-chat-col">' +
|
|
1177
|
+
'<div class="rgl-msgs" id="rgl-msgs"></div>' +
|
|
1178
|
+
'<div class="rgl-preview" id="rgl-preview"></div>' +
|
|
1179
|
+
'<div class="rgl-footer">' +
|
|
1180
|
+
'<button class="rgl-attach" id="rgl-attach" title="发送图片">' +
|
|
1181
|
+
'<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg>' +
|
|
1182
|
+
'<input id="rgl-file" type="file" accept="image/*" style="display:none;" />' +
|
|
1183
|
+
'</button>' +
|
|
1184
|
+
'<input class="rgl-input" id="rgl-input" type="text" placeholder="请输入您的问题..." />' +
|
|
1185
|
+
'<button class="rgl-send" id="rgl-send">发送</button>' +
|
|
1186
|
+
'</div>' +
|
|
1187
|
+
'</div>' +
|
|
1188
|
+
'</div>';
|
|
112
1189
|
document.body.appendChild(chatBox);
|
|
113
1190
|
|
|
114
|
-
var headerEl = chatBox.querySelector('#
|
|
115
|
-
var
|
|
116
|
-
var
|
|
117
|
-
var
|
|
118
|
-
var
|
|
119
|
-
var
|
|
120
|
-
var
|
|
121
|
-
var
|
|
122
|
-
var
|
|
123
|
-
var
|
|
124
|
-
var
|
|
1191
|
+
var headerEl = chatBox.querySelector('#rgl-header');
|
|
1192
|
+
var headerAvatarEl = chatBox.querySelector('#rgl-header-avatar');
|
|
1193
|
+
var titleEl = chatBox.querySelector('#rgl-header-title');
|
|
1194
|
+
var subtitleEl = chatBox.querySelector('#rgl-header-sub');
|
|
1195
|
+
var hdrKbEl = chatBox.querySelector('#rgl-hdr-kb');
|
|
1196
|
+
var kbPaneEl = chatBox.querySelector('#rgl-kb-pane');
|
|
1197
|
+
var kbListEl = chatBox.querySelector('#rgl-kb-list');
|
|
1198
|
+
var kbDetailEl = chatBox.querySelector('#rgl-kb-detail');
|
|
1199
|
+
var kbDetailTitleEl = chatBox.querySelector('#rgl-kb-detail-title');
|
|
1200
|
+
var kbDetailContentEl = chatBox.querySelector('#rgl-kb-detail-content');
|
|
1201
|
+
var kbAskEl = chatBox.querySelector('#rgl-kb-ask');
|
|
1202
|
+
var kbSearchEl = chatBox.querySelector('#rgl-kb-search');
|
|
1203
|
+
var messagesEl = chatBox.querySelector('#rgl-msgs');
|
|
1204
|
+
var inputEl = chatBox.querySelector('#rgl-input');
|
|
1205
|
+
var sendBtn = chatBox.querySelector('#rgl-send');
|
|
1206
|
+
var fileInput = chatBox.querySelector('#rgl-file');
|
|
1207
|
+
var attachBtn = chatBox.querySelector('#rgl-attach');
|
|
1208
|
+
var previewEl = chatBox.querySelector('#rgl-preview');
|
|
125
1209
|
|
|
126
1210
|
// ==================== 工具函数 ====================
|
|
1211
|
+
function escHtml(text) {
|
|
1212
|
+
return String(text == null ? '' : text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
1213
|
+
}
|
|
1214
|
+
// 相对路径图片按 API_BASE 补全(SDK 嵌入跨域站点时相对路径会失效)
|
|
1215
|
+
function resolveUrl(u) {
|
|
1216
|
+
if (!u) return '';
|
|
1217
|
+
return u.indexOf('http') === 0 ? u : API_BASE + u;
|
|
1218
|
+
}
|
|
127
1219
|
function renderMarkdown(text) {
|
|
128
|
-
var html =
|
|
129
|
-
html = html.replace(/```(\w*)\n([\s\S]*?)```/g, '<pre style="background:#f0f0f0;padding:8px;border-radius:6px;font-size:13px;overflow-x:auto;"><code>$2</code></pre>');
|
|
1220
|
+
var html = escHtml(text);
|
|
1221
|
+
html = html.replace(/```(\w*)\n([\s\S]*?)```/g, '<pre style="background:#f0f0f0;padding:8px;border-radius:6px;font-size:13px;overflow-x:auto;margin:6px 0;"><code>$2</code></pre>');
|
|
130
1222
|
html = html.replace(/`([^`]+)`/g, '<code style="background:#f0f0f0;padding:1px 4px;border-radius:3px;font-size:13px;">$1</code>');
|
|
131
1223
|
html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
|
|
132
1224
|
html = html.replace(/\*(.+?)\*/g, '<em>$1</em>');
|
|
@@ -140,139 +1232,347 @@
|
|
|
140
1232
|
html = html.replace(/^---$/gm, '<hr style="border:none;border-top:1px solid #ddd;margin:8px 0;">');
|
|
141
1233
|
return html;
|
|
142
1234
|
}
|
|
143
|
-
|
|
144
|
-
// 消息时间(HH:MM)
|
|
145
1235
|
function formatTime(ts) {
|
|
146
1236
|
var d = ts ? new Date(String(ts).replace(' ', 'T')) : new Date();
|
|
147
1237
|
if (isNaN(d.getTime())) d = new Date();
|
|
148
1238
|
var pad = function (n) { return n < 10 ? '0' + n : '' + n; };
|
|
149
1239
|
return pad(d.getHours()) + ':' + pad(d.getMinutes());
|
|
150
1240
|
}
|
|
151
|
-
// 消息昵称
|
|
152
1241
|
function roleLabel(role, name) {
|
|
153
1242
|
if (role === 'user') return VISITOR_NAME || '我';
|
|
154
|
-
if (role === 'assistant') return 'AI';
|
|
1243
|
+
if (role === 'assistant') return 'AI客服';
|
|
155
1244
|
return name || '客服';
|
|
156
1245
|
}
|
|
157
|
-
// 昵称+时间(气泡上方,头像右侧)
|
|
158
1246
|
function makeMsgHeader(role, name, time) {
|
|
159
1247
|
var el = document.createElement('div');
|
|
160
|
-
el.
|
|
1248
|
+
el.className = 'rgl-msg-meta';
|
|
161
1249
|
el.textContent = roleLabel(role, name) + ' · ' + formatTime(time);
|
|
162
1250
|
return el;
|
|
163
1251
|
}
|
|
164
|
-
|
|
165
1252
|
function makeAvatar(role, name) {
|
|
166
1253
|
var avatar = document.createElement('div');
|
|
167
|
-
avatar.
|
|
168
|
-
(role === 'user' ? 'background:#10b981;' : 'background:' + PRIMARY + ';');
|
|
1254
|
+
avatar.className = 'rgl-msg-avatar';
|
|
169
1255
|
if (role === 'user') {
|
|
1256
|
+
avatar.style.background = '#10b981';
|
|
170
1257
|
avatar.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>';
|
|
171
1258
|
} else {
|
|
172
|
-
|
|
173
|
-
|
|
1259
|
+
avatar.style.background = PRIMARY;
|
|
1260
|
+
if (role === 'agent' && agentAvatar) {
|
|
1261
|
+
avatar.style.backgroundImage = 'url(' + agentAvatar + ')';
|
|
1262
|
+
} else {
|
|
1263
|
+
avatar.textContent = (name ? name.charAt(0) : '助');
|
|
1264
|
+
}
|
|
174
1265
|
}
|
|
175
1266
|
return avatar;
|
|
176
1267
|
}
|
|
177
|
-
|
|
178
1268
|
function addTextMessage(role, content, name, time) {
|
|
179
1269
|
var div = document.createElement('div');
|
|
180
|
-
div.
|
|
181
|
-
(role === 'user' ? 'justify-content:flex-end;' : 'justify-content:flex-start;');
|
|
1270
|
+
div.className = 'rgl-msg ' + (role === 'user' ? 'user' : (role === 'agent' ? 'agent' : 'bot'));
|
|
182
1271
|
if (role !== 'user') div.appendChild(makeAvatar(role, name));
|
|
183
|
-
// 头像右侧列:昵称+时间(上) + 气泡(下);flex:1 给出确定宽度基准,气泡宽度随内容
|
|
184
1272
|
var col = document.createElement('div');
|
|
185
|
-
col.
|
|
186
|
-
(role === 'user' ? 'flex-end' : 'flex-start') + ';';
|
|
1273
|
+
col.className = 'rgl-msg-col';
|
|
187
1274
|
col.appendChild(makeMsgHeader(role, name, time));
|
|
188
1275
|
var bubble = document.createElement('div');
|
|
189
|
-
bubble.
|
|
190
|
-
(role === 'user' ? 'background:' + PRIMARY + ';color:white;' : 'background:white;color:#333;border:1px solid #e0e0e0;');
|
|
1276
|
+
bubble.className = 'rgl-bubble';
|
|
191
1277
|
if (role === 'user') {
|
|
192
1278
|
bubble.textContent = content;
|
|
193
1279
|
} else {
|
|
194
1280
|
bubble.innerHTML = renderMarkdown(content);
|
|
195
|
-
// AI 回复下挂"转人工"快捷入口
|
|
196
1281
|
if (role === 'assistant' && serviceMode === 'bot') appendQuickTransfer(bubble);
|
|
197
1282
|
}
|
|
198
1283
|
col.appendChild(bubble);
|
|
199
1284
|
div.appendChild(col);
|
|
200
1285
|
if (role === 'user') div.appendChild(makeAvatar('user'));
|
|
201
1286
|
messagesEl.appendChild(div);
|
|
202
|
-
|
|
1287
|
+
scrollToBottom();
|
|
203
1288
|
}
|
|
204
|
-
|
|
205
1289
|
function addImageMessage(role, imageUrl, time) {
|
|
206
1290
|
var div = document.createElement('div');
|
|
207
|
-
div.
|
|
208
|
-
(role === 'user' ? 'justify-content:flex-end;' : 'justify-content:flex-start;');
|
|
1291
|
+
div.className = 'rgl-msg ' + (role === 'user' ? 'user' : 'bot');
|
|
209
1292
|
if (role !== 'user') div.appendChild(makeAvatar(role));
|
|
210
1293
|
var col = document.createElement('div');
|
|
211
|
-
col.
|
|
212
|
-
(role === 'user' ? 'flex-end' : 'flex-start') + ';';
|
|
1294
|
+
col.className = 'rgl-msg-col';
|
|
213
1295
|
col.appendChild(makeMsgHeader(role, '', time));
|
|
214
1296
|
var bubble = document.createElement('div');
|
|
215
|
-
bubble.
|
|
1297
|
+
bubble.className = 'rgl-bubble';
|
|
1298
|
+
bubble.style.padding = '4px';
|
|
1299
|
+
bubble.style.border = '1px solid #e0e2e8';
|
|
216
1300
|
var img = document.createElement('img');
|
|
217
|
-
img.src =
|
|
218
|
-
img.style.cssText = 'max-width:100%;max-height:200px;
|
|
1301
|
+
img.src = resolveUrl(imageUrl);
|
|
1302
|
+
img.style.cssText = 'max-width:100%;max-height:200px;border-radius:8px;';
|
|
219
1303
|
img.onclick = function () { window.open(img.src, '_blank'); };
|
|
220
1304
|
bubble.appendChild(img);
|
|
221
1305
|
col.appendChild(bubble);
|
|
222
1306
|
div.appendChild(col);
|
|
223
1307
|
if (role === 'user') div.appendChild(makeAvatar('user'));
|
|
224
1308
|
messagesEl.appendChild(div);
|
|
225
|
-
|
|
1309
|
+
scrollToBottom();
|
|
226
1310
|
}
|
|
227
|
-
|
|
228
1311
|
function addSystemMessage(content) {
|
|
229
1312
|
var div = document.createElement('div');
|
|
230
|
-
div.
|
|
231
|
-
div.innerHTML = '<
|
|
1313
|
+
div.className = 'rgl-msg-system';
|
|
1314
|
+
div.innerHTML = '<span>' + renderMarkdown(content) + '</span>';
|
|
232
1315
|
messagesEl.appendChild(div);
|
|
233
|
-
|
|
1316
|
+
scrollToBottom();
|
|
234
1317
|
}
|
|
235
|
-
|
|
236
1318
|
function addTyping() {
|
|
1319
|
+
if (document.getElementById('rgl-typing')) return;
|
|
237
1320
|
var div = document.createElement('div');
|
|
238
|
-
div.
|
|
239
|
-
div.style.cssText = 'margin-bottom:12px;display:flex;align-items:flex-start;gap:8px;justify-content:flex-start;';
|
|
1321
|
+
div.className = 'rgl-msg';
|
|
240
1322
|
div.appendChild(makeAvatar('assistant'));
|
|
241
|
-
var
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
1323
|
+
var col = document.createElement('div');
|
|
1324
|
+
col.className = 'rgl-msg-col';
|
|
1325
|
+
var typing = document.createElement('div');
|
|
1326
|
+
typing.className = 'rgl-typing';
|
|
1327
|
+
typing.id = 'rgl-typing';
|
|
1328
|
+
typing.innerHTML = '<i></i><i></i><i></i> 正在思考...';
|
|
1329
|
+
col.appendChild(typing);
|
|
1330
|
+
div.appendChild(col);
|
|
245
1331
|
messagesEl.appendChild(div);
|
|
246
|
-
|
|
1332
|
+
scrollToBottom();
|
|
247
1333
|
}
|
|
248
|
-
function removeTyping() {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (serviceMode === 'agent' && agentName) {
|
|
255
|
-
agentAvatarEl.style.display = 'flex';
|
|
256
|
-
agentAvatarEl.textContent = agentName.charAt(0);
|
|
257
|
-
if (agentAvatar) agentAvatarEl.style.backgroundImage = 'url(' + agentAvatar + ')';
|
|
258
|
-
} else {
|
|
259
|
-
agentAvatarEl.style.display = 'none';
|
|
1334
|
+
function removeTyping() {
|
|
1335
|
+
var el = document.getElementById('rgl-typing');
|
|
1336
|
+
if (el) {
|
|
1337
|
+
var row = el.closest('.rgl-msg'); // 整行移除,避免遗留空头像(双头像问题)
|
|
1338
|
+
if (row) row.remove();
|
|
1339
|
+
else el.remove();
|
|
260
1340
|
}
|
|
261
|
-
transferBtn.style.display = (serviceMode === 'bot') ? 'block' : 'none';
|
|
262
1341
|
}
|
|
263
|
-
|
|
1342
|
+
function scrollToBottom() { messagesEl.scrollTop = messagesEl.scrollHeight; }
|
|
264
1343
|
function appendQuickTransfer(bubbleEl) {
|
|
265
1344
|
var link = document.createElement('div');
|
|
266
|
-
link.
|
|
1345
|
+
link.className = 'rgl-quick-transfer';
|
|
267
1346
|
link.textContent = '转人工客服 →';
|
|
268
1347
|
link.onclick = function () { requestTransfer(); };
|
|
269
1348
|
bubbleEl.appendChild(link);
|
|
270
1349
|
}
|
|
1350
|
+
function updateHeader() {
|
|
1351
|
+
titleEl.textContent = serviceMode === 'agent' ? '人工坐席' : (S.appName || '在线客服');
|
|
1352
|
+
subtitleEl.textContent = serviceMode === 'agent' && agentName ? agentName : '';
|
|
1353
|
+
if (serviceMode === 'agent') {
|
|
1354
|
+
headerAvatarEl.style.display = 'flex';
|
|
1355
|
+
if (agentAvatar) {
|
|
1356
|
+
headerAvatarEl.style.backgroundImage = 'url(' + agentAvatar + ')';
|
|
1357
|
+
headerAvatarEl.textContent = '';
|
|
1358
|
+
} else {
|
|
1359
|
+
headerAvatarEl.style.backgroundImage = 'none';
|
|
1360
|
+
headerAvatarEl.textContent = (agentName || '客').charAt(0);
|
|
1361
|
+
}
|
|
1362
|
+
} else {
|
|
1363
|
+
headerAvatarEl.style.display = 'none';
|
|
1364
|
+
headerAvatarEl.style.backgroundImage = 'none';
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// ==================== 知识库分栏(左侧伸缩,聊天保持原位) ====================
|
|
1369
|
+
function applyKbLayout() {
|
|
1370
|
+
// 仅在窗口打开时按右边缘锚定(隐藏时 offsetLeft/offsetTop 为 0,会破坏位置)
|
|
1371
|
+
var wasPlaced = isOpen && !!chatBox.style.left;
|
|
1372
|
+
var prevRight = wasPlaced ? (chatBox.offsetLeft + chatBox.offsetWidth) : null;
|
|
1373
|
+
var wantKb = S.faqEnabled && kbOpen;
|
|
1374
|
+
kbPaneEl.style.display = wantKb ? 'flex' : 'none';
|
|
1375
|
+
hdrKbEl.style.display = S.faqEnabled ? 'flex' : 'none';
|
|
1376
|
+
hdrKbEl.classList.toggle('active', wantKb);
|
|
1377
|
+
chatBox.style.width = wantKb ? '740px' : '400px';
|
|
1378
|
+
chatBox.style.maxWidth = 'calc(100vw - 24px)';
|
|
1379
|
+
if (wantKb) renderKbList();
|
|
1380
|
+
// 宽度变化后保持右边缘(右侧聊天列)位置不变:知识库只向左伸缩,不推移聊天
|
|
1381
|
+
if (wasPlaced && prevRight != null) {
|
|
1382
|
+
var pos = clampChatPos(prevRight - (chatBox.offsetWidth || 400), chatBox.offsetTop || 0);
|
|
1383
|
+
chatBox.style.left = pos.left + 'px';
|
|
1384
|
+
chatBox.style.top = pos.top + 'px';
|
|
1385
|
+
persistChatPos();
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
// 切换知识库:仅翻转状态,锚定逻辑在 applyKbLayout 内处理
|
|
1389
|
+
function toggleKb() {
|
|
1390
|
+
kbOpen = !kbOpen;
|
|
1391
|
+
applyKbLayout();
|
|
1392
|
+
}
|
|
1393
|
+
hdrKbEl.onclick = function (e) { e.stopPropagation(); toggleKb(); };
|
|
1394
|
+
|
|
1395
|
+
function renderKbList() {
|
|
1396
|
+
var keyword = (kbSearchEl.value || '').trim().toLowerCase();
|
|
1397
|
+
var list = S.faqs.filter(function (f) {
|
|
1398
|
+
if (!keyword) return true;
|
|
1399
|
+
return (f.title || '').toLowerCase().indexOf(keyword) !== -1;
|
|
1400
|
+
});
|
|
1401
|
+
kbListEl.innerHTML = '';
|
|
1402
|
+
if (!list.length) {
|
|
1403
|
+
var empty = document.createElement('div');
|
|
1404
|
+
empty.className = 'rgl-kb-empty';
|
|
1405
|
+
empty.textContent = keyword ? '未找到相关问题' : '暂无常见问题';
|
|
1406
|
+
kbListEl.appendChild(empty);
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
list.forEach(function (f) {
|
|
1410
|
+
var btn = document.createElement('button');
|
|
1411
|
+
btn.className = 'rgl-kb-item';
|
|
1412
|
+
var title = document.createElement('span');
|
|
1413
|
+
title.className = 'rgl-kb-item-title';
|
|
1414
|
+
title.textContent = f.title;
|
|
1415
|
+
btn.appendChild(title);
|
|
1416
|
+
if (f.content) {
|
|
1417
|
+
var snip = document.createElement('span');
|
|
1418
|
+
snip.className = 'rgl-kb-item-snip';
|
|
1419
|
+
snip.textContent = String(f.content).replace(/[#*`>\n]+/g, ' ').slice(0, 60);
|
|
1420
|
+
btn.appendChild(snip);
|
|
1421
|
+
}
|
|
1422
|
+
// 保持原对话逻辑:点击常见问题同时在右侧聊天中提问
|
|
1423
|
+
btn.onclick = function () { openKbDetail(f); sendMessage(f.title || ''); };
|
|
1424
|
+
kbListEl.appendChild(btn);
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
kbSearchEl.addEventListener('input', renderKbList);
|
|
1428
|
+
|
|
1429
|
+
function openKbDetail(f) {
|
|
1430
|
+
activeFaqId = f.id;
|
|
1431
|
+
kbListEl.style.display = 'none';
|
|
1432
|
+
kbDetailEl.style.display = 'flex';
|
|
1433
|
+
kbDetailTitleEl.textContent = f.title || '';
|
|
1434
|
+
kbDetailContentEl.innerHTML = renderMarkdown(f.content || '');
|
|
1435
|
+
kbDetailEl.querySelector('.rgl-kb-detail-scroll').scrollTop = 0;
|
|
1436
|
+
kbAskEl.onclick = function () { sendMessage(f.title || ''); };
|
|
1437
|
+
}
|
|
1438
|
+
function backKbList() {
|
|
1439
|
+
kbDetailEl.style.display = 'none';
|
|
1440
|
+
kbListEl.style.display = 'flex';
|
|
1441
|
+
renderKbList();
|
|
1442
|
+
}
|
|
1443
|
+
chatBox.querySelector('#rgl-kb-back').onclick = function (e) { e.stopPropagation(); backKbList(); };
|
|
1444
|
+
|
|
1445
|
+
// ==================== 聊天窗口定位 / 拖拽 ====================
|
|
1446
|
+
function clampChatPos(left, top) {
|
|
1447
|
+
var w = chatBox.offsetWidth || 400;
|
|
1448
|
+
var h = chatBox.offsetHeight || 620;
|
|
1449
|
+
left = Math.max(8, Math.min(window.innerWidth - w - 8, left));
|
|
1450
|
+
top = Math.max(8, Math.min(window.innerHeight - h - 8, top));
|
|
1451
|
+
return { left: left, top: top };
|
|
1452
|
+
}
|
|
1453
|
+
// 打开时按入口定位:常见问题=整体水平+垂直居中;在线客服=右侧垂直居中
|
|
1454
|
+
function positionForOpen() {
|
|
1455
|
+
var w = chatBox.offsetWidth || 400;
|
|
1456
|
+
var h = chatBox.offsetHeight || 620;
|
|
1457
|
+
var left, top;
|
|
1458
|
+
if (kbOpen) {
|
|
1459
|
+
left = Math.max(8, (window.innerWidth - w) / 2);
|
|
1460
|
+
top = Math.max(8, (window.innerHeight - h) / 2);
|
|
1461
|
+
} else {
|
|
1462
|
+
left = window.innerWidth - 96 - w;
|
|
1463
|
+
top = Math.max(12, (window.innerHeight - h) / 2);
|
|
1464
|
+
}
|
|
1465
|
+
var pos = clampChatPos(left, top);
|
|
1466
|
+
chatBox.style.left = pos.left + 'px';
|
|
1467
|
+
chatBox.style.top = pos.top + 'px';
|
|
1468
|
+
chatBox.style.right = 'auto';
|
|
1469
|
+
chatBox.style.bottom = 'auto';
|
|
1470
|
+
persistChatPos();
|
|
1471
|
+
}
|
|
1472
|
+
function persistChatPos() {
|
|
1473
|
+
try {
|
|
1474
|
+
localStorage.setItem(POS_KEY, JSON.stringify({ left: parseInt(chatBox.style.left, 10), top: parseInt(chatBox.style.top, 10) }));
|
|
1475
|
+
} catch (e) {}
|
|
1476
|
+
}
|
|
1477
|
+
var dragState = null;
|
|
1478
|
+
function dragStart(clientX, clientY) {
|
|
1479
|
+
var r = chatBox.getBoundingClientRect();
|
|
1480
|
+
dragState = { sx: clientX, sy: clientY, ox: r.left, oy: r.top };
|
|
1481
|
+
}
|
|
1482
|
+
function dragMove(clientX, clientY) {
|
|
1483
|
+
if (!dragState) return;
|
|
1484
|
+
var pos = clampChatPos(dragState.ox + (clientX - dragState.sx), dragState.oy + (clientY - dragState.sy));
|
|
1485
|
+
chatBox.style.left = pos.left + 'px';
|
|
1486
|
+
chatBox.style.top = pos.top + 'px';
|
|
1487
|
+
}
|
|
1488
|
+
function dragEnd() {
|
|
1489
|
+
if (!dragState) return;
|
|
1490
|
+
dragState = null;
|
|
1491
|
+
persistChatPos();
|
|
1492
|
+
}
|
|
1493
|
+
headerEl.addEventListener('pointerdown', function (e) {
|
|
1494
|
+
if (e.target.closest('button')) return;
|
|
1495
|
+
dragStart(e.clientX, e.clientY);
|
|
1496
|
+
e.preventDefault();
|
|
1497
|
+
});
|
|
1498
|
+
document.addEventListener('pointermove', function (e) {
|
|
1499
|
+
if (!dragState) return;
|
|
1500
|
+
dragMove(e.clientX, e.clientY);
|
|
1501
|
+
});
|
|
1502
|
+
document.addEventListener('pointerup', dragEnd);
|
|
1503
|
+
|
|
1504
|
+
// ==================== 配置合并 & 应用 ====================
|
|
1505
|
+
function applyConfigUI() {
|
|
1506
|
+
// 工具组合卡片按配置渲染
|
|
1507
|
+
renderMenu();
|
|
1508
|
+
// 知识库开关:默认不展开,点击「常见问题」才展开
|
|
1509
|
+
kbOpen = false;
|
|
1510
|
+
hdrKbEl.style.display = S.faqEnabled ? 'flex' : 'none';
|
|
1511
|
+
kbPaneEl.querySelector('#rgl-kb-title').textContent = S.faqTitle || '常见问题';
|
|
1512
|
+
if (!S.faqEnabled) { kbOpen = false; kbPaneEl.style.display = 'none'; }
|
|
1513
|
+
if (S.welcome && messagesEl.children.length === 0) {
|
|
1514
|
+
addSystemMessage(S.welcome);
|
|
1515
|
+
}
|
|
1516
|
+
updateHeader();
|
|
1517
|
+
applyKbLayout();
|
|
1518
|
+
}
|
|
1519
|
+
function mergeConfig(remote) {
|
|
1520
|
+
// 基础:后端注入默认值
|
|
1521
|
+
var qr = SERVER_CFG.qr_code_url
|
|
1522
|
+
? { title: SERVER_CFG.qr_code_title || '扫码咨询', desc: SERVER_CFG.qr_code_desc || '', url: SERVER_CFG.qr_code_url }
|
|
1523
|
+
: null;
|
|
1524
|
+
S = {
|
|
1525
|
+
qr: qr,
|
|
1526
|
+
contact: {
|
|
1527
|
+
phone: SERVER_CFG.contact_phone || '',
|
|
1528
|
+
email: SERVER_CFG.contact_email || '',
|
|
1529
|
+
online_url: SERVER_CFG.contact_online_url || '',
|
|
1530
|
+
address: SERVER_CFG.contact_address || '',
|
|
1531
|
+
},
|
|
1532
|
+
faqEnabled: SERVER_CFG.faq_enabled !== false,
|
|
1533
|
+
faqTitle: SERVER_CFG.faq_title || '常见问题',
|
|
1534
|
+
faqs: [],
|
|
1535
|
+
appName: '',
|
|
1536
|
+
welcome: WELCOME,
|
|
1537
|
+
};
|
|
1538
|
+
// 运行时后端最新配置
|
|
1539
|
+
if (remote) {
|
|
1540
|
+
if (remote.app_name) S.appName = remote.app_name;
|
|
1541
|
+
if (remote.welcome_message) S.welcome = remote.welcome_message;
|
|
1542
|
+
if (remote.qr_code && remote.qr_code.url) S.qr = remote.qr_code;
|
|
1543
|
+
if (remote.contact) {
|
|
1544
|
+
S.contact = Object.assign({}, S.contact, remote.contact);
|
|
1545
|
+
}
|
|
1546
|
+
if (typeof remote.faq_enabled === 'boolean') S.faqEnabled = remote.faq_enabled;
|
|
1547
|
+
if (remote.faq_title) S.faqTitle = remote.faq_title;
|
|
1548
|
+
if (Array.isArray(remote.faqs)) S.faqs = remote.faqs;
|
|
1549
|
+
}
|
|
1550
|
+
// 页面级配置最高优先级
|
|
1551
|
+
if (_cfg.qr_code) S.qr = _cfg.qr_code;
|
|
1552
|
+
if (_cfg.contact) S.contact = Object.assign({}, S.contact, _cfg.contact);
|
|
1553
|
+
if (typeof _cfg.faq_enabled === 'boolean') S.faqEnabled = _cfg.faq_enabled;
|
|
1554
|
+
if (_cfg.faq_title) S.faqTitle = _cfg.faq_title;
|
|
1555
|
+
if (Array.isArray(_cfg.faqs)) S.faqs = _cfg.faqs;
|
|
1556
|
+
if (_cfg.app_name) S.appName = _cfg.app_name;
|
|
1557
|
+
if (_cfg.welcome_message) S.welcome = _cfg.welcome_message;
|
|
1558
|
+
applyConfigUI();
|
|
1559
|
+
}
|
|
1560
|
+
// 运行时拉取该配置的 SDK 公开配置(二维码/联系方式/常见问题)
|
|
1561
|
+
function fetchSdkConfig() {
|
|
1562
|
+
try {
|
|
1563
|
+
fetch(API_BASE + '/api/v1/cs/sdk-config?app_id=' + encodeURIComponent(APP_ID))
|
|
1564
|
+
.then(function (r) { return r.json(); })
|
|
1565
|
+
.then(function (res) {
|
|
1566
|
+
if (res && res.code === 0 && res.data) { mergeConfig(res.data); }
|
|
1567
|
+
else { mergeConfig(null); }
|
|
1568
|
+
})
|
|
1569
|
+
.catch(function () { mergeConfig(null); });
|
|
1570
|
+
} catch (e) { mergeConfig(null); }
|
|
1571
|
+
}
|
|
271
1572
|
|
|
272
1573
|
// ==================== 转人工 ====================
|
|
273
1574
|
function requestTransfer() {
|
|
274
1575
|
if (serviceMode !== 'bot') return;
|
|
275
|
-
transferBtn.disabled = true;
|
|
276
1576
|
addSystemMessage('正在为您接入人工坐席...');
|
|
277
1577
|
fetch(API_BASE + '/api/v1/cs/transfer', {
|
|
278
1578
|
method: 'POST',
|
|
@@ -284,7 +1584,6 @@
|
|
|
284
1584
|
visitor_name: VISITOR_NAME || undefined,
|
|
285
1585
|
})
|
|
286
1586
|
}).then(function (res) { return res.json(); }).then(function (res) {
|
|
287
|
-
transferBtn.disabled = false;
|
|
288
1587
|
if (res.code === 0 && res.data) {
|
|
289
1588
|
var d = res.data;
|
|
290
1589
|
serviceMode = 'waiting';
|
|
@@ -303,13 +1602,11 @@
|
|
|
303
1602
|
updateHeader();
|
|
304
1603
|
}
|
|
305
1604
|
}).catch(function () {
|
|
306
|
-
transferBtn.disabled = false;
|
|
307
1605
|
serviceMode = 'bot';
|
|
308
1606
|
addSystemMessage('网络异常,转人工失败,请稍后再试');
|
|
309
1607
|
updateHeader();
|
|
310
1608
|
});
|
|
311
1609
|
}
|
|
312
|
-
transferBtn.onclick = requestTransfer;
|
|
313
1610
|
|
|
314
1611
|
// ==================== WebSocket(接收坐席消息) ====================
|
|
315
1612
|
function wsBase() {
|
|
@@ -318,10 +1615,9 @@
|
|
|
318
1615
|
if (base.indexOf('http://') === 0) return 'ws://' + base.slice(7);
|
|
319
1616
|
return (location.protocol === 'https:' ? 'wss://' : 'ws://') + location.host;
|
|
320
1617
|
}
|
|
321
|
-
var wsSessionId = null;
|
|
1618
|
+
var wsSessionId = null;
|
|
322
1619
|
function connectWS() {
|
|
323
1620
|
if (!sessionId) return;
|
|
324
|
-
// 会话ID变化(如结束后重新咨询开启新会话)时,断开旧连接并重连
|
|
325
1621
|
if (ws && ws.readyState === WebSocket.OPEN && wsSessionId === sessionId) return;
|
|
326
1622
|
try { if (ws) { ws.onclose = null; try { ws.close(); } catch (e) {} ws = null; wsConnected = false; } } catch (e) {}
|
|
327
1623
|
try {
|
|
@@ -340,7 +1636,6 @@
|
|
|
340
1636
|
removeTyping();
|
|
341
1637
|
serviceMode = 'agent';
|
|
342
1638
|
if (msg.agent_name && agentName !== msg.agent_name) { agentName = msg.agent_name; updateHeader(); }
|
|
343
|
-
// 收起对话框时累计未读数,悬浮按钮角标提示
|
|
344
1639
|
if (!isOpen) { unreadCount++; updateUnread(); }
|
|
345
1640
|
addTextMessage('agent', msg.content, msg.agent_name || '客服', msg.created_at);
|
|
346
1641
|
} else if (msg.type === 'agent_online') {
|
|
@@ -358,42 +1653,36 @@
|
|
|
358
1653
|
}
|
|
359
1654
|
}
|
|
360
1655
|
|
|
361
|
-
// ====================
|
|
1656
|
+
// ==================== 满意度评价(人工结束后) ====================
|
|
362
1657
|
function showRating() {
|
|
363
|
-
if (!sessionId || document.getElementById('
|
|
1658
|
+
if (!sessionId || document.getElementById('rgl-rating')) return;
|
|
364
1659
|
var div = document.createElement('div');
|
|
365
|
-
div.
|
|
366
|
-
div.
|
|
367
|
-
|
|
368
|
-
|
|
1660
|
+
div.className = 'rgl-rating';
|
|
1661
|
+
div.id = 'rgl-rating';
|
|
1662
|
+
var stars = '';
|
|
1663
|
+
for (var i = 1; i <= 5; i++) {
|
|
1664
|
+
stars += '<span class="rgl-star" data-v="' + i + '">★</span>';
|
|
1665
|
+
}
|
|
1666
|
+
div.innerHTML = '<div class="rgl-rating-card">' +
|
|
369
1667
|
'<div style="font-size:13px;color:#444;margin-bottom:6px;">请评价本次人工服务</div>' +
|
|
370
|
-
'<div style="display:flex;justify-content:center;gap:4px;">' +
|
|
371
|
-
'<
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
'
|
|
375
|
-
|
|
376
|
-
'</div>' +
|
|
377
|
-
'<div style="font-size:11px;color:#999;margin-top:4px;">点击星星评分</div>' +
|
|
378
|
-
'</div>';
|
|
379
|
-
var stars = div.querySelectorAll('.reglow-cs-star');
|
|
380
|
-
for (var i = 0; i < stars.length; i++) {
|
|
381
|
-
stars[i].addEventListener('click', function () {
|
|
382
|
-
var v = parseInt(this.getAttribute('data-v'), 10);
|
|
383
|
-
submitRating(v);
|
|
1668
|
+
'<div style="display:flex;justify-content:center;gap:4px;">' + stars + '</div>' +
|
|
1669
|
+
'<div style="font-size:11px;color:#999;margin-top:4px;">点击星星评分</div></div>';
|
|
1670
|
+
var starEls = div.querySelectorAll('.rgl-star');
|
|
1671
|
+
for (var j = 0; j < starEls.length; j++) {
|
|
1672
|
+
starEls[j].addEventListener('click', function () {
|
|
1673
|
+
submitRating(parseInt(this.getAttribute('data-v'), 10));
|
|
384
1674
|
});
|
|
385
1675
|
}
|
|
386
1676
|
messagesEl.appendChild(div);
|
|
387
|
-
|
|
1677
|
+
scrollToBottom();
|
|
388
1678
|
}
|
|
389
|
-
|
|
390
1679
|
function submitRating(rating) {
|
|
391
1680
|
fetch(API_BASE + '/api/v1/cs/rating', {
|
|
392
1681
|
method: 'POST',
|
|
393
1682
|
headers: { 'Content-Type': 'application/json' },
|
|
394
1683
|
body: JSON.stringify({ session_id: sessionId, rating: rating })
|
|
395
|
-
}).then(function (res) { return res.json(); }).then(function (
|
|
396
|
-
var el = document.getElementById('
|
|
1684
|
+
}).then(function (res) { return res.json(); }).then(function () {
|
|
1685
|
+
var el = document.getElementById('rgl-rating');
|
|
397
1686
|
if (el) {
|
|
398
1687
|
el.innerHTML = '<div style="display:inline-block;background:#e8f5e9;color:#2e7d32;border-radius:12px;padding:8px 16px;font-size:12px;">感谢您的评价(' + rating + ' 星)</div>';
|
|
399
1688
|
}
|
|
@@ -452,23 +1741,22 @@
|
|
|
452
1741
|
}
|
|
453
1742
|
function setPendingImage(url) {
|
|
454
1743
|
pendingImageUrl = url;
|
|
1744
|
+
previewEl.innerHTML = '';
|
|
455
1745
|
var wrapper = document.createElement('div');
|
|
456
|
-
wrapper.
|
|
1746
|
+
wrapper.className = 'rgl-preview-inner';
|
|
457
1747
|
var img = document.createElement('img');
|
|
458
|
-
img.src =
|
|
459
|
-
img.style.cssText = 'max-height:80px;max-width:200px;border-radius:8px;border:1px solid #ddd;';
|
|
1748
|
+
img.src = resolveUrl(url);
|
|
460
1749
|
wrapper.appendChild(img);
|
|
461
1750
|
var closeSpan = document.createElement('span');
|
|
462
|
-
closeSpan.
|
|
1751
|
+
closeSpan.className = 'rgl-preview-close';
|
|
463
1752
|
closeSpan.innerHTML = '×';
|
|
464
1753
|
closeSpan.onclick = clearPendingImage;
|
|
465
1754
|
wrapper.appendChild(closeSpan);
|
|
466
|
-
previewEl.innerHTML = '';
|
|
467
1755
|
previewEl.appendChild(wrapper);
|
|
468
1756
|
previewEl.style.display = 'block';
|
|
469
1757
|
}
|
|
470
1758
|
|
|
471
|
-
// ====================
|
|
1759
|
+
// ==================== 发送消息(SSE 流式) ====================
|
|
472
1760
|
function persistSession() {
|
|
473
1761
|
try { localStorage.setItem(STORAGE_KEY, sessionId); } catch (e) {}
|
|
474
1762
|
}
|
|
@@ -486,7 +1774,7 @@
|
|
|
486
1774
|
|
|
487
1775
|
var replyText = '';
|
|
488
1776
|
var replyDiv = null;
|
|
489
|
-
var replyId = '
|
|
1777
|
+
var replyId = 'rgl-reply-' + Date.now() + '-' + Math.random().toString(36).substr(2, 6);
|
|
490
1778
|
|
|
491
1779
|
fetch(API_BASE + '/api/v1/cs/chat', {
|
|
492
1780
|
method: 'POST',
|
|
@@ -499,6 +1787,16 @@
|
|
|
499
1787
|
visitor_name: VISITOR_NAME || undefined,
|
|
500
1788
|
})
|
|
501
1789
|
}).then(function (response) {
|
|
1790
|
+
// 非 2xx:读取后端 JSON 错误信息展示给用户(避免静默无响应)
|
|
1791
|
+
if (!response.ok) {
|
|
1792
|
+
return response.text().then(function (txt) {
|
|
1793
|
+
removeTyping();
|
|
1794
|
+
var msg = '服务暂时不可用,请稍后再试';
|
|
1795
|
+
try { var j = JSON.parse(txt); if (j && j.msg) msg = j.msg; } catch (e) {}
|
|
1796
|
+
addTextMessage('assistant', msg);
|
|
1797
|
+
sendBtn.disabled = false;
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
502
1800
|
var reader = response.body.getReader();
|
|
503
1801
|
var decoder = new TextDecoder();
|
|
504
1802
|
function read() {
|
|
@@ -519,13 +1817,13 @@
|
|
|
519
1817
|
if (!replyDiv) {
|
|
520
1818
|
removeTyping();
|
|
521
1819
|
replyDiv = document.createElement('div');
|
|
522
|
-
replyDiv.
|
|
1820
|
+
replyDiv.className = 'rgl-msg bot';
|
|
523
1821
|
replyDiv.appendChild(makeAvatar('assistant'));
|
|
524
1822
|
var replyCol = document.createElement('div');
|
|
525
|
-
replyCol.
|
|
1823
|
+
replyCol.className = 'rgl-msg-col';
|
|
526
1824
|
replyCol.appendChild(makeMsgHeader('assistant', '', ''));
|
|
527
1825
|
var bubble = document.createElement('div');
|
|
528
|
-
bubble.
|
|
1826
|
+
bubble.className = 'rgl-bubble';
|
|
529
1827
|
bubble.id = replyId;
|
|
530
1828
|
replyCol.appendChild(bubble);
|
|
531
1829
|
replyDiv.appendChild(replyCol);
|
|
@@ -534,12 +1832,10 @@
|
|
|
534
1832
|
replyText += json.content;
|
|
535
1833
|
var bubbleEl = document.getElementById(replyId);
|
|
536
1834
|
if (bubbleEl) bubbleEl.innerHTML = renderMarkdown(replyText);
|
|
537
|
-
|
|
1835
|
+
scrollToBottom();
|
|
538
1836
|
} else if (json.type === 'handled_by_agent') {
|
|
539
|
-
// 人工模式下消息已转交坐席,回复将通过 WebSocket 推送
|
|
540
1837
|
removeTyping();
|
|
541
1838
|
} else if (json.type === 'transfer_required') {
|
|
542
|
-
// 智能转人工:系统已自动接入坐席
|
|
543
1839
|
removeTyping();
|
|
544
1840
|
serviceMode = json.agent_id ? 'agent' : 'waiting';
|
|
545
1841
|
if (json.agent_name) { agentName = json.agent_name; updateHeader(); }
|
|
@@ -547,10 +1843,7 @@
|
|
|
547
1843
|
connectWS();
|
|
548
1844
|
} else if (json.type === 'done') {
|
|
549
1845
|
sendBtn.disabled = false;
|
|
550
|
-
if (replyText && replyDiv)
|
|
551
|
-
// AI 回复下挂"转人工"快捷入口
|
|
552
|
-
if (serviceMode === 'bot') appendQuickTransfer(replyDiv.lastChild);
|
|
553
|
-
}
|
|
1846
|
+
if (replyText && replyDiv && serviceMode === 'bot') appendQuickTransfer(replyDiv.lastChild);
|
|
554
1847
|
if (!replyText) removeTyping();
|
|
555
1848
|
} else if (json.type === 'error') {
|
|
556
1849
|
removeTyping();
|
|
@@ -561,7 +1854,6 @@
|
|
|
561
1854
|
}
|
|
562
1855
|
read();
|
|
563
1856
|
}).catch(function () {
|
|
564
|
-
// 流被中断(连接重置/后端重启):恢复输入并提示,避免 UI 卡死
|
|
565
1857
|
sendBtn.disabled = false;
|
|
566
1858
|
removeTyping();
|
|
567
1859
|
if (!replyText) addTextMessage('assistant', '网络中断,请重新发送');
|
|
@@ -579,6 +1871,7 @@
|
|
|
579
1871
|
inputEl.onkeydown = function (e) { if (e.key === 'Enter') sendMessage(); };
|
|
580
1872
|
|
|
581
1873
|
// 文件选择 -> 预览
|
|
1874
|
+
attachBtn.onclick = function () { fileInput.click(); };
|
|
582
1875
|
fileInput.onchange = function () {
|
|
583
1876
|
if (fileInput.files && fileInput.files[0]) {
|
|
584
1877
|
var file = fileInput.files[0];
|
|
@@ -607,25 +1900,37 @@
|
|
|
607
1900
|
});
|
|
608
1901
|
|
|
609
1902
|
// ==================== 窗口开关 ====================
|
|
610
|
-
|
|
611
|
-
|
|
1903
|
+
chatBox.querySelector('#rgl-close').addEventListener('click', function (e) {
|
|
1904
|
+
e.stopPropagation(); e.preventDefault();
|
|
1905
|
+
closeChat();
|
|
1906
|
+
});
|
|
1907
|
+
|
|
1908
|
+
function toggleChat() {
|
|
612
1909
|
isOpen = !isOpen;
|
|
613
1910
|
chatBox.style.display = isOpen ? 'flex' : 'none';
|
|
614
|
-
if (isOpen)
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if (sessionId) { loadHistory(); connectWS(); }
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
chatBox.querySelector('#reglow-cs-close').addEventListener('click', function (e) {
|
|
622
|
-
e.stopPropagation(); e.preventDefault();
|
|
1911
|
+
if (isOpen) openChatInner();
|
|
1912
|
+
else closePop();
|
|
1913
|
+
}
|
|
1914
|
+
function closeChat() {
|
|
623
1915
|
isOpen = false;
|
|
624
1916
|
chatBox.style.display = 'none';
|
|
625
|
-
|
|
1917
|
+
closePop();
|
|
1918
|
+
}
|
|
1919
|
+
function openChatInner() {
|
|
1920
|
+
clearUnread();
|
|
1921
|
+
applyKbLayout(); // 先按知识库开关设定窗口宽度(在线客服=400/常见问题=740)
|
|
1922
|
+
positionForOpen(); // 再按入口定位:常见问题=整体居中;在线客服=右侧垂直居中
|
|
1923
|
+
if (!messagesEl.children.length) addSystemMessage(S.welcome || WELCOME);
|
|
1924
|
+
inputEl.focus();
|
|
1925
|
+
if (sessionId) { loadHistory(); connectWS(); }
|
|
1926
|
+
}
|
|
1927
|
+
function openChat(view) {
|
|
1928
|
+
isOpen = true;
|
|
1929
|
+
chatBox.style.display = 'flex';
|
|
1930
|
+
openChatInner();
|
|
1931
|
+
}
|
|
626
1932
|
|
|
627
1933
|
// ==================== 帮助助手模式 ====================
|
|
628
|
-
// 页面任意元素加 data-cs-question="问题文本",点击即打开客服并自动发送该问题
|
|
629
1934
|
function bindHelpElements() {
|
|
630
1935
|
var nodes = document.querySelectorAll('[data-cs-question]');
|
|
631
1936
|
for (var i = 0; i < nodes.length; i++) {
|
|
@@ -635,32 +1940,29 @@
|
|
|
635
1940
|
var q = node.getAttribute('data-cs-question');
|
|
636
1941
|
node.addEventListener('click', function (e) {
|
|
637
1942
|
e.stopPropagation();
|
|
638
|
-
openChat();
|
|
1943
|
+
openChat('chat');
|
|
639
1944
|
sendMessage(q || '你好,我有一个问题想咨询');
|
|
640
1945
|
});
|
|
641
1946
|
})(nodes[i]);
|
|
642
1947
|
}
|
|
643
1948
|
}
|
|
644
|
-
|
|
645
|
-
isOpen = true;
|
|
646
|
-
chatBox.style.display = 'flex';
|
|
647
|
-
clearUnread();
|
|
648
|
-
if (!messagesEl.children.length) addSystemMessage(WELCOME);
|
|
649
|
-
connectWS();
|
|
650
|
-
}
|
|
651
|
-
// 暴露全局 API:window.ReglowCS.open(question)
|
|
1949
|
+
// 暴露全局 API:window.ReglowCS
|
|
652
1950
|
try {
|
|
653
1951
|
window.ReglowCS = window.ReglowCS || {};
|
|
654
1952
|
window.ReglowCS.open = function (question) {
|
|
655
|
-
openChat();
|
|
1953
|
+
openChat('chat');
|
|
656
1954
|
if (question) sendMessage(question);
|
|
657
1955
|
else inputEl.focus();
|
|
658
1956
|
};
|
|
1957
|
+
window.ReglowCS.openKb = function () { kbOpen = true; openChat('chat'); };
|
|
659
1958
|
} catch (e) {}
|
|
660
1959
|
|
|
661
|
-
//
|
|
662
|
-
|
|
1960
|
+
// ==================== 初始化 ====================
|
|
1961
|
+
mergeConfig(null); // 先用后端注入默认值渲染 UI
|
|
1962
|
+
fetchSdkConfig(); // 运行时拉取最新配置(二维码/联系方式/常见问题)
|
|
1963
|
+
// 聊天窗位置在首次打开时(openChatInner -> placeChat)按真实宽度计算,避免隐藏时 offsetWidth=0 导致默认位错误
|
|
663
1964
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', bindLoop);
|
|
664
1965
|
else bindLoop();
|
|
1966
|
+
function bindLoop() { bindHelpElements(); setTimeout(bindLoop, 1500); }
|
|
665
1967
|
})();
|
|
666
1968
|
</script>
|