odant-work 1.0.79 → 1.0.81
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/#system/package-manifest.json +14 -12
- package/$server/$folder/lib/explorer/explorer.js +56 -1
- package/$server/$folder/lib/node/node.js +266 -0
- package/$server/$folder/lib/support/support.js +1232 -0
- package/package.json +1 -1
- package/sources/client/folder.js +4 -0
- package/sources/host/auto-updater.js +79 -14
- package/sources/modules/support/index.js +414 -0
- package/sources/server/access/gateway.js +5 -2
- package/sources/server/class.js +11 -0
- package/sources/server/server.js +85 -6
- package/sources/work.js +9 -4
|
@@ -0,0 +1,1232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Клиентский модуль службы поддержки и встроенного Remote Desktop (ODA):
|
|
3
|
+
* - <work-support-panel>: создание обращения (скриншот с разметкой / видео до 60 сек / техданные) + переписка по тикетам;
|
|
4
|
+
* - <work-support-remote-bar>: плавающая плашка активного Remote Desktop с переключателем «Только просмотр / Управление WORK»,
|
|
5
|
+
* WebRTC + резервной передачей кадров, лазерной указкой и безопасным управлением интерфейсом WORK (включая iframe форм).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const MAX_VIDEO_SEC = 60;
|
|
9
|
+
const REMOTE_POLL_MS = 650;
|
|
10
|
+
|
|
11
|
+
export function installSupportErrorCollector() {
|
|
12
|
+
if (typeof window === 'undefined') return;
|
|
13
|
+
const host = globalThis.WORK || window;
|
|
14
|
+
if (host.__supportErrInstalled) return;
|
|
15
|
+
host.__supportErrInstalled = true;
|
|
16
|
+
host.__supportErrors = host.__supportErrors || [];
|
|
17
|
+
const pushErr = (kind, msg) => {
|
|
18
|
+
const list = host.__supportErrors;
|
|
19
|
+
list.push({ time: new Date().toISOString(), kind, message: String(msg || '').slice(0, 300) });
|
|
20
|
+
if (list.length > 15) list.shift();
|
|
21
|
+
};
|
|
22
|
+
window.addEventListener('error', (e) => pushErr('error', e?.message || e?.error?.message || 'Script error'));
|
|
23
|
+
window.addEventListener('unhandledrejection', (e) => pushErr('rejection', e?.reason?.message || e?.reason || 'Unhandled rejection'));
|
|
24
|
+
}
|
|
25
|
+
installSupportErrorCollector();
|
|
26
|
+
|
|
27
|
+
function deepElementFromPoint(x, y) {
|
|
28
|
+
let doc = document;
|
|
29
|
+
let cx = x;
|
|
30
|
+
let cy = y;
|
|
31
|
+
for (let hop = 0; hop < 8; hop++) {
|
|
32
|
+
let el = doc.elementFromPoint(cx, cy);
|
|
33
|
+
if (!el) return null;
|
|
34
|
+
while (el && el.shadowRoot) {
|
|
35
|
+
const inner = el.shadowRoot.elementFromPoint(cx, cy);
|
|
36
|
+
if (!inner || inner === el) break;
|
|
37
|
+
el = inner;
|
|
38
|
+
}
|
|
39
|
+
if (el && el.tagName === 'IFRAME') {
|
|
40
|
+
try {
|
|
41
|
+
const subDoc = el.contentDocument;
|
|
42
|
+
if (subDoc) {
|
|
43
|
+
const r = el.getBoundingClientRect();
|
|
44
|
+
cx = cx - r.left;
|
|
45
|
+
cy = cy - r.top;
|
|
46
|
+
doc = subDoc;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return el;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return el;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isSensitiveOrProtectedTarget(el) {
|
|
60
|
+
if (!el) return true;
|
|
61
|
+
let cur = el;
|
|
62
|
+
for (let i = 0; i < 12 && cur; i++) {
|
|
63
|
+
const tag = String(cur.tagName || '').toLowerCase();
|
|
64
|
+
if (tag === 'work-support-remote-bar' || tag === 'work-support-panel')
|
|
65
|
+
return true;
|
|
66
|
+
if (tag === 'input' && String(cur.type || '').toLowerCase() === 'password')
|
|
67
|
+
return true;
|
|
68
|
+
if (cur.dataset?.secret !== undefined || cur.classList?.contains('secret'))
|
|
69
|
+
return true;
|
|
70
|
+
cur = cur.parentElement || cur.getRootNode?.()?.host || null;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const href = String(el.ownerDocument?.location?.href || '');
|
|
74
|
+
if (href.includes('#secret') || href.includes('read_secret'))
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch { /* ignore */ }
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function applyRemoteControlEvent(ev) {
|
|
82
|
+
if (!ev || typeof ev !== 'object') return;
|
|
83
|
+
const x = Math.max(0, Math.min(window.innerWidth - 1, Math.round((Number(ev.x) || 0) * window.innerWidth)));
|
|
84
|
+
const y = Math.max(0, Math.min(window.innerHeight - 1, Math.round((Number(ev.y) || 0) * window.innerHeight)));
|
|
85
|
+
const target = deepElementFromPoint(x, y);
|
|
86
|
+
if (!target || isSensitiveOrProtectedTarget(target))
|
|
87
|
+
return;
|
|
88
|
+
|
|
89
|
+
const win = target.ownerDocument?.defaultView || window;
|
|
90
|
+
if (ev.type === 'click' || ev.type === 'dblclick') {
|
|
91
|
+
target.focus?.();
|
|
92
|
+
const opts = { bubbles: true, cancelable: true, composed: true, clientX: x, clientY: y, view: win };
|
|
93
|
+
target.dispatchEvent(new MouseEvent('mousedown', opts));
|
|
94
|
+
target.dispatchEvent(new MouseEvent('mouseup', opts));
|
|
95
|
+
target.dispatchEvent(new MouseEvent('click', opts));
|
|
96
|
+
if (ev.type === 'dblclick')
|
|
97
|
+
target.dispatchEvent(new MouseEvent('dblclick', opts));
|
|
98
|
+
}
|
|
99
|
+
else if (ev.type === 'scroll') {
|
|
100
|
+
let sc = target;
|
|
101
|
+
while (sc && sc !== sc.ownerDocument?.documentElement) {
|
|
102
|
+
if (sc.scrollHeight > sc.clientHeight) {
|
|
103
|
+
sc.scrollTop += Number(ev.deltaY) || 0;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
sc = sc.parentElement || sc.getRootNode?.()?.host || null;
|
|
107
|
+
}
|
|
108
|
+
win.scrollBy(0, Number(ev.deltaY) || 0);
|
|
109
|
+
}
|
|
110
|
+
else if (ev.type === 'input' && typeof ev.text === 'string') {
|
|
111
|
+
const active = target.ownerDocument?.activeElement || target;
|
|
112
|
+
const el = (active && !isSensitiveOrProtectedTarget(active)) ? active : target;
|
|
113
|
+
if ('value' in el && !el.readOnly && !el.disabled) {
|
|
114
|
+
el.value = String(el.value || '') + ev.text;
|
|
115
|
+
el.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
116
|
+
el.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (ev.type === 'keydown' && typeof ev.key === 'string') {
|
|
120
|
+
const active = target.ownerDocument?.activeElement || target;
|
|
121
|
+
const el = (active && !isSensitiveOrProtectedTarget(active)) ? active : target;
|
|
122
|
+
if (ev.key === 'Backspace' && 'value' in el && !el.readOnly && !el.disabled) {
|
|
123
|
+
el.value = String(el.value || '').slice(0, -1);
|
|
124
|
+
el.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
el.dispatchEvent(new KeyboardEvent('keydown', { key: ev.key, bubbles: true, cancelable: true, composed: true }));
|
|
128
|
+
el.dispatchEvent(new KeyboardEvent('keyup', { key: ev.key, bubbles: true, cancelable: true, composed: true }));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
ODA({
|
|
133
|
+
is: 'work-support-remote-bar',
|
|
134
|
+
imports: 'oda//icon',
|
|
135
|
+
template: /*html*/`
|
|
136
|
+
<style>
|
|
137
|
+
:host {
|
|
138
|
+
position: fixed;
|
|
139
|
+
inset: 0;
|
|
140
|
+
pointer-events: none;
|
|
141
|
+
z-index: 2147483000;
|
|
142
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
143
|
+
}
|
|
144
|
+
.pill {
|
|
145
|
+
position: fixed;
|
|
146
|
+
top: 10px;
|
|
147
|
+
left: 50%;
|
|
148
|
+
transform: translateX(-50%);
|
|
149
|
+
pointer-events: auto;
|
|
150
|
+
display: flex;
|
|
151
|
+
align-items: center;
|
|
152
|
+
gap: 10px;
|
|
153
|
+
padding: 7px 14px;
|
|
154
|
+
border-radius: 999px;
|
|
155
|
+
background: #0f172a;
|
|
156
|
+
color: #f8fafc;
|
|
157
|
+
border: 1px solid rgba(56, 189, 248, 0.45);
|
|
158
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
|
|
159
|
+
font-size: 12.5px;
|
|
160
|
+
white-space: nowrap;
|
|
161
|
+
}
|
|
162
|
+
.dot {
|
|
163
|
+
width: 9px;
|
|
164
|
+
height: 9px;
|
|
165
|
+
border-radius: 50%;
|
|
166
|
+
background: #ef4444;
|
|
167
|
+
box-shadow: 0 0 8px #ef4444;
|
|
168
|
+
flex-shrink: 0;
|
|
169
|
+
}
|
|
170
|
+
.mode-btn {
|
|
171
|
+
border: 1px solid rgba(255, 255, 255, 0.22);
|
|
172
|
+
background: rgba(255, 255, 255, 0.1);
|
|
173
|
+
color: #fff;
|
|
174
|
+
border-radius: 999px;
|
|
175
|
+
padding: 4px 10px;
|
|
176
|
+
font: inherit;
|
|
177
|
+
font-size: 12px;
|
|
178
|
+
font-weight: 600;
|
|
179
|
+
cursor: pointer;
|
|
180
|
+
}
|
|
181
|
+
.mode-btn.control {
|
|
182
|
+
background: #16a34a;
|
|
183
|
+
border-color: #4ade80;
|
|
184
|
+
}
|
|
185
|
+
.stop-btn {
|
|
186
|
+
border: none;
|
|
187
|
+
background: #dc2626;
|
|
188
|
+
color: #fff;
|
|
189
|
+
border-radius: 999px;
|
|
190
|
+
padding: 4px 11px;
|
|
191
|
+
font: inherit;
|
|
192
|
+
font-size: 12px;
|
|
193
|
+
font-weight: 600;
|
|
194
|
+
cursor: pointer;
|
|
195
|
+
}
|
|
196
|
+
.cursor {
|
|
197
|
+
position: fixed;
|
|
198
|
+
pointer-events: none;
|
|
199
|
+
transform: translate(-4px, -4px);
|
|
200
|
+
display: flex;
|
|
201
|
+
align-items: center;
|
|
202
|
+
gap: 4px;
|
|
203
|
+
transition: left 60ms linear, top 60ms linear;
|
|
204
|
+
}
|
|
205
|
+
.cursor-dot {
|
|
206
|
+
width: 14px;
|
|
207
|
+
height: 14px;
|
|
208
|
+
border-radius: 50%;
|
|
209
|
+
background: rgba(239, 68, 68, 0.9);
|
|
210
|
+
border: 2px solid #fff;
|
|
211
|
+
box-shadow: 0 0 10px rgba(239, 68, 68, 0.85);
|
|
212
|
+
}
|
|
213
|
+
.cursor-tag {
|
|
214
|
+
padding: 2px 7px;
|
|
215
|
+
border-radius: 6px;
|
|
216
|
+
background: #ef4444;
|
|
217
|
+
color: #fff;
|
|
218
|
+
font-size: 11px;
|
|
219
|
+
font-weight: 600;
|
|
220
|
+
box-shadow: 0 2px 8px rgba(0,0,0,.3);
|
|
221
|
+
}
|
|
222
|
+
</style>
|
|
223
|
+
<div class="pill">
|
|
224
|
+
<span class="dot"></span>
|
|
225
|
+
<span>Поддержка видит экран · <b>{{ticketId}}</b></span>
|
|
226
|
+
<button type="button" class="mode-btn" :class="{ control: mode === 'control' }" @tap="toggleMode()">
|
|
227
|
+
{{mode === 'control' ? 'Управление WORK (вкл)' : 'Только просмотр'}}
|
|
228
|
+
</button>
|
|
229
|
+
<button type="button" class="stop-btn" @tap="stopSession()">Прервать</button>
|
|
230
|
+
</div>
|
|
231
|
+
<div class="cursor" ~if="cursorVisible" :style="'left:' + cursorX + 'px;top:' + cursorY + 'px'">
|
|
232
|
+
<div class="cursor-dot"></div>
|
|
233
|
+
<div class="cursor-tag">{{engineerName || 'Поддержка'}}</div>
|
|
234
|
+
</div>
|
|
235
|
+
`,
|
|
236
|
+
ticketId: '',
|
|
237
|
+
mode: 'view',
|
|
238
|
+
engineerName: 'Поддержка',
|
|
239
|
+
cursorVisible: false,
|
|
240
|
+
cursorX: 0,
|
|
241
|
+
cursorY: 0,
|
|
242
|
+
_stream: null,
|
|
243
|
+
_pc: null,
|
|
244
|
+
_pollTimer: null,
|
|
245
|
+
_frameTimer: null,
|
|
246
|
+
_lastOfferSeq: 0,
|
|
247
|
+
_iceConnected: false,
|
|
248
|
+
async start(ticketId, { mode = 'view', engineerName = 'Поддержка' } = {}) {
|
|
249
|
+
this.ticketId = ticketId;
|
|
250
|
+
this.mode = mode === 'control' ? 'control' : 'view';
|
|
251
|
+
this.engineerName = engineerName || 'Поддержка';
|
|
252
|
+
try {
|
|
253
|
+
this._stream = await navigator.mediaDevices.getDisplayMedia({
|
|
254
|
+
video: { frameRate: 12 },
|
|
255
|
+
preferCurrentTab: true,
|
|
256
|
+
audio: false,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
catch (err) {
|
|
260
|
+
throw new Error('Не удалось получить доступ к экрану: ' + (err?.message || err));
|
|
261
|
+
}
|
|
262
|
+
const track = this._stream.getVideoTracks()[0];
|
|
263
|
+
track?.addEventListener('ended', () => this.stopSession(true));
|
|
264
|
+
|
|
265
|
+
await WORK.fetch('/', 'support_remote', {}, JSON.stringify({
|
|
266
|
+
ticketId: this.ticketId,
|
|
267
|
+
action: 'start',
|
|
268
|
+
mode: this.mode,
|
|
269
|
+
}));
|
|
270
|
+
|
|
271
|
+
this._setupPeer();
|
|
272
|
+
this._startPolling();
|
|
273
|
+
this._startFallbackFrames();
|
|
274
|
+
},
|
|
275
|
+
_setupPeer() {
|
|
276
|
+
try {
|
|
277
|
+
const pc = new RTCPeerConnection({ iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] });
|
|
278
|
+
this._pc = pc;
|
|
279
|
+
for (const t of this._stream.getTracks())
|
|
280
|
+
pc.addTrack(t, this._stream);
|
|
281
|
+
pc.oniceconnectionstatechange = () => {
|
|
282
|
+
this._iceConnected = pc.iceConnectionState === 'connected' || pc.iceConnectionState === 'completed';
|
|
283
|
+
};
|
|
284
|
+
pc.onicecandidate = (e) => {
|
|
285
|
+
if (e.candidate && this.ticketId) {
|
|
286
|
+
WORK.fetch('/', 'support_remote', {}, JSON.stringify({
|
|
287
|
+
ticketId: this.ticketId,
|
|
288
|
+
action: 'ice',
|
|
289
|
+
candidate: e.candidate.toJSON ? e.candidate.toJSON() : e.candidate,
|
|
290
|
+
})).catch(() => {});
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
catch { /* fallback frames will handle it */ }
|
|
295
|
+
},
|
|
296
|
+
_startPolling() {
|
|
297
|
+
if (this._pollTimer) clearInterval(this._pollTimer);
|
|
298
|
+
this._pollTimer = setInterval(async () => {
|
|
299
|
+
if (!this.ticketId) return;
|
|
300
|
+
try {
|
|
301
|
+
const res = await WORK.fetch('/', 'support_remote', {}, JSON.stringify({
|
|
302
|
+
ticketId: this.ticketId,
|
|
303
|
+
action: 'poll',
|
|
304
|
+
}));
|
|
305
|
+
const r = res?.remote;
|
|
306
|
+
if (!r) return;
|
|
307
|
+
if (r.state === 'ended') {
|
|
308
|
+
this.stopSession(false);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (r.offer && r.offer.seq !== this._lastOfferSeq && this._pc) {
|
|
312
|
+
this._lastOfferSeq = r.offer.seq;
|
|
313
|
+
try {
|
|
314
|
+
await this._pc.setRemoteDescription(new RTCSessionDescription({ type: r.offer.type, sdp: r.offer.sdp }));
|
|
315
|
+
const ans = await this._pc.createAnswer();
|
|
316
|
+
await this._pc.setLocalDescription(ans);
|
|
317
|
+
await WORK.fetch('/', 'support_remote', {}, JSON.stringify({
|
|
318
|
+
ticketId: this.ticketId,
|
|
319
|
+
action: 'answer',
|
|
320
|
+
answer: { type: ans.type, sdp: ans.sdp },
|
|
321
|
+
}));
|
|
322
|
+
}
|
|
323
|
+
catch { /* ignore */ }
|
|
324
|
+
}
|
|
325
|
+
if (Array.isArray(r.ice) && this._pc) {
|
|
326
|
+
for (const c of r.ice) {
|
|
327
|
+
try { await this._pc.addIceCandidate(new RTCIceCandidate(c)); } catch { /* ignore */ }
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (Array.isArray(r.controlEvents)) {
|
|
331
|
+
for (const ev of r.controlEvents) {
|
|
332
|
+
if (ev.type === 'pointer') {
|
|
333
|
+
this.cursorVisible = true;
|
|
334
|
+
this.cursorX = Math.round((Number(ev.x) || 0) * window.innerWidth);
|
|
335
|
+
this.cursorY = Math.round((Number(ev.y) || 0) * window.innerHeight);
|
|
336
|
+
}
|
|
337
|
+
else if (this.mode === 'control') {
|
|
338
|
+
applyRemoteControlEvent(ev);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch { /* ignore */ }
|
|
344
|
+
}, REMOTE_POLL_MS);
|
|
345
|
+
},
|
|
346
|
+
_startFallbackFrames() {
|
|
347
|
+
if (this._frameTimer) clearInterval(this._frameTimer);
|
|
348
|
+
const video = document.createElement('video');
|
|
349
|
+
video.muted = true;
|
|
350
|
+
video.playsInline = true;
|
|
351
|
+
video.srcObject = this._stream;
|
|
352
|
+
video.play().catch(() => {});
|
|
353
|
+
const canvas = document.createElement('canvas');
|
|
354
|
+
this._frameTimer = setInterval(async () => {
|
|
355
|
+
if (this._iceConnected || !this._stream || !video.videoWidth) return;
|
|
356
|
+
const scale = Math.min(1, 1280 / video.videoWidth);
|
|
357
|
+
canvas.width = Math.max(1, Math.round(video.videoWidth * scale));
|
|
358
|
+
canvas.height = Math.max(1, Math.round(video.videoHeight * scale));
|
|
359
|
+
const ctx = canvas.getContext('2d');
|
|
360
|
+
if (!ctx) return;
|
|
361
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
362
|
+
const dataUrl = canvas.toDataURL('image/jpeg', 0.65);
|
|
363
|
+
WORK.fetch('/', 'support_remote', {}, JSON.stringify({
|
|
364
|
+
ticketId: this.ticketId,
|
|
365
|
+
action: 'frame',
|
|
366
|
+
dataUrl,
|
|
367
|
+
width: canvas.width,
|
|
368
|
+
height: canvas.height,
|
|
369
|
+
})).catch(() => {});
|
|
370
|
+
}, 1000);
|
|
371
|
+
},
|
|
372
|
+
async toggleMode() {
|
|
373
|
+
this.mode = this.mode === 'control' ? 'view' : 'control';
|
|
374
|
+
if (this.ticketId) {
|
|
375
|
+
await WORK.fetch('/', 'support_remote', {}, JSON.stringify({
|
|
376
|
+
ticketId: this.ticketId,
|
|
377
|
+
action: 'mode',
|
|
378
|
+
mode: this.mode,
|
|
379
|
+
})).catch(() => {});
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
async stopSession(notifyServer = true) {
|
|
383
|
+
const tid = this.ticketId;
|
|
384
|
+
this.ticketId = '';
|
|
385
|
+
if (this._pollTimer) clearInterval(this._pollTimer);
|
|
386
|
+
if (this._frameTimer) clearInterval(this._frameTimer);
|
|
387
|
+
this._pollTimer = null;
|
|
388
|
+
this._frameTimer = null;
|
|
389
|
+
try { this._pc?.close(); } catch { /* ignore */ }
|
|
390
|
+
this._pc = null;
|
|
391
|
+
try { this._stream?.getTracks?.().forEach(t => t.stop()); } catch { /* ignore */ }
|
|
392
|
+
this._stream = null;
|
|
393
|
+
if (notifyServer && tid) {
|
|
394
|
+
await WORK.fetch('/', 'support_remote', {}, JSON.stringify({
|
|
395
|
+
ticketId: tid,
|
|
396
|
+
action: 'end',
|
|
397
|
+
})).catch(() => {});
|
|
398
|
+
}
|
|
399
|
+
this.dispatchEvent(new CustomEvent('remote-ended', { bubbles: true, composed: true }));
|
|
400
|
+
this.remove();
|
|
401
|
+
},
|
|
402
|
+
detached() {
|
|
403
|
+
if (this._pollTimer) clearInterval(this._pollTimer);
|
|
404
|
+
if (this._frameTimer) clearInterval(this._frameTimer);
|
|
405
|
+
try { this._pc?.close(); } catch { /* ignore */ }
|
|
406
|
+
try { this._stream?.getTracks?.().forEach(t => t.stop()); } catch { /* ignore */ }
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
ODA({
|
|
411
|
+
is: 'work-support-panel',
|
|
412
|
+
imports: 'oda//icon, oda//button',
|
|
413
|
+
template: /*html*/`
|
|
414
|
+
<style>
|
|
415
|
+
:host {
|
|
416
|
+
position: fixed;
|
|
417
|
+
inset: 0;
|
|
418
|
+
z-index: 2147482000;
|
|
419
|
+
display: flex;
|
|
420
|
+
align-items: center;
|
|
421
|
+
justify-content: center;
|
|
422
|
+
background: rgba(15, 23, 42, 0.45);
|
|
423
|
+
backdrop-filter: blur(3px);
|
|
424
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
425
|
+
color: var(--content-color, #0f172a);
|
|
426
|
+
}
|
|
427
|
+
:host([minimized]) {
|
|
428
|
+
background: transparent;
|
|
429
|
+
backdrop-filter: none;
|
|
430
|
+
pointer-events: none;
|
|
431
|
+
align-items: flex-end;
|
|
432
|
+
justify-content: flex-end;
|
|
433
|
+
padding: 16px;
|
|
434
|
+
}
|
|
435
|
+
.rec-bar {
|
|
436
|
+
pointer-events: auto;
|
|
437
|
+
display: flex;
|
|
438
|
+
align-items: center;
|
|
439
|
+
gap: 10px;
|
|
440
|
+
padding: 10px 16px;
|
|
441
|
+
border-radius: 999px;
|
|
442
|
+
background: #0f172a;
|
|
443
|
+
color: #fff;
|
|
444
|
+
box-shadow: 0 12px 32px rgba(0,0,0,.35);
|
|
445
|
+
font-size: 13px;
|
|
446
|
+
}
|
|
447
|
+
.rec-dot {
|
|
448
|
+
width: 10px;
|
|
449
|
+
height: 10px;
|
|
450
|
+
border-radius: 50%;
|
|
451
|
+
background: #ef4444;
|
|
452
|
+
animation: pulse 1s infinite;
|
|
453
|
+
}
|
|
454
|
+
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
|
|
455
|
+
.card {
|
|
456
|
+
width: min(820px, 94vw);
|
|
457
|
+
max-height: 88vh;
|
|
458
|
+
display: flex;
|
|
459
|
+
flex-direction: column;
|
|
460
|
+
background: var(--content-background, #ffffff);
|
|
461
|
+
color: var(--content-color, #0f172a);
|
|
462
|
+
border: 1px solid var(--subtle-border, #cbd5e1);
|
|
463
|
+
border-radius: 14px;
|
|
464
|
+
box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28);
|
|
465
|
+
overflow: hidden;
|
|
466
|
+
}
|
|
467
|
+
.head {
|
|
468
|
+
display: flex;
|
|
469
|
+
align-items: center;
|
|
470
|
+
gap: 10px;
|
|
471
|
+
padding: 12px 16px;
|
|
472
|
+
background: var(--subtle-background, #f8fafc);
|
|
473
|
+
border-bottom: 1px solid var(--subtle-border, #e2e8f0);
|
|
474
|
+
}
|
|
475
|
+
.head-title {
|
|
476
|
+
font-weight: 700;
|
|
477
|
+
font-size: 15px;
|
|
478
|
+
}
|
|
479
|
+
.tabs {
|
|
480
|
+
display: flex;
|
|
481
|
+
gap: 6px;
|
|
482
|
+
margin-left: 12px;
|
|
483
|
+
}
|
|
484
|
+
.tab-btn {
|
|
485
|
+
border: 1px solid var(--subtle-border, #cbd5e1);
|
|
486
|
+
background: var(--content-background, #fff);
|
|
487
|
+
color: inherit;
|
|
488
|
+
border-radius: 8px;
|
|
489
|
+
padding: 5px 12px;
|
|
490
|
+
font: inherit;
|
|
491
|
+
font-size: 12.5px;
|
|
492
|
+
font-weight: 600;
|
|
493
|
+
cursor: pointer;
|
|
494
|
+
}
|
|
495
|
+
.tab-btn.active {
|
|
496
|
+
background: var(--accent-color, #4f46e5);
|
|
497
|
+
color: #fff;
|
|
498
|
+
border-color: var(--accent-color, #4f46e5);
|
|
499
|
+
}
|
|
500
|
+
.close-x {
|
|
501
|
+
margin-left: auto;
|
|
502
|
+
border: none;
|
|
503
|
+
background: transparent;
|
|
504
|
+
color: var(--muted-color, #64748b);
|
|
505
|
+
font-size: 20px;
|
|
506
|
+
cursor: pointer;
|
|
507
|
+
padding: 2px 8px;
|
|
508
|
+
border-radius: 6px;
|
|
509
|
+
}
|
|
510
|
+
.close-x:hover {
|
|
511
|
+
background: var(--subtle-background, #e2e8f0);
|
|
512
|
+
color: var(--content-color, #0f172a);
|
|
513
|
+
}
|
|
514
|
+
.body {
|
|
515
|
+
padding: 16px;
|
|
516
|
+
overflow-y: auto;
|
|
517
|
+
display: flex;
|
|
518
|
+
flex-direction: column;
|
|
519
|
+
gap: 12px;
|
|
520
|
+
min-height: 320px;
|
|
521
|
+
}
|
|
522
|
+
.capture-row {
|
|
523
|
+
display: flex;
|
|
524
|
+
gap: 8px;
|
|
525
|
+
flex-wrap: wrap;
|
|
526
|
+
align-items: center;
|
|
527
|
+
}
|
|
528
|
+
.btn {
|
|
529
|
+
border: 1px solid var(--subtle-border, #cbd5e1);
|
|
530
|
+
background: var(--subtle-background, #f1f5f9);
|
|
531
|
+
color: inherit;
|
|
532
|
+
border-radius: 8px;
|
|
533
|
+
padding: 7px 12px;
|
|
534
|
+
font: inherit;
|
|
535
|
+
font-size: 13px;
|
|
536
|
+
font-weight: 600;
|
|
537
|
+
cursor: pointer;
|
|
538
|
+
display: inline-flex;
|
|
539
|
+
align-items: center;
|
|
540
|
+
gap: 6px;
|
|
541
|
+
}
|
|
542
|
+
.btn:hover { filter: brightness(0.96); }
|
|
543
|
+
.btn.primary {
|
|
544
|
+
background: var(--accent-color, #4f46e5);
|
|
545
|
+
border-color: var(--accent-color, #4f46e5);
|
|
546
|
+
color: #fff;
|
|
547
|
+
}
|
|
548
|
+
.btn.ok {
|
|
549
|
+
background: #16a34a;
|
|
550
|
+
border-color: #16a34a;
|
|
551
|
+
color: #fff;
|
|
552
|
+
}
|
|
553
|
+
.btn.danger {
|
|
554
|
+
background: #dc2626;
|
|
555
|
+
border-color: #dc2626;
|
|
556
|
+
color: #fff;
|
|
557
|
+
}
|
|
558
|
+
textarea, input[type="text"] {
|
|
559
|
+
width: 100%;
|
|
560
|
+
box-sizing: border-box;
|
|
561
|
+
padding: 9px 12px;
|
|
562
|
+
border-radius: 8px;
|
|
563
|
+
border: 1px solid var(--subtle-border, #cbd5e1);
|
|
564
|
+
background: var(--content-background, #fff);
|
|
565
|
+
color: inherit;
|
|
566
|
+
font: inherit;
|
|
567
|
+
font-size: 13px;
|
|
568
|
+
}
|
|
569
|
+
.preview-box {
|
|
570
|
+
border: 1px solid var(--subtle-border, #cbd5e1);
|
|
571
|
+
border-radius: 10px;
|
|
572
|
+
padding: 10px;
|
|
573
|
+
background: var(--subtle-background, #f8fafc);
|
|
574
|
+
display: flex;
|
|
575
|
+
flex-direction: column;
|
|
576
|
+
gap: 8px;
|
|
577
|
+
}
|
|
578
|
+
.shot-canvas {
|
|
579
|
+
max-width: 100%;
|
|
580
|
+
max-height: 280px;
|
|
581
|
+
border-radius: 6px;
|
|
582
|
+
border: 1px solid var(--subtle-border, #cbd5e1);
|
|
583
|
+
cursor: crosshair;
|
|
584
|
+
align-self: center;
|
|
585
|
+
background: #0f172a;
|
|
586
|
+
}
|
|
587
|
+
.tickets-split {
|
|
588
|
+
display: grid;
|
|
589
|
+
grid-template-columns: 260px 1fr;
|
|
590
|
+
gap: 12px;
|
|
591
|
+
min-height: 360px;
|
|
592
|
+
}
|
|
593
|
+
@media (max-width: 680px) {
|
|
594
|
+
.tickets-split { grid-template-columns: 1fr; }
|
|
595
|
+
}
|
|
596
|
+
.t-list {
|
|
597
|
+
border: 1px solid var(--subtle-border, #e2e8f0);
|
|
598
|
+
border-radius: 10px;
|
|
599
|
+
overflow-y: auto;
|
|
600
|
+
max-height: 460px;
|
|
601
|
+
display: flex;
|
|
602
|
+
flex-direction: column;
|
|
603
|
+
}
|
|
604
|
+
.t-item {
|
|
605
|
+
padding: 10px 12px;
|
|
606
|
+
border-bottom: 1px solid var(--subtle-border, #e2e8f0);
|
|
607
|
+
cursor: pointer;
|
|
608
|
+
display: flex;
|
|
609
|
+
flex-direction: column;
|
|
610
|
+
gap: 4px;
|
|
611
|
+
}
|
|
612
|
+
.t-item:hover { background: var(--subtle-background, #f8fafc); }
|
|
613
|
+
.t-item.active {
|
|
614
|
+
background: color-mix(in srgb, var(--accent-color, #4f46e5) 10%, var(--content-background, #fff));
|
|
615
|
+
border-left: 3px solid var(--accent-color, #4f46e5);
|
|
616
|
+
}
|
|
617
|
+
.t-thread {
|
|
618
|
+
border: 1px solid var(--subtle-border, #e2e8f0);
|
|
619
|
+
border-radius: 10px;
|
|
620
|
+
padding: 12px;
|
|
621
|
+
display: flex;
|
|
622
|
+
flex-direction: column;
|
|
623
|
+
gap: 10px;
|
|
624
|
+
max-height: 460px;
|
|
625
|
+
}
|
|
626
|
+
.msgs {
|
|
627
|
+
flex: 1;
|
|
628
|
+
overflow-y: auto;
|
|
629
|
+
display: flex;
|
|
630
|
+
flex-direction: column;
|
|
631
|
+
gap: 8px;
|
|
632
|
+
}
|
|
633
|
+
.msg {
|
|
634
|
+
padding: 8px 11px;
|
|
635
|
+
border-radius: 10px;
|
|
636
|
+
background: var(--subtle-background, #f1f5f9);
|
|
637
|
+
font-size: 13px;
|
|
638
|
+
max-width: 90%;
|
|
639
|
+
}
|
|
640
|
+
.msg.support {
|
|
641
|
+
align-self: flex-start;
|
|
642
|
+
background: color-mix(in srgb, #2563eb 11%, var(--content-background, #fff));
|
|
643
|
+
border: 1px solid color-mix(in srgb, #2563eb 25%, transparent);
|
|
644
|
+
}
|
|
645
|
+
.msg.client {
|
|
646
|
+
align-self: flex-end;
|
|
647
|
+
background: color-mix(in srgb, var(--accent-color, #4f46e5) 10%, var(--content-background, #fff));
|
|
648
|
+
}
|
|
649
|
+
.tag {
|
|
650
|
+
display: inline-flex;
|
|
651
|
+
align-items: center;
|
|
652
|
+
padding: 2px 7px;
|
|
653
|
+
border-radius: 999px;
|
|
654
|
+
font-size: 11px;
|
|
655
|
+
font-weight: 600;
|
|
656
|
+
background: var(--subtle-background, #e2e8f0);
|
|
657
|
+
}
|
|
658
|
+
.tag.ok { background: #dcfce7; color: #15803d; }
|
|
659
|
+
.tag.warn { background: #fef3c7; color: #b45309; }
|
|
660
|
+
.tag.info { background: #e0f2fe; color: #0369a1; }
|
|
661
|
+
.remote-banner {
|
|
662
|
+
padding: 10px 12px;
|
|
663
|
+
border-radius: 10px;
|
|
664
|
+
border: 1px solid #38bdf8;
|
|
665
|
+
background: color-mix(in srgb, #0284c7 10%, var(--content-background, #fff));
|
|
666
|
+
display: flex;
|
|
667
|
+
flex-direction: column;
|
|
668
|
+
gap: 8px;
|
|
669
|
+
font-size: 13px;
|
|
670
|
+
}
|
|
671
|
+
.err { color: #dc2626; font-size: 12.5px; }
|
|
672
|
+
.muted { color: var(--muted-color, #64748b); font-size: 12px; }
|
|
673
|
+
</style>
|
|
674
|
+
|
|
675
|
+
<div ~if="recording" class="rec-bar">
|
|
676
|
+
<span class="rec-dot"></span>
|
|
677
|
+
<span>Запись экрана: {{recordSecLabel}} / 01:00</span>
|
|
678
|
+
<button type="button" class="btn danger" style="padding:4px 10px;font-size:12px" @tap="stopVideoCapture()">⏹ Остановить</button>
|
|
679
|
+
</div>
|
|
680
|
+
|
|
681
|
+
<div ~if="!minimized" class="card">
|
|
682
|
+
<div class="head">
|
|
683
|
+
<oda-icon icon="icons:help" icon-size="20"></oda-icon>
|
|
684
|
+
<span class="head-title">Служба поддержки ODANT-WORK</span>
|
|
685
|
+
<div class="tabs">
|
|
686
|
+
<button type="button" class="tab-btn" :class="{ active: activeTab === 'new' }" @tap="activeTab = 'new'">Новое обращение</button>
|
|
687
|
+
<button type="button" class="tab-btn" :class="{ active: activeTab === 'list' }" @tap="openListTab()">
|
|
688
|
+
Обращения ({{tickets.length}})<span ~if="unreadTotal > 0"> · +{{unreadTotal}}</span>
|
|
689
|
+
</button>
|
|
690
|
+
</div>
|
|
691
|
+
<button type="button" class="close-x" title="Закрыть" @tap="closePanel()">×</button>
|
|
692
|
+
</div>
|
|
693
|
+
|
|
694
|
+
<!-- Вкладка: Новое обращение -->
|
|
695
|
+
<div class="body" ~if="activeTab === 'new'">
|
|
696
|
+
<div class="capture-row">
|
|
697
|
+
<button type="button" class="btn" @tap="captureScreenshot()">📸 Скриншот экрана</button>
|
|
698
|
+
<button type="button" class="btn" @tap="startVideoCapture()">🎥 Записать видео (до 60 с)</button>
|
|
699
|
+
<label class="btn" style="cursor:pointer">
|
|
700
|
+
📎 Прикрепить файл
|
|
701
|
+
<input type="file" accept="image/*,video/*" style="display:none" @change="onFilePicked($event)">
|
|
702
|
+
</label>
|
|
703
|
+
<span class="muted">Скриншот и видео снимаются прямо с рабочего экрана WORK</span>
|
|
704
|
+
</div>
|
|
705
|
+
|
|
706
|
+
<!-- Редактор разметки скриншота -->
|
|
707
|
+
<div class="preview-box" ~if="hasScreenshot">
|
|
708
|
+
<div style="display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap">
|
|
709
|
+
<span class="muted">Можно обвести проблемное место прямо мышью по скриншоту:</span>
|
|
710
|
+
<div style="display:flex;gap:6px">
|
|
711
|
+
<button type="button" class="btn" style="padding:4px 9px;font-size:12px" @tap="clearScreenshotMarkup()">Сбросить пометки</button>
|
|
712
|
+
<button type="button" class="btn" style="padding:4px 9px;font-size:12px;color:#dc2626" @tap="removeScreenshot()">Удалить скриншот</button>
|
|
713
|
+
</div>
|
|
714
|
+
</div>
|
|
715
|
+
<canvas id="shotCanvas" class="shot-canvas"
|
|
716
|
+
@mousedown="onShotDrawStart($event)"
|
|
717
|
+
@mousemove="onShotDrawMove($event)"
|
|
718
|
+
@mouseup="onShotDrawEnd()"
|
|
719
|
+
@mouseleave="onShotDrawEnd()"></canvas>
|
|
720
|
+
</div>
|
|
721
|
+
|
|
722
|
+
<!-- Предпросмотр видео -->
|
|
723
|
+
<div class="preview-box" ~if="videoDataUrl">
|
|
724
|
+
<div style="display:flex;align-items:center;justify-content:space-between">
|
|
725
|
+
<span class="muted">Записанное видео ({{videoName}})</span>
|
|
726
|
+
<button type="button" class="btn" style="padding:4px 9px;font-size:12px;color:#dc2626" @tap="removeVideo()">Удалить видео</button>
|
|
727
|
+
</div>
|
|
728
|
+
<video controls :src="videoDataUrl" style="max-height:240px;border-radius:6px;background:#000"></video>
|
|
729
|
+
</div>
|
|
730
|
+
|
|
731
|
+
<div>
|
|
732
|
+
<textarea rows="4" placeholder="Опишите проблему: что делали, что ожидали и что пошло не так…" ::value="problemText"></textarea>
|
|
733
|
+
</div>
|
|
734
|
+
|
|
735
|
+
<label style="display:flex;align-items:center;gap:8px;font-size:12.5px;cursor:pointer;user-select:none">
|
|
736
|
+
<input type="checkbox" ::checked="includeTech">
|
|
737
|
+
<span>Приложить технические данные (версия WORK, путь текущей формы и ошибки)</span>
|
|
738
|
+
</label>
|
|
739
|
+
|
|
740
|
+
<div ~if="error" class="err">{{error}}</div>
|
|
741
|
+
|
|
742
|
+
<div style="display:flex;justify-content:flex-end;gap:8px">
|
|
743
|
+
<button type="button" class="btn" @tap="closePanel()">Отмена</button>
|
|
744
|
+
<button type="button" class="btn primary" :disabled="sending" @tap="submitTicket()">
|
|
745
|
+
{{sending ? 'Отправка…' : 'Отправить в поддержку'}}
|
|
746
|
+
</button>
|
|
747
|
+
</div>
|
|
748
|
+
</div>
|
|
749
|
+
|
|
750
|
+
<!-- Вкладка: Список обращений и переписка -->
|
|
751
|
+
<div class="body" ~if="activeTab === 'list'">
|
|
752
|
+
<div ~if="error" class="err">{{error}}</div>
|
|
753
|
+
<div ~if="!tickets.length && !loading" class="muted" style="padding:24px;text-align:center">
|
|
754
|
+
Обращений пока нет. Нажмите «Новое обращение», чтобы написать в службу поддержки.
|
|
755
|
+
</div>
|
|
756
|
+
<div class="tickets-split" ~if="tickets.length">
|
|
757
|
+
<div class="t-list">
|
|
758
|
+
<div class="t-item" ~for="tickets" :class="{ active: selectedTicketId === $for.item.ticketId }" @tap="selectTicket($for.item.ticketId)">
|
|
759
|
+
<div style="display:flex;align-items:center;justify-content:space-between;gap:6px">
|
|
760
|
+
<b style="font-size:12.5px">{{$for.item.ticketId}}</b>
|
|
761
|
+
<span class="tag" :class="$for.item.status === 'answered' ? 'ok' : ($for.item.status === 'in_progress' ? 'info' : 'warn')">
|
|
762
|
+
{{statusLabel($for.item.status)}}
|
|
763
|
+
</span>
|
|
764
|
+
</div>
|
|
765
|
+
<div class="muted" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
|
|
766
|
+
{{($for.item.messages?.[0]?.text) || 'Без описания'}}
|
|
767
|
+
</div>
|
|
768
|
+
<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap">
|
|
769
|
+
<span class="muted">{{formatTime($for.item.createdAt)}}</span>
|
|
770
|
+
<span ~if="$for.item.unreadCount > 0" class="tag ok">+{{$for.item.unreadCount}}</span>
|
|
771
|
+
<span ~if="$for.item.remote?.state === 'requested'" class="tag info">🖥 Запрос экрана</span>
|
|
772
|
+
</div>
|
|
773
|
+
</div>
|
|
774
|
+
</div>
|
|
775
|
+
|
|
776
|
+
<div class="t-thread" ~if="selectedTicket">
|
|
777
|
+
<div style="display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;border-bottom:1px solid var(--subtle-border,#e2e8f0);padding-bottom:8px">
|
|
778
|
+
<div>
|
|
779
|
+
<b>{{selectedTicket.ticketId}}</b>
|
|
780
|
+
<span class="tag" style="margin-left:6px">{{selectedTicket.tierName || 'Поддержка'}}</span>
|
|
781
|
+
<span ~if="selectedTicket.assignedSupportName" class="muted" style="margin-left:6px">Инженер: {{selectedTicket.assignedSupportName}}</span>
|
|
782
|
+
</div>
|
|
783
|
+
<button ~if="selectedTicket.status !== 'closed'" type="button" class="btn" style="padding:4px 9px;font-size:12px" @tap="startRemoteDesktop(selectedTicket.ticketId, 'view')">
|
|
784
|
+
🖥 Поделиться экраном
|
|
785
|
+
</button>
|
|
786
|
+
</div>
|
|
787
|
+
|
|
788
|
+
<!-- Запрос оператора на удалённый экран -->
|
|
789
|
+
<div class="remote-banner" ~if="selectedTicket.remote?.state === 'requested'">
|
|
790
|
+
<div><b>{{selectedTicket.remote?.requestedBy?.engineerName || 'Инженер поддержки'}}</b> запрашивает доступ к вашему экрану WORK.</div>
|
|
791
|
+
<div style="display:flex;gap:6px;flex-wrap:wrap">
|
|
792
|
+
<button type="button" class="btn ok" style="padding:5px 10px;font-size:12px" @tap="startRemoteDesktop(selectedTicket.ticketId, 'view')">Поделиться (Только просмотр)</button>
|
|
793
|
+
<button type="button" class="btn primary" style="padding:5px 10px;font-size:12px" @tap="startRemoteDesktop(selectedTicket.ticketId, 'control')">Поделиться с управлением</button>
|
|
794
|
+
<button type="button" class="btn" style="padding:5px 10px;font-size:12px" @tap="rejectRemoteDesktop(selectedTicket.ticketId)">Отклонить</button>
|
|
795
|
+
</div>
|
|
796
|
+
</div>
|
|
797
|
+
|
|
798
|
+
<div class="msgs">
|
|
799
|
+
<div class="msg" ~for="selectedTicket.messages" :class="$for.item.from === 'support' ? 'support' : 'client'">
|
|
800
|
+
<div class="muted" style="margin-bottom:2px"><b>{{$for.item.author}}</b> · {{formatTime($for.item.time)}}</div>
|
|
801
|
+
<div style="white-space:pre-wrap">{{$for.item.text}}</div>
|
|
802
|
+
<div ~if="$for.item.attachments?.length" style="display:flex;gap:6px;flex-wrap:wrap;margin-top:6px">
|
|
803
|
+
<div ~for="$for.item.attachments">
|
|
804
|
+
<img ~if="$for.$for.item.kind !== 'video'" :src="mediaUrl($for.$for.item)" style="max-width:220px;max-height:140px;border-radius:6px;border:1px solid var(--subtle-border);cursor:pointer" @tap="loadMediaInto($event, selectedTicket.ticketId, $for.$for.item)">
|
|
805
|
+
<video ~if="$for.$for.item.kind === 'video'" controls preload="metadata" :src="mediaUrl($for.$for.item)" style="max-width:260px;max-height:160px;border-radius:6px;background:#000"></video>
|
|
806
|
+
</div>
|
|
807
|
+
</div>
|
|
808
|
+
</div>
|
|
809
|
+
</div>
|
|
810
|
+
|
|
811
|
+
<div ~if="selectedTicket.status !== 'closed'" style="display:flex;gap:8px;align-items:center">
|
|
812
|
+
<input type="text" placeholder="Написать сообщение инженеру…" ::value="replyText" @keydown.enter="sendReply()">
|
|
813
|
+
<button type="button" class="btn primary" :disabled="sending" @tap="sendReply()">Отправить</button>
|
|
814
|
+
</div>
|
|
815
|
+
</div>
|
|
816
|
+
</div>
|
|
817
|
+
</div>
|
|
818
|
+
</div>
|
|
819
|
+
`,
|
|
820
|
+
activeTab: 'new',
|
|
821
|
+
problemText: '',
|
|
822
|
+
includeTech: true,
|
|
823
|
+
hasScreenshot: false,
|
|
824
|
+
_rawShotCanvas: null,
|
|
825
|
+
_drawing: false,
|
|
826
|
+
_lastPt: null,
|
|
827
|
+
videoDataUrl: '',
|
|
828
|
+
videoMime: '',
|
|
829
|
+
videoName: '',
|
|
830
|
+
recording: false,
|
|
831
|
+
recordSec: 0,
|
|
832
|
+
_recTimer: null,
|
|
833
|
+
_mediaRecorder: null,
|
|
834
|
+
_recStream: null,
|
|
835
|
+
minimized: {
|
|
836
|
+
$def: false,
|
|
837
|
+
$attr: true,
|
|
838
|
+
},
|
|
839
|
+
sending: false,
|
|
840
|
+
loading: false,
|
|
841
|
+
error: '',
|
|
842
|
+
tickets: [],
|
|
843
|
+
unreadTotal: 0,
|
|
844
|
+
selectedTicketId: '',
|
|
845
|
+
replyText: '',
|
|
846
|
+
_mediaCache: {},
|
|
847
|
+
_pollTimer: null,
|
|
848
|
+
get recordSecLabel() {
|
|
849
|
+
const s = Math.max(0, Number(this.recordSec) || 0);
|
|
850
|
+
return `00:${String(s).padStart(2, '0')}`;
|
|
851
|
+
},
|
|
852
|
+
get selectedTicket() {
|
|
853
|
+
return (this.tickets || []).find(t => t.ticketId === this.selectedTicketId) || this.tickets?.[0] || null;
|
|
854
|
+
},
|
|
855
|
+
attached() {
|
|
856
|
+
this.refreshTickets();
|
|
857
|
+
this._pollTimer = setInterval(() => {
|
|
858
|
+
if (this.activeTab === 'list')
|
|
859
|
+
this.refreshTickets();
|
|
860
|
+
}, 8000);
|
|
861
|
+
},
|
|
862
|
+
detached() {
|
|
863
|
+
if (this._pollTimer) clearInterval(this._pollTimer);
|
|
864
|
+
if (this._recTimer) clearInterval(this._recTimer);
|
|
865
|
+
try { this._recStream?.getTracks?.().forEach(t => t.stop()); } catch { /* ignore */ }
|
|
866
|
+
},
|
|
867
|
+
statusLabel(st) {
|
|
868
|
+
return { open: 'Открыт', in_progress: 'На контроле', answered: 'Отвечен', closed: 'Закрыт' }[st] || st || 'Открыт';
|
|
869
|
+
},
|
|
870
|
+
formatTime(ms) {
|
|
871
|
+
if (!ms) return '';
|
|
872
|
+
try { return new Date(ms).toLocaleString('ru-RU', { dateStyle: 'short', timeStyle: 'short' }); }
|
|
873
|
+
catch { return ''; }
|
|
874
|
+
},
|
|
875
|
+
closePanel() {
|
|
876
|
+
this.dispatchEvent(new CustomEvent('support-closed', { detail: { unreadTotal: this.unreadTotal }, bubbles: true, composed: true }));
|
|
877
|
+
this.remove();
|
|
878
|
+
},
|
|
879
|
+
async openListTab() {
|
|
880
|
+
this.activeTab = 'list';
|
|
881
|
+
await this.refreshTickets();
|
|
882
|
+
if (this.selectedTicket)
|
|
883
|
+
await this.selectTicket(this.selectedTicket.ticketId);
|
|
884
|
+
},
|
|
885
|
+
async refreshTickets() {
|
|
886
|
+
this.loading = true;
|
|
887
|
+
try {
|
|
888
|
+
const res = await WORK.fetch('/', 'support_list');
|
|
889
|
+
this.tickets = Array.isArray(res?.tickets) ? res.tickets : [];
|
|
890
|
+
this.unreadTotal = Number(res?.unreadTotal || 0);
|
|
891
|
+
if (!this.selectedTicketId && this.tickets.length)
|
|
892
|
+
this.selectedTicketId = this.tickets[0].ticketId;
|
|
893
|
+
// Предзагрузка медиафайлов выбранного тикета через локальный WORK
|
|
894
|
+
if (this.selectedTicket)
|
|
895
|
+
this._preloadTicketMedia(this.selectedTicket);
|
|
896
|
+
}
|
|
897
|
+
catch (err) {
|
|
898
|
+
this.error = String(err?.message || err);
|
|
899
|
+
}
|
|
900
|
+
finally {
|
|
901
|
+
this.loading = false;
|
|
902
|
+
}
|
|
903
|
+
},
|
|
904
|
+
async selectTicket(ticketId) {
|
|
905
|
+
this.selectedTicketId = ticketId;
|
|
906
|
+
const t = (this.tickets || []).find(x => x.ticketId === ticketId);
|
|
907
|
+
if (t && t.unreadCount > 0) {
|
|
908
|
+
await WORK.fetch('/', 'support_mark_read', {}, JSON.stringify({ ticketId })).catch(() => {});
|
|
909
|
+
t.unreadCount = 0;
|
|
910
|
+
this.tickets = [...this.tickets];
|
|
911
|
+
this.unreadTotal = this.tickets.reduce((s, x) => s + Number(x.unreadCount || 0), 0);
|
|
912
|
+
}
|
|
913
|
+
if (t)
|
|
914
|
+
this._preloadTicketMedia(t);
|
|
915
|
+
},
|
|
916
|
+
mediaUrl(att) {
|
|
917
|
+
if (!att?.id) return '';
|
|
918
|
+
return this._mediaCache?.[att.id] || '';
|
|
919
|
+
},
|
|
920
|
+
async _preloadTicketMedia(ticket) {
|
|
921
|
+
const atts = [];
|
|
922
|
+
for (const m of ticket?.messages || []) {
|
|
923
|
+
for (const a of m?.attachments || [])
|
|
924
|
+
atts.push(a);
|
|
925
|
+
}
|
|
926
|
+
for (const a of atts) {
|
|
927
|
+
if (!a?.id || this._mediaCache[a.id]) continue;
|
|
928
|
+
try {
|
|
929
|
+
const res = await WORK.fetch('/', 'support_media', { ticketId: ticket.ticketId, file: a.id });
|
|
930
|
+
if (res?.dataUrl) {
|
|
931
|
+
this._mediaCache = { ...this._mediaCache, [a.id]: res.dataUrl };
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
catch { /* ignore */ }
|
|
935
|
+
}
|
|
936
|
+
},
|
|
937
|
+
async captureScreenshot() {
|
|
938
|
+
this.error = '';
|
|
939
|
+
if (!navigator.mediaDevices?.getDisplayMedia) {
|
|
940
|
+
this.error = 'Захват экрана не поддерживается в этом браузере — прикрепите файл кнопкой «Прикрепить файл».';
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
this.minimized = true;
|
|
944
|
+
await new Promise(r => setTimeout(r, 220));
|
|
945
|
+
let stream = null;
|
|
946
|
+
try {
|
|
947
|
+
stream = await navigator.mediaDevices.getDisplayMedia({
|
|
948
|
+
video: { displaySurface: 'browser' },
|
|
949
|
+
preferCurrentTab: true,
|
|
950
|
+
audio: false,
|
|
951
|
+
});
|
|
952
|
+
const video = document.createElement('video');
|
|
953
|
+
video.muted = true;
|
|
954
|
+
video.srcObject = stream;
|
|
955
|
+
await video.play();
|
|
956
|
+
await new Promise(r => setTimeout(r, 120));
|
|
957
|
+
const canvas = document.createElement('canvas');
|
|
958
|
+
canvas.width = video.videoWidth || 1280;
|
|
959
|
+
canvas.height = video.videoHeight || 720;
|
|
960
|
+
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
961
|
+
this._rawShotCanvas = canvas;
|
|
962
|
+
this.hasScreenshot = true;
|
|
963
|
+
this.minimized = false;
|
|
964
|
+
await new Promise(r => setTimeout(r, 60));
|
|
965
|
+
this._renderRawShotToUi();
|
|
966
|
+
}
|
|
967
|
+
catch (err) {
|
|
968
|
+
this.minimized = false;
|
|
969
|
+
if (err?.name !== 'AbortError' && err?.name !== 'NotAllowedError')
|
|
970
|
+
this.error = 'Не удалось снять скриншот: ' + (err?.message || err);
|
|
971
|
+
}
|
|
972
|
+
finally {
|
|
973
|
+
try { stream?.getTracks?.().forEach(t => t.stop()); } catch { /* ignore */ }
|
|
974
|
+
}
|
|
975
|
+
},
|
|
976
|
+
_renderRawShotToUi() {
|
|
977
|
+
const uiCanvas = this.$('#shotCanvas');
|
|
978
|
+
const src = this._rawShotCanvas;
|
|
979
|
+
if (!uiCanvas || !src) return;
|
|
980
|
+
uiCanvas.width = src.width;
|
|
981
|
+
uiCanvas.height = src.height;
|
|
982
|
+
uiCanvas.getContext('2d').drawImage(src, 0, 0);
|
|
983
|
+
},
|
|
984
|
+
clearScreenshotMarkup() {
|
|
985
|
+
this._renderRawShotToUi();
|
|
986
|
+
},
|
|
987
|
+
removeScreenshot() {
|
|
988
|
+
this.hasScreenshot = false;
|
|
989
|
+
this._rawShotCanvas = null;
|
|
990
|
+
},
|
|
991
|
+
_canvasCoords(e) {
|
|
992
|
+
const c = this.$('#shotCanvas');
|
|
993
|
+
if (!c) return null;
|
|
994
|
+
const r = c.getBoundingClientRect();
|
|
995
|
+
return {
|
|
996
|
+
x: ((e.clientX - r.left) / r.width) * c.width,
|
|
997
|
+
y: ((e.clientY - r.top) / r.height) * c.height,
|
|
998
|
+
};
|
|
999
|
+
},
|
|
1000
|
+
onShotDrawStart(e) {
|
|
1001
|
+
this._drawing = true;
|
|
1002
|
+
this._lastPt = this._canvasCoords(e);
|
|
1003
|
+
},
|
|
1004
|
+
onShotDrawMove(e) {
|
|
1005
|
+
if (!this._drawing) return;
|
|
1006
|
+
const c = this.$('#shotCanvas');
|
|
1007
|
+
const pt = this._canvasCoords(e);
|
|
1008
|
+
if (!c || !pt || !this._lastPt) return;
|
|
1009
|
+
const ctx = c.getContext('2d');
|
|
1010
|
+
ctx.strokeStyle = '#ef4444';
|
|
1011
|
+
ctx.lineWidth = Math.max(3, Math.round(c.width / 320));
|
|
1012
|
+
ctx.lineCap = 'round';
|
|
1013
|
+
ctx.beginPath();
|
|
1014
|
+
ctx.moveTo(this._lastPt.x, this._lastPt.y);
|
|
1015
|
+
ctx.lineTo(pt.x, pt.y);
|
|
1016
|
+
ctx.stroke();
|
|
1017
|
+
this._lastPt = pt;
|
|
1018
|
+
},
|
|
1019
|
+
onShotDrawEnd() {
|
|
1020
|
+
this._drawing = false;
|
|
1021
|
+
this._lastPt = null;
|
|
1022
|
+
},
|
|
1023
|
+
async startVideoCapture() {
|
|
1024
|
+
this.error = '';
|
|
1025
|
+
if (!navigator.mediaDevices?.getDisplayMedia || typeof MediaRecorder === 'undefined') {
|
|
1026
|
+
this.error = 'Запись видео с экрана не поддерживается в этом браузере.';
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
this.minimized = true;
|
|
1030
|
+
try {
|
|
1031
|
+
const stream = await navigator.mediaDevices.getDisplayMedia({
|
|
1032
|
+
video: { frameRate: 15 },
|
|
1033
|
+
preferCurrentTab: true,
|
|
1034
|
+
audio: false,
|
|
1035
|
+
});
|
|
1036
|
+
this._recStream = stream;
|
|
1037
|
+
const chunks = [];
|
|
1038
|
+
const mime = MediaRecorder.isTypeSupported('video/webm;codecs=vp8')
|
|
1039
|
+
? 'video/webm;codecs=vp8'
|
|
1040
|
+
: 'video/webm';
|
|
1041
|
+
const mr = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 900_000 });
|
|
1042
|
+
this._mediaRecorder = mr;
|
|
1043
|
+
this.recording = true;
|
|
1044
|
+
this.recordSec = 0;
|
|
1045
|
+
|
|
1046
|
+
mr.ondataavailable = (e) => { if (e.data?.size) chunks.push(e.data); };
|
|
1047
|
+
mr.onstop = () => {
|
|
1048
|
+
this.recording = false;
|
|
1049
|
+
this.minimized = false;
|
|
1050
|
+
if (this._recTimer) { clearInterval(this._recTimer); this._recTimer = null; }
|
|
1051
|
+
try { stream.getTracks().forEach(t => t.stop()); } catch { /* ignore */ }
|
|
1052
|
+
this._recStream = null;
|
|
1053
|
+
if (chunks.length) {
|
|
1054
|
+
const blob = new Blob(chunks, { type: 'video/webm' });
|
|
1055
|
+
const reader = new FileReader();
|
|
1056
|
+
reader.onload = () => {
|
|
1057
|
+
this.videoDataUrl = String(reader.result || '');
|
|
1058
|
+
this.videoMime = 'video/webm';
|
|
1059
|
+
this.videoName = `screen-${this.recordSec || 1}s.webm`;
|
|
1060
|
+
};
|
|
1061
|
+
reader.readAsDataURL(blob);
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
stream.getVideoTracks()[0]?.addEventListener('ended', () => this.stopVideoCapture());
|
|
1065
|
+
mr.start(500);
|
|
1066
|
+
this._recTimer = setInterval(() => {
|
|
1067
|
+
this.recordSec++;
|
|
1068
|
+
if (this.recordSec >= MAX_VIDEO_SEC)
|
|
1069
|
+
this.stopVideoCapture();
|
|
1070
|
+
}, 1000);
|
|
1071
|
+
}
|
|
1072
|
+
catch (err) {
|
|
1073
|
+
this.recording = false;
|
|
1074
|
+
this.minimized = false;
|
|
1075
|
+
if (err?.name !== 'AbortError' && err?.name !== 'NotAllowedError')
|
|
1076
|
+
this.error = 'Не удалось начать запись: ' + (err?.message || err);
|
|
1077
|
+
}
|
|
1078
|
+
},
|
|
1079
|
+
stopVideoCapture() {
|
|
1080
|
+
try {
|
|
1081
|
+
if (this._mediaRecorder && this._mediaRecorder.state !== 'inactive')
|
|
1082
|
+
this._mediaRecorder.stop();
|
|
1083
|
+
}
|
|
1084
|
+
catch { /* ignore */ }
|
|
1085
|
+
},
|
|
1086
|
+
removeVideo() {
|
|
1087
|
+
this.videoDataUrl = '';
|
|
1088
|
+
this.videoMime = '';
|
|
1089
|
+
this.videoName = '';
|
|
1090
|
+
},
|
|
1091
|
+
onFilePicked(e) {
|
|
1092
|
+
const file = e?.target?.files?.[0];
|
|
1093
|
+
if (!file) return;
|
|
1094
|
+
const reader = new FileReader();
|
|
1095
|
+
reader.onload = () => {
|
|
1096
|
+
const url = String(reader.result || '');
|
|
1097
|
+
if (file.type.startsWith('video/')) {
|
|
1098
|
+
this.videoDataUrl = url;
|
|
1099
|
+
this.videoMime = file.type;
|
|
1100
|
+
this.videoName = file.name;
|
|
1101
|
+
}
|
|
1102
|
+
else if (file.type.startsWith('image/')) {
|
|
1103
|
+
const img = new Image();
|
|
1104
|
+
img.onload = async () => {
|
|
1105
|
+
const c = document.createElement('canvas');
|
|
1106
|
+
c.width = img.naturalWidth || 1280;
|
|
1107
|
+
c.height = img.naturalHeight || 720;
|
|
1108
|
+
c.getContext('2d').drawImage(img, 0, 0);
|
|
1109
|
+
this._rawShotCanvas = c;
|
|
1110
|
+
this.hasScreenshot = true;
|
|
1111
|
+
await new Promise(r => setTimeout(r, 50));
|
|
1112
|
+
this._renderRawShotToUi();
|
|
1113
|
+
};
|
|
1114
|
+
img.src = url;
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
reader.readAsDataURL(file);
|
|
1118
|
+
e.target.value = '';
|
|
1119
|
+
},
|
|
1120
|
+
_collectTechContext() {
|
|
1121
|
+
const host = globalThis.WORK || window;
|
|
1122
|
+
let focusedPath = '';
|
|
1123
|
+
try {
|
|
1124
|
+
const exp = document.querySelector('item-explorer') || window.top?.document?.querySelector('item-explorer');
|
|
1125
|
+
focusedPath = exp?.focusedPage || exp?.$item?.path || '';
|
|
1126
|
+
}
|
|
1127
|
+
catch { /* ignore */ }
|
|
1128
|
+
return {
|
|
1129
|
+
url: window.location.href,
|
|
1130
|
+
focusedPath,
|
|
1131
|
+
userAgent: navigator.userAgent,
|
|
1132
|
+
viewport: `${window.innerWidth}x${window.innerHeight}`,
|
|
1133
|
+
recentErrors: Array.isArray(host.__supportErrors) ? [...host.__supportErrors] : [],
|
|
1134
|
+
};
|
|
1135
|
+
},
|
|
1136
|
+
async submitTicket() {
|
|
1137
|
+
this.error = '';
|
|
1138
|
+
const text = String(this.problemText || '').trim();
|
|
1139
|
+
const attachments = [];
|
|
1140
|
+
const shotCanvas = this.$('#shotCanvas');
|
|
1141
|
+
if (this.hasScreenshot && shotCanvas) {
|
|
1142
|
+
attachments.push({
|
|
1143
|
+
name: 'screenshot.png',
|
|
1144
|
+
mime: 'image/png',
|
|
1145
|
+
dataBase64: shotCanvas.toDataURL('image/png'),
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
if (this.videoDataUrl) {
|
|
1149
|
+
attachments.push({
|
|
1150
|
+
name: this.videoName || 'recording.webm',
|
|
1151
|
+
mime: this.videoMime || 'video/webm',
|
|
1152
|
+
dataBase64: this.videoDataUrl,
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
if (!text && !attachments.length) {
|
|
1156
|
+
this.error = 'Опишите проблему или приложите скриншот / видео.';
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
this.sending = true;
|
|
1160
|
+
try {
|
|
1161
|
+
const res = await WORK.fetch('/', 'support_create', {}, JSON.stringify({
|
|
1162
|
+
text,
|
|
1163
|
+
includeTech: Boolean(this.includeTech),
|
|
1164
|
+
techContext: this.includeTech ? this._collectTechContext() : null,
|
|
1165
|
+
attachments,
|
|
1166
|
+
}));
|
|
1167
|
+
this.problemText = '';
|
|
1168
|
+
this.removeScreenshot();
|
|
1169
|
+
this.removeVideo();
|
|
1170
|
+
await this.refreshTickets();
|
|
1171
|
+
if (res?.ticket?.ticketId)
|
|
1172
|
+
this.selectedTicketId = res.ticket.ticketId;
|
|
1173
|
+
this.activeTab = 'list';
|
|
1174
|
+
}
|
|
1175
|
+
catch (err) {
|
|
1176
|
+
this.error = String(err?.message || err);
|
|
1177
|
+
}
|
|
1178
|
+
finally {
|
|
1179
|
+
this.sending = false;
|
|
1180
|
+
}
|
|
1181
|
+
},
|
|
1182
|
+
async sendReply() {
|
|
1183
|
+
const text = String(this.replyText || '').trim();
|
|
1184
|
+
if (!text || !this.selectedTicket) return;
|
|
1185
|
+
this.sending = true;
|
|
1186
|
+
this.error = '';
|
|
1187
|
+
try {
|
|
1188
|
+
await WORK.fetch('/', 'support_reply', {}, JSON.stringify({
|
|
1189
|
+
ticketId: this.selectedTicket.ticketId,
|
|
1190
|
+
text,
|
|
1191
|
+
}));
|
|
1192
|
+
this.replyText = '';
|
|
1193
|
+
await this.refreshTickets();
|
|
1194
|
+
}
|
|
1195
|
+
catch (err) {
|
|
1196
|
+
this.error = String(err?.message || err);
|
|
1197
|
+
}
|
|
1198
|
+
finally {
|
|
1199
|
+
this.sending = false;
|
|
1200
|
+
}
|
|
1201
|
+
},
|
|
1202
|
+
async rejectRemoteDesktop(ticketId) {
|
|
1203
|
+
try {
|
|
1204
|
+
await WORK.fetch('/', 'support_remote', {}, JSON.stringify({ ticketId, action: 'reject' }));
|
|
1205
|
+
await this.refreshTickets();
|
|
1206
|
+
}
|
|
1207
|
+
catch (err) {
|
|
1208
|
+
this.error = String(err?.message || err);
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1211
|
+
async startRemoteDesktop(ticketId, mode = 'view') {
|
|
1212
|
+
this.error = '';
|
|
1213
|
+
if (document.querySelector('work-support-remote-bar')) {
|
|
1214
|
+
this.error = 'Сессия удалённого экрана уже активна.';
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const t = (this.tickets || []).find(x => x.ticketId === ticketId);
|
|
1218
|
+
const bar = document.createElement('work-support-remote-bar');
|
|
1219
|
+
document.body.appendChild(bar);
|
|
1220
|
+
try {
|
|
1221
|
+
await bar.start(ticketId, {
|
|
1222
|
+
mode,
|
|
1223
|
+
engineerName: t?.remote?.requestedBy?.engineerName || t?.assignedSupportName || 'Поддержка',
|
|
1224
|
+
});
|
|
1225
|
+
this.closePanel();
|
|
1226
|
+
}
|
|
1227
|
+
catch (err) {
|
|
1228
|
+
bar.remove();
|
|
1229
|
+
this.error = String(err?.message || err);
|
|
1230
|
+
}
|
|
1231
|
+
},
|
|
1232
|
+
});
|