dsh-qq-affinity 0.0.0-stage → 0.14.2
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 +55 -2
- package/client.js +3550 -0
- package/cordis.patch.yml +6 -0
- package/docs/DETAIL.md +332 -0
- package/icon.svg +12 -0
- package/index.js +128 -0
- package/lib/analyze.js +777 -0
- package/lib/api.js +984 -0
- package/lib/backfill.js +146 -0
- package/lib/bridge-server.js +78 -0
- package/lib/care.js +240 -0
- package/lib/features.js +200 -0
- package/lib/home.js +168 -0
- package/lib/inbound.js +120 -0
- package/lib/llm.js +137 -0
- package/lib/media.js +161 -0
- package/lib/onebot.js +207 -0
- package/lib/parse.js +184 -0
- package/lib/recover.js +46 -0
- package/lib/store.js +705 -0
- package/lib/util.js +186 -0
- package/lib/vision.js +108 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +38 -4
- package/scripts/api-e2e.mjs +538 -0
- package/scripts/backfill-e2e.mjs +142 -0
- package/scripts/backfill-live.mjs +60 -0
- package/scripts/bridge-e2e.mjs +137 -0
- package/scripts/care-e2e.mjs +217 -0
- package/scripts/check-hook-order.mjs +83 -0
- package/scripts/make-napcat-config.mjs +87 -0
- package/scripts/media-e2e.mjs +103 -0
- package/scripts/recover-e2e.mjs +75 -0
- package/scripts/selftest.mjs +159 -0
- package/scripts/strip-bom.mjs +27 -0
package/client.js
ADDED
|
@@ -0,0 +1,3550 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QQ affinity profiles — browser half.
|
|
3
|
+
*
|
|
4
|
+
* Registers one global sidebar entry and the main panel it selects. The panel
|
|
5
|
+
* reads and writes everything through the Host API below `/api/qq-affinity`
|
|
6
|
+
* and keeps no state outside this tab's memory.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
window.__ModuleLoader__.load({
|
|
10
|
+
id: 'dsh-qq-affinity',
|
|
11
|
+
|
|
12
|
+
factory(require) {
|
|
13
|
+
const React = require('react')
|
|
14
|
+
const h = React.createElement
|
|
15
|
+
const { useCallback, useEffect, useRef, useState } = React
|
|
16
|
+
|
|
17
|
+
const API_BASE = 'api/qq-affinity'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This bundle's version. The Host reports its own; when the two differ the
|
|
21
|
+
* panel says so, because a stale bundle otherwise looks like a broken button.
|
|
22
|
+
*/
|
|
23
|
+
const VERSION = '0.14.2'
|
|
24
|
+
|
|
25
|
+
// ---------------------------------------------------------------- palette
|
|
26
|
+
|
|
27
|
+
const token = (name, fallback) => `var(${name}, ${fallback})`
|
|
28
|
+
|
|
29
|
+
const C = {
|
|
30
|
+
bg: token('--dsw-alias-bg-base', '#ffffff'),
|
|
31
|
+
layer1: token('--dsw-alias-bg-layer-1', '#f7f8fa'),
|
|
32
|
+
layer2: token('--dsw-alias-bg-layer-2', '#eef0f4'),
|
|
33
|
+
overlay: token('--dsw-alias-bg-overlay', '#ffffff'),
|
|
34
|
+
border1: token('--dsw-alias-border-l1', '#e3e6eb'),
|
|
35
|
+
border2: token('--dsw-alias-border-l2', '#cfd4dc'),
|
|
36
|
+
label: token('--dsw-alias-label-primary', '#1b1f24'),
|
|
37
|
+
label2: token('--dsw-alias-label-secondary', '#6b7280'),
|
|
38
|
+
brand: token('--dsw-alias-brand-primary', '#2f6fed'),
|
|
39
|
+
success: token('--dsw-alias-state-success-primary', '#18a058'),
|
|
40
|
+
warn: token('--dsw-alias-state-warn-primary', '#c98a00'),
|
|
41
|
+
error: token('--dsw-alias-state-error-primary', '#d03050'),
|
|
42
|
+
idle: token('--dsw-alias-state-idle-primary', '#9aa3af'),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// A low score is information, not a fault: red is reserved for very low.
|
|
46
|
+
// A score ramp with more bands than the shipped semantic colours provide:
|
|
47
|
+
// each step is a `color-mix` of two theme tokens, so it still follows the
|
|
48
|
+
// light/dark palette. Where the engine lacks color-mix, three plain bands
|
|
49
|
+
// remain instead of losing the colour entirely.
|
|
50
|
+
const supportsColorMix = typeof CSS !== 'undefined'
|
|
51
|
+
&& typeof CSS.supports === 'function'
|
|
52
|
+
&& CSS.supports('color', 'color-mix(in oklab, #fff, #000)')
|
|
53
|
+
|
|
54
|
+
const mix = (from, to, percent) => `color-mix(in oklab, ${from} ${percent}%, ${to} ${100 - percent}%)`
|
|
55
|
+
|
|
56
|
+
/** Score bands, richest first. */
|
|
57
|
+
const BANDS = [
|
|
58
|
+
[90, () => C.success],
|
|
59
|
+
[80, () => mix(C.success, C.brand, 72)],
|
|
60
|
+
[70, () => mix(C.success, C.warn, 62)],
|
|
61
|
+
[60, () => mix(C.warn, C.success, 76)],
|
|
62
|
+
[50, () => C.warn],
|
|
63
|
+
[40, () => mix(C.warn, C.error, 68)],
|
|
64
|
+
[25, () => mix(C.error, C.warn, 80)],
|
|
65
|
+
[0, () => C.error],
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
/** Colour for a 0-100 score. */
|
|
69
|
+
const tone = (value) => {
|
|
70
|
+
const n = Number(value)
|
|
71
|
+
if (!Number.isFinite(n)) return C.label2
|
|
72
|
+
if (!supportsColorMix) {
|
|
73
|
+
return n >= 70 ? C.success : n >= 40 ? C.warn : n >= 20 ? C.label2 : C.error
|
|
74
|
+
}
|
|
75
|
+
for (const [min, color] of BANDS) if (n >= min) return color()
|
|
76
|
+
return C.error
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A translucent wash of one accent colour, over whatever is behind it. */
|
|
80
|
+
const tint = (color, percent) => (supportsColorMix
|
|
81
|
+
? `color-mix(in oklab, ${color} ${percent}%, transparent)`
|
|
82
|
+
: C.layer1)
|
|
83
|
+
|
|
84
|
+
/** Distinct accent per list position, so neighbouring traits never match. */
|
|
85
|
+
const TRAIT_COLORS = [
|
|
86
|
+
() => C.brand,
|
|
87
|
+
() => mix(C.brand, C.success, 45),
|
|
88
|
+
() => C.success,
|
|
89
|
+
() => mix(C.success, C.warn, 50),
|
|
90
|
+
() => C.warn,
|
|
91
|
+
() => mix(C.warn, C.error, 55),
|
|
92
|
+
]
|
|
93
|
+
const traitColor = (index) => (supportsColorMix ? TRAIT_COLORS[index % TRAIT_COLORS.length]() : C.brand)
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The MBTI card that heads a personality sketch.
|
|
97
|
+
*
|
|
98
|
+
* Each axis is a two-pole bar filled towards the chosen side, so the shape
|
|
99
|
+
* of the type is readable without parsing the four letters.
|
|
100
|
+
* @param {{ type: string, nickname: string, confidence: number, caveat: string,
|
|
101
|
+
* axes: Array<{ axis: string, letter: string, strength: number, reason: string, labels: string[] }> }} mbti
|
|
102
|
+
*/
|
|
103
|
+
function mbtiCard(mbti) {
|
|
104
|
+
const accent = supportsColorMix ? mix(C.brand, C.success, 55) : C.brand
|
|
105
|
+
return h('div', {
|
|
106
|
+
key: 'mbti',
|
|
107
|
+
style: {
|
|
108
|
+
background: tint(accent, 12),
|
|
109
|
+
border: `1px solid ${supportsColorMix ? `color-mix(in oklab, ${accent} 40%, transparent)` : C.border1}`,
|
|
110
|
+
borderRadius: 12,
|
|
111
|
+
padding: '12px 14px',
|
|
112
|
+
display: 'flex',
|
|
113
|
+
flexDirection: 'column',
|
|
114
|
+
gap: 10,
|
|
115
|
+
},
|
|
116
|
+
}, [
|
|
117
|
+
h('div', { key: 'head', style: { display: 'flex', alignItems: 'baseline', gap: 8, flexWrap: 'wrap' } }, [
|
|
118
|
+
h('span', {
|
|
119
|
+
key: 'type',
|
|
120
|
+
style: { fontSize: 25, fontWeight: 700, letterSpacing: '3px', color: accent, lineHeight: 1.1 },
|
|
121
|
+
}, mbti.type),
|
|
122
|
+
mbti.nickname === '' ? null : h('span', {
|
|
123
|
+
key: 'nick',
|
|
124
|
+
style: { fontSize: 12.5, color: C.label },
|
|
125
|
+
}, mbti.nickname),
|
|
126
|
+
h('div', { key: 'sp', style: { flex: 1 } }),
|
|
127
|
+
h('span', {
|
|
128
|
+
key: 'conf',
|
|
129
|
+
style: { fontSize: 10.5, color: C.label2, whiteSpace: 'nowrap' },
|
|
130
|
+
}, `MBTI 置信 ${Math.round((mbti.confidence ?? 0) * 100)}%`),
|
|
131
|
+
]),
|
|
132
|
+
h('div', { key: 'axes', style: { display: 'flex', flexDirection: 'column', gap: 7 } }, mbti.axes.map((axis) => {
|
|
133
|
+
// `axis` is the pole pair in order, e.g. "EI": the first letter is left.
|
|
134
|
+
const chosenLeft = axis.letter === String(axis.axis)[0]
|
|
135
|
+
const fill = {
|
|
136
|
+
position: 'absolute',
|
|
137
|
+
top: 0,
|
|
138
|
+
bottom: 0,
|
|
139
|
+
width: `${Math.max(4, Math.min(100, axis.strength))}%`,
|
|
140
|
+
background: accent,
|
|
141
|
+
borderRadius: 999,
|
|
142
|
+
}
|
|
143
|
+
if (chosenLeft) fill.left = 0
|
|
144
|
+
else fill.right = 0
|
|
145
|
+
return h('div', {
|
|
146
|
+
key: axis.axis,
|
|
147
|
+
title: axis.reason === '' ? undefined : axis.reason,
|
|
148
|
+
style: { display: 'flex', alignItems: 'center', gap: 7 },
|
|
149
|
+
}, [
|
|
150
|
+
h('span', {
|
|
151
|
+
key: 'l',
|
|
152
|
+
style: {
|
|
153
|
+
width: 30,
|
|
154
|
+
fontSize: 10.5,
|
|
155
|
+
color: chosenLeft ? C.label : C.label2,
|
|
156
|
+
fontWeight: chosenLeft ? 600 : 400,
|
|
157
|
+
},
|
|
158
|
+
}, axis.labels[0]),
|
|
159
|
+
h('div', {
|
|
160
|
+
key: 'track',
|
|
161
|
+
style: {
|
|
162
|
+
position: 'relative',
|
|
163
|
+
flex: 1,
|
|
164
|
+
height: 5,
|
|
165
|
+
borderRadius: 999,
|
|
166
|
+
background: supportsColorMix ? `color-mix(in oklab, ${C.label2} 22%, transparent)` : C.border1,
|
|
167
|
+
overflow: 'hidden',
|
|
168
|
+
},
|
|
169
|
+
}, h('div', { style: fill })),
|
|
170
|
+
h('span', {
|
|
171
|
+
key: 'r',
|
|
172
|
+
style: {
|
|
173
|
+
width: 30,
|
|
174
|
+
textAlign: 'right',
|
|
175
|
+
fontSize: 10.5,
|
|
176
|
+
color: chosenLeft ? C.label2 : C.label,
|
|
177
|
+
fontWeight: chosenLeft ? 400 : 600,
|
|
178
|
+
},
|
|
179
|
+
}, axis.labels[1]),
|
|
180
|
+
h('span', {
|
|
181
|
+
key: 'v',
|
|
182
|
+
style: {
|
|
183
|
+
width: 52,
|
|
184
|
+
textAlign: 'right',
|
|
185
|
+
fontSize: 10.5,
|
|
186
|
+
color: accent,
|
|
187
|
+
fontVariantNumeric: 'tabular-nums',
|
|
188
|
+
},
|
|
189
|
+
}, `${axis.letter} ${axis.strength}%`),
|
|
190
|
+
])
|
|
191
|
+
})),
|
|
192
|
+
mbti.caveat === '' ? null : h('div', {
|
|
193
|
+
key: 'caveat',
|
|
194
|
+
style: { fontSize: 10.5, color: C.label2, lineHeight: 1.6 },
|
|
195
|
+
}, mbti.caveat),
|
|
196
|
+
])
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const inputStyle = {
|
|
200
|
+
width: '100%',
|
|
201
|
+
boxSizing: 'border-box',
|
|
202
|
+
border: `1px solid ${C.border2}`,
|
|
203
|
+
background: C.bg,
|
|
204
|
+
color: C.label,
|
|
205
|
+
borderRadius: 6,
|
|
206
|
+
padding: '7px 9px',
|
|
207
|
+
font: 'inherit',
|
|
208
|
+
fontSize: 12.5,
|
|
209
|
+
outline: 'none',
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ------------------------------------------------------------------- api
|
|
213
|
+
|
|
214
|
+
/** One request to the Host panel API, decoding the shared `{ ok, error }` envelope. */
|
|
215
|
+
async function api(path, options = {}) {
|
|
216
|
+
const url = new URL(`${API_BASE}/${path}`, document.baseURI)
|
|
217
|
+
const init = { method: options.method ?? 'GET', credentials: 'same-origin', headers: {} }
|
|
218
|
+
if (options.body !== undefined) {
|
|
219
|
+
init.headers['content-type'] = 'application/json'
|
|
220
|
+
init.body = JSON.stringify(options.body)
|
|
221
|
+
}
|
|
222
|
+
const transport = globalThis.__DSH_TRANSPORT__?.fetch
|
|
223
|
+
let response
|
|
224
|
+
try {
|
|
225
|
+
response = transport === undefined ? await fetch(url.href, init) : await transport(url.href, init)
|
|
226
|
+
} catch (error) {
|
|
227
|
+
throw new Error(`连不上插件后台:${error instanceof Error ? error.message : String(error)}`)
|
|
228
|
+
}
|
|
229
|
+
const text = await response.text()
|
|
230
|
+
let value
|
|
231
|
+
try {
|
|
232
|
+
value = JSON.parse(text)
|
|
233
|
+
} catch {
|
|
234
|
+
throw new Error(`插件后台返回了非 JSON 内容(HTTP ${response.status})。`)
|
|
235
|
+
}
|
|
236
|
+
if (value !== null && typeof value === 'object' && value.ok === false) {
|
|
237
|
+
// The payload carries machine-readable hints such as `needsSelfUin`.
|
|
238
|
+
const failure = new Error(value.error ?? '请求失败。')
|
|
239
|
+
failure.payload = value
|
|
240
|
+
throw failure
|
|
241
|
+
}
|
|
242
|
+
if (!response.ok) throw new Error(`请求失败(HTTP ${response.status})。`)
|
|
243
|
+
return value
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const fmtTime = (value) => {
|
|
247
|
+
if (value === undefined || value === null || value === '') return '—'
|
|
248
|
+
const d = new Date(value)
|
|
249
|
+
if (Number.isNaN(d.getTime())) return '—'
|
|
250
|
+
const p = (v) => String(v).padStart(2, '0')
|
|
251
|
+
return `${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// -------------------------------------------------------------- controls
|
|
255
|
+
|
|
256
|
+
/** A button with hover and focus feedback, themed by tone. */
|
|
257
|
+
function Btn(props) {
|
|
258
|
+
const { children, onClick, disabled = false, kind = 'quiet', title, ariaLabel, role, ariaChecked, ariaPressed, style } = props
|
|
259
|
+
const [active, setActive] = useState(false)
|
|
260
|
+
const tones = {
|
|
261
|
+
quiet: {
|
|
262
|
+
background: active && !disabled ? C.layer2 : 'transparent',
|
|
263
|
+
color: C.label,
|
|
264
|
+
borderColor: active && !disabled ? C.border2 : 'transparent',
|
|
265
|
+
},
|
|
266
|
+
outline: {
|
|
267
|
+
background: active && !disabled ? C.layer2 : 'transparent',
|
|
268
|
+
color: C.label,
|
|
269
|
+
borderColor: C.border2,
|
|
270
|
+
},
|
|
271
|
+
primary: {
|
|
272
|
+
background: disabled ? C.idle : (active ? C.brand : C.brand),
|
|
273
|
+
color: '#fff',
|
|
274
|
+
borderColor: disabled ? C.idle : C.brand,
|
|
275
|
+
filter: active && !disabled ? 'brightness(.94)' : 'none',
|
|
276
|
+
},
|
|
277
|
+
danger: {
|
|
278
|
+
background: 'transparent',
|
|
279
|
+
color: C.error,
|
|
280
|
+
borderColor: active && !disabled ? C.error : C.border1,
|
|
281
|
+
},
|
|
282
|
+
}
|
|
283
|
+
return h('button', {
|
|
284
|
+
type: 'button',
|
|
285
|
+
role,
|
|
286
|
+
'aria-checked': ariaChecked,
|
|
287
|
+
'aria-pressed': ariaPressed,
|
|
288
|
+
'aria-label': ariaLabel,
|
|
289
|
+
title,
|
|
290
|
+
disabled,
|
|
291
|
+
onClick,
|
|
292
|
+
onMouseEnter: () => setActive(true),
|
|
293
|
+
onMouseLeave: () => setActive(false),
|
|
294
|
+
onFocus: () => setActive(true),
|
|
295
|
+
onBlur: () => setActive(false),
|
|
296
|
+
style: {
|
|
297
|
+
appearance: 'none',
|
|
298
|
+
border: '1px solid transparent',
|
|
299
|
+
borderRadius: 6,
|
|
300
|
+
font: 'inherit',
|
|
301
|
+
fontSize: 12,
|
|
302
|
+
lineHeight: '18px',
|
|
303
|
+
padding: '4px 10px',
|
|
304
|
+
display: 'inline-flex',
|
|
305
|
+
alignItems: 'center',
|
|
306
|
+
gap: 4,
|
|
307
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
308
|
+
opacity: disabled ? 0.5 : 1,
|
|
309
|
+
userSelect: 'none',
|
|
310
|
+
transition: 'background-color 120ms ease, border-color 120ms ease, filter 120ms ease',
|
|
311
|
+
...tones[kind],
|
|
312
|
+
...style,
|
|
313
|
+
},
|
|
314
|
+
}, children)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** An on/off switch with the host's switch semantics. */
|
|
318
|
+
function Toggle({ checked, onChange, label, disabled = false }) {
|
|
319
|
+
return h('button', {
|
|
320
|
+
type: 'button',
|
|
321
|
+
role: 'switch',
|
|
322
|
+
'aria-checked': checked,
|
|
323
|
+
'aria-label': label,
|
|
324
|
+
disabled,
|
|
325
|
+
onClick: () => { if (!disabled) onChange(!checked) },
|
|
326
|
+
title: label,
|
|
327
|
+
style: {
|
|
328
|
+
appearance: 'none',
|
|
329
|
+
position: 'relative',
|
|
330
|
+
width: 34,
|
|
331
|
+
height: 20,
|
|
332
|
+
padding: 0,
|
|
333
|
+
borderRadius: 999,
|
|
334
|
+
border: `1px solid ${checked ? 'transparent' : C.border2}`,
|
|
335
|
+
background: checked ? C.brand : C.layer2,
|
|
336
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
337
|
+
transition: 'background-color 140ms ease',
|
|
338
|
+
flex: '0 0 auto',
|
|
339
|
+
opacity: disabled ? 0.5 : 1,
|
|
340
|
+
},
|
|
341
|
+
}, h('span', {
|
|
342
|
+
'aria-hidden': true,
|
|
343
|
+
style: {
|
|
344
|
+
position: 'absolute',
|
|
345
|
+
top: 2,
|
|
346
|
+
left: checked ? 16 : 2,
|
|
347
|
+
width: 14,
|
|
348
|
+
height: 14,
|
|
349
|
+
borderRadius: 999,
|
|
350
|
+
background: '#fff',
|
|
351
|
+
boxShadow: '0 1px 2px rgba(0,0,0,.18)',
|
|
352
|
+
transition: 'left 140ms cubic-bezier(.2,.8,.2,1)',
|
|
353
|
+
},
|
|
354
|
+
}))
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** A 0-100 meter with its number. */
|
|
358
|
+
function Meter({ label, value, ariaLabel }) {
|
|
359
|
+
const shown = typeof value === 'number' && Number.isFinite(value) ? Math.round(value) : undefined
|
|
360
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } }, [
|
|
361
|
+
h('div', { key: 'h', style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 8 } }, [
|
|
362
|
+
h('span', { key: 'l', style: { fontSize: 12, color: C.label2 } }, label),
|
|
363
|
+
h('span', {
|
|
364
|
+
key: 'v',
|
|
365
|
+
style: {
|
|
366
|
+
fontSize: shown === undefined ? 12 : 20,
|
|
367
|
+
fontWeight: 600,
|
|
368
|
+
color: shown === undefined ? C.label2 : tone(shown),
|
|
369
|
+
fontVariantNumeric: 'tabular-nums',
|
|
370
|
+
},
|
|
371
|
+
}, shown === undefined ? '未分析' : String(shown)),
|
|
372
|
+
]),
|
|
373
|
+
h('div', {
|
|
374
|
+
key: 't',
|
|
375
|
+
role: 'meter',
|
|
376
|
+
'aria-valuemin': 0,
|
|
377
|
+
'aria-valuemax': 100,
|
|
378
|
+
'aria-valuenow': shown ?? 0,
|
|
379
|
+
'aria-label': ariaLabel ?? label,
|
|
380
|
+
style: { height: 6, borderRadius: 999, background: C.layer2, overflow: 'hidden' },
|
|
381
|
+
}, h('div', {
|
|
382
|
+
style: {
|
|
383
|
+
width: `${shown ?? 0}%`,
|
|
384
|
+
height: '100%',
|
|
385
|
+
background: shown === undefined ? 'transparent' : tone(shown),
|
|
386
|
+
borderRadius: 999,
|
|
387
|
+
transition: 'width 260ms cubic-bezier(.2,.8,.2,1)',
|
|
388
|
+
},
|
|
389
|
+
})),
|
|
390
|
+
])
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** A short inline chip. */
|
|
394
|
+
function Chip({ children, color = C.label2, mono = false }) {
|
|
395
|
+
return h('span', {
|
|
396
|
+
style: {
|
|
397
|
+
display: 'inline-flex',
|
|
398
|
+
alignItems: 'center',
|
|
399
|
+
gap: 4,
|
|
400
|
+
padding: '1px 7px',
|
|
401
|
+
borderRadius: 999,
|
|
402
|
+
border: `1px solid ${C.border1}`,
|
|
403
|
+
color,
|
|
404
|
+
fontSize: 11,
|
|
405
|
+
lineHeight: '16px',
|
|
406
|
+
fontVariantNumeric: mono ? 'tabular-nums' : undefined,
|
|
407
|
+
whiteSpace: 'nowrap',
|
|
408
|
+
},
|
|
409
|
+
}, children)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** A titled panel section. */
|
|
413
|
+
function Section({ title, extra, children }) {
|
|
414
|
+
return h('section', {
|
|
415
|
+
style: {
|
|
416
|
+
background: C.layer1,
|
|
417
|
+
border: `1px solid ${C.border1}`,
|
|
418
|
+
borderRadius: 10,
|
|
419
|
+
padding: 14,
|
|
420
|
+
display: 'flex',
|
|
421
|
+
flexDirection: 'column',
|
|
422
|
+
gap: 10,
|
|
423
|
+
minWidth: 0,
|
|
424
|
+
},
|
|
425
|
+
}, [
|
|
426
|
+
h('div', {
|
|
427
|
+
key: 'head',
|
|
428
|
+
style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, minHeight: 20 },
|
|
429
|
+
}, [
|
|
430
|
+
h('h3', { key: 't', style: { margin: 0, fontSize: 13, fontWeight: 600, color: C.label } }, title),
|
|
431
|
+
extra === undefined || extra === null ? null : h('div', { key: 'e', style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap' } }, extra),
|
|
432
|
+
]),
|
|
433
|
+
children,
|
|
434
|
+
])
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** A modal surface. Children own their own form state. */
|
|
438
|
+
function Dialog({ title, onClose, footer, children }) {
|
|
439
|
+
const box = useRef(null)
|
|
440
|
+
const close = useRef(onClose)
|
|
441
|
+
close.current = onClose
|
|
442
|
+
useEffect(() => {
|
|
443
|
+
const previous = document.activeElement
|
|
444
|
+
const node = box.current
|
|
445
|
+
// A form's own autoFocus already landed on its field during commit; only
|
|
446
|
+
// take focus when the active element is still outside this dialog.
|
|
447
|
+
if (node !== null && !node.contains(document.activeElement)) {
|
|
448
|
+
const first = node.querySelector('input, textarea, select, button')
|
|
449
|
+
if (first !== null) first.focus()
|
|
450
|
+
else node.focus()
|
|
451
|
+
}
|
|
452
|
+
const onKey = (event) => { if (event.key === 'Escape') close.current() }
|
|
453
|
+
window.addEventListener('keydown', onKey)
|
|
454
|
+
return () => {
|
|
455
|
+
window.removeEventListener('keydown', onKey)
|
|
456
|
+
if (previous instanceof HTMLElement && previous.isConnected) previous.focus()
|
|
457
|
+
}
|
|
458
|
+
}, [])
|
|
459
|
+
return h('div', {
|
|
460
|
+
role: 'presentation',
|
|
461
|
+
onMouseDown: (event) => { if (event.target === event.currentTarget) close.current() },
|
|
462
|
+
style: {
|
|
463
|
+
position: 'fixed',
|
|
464
|
+
inset: 0,
|
|
465
|
+
background: 'rgba(0,0,0,.34)',
|
|
466
|
+
display: 'flex',
|
|
467
|
+
alignItems: 'center',
|
|
468
|
+
justifyContent: 'center',
|
|
469
|
+
padding: 24,
|
|
470
|
+
zIndex: 30,
|
|
471
|
+
},
|
|
472
|
+
}, h('div', {
|
|
473
|
+
ref: box,
|
|
474
|
+
role: 'dialog',
|
|
475
|
+
'aria-modal': 'true',
|
|
476
|
+
'aria-label': title,
|
|
477
|
+
tabIndex: -1,
|
|
478
|
+
style: {
|
|
479
|
+
background: C.overlay,
|
|
480
|
+
color: C.label,
|
|
481
|
+
border: `1px solid ${C.border2}`,
|
|
482
|
+
borderRadius: 12,
|
|
483
|
+
boxShadow: '0 18px 48px rgba(0,0,0,.24)',
|
|
484
|
+
width: 'min(660px, 100%)',
|
|
485
|
+
maxHeight: 'min(680px, 90vh)',
|
|
486
|
+
display: 'flex',
|
|
487
|
+
flexDirection: 'column',
|
|
488
|
+
overflow: 'hidden',
|
|
489
|
+
outline: 'none',
|
|
490
|
+
},
|
|
491
|
+
}, [
|
|
492
|
+
h('div', {
|
|
493
|
+
key: 'h',
|
|
494
|
+
style: { padding: '14px 16px', borderBottom: `1px solid ${C.border1}`, fontSize: 14, fontWeight: 600, flex: '0 0 auto' },
|
|
495
|
+
}, title),
|
|
496
|
+
h('div', {
|
|
497
|
+
key: 'b',
|
|
498
|
+
style: { padding: 16, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 10, fontSize: 12.5, lineHeight: 1.7 },
|
|
499
|
+
}, children),
|
|
500
|
+
h('div', {
|
|
501
|
+
key: 'f',
|
|
502
|
+
style: { padding: '12px 16px', borderTop: `1px solid ${C.border1}`, display: 'flex', gap: 8, justifyContent: 'flex-end', flex: '0 0 auto' },
|
|
503
|
+
}, footer),
|
|
504
|
+
]))
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** A labelled field. */
|
|
508
|
+
function Field({ label, hint, children }) {
|
|
509
|
+
return h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } }, [
|
|
510
|
+
h('span', { key: 'l', style: { color: C.label2, fontSize: 11.5 } }, label),
|
|
511
|
+
children,
|
|
512
|
+
hint === undefined ? null : h('span', { key: 'h', style: { color: C.label2, fontSize: 11 } }, hint),
|
|
513
|
+
])
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// ---------------------------------------------------------------- dialogs
|
|
517
|
+
|
|
518
|
+
function SettingsForm({ settings, channel, vision, dataLocation, autoCount, busy, onClose, onSave, onTest, onMove, onBackfill }) {
|
|
519
|
+
const [uin, setUin] = useState(settings.selfUin)
|
|
520
|
+
const [careEnabled, setCareEnabled] = useState(settings.careEnabled === true)
|
|
521
|
+
const [apiBase, setApiBase] = useState(settings.onebot.apiBase)
|
|
522
|
+
const [accessToken, setAccessToken] = useState(settings.onebot.accessToken)
|
|
523
|
+
const [inboundToken, setInboundToken] = useState(settings.onebot.inboundToken)
|
|
524
|
+
const [autoBackfill, setAutoBackfill] = useState(settings.onebot.autoBackfill !== false)
|
|
525
|
+
const [imagesOn, setImagesOn] = useState(settings.visionImages !== false)
|
|
526
|
+
const [test, setTest] = useState(null)
|
|
527
|
+
const [testing, setTesting] = useState(false)
|
|
528
|
+
const [target, setTarget] = useState('')
|
|
529
|
+
const [cleanup, setCleanup] = useState(false)
|
|
530
|
+
const [moveResult, setMoveResult] = useState(null)
|
|
531
|
+
const [moving, setMoving] = useState(false)
|
|
532
|
+
// The archive location is a prop, so the browser global is spelled out.
|
|
533
|
+
const fixedUrl = channel?.bridgeUrl ?? ''
|
|
534
|
+
const fixedReady = channel?.bridgeListening === true
|
|
535
|
+
const fallbackUrl = `${window.location.origin}${channel?.inboundPath ?? '/qq-affinity/onebot'}`
|
|
536
|
+
const locked = dataLocation?.envLocked === true
|
|
537
|
+
|
|
538
|
+
const runMove = async (action, mode) => {
|
|
539
|
+
if (mode === 'migrate' && cleanup) {
|
|
540
|
+
const confirmed = window.confirm('迁移完成后会删除原位置里的档案文件(meta、聊天记录、发件箱)。确定?')
|
|
541
|
+
if (!confirmed) return
|
|
542
|
+
}
|
|
543
|
+
setMoving(true)
|
|
544
|
+
setMoveResult(null)
|
|
545
|
+
try {
|
|
546
|
+
const result = await onMove(action === 'default'
|
|
547
|
+
? { action: 'default' }
|
|
548
|
+
: { action: 'move', target, mode, cleanup })
|
|
549
|
+
setMoveResult({
|
|
550
|
+
ok: true,
|
|
551
|
+
note: result.outcome.mode === 'migrate'
|
|
552
|
+
? `已迁移 ${result.outcome.copied} 项到新位置。${result.note}`
|
|
553
|
+
: `已切换到新位置。${result.outcome.mode === 'switch' ? '原位置的数据没有搬动。' : ''}`,
|
|
554
|
+
})
|
|
555
|
+
if (action !== 'default') setTarget('')
|
|
556
|
+
} catch (failure) {
|
|
557
|
+
setMoveResult({ ok: false, note: failure.message })
|
|
558
|
+
} finally {
|
|
559
|
+
setMoving(false)
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const runTest = async () => {
|
|
564
|
+
setTesting(true)
|
|
565
|
+
setTest(null)
|
|
566
|
+
try {
|
|
567
|
+
const result = await onTest({ apiBase, accessToken })
|
|
568
|
+
setTest({
|
|
569
|
+
ok: true,
|
|
570
|
+
text: `已连上,登录身份是 ${result.login.nickname || '(无昵称)'}(${result.login.uin || '未知号码'})。这套地址和 token 已保存,通道已启用。`,
|
|
571
|
+
})
|
|
572
|
+
} catch (failure) {
|
|
573
|
+
setTest({ ok: false, text: failure.message })
|
|
574
|
+
} finally {
|
|
575
|
+
setTesting(false)
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const toggleCare = (next) => {
|
|
580
|
+
if (next && autoCount > 0) {
|
|
581
|
+
const confirmed = window.confirm(
|
|
582
|
+
`打开总开关后,${autoCount} 个设成「自动发送」的人会立刻开始以你的身份直接回复。确定?`,
|
|
583
|
+
)
|
|
584
|
+
if (!confirmed) return
|
|
585
|
+
}
|
|
586
|
+
setCareEnabled(next)
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return h(Dialog, {
|
|
590
|
+
title: '设置',
|
|
591
|
+
onClose,
|
|
592
|
+
footer: [
|
|
593
|
+
h(Btn, { key: 'c', kind: 'quiet', onClick: onClose }, '取消'),
|
|
594
|
+
h(Btn, {
|
|
595
|
+
key: 's',
|
|
596
|
+
kind: 'primary',
|
|
597
|
+
disabled: busy || testing,
|
|
598
|
+
onClick: () => onSave({ selfUin: uin, careEnabled, visionImages: imagesOn, onebot: { apiBase, accessToken, inboundToken, autoBackfill } }),
|
|
599
|
+
}, '保存'),
|
|
600
|
+
],
|
|
601
|
+
}, [
|
|
602
|
+
h('div', {
|
|
603
|
+
key: 'who',
|
|
604
|
+
style: { display: 'flex', flexDirection: 'column', gap: 8 },
|
|
605
|
+
}, [
|
|
606
|
+
h('div', { key: 'h', style: { fontSize: 12, fontWeight: 600, color: C.label } }, '身份'),
|
|
607
|
+
h(Field, {
|
|
608
|
+
key: 'u',
|
|
609
|
+
label: '我的 QQ 号',
|
|
610
|
+
hint: '聊天记录里你自己的 QQ 号。填了它,你发出去的消息才会算作「我」。',
|
|
611
|
+
}, h('input', {
|
|
612
|
+
value: uin,
|
|
613
|
+
inputMode: 'numeric',
|
|
614
|
+
autoFocus: true,
|
|
615
|
+
placeholder: '例如 123456789',
|
|
616
|
+
onChange: (event) => setUin(event.target.value.replace(/\D/g, '').slice(0, 12)),
|
|
617
|
+
style: inputStyle,
|
|
618
|
+
})),
|
|
619
|
+
]),
|
|
620
|
+
|
|
621
|
+
h('div', {
|
|
622
|
+
key: 'vision',
|
|
623
|
+
style: { display: 'flex', flexDirection: 'column', gap: 6 },
|
|
624
|
+
}, [
|
|
625
|
+
h('div', { key: 'h', style: { fontSize: 12, fontWeight: 600, color: C.label } }, '图片与表情包'),
|
|
626
|
+
h('div', { key: 'row', style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } }, [
|
|
627
|
+
h(Toggle, {
|
|
628
|
+
key: 'sw',
|
|
629
|
+
checked: imagesOn,
|
|
630
|
+
disabled: busy,
|
|
631
|
+
label: '允许把图片/表情包发给模型',
|
|
632
|
+
onChange: setImagesOn,
|
|
633
|
+
}),
|
|
634
|
+
h('span', { key: 'n', style: { fontSize: 11, color: C.label2, lineHeight: 1.6 } },
|
|
635
|
+
'开启后,分析会挑最近的几张图交给模型看(图片会离开本机)。'),
|
|
636
|
+
]),
|
|
637
|
+
vision === null ? null : h('div', {
|
|
638
|
+
key: 'status',
|
|
639
|
+
style: {
|
|
640
|
+
fontSize: 11,
|
|
641
|
+
lineHeight: 1.7,
|
|
642
|
+
color: vision.ready === true ? C.success : C.warn,
|
|
643
|
+
},
|
|
644
|
+
}, vision.ready === true
|
|
645
|
+
? `当前模型 ${vision.provider} / ${vision.model} 支持读图,可以用。`
|
|
646
|
+
: !vision.allowed
|
|
647
|
+
? '已关闭:不会下载任何图片,只保留「[图片]」「[表情包」标记。'
|
|
648
|
+
: vision.attachmentService !== true
|
|
649
|
+
? '这个环境没有附件服务,无法把图片交给模型。'
|
|
650
|
+
: `当前模型 ${vision.provider} / ${vision.model} 不接受图片输入,只能读到「[图片]」这样的文字标记。换成支持视觉的模型后再试。`),
|
|
651
|
+
]),
|
|
652
|
+
|
|
653
|
+
h('div', {
|
|
654
|
+
key: 'loc',
|
|
655
|
+
style: { display: 'flex', flexDirection: 'column', gap: 8 },
|
|
656
|
+
}, [
|
|
657
|
+
h('div', { key: 'h', style: { fontSize: 12, fontWeight: 600, color: C.label } }, '数据位置'),
|
|
658
|
+
h('div', {
|
|
659
|
+
key: 'cur',
|
|
660
|
+
style: {
|
|
661
|
+
display: 'flex',
|
|
662
|
+
alignItems: 'center',
|
|
663
|
+
gap: 6,
|
|
664
|
+
border: `1px solid ${C.border1}`,
|
|
665
|
+
borderRadius: 6,
|
|
666
|
+
padding: '5px 8px',
|
|
667
|
+
background: C.layer1,
|
|
668
|
+
},
|
|
669
|
+
}, [
|
|
670
|
+
h('code', {
|
|
671
|
+
key: 'v',
|
|
672
|
+
style: { flex: 1, fontSize: 11.5, wordBreak: 'break-all', fontFamily: 'ui-monospace, Consolas, monospace' },
|
|
673
|
+
}, dataLocation?.directory ?? ''),
|
|
674
|
+
dataLocation?.custom === true
|
|
675
|
+
? h(Chip, { key: 'c', color: C.brand }, '自定义')
|
|
676
|
+
: h(Chip, { key: 'c' }, '默认'),
|
|
677
|
+
]),
|
|
678
|
+
h('div', {
|
|
679
|
+
key: 'p',
|
|
680
|
+
style: { fontSize: 11, color: C.label2, lineHeight: 1.7 },
|
|
681
|
+
}, '改变之后立刻生效:档案、聊天记录、发件箱都从新位置读写,不需要重启 DSH。'),
|
|
682
|
+
locked ? h('div', {
|
|
683
|
+
key: 'locked',
|
|
684
|
+
style: {
|
|
685
|
+
fontSize: 11.5,
|
|
686
|
+
color: C.warn,
|
|
687
|
+
border: `1px solid ${C.warn}`,
|
|
688
|
+
borderRadius: 8,
|
|
689
|
+
padding: '8px 10px',
|
|
690
|
+
lineHeight: 1.7,
|
|
691
|
+
},
|
|
692
|
+
}, `数据位置被环境变量 DSH_QQ_AFFINITY_HOME 固定为 ${dataLocation.envValue},面板改不了。想在这里改,先去掉那个变量。`) : null,
|
|
693
|
+
locked ? null : h('div', {
|
|
694
|
+
key: 'form',
|
|
695
|
+
style: { display: 'flex', flexDirection: 'column', gap: 8 },
|
|
696
|
+
}, [
|
|
697
|
+
h(Field, {
|
|
698
|
+
key: 't',
|
|
699
|
+
label: '新位置(绝对路径)',
|
|
700
|
+
hint: '例如 D:\\QQ档案 或 ~/qq-affinity。目录不存在会自动创建。',
|
|
701
|
+
}, h('input', {
|
|
702
|
+
value: target,
|
|
703
|
+
placeholder: 'D:\\QQ档案',
|
|
704
|
+
onChange: (event) => { setTarget(event.target.value.slice(0, 400)); setMoveResult(null) },
|
|
705
|
+
style: inputStyle,
|
|
706
|
+
})),
|
|
707
|
+
h('div', { key: 'cl', style: { display: 'flex', alignItems: 'center', gap: 8 } }, [
|
|
708
|
+
h(Toggle, {
|
|
709
|
+
key: 'sw',
|
|
710
|
+
checked: cleanup,
|
|
711
|
+
disabled: moving,
|
|
712
|
+
label: '迁移后删除原位置的数据',
|
|
713
|
+
onChange: setCleanup,
|
|
714
|
+
}),
|
|
715
|
+
h('span', { key: 'l', style: { fontSize: 11.5, color: C.label2, lineHeight: 1.6 } },
|
|
716
|
+
'迁移后删除原位置的数据(默认不删,方便你确认后再手动清理)'),
|
|
717
|
+
]),
|
|
718
|
+
h('div', { key: 'btn', style: { display: 'flex', gap: 8, flexWrap: 'wrap' } }, [
|
|
719
|
+
h(Btn, {
|
|
720
|
+
key: 'mv',
|
|
721
|
+
kind: 'primary',
|
|
722
|
+
disabled: moving || busy || target.trim() === '',
|
|
723
|
+
onClick: () => void runMove('move', 'migrate'),
|
|
724
|
+
}, moving ? '处理中…' : '迁移到这个位置'),
|
|
725
|
+
h(Btn, {
|
|
726
|
+
key: 'sw',
|
|
727
|
+
kind: 'outline',
|
|
728
|
+
disabled: moving || busy || target.trim() === '',
|
|
729
|
+
onClick: () => void runMove('move', 'switch'),
|
|
730
|
+
}, '切过去(不搬数据)'),
|
|
731
|
+
dataLocation?.custom === true ? h(Btn, {
|
|
732
|
+
key: 'd',
|
|
733
|
+
kind: 'quiet',
|
|
734
|
+
disabled: moving || busy,
|
|
735
|
+
onClick: () => void runMove('default'),
|
|
736
|
+
}, '恢复默认位置') : null,
|
|
737
|
+
]),
|
|
738
|
+
]),
|
|
739
|
+
moveResult === null ? null : h('div', {
|
|
740
|
+
key: 'res',
|
|
741
|
+
style: {
|
|
742
|
+
fontSize: 12,
|
|
743
|
+
lineHeight: 1.7,
|
|
744
|
+
color: moveResult.ok ? C.success : C.error,
|
|
745
|
+
background: C.layer1,
|
|
746
|
+
border: `1px solid ${moveResult.ok ? C.success : C.error}`,
|
|
747
|
+
borderRadius: 8,
|
|
748
|
+
padding: '8px 10px',
|
|
749
|
+
},
|
|
750
|
+
}, moveResult.note),
|
|
751
|
+
]),
|
|
752
|
+
|
|
753
|
+
h('div', {
|
|
754
|
+
key: 'care',
|
|
755
|
+
style: {
|
|
756
|
+
display: 'flex',
|
|
757
|
+
alignItems: 'flex-start',
|
|
758
|
+
gap: 10,
|
|
759
|
+
border: `1px solid ${careEnabled ? C.brand : C.border1}`,
|
|
760
|
+
borderRadius: 8,
|
|
761
|
+
padding: 10,
|
|
762
|
+
background: C.layer1,
|
|
763
|
+
},
|
|
764
|
+
}, [
|
|
765
|
+
h('div', { key: 't', style: { flex: 1, display: 'flex', flexDirection: 'column', gap: 2 } }, [
|
|
766
|
+
h('span', { key: 'a', style: { fontSize: 12, fontWeight: 600 } }, '智能托管总开关'),
|
|
767
|
+
h('span', { key: 'b', style: { fontSize: 11, color: C.label2, lineHeight: 1.6 } },
|
|
768
|
+
careEnabled
|
|
769
|
+
? `正在生效。关掉并保存后,${autoCount > 0 ? `${autoCount} 个自动发送的人` : '所有开了托管的人'}会立刻停止自动回复。`
|
|
770
|
+
: '现在是关的。打开了托管的人不会自动回复,单人设置都还在。'),
|
|
771
|
+
]),
|
|
772
|
+
h(Toggle, {
|
|
773
|
+
key: 's',
|
|
774
|
+
checked: careEnabled,
|
|
775
|
+
label: careEnabled ? '关闭智能托管' : '开启智能托管',
|
|
776
|
+
onChange: toggleCare,
|
|
777
|
+
}),
|
|
778
|
+
]),
|
|
779
|
+
|
|
780
|
+
h('div', { key: 'rt', style: { display: 'flex', flexDirection: 'column', gap: 8, marginTop: 4 } }, [
|
|
781
|
+
h('div', { key: 'h', style: { fontSize: 12, fontWeight: 600, color: C.label } }, '实时通道'),
|
|
782
|
+
h('div', { key: 'p', style: { fontSize: 11, color: C.label2, lineHeight: 1.7 } },
|
|
783
|
+
'自动回复必须能收到消息、也能把话发出去。这一步需要一个 OneBot v11 实现(NapCat / LLOneBot)挂在你自己登录的 QQ 上;插件只连它的本地 HTTP 接口,不碰 QQ 本身。'),
|
|
784
|
+
h(Field, { key: 'base', label: 'HTTP API 地址' }, h('input', {
|
|
785
|
+
value: apiBase,
|
|
786
|
+
placeholder: 'http://127.0.0.1:3001',
|
|
787
|
+
onChange: (event) => setApiBase(event.target.value.slice(0, 200)),
|
|
788
|
+
style: inputStyle,
|
|
789
|
+
})),
|
|
790
|
+
h(Field, {
|
|
791
|
+
key: 'access',
|
|
792
|
+
label: 'API access token(通道那边设置的)',
|
|
793
|
+
hint: '留空表示通道没有开 token。',
|
|
794
|
+
}, h('input', {
|
|
795
|
+
value: accessToken,
|
|
796
|
+
type: 'password',
|
|
797
|
+
autoComplete: 'off',
|
|
798
|
+
placeholder: '可留空',
|
|
799
|
+
onChange: (event) => setAccessToken(event.target.value.slice(0, 200)),
|
|
800
|
+
style: inputStyle,
|
|
801
|
+
})),
|
|
802
|
+
h(Field, {
|
|
803
|
+
key: 'inbound',
|
|
804
|
+
label: '上报口令(插件自己校验用的)',
|
|
805
|
+
hint: '留空则只接受本机 127.0.0.1 的请求。填了之后,通道上报时必须带上它,否则会被 401 拒掉。',
|
|
806
|
+
}, h('input', {
|
|
807
|
+
value: inboundToken,
|
|
808
|
+
type: 'password',
|
|
809
|
+
autoComplete: 'off',
|
|
810
|
+
placeholder: '建议填一串随机字符',
|
|
811
|
+
onChange: (event) => setInboundToken(event.target.value.slice(0, 200)),
|
|
812
|
+
style: inputStyle,
|
|
813
|
+
})),
|
|
814
|
+
h('div', {
|
|
815
|
+
key: 'cb',
|
|
816
|
+
style: { display: 'flex', flexDirection: 'column', gap: 6 },
|
|
817
|
+
}, [
|
|
818
|
+
h('div', { key: 'l', style: { fontSize: 11.5, color: C.label2 } },
|
|
819
|
+
'把这个地址填到通道的「HTTP 上报 / 反向 HTTP」里:'),
|
|
820
|
+
h('div', {
|
|
821
|
+
key: 'fixed',
|
|
822
|
+
style: {
|
|
823
|
+
display: 'flex',
|
|
824
|
+
gap: 6,
|
|
825
|
+
alignItems: 'center',
|
|
826
|
+
border: `1px solid ${fixedReady ? C.brand : C.warn}`,
|
|
827
|
+
borderRadius: 6,
|
|
828
|
+
padding: '5px 8px',
|
|
829
|
+
background: C.layer1,
|
|
830
|
+
},
|
|
831
|
+
}, [
|
|
832
|
+
h('code', {
|
|
833
|
+
key: 'v',
|
|
834
|
+
style: { flex: 1, fontSize: 11.5, wordBreak: 'break-all', fontFamily: 'ui-monospace, Consolas, monospace' },
|
|
835
|
+
}, fixedReady ? fixedUrl : `127.0.0.1:${channel?.bridgePort ?? 17890}/qq-affinity/onebot`),
|
|
836
|
+
fixedReady
|
|
837
|
+
? h(Chip, { key: 's', color: C.brand }, '固定地址 · 已监听')
|
|
838
|
+
: h(Chip, { key: 's', color: C.warn }, '端口没起来'),
|
|
839
|
+
h(Btn, {
|
|
840
|
+
key: 'copy',
|
|
841
|
+
kind: 'quiet',
|
|
842
|
+
disabled: !fixedReady,
|
|
843
|
+
onClick: async () => {
|
|
844
|
+
try {
|
|
845
|
+
await navigator.clipboard.writeText(fixedUrl)
|
|
846
|
+
} catch {
|
|
847
|
+
// Clipboard may be unavailable; the address is on screen either way.
|
|
848
|
+
}
|
|
849
|
+
},
|
|
850
|
+
}, '复制'),
|
|
851
|
+
]),
|
|
852
|
+
fixedReady
|
|
853
|
+
? h('div', { key: 'ok', style: { fontSize: 11, color: C.label2, lineHeight: 1.7 } },
|
|
854
|
+
'这个端口是插件自己固定监听的,DSH 重启也不会变 —— 填一次就行。')
|
|
855
|
+
: h('div', { key: 'bad', style: { fontSize: 11, color: C.warn, lineHeight: 1.7 } },
|
|
856
|
+
`固定端口 ${channel?.bridgePort ?? 17890} 没起来(${channel?.bridgeError ?? '未知原因'})。可能是另一个 DSH 实例占了它。临时改用下面的备用地址,或者关掉那个实例。`),
|
|
857
|
+
h('div', { key: 'altrow', style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap' } }, [
|
|
858
|
+
h('span', { key: 'l', style: { fontSize: 11, color: C.label2 } }, '备用(走 DSH 自己的端口,重启会变):'),
|
|
859
|
+
h('code', {
|
|
860
|
+
key: 'v',
|
|
861
|
+
style: { fontSize: 11, color: C.label2, wordBreak: 'break-all', fontFamily: 'ui-monospace, Consolas, monospace' },
|
|
862
|
+
}, fallbackUrl),
|
|
863
|
+
h(Btn, {
|
|
864
|
+
key: 'copy',
|
|
865
|
+
kind: 'quiet',
|
|
866
|
+
onClick: async () => {
|
|
867
|
+
try {
|
|
868
|
+
await navigator.clipboard.writeText(fallbackUrl)
|
|
869
|
+
} catch {
|
|
870
|
+
// Clipboard may be unavailable; the address is on screen either way.
|
|
871
|
+
}
|
|
872
|
+
},
|
|
873
|
+
}, '复制'),
|
|
874
|
+
]),
|
|
875
|
+
]),
|
|
876
|
+
inboundToken === '' ? null : h('div', {
|
|
877
|
+
key: 'how',
|
|
878
|
+
style: { fontSize: 11, color: C.label2, lineHeight: 1.7 },
|
|
879
|
+
}, `带上口令的两种写法:在通道的请求头里加 Authorization: Bearer ${inboundToken.slice(0, 4)}…;或者直接把地址写成 <上面的地址>?access_token=<你的口令>。`),
|
|
880
|
+
h('div', { key: 'actions', style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } }, [
|
|
881
|
+
h(Btn, {
|
|
882
|
+
key: 'test',
|
|
883
|
+
kind: 'outline',
|
|
884
|
+
disabled: testing,
|
|
885
|
+
onClick: () => void runTest(),
|
|
886
|
+
}, testing ? '正在连接…' : '用上面这套配置测试连接'),
|
|
887
|
+
h('span', { key: 'n', style: { fontSize: 11, color: C.label2 } },
|
|
888
|
+
'测试用的是输入框里的值,成功后会自动保存并启用通道。'),
|
|
889
|
+
]),
|
|
890
|
+
test === null ? null : h('div', {
|
|
891
|
+
key: 'res',
|
|
892
|
+
style: {
|
|
893
|
+
fontSize: 12,
|
|
894
|
+
lineHeight: 1.7,
|
|
895
|
+
color: test.ok ? C.success : C.error,
|
|
896
|
+
background: C.layer1,
|
|
897
|
+
border: `1px solid ${test.ok ? C.success : C.error}`,
|
|
898
|
+
borderRadius: 8,
|
|
899
|
+
padding: '8px 10px',
|
|
900
|
+
},
|
|
901
|
+
}, test.text),
|
|
902
|
+
h('div', {
|
|
903
|
+
key: 'last',
|
|
904
|
+
style: {
|
|
905
|
+
fontSize: 11,
|
|
906
|
+
lineHeight: 1.7,
|
|
907
|
+
color: channel?.lastInboundAt ? C.success : C.label2,
|
|
908
|
+
},
|
|
909
|
+
}, channel?.lastInboundAt
|
|
910
|
+
? `最近一次收到上报:${new Date(channel.lastInboundAt).toLocaleString('zh-CN')}`
|
|
911
|
+
: '还没收到过上报。填完上面的地址后,让人给你发一条消息,这里出现时间就说明双向通了。'),
|
|
912
|
+
h('div', {
|
|
913
|
+
key: 'backfill',
|
|
914
|
+
style: {
|
|
915
|
+
display: 'flex',
|
|
916
|
+
flexDirection: 'column',
|
|
917
|
+
gap: 8,
|
|
918
|
+
borderTop: `1px solid ${C.border1}`,
|
|
919
|
+
paddingTop: 10,
|
|
920
|
+
marginTop: 2,
|
|
921
|
+
},
|
|
922
|
+
}, [
|
|
923
|
+
h('div', { key: 'h', style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } }, [
|
|
924
|
+
h(Toggle, {
|
|
925
|
+
key: 'sw',
|
|
926
|
+
checked: autoBackfill,
|
|
927
|
+
disabled: busy,
|
|
928
|
+
label: '接通后自动补齐历史',
|
|
929
|
+
onChange: setAutoBackfill,
|
|
930
|
+
}),
|
|
931
|
+
h('span', { key: 'l', style: { fontSize: 11.5, color: C.label2, lineHeight: 1.6 } },
|
|
932
|
+
'接通后自动补齐历史(每个已开启的对话拉一次)'),
|
|
933
|
+
]),
|
|
934
|
+
h('div', { key: 'row', style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } }, [
|
|
935
|
+
h(Btn, {
|
|
936
|
+
key: 'run',
|
|
937
|
+
kind: 'outline',
|
|
938
|
+
disabled: busy || channel?.enabled !== true,
|
|
939
|
+
title: channel?.enabled === true ? '把桥里已经载入的消息同步进所有已开启的对话' : '先测试连接,通道启用后才能同步',
|
|
940
|
+
onClick: () => void onBackfill(),
|
|
941
|
+
}, busy === 'backfill:' ? '正在同步…' : '同步桥里已载入的消息'),
|
|
942
|
+
h('span', { key: 'n', style: { fontSize: 11, color: C.label2, lineHeight: 1.6 } },
|
|
943
|
+
channel?.lastBackfillAt
|
|
944
|
+
? `上次同步:${new Date(channel.lastBackfillAt).toLocaleString('zh-CN')}`
|
|
945
|
+
: '还没同步过。'),
|
|
946
|
+
]),
|
|
947
|
+
h('div', {
|
|
948
|
+
key: 'hint',
|
|
949
|
+
style: { fontSize: 11, color: C.label2, lineHeight: 1.7 },
|
|
950
|
+
}, [
|
|
951
|
+
h('div', { key: 'a' }, '只读「桥里已经载入的消息」(群聊和私聊都算)——桥不会向 QQ 服务器要历史,所以没在桥里出现过的旧消息是拿不到的。'),
|
|
952
|
+
h('div', { key: 'b' }, '插件启动时也会自动同步一次,把 DSH 重启期间桥里攒下的消息补进来(开关开着且距上次同步超过 5 分钟时)。'),
|
|
953
|
+
]),
|
|
954
|
+
]),
|
|
955
|
+
]),
|
|
956
|
+
])
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/** Rename one conversation from the right-click menu. */
|
|
960
|
+
function RenameDialog({ initial, busy, onClose, onSave }) {
|
|
961
|
+
const [value, setValue] = useState(initial)
|
|
962
|
+
return h(Dialog, {
|
|
963
|
+
title: '修改备注',
|
|
964
|
+
onClose,
|
|
965
|
+
footer: [
|
|
966
|
+
h(Btn, { key: 'c', kind: 'quiet', onClick: onClose }, '取消'),
|
|
967
|
+
h(Btn, {
|
|
968
|
+
key: 's',
|
|
969
|
+
kind: 'primary',
|
|
970
|
+
disabled: busy || value.trim() === '',
|
|
971
|
+
onClick: () => onSave(value.trim()),
|
|
972
|
+
}, busy ? '保存中…' : '保存'),
|
|
973
|
+
],
|
|
974
|
+
}, h(Field, { label: '备注(对方在你这里的名字)' }, h('input', {
|
|
975
|
+
value,
|
|
976
|
+
autoFocus: true,
|
|
977
|
+
placeholder: '例如 r老师',
|
|
978
|
+
onChange: (event) => setValue(event.target.value.slice(0, 120)),
|
|
979
|
+
onKeyDown: (event) => {
|
|
980
|
+
if (event.key === 'Enter' && value.trim() !== '') onSave(value.trim())
|
|
981
|
+
},
|
|
982
|
+
style: inputStyle,
|
|
983
|
+
})))
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
function CreatorForm({ initialKind, busy, onClose, onAdd }) {
|
|
987
|
+
const [kind, setKind] = useState(initialKind ?? 'c2c')
|
|
988
|
+
const [title, setTitle] = useState('')
|
|
989
|
+
const [peerUin, setPeerUin] = useState('')
|
|
990
|
+
const [groupUin, setGroupUin] = useState('')
|
|
991
|
+
return h(Dialog, {
|
|
992
|
+
title: '添加对话',
|
|
993
|
+
onClose,
|
|
994
|
+
footer: [
|
|
995
|
+
h(Btn, { key: 'c', kind: 'quiet', onClick: onClose }, '取消'),
|
|
996
|
+
h(Btn, {
|
|
997
|
+
key: 's',
|
|
998
|
+
kind: 'primary',
|
|
999
|
+
disabled: busy,
|
|
1000
|
+
onClick: () => onAdd({ kind, title, peerUin, groupUin }),
|
|
1001
|
+
}, '添加'),
|
|
1002
|
+
],
|
|
1003
|
+
}, [
|
|
1004
|
+
h('div', { key: 'p', style: { color: C.label2 } },
|
|
1005
|
+
'添加后这个对话默认是关闭的:只有你打开开关,插件才会读取和保存它的记录。'),
|
|
1006
|
+
h('div', { key: 'k', role: 'group', 'aria-label': '对话类型', style: { display: 'flex', gap: 8 } }, [
|
|
1007
|
+
h(Btn, { key: 'c', kind: kind === 'c2c' ? 'primary' : 'outline', ariaPressed: kind === 'c2c', onClick: () => setKind('c2c') }, '私聊'),
|
|
1008
|
+
h(Btn, { key: 'g', kind: kind === 'group' ? 'primary' : 'outline', ariaPressed: kind === 'group', onClick: () => setKind('group') }, '群聊'),
|
|
1009
|
+
]),
|
|
1010
|
+
h(Field, { key: 't', label: kind === 'group' ? '群名称' : '对方昵称' }, h('input', {
|
|
1011
|
+
value: title,
|
|
1012
|
+
autoFocus: true,
|
|
1013
|
+
placeholder: kind === 'group' ? '例如 老同学群' : '例如 小明',
|
|
1014
|
+
onChange: (event) => setTitle(event.target.value.slice(0, 120)),
|
|
1015
|
+
style: inputStyle,
|
|
1016
|
+
})),
|
|
1017
|
+
kind === 'group'
|
|
1018
|
+
? h(Field, {
|
|
1019
|
+
key: 'g',
|
|
1020
|
+
label: '群号',
|
|
1021
|
+
hint: '可留空;填了才能和同名群区分开,也方便以后接实时通道。',
|
|
1022
|
+
}, h('input', {
|
|
1023
|
+
value: groupUin,
|
|
1024
|
+
inputMode: 'numeric',
|
|
1025
|
+
placeholder: '例如 123456789',
|
|
1026
|
+
onChange: (event) => setGroupUin(event.target.value.replace(/\D/g, '').slice(0, 12)),
|
|
1027
|
+
style: inputStyle,
|
|
1028
|
+
}))
|
|
1029
|
+
: h(Field, {
|
|
1030
|
+
key: 'p',
|
|
1031
|
+
label: '对方 QQ 号',
|
|
1032
|
+
hint: '可以留空:导入记录后会自动识别。同一个人在不同群里会共用同一份档案。',
|
|
1033
|
+
}, h('input', {
|
|
1034
|
+
value: peerUin,
|
|
1035
|
+
inputMode: 'numeric',
|
|
1036
|
+
placeholder: '例如 10001',
|
|
1037
|
+
onChange: (event) => setPeerUin(event.target.value.replace(/\D/g, '').slice(0, 12)),
|
|
1038
|
+
style: inputStyle,
|
|
1039
|
+
})),
|
|
1040
|
+
])
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
function ImportForm({ conversation, busy, onClose, onSubmit, onNeedSelf }) {
|
|
1044
|
+
const [text, setText] = useState('')
|
|
1045
|
+
const [fileName, setFileName] = useState('')
|
|
1046
|
+
const [result, setResult] = useState(null)
|
|
1047
|
+
const fileRef = useRef(null)
|
|
1048
|
+
const title = conversation === undefined ? '导入聊天记录' : `导入到「${conversation.title || '未命名对话'}」`
|
|
1049
|
+
|
|
1050
|
+
const dirty = text.trim() !== ''
|
|
1051
|
+
const requestClose = () => {
|
|
1052
|
+
if (busy) return
|
|
1053
|
+
if (dirty && !window.confirm('已经粘贴或选择的记录不会保存,确定关闭吗?')) return
|
|
1054
|
+
onClose()
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
const readFile = async (file) => {
|
|
1058
|
+
if (file === undefined) return
|
|
1059
|
+
try {
|
|
1060
|
+
setText(await file.text())
|
|
1061
|
+
setFileName(file.name)
|
|
1062
|
+
setResult(null)
|
|
1063
|
+
} catch (error) {
|
|
1064
|
+
setResult({ error: `读取文件失败:${error instanceof Error ? error.message : String(error)}` })
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
return h(Dialog, {
|
|
1069
|
+
title,
|
|
1070
|
+
onClose: requestClose,
|
|
1071
|
+
footer: [
|
|
1072
|
+
h(Btn, { key: 'c', kind: 'quiet', onClick: requestClose }, '关闭'),
|
|
1073
|
+
h(Btn, {
|
|
1074
|
+
key: 's',
|
|
1075
|
+
kind: 'primary',
|
|
1076
|
+
disabled: busy || !dirty,
|
|
1077
|
+
onClick: async () => {
|
|
1078
|
+
const payload = await onSubmit(text)
|
|
1079
|
+
if (payload !== undefined) setResult(payload)
|
|
1080
|
+
},
|
|
1081
|
+
}, busy ? '导入中…' : '导入'),
|
|
1082
|
+
],
|
|
1083
|
+
}, [
|
|
1084
|
+
h('div', { key: 'p', style: { color: C.label2, lineHeight: 1.8 } }, [
|
|
1085
|
+
'在 QQ 的消息管理器里选中这个对话 → 导出消息记录 → 选择 ',
|
|
1086
|
+
h('b', { key: 'b' }, '文本 (.txt)'),
|
|
1087
|
+
' 格式,然后把文件拖进来或直接粘贴。HTML / MHT 导出暂时不支持。',
|
|
1088
|
+
]),
|
|
1089
|
+
h('div', { key: 'row', style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } }, [
|
|
1090
|
+
h('input', {
|
|
1091
|
+
key: 'file',
|
|
1092
|
+
ref: fileRef,
|
|
1093
|
+
type: 'file',
|
|
1094
|
+
accept: '.txt,.json,text/plain,application/json',
|
|
1095
|
+
style: { display: 'none' },
|
|
1096
|
+
onChange: (event) => { void readFile(event.target.files?.[0]) },
|
|
1097
|
+
}),
|
|
1098
|
+
h(Btn, { key: 'pick', kind: 'outline', onClick: () => fileRef.current?.click() }, '选择 .txt / .json'),
|
|
1099
|
+
fileName === '' ? null : h(Chip, { key: 'n' }, fileName),
|
|
1100
|
+
h('div', { key: 'sp', style: { flex: 1 } }),
|
|
1101
|
+
h('span', { key: 'c', style: { fontSize: 11, color: C.label2, fontVariantNumeric: 'tabular-nums' } }, `${text.length} 字符`),
|
|
1102
|
+
]),
|
|
1103
|
+
h('textarea', {
|
|
1104
|
+
key: 'text',
|
|
1105
|
+
value: text,
|
|
1106
|
+
onChange: (event) => { setText(event.target.value); setResult(null) },
|
|
1107
|
+
placeholder: '把导出的聊天记录粘贴到这里。\n\n支持的格式:\n2023-07-01 21:03:10 小明(10001)\n在吗\n\n也支持单行写法:\n2023-07-01 21:03:10 小明(10001): 在吗',
|
|
1108
|
+
spellCheck: false,
|
|
1109
|
+
style: { ...inputStyle, minHeight: 170, resize: 'vertical', fontFamily: 'ui-monospace, Consolas, monospace', fontSize: 12, lineHeight: 1.6 },
|
|
1110
|
+
}),
|
|
1111
|
+
result === null ? null : h('div', {
|
|
1112
|
+
key: 'res',
|
|
1113
|
+
style: {
|
|
1114
|
+
background: C.layer1,
|
|
1115
|
+
border: `1px solid ${result.error === undefined ? C.border1 : C.error}`,
|
|
1116
|
+
borderRadius: 8,
|
|
1117
|
+
padding: 10,
|
|
1118
|
+
fontSize: 12,
|
|
1119
|
+
lineHeight: 1.8,
|
|
1120
|
+
color: result.error === undefined ? C.label2 : C.error,
|
|
1121
|
+
display: 'flex',
|
|
1122
|
+
flexDirection: 'column',
|
|
1123
|
+
gap: 8,
|
|
1124
|
+
alignItems: 'flex-start',
|
|
1125
|
+
},
|
|
1126
|
+
}, result.error === undefined
|
|
1127
|
+
? [
|
|
1128
|
+
`识别 ${result.parsed} 条,新增 ${result.added} 条,重复 ${result.duplicates} 条。`,
|
|
1129
|
+
result.adoptedMatched > 0 ? ` 其中 ${result.adoptedMatched} 条为此前采用的 AI 建议。` : '',
|
|
1130
|
+
` 现在共 ${result.totalMessages} 条。`,
|
|
1131
|
+
].join('')
|
|
1132
|
+
: [
|
|
1133
|
+
h('span', { key: 'msg' }, result.error),
|
|
1134
|
+
result.stats === undefined ? null : h('span', {
|
|
1135
|
+
key: 'stats',
|
|
1136
|
+
style: { color: C.label2 },
|
|
1137
|
+
}, `这份文本里有 ${result.stats.candidates} 行看起来像消息头,识别成功 ${result.stats.parsed} 条。`),
|
|
1138
|
+
result.needsSelfUin ? h(Btn, {
|
|
1139
|
+
key: 'go',
|
|
1140
|
+
kind: 'primary',
|
|
1141
|
+
onClick: () => { onNeedSelf() },
|
|
1142
|
+
}, '去填写我的 QQ 号') : null,
|
|
1143
|
+
result.needsSelfUin ? null : h('span', {
|
|
1144
|
+
key: 'tip',
|
|
1145
|
+
style: { color: C.label2 },
|
|
1146
|
+
}, '如果导出的是 HTML / MHT,请改用「导出消息记录 → 文本」。'),
|
|
1147
|
+
]),
|
|
1148
|
+
])
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// ------------------------------------------------------------- care view
|
|
1152
|
+
|
|
1153
|
+
const OUTBOX_LABEL = {
|
|
1154
|
+
draft: '待确认',
|
|
1155
|
+
sending: '发送中',
|
|
1156
|
+
sent: '已发送',
|
|
1157
|
+
skipped: '未回复',
|
|
1158
|
+
failed: '发送失败',
|
|
1159
|
+
cancelled: '已取消',
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
const OUTBOX_COLOR = (status) => (status === 'sent'
|
|
1163
|
+
? C.success
|
|
1164
|
+
: status === 'failed' ? C.error
|
|
1165
|
+
: status === 'draft' ? C.brand
|
|
1166
|
+
: status === 'sending' ? C.warn : C.label2)
|
|
1167
|
+
|
|
1168
|
+
/** The record of every automatic reply attempt, with the pending ones actionable. */
|
|
1169
|
+
function OutboxList({ rows, busy, onApprove, onCancel, limit = 8, nameOf }) {
|
|
1170
|
+
if (rows.length === 0) {
|
|
1171
|
+
return h('div', { style: { fontSize: 12, color: C.label2, lineHeight: 1.8 } },
|
|
1172
|
+
'还没有触发过自动回复。开了托管之后,每次尝试都会被记在这里 —— 发出去的、等你确认的、被护栏拦下的,拦下的会写明原因。')
|
|
1173
|
+
}
|
|
1174
|
+
// Drafts never fall off the end of the list, and they come first: a pending
|
|
1175
|
+
// reply the user never sees is the same as a reply that never happened.
|
|
1176
|
+
const pending = rows.filter(row => row.status === 'draft').slice().reverse()
|
|
1177
|
+
const settled = rows.filter(row => row.status !== 'draft').slice(-limit).reverse()
|
|
1178
|
+
const ordered = [...pending, ...settled]
|
|
1179
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } }, [
|
|
1180
|
+
pending.length === 0 ? null : h('div', {
|
|
1181
|
+
key: 'pending',
|
|
1182
|
+
style: { fontSize: 11.5, color: C.brand, lineHeight: 1.6 },
|
|
1183
|
+
}, `${pending.length} 条写好了等你确认 —— 点「发送」才会真的发出去。`),
|
|
1184
|
+
...ordered.map(row => h('div', {
|
|
1185
|
+
key: row.id,
|
|
1186
|
+
style: {
|
|
1187
|
+
border: `1px solid ${row.status === 'draft' ? C.brand : C.border1}`,
|
|
1188
|
+
borderRadius: 8,
|
|
1189
|
+
padding: '8px 10px',
|
|
1190
|
+
background: C.bg,
|
|
1191
|
+
display: 'flex',
|
|
1192
|
+
flexDirection: 'column',
|
|
1193
|
+
gap: 5,
|
|
1194
|
+
},
|
|
1195
|
+
}, [
|
|
1196
|
+
h('div', { key: 'top', style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } }, [
|
|
1197
|
+
h(Chip, { key: 's', color: OUTBOX_COLOR(row.status) }, OUTBOX_LABEL[row.status] ?? row.status),
|
|
1198
|
+
h('span', { key: 't', style: { fontSize: 10.5, color: C.label2, fontVariantNumeric: 'tabular-nums' } }, fmtTime(row.createdAt)),
|
|
1199
|
+
nameOf === undefined ? null : h('span', {
|
|
1200
|
+
key: 'to',
|
|
1201
|
+
style: { fontSize: 10.5, color: C.label2 },
|
|
1202
|
+
}, `→ ${nameOf(row)}`),
|
|
1203
|
+
h('div', { key: 'sp', style: { flex: 1 } }),
|
|
1204
|
+
row.status === 'draft' ? h(Btn, {
|
|
1205
|
+
key: 'ok',
|
|
1206
|
+
kind: 'primary',
|
|
1207
|
+
disabled: busy,
|
|
1208
|
+
onClick: () => onApprove(row.id),
|
|
1209
|
+
}, '发送') : null,
|
|
1210
|
+
row.status === 'draft' ? h(Btn, {
|
|
1211
|
+
key: 'no',
|
|
1212
|
+
kind: 'quiet',
|
|
1213
|
+
disabled: busy,
|
|
1214
|
+
onClick: () => onCancel(row.id),
|
|
1215
|
+
}, '丢弃') : null,
|
|
1216
|
+
]),
|
|
1217
|
+
row.inboundText === '' ? null : h('div', {
|
|
1218
|
+
key: 'in',
|
|
1219
|
+
style: { fontSize: 11.5, color: C.label2, lineHeight: 1.65, wordBreak: 'break-word' },
|
|
1220
|
+
}, `对方:${row.inboundText}`),
|
|
1221
|
+
row.text === '' ? null : h('div', {
|
|
1222
|
+
key: 'out',
|
|
1223
|
+
style: {
|
|
1224
|
+
fontSize: 12.5,
|
|
1225
|
+
lineHeight: 1.7,
|
|
1226
|
+
wordBreak: 'break-word',
|
|
1227
|
+
whiteSpace: 'pre-wrap',
|
|
1228
|
+
color: row.status === 'skipped' || row.status === 'cancelled' ? C.label2 : C.label,
|
|
1229
|
+
},
|
|
1230
|
+
}, row.text),
|
|
1231
|
+
row.reason === '' ? null : h('div', {
|
|
1232
|
+
key: 'why',
|
|
1233
|
+
style: { fontSize: 11, color: row.status === 'failed' ? C.error : C.warn, lineHeight: 1.6 },
|
|
1234
|
+
}, row.reason),
|
|
1235
|
+
])),
|
|
1236
|
+
])
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
/** Per-person automatic reply settings. */
|
|
1240
|
+
function CarePanel({ person, channel, careEnabled, busy, usage, onChange }) {
|
|
1241
|
+
const care = person.care
|
|
1242
|
+
const [cap, setCap] = useState(String(care.hourlyCap))
|
|
1243
|
+
const [chars, setChars] = useState(String(care.maxReplyChars))
|
|
1244
|
+
const [quietFrom, setQuietFrom] = useState(care.quietFrom)
|
|
1245
|
+
const [quietTo, setQuietTo] = useState(care.quietTo)
|
|
1246
|
+
const [clockError, setClockError] = useState('')
|
|
1247
|
+
|
|
1248
|
+
const channelReady = channel !== undefined && channel.available === true && channel.enabled === true
|
|
1249
|
+
const commitNumber = (field, value, min, max, reset) => {
|
|
1250
|
+
const parsed = Number(value)
|
|
1251
|
+
if (!Number.isFinite(parsed)) { reset(); return }
|
|
1252
|
+
onChange({ [field]: Math.round(Math.min(max, Math.max(min, parsed))) })
|
|
1253
|
+
}
|
|
1254
|
+
const commitClock = (field, value, reset) => {
|
|
1255
|
+
const text = value.trim()
|
|
1256
|
+
// An empty value is the documented way to switch the quiet window off.
|
|
1257
|
+
if (text === '') {
|
|
1258
|
+
setClockError('')
|
|
1259
|
+
onChange({ [field]: '' })
|
|
1260
|
+
return
|
|
1261
|
+
}
|
|
1262
|
+
if (!/^\d{1,2}:\d{2}$/.test(text)) {
|
|
1263
|
+
setClockError('时段要写成 23:30 这种 HH:mm;两边都留空表示不启用免打扰。')
|
|
1264
|
+
reset()
|
|
1265
|
+
return
|
|
1266
|
+
}
|
|
1267
|
+
setClockError('')
|
|
1268
|
+
onChange({ [field]: text })
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } }, [
|
|
1272
|
+
!channelReady ? h('div', {
|
|
1273
|
+
key: 'warn',
|
|
1274
|
+
style: {
|
|
1275
|
+
fontSize: 11.5,
|
|
1276
|
+
lineHeight: 1.7,
|
|
1277
|
+
color: C.warn,
|
|
1278
|
+
border: `1px solid ${C.warn}`,
|
|
1279
|
+
borderRadius: 8,
|
|
1280
|
+
padding: '8px 10px',
|
|
1281
|
+
},
|
|
1282
|
+
}, '实时通道还没接通,托管现在只能记录、不能收发。到「设置」里填上 NapCat / LLOneBot 的地址并点一次测试连接。') : null,
|
|
1283
|
+
|
|
1284
|
+
h('div', { key: 'head', style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } }, [
|
|
1285
|
+
h('div', { key: 'l', style: { flex: 1, minWidth: 180, display: 'flex', flexDirection: 'column', gap: 2 } }, [
|
|
1286
|
+
h('span', { key: 'a', style: { fontSize: 12.5, fontWeight: 600 } }, '对这个人开启智能托管'),
|
|
1287
|
+
h('span', { key: 'b', style: { fontSize: 11, color: C.label2, lineHeight: 1.6 } },
|
|
1288
|
+
care.mode === 'auto'
|
|
1289
|
+
? '开着:TA 发来消息时,插件会直接替你回一句。'
|
|
1290
|
+
: '开着:TA 发来消息时,插件会写好一句等你确认,不会自己发出去。'),
|
|
1291
|
+
]),
|
|
1292
|
+
h(Toggle, {
|
|
1293
|
+
key: 'sw',
|
|
1294
|
+
checked: care.enabled === true,
|
|
1295
|
+
disabled: busy,
|
|
1296
|
+
label: care.enabled ? '关闭这个人的托管' : '对这个人生开启智能托管',
|
|
1297
|
+
onChange: (next) => onChange({ enabled: next }),
|
|
1298
|
+
}),
|
|
1299
|
+
]),
|
|
1300
|
+
|
|
1301
|
+
!careEnabled ? h('div', {
|
|
1302
|
+
key: 'global-off',
|
|
1303
|
+
style: { fontSize: 11, color: C.label2, lineHeight: 1.6 },
|
|
1304
|
+
}, '注意:托管总开关现在是关的,这里打开也不会生效。到「设置」里打开总开关。') : null,
|
|
1305
|
+
|
|
1306
|
+
h('div', { key: 'mode', style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } }, [
|
|
1307
|
+
h('span', { key: 'l', style: { fontSize: 11.5, color: C.label2 } }, '方式'),
|
|
1308
|
+
h(Btn, {
|
|
1309
|
+
key: 'd',
|
|
1310
|
+
kind: care.mode === 'draft' ? 'primary' : 'outline',
|
|
1311
|
+
ariaPressed: care.mode === 'draft',
|
|
1312
|
+
disabled: busy,
|
|
1313
|
+
onClick: () => onChange({ mode: 'draft' }),
|
|
1314
|
+
}, '先给我确认'),
|
|
1315
|
+
h(Btn, {
|
|
1316
|
+
key: 'a',
|
|
1317
|
+
kind: care.mode === 'auto' ? 'primary' : 'outline',
|
|
1318
|
+
ariaPressed: care.mode === 'auto',
|
|
1319
|
+
disabled: busy,
|
|
1320
|
+
onClick: () => {
|
|
1321
|
+
if (!window.confirm('选「自动发送」之后,TA 一发消息插件就会直接替你回,中间没有确认步骤。确定吗?')) return
|
|
1322
|
+
onChange({ mode: 'auto' })
|
|
1323
|
+
},
|
|
1324
|
+
}, '自动发送'),
|
|
1325
|
+
]),
|
|
1326
|
+
|
|
1327
|
+
h('div', { key: 'limits', style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(120px, 1fr))', gap: 8 } }, [
|
|
1328
|
+
h(Field, { key: 'cap', label: '每小时最多几条' }, h('input', {
|
|
1329
|
+
value: cap,
|
|
1330
|
+
inputMode: 'numeric',
|
|
1331
|
+
onChange: (event) => setCap(event.target.value.replace(/\D/g, '').slice(0, 2)),
|
|
1332
|
+
onBlur: () => commitNumber('hourlyCap', cap, 1, 60, () => setCap(String(care.hourlyCap))),
|
|
1333
|
+
style: inputStyle,
|
|
1334
|
+
})),
|
|
1335
|
+
h(Field, { key: 'len', label: '回复字数上限' }, h('input', {
|
|
1336
|
+
value: chars,
|
|
1337
|
+
inputMode: 'numeric',
|
|
1338
|
+
onChange: (event) => setChars(event.target.value.replace(/\D/g, '').slice(0, 3)),
|
|
1339
|
+
onBlur: () => commitNumber('maxReplyChars', chars, 10, 300, () => setChars(String(care.maxReplyChars))),
|
|
1340
|
+
style: inputStyle,
|
|
1341
|
+
})),
|
|
1342
|
+
]),
|
|
1343
|
+
|
|
1344
|
+
h('div', { key: 'quiet', style: { display: 'flex', gap: 8, alignItems: 'flex-end', flexWrap: 'wrap' } }, [
|
|
1345
|
+
h(Field, { key: 'f', label: '免打扰开始(留空 = 不启用)' }, h('input', {
|
|
1346
|
+
value: quietFrom,
|
|
1347
|
+
placeholder: '23:30',
|
|
1348
|
+
onChange: (event) => setQuietFrom(event.target.value.slice(0, 5)),
|
|
1349
|
+
onBlur: () => commitClock('quietFrom', quietFrom, () => setQuietFrom(care.quietFrom)),
|
|
1350
|
+
style: { ...inputStyle, width: 90 },
|
|
1351
|
+
})),
|
|
1352
|
+
h(Field, { key: 't', label: '免打扰结束' }, h('input', {
|
|
1353
|
+
value: quietTo,
|
|
1354
|
+
placeholder: '08:00',
|
|
1355
|
+
onChange: (event) => setQuietTo(event.target.value.slice(0, 5)),
|
|
1356
|
+
onBlur: () => commitClock('quietTo', quietTo, () => setQuietTo(care.quietTo)),
|
|
1357
|
+
style: { ...inputStyle, width: 90 },
|
|
1358
|
+
})),
|
|
1359
|
+
h('div', { key: 'm', style: { flex: 1, minWidth: 180 } }, h('div', {
|
|
1360
|
+
style: { display: 'flex', alignItems: 'center', gap: 8, fontSize: 11.5, color: C.label2, lineHeight: 1.6 },
|
|
1361
|
+
}, [
|
|
1362
|
+
h(Toggle, {
|
|
1363
|
+
key: 'sw',
|
|
1364
|
+
checked: care.groupOnlyWhenMentioned !== false,
|
|
1365
|
+
disabled: busy,
|
|
1366
|
+
label: '群里只回 @ 我的消息',
|
|
1367
|
+
onChange: (next) => {
|
|
1368
|
+
if (next === false && care.mode === 'auto') {
|
|
1369
|
+
const confirmed = window.confirm('关掉之后,TA 在任何群里说话都会被自动回复,而且是用你的身份发言。确定?')
|
|
1370
|
+
if (!confirmed) return
|
|
1371
|
+
}
|
|
1372
|
+
onChange({ groupOnlyWhenMentioned: next })
|
|
1373
|
+
},
|
|
1374
|
+
}),
|
|
1375
|
+
h('span', { key: 'l' }, '群里只回 @ 我的消息'),
|
|
1376
|
+
])),
|
|
1377
|
+
]),
|
|
1378
|
+
|
|
1379
|
+
clockError === '' ? null : h('div', {
|
|
1380
|
+
key: 'clock-error',
|
|
1381
|
+
style: { fontSize: 11, color: C.error, lineHeight: 1.6 },
|
|
1382
|
+
}, clockError),
|
|
1383
|
+
|
|
1384
|
+
usage === undefined ? null : h('div', {
|
|
1385
|
+
key: 'usage',
|
|
1386
|
+
style: { fontSize: 11, color: C.label2 },
|
|
1387
|
+
}, `最近一小时自动回复 ${usage.lastHour} 条,最后一条 ${fmtTime(usage.lastAt)}。`),
|
|
1388
|
+
])
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* Surface a failure instead of an empty panel: the renderer unmounts a slot
|
|
1393
|
+
* entry that throws, which looks exactly like a blank page and explains
|
|
1394
|
+
* nothing to the person looking at it.
|
|
1395
|
+
*/
|
|
1396
|
+
class PanelBoundary extends React.Component {
|
|
1397
|
+
constructor(props) {
|
|
1398
|
+
super(props)
|
|
1399
|
+
this.state = { error: null }
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
static getDerivedStateFromError(error) {
|
|
1403
|
+
return { error }
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
componentDidCatch(error, info) {
|
|
1407
|
+
console.error('qq-affinity: panel crashed', error, info)
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
render() {
|
|
1411
|
+
if (this.state.error === null) return this.props.children
|
|
1412
|
+
const detail = this.state.error !== null && this.state.error !== undefined && typeof this.state.error.message === 'string'
|
|
1413
|
+
? this.state.error.message
|
|
1414
|
+
: String(this.state.error)
|
|
1415
|
+
return h('div', { style: { padding: 28, fontSize: 13, lineHeight: 1.8, color: C.label } }, [
|
|
1416
|
+
h('div', { key: 'a', style: { fontWeight: 600, color: C.error, marginBottom: 6 } }, 'QQ 好感度面板出错了'),
|
|
1417
|
+
h('div', {
|
|
1418
|
+
key: 'b',
|
|
1419
|
+
style: {
|
|
1420
|
+
fontFamily: 'ui-monospace, Consolas, monospace',
|
|
1421
|
+
fontSize: 12,
|
|
1422
|
+
color: C.label2,
|
|
1423
|
+
whiteSpace: 'pre-wrap',
|
|
1424
|
+
wordBreak: 'break-word',
|
|
1425
|
+
},
|
|
1426
|
+
}, detail),
|
|
1427
|
+
h('div', { key: 'c', style: { marginTop: 10, color: C.label2 } },
|
|
1428
|
+
'刷新页面可以重试;开发者工具的控制台里有完整堆栈。'),
|
|
1429
|
+
])
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
/** The registered panel entry: the real UI, behind a readable failure screen. */
|
|
1434
|
+
function PanelRoot() {
|
|
1435
|
+
return h(PanelBoundary, null, h(App))
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
// ----------------------------------------------------------------- panel
|
|
1439
|
+
|
|
1440
|
+
function App() {
|
|
1441
|
+
const [state, setState] = useState(null)
|
|
1442
|
+
const [error, setError] = useState('')
|
|
1443
|
+
const [busy, setBusy] = useState('')
|
|
1444
|
+
const [tab, setTab] = useState('conversations')
|
|
1445
|
+
const [selectedConversation, setSelectedConversation] = useState('')
|
|
1446
|
+
const [selectedPerson, setSelectedPerson] = useState('')
|
|
1447
|
+
const [messages, setMessages] = useState(null)
|
|
1448
|
+
const [batches, setBatches] = useState([])
|
|
1449
|
+
const [personOutbox, setPersonOutbox] = useState([])
|
|
1450
|
+
const [toast, setToast] = useState('')
|
|
1451
|
+
// An analysis failure must stay on screen long enough to read and copy.
|
|
1452
|
+
const [panelError, setPanelError] = useState(null)
|
|
1453
|
+
const [importing, setImporting] = useState(null)
|
|
1454
|
+
const [creating, setCreating] = useState(null)
|
|
1455
|
+
const [settingsOpen, setSettingsOpen] = useState(false)
|
|
1456
|
+
// Right-click menu on a conversation row, and the rename dialog it opens.
|
|
1457
|
+
const [rowMenu, setRowMenu] = useState(null)
|
|
1458
|
+
const [renaming, setRenaming] = useState(null)
|
|
1459
|
+
/** Shared look for the right-click menu entries. */
|
|
1460
|
+
const menuItemStyle = {
|
|
1461
|
+
border: 'none',
|
|
1462
|
+
background: 'transparent',
|
|
1463
|
+
color: C.label,
|
|
1464
|
+
fontSize: 12,
|
|
1465
|
+
padding: '6px 10px',
|
|
1466
|
+
borderRadius: 5,
|
|
1467
|
+
cursor: 'pointer',
|
|
1468
|
+
textAlign: 'left',
|
|
1469
|
+
}
|
|
1470
|
+
// Batch refresh: the Host owns the job, the panel polls its progress.
|
|
1471
|
+
const [refreshJob, setRefreshJob] = useState(null)
|
|
1472
|
+
const [refreshTick, setRefreshTick] = useState(0)
|
|
1473
|
+
|
|
1474
|
+
// While a batch refresh is running, ask for progress every two seconds and
|
|
1475
|
+
// take the fresh archive state the Host returns with it.
|
|
1476
|
+
useEffect(() => {
|
|
1477
|
+
if (refreshJob === null || refreshJob.running !== true) return undefined
|
|
1478
|
+
let cancelled = false
|
|
1479
|
+
const timer = setTimeout(async () => {
|
|
1480
|
+
try {
|
|
1481
|
+
const result = await api('refresh-all', { method: 'POST', body: { action: 'status' } })
|
|
1482
|
+
if (cancelled || !alive.current) return
|
|
1483
|
+
setRefreshJob(result.job)
|
|
1484
|
+
setState(result.state)
|
|
1485
|
+
} catch {
|
|
1486
|
+
// One missed poll is fine; the next tick retries.
|
|
1487
|
+
if (!cancelled) setRefreshTick(value => value + 1)
|
|
1488
|
+
}
|
|
1489
|
+
}, 2000)
|
|
1490
|
+
return () => {
|
|
1491
|
+
cancelled = true
|
|
1492
|
+
clearTimeout(timer)
|
|
1493
|
+
}
|
|
1494
|
+
}, [refreshJob, refreshTick])
|
|
1495
|
+
// Archive list ordering: one of the three metrics, raw message count, or
|
|
1496
|
+
// the order the user arranged by dragging.
|
|
1497
|
+
const [sortField, setSortField] = useState('their')
|
|
1498
|
+
const [sortDir, setSortDir] = useState('desc')
|
|
1499
|
+
|
|
1500
|
+
// Folded sub-sections are a browsing preference, not archive data, so they
|
|
1501
|
+
// live in the browser rather than in meta.json.
|
|
1502
|
+
const [folded, setFolded] = useState(() => {
|
|
1503
|
+
try {
|
|
1504
|
+
const raw = localStorage.getItem('qq-affinity:folded')
|
|
1505
|
+
const parsed = raw === null ? null : JSON.parse(raw)
|
|
1506
|
+
return parsed !== null && typeof parsed === 'object' ? parsed : {}
|
|
1507
|
+
} catch {
|
|
1508
|
+
return {}
|
|
1509
|
+
}
|
|
1510
|
+
})
|
|
1511
|
+
const isFolded = (key) => folded[key] === true
|
|
1512
|
+
const toggleFold = (key) => {
|
|
1513
|
+
setFolded((previous) => {
|
|
1514
|
+
const next = { ...previous, [key]: previous[key] !== true }
|
|
1515
|
+
try {
|
|
1516
|
+
localStorage.setItem('qq-affinity:folded', JSON.stringify(next))
|
|
1517
|
+
} catch {
|
|
1518
|
+
// A blocked storage write only costs the preference, not the panel.
|
|
1519
|
+
}
|
|
1520
|
+
return next
|
|
1521
|
+
})
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
/** A foldable list heading: double-click it, or click the caret. */
|
|
1525
|
+
function sectionHead(key, label, count) {
|
|
1526
|
+
const collapsed = isFolded(key)
|
|
1527
|
+
return h('div', {
|
|
1528
|
+
key: `head-${key}`,
|
|
1529
|
+
title: '双击展开 / 收起',
|
|
1530
|
+
onDoubleClick: () => toggleFold(key),
|
|
1531
|
+
style: {
|
|
1532
|
+
padding: '8px 8px 3px',
|
|
1533
|
+
fontSize: 10.5,
|
|
1534
|
+
letterSpacing: '.4px',
|
|
1535
|
+
color: C.label2,
|
|
1536
|
+
display: 'flex',
|
|
1537
|
+
alignItems: 'center',
|
|
1538
|
+
gap: 6,
|
|
1539
|
+
cursor: 'pointer',
|
|
1540
|
+
userSelect: 'none',
|
|
1541
|
+
},
|
|
1542
|
+
}, [
|
|
1543
|
+
h('span', {
|
|
1544
|
+
key: 'caret',
|
|
1545
|
+
role: 'button',
|
|
1546
|
+
'aria-label': collapsed ? '展开' : '收起',
|
|
1547
|
+
onClick: (event) => {
|
|
1548
|
+
event.stopPropagation()
|
|
1549
|
+
toggleFold(key)
|
|
1550
|
+
},
|
|
1551
|
+
style: { width: 10, textAlign: 'center', fontSize: 9, lineHeight: 1 },
|
|
1552
|
+
}, collapsed ? '▸' : '▾'),
|
|
1553
|
+
h('span', { key: 'l' }, label),
|
|
1554
|
+
h('span', { key: 'n', style: { fontVariantNumeric: 'tabular-nums', opacity: 0.75 } }, String(count)),
|
|
1555
|
+
h('span', { key: 'line', style: { flex: 1, height: 1, background: C.border1 } }),
|
|
1556
|
+
])
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
/** Up/down buttons for one row: reordering that needs no gesture at all. */
|
|
1560
|
+
function moveButtons(kind, rows, id) {
|
|
1561
|
+
const ids = rows.map(row => (kind === 'conversations' ? row.id : row.uin))
|
|
1562
|
+
const index = ids.indexOf(id)
|
|
1563
|
+
const total = ids.length
|
|
1564
|
+
const arrow = (glyph, delta, disabled, label) => h('button', {
|
|
1565
|
+
key: glyph,
|
|
1566
|
+
type: 'button',
|
|
1567
|
+
'aria-label': label,
|
|
1568
|
+
title: label,
|
|
1569
|
+
disabled,
|
|
1570
|
+
onClick: (event) => {
|
|
1571
|
+
event.stopPropagation()
|
|
1572
|
+
event.preventDefault()
|
|
1573
|
+
if (index < 0 || index + delta < 0 || index + delta >= total) return
|
|
1574
|
+
if (kind === 'pinned') {
|
|
1575
|
+
void movePin(id, delta)
|
|
1576
|
+
return
|
|
1577
|
+
}
|
|
1578
|
+
void swapOrder(kind, ids, index, index + delta)
|
|
1579
|
+
},
|
|
1580
|
+
style: {
|
|
1581
|
+
border: 'none',
|
|
1582
|
+
background: 'transparent',
|
|
1583
|
+
padding: '1px 2px',
|
|
1584
|
+
fontSize: 8,
|
|
1585
|
+
lineHeight: 1,
|
|
1586
|
+
color: disabled ? C.idle : C.label2,
|
|
1587
|
+
cursor: disabled ? 'default' : 'pointer',
|
|
1588
|
+
},
|
|
1589
|
+
}, glyph)
|
|
1590
|
+
return h('span', {
|
|
1591
|
+
key: 'move',
|
|
1592
|
+
style: { display: 'flex', flexDirection: 'column', gap: 0, flex: '0 0 auto' },
|
|
1593
|
+
}, [
|
|
1594
|
+
arrow('▲', -1, index <= 0, '上移一位'),
|
|
1595
|
+
arrow('▼', 1, index < 0 || index >= total - 1, '下移一位'),
|
|
1596
|
+
])
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
/**
|
|
1600
|
+
* Swap two adjacent rows and persist the section's order.
|
|
1601
|
+
*
|
|
1602
|
+
* The smallest possible surface: ids are computed here from the rows on
|
|
1603
|
+
* screen, nothing is read from global order state, and every step after
|
|
1604
|
+
* the click is wrapped so a failure shows a message instead of a crash.
|
|
1605
|
+
*/
|
|
1606
|
+
async function swapOrder(kind, ids, from, to) {
|
|
1607
|
+
if (!Array.isArray(ids) || from < 0 || to < 0 || from >= ids.length || to >= ids.length) return
|
|
1608
|
+
const next = [...ids]
|
|
1609
|
+
;[next[from], next[to]] = [next[to], next[from]]
|
|
1610
|
+
setBusy(`order:${kind}`)
|
|
1611
|
+
try {
|
|
1612
|
+
const result = await api('order', { method: 'POST', body: { kind, ids: next } })
|
|
1613
|
+
if (!alive.current) return
|
|
1614
|
+
setPanelError(null)
|
|
1615
|
+
setState(result.state)
|
|
1616
|
+
} catch (failure) {
|
|
1617
|
+
if (!alive.current) return
|
|
1618
|
+
const message = `顺序没有保存成功:${failure instanceof Error ? failure.message : String(failure)}`
|
|
1619
|
+
setPanelError({ where: `order:${kind}`, message })
|
|
1620
|
+
notify(message)
|
|
1621
|
+
} finally {
|
|
1622
|
+
if (alive.current) setBusy('')
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
const alive = useRef(true)
|
|
1627
|
+
const pendingConversation = useRef('')
|
|
1628
|
+
const pendingPerson = useRef('')
|
|
1629
|
+
|
|
1630
|
+
// Derived from the snapshot before any hook reads them: an effect's
|
|
1631
|
+
// dependency array is evaluated during render, so a const declared later
|
|
1632
|
+
// in the body would be in the temporal dead zone and throw.
|
|
1633
|
+
const conversations = state?.conversations ?? []
|
|
1634
|
+
const people = state?.people ?? []
|
|
1635
|
+
const conversation = conversations.find(row => row.id === selectedConversation)
|
|
1636
|
+
const person = people.find(row => row.uin === selectedPerson)
|
|
1637
|
+
const selfMissing = state === null || state.settings.selfUin === ''
|
|
1638
|
+
const careEnabled = state?.settings?.careEnabled === true
|
|
1639
|
+
const careActive = state?.careActive ?? 0
|
|
1640
|
+
const draftCount = state?.draftCount ?? 0
|
|
1641
|
+
const channelReady = state?.channel?.enabled === true
|
|
1642
|
+
|
|
1643
|
+
useEffect(() => () => { alive.current = false }, [])
|
|
1644
|
+
|
|
1645
|
+
const notify = useCallback((message) => {
|
|
1646
|
+
setToast(message)
|
|
1647
|
+
window.setTimeout(() => { if (alive.current) setToast('') }, 4600)
|
|
1648
|
+
}, [])
|
|
1649
|
+
|
|
1650
|
+
const load = useCallback(async () => {
|
|
1651
|
+
try {
|
|
1652
|
+
const next = await api(`state?v=${encodeURIComponent(VERSION)}`)
|
|
1653
|
+
if (!alive.current) return
|
|
1654
|
+
setState(next)
|
|
1655
|
+
setError('')
|
|
1656
|
+
} catch (failure) {
|
|
1657
|
+
if (alive.current) setError(failure.message)
|
|
1658
|
+
}
|
|
1659
|
+
}, [])
|
|
1660
|
+
|
|
1661
|
+
useEffect(() => { void load() }, [load])
|
|
1662
|
+
|
|
1663
|
+
const run = useCallback(async (key, action) => {
|
|
1664
|
+
setBusy(key)
|
|
1665
|
+
try {
|
|
1666
|
+
return await action()
|
|
1667
|
+
} catch (failure) {
|
|
1668
|
+
if (alive.current) notify(failure.message)
|
|
1669
|
+
return undefined
|
|
1670
|
+
} finally {
|
|
1671
|
+
if (alive.current) setBusy('')
|
|
1672
|
+
}
|
|
1673
|
+
}, [notify])
|
|
1674
|
+
|
|
1675
|
+
const loadConversation = useCallback(async (id) => {
|
|
1676
|
+
pendingConversation.current = id
|
|
1677
|
+
if (id === '') { setMessages(null); setBatches([]); return }
|
|
1678
|
+
try {
|
|
1679
|
+
const [messageResult, suggestionResult] = await Promise.all([
|
|
1680
|
+
api(`messages?conversationId=${encodeURIComponent(id)}&limit=150`),
|
|
1681
|
+
api(`suggestions?conversationId=${encodeURIComponent(id)}`),
|
|
1682
|
+
])
|
|
1683
|
+
// A faster earlier request must not overwrite the conversation the user picked since.
|
|
1684
|
+
if (!alive.current || pendingConversation.current !== id) return
|
|
1685
|
+
setMessages({ ...messageResult, requestId: id })
|
|
1686
|
+
setBatches(suggestionResult.batches ?? [])
|
|
1687
|
+
} catch (failure) {
|
|
1688
|
+
if (alive.current) notify(failure.message)
|
|
1689
|
+
}
|
|
1690
|
+
}, [notify])
|
|
1691
|
+
|
|
1692
|
+
useEffect(() => { void loadConversation(selectedConversation) }, [selectedConversation, loadConversation])
|
|
1693
|
+
|
|
1694
|
+
const loadPersonOutbox = useCallback(async (uin) => {
|
|
1695
|
+
pendingPerson.current = uin
|
|
1696
|
+
if (uin === '') { setPersonOutbox([]); return }
|
|
1697
|
+
try {
|
|
1698
|
+
const result = await api(`outbox?uin=${encodeURIComponent(uin)}`)
|
|
1699
|
+
if (alive.current && pendingPerson.current === uin) setPersonOutbox(result.rows ?? [])
|
|
1700
|
+
} catch {
|
|
1701
|
+
// A missing history is not worth interrupting the panel for.
|
|
1702
|
+
}
|
|
1703
|
+
}, [])
|
|
1704
|
+
|
|
1705
|
+
useEffect(() => { void loadPersonOutbox(selectedPerson) }, [selectedPerson, loadPersonOutbox])
|
|
1706
|
+
|
|
1707
|
+
useEffect(() => {
|
|
1708
|
+
// While anything is under care, or a reply is waiting on the user, keep the
|
|
1709
|
+
// panel honest: automatic replies arrive without the user touching the page.
|
|
1710
|
+
if (careActive === 0 && draftCount === 0) return undefined
|
|
1711
|
+
const timer = window.setInterval(() => {
|
|
1712
|
+
void load()
|
|
1713
|
+
if (pendingConversation.current !== '') void loadConversation(pendingConversation.current)
|
|
1714
|
+
if (pendingPerson.current !== '') void loadPersonOutbox(pendingPerson.current)
|
|
1715
|
+
}, 25000)
|
|
1716
|
+
return () => window.clearInterval(timer)
|
|
1717
|
+
}, [careActive, draftCount, load, loadConversation, loadPersonOutbox])
|
|
1718
|
+
|
|
1719
|
+
// Handlers ----------------------------------------------------------
|
|
1720
|
+
|
|
1721
|
+
const toggleConversation = async (row, enabled) => {
|
|
1722
|
+
const result = await run(`toggle:${row.id}`, () => api('conversation', {
|
|
1723
|
+
method: 'POST',
|
|
1724
|
+
body: { action: 'toggle', id: row.id, enabled },
|
|
1725
|
+
}))
|
|
1726
|
+
if (result === undefined) return
|
|
1727
|
+
setState(result.state)
|
|
1728
|
+
await loadConversation(row.id)
|
|
1729
|
+
notify(enabled ? pullMessage(result.autoPull, '已开启') : '已关闭:这个对话不再参与任何判断。')
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* One sentence about what an automatic pull actually did.
|
|
1734
|
+
* @param {object | undefined} pull
|
|
1735
|
+
* @param {string} prefix
|
|
1736
|
+
*/
|
|
1737
|
+
const pullMessage = (pull, prefix) => {
|
|
1738
|
+
if (pull === undefined) return `${prefix}。`
|
|
1739
|
+
if (pull.reason === 'channel-off') return `${prefix}。实时通道没接通,所以没有自动读取;接通后点一次「补齐历史」即可。`
|
|
1740
|
+
if (pull.error !== undefined) {
|
|
1741
|
+
// The bridge reading from the QQ client's local cache: an empty result
|
|
1742
|
+
// means that cache has nothing, which the user can fix in QQ.
|
|
1743
|
+
if (/没有可用|empty/i.test(pull.error)) {
|
|
1744
|
+
return `${prefix},但没读到历史:QQ 客户端本地还没有这个对话的缓存。在 QQ 里打开它往上翻一下,再点「补齐历史」;之后的新消息会照常自动进来。`
|
|
1745
|
+
}
|
|
1746
|
+
return `${prefix},但自动读取没成功:${pull.error}`
|
|
1747
|
+
}
|
|
1748
|
+
if (pull.added > 0) return `${prefix},已自动读入最近 ${pull.added} 条消息。`
|
|
1749
|
+
return `${prefix},没有读到新消息(可能已经是最新的)。`
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
const addConversation = async (draft) => {
|
|
1753
|
+
const result = await run('create', () => api('conversation', {
|
|
1754
|
+
method: 'POST',
|
|
1755
|
+
body: { action: 'create', ...draft },
|
|
1756
|
+
}))
|
|
1757
|
+
if (result === undefined) return
|
|
1758
|
+
setState(result.state)
|
|
1759
|
+
setCreating(null)
|
|
1760
|
+
setTab('conversations')
|
|
1761
|
+
setSelectedConversation(result.conversation.id)
|
|
1762
|
+
notify(pullMessage(result.autoPull, '已添加'))
|
|
1763
|
+
await loadConversation(result.conversation.id)
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
const saveSettings = async (payload) => {
|
|
1767
|
+
const result = await run('settings', () => api('settings', { method: 'POST', body: payload }))
|
|
1768
|
+
if (result === undefined) return
|
|
1769
|
+
setState(result)
|
|
1770
|
+
setSettingsOpen(false)
|
|
1771
|
+
notify('已保存。')
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
/** The connection test reports its own failure inside the dialog, not as a toast. */
|
|
1775
|
+
const testChannel = async (draft) => {
|
|
1776
|
+
setBusy('test')
|
|
1777
|
+
try {
|
|
1778
|
+
const result = await api('onebot/test', { method: 'POST', body: { onebot: draft ?? {} } })
|
|
1779
|
+
if (alive.current) setState(result.state)
|
|
1780
|
+
return result
|
|
1781
|
+
} finally {
|
|
1782
|
+
if (alive.current) setBusy('')
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
/** Move the archive; failures belong inside the dialog that asked for it. */
|
|
1787
|
+
const moveLocation = async (payload) => {
|
|
1788
|
+
setBusy('location')
|
|
1789
|
+
try {
|
|
1790
|
+
const result = await api('location', { method: 'POST', body: payload })
|
|
1791
|
+
if (!alive.current) return result
|
|
1792
|
+
setState(result.state)
|
|
1793
|
+
// The selection may not exist in the archive that just became current.
|
|
1794
|
+
if (selectedConversation !== '' && result.state.conversations.some(row => row.id === selectedConversation)) {
|
|
1795
|
+
await loadConversation(selectedConversation)
|
|
1796
|
+
} else {
|
|
1797
|
+
setSelectedConversation('')
|
|
1798
|
+
setMessages(null)
|
|
1799
|
+
setBatches([])
|
|
1800
|
+
}
|
|
1801
|
+
if (selectedPerson !== '' && result.state.people.some(row => row.uin === selectedPerson)) {
|
|
1802
|
+
await loadPersonOutbox(selectedPerson)
|
|
1803
|
+
} else {
|
|
1804
|
+
setSelectedPerson('')
|
|
1805
|
+
setPersonOutbox([])
|
|
1806
|
+
}
|
|
1807
|
+
return result
|
|
1808
|
+
} finally {
|
|
1809
|
+
if (alive.current) setBusy('')
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
const setCare = async (uin, patch) => {
|
|
1814
|
+
const result = await run(`care:${uin}`, () => api('care', { method: 'POST', body: { uin, patch } }))
|
|
1815
|
+
if (result === undefined) return
|
|
1816
|
+
setState(result.state)
|
|
1817
|
+
if (patch.enabled === true) notify('已开启托管。盯一下下面的记录,确认它按你预期的方式回。')
|
|
1818
|
+
else if (patch.enabled === false) notify('已关闭托管。')
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
/** Pull history from the bridge; the Host reports per-conversation outcomes. */
|
|
1822
|
+
const backfill = async (conversationId) => {
|
|
1823
|
+
setBusy(`backfill:${conversationId}`)
|
|
1824
|
+
try {
|
|
1825
|
+
const result = await api('backfill', { method: 'POST', body: conversationId === '' ? {} : { conversationId } })
|
|
1826
|
+
if (!alive.current) return result
|
|
1827
|
+
setState(result.state)
|
|
1828
|
+
if (conversationId !== '') await loadConversation(conversationId)
|
|
1829
|
+
notify(result.note ?? `补齐完成,新增 ${result.added} 条。`)
|
|
1830
|
+
return result
|
|
1831
|
+
} catch (failure) {
|
|
1832
|
+
if (alive.current) notify(failure.message)
|
|
1833
|
+
return undefined
|
|
1834
|
+
} finally {
|
|
1835
|
+
if (alive.current) setBusy('')
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
const outboxAction = async (id, action) => {
|
|
1840
|
+
const result = await run(`outbox:${id}`, () => api('outbox/action', { method: 'POST', body: { id, action } }))
|
|
1841
|
+
if (result === undefined) return
|
|
1842
|
+
setState(result.state)
|
|
1843
|
+
if (selectedConversation !== '') await loadConversation(selectedConversation)
|
|
1844
|
+
if (selectedPerson !== '') await loadPersonOutbox(selectedPerson)
|
|
1845
|
+
notify(action === 'approve' ? '已发送。' : '已丢弃这条草稿。')
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
const pauseCare = async () => {
|
|
1849
|
+
const result = await run('pause', () => api('settings', { method: 'POST', body: { careEnabled: false } }))
|
|
1850
|
+
if (result === undefined) return
|
|
1851
|
+
setState(result)
|
|
1852
|
+
notify('托管已全部暂停。单人设置都还在,下次打开总开关就会恢复。')
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
const scorePerson = async (uin) => {
|
|
1856
|
+
setBusy(`score:${uin}`)
|
|
1857
|
+
setPanelError(null)
|
|
1858
|
+
try {
|
|
1859
|
+
const result = await api('score', { method: 'POST', body: { uin } })
|
|
1860
|
+
if (!alive.current) return
|
|
1861
|
+
setState(result.state)
|
|
1862
|
+
setSelectedPerson(uin)
|
|
1863
|
+
setTab('people')
|
|
1864
|
+
notify(`已更新 QQ ${uin} 的三项分数。`)
|
|
1865
|
+
} catch (failure) {
|
|
1866
|
+
if (!alive.current) return
|
|
1867
|
+
// Keep it visible: the toast disappears before it can be read.
|
|
1868
|
+
setPanelError({ where: `score:${uin}`, message: failure.message })
|
|
1869
|
+
} finally {
|
|
1870
|
+
if (alive.current) setBusy('')
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
const suggest = async (id) => {
|
|
1875
|
+
const result = await run(`suggest:${id}`, () => api('suggest', { method: 'POST', body: { conversationId: id } }))
|
|
1876
|
+
if (result === undefined) return
|
|
1877
|
+
setBatches(result.batches ?? [])
|
|
1878
|
+
notify('已生成三条候选回复。')
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
/** Copy text, reporting whether the browser allowed it. */
|
|
1882
|
+
const copyText = async (text) => {
|
|
1883
|
+
try {
|
|
1884
|
+
await navigator.clipboard.writeText(String(text ?? ''))
|
|
1885
|
+
return true
|
|
1886
|
+
} catch {
|
|
1887
|
+
return false
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
const adopt = async (conversationId, optionId) => {
|
|
1892
|
+
const option = batches.flatMap(batch => batch.options ?? []).find(entry => entry.id === optionId)
|
|
1893
|
+
setBusy(`adopt:${optionId}`)
|
|
1894
|
+
try {
|
|
1895
|
+
const result = await api('adopt', { method: 'POST', body: { conversationId, suggestionId: optionId } })
|
|
1896
|
+
if (!alive.current) return
|
|
1897
|
+
// Clipboard is only the fallback: normally the Host sends it for us.
|
|
1898
|
+
if (result.sent !== true) await copyText(result.text ?? option?.text)
|
|
1899
|
+
await loadConversation(conversationId)
|
|
1900
|
+
notify(result.note ?? '已发送。')
|
|
1901
|
+
} catch (failure) {
|
|
1902
|
+
if (!alive.current) return
|
|
1903
|
+
// The adoption is recorded even when sending failed, so keep the text reachable.
|
|
1904
|
+
const text = failure.payload?.text ?? option?.text
|
|
1905
|
+
const copied = typeof text === 'string' && text !== '' ? await copyText(text) : false
|
|
1906
|
+
notify(`${failure.message}${copied ? '(文本已复制到剪贴板)' : ''}`)
|
|
1907
|
+
await loadConversation(conversationId)
|
|
1908
|
+
} finally {
|
|
1909
|
+
if (alive.current) setBusy('')
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
const analyzePersonaRow = async (uin) => {
|
|
1914
|
+
setBusy(`persona:${uin}`)
|
|
1915
|
+
setPanelError(null)
|
|
1916
|
+
try {
|
|
1917
|
+
const result = await api('persona', { method: 'POST', body: { uin } })
|
|
1918
|
+
if (!alive.current) return
|
|
1919
|
+
setState(result.state)
|
|
1920
|
+
notify('人格画像已更新。')
|
|
1921
|
+
} catch (failure) {
|
|
1922
|
+
if (!alive.current) return
|
|
1923
|
+
setPanelError({ where: `persona:${uin}`, message: failure.message })
|
|
1924
|
+
} finally {
|
|
1925
|
+
if (alive.current) setBusy('')
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
const analyzeSelfProfile = async () => {
|
|
1930
|
+
setBusy('self')
|
|
1931
|
+
setPanelError(null)
|
|
1932
|
+
try {
|
|
1933
|
+
const result = await api('self', { method: 'POST' })
|
|
1934
|
+
if (!alive.current) return
|
|
1935
|
+
setState(result.state)
|
|
1936
|
+
notify('自我分析已更新。')
|
|
1937
|
+
} catch (failure) {
|
|
1938
|
+
if (!alive.current) return
|
|
1939
|
+
setPanelError({ where: 'self', message: failure.message })
|
|
1940
|
+
} finally {
|
|
1941
|
+
if (alive.current) setBusy('')
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
/** Kick off a Host-side refresh of every profiled person. */
|
|
1946
|
+
const startRefreshAll = async () => {
|
|
1947
|
+
setPanelError(null)
|
|
1948
|
+
try {
|
|
1949
|
+
const result = await api('refresh-all', { method: 'POST', body: {} })
|
|
1950
|
+
if (!alive.current) return
|
|
1951
|
+
setRefreshJob(result.job)
|
|
1952
|
+
if (result.job.total === 0) notify('还没有建档的人,没有可更新的数据。')
|
|
1953
|
+
else notify(`已开始更新你建档的 ${result.job.total} 个人。`)
|
|
1954
|
+
} catch (failure) {
|
|
1955
|
+
if (alive.current) notify(failure.message)
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
const cancelRefreshAll = async () => {
|
|
1960
|
+
try {
|
|
1961
|
+
const result = await api('refresh-all', { method: 'POST', body: { action: 'cancel' } })
|
|
1962
|
+
if (!alive.current) return
|
|
1963
|
+
setRefreshJob(result.job)
|
|
1964
|
+
notify('已请求停止。')
|
|
1965
|
+
} catch (failure) {
|
|
1966
|
+
if (alive.current) notify(failure.message)
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
/** Pin or unpin one conversation. */
|
|
1971
|
+
const togglePin = async (id) => {
|
|
1972
|
+
try {
|
|
1973
|
+
const result = await api('pinned', { method: 'POST', body: { action: 'toggle', id } })
|
|
1974
|
+
if (!alive.current) return
|
|
1975
|
+
setState(result.state)
|
|
1976
|
+
notify(result.pinned.includes(id) ? '已置顶。' : '已取消置顶。')
|
|
1977
|
+
} catch (failure) {
|
|
1978
|
+
if (alive.current) notify(failure.message)
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
/** Move one pin up or down among the pinned conversations. */
|
|
1983
|
+
const movePin = async (id, delta) => {
|
|
1984
|
+
try {
|
|
1985
|
+
const result = await api('pinned', { method: 'POST', body: { action: 'move', id, delta } })
|
|
1986
|
+
if (!alive.current) return
|
|
1987
|
+
setState(result.state)
|
|
1988
|
+
} catch (failure) {
|
|
1989
|
+
if (alive.current) notify(failure.message)
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
/** Save a new remark for one conversation. */
|
|
1994
|
+
const saveRename = async (id, title) => {
|
|
1995
|
+
try {
|
|
1996
|
+
const result = await api('conversation', { method: 'POST', body: { action: 'update', id, title } })
|
|
1997
|
+
if (!alive.current) return
|
|
1998
|
+
setState(result.state)
|
|
1999
|
+
notify('备注已保存。')
|
|
2000
|
+
} catch (failure) {
|
|
2001
|
+
if (alive.current) notify(failure.message)
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
const submitImport = async (text) => {
|
|
2006
|
+
if (importing === null) return undefined
|
|
2007
|
+
setBusy('import')
|
|
2008
|
+
try {
|
|
2009
|
+
const result = await api('import', { method: 'POST', body: { conversationId: importing.id, text } })
|
|
2010
|
+
if (!alive.current) return undefined
|
|
2011
|
+
setState(result.state)
|
|
2012
|
+
await loadConversation(importing.id)
|
|
2013
|
+
return result
|
|
2014
|
+
} catch (failure) {
|
|
2015
|
+
return {
|
|
2016
|
+
error: failure.message,
|
|
2017
|
+
needsSelfUin: failure.payload?.needsSelfUin === true,
|
|
2018
|
+
stats: failure.payload?.stats,
|
|
2019
|
+
}
|
|
2020
|
+
} finally {
|
|
2021
|
+
if (alive.current) setBusy('')
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
const removeConversation = async (id) => {
|
|
2026
|
+
if (!window.confirm('删除这个对话以及它保存的全部聊天记录?这个操作不能撤销。')) return
|
|
2027
|
+
const result = await run(`remove:${id}`, () => api('conversation', { method: 'POST', body: { action: 'remove', id } }))
|
|
2028
|
+
if (result === undefined) return
|
|
2029
|
+
setState(result.state)
|
|
2030
|
+
setSelectedConversation('')
|
|
2031
|
+
notify('已删除这个对话的本地数据。')
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
// Views -------------------------------------------------------------
|
|
2035
|
+
|
|
2036
|
+
if (state === null && error !== '') {
|
|
2037
|
+
return h('div', { style: { padding: 32, fontSize: 13, lineHeight: 1.8, color: C.label } }, [
|
|
2038
|
+
h('div', { key: 'a', style: { fontWeight: 600, color: C.error, marginBottom: 6 } }, '插件后台没有响应'),
|
|
2039
|
+
h('div', { key: 'b', style: { color: C.label2 } }, error),
|
|
2040
|
+
h('div', { key: 'c', style: { marginTop: 10, color: C.label2 } },
|
|
2041
|
+
'确认「QQ 好感度档案」这一行在插件的 Installed 列表里是启用状态,然后刷新页面。'),
|
|
2042
|
+
h('div', { key: 'd', style: { marginTop: 12 } },
|
|
2043
|
+
h(Btn, { kind: 'outline', onClick: () => { void load() } }, '重试')),
|
|
2044
|
+
])
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
if (state === null) return h('div', { style: { padding: 32, color: C.label2, fontSize: 13 } }, '正在读取本地档案…')
|
|
2048
|
+
|
|
2049
|
+
return h('div', {
|
|
2050
|
+
style: {
|
|
2051
|
+
height: '100%',
|
|
2052
|
+
minHeight: 0,
|
|
2053
|
+
display: 'flex',
|
|
2054
|
+
flexDirection: 'column',
|
|
2055
|
+
background: C.bg,
|
|
2056
|
+
color: C.label,
|
|
2057
|
+
fontSize: 13,
|
|
2058
|
+
overflow: 'hidden',
|
|
2059
|
+
},
|
|
2060
|
+
}, [
|
|
2061
|
+
h('header', {
|
|
2062
|
+
key: 'header',
|
|
2063
|
+
style: { flex: '0 0 auto', display: 'flex', alignItems: 'center', gap: 10, padding: '12px 18px', borderBottom: `1px solid ${C.border1}` },
|
|
2064
|
+
}, [
|
|
2065
|
+
h('div', { key: 't', style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0, flex: 1 } }, [
|
|
2066
|
+
h('div', { style: { fontSize: 14, fontWeight: 600 } }, 'QQ 好感度档案'),
|
|
2067
|
+
h('div', {
|
|
2068
|
+
title: state.dataDir,
|
|
2069
|
+
style: { fontSize: 11, color: C.label2, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' },
|
|
2070
|
+
}, selfMissing ? '先填写你的 QQ 号,插件才能区分「我」和「对方」' : `数据保存在 ${state.dataDir}`),
|
|
2071
|
+
]),
|
|
2072
|
+
careActive > 0 || draftCount > 0 ? h('div', {
|
|
2073
|
+
key: 'care',
|
|
2074
|
+
style: {
|
|
2075
|
+
display: 'flex',
|
|
2076
|
+
alignItems: 'center',
|
|
2077
|
+
gap: 8,
|
|
2078
|
+
border: `1px solid ${careActive === 0 ? C.brand : careEnabled ? (channelReady ? C.brand : C.warn) : C.border2}`,
|
|
2079
|
+
background: careEnabled && channelReady ? 'transparent' : C.layer1,
|
|
2080
|
+
borderRadius: 999,
|
|
2081
|
+
padding: '2px 4px 2px 10px',
|
|
2082
|
+
},
|
|
2083
|
+
}, [
|
|
2084
|
+
h('span', {
|
|
2085
|
+
key: 'l',
|
|
2086
|
+
style: {
|
|
2087
|
+
fontSize: 11.5,
|
|
2088
|
+
whiteSpace: 'nowrap',
|
|
2089
|
+
color: careActive > 0 && careEnabled && !channelReady ? C.warn : careEnabled ? C.brand : C.label2,
|
|
2090
|
+
},
|
|
2091
|
+
}, careActive === 0
|
|
2092
|
+
? `${draftCount} 条待确认`
|
|
2093
|
+
: !careEnabled
|
|
2094
|
+
? `托管已暂停 · ${careActive} 人`
|
|
2095
|
+
: !channelReady
|
|
2096
|
+
? `托管待接通 · ${careActive} 人`
|
|
2097
|
+
: `托管运行中 · ${careActive} 人`),
|
|
2098
|
+
draftCount > 0 && careActive > 0
|
|
2099
|
+
? h(Chip, { key: 'd', color: C.brand }, `${draftCount} 待确认`)
|
|
2100
|
+
: null,
|
|
2101
|
+
careActive > 0 && careEnabled ? h(Btn, {
|
|
2102
|
+
key: 'pause',
|
|
2103
|
+
kind: 'quiet',
|
|
2104
|
+
title: '立刻暂停所有自动回复,单人设置保留',
|
|
2105
|
+
onClick: () => void pauseCare(),
|
|
2106
|
+
style: { padding: '2px 8px', fontSize: 11 },
|
|
2107
|
+
}, '全部暂停') : h(Btn, {
|
|
2108
|
+
key: 'open',
|
|
2109
|
+
kind: 'quiet',
|
|
2110
|
+
onClick: () => setSettingsOpen(true),
|
|
2111
|
+
style: { padding: '2px 8px', fontSize: 11 },
|
|
2112
|
+
}, careActive === 0 ? '去确认' : '去设置'),
|
|
2113
|
+
]) : null,
|
|
2114
|
+
h(Btn, {
|
|
2115
|
+
key: 'self',
|
|
2116
|
+
kind: selfMissing ? 'primary' : 'outline',
|
|
2117
|
+
onClick: () => setSettingsOpen(true),
|
|
2118
|
+
}, selfMissing ? '填写我的 QQ 号' : '设置'),
|
|
2119
|
+
h(Btn, {
|
|
2120
|
+
key: 'refresh',
|
|
2121
|
+
kind: 'quiet',
|
|
2122
|
+
title: '重新读取本地档案',
|
|
2123
|
+
ariaLabel: '刷新',
|
|
2124
|
+
onClick: () => { void load(); void loadConversation(selectedConversation) },
|
|
2125
|
+
}, '刷新'),
|
|
2126
|
+
]),
|
|
2127
|
+
|
|
2128
|
+
h('div', { key: 'body', style: { flex: 1, minHeight: 0, display: 'flex' } }, [
|
|
2129
|
+
h('aside', {
|
|
2130
|
+
key: 'left',
|
|
2131
|
+
style: {
|
|
2132
|
+
flex: '0 0 262px',
|
|
2133
|
+
minWidth: 0,
|
|
2134
|
+
borderRight: `1px solid ${C.border1}`,
|
|
2135
|
+
display: 'flex',
|
|
2136
|
+
flexDirection: 'column',
|
|
2137
|
+
background: C.layer1,
|
|
2138
|
+
},
|
|
2139
|
+
}, [
|
|
2140
|
+
h('div', {
|
|
2141
|
+
key: 'tabs',
|
|
2142
|
+
role: 'tablist',
|
|
2143
|
+
'aria-label': '档案视图',
|
|
2144
|
+
style: { display: 'flex', gap: 4, padding: '10px 10px 6px', flex: '0 0 auto' },
|
|
2145
|
+
}, [
|
|
2146
|
+
tabButton('conversations', '对话', conversations.length),
|
|
2147
|
+
tabButton('people', '档案', people.length),
|
|
2148
|
+
tabButton('self', '我', 0),
|
|
2149
|
+
]),
|
|
2150
|
+
tab === 'people' ? sortBar() : null,
|
|
2151
|
+
panelError !== null && typeof panelError.where === 'string' && panelError.where.startsWith('order:') ? h('div', {
|
|
2152
|
+
key: 'order-error',
|
|
2153
|
+
style: {
|
|
2154
|
+
margin: '0 10px 6px',
|
|
2155
|
+
padding: '6px 9px',
|
|
2156
|
+
borderRadius: 6,
|
|
2157
|
+
background: C.layer1,
|
|
2158
|
+
border: `1px solid ${C.error}`,
|
|
2159
|
+
color: C.error,
|
|
2160
|
+
fontSize: 11,
|
|
2161
|
+
lineHeight: 1.6,
|
|
2162
|
+
whiteSpace: 'pre-wrap',
|
|
2163
|
+
wordBreak: 'break-word',
|
|
2164
|
+
flex: '0 0 auto',
|
|
2165
|
+
},
|
|
2166
|
+
}, panelError.message) : null,
|
|
2167
|
+
h('div', { key: 'list', style: { flex: 1, minHeight: 0, overflowY: 'auto', padding: '4px 8px 12px' } },
|
|
2168
|
+
tab === 'conversations'
|
|
2169
|
+
? conversationList()
|
|
2170
|
+
: tab === 'people' ? peopleList() : selfRail()),
|
|
2171
|
+
h('div', {
|
|
2172
|
+
key: 'foot',
|
|
2173
|
+
style: {
|
|
2174
|
+
padding: 10,
|
|
2175
|
+
borderTop: `1px solid ${C.border1}`,
|
|
2176
|
+
display: 'flex',
|
|
2177
|
+
flexDirection: 'column',
|
|
2178
|
+
gap: 6,
|
|
2179
|
+
flex: '0 0 auto',
|
|
2180
|
+
},
|
|
2181
|
+
}, [
|
|
2182
|
+
refreshBar(),
|
|
2183
|
+
h(Btn, {
|
|
2184
|
+
key: 'add',
|
|
2185
|
+
kind: conversations.length === 0 ? 'primary' : 'outline',
|
|
2186
|
+
style: { flex: 1, justifyContent: 'center' },
|
|
2187
|
+
onClick: () => setCreating({ kind: 'c2c' }),
|
|
2188
|
+
}, '+ 添加对话'),
|
|
2189
|
+
versionLine(),
|
|
2190
|
+
]),
|
|
2191
|
+
]),
|
|
2192
|
+
|
|
2193
|
+
h('main', {
|
|
2194
|
+
key: 'right',
|
|
2195
|
+
style: { flex: 1, minWidth: 0, minHeight: 0, overflowY: 'auto', padding: 18 },
|
|
2196
|
+
}, tab === 'conversations'
|
|
2197
|
+
? (conversation === undefined ? emptyState() : conversationDetail(conversation))
|
|
2198
|
+
: tab === 'people'
|
|
2199
|
+
? (person === undefined ? emptyState() : personDetail(person))
|
|
2200
|
+
: selfDetail()),
|
|
2201
|
+
]),
|
|
2202
|
+
|
|
2203
|
+
settingsOpen ? h(SettingsForm, {
|
|
2204
|
+
key: 'settings',
|
|
2205
|
+
settings: state.settings,
|
|
2206
|
+
channel: state.channel,
|
|
2207
|
+
dataLocation: state.location,
|
|
2208
|
+
autoCount: state.careAutoActive ?? 0,
|
|
2209
|
+
vision: state.vision ?? null,
|
|
2210
|
+
busy: busy === 'settings' || busy === 'test' || busy === 'location' || busy === 'backfill:',
|
|
2211
|
+
onClose: () => setSettingsOpen(false),
|
|
2212
|
+
onSave: (payload) => void saveSettings(payload),
|
|
2213
|
+
onTest: testChannel,
|
|
2214
|
+
onMove: moveLocation,
|
|
2215
|
+
onBackfill: () => backfill(''),
|
|
2216
|
+
}) : null,
|
|
2217
|
+
creating !== null ? h(CreatorForm, {
|
|
2218
|
+
key: 'creator',
|
|
2219
|
+
initialKind: creating.kind,
|
|
2220
|
+
busy: busy === 'create',
|
|
2221
|
+
onClose: () => setCreating(null),
|
|
2222
|
+
onAdd: (draft) => void addConversation(draft),
|
|
2223
|
+
}) : null,
|
|
2224
|
+
renaming !== null ? h(RenameDialog, {
|
|
2225
|
+
key: 'rename',
|
|
2226
|
+
initial: renaming.title ?? '',
|
|
2227
|
+
busy: busy === `rename:${renaming.id}`,
|
|
2228
|
+
onClose: () => setRenaming(null),
|
|
2229
|
+
onSave: (title) => { void saveRename(renaming.id, title); setRenaming(null) },
|
|
2230
|
+
}) : null,
|
|
2231
|
+
rowMenu !== null ? h('div', {
|
|
2232
|
+
key: 'rowmenu-backdrop',
|
|
2233
|
+
style: { position: 'fixed', inset: 0, zIndex: 90, background: 'transparent' },
|
|
2234
|
+
onClick: () => setRowMenu(null),
|
|
2235
|
+
onContextMenu: (event) => {
|
|
2236
|
+
event.preventDefault()
|
|
2237
|
+
setRowMenu(null)
|
|
2238
|
+
},
|
|
2239
|
+
}, h('div', {
|
|
2240
|
+
key: 'rowmenu',
|
|
2241
|
+
style: {
|
|
2242
|
+
position: 'fixed',
|
|
2243
|
+
left: rowMenu.x,
|
|
2244
|
+
top: rowMenu.y,
|
|
2245
|
+
zIndex: 91,
|
|
2246
|
+
background: C.overlay,
|
|
2247
|
+
border: `1px solid ${C.border1}`,
|
|
2248
|
+
borderRadius: 8,
|
|
2249
|
+
padding: 4,
|
|
2250
|
+
display: 'flex',
|
|
2251
|
+
flexDirection: 'column',
|
|
2252
|
+
minWidth: 132,
|
|
2253
|
+
boxShadow: '0 6px 24px rgba(0,0,0,.18)',
|
|
2254
|
+
},
|
|
2255
|
+
onClick: (event) => event.stopPropagation(),
|
|
2256
|
+
}, [
|
|
2257
|
+
h('button', {
|
|
2258
|
+
key: 'rename',
|
|
2259
|
+
type: 'button',
|
|
2260
|
+
onClick: () => {
|
|
2261
|
+
setRenaming({ id: rowMenu.id, title: rowMenu.title })
|
|
2262
|
+
setRowMenu(null)
|
|
2263
|
+
},
|
|
2264
|
+
style: menuItemStyle,
|
|
2265
|
+
}, '修改备注'),
|
|
2266
|
+
h('button', {
|
|
2267
|
+
key: 'pin',
|
|
2268
|
+
type: 'button',
|
|
2269
|
+
onClick: () => {
|
|
2270
|
+
void togglePin(rowMenu.id)
|
|
2271
|
+
setRowMenu(null)
|
|
2272
|
+
},
|
|
2273
|
+
style: menuItemStyle,
|
|
2274
|
+
}, rowMenu.pinned === true ? '取消置顶' : '置顶'),
|
|
2275
|
+
])) : null,
|
|
2276
|
+
importing !== null ? h(ImportForm, {
|
|
2277
|
+
key: 'import',
|
|
2278
|
+
conversation,
|
|
2279
|
+
busy: busy === 'import',
|
|
2280
|
+
onClose: () => setImporting(null),
|
|
2281
|
+
onSubmit: submitImport,
|
|
2282
|
+
onNeedSelf: () => { setImporting(null); setSettingsOpen(true) },
|
|
2283
|
+
}) : null,
|
|
2284
|
+
toast === '' ? null : h('div', {
|
|
2285
|
+
key: 'toast',
|
|
2286
|
+
role: 'status',
|
|
2287
|
+
style: {
|
|
2288
|
+
position: 'fixed',
|
|
2289
|
+
left: '50%',
|
|
2290
|
+
bottom: 24,
|
|
2291
|
+
transform: 'translateX(-50%)',
|
|
2292
|
+
background: C.overlay,
|
|
2293
|
+
color: C.label,
|
|
2294
|
+
border: `1px solid ${C.border2}`,
|
|
2295
|
+
boxShadow: '0 8px 28px rgba(0,0,0,.18)',
|
|
2296
|
+
borderRadius: 8,
|
|
2297
|
+
padding: '9px 14px',
|
|
2298
|
+
fontSize: 12,
|
|
2299
|
+
maxWidth: 620,
|
|
2300
|
+
lineHeight: 1.65,
|
|
2301
|
+
zIndex: 40,
|
|
2302
|
+
pointerEvents: 'none',
|
|
2303
|
+
},
|
|
2304
|
+
}, toast),
|
|
2305
|
+
])
|
|
2306
|
+
|
|
2307
|
+
// Pieces ------------------------------------------------------------
|
|
2308
|
+
|
|
2309
|
+
function tabButton(key, label, count) {
|
|
2310
|
+
const current = tab === key
|
|
2311
|
+
return h('button', {
|
|
2312
|
+
key,
|
|
2313
|
+
type: 'button',
|
|
2314
|
+
role: 'tab',
|
|
2315
|
+
'aria-selected': current,
|
|
2316
|
+
// Switching views keeps each side's selection, so going back costs nothing.
|
|
2317
|
+
onClick: () => setTab(key),
|
|
2318
|
+
style: {
|
|
2319
|
+
flex: 1,
|
|
2320
|
+
appearance: 'none',
|
|
2321
|
+
border: 'none',
|
|
2322
|
+
borderRadius: 6,
|
|
2323
|
+
padding: '5px 8px',
|
|
2324
|
+
font: 'inherit',
|
|
2325
|
+
fontSize: 12,
|
|
2326
|
+
cursor: 'pointer',
|
|
2327
|
+
background: current ? C.bg : 'transparent',
|
|
2328
|
+
color: current ? C.label : C.label2,
|
|
2329
|
+
fontWeight: current ? 600 : 400,
|
|
2330
|
+
display: 'flex',
|
|
2331
|
+
alignItems: 'center',
|
|
2332
|
+
justifyContent: 'center',
|
|
2333
|
+
gap: 6,
|
|
2334
|
+
},
|
|
2335
|
+
}, [label, h('span', {
|
|
2336
|
+
key: 'c',
|
|
2337
|
+
style: { fontSize: 11, color: C.label2, fontVariantNumeric: 'tabular-nums' },
|
|
2338
|
+
}, String(count))])
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
/**
|
|
2342
|
+
* One list row. With a `drag` descriptor the row can be reordered.
|
|
2343
|
+
*
|
|
2344
|
+
* Reordering uses pointer events, not HTML5 drag-and-drop: the desktop
|
|
2345
|
+
* shell can suppress native dragging through CSS (`-webkit-user-drag`),
|
|
2346
|
+
* and a suppressed native drag fails completely silently. Pointer events
|
|
2347
|
+
* are never affected by that.
|
|
2348
|
+
*/
|
|
2349
|
+
function rowShell(active, onClick, children, onContextMenu) {
|
|
2350
|
+
return h('div', {
|
|
2351
|
+
role: 'button',
|
|
2352
|
+
tabIndex: 0,
|
|
2353
|
+
onClick,
|
|
2354
|
+
onContextMenu,
|
|
2355
|
+
onKeyDown: (event) => {
|
|
2356
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
2357
|
+
event.preventDefault()
|
|
2358
|
+
onClick()
|
|
2359
|
+
}
|
|
2360
|
+
},
|
|
2361
|
+
style: {
|
|
2362
|
+
display: 'flex',
|
|
2363
|
+
alignItems: 'center',
|
|
2364
|
+
gap: 8,
|
|
2365
|
+
padding: '7px 8px',
|
|
2366
|
+
marginBottom: 2,
|
|
2367
|
+
borderRadius: 6,
|
|
2368
|
+
cursor: 'pointer',
|
|
2369
|
+
background: active ? C.bg : 'transparent',
|
|
2370
|
+
border: `1px solid ${active ? C.border1 : 'transparent'}`,
|
|
2371
|
+
},
|
|
2372
|
+
}, children)
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
/** Conversations split by kind, each half keeping the arranged order. */
|
|
2376
|
+
/**
|
|
2377
|
+
* Version footer. A client bundle older than the Host is the one failure
|
|
2378
|
+
* mode that looks like "the button is broken", so it is stated outright.
|
|
2379
|
+
*/
|
|
2380
|
+
function versionLine() {
|
|
2381
|
+
const host = state.versions?.host ?? ''
|
|
2382
|
+
const mismatch = host !== '' && host !== VERSION
|
|
2383
|
+
return h('div', {
|
|
2384
|
+
key: 'ver',
|
|
2385
|
+
title: mismatch
|
|
2386
|
+
? `界面 v${VERSION},后台 v${host}:界面是旧版本,按 Ctrl+Shift+R 硬刷新`
|
|
2387
|
+
: '界面与后台版本一致',
|
|
2388
|
+
style: {
|
|
2389
|
+
fontSize: 10,
|
|
2390
|
+
lineHeight: 1.5,
|
|
2391
|
+
display: 'flex',
|
|
2392
|
+
justifyContent: 'space-between',
|
|
2393
|
+
gap: 6,
|
|
2394
|
+
color: mismatch ? C.error : C.label2,
|
|
2395
|
+
},
|
|
2396
|
+
}, [
|
|
2397
|
+
h('span', { key: 'c' }, `界面 v${VERSION}`),
|
|
2398
|
+
h('span', { key: 'h' }, host === '' ? '' : `后台 v${host}`),
|
|
2399
|
+
])
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
function conversationGroups() {
|
|
2403
|
+
const pinned = new Set(state.pinned ?? [])
|
|
2404
|
+
return [
|
|
2405
|
+
['私聊', conversations.filter(row => row.kind !== 'group' && !pinned.has(row.id))],
|
|
2406
|
+
['群聊', conversations.filter(row => row.kind === 'group' && !pinned.has(row.id))],
|
|
2407
|
+
].filter(([, rows]) => rows.length > 0)
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
/** Pinned conversations in pin order (topmost first). */
|
|
2411
|
+
function pinnedRows() {
|
|
2412
|
+
const map = new Map(conversations.map(row => [row.id, row]))
|
|
2413
|
+
return (state.pinned ?? []).map(id => map.get(id)).filter(row => row !== undefined)
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
/** The order the conversation list is rendered in. */
|
|
2417
|
+
|
|
2418
|
+
function conversationList() {
|
|
2419
|
+
if (conversations.length === 0) {
|
|
2420
|
+
return h('div', { style: { padding: '18px 10px', color: C.label2, fontSize: 12, lineHeight: 1.85 } }, [
|
|
2421
|
+
h('div', { key: 'a', style: { color: C.label, fontWeight: 600, marginBottom: 4 } }, '还没有对话'),
|
|
2422
|
+
h('div', { key: 'b' }, '点下面的「添加对话」,填上名字和 QQ 号(群聊填群号)。实时通道接通时,添加后会立刻拉取最近 200 条消息;没接通就先存着,之后接通了点一次「补齐历史」。'),
|
|
2423
|
+
])
|
|
2424
|
+
}
|
|
2425
|
+
const blocks = []
|
|
2426
|
+
const renderRow = (row, sectionRows, moveKind) => {
|
|
2427
|
+
// Colour carries the kind; the filled/hollow dot carries on/off.
|
|
2428
|
+
const dotColor = row.kind === 'group' ? C.success : C.brand
|
|
2429
|
+
return rowShell(row.id === selectedConversation, () => {
|
|
2430
|
+
setTab('conversations')
|
|
2431
|
+
setSelectedConversation(row.id)
|
|
2432
|
+
}, [
|
|
2433
|
+
h('span', {
|
|
2434
|
+
key: 'dot',
|
|
2435
|
+
title: `${row.kind === 'group' ? '群聊' : '私聊'} · ${row.enabled ? '已开启' : '未开启'}`,
|
|
2436
|
+
style: {
|
|
2437
|
+
width: 7,
|
|
2438
|
+
height: 7,
|
|
2439
|
+
borderRadius: 999,
|
|
2440
|
+
flex: '0 0 auto',
|
|
2441
|
+
boxSizing: 'border-box',
|
|
2442
|
+
background: row.enabled ? dotColor : 'transparent',
|
|
2443
|
+
border: `1.5px solid ${dotColor}`,
|
|
2444
|
+
opacity: row.enabled ? 1 : 0.6,
|
|
2445
|
+
},
|
|
2446
|
+
}),
|
|
2447
|
+
h('span', {
|
|
2448
|
+
key: 'name',
|
|
2449
|
+
style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontSize: 12.5 },
|
|
2450
|
+
}, row.title === '' ? (row.peerUin === '' ? '未命名对话' : `QQ ${row.peerUin}`) : row.title),
|
|
2451
|
+
h('span', {
|
|
2452
|
+
key: 'n',
|
|
2453
|
+
style: { fontSize: 11, color: C.label2, fontVariantNumeric: 'tabular-nums' },
|
|
2454
|
+
}, row.messageCount > 0 ? String(row.messageCount) : '—'),
|
|
2455
|
+
moveButtons(moveKind, sectionRows, row.id),
|
|
2456
|
+
], (event) => {
|
|
2457
|
+
event.preventDefault()
|
|
2458
|
+
event.stopPropagation()
|
|
2459
|
+
setRowMenu({ x: event.clientX, y: event.clientY, id: row.id, title: row.title, pinned: (state.pinned ?? []).includes(row.id) })
|
|
2460
|
+
})
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
const pins = pinnedRows()
|
|
2464
|
+
if (pins.length > 0) {
|
|
2465
|
+
const foldKey = 'conversations:置顶'
|
|
2466
|
+
blocks.push(sectionHead(foldKey, '置顶', pins.length))
|
|
2467
|
+
if (!isFolded(foldKey)) for (const row of pins) blocks.push(renderRow(row, pins, 'pinned'))
|
|
2468
|
+
}
|
|
2469
|
+
for (const [label, rows] of conversationGroups()) {
|
|
2470
|
+
const foldKey = `conversations:${label}`
|
|
2471
|
+
blocks.push(sectionHead(foldKey, label, rows.length))
|
|
2472
|
+
if (isFolded(foldKey)) continue
|
|
2473
|
+
for (const row of rows) blocks.push(renderRow(row, rows, 'conversations'))
|
|
2474
|
+
}
|
|
2475
|
+
return blocks
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
/** The metric a档案 row is being sorted by. */
|
|
2479
|
+
function sortValue(row) {
|
|
2480
|
+
if (sortField === 'messages') return row.messageCount ?? 0
|
|
2481
|
+
const stored = row.score
|
|
2482
|
+
if (stored === null || stored === undefined) return undefined
|
|
2483
|
+
if (sortField === 'mine') return stored.myFavor.score
|
|
2484
|
+
if (sortField === 'intimacy') return stored.intimacy.score
|
|
2485
|
+
return stored.theirFavor.score
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
/** Apply the active metric sort to one already-partitioned slice. */
|
|
2489
|
+
function sortSlice(rows) {
|
|
2490
|
+
return [...rows].sort((left, right) => {
|
|
2491
|
+
const a = sortValue(left)
|
|
2492
|
+
const b = sortValue(right)
|
|
2493
|
+
// Rows without that metric always sink, whichever direction is chosen.
|
|
2494
|
+
if (a === undefined && b === undefined) return (right.messageCount ?? 0) - (left.messageCount ?? 0)
|
|
2495
|
+
if (a === undefined) return 1
|
|
2496
|
+
if (b === undefined) return -1
|
|
2497
|
+
return sortDir === 'desc' ? b - a : a - b
|
|
2498
|
+
})
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
/**
|
|
2502
|
+
* People split by how they entered the archive: a private chat the user
|
|
2503
|
+
* added by hand, or a group member who only appeared because that group
|
|
2504
|
+
* was turned on.
|
|
2505
|
+
*/
|
|
2506
|
+
function personGroups() {
|
|
2507
|
+
return [
|
|
2508
|
+
['私聊里的人物(手动添加)', people.filter(row => row.origin !== 'group')],
|
|
2509
|
+
['群聊里出现的人物', people.filter(row => row.origin === 'group')],
|
|
2510
|
+
].filter(([, rows]) => rows.length > 0)
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
function sortBar() {
|
|
2514
|
+
const options = [
|
|
2515
|
+
['their', 'TA 对你的好感度'],
|
|
2516
|
+
['mine', '你对 TA 的好感度'],
|
|
2517
|
+
['intimacy', '亲密度'],
|
|
2518
|
+
['messages', '消息条数'],
|
|
2519
|
+
]
|
|
2520
|
+
return h('div', {
|
|
2521
|
+
key: 'sort',
|
|
2522
|
+
style: {
|
|
2523
|
+
display: 'flex',
|
|
2524
|
+
gap: 4,
|
|
2525
|
+
alignItems: 'center',
|
|
2526
|
+
padding: '0 10px 8px',
|
|
2527
|
+
flex: '0 0 auto',
|
|
2528
|
+
},
|
|
2529
|
+
}, [
|
|
2530
|
+
h('select', {
|
|
2531
|
+
key: 'field',
|
|
2532
|
+
value: sortField,
|
|
2533
|
+
'aria-label': '排序依据',
|
|
2534
|
+
onChange: (event) => setSortField(event.target.value),
|
|
2535
|
+
style: {
|
|
2536
|
+
flex: 1,
|
|
2537
|
+
minWidth: 0,
|
|
2538
|
+
appearance: 'none',
|
|
2539
|
+
border: `1px solid ${C.border1}`,
|
|
2540
|
+
borderRadius: 6,
|
|
2541
|
+
background: C.bg,
|
|
2542
|
+
color: C.label,
|
|
2543
|
+
fontSize: 11.5,
|
|
2544
|
+
padding: '3px 6px',
|
|
2545
|
+
font: 'inherit',
|
|
2546
|
+
cursor: 'pointer',
|
|
2547
|
+
},
|
|
2548
|
+
}, options.map(([value, label]) => h('option', { key: value, value }, label))),
|
|
2549
|
+
h(Btn, {
|
|
2550
|
+
key: 'dir',
|
|
2551
|
+
kind: 'outline',
|
|
2552
|
+
ariaLabel: sortDir === 'desc' ? '当前降序,点击切换升序' : '当前升序,点击切换降序',
|
|
2553
|
+
title: sortDir === 'desc' ? '降序(高到低)' : '升序(低到高)',
|
|
2554
|
+
onClick: () => setSortDir(sortDir === 'desc' ? 'asc' : 'desc'),
|
|
2555
|
+
style: { padding: '3px 8px', fontSize: 11.5 },
|
|
2556
|
+
}, sortDir === 'desc' ? '↓ 降序' : '↑ 升序'),
|
|
2557
|
+
])
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
/** The batch-refresh bar, above the add-conversation button. */
|
|
2561
|
+
function refreshBar() {
|
|
2562
|
+
const job = refreshJob
|
|
2563
|
+
if (job === null || job.running !== true) {
|
|
2564
|
+
return h('div', {
|
|
2565
|
+
key: 'refresh',
|
|
2566
|
+
style: { flex: '0 0 auto' },
|
|
2567
|
+
}, h(Btn, {
|
|
2568
|
+
key: 'run',
|
|
2569
|
+
kind: 'outline',
|
|
2570
|
+
title: '只重新分析你自己建档的人(私聊里的人物)。群聊里出现的人不会被动到。',
|
|
2571
|
+
onClick: () => void startRefreshAll(),
|
|
2572
|
+
style: { width: '100%', justifyContent: 'center' },
|
|
2573
|
+
}, '一键更新全部'))
|
|
2574
|
+
}
|
|
2575
|
+
const total = Math.max(1, job.total)
|
|
2576
|
+
const percent = Math.round(Math.min(100, job.done / total * 100))
|
|
2577
|
+
const currentName = people.find(row => row.uin === job.current)?.names?.slice(-1)[0] ?? job.current
|
|
2578
|
+
return h('div', {
|
|
2579
|
+
key: 'refresh',
|
|
2580
|
+
style: { display: 'flex', flexDirection: 'column', gap: 6, flex: '0 0 auto' },
|
|
2581
|
+
}, [
|
|
2582
|
+
h('div', { key: 't', style: { display: 'flex', alignItems: 'center', gap: 6 } }, [
|
|
2583
|
+
h('span', {
|
|
2584
|
+
key: 's',
|
|
2585
|
+
style: { flex: 1, fontSize: 11, color: C.label2, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
2586
|
+
}, `更新中 ${job.done}/${job.total}${job.failed > 0 ? ` · 失败 ${job.failed}` : ''} · ${currentName}`),
|
|
2587
|
+
h(Btn, { key: 'c', kind: 'outline', style: { padding: '2px 7px', fontSize: 11 }, onClick: () => void cancelRefreshAll() }, '停止'),
|
|
2588
|
+
]),
|
|
2589
|
+
h('div', {
|
|
2590
|
+
key: 'bar',
|
|
2591
|
+
style: { height: 4, borderRadius: 999, background: C.layer2, overflow: 'hidden' },
|
|
2592
|
+
}, h('div', { style: { width: `${percent}%`, height: '100%', background: C.brand } })),
|
|
2593
|
+
])
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
/** One person row inside the archive list. */
|
|
2597
|
+
function personRow(row, ordered) {
|
|
2598
|
+
const name = row.names.length > 0 ? row.names[row.names.length - 1] : `QQ ${row.uin}`
|
|
2599
|
+
const stored = row.score
|
|
2600
|
+
const shown = sortValue(row) === undefined
|
|
2601
|
+
? (stored === null || stored === undefined ? undefined : stored.theirFavor.score)
|
|
2602
|
+
: sortValue(row)
|
|
2603
|
+
const metricLabel = sortField === 'messages' ? '条' : ''
|
|
2604
|
+
return rowShell(row.uin === selectedPerson, () => {
|
|
2605
|
+
setTab('people')
|
|
2606
|
+
setSelectedPerson(row.uin)
|
|
2607
|
+
}, [
|
|
2608
|
+
h('span', { key: 'name', title: `QQ ${row.uin}`, style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 1 } }, [
|
|
2609
|
+
h('span', {
|
|
2610
|
+
key: 'n',
|
|
2611
|
+
style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontSize: 12.5 },
|
|
2612
|
+
}, [
|
|
2613
|
+
h('span', { key: 'real' }, name),
|
|
2614
|
+
// The remark lives on the conversation, not on the person record.
|
|
2615
|
+
row.remark === '' || row.remark === undefined
|
|
2616
|
+
? null
|
|
2617
|
+
: h('span', {
|
|
2618
|
+
key: 'remark',
|
|
2619
|
+
style: { color: C.label2, fontSize: 11.5 },
|
|
2620
|
+
}, `(${row.remark})`),
|
|
2621
|
+
]),
|
|
2622
|
+
]),
|
|
2623
|
+
stored === null || stored === undefined
|
|
2624
|
+
? h('span', { key: 'm', style: { fontSize: 10.5, color: C.label2 } }, '未分析')
|
|
2625
|
+
: h('span', {
|
|
2626
|
+
key: 'm',
|
|
2627
|
+
title: `TA→你 ${stored.theirFavor.score} · 你→TA ${stored.myFavor.score} · 亲密度 ${stored.intimacy.score}`,
|
|
2628
|
+
style: {
|
|
2629
|
+
fontSize: sortField === 'messages' ? 11 : 15,
|
|
2630
|
+
fontWeight: sortField === 'messages' ? 400 : 600,
|
|
2631
|
+
color: sortField === 'messages' ? C.label2 : tone(shown),
|
|
2632
|
+
fontVariantNumeric: 'tabular-nums',
|
|
2633
|
+
letterSpacing: '-.2px',
|
|
2634
|
+
},
|
|
2635
|
+
}, `${shown}${metricLabel}`),
|
|
2636
|
+
moveButtons('people', ordered, row.uin),
|
|
2637
|
+
])
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
function peopleList() {
|
|
2641
|
+
if (people.length === 0) {
|
|
2642
|
+
return h('div', { style: { padding: '18px 10px', color: C.label2, fontSize: 12, lineHeight: 1.85 } },
|
|
2643
|
+
'还没有任何人的档案。导入并开启至少一个对话之后,插件才会按 QQ 号建档。')
|
|
2644
|
+
}
|
|
2645
|
+
const blocks = []
|
|
2646
|
+
for (const [label, rows] of personGroups()) {
|
|
2647
|
+
const foldKey = `people:${label}`
|
|
2648
|
+
blocks.push(sectionHead(foldKey, label, rows.length))
|
|
2649
|
+
if (isFolded(foldKey)) continue
|
|
2650
|
+
const ordered = sortSlice(rows)
|
|
2651
|
+
for (const row of ordered) blocks.push(personRow(row, ordered))
|
|
2652
|
+
}
|
|
2653
|
+
return blocks
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
function emptyState() {
|
|
2657
|
+
return h('div', {
|
|
2658
|
+
style: {
|
|
2659
|
+
height: '100%',
|
|
2660
|
+
minHeight: 320,
|
|
2661
|
+
display: 'flex',
|
|
2662
|
+
flexDirection: 'column',
|
|
2663
|
+
alignItems: 'center',
|
|
2664
|
+
justifyContent: 'center',
|
|
2665
|
+
gap: 12,
|
|
2666
|
+
color: C.label2,
|
|
2667
|
+
lineHeight: 1.9,
|
|
2668
|
+
textAlign: 'center',
|
|
2669
|
+
},
|
|
2670
|
+
}, [
|
|
2671
|
+
h('div', { key: 'a', style: { fontSize: 15, color: C.label, fontWeight: 600 } }, '选一个对话,或先建一个'),
|
|
2672
|
+
h('div', { key: 'b', style: { fontSize: 12, maxWidth: 430 } },
|
|
2673
|
+
'插件不会主动去读 QQ。每个对话都要你手动开启,只有开启之后导入的记录才会被保存和计算。'),
|
|
2674
|
+
h('ol', { key: 'c', style: { textAlign: 'left', fontSize: 12, margin: 0, paddingLeft: 18 } }, [
|
|
2675
|
+
h('li', { key: '1' }, `填上你自己的 QQ 号${selfMissing ? '(还没填)' : ''}`),
|
|
2676
|
+
h('li', { key: '2' }, '添加对话,填名字就行;对方的 QQ 号可以从记录里自动识别'),
|
|
2677
|
+
h('li', { key: '3' }, '打开这个对话的开关'),
|
|
2678
|
+
h('li', { key: '4' }, '导入导出的聊天记录(.txt 或粘贴)'),
|
|
2679
|
+
h('li', { key: '5' }, '在「档案」里分析好感度,在对话里要回复建议'),
|
|
2680
|
+
]),
|
|
2681
|
+
h('div', { key: 'd', style: { display: 'flex', gap: 8, marginTop: 2 } }, [
|
|
2682
|
+
selfMissing
|
|
2683
|
+
? h(Btn, { key: 's', kind: 'primary', onClick: () => setSettingsOpen(true) }, '填写我的 QQ 号')
|
|
2684
|
+
: null,
|
|
2685
|
+
h(Btn, {
|
|
2686
|
+
key: 'c',
|
|
2687
|
+
kind: selfMissing ? 'outline' : 'primary',
|
|
2688
|
+
onClick: () => setCreating({ kind: 'c2c' }),
|
|
2689
|
+
}, '添加对话'),
|
|
2690
|
+
]),
|
|
2691
|
+
])
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
function conversationDetail(row) {
|
|
2695
|
+
// Only data fetched for this exact conversation may render; anything else
|
|
2696
|
+
// is still in flight and would otherwise flash as an empty transcript.
|
|
2697
|
+
const loaded = messages !== null && messages.requestId === row.id
|
|
2698
|
+
const features = loaded ? messages.features : undefined
|
|
2699
|
+
const items = loaded ? (messages.messages ?? []) : []
|
|
2700
|
+
const newestBatch = batches[0]
|
|
2701
|
+
|
|
2702
|
+
return h('div', {
|
|
2703
|
+
style: { display: 'flex', flexDirection: 'column', gap: 14, paddingBottom: 28, maxWidth: 1000 },
|
|
2704
|
+
}, [
|
|
2705
|
+
h('div', { key: 'head', style: { display: 'flex', alignItems: 'flex-start', gap: 12, flexWrap: 'wrap' } }, [
|
|
2706
|
+
h('div', { key: 'id', style: { flex: 1, minWidth: 210, display: 'flex', flexDirection: 'column', gap: 5 } }, [
|
|
2707
|
+
h('div', { key: 'r1', style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } }, [
|
|
2708
|
+
h('h2', {
|
|
2709
|
+
key: 'n',
|
|
2710
|
+
style: { margin: 0, fontSize: 17, fontWeight: 600 },
|
|
2711
|
+
}, row.title === '' ? `QQ ${row.peerUin || '未命名'}` : row.title),
|
|
2712
|
+
h(Chip, { key: 'k' }, row.kind === 'group' ? '群聊' : '私聊'),
|
|
2713
|
+
row.enabled
|
|
2714
|
+
? h(Chip, { key: 'e', color: C.brand }, '已开启')
|
|
2715
|
+
: h(Chip, { key: 'e', color: C.idle }, '未开启'),
|
|
2716
|
+
]),
|
|
2717
|
+
h('div', { key: 'r2', style: { fontSize: 11.5, color: C.label2, display: 'flex', gap: 12, flexWrap: 'wrap' } }, [
|
|
2718
|
+
h('span', { key: 'q' }, row.kind === 'group' ? `群号 ${row.groupUin || '—'}` : `对方 QQ ${row.peerUin || '—'}`),
|
|
2719
|
+
h('span', { key: 'c' }, `${row.messageCount} 条消息`),
|
|
2720
|
+
h('span', { key: 't' }, `最后一条 ${fmtTime(row.lastMessageAt)}`),
|
|
2721
|
+
]),
|
|
2722
|
+
]),
|
|
2723
|
+
h('div', { key: 'sw', style: { display: 'flex', alignItems: 'center', gap: 8 } }, [
|
|
2724
|
+
h('span', { key: 'l', style: { fontSize: 12, color: C.label2 } }, '读取这个对话'),
|
|
2725
|
+
h(Toggle, {
|
|
2726
|
+
key: 's',
|
|
2727
|
+
checked: row.enabled,
|
|
2728
|
+
disabled: busy !== '',
|
|
2729
|
+
label: row.enabled ? '关闭这个对话的读取' : '开启这个对话的读取',
|
|
2730
|
+
onChange: (next) => void toggleConversation(row, next),
|
|
2731
|
+
}),
|
|
2732
|
+
]),
|
|
2733
|
+
]),
|
|
2734
|
+
|
|
2735
|
+
!row.enabled ? h('div', {
|
|
2736
|
+
key: 'off',
|
|
2737
|
+
style: {
|
|
2738
|
+
background: C.layer1,
|
|
2739
|
+
border: `1px dashed ${C.border2}`,
|
|
2740
|
+
borderRadius: 10,
|
|
2741
|
+
padding: 14,
|
|
2742
|
+
color: C.label2,
|
|
2743
|
+
fontSize: 12,
|
|
2744
|
+
lineHeight: 1.85,
|
|
2745
|
+
},
|
|
2746
|
+
}, '这个对话是关闭状态:插件不会读取、保存或分析它的任何内容。把上面的「读取这个对话」打开之后,才会出现导入和分析的入口。') : null,
|
|
2747
|
+
|
|
2748
|
+
row.enabled && row.messageCount === 0 ? h('div', {
|
|
2749
|
+
key: 'empty',
|
|
2750
|
+
style: {
|
|
2751
|
+
background: C.layer1,
|
|
2752
|
+
border: `1px dashed ${C.border2}`,
|
|
2753
|
+
borderRadius: 10,
|
|
2754
|
+
padding: 14,
|
|
2755
|
+
fontSize: 12,
|
|
2756
|
+
lineHeight: 1.9,
|
|
2757
|
+
color: C.label2,
|
|
2758
|
+
},
|
|
2759
|
+
}, [
|
|
2760
|
+
h('div', { key: 'a', style: { color: C.label, fontWeight: 600, marginBottom: 4 } }, '这个对话还没有消息,两条路:'),
|
|
2761
|
+
h('div', { key: 'b' }, '① 接实时通道(设置 → 实时通道)。之后新消息自动进来,也能一键把历史补齐 —— 这是唯一能做到全自动的路。'),
|
|
2762
|
+
h('div', { key: 'c' }, '② 导入 .txt 文本记录。注意 QQ 自己导出的 .bak 是加密容器,插件解析不了;只有别的客户端导出的纯文本才认。'),
|
|
2763
|
+
]) : null,
|
|
2764
|
+
|
|
2765
|
+
row.enabled ? h('div', { key: 'actions', style: { display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center' } }, [
|
|
2766
|
+
h(Btn, { key: 'imp', kind: 'primary', onClick: () => setImporting({ id: row.id }) }, '导入聊天记录'),
|
|
2767
|
+
channelReady ? h(Btn, {
|
|
2768
|
+
key: 'hist',
|
|
2769
|
+
kind: 'outline',
|
|
2770
|
+
disabled: busy === `backfill:${row.id}`,
|
|
2771
|
+
title: '把桥里已经载入的消息同步进这个对话',
|
|
2772
|
+
onClick: () => void backfill(row.id),
|
|
2773
|
+
}, busy === `backfill:${row.id}` ? '正在同步…' : '同步已载入的消息') : null,
|
|
2774
|
+
h(Btn, {
|
|
2775
|
+
key: 'sug',
|
|
2776
|
+
kind: 'outline',
|
|
2777
|
+
disabled: busy === `suggest:${row.id}` || row.messageCount === 0,
|
|
2778
|
+
title: row.messageCount === 0 ? '先导入记录,才有需要回的消息' : undefined,
|
|
2779
|
+
onClick: () => void suggest(row.id),
|
|
2780
|
+
}, busy === `suggest:${row.id}` ? '正在生成…' : '生成三条回复建议'),
|
|
2781
|
+
row.peerUin !== '' ? h(Btn, {
|
|
2782
|
+
key: 'score',
|
|
2783
|
+
kind: 'outline',
|
|
2784
|
+
disabled: busy === `score:${row.peerUin}`,
|
|
2785
|
+
onClick: () => void scorePerson(row.peerUin),
|
|
2786
|
+
}, busy === `score:${row.peerUin}` ? '正在分析…' : '分析好感度') : null,
|
|
2787
|
+
h('div', { key: 'sp', style: { flex: 1 } }),
|
|
2788
|
+
h(Btn, { key: 'del', kind: 'danger', onClick: () => void removeConversation(row.id) }, '删除数据'),
|
|
2789
|
+
]) : null,
|
|
2790
|
+
|
|
2791
|
+
row.enabled && row.kind === 'group' ? h('div', {
|
|
2792
|
+
key: 'members',
|
|
2793
|
+
style: { fontSize: 11.5, color: C.label2, lineHeight: 1.8, display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' },
|
|
2794
|
+
}, (row.participants ?? []).length === 0
|
|
2795
|
+
? ['导入记录后,这里会列出群里的每个人;点名字就能单独分析 TA 的好感度。']
|
|
2796
|
+
: [
|
|
2797
|
+
h('span', { key: 'l' }, '群成员档案:'),
|
|
2798
|
+
...(row.participants ?? []).slice(0, 12).map(uin => h(Btn, {
|
|
2799
|
+
key: uin,
|
|
2800
|
+
kind: 'quiet',
|
|
2801
|
+
disabled: busy === `score:${uin}`,
|
|
2802
|
+
onClick: () => void scorePerson(uin),
|
|
2803
|
+
style: { padding: '1px 7px', fontSize: 11 },
|
|
2804
|
+
}, people.find(entry => entry.uin === uin)?.names.slice(-1)[0] ?? `QQ ${uin}`)),
|
|
2805
|
+
]) : null,
|
|
2806
|
+
|
|
2807
|
+
row.enabled && newestBatch !== undefined ? h(Section, {
|
|
2808
|
+
key: 'suggestions',
|
|
2809
|
+
title: '智能回复建议',
|
|
2810
|
+
extra: [
|
|
2811
|
+
h('span', { key: 't', style: { fontSize: 11, color: C.label2 } }, fmtTime(newestBatch.createdAt)),
|
|
2812
|
+
h(Btn, { key: 'again', kind: 'quiet', onClick: () => void suggest(row.id) }, '换一批'),
|
|
2813
|
+
],
|
|
2814
|
+
}, [
|
|
2815
|
+
h('div', {
|
|
2816
|
+
key: 'quote',
|
|
2817
|
+
style: {
|
|
2818
|
+
fontSize: 12,
|
|
2819
|
+
color: C.label2,
|
|
2820
|
+
background: C.bg,
|
|
2821
|
+
border: `1px solid ${C.border1}`,
|
|
2822
|
+
borderRadius: 8,
|
|
2823
|
+
padding: '8px 10px',
|
|
2824
|
+
lineHeight: 1.7,
|
|
2825
|
+
whiteSpace: 'pre-wrap',
|
|
2826
|
+
wordBreak: 'break-word',
|
|
2827
|
+
},
|
|
2828
|
+
}, `${newestBatch.targetName || '对方'}:${newestBatch.basedOnText}`),
|
|
2829
|
+
...(newestBatch.options ?? []).map(option => h('div', {
|
|
2830
|
+
key: option.id,
|
|
2831
|
+
style: {
|
|
2832
|
+
border: `1px solid ${option.adopted ? C.brand : C.border1}`,
|
|
2833
|
+
background: C.bg,
|
|
2834
|
+
borderRadius: 8,
|
|
2835
|
+
padding: 10,
|
|
2836
|
+
display: 'flex',
|
|
2837
|
+
flexDirection: 'column',
|
|
2838
|
+
gap: 6,
|
|
2839
|
+
},
|
|
2840
|
+
}, [
|
|
2841
|
+
h('div', { key: 'top', style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } }, [
|
|
2842
|
+
h(Chip, { key: 's', color: C.brand }, option.strategy),
|
|
2843
|
+
option.adopted ? h(Chip, { key: 'a', color: C.success }, '已采用') : null,
|
|
2844
|
+
h('div', { key: 'sp', style: { flex: 1 } }),
|
|
2845
|
+
h(Btn, {
|
|
2846
|
+
key: 'adopt',
|
|
2847
|
+
kind: option.adopted ? 'outline' : 'primary',
|
|
2848
|
+
disabled: option.adopted === true || busy === `adopt:${option.id}`,
|
|
2849
|
+
title: channelReady
|
|
2850
|
+
? '直接以你的身份发给对方'
|
|
2851
|
+
: '通道没接通,只能记录并复制到剪贴板',
|
|
2852
|
+
onClick: () => void adopt(row.id, option.id),
|
|
2853
|
+
}, option.adopted ? '已发送' : (channelReady ? '采用并发送' : '采用')),
|
|
2854
|
+
]),
|
|
2855
|
+
h('div', {
|
|
2856
|
+
key: 'text',
|
|
2857
|
+
style: { fontSize: 13, lineHeight: 1.75, whiteSpace: 'pre-wrap', wordBreak: 'break-word' },
|
|
2858
|
+
}, option.text),
|
|
2859
|
+
option.why === '' ? null : h('div', { key: 'why', style: { fontSize: 11.5, color: C.label2, lineHeight: 1.6 } }, `为什么:${option.why}`),
|
|
2860
|
+
option.expectedGain === '' ? null : h('div', { key: 'gain', style: { fontSize: 11.5, color: C.label2, lineHeight: 1.6 } }, `预期:${option.expectedGain}`),
|
|
2861
|
+
option.risk === '' ? null : h('div', { key: 'risk', style: { fontSize: 11.5, color: C.warn, lineHeight: 1.6 } }, `风险:${option.risk}`),
|
|
2862
|
+
])),
|
|
2863
|
+
h('div', {
|
|
2864
|
+
key: 'note',
|
|
2865
|
+
style: { fontSize: 11, color: C.label2, lineHeight: 1.75 },
|
|
2866
|
+
}, channelReady
|
|
2867
|
+
? '「采用并发送」会直接以你的身份发给对方,同时记为 AI 代笔(不计入「你对 TA 的好感度」)。'
|
|
2868
|
+
: '实时通道没接通,所以现在只能记录 + 复制。接通之后这里会直接发送。'),
|
|
2869
|
+
]) : null,
|
|
2870
|
+
|
|
2871
|
+
row.enabled ? h(Section, {
|
|
2872
|
+
key: 'outbox',
|
|
2873
|
+
title: '自动回复记录',
|
|
2874
|
+
extra: h(Btn, {
|
|
2875
|
+
key: 'all',
|
|
2876
|
+
kind: 'quiet',
|
|
2877
|
+
onClick: () => { void load() },
|
|
2878
|
+
title: '重新读取',
|
|
2879
|
+
}, '刷新'),
|
|
2880
|
+
}, h(OutboxList, {
|
|
2881
|
+
rows: loaded ? (messages.outbox ?? []) : [],
|
|
2882
|
+
busy: busy !== '',
|
|
2883
|
+
onApprove: (id) => void outboxAction(id, 'approve'),
|
|
2884
|
+
onCancel: (id) => void outboxAction(id, 'cancel'),
|
|
2885
|
+
nameOf: () => row.title === '' ? `QQ ${row.peerUin || row.groupUin || '未知'}` : row.title,
|
|
2886
|
+
})) : null,
|
|
2887
|
+
|
|
2888
|
+
row.enabled ? h(Section, {
|
|
2889
|
+
key: 'transcript',
|
|
2890
|
+
title: '聊天记录',
|
|
2891
|
+
extra: features === undefined ? null : [
|
|
2892
|
+
h(Chip, { key: 'm', mono: true }, `${features.totalMessages} 条`),
|
|
2893
|
+
h(Chip, { key: 'a', mono: true, color: features.aiAdoptedMessages > 0 ? C.brand : C.label2 }, `AI 代笔 ${features.aiAdoptedMessages}`),
|
|
2894
|
+
],
|
|
2895
|
+
}, [
|
|
2896
|
+
!loaded
|
|
2897
|
+
? h('div', { key: 'loading', style: { fontSize: 12, color: C.label2, lineHeight: 1.85 } }, '正在读取…')
|
|
2898
|
+
: (items.length === 0
|
|
2899
|
+
? h('div', { key: 'none', style: { fontSize: 12, color: C.label2, lineHeight: 1.85 } }, '还没有导入记录。点上面的「导入聊天记录」。')
|
|
2900
|
+
: h('div', {
|
|
2901
|
+
key: 'list',
|
|
2902
|
+
style: { display: 'flex', flexDirection: 'column', gap: 6, maxHeight: 430, overflowY: 'auto', paddingRight: 4 },
|
|
2903
|
+
}, items.map(message => h('div', {
|
|
2904
|
+
key: message.id,
|
|
2905
|
+
style: {
|
|
2906
|
+
display: 'flex',
|
|
2907
|
+
flexDirection: 'column',
|
|
2908
|
+
gap: 2,
|
|
2909
|
+
alignItems: message.direction === 'out' ? 'flex-end' : 'flex-start',
|
|
2910
|
+
},
|
|
2911
|
+
}, [
|
|
2912
|
+
h('div', {
|
|
2913
|
+
key: 'b',
|
|
2914
|
+
style: {
|
|
2915
|
+
maxWidth: '78%',
|
|
2916
|
+
background: message.direction === 'out' ? C.brand : C.bg,
|
|
2917
|
+
color: message.direction === 'out' ? '#fff' : C.label,
|
|
2918
|
+
border: `1px solid ${message.direction === 'out' ? C.brand : C.border1}`,
|
|
2919
|
+
borderRadius: 8,
|
|
2920
|
+
padding: '6px 9px',
|
|
2921
|
+
fontSize: 12.5,
|
|
2922
|
+
lineHeight: 1.65,
|
|
2923
|
+
whiteSpace: 'pre-wrap',
|
|
2924
|
+
wordBreak: 'break-word',
|
|
2925
|
+
},
|
|
2926
|
+
}, message.text),
|
|
2927
|
+
h('div', {
|
|
2928
|
+
key: 'm',
|
|
2929
|
+
style: { fontSize: 10.5, color: C.label2, display: 'flex', gap: 6, alignItems: 'center' },
|
|
2930
|
+
}, [
|
|
2931
|
+
h('span', { key: 't', style: { fontVariantNumeric: 'tabular-nums' } }, fmtTime(message.ts)),
|
|
2932
|
+
h('span', { key: 'n' }, message.senderName === '' ? message.senderUin : message.senderName),
|
|
2933
|
+
message.aiAuthored
|
|
2934
|
+
? h(Chip, { key: 'ai', color: message.aiAuto ? C.warn : C.brand }, message.aiAuto ? 'AI 自动回复' : 'AI 代笔')
|
|
2935
|
+
: null,
|
|
2936
|
+
]),
|
|
2937
|
+
])))),
|
|
2938
|
+
]) : null,
|
|
2939
|
+
])
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
/** Left rail entry for the "我" tab. */
|
|
2943
|
+
function selfRail() {
|
|
2944
|
+
const profile = state.selfProfile ?? null
|
|
2945
|
+
return rowShell(tab === 'self', () => setTab('self'), [
|
|
2946
|
+
h('span', {
|
|
2947
|
+
key: 'dot',
|
|
2948
|
+
style: { width: 7, height: 7, borderRadius: 999, flex: '0 0 auto', background: C.brand },
|
|
2949
|
+
}),
|
|
2950
|
+
h('span', { key: 'n', style: { flex: 1, minWidth: 0, fontSize: 12.5 } }, '我的综合画像'),
|
|
2951
|
+
h('span', {
|
|
2952
|
+
key: 's',
|
|
2953
|
+
style: { fontSize: 10.5, color: profile === null ? C.label2 : C.success },
|
|
2954
|
+
}, profile === null ? '未分析' : '已有'),
|
|
2955
|
+
])
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
/** One titled bullet list, used by the self analysis panel. */
|
|
2959
|
+
function bulletBlock(title, items, color) {
|
|
2960
|
+
if (!Array.isArray(items) || items.length === 0) return null
|
|
2961
|
+
return h('div', { key: title, style: { display: 'flex', flexDirection: 'column', gap: 3 } }, [
|
|
2962
|
+
h('span', { key: 'l', style: { fontSize: 11.5, color } }, title),
|
|
2963
|
+
h('ul', { key: 'u', style: { margin: 0, paddingLeft: 18, fontSize: 12, lineHeight: 1.85 } },
|
|
2964
|
+
items.map((line, index) => h('li', { key: index }, line))),
|
|
2965
|
+
])
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
/** The "我" tab: a portrait of the user across every enabled conversation. */
|
|
2969
|
+
function selfDetail() {
|
|
2970
|
+
const profile = state.selfProfile ?? null
|
|
2971
|
+
const errorBox = panelError !== null && panelError.where === 'self' ? h('div', {
|
|
2972
|
+
key: 'self-error',
|
|
2973
|
+
style: {
|
|
2974
|
+
background: C.layer1,
|
|
2975
|
+
border: `1px solid ${C.error}`,
|
|
2976
|
+
borderRadius: 10,
|
|
2977
|
+
padding: '10px 12px',
|
|
2978
|
+
fontSize: 11.5,
|
|
2979
|
+
color: C.label,
|
|
2980
|
+
lineHeight: 1.7,
|
|
2981
|
+
whiteSpace: 'pre-wrap',
|
|
2982
|
+
wordBreak: 'break-word',
|
|
2983
|
+
fontFamily: 'ui-monospace, Consolas, monospace',
|
|
2984
|
+
},
|
|
2985
|
+
}, panelError.message) : null
|
|
2986
|
+
|
|
2987
|
+
const header = h(Section, {
|
|
2988
|
+
key: 'self',
|
|
2989
|
+
title: '综合分析:我',
|
|
2990
|
+
extra: [
|
|
2991
|
+
profile === null ? null : h('span', { key: 'c', style: { fontSize: 11, color: C.label2 } },
|
|
2992
|
+
`置信度 ${Math.round((profile.confidence ?? 0) * 100)}%`),
|
|
2993
|
+
h(Btn, {
|
|
2994
|
+
key: 'run',
|
|
2995
|
+
kind: profile === null ? 'primary' : 'outline',
|
|
2996
|
+
disabled: busy === 'self',
|
|
2997
|
+
onClick: () => void analyzeSelfProfile(),
|
|
2998
|
+
}, busy === 'self' ? '正在分析…' : (profile === null ? '分析我自己' : '重新分析')),
|
|
2999
|
+
],
|
|
3000
|
+
}, profile === null
|
|
3001
|
+
? h('div', { style: { fontSize: 12, color: C.label2, lineHeight: 1.85 } },
|
|
3002
|
+
'把你在所有已开启对话里**自己打的字**放在一起分析:说话习惯、优点、容易踩的坑、对不同人的差异,以及一个 MBTI 倾向。AI 代笔和自动回复会被排除。')
|
|
3003
|
+
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 12 } }, [
|
|
3004
|
+
profile.mbti === null || profile.mbti === undefined ? null : mbtiCard(profile.mbti),
|
|
3005
|
+
h('div', {
|
|
3006
|
+
key: 'summary',
|
|
3007
|
+
style: { fontSize: 13.5, color: C.label, lineHeight: 1.75, fontWeight: 600 },
|
|
3008
|
+
}, profile.summary),
|
|
3009
|
+
(profile.tags ?? []).length === 0 ? null : h('div', {
|
|
3010
|
+
key: 'tags',
|
|
3011
|
+
style: { display: 'flex', gap: 5, flexWrap: 'wrap' },
|
|
3012
|
+
}, profile.tags.map((tag, index) => {
|
|
3013
|
+
const color = traitColor(index)
|
|
3014
|
+
return h('span', {
|
|
3015
|
+
key: index,
|
|
3016
|
+
style: {
|
|
3017
|
+
fontSize: 11,
|
|
3018
|
+
lineHeight: 1.5,
|
|
3019
|
+
padding: '2px 7px',
|
|
3020
|
+
borderRadius: 999,
|
|
3021
|
+
color,
|
|
3022
|
+
border: `1px solid ${supportsColorMix ? `color-mix(in oklab, ${color} 45%, transparent)` : color}`,
|
|
3023
|
+
background: tint(color, 12),
|
|
3024
|
+
},
|
|
3025
|
+
}, tag)
|
|
3026
|
+
})),
|
|
3027
|
+
(profile.traits ?? []).length === 0 ? null : h('div', {
|
|
3028
|
+
key: 'traits',
|
|
3029
|
+
style: { display: 'flex', flexDirection: 'column', gap: 7 },
|
|
3030
|
+
}, profile.traits.map((trait, index) => {
|
|
3031
|
+
const color = traitColor(index)
|
|
3032
|
+
const strength = Math.round((trait.strength ?? 0.6) * 100)
|
|
3033
|
+
return h('div', {
|
|
3034
|
+
key: index,
|
|
3035
|
+
style: {
|
|
3036
|
+
background: tint(color, 10),
|
|
3037
|
+
border: `1px solid ${supportsColorMix ? `color-mix(in oklab, ${color} 28%, transparent)` : C.border1}`,
|
|
3038
|
+
borderLeft: `3px solid ${color}`,
|
|
3039
|
+
borderRadius: 8,
|
|
3040
|
+
padding: '8px 10px',
|
|
3041
|
+
display: 'flex',
|
|
3042
|
+
flexDirection: 'column',
|
|
3043
|
+
gap: 4,
|
|
3044
|
+
},
|
|
3045
|
+
}, [
|
|
3046
|
+
h('div', { key: 'top', style: { display: 'flex', alignItems: 'center', gap: 7 } }, [
|
|
3047
|
+
h('span', { key: 'l', style: { fontSize: 12.5, fontWeight: 600, color: C.label } }, trait.label),
|
|
3048
|
+
h('div', {
|
|
3049
|
+
key: 'bar',
|
|
3050
|
+
style: {
|
|
3051
|
+
flex: 1,
|
|
3052
|
+
height: 3,
|
|
3053
|
+
borderRadius: 999,
|
|
3054
|
+
background: supportsColorMix ? `color-mix(in oklab, ${color} 22%, transparent)` : C.border1,
|
|
3055
|
+
overflow: 'hidden',
|
|
3056
|
+
},
|
|
3057
|
+
}, h('div', { style: { width: `${Math.max(6, Math.min(100, strength))}%`, height: '100%', background: color } })),
|
|
3058
|
+
h('span', { key: 'p', style: { fontSize: 10.5, color, fontVariantNumeric: 'tabular-nums' } }, `${strength}`),
|
|
3059
|
+
]),
|
|
3060
|
+
trait.evidence === '' ? null : h('span', {
|
|
3061
|
+
key: 'e',
|
|
3062
|
+
style: { fontSize: 11.5, color: C.label2, lineHeight: 1.7 },
|
|
3063
|
+
}, trait.evidence),
|
|
3064
|
+
])
|
|
3065
|
+
})),
|
|
3066
|
+
(profile.speakingStyle ?? '') === '' ? null : h('div', {
|
|
3067
|
+
key: 'style',
|
|
3068
|
+
style: { fontSize: 12, color: C.label2, lineHeight: 1.75 },
|
|
3069
|
+
}, h('span', { key: 'k', style: { color: C.label } }, '说话风格 '), profile.speakingStyle),
|
|
3070
|
+
h('div', {
|
|
3071
|
+
key: 'lists',
|
|
3072
|
+
style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: 10 },
|
|
3073
|
+
}, [
|
|
3074
|
+
bulletBlock('我的优点', profile.strengths, C.success),
|
|
3075
|
+
bulletBlock('容易踩的坑', profile.blindSpots, C.warn),
|
|
3076
|
+
]),
|
|
3077
|
+
(profile.patternsByPerson ?? []).length === 0 ? null : h('div', {
|
|
3078
|
+
key: 'patterns',
|
|
3079
|
+
style: { display: 'flex', flexDirection: 'column', gap: 5 },
|
|
3080
|
+
}, [
|
|
3081
|
+
h('span', { key: 'l', style: { fontSize: 11.5, color: C.label2 } }, '对不同人的差异'),
|
|
3082
|
+
...profile.patternsByPerson.map((item, index) => h('div', {
|
|
3083
|
+
key: index,
|
|
3084
|
+
style: {
|
|
3085
|
+
background: C.layer1,
|
|
3086
|
+
border: `1px solid ${C.border1}`,
|
|
3087
|
+
borderRadius: 8,
|
|
3088
|
+
padding: '6px 9px',
|
|
3089
|
+
display: 'flex',
|
|
3090
|
+
flexDirection: 'column',
|
|
3091
|
+
gap: 2,
|
|
3092
|
+
},
|
|
3093
|
+
}, [
|
|
3094
|
+
h('span', { key: 'n', style: { fontSize: 12, fontWeight: 600 } }, item.name),
|
|
3095
|
+
h('span', { key: 't', style: { fontSize: 11.5, color: C.label2, lineHeight: 1.7 } }, item.note),
|
|
3096
|
+
])),
|
|
3097
|
+
]),
|
|
3098
|
+
bulletBlock('可以试试', profile.advise, C.brand),
|
|
3099
|
+
h('div', {
|
|
3100
|
+
key: 'based',
|
|
3101
|
+
style: { fontSize: 11, color: C.label2, lineHeight: 1.6 },
|
|
3102
|
+
}, `依据你真实发出的 ${profile.basedOn?.myMessages ?? 0} 条消息(另有 ${profile.basedOn?.excludedAiMessages ?? 0} 条 AI 代笔已排除),更新于 ${fmtTime(profile.updatedAt)}。`),
|
|
3103
|
+
]))
|
|
3104
|
+
|
|
3105
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 12 } }, [errorBox, header])
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
function personDetail(row) {
|
|
3109
|
+
const stored = row.score
|
|
3110
|
+
const persona = row.persona ?? null
|
|
3111
|
+
const name = row.names.length > 0 ? row.names[row.names.length - 1] : `QQ ${row.uin}`
|
|
3112
|
+
|
|
3113
|
+
/** "上次 74,这次 79" — one chip per metric, coloured by direction. */
|
|
3114
|
+
function compareBlock(score) {
|
|
3115
|
+
const history = Array.isArray(score.history) ? score.history : []
|
|
3116
|
+
if (history.length === 0) return null
|
|
3117
|
+
const previous = history[0]
|
|
3118
|
+
const metric = (label, now, prev) => {
|
|
3119
|
+
const delta = now - prev
|
|
3120
|
+
const color = delta > 0 ? C.success : delta < 0 ? C.error : C.label2
|
|
3121
|
+
const arrow = delta > 0 ? '↑' : delta < 0 ? '↓' : '→'
|
|
3122
|
+
return h('span', {
|
|
3123
|
+
key: label,
|
|
3124
|
+
title: `上次(${fmtTime(previous.at) || '更早'}):${prev},现在:${now}`,
|
|
3125
|
+
style: { fontSize: 11, color: C.label2, display: 'inline-flex', alignItems: 'center', gap: 4 },
|
|
3126
|
+
}, [
|
|
3127
|
+
h('span', { key: 'l' }, label),
|
|
3128
|
+
h('span', { key: 'n', style: { color: C.label, fontWeight: 600, fontVariantNumeric: 'tabular-nums' } }, String(now)),
|
|
3129
|
+
h('span', {
|
|
3130
|
+
key: 'd',
|
|
3131
|
+
style: { color, fontVariantNumeric: 'tabular-nums', fontSize: 10.5 },
|
|
3132
|
+
}, `${arrow}${delta > 0 ? '+' : ''}${delta}`),
|
|
3133
|
+
])
|
|
3134
|
+
}
|
|
3135
|
+
const rows = history.slice(0, 6).map((entry, index) => h('div', {
|
|
3136
|
+
key: index,
|
|
3137
|
+
style: {
|
|
3138
|
+
display: 'flex',
|
|
3139
|
+
justifyContent: 'space-between',
|
|
3140
|
+
gap: 8,
|
|
3141
|
+
fontSize: 10.5,
|
|
3142
|
+
color: C.label2,
|
|
3143
|
+
fontVariantNumeric: 'tabular-nums',
|
|
3144
|
+
lineHeight: 1.8,
|
|
3145
|
+
borderBottom: index === history.slice(0, 6).length - 1 ? 'none' : `1px solid ${C.border1}`,
|
|
3146
|
+
},
|
|
3147
|
+
}, [
|
|
3148
|
+
h('span', { key: 't' }, fmtTime(entry.at) || '更早'),
|
|
3149
|
+
h('span', { key: 'v' }, `${entry.theirFavor} · ${entry.myFavor} · ${entry.intimacy}`),
|
|
3150
|
+
h('span', { key: 'c', style: { opacity: 0.75 } }, `置信 ${Math.round(entry.confidence * 100)}%`),
|
|
3151
|
+
]))
|
|
3152
|
+
return h('div', { key: 'compare', style: { display: 'flex', flexDirection: 'column', gap: 8 } }, [
|
|
3153
|
+
h('div', { key: 'now', style: { display: 'flex', gap: 14, flexWrap: 'wrap', alignItems: 'center' } }, [
|
|
3154
|
+
metric('TA 对你', score.theirFavor.score, previous.theirFavor),
|
|
3155
|
+
metric('你对 TA', score.myFavor.score, previous.myFavor),
|
|
3156
|
+
metric('亲密度', score.intimacy.score, previous.intimacy),
|
|
3157
|
+
]),
|
|
3158
|
+
h('div', {
|
|
3159
|
+
key: 'hist',
|
|
3160
|
+
style: {
|
|
3161
|
+
background: C.layer1,
|
|
3162
|
+
border: `1px solid ${C.border1}`,
|
|
3163
|
+
borderRadius: 8,
|
|
3164
|
+
padding: '6px 10px',
|
|
3165
|
+
display: 'flex',
|
|
3166
|
+
flexDirection: 'column',
|
|
3167
|
+
gap: 1,
|
|
3168
|
+
},
|
|
3169
|
+
}, [
|
|
3170
|
+
h('span', { key: 'h', style: { fontSize: 10.5, color: C.label2, marginBottom: 3 } }, '最近几次的分数'),
|
|
3171
|
+
...rows,
|
|
3172
|
+
]),
|
|
3173
|
+
])
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
const reasonCard = (title, reasons) => h(Section, { key: title, title }, (reasons ?? []).length === 0
|
|
3177
|
+
? h('div', { key: 'none', style: { fontSize: 12, color: C.label2 } }, '模型没有给出理由。')
|
|
3178
|
+
: h('ul', {
|
|
3179
|
+
key: 'list',
|
|
3180
|
+
style: { margin: 0, paddingLeft: 18, fontSize: 12, color: C.label2, lineHeight: 1.85 },
|
|
3181
|
+
}, reasons.map((line, index) => h('li', { key: index }, line))))
|
|
3182
|
+
|
|
3183
|
+
const stat = (label, value) => h('div', {
|
|
3184
|
+
key: label,
|
|
3185
|
+
style: {
|
|
3186
|
+
background: C.bg,
|
|
3187
|
+
border: `1px solid ${C.border1}`,
|
|
3188
|
+
borderRadius: 8,
|
|
3189
|
+
padding: '8px 10px',
|
|
3190
|
+
display: 'flex',
|
|
3191
|
+
flexDirection: 'column',
|
|
3192
|
+
gap: 2,
|
|
3193
|
+
},
|
|
3194
|
+
}, [
|
|
3195
|
+
h('span', { key: 'v', style: { fontSize: 15, fontWeight: 600, fontVariantNumeric: 'tabular-nums' } }, value),
|
|
3196
|
+
h('span', { key: 'l', style: { fontSize: 11, color: C.label2 } }, label),
|
|
3197
|
+
])
|
|
3198
|
+
|
|
3199
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 14, paddingBottom: 28, maxWidth: 1000 } }, [
|
|
3200
|
+
h('div', { key: 'head', style: { display: 'flex', alignItems: 'flex-start', gap: 12, flexWrap: 'wrap' } }, [
|
|
3201
|
+
h('div', { key: 'id', style: { flex: 1, minWidth: 210, display: 'flex', flexDirection: 'column', gap: 5 } }, [
|
|
3202
|
+
h('h2', { key: 'n', style: { margin: 0, fontSize: 17, fontWeight: 600, display: 'flex', alignItems: 'center', gap: 8 } }, [
|
|
3203
|
+
h('span', { key: 't' }, name),
|
|
3204
|
+
h(Chip, {
|
|
3205
|
+
key: 'o',
|
|
3206
|
+
color: row.origin === 'group' ? C.success : C.brand,
|
|
3207
|
+
}, row.origin === 'group' ? '群聊里出现' : '手动添加'),
|
|
3208
|
+
]),
|
|
3209
|
+
h('div', { key: 'm', style: { fontSize: 11.5, color: C.label2, display: 'flex', gap: 12, flexWrap: 'wrap' } }, [
|
|
3210
|
+
h('span', { key: 'q' }, `QQ ${row.uin}`),
|
|
3211
|
+
row.remark === '' || row.remark === undefined ? null : h('span', { key: 'r' }, `备注 ${row.remark}`),
|
|
3212
|
+
h('span', { key: 'c' }, `${row.messageRows} 条参与计算的记录`),
|
|
3213
|
+
h('span', { key: 'k' }, `${(row.contributingConversations ?? []).length} 个已开启的对话`),
|
|
3214
|
+
h('span', { key: 'u' }, `更新于 ${stored === null ? '—' : fmtTime(stored.updatedAt)}`),
|
|
3215
|
+
]),
|
|
3216
|
+
]),
|
|
3217
|
+
h(Btn, {
|
|
3218
|
+
key: 'run',
|
|
3219
|
+
kind: 'primary',
|
|
3220
|
+
disabled: busy === `score:${row.uin}`,
|
|
3221
|
+
onClick: () => void scorePerson(row.uin),
|
|
3222
|
+
}, busy === `score:${row.uin}` ? '正在分析…' : (stored === null ? '开始分析' : '重新分析')),
|
|
3223
|
+
]),
|
|
3224
|
+
|
|
3225
|
+
panelError !== null && panelError.where === `score:${row.uin}` ? h('div', {
|
|
3226
|
+
key: 'score-error',
|
|
3227
|
+
style: {
|
|
3228
|
+
background: C.layer1,
|
|
3229
|
+
border: `1px solid ${C.error}`,
|
|
3230
|
+
borderRadius: 10,
|
|
3231
|
+
padding: '10px 12px',
|
|
3232
|
+
display: 'flex',
|
|
3233
|
+
flexDirection: 'column',
|
|
3234
|
+
gap: 6,
|
|
3235
|
+
},
|
|
3236
|
+
}, [
|
|
3237
|
+
h('div', { key: 't', style: { fontSize: 12, fontWeight: 600, color: C.error } }, '分析没有完成'),
|
|
3238
|
+
h('div', {
|
|
3239
|
+
key: 'm',
|
|
3240
|
+
style: {
|
|
3241
|
+
fontSize: 11.5,
|
|
3242
|
+
color: C.label,
|
|
3243
|
+
lineHeight: 1.7,
|
|
3244
|
+
whiteSpace: 'pre-wrap',
|
|
3245
|
+
wordBreak: 'break-word',
|
|
3246
|
+
fontFamily: 'ui-monospace, Consolas, monospace',
|
|
3247
|
+
},
|
|
3248
|
+
}, panelError.message),
|
|
3249
|
+
h('div', { key: 'h', style: { fontSize: 11, color: C.label2, lineHeight: 1.6 } },
|
|
3250
|
+
'这段是插件后台返回的原始原因。常见是模型调用失败(额度/登录/网络),把这段发我就能定位。'),
|
|
3251
|
+
]) : null,
|
|
3252
|
+
|
|
3253
|
+
stored !== null && stored.stale === true ? h('div', {
|
|
3254
|
+
key: 'stale',
|
|
3255
|
+
style: {
|
|
3256
|
+
background: C.layer1,
|
|
3257
|
+
border: `1px solid ${C.warn}`,
|
|
3258
|
+
borderRadius: 10,
|
|
3259
|
+
padding: '10px 12px',
|
|
3260
|
+
fontSize: 12,
|
|
3261
|
+
color: C.label,
|
|
3262
|
+
lineHeight: 1.75,
|
|
3263
|
+
},
|
|
3264
|
+
}, [h('strong', { key: 'a', style: { color: C.warn } }, '记录已经变化。'),
|
|
3265
|
+
' 下面这组分数是之前算出来的,导入新记录或开关对话之后建议重新分析。']) : null,
|
|
3266
|
+
|
|
3267
|
+
stored === null
|
|
3268
|
+
? h('div', {
|
|
3269
|
+
key: 'none',
|
|
3270
|
+
style: {
|
|
3271
|
+
background: C.layer1,
|
|
3272
|
+
border: `1px dashed ${C.border2}`,
|
|
3273
|
+
borderRadius: 10,
|
|
3274
|
+
padding: 16,
|
|
3275
|
+
fontSize: 12,
|
|
3276
|
+
color: C.label2,
|
|
3277
|
+
lineHeight: 1.85,
|
|
3278
|
+
},
|
|
3279
|
+
}, '还没有对这个人做过分析。分析会读取所有已开启对话里与 TA 相关的记录,调用一次模型,然后把三项分数保存在本地。')
|
|
3280
|
+
: null,
|
|
3281
|
+
|
|
3282
|
+
stored === null ? null : h('div', {
|
|
3283
|
+
key: 'meters',
|
|
3284
|
+
style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(210px, 1fr))', gap: 12 },
|
|
3285
|
+
}, [
|
|
3286
|
+
h(Section, { key: 'their', title: 'TA 对你的好感度' }, h(Meter, {
|
|
3287
|
+
label: '满分 100',
|
|
3288
|
+
ariaLabel: 'TA 对你的好感度',
|
|
3289
|
+
value: stored.theirFavor.score,
|
|
3290
|
+
})),
|
|
3291
|
+
h(Section, { key: 'mine', title: '你对 TA 的好感度' }, h(Meter, {
|
|
3292
|
+
label: '满分 100',
|
|
3293
|
+
ariaLabel: '你对 TA 的好感度',
|
|
3294
|
+
value: stored.myFavor.score,
|
|
3295
|
+
})),
|
|
3296
|
+
h(Section, { key: 'intim', title: '你们的亲密度' }, h(Meter, {
|
|
3297
|
+
label: '满分 100',
|
|
3298
|
+
ariaLabel: '你们的亲密度',
|
|
3299
|
+
value: stored.intimacy.score,
|
|
3300
|
+
})),
|
|
3301
|
+
]),
|
|
3302
|
+
|
|
3303
|
+
stored === null ? null : h('div', {
|
|
3304
|
+
key: 'legend',
|
|
3305
|
+
style: { display: 'flex', alignItems: 'center', gap: 8, padding: '0 2px' },
|
|
3306
|
+
}, [
|
|
3307
|
+
h('span', { key: 'l', style: { fontSize: 10.5, color: C.label2, whiteSpace: 'nowrap' } }, '0 低'),
|
|
3308
|
+
h('div', {
|
|
3309
|
+
key: 'bar',
|
|
3310
|
+
'aria-hidden': true,
|
|
3311
|
+
style: { flex: 1, display: 'flex', height: 6, borderRadius: 999, overflow: 'hidden' },
|
|
3312
|
+
}, [...BANDS].reverse().map(([, color], index) => h('div', {
|
|
3313
|
+
key: index,
|
|
3314
|
+
style: { flex: 1, background: color() },
|
|
3315
|
+
}))),
|
|
3316
|
+
h('span', { key: 'r', style: { fontSize: 10.5, color: C.label2, whiteSpace: 'nowrap' } }, '高 100'),
|
|
3317
|
+
]),
|
|
3318
|
+
|
|
3319
|
+
stored === null ? null : compareBlock(stored),
|
|
3320
|
+
|
|
3321
|
+
stored === null ? null : h('div', {
|
|
3322
|
+
key: 'reasons',
|
|
3323
|
+
style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(260px, 1fr))', gap: 12 },
|
|
3324
|
+
}, [
|
|
3325
|
+
reasonCard('TA 对你的好感度', stored.theirFavor.reasons),
|
|
3326
|
+
reasonCard('你对 TA 的好感度', stored.myFavor.reasons),
|
|
3327
|
+
reasonCard('你们的亲密度', stored.intimacy.reasons),
|
|
3328
|
+
]),
|
|
3329
|
+
|
|
3330
|
+
stored === null ? null : h(Section, {
|
|
3331
|
+
key: 'based',
|
|
3332
|
+
title: '计算依据',
|
|
3333
|
+
extra: h(Chip, { key: 'c', mono: true }, `置信度 ${Math.round((stored.confidence ?? 0) * 100)}%`),
|
|
3334
|
+
}, [
|
|
3335
|
+
h('div', {
|
|
3336
|
+
key: 'grid',
|
|
3337
|
+
style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(140px, 1fr))', gap: 8, fontSize: 12 },
|
|
3338
|
+
}, [
|
|
3339
|
+
stat('参与计算消息', String(stored.basedOn?.totalMessages ?? 0)),
|
|
3340
|
+
stat('我的真实表达', String(stored.basedOn?.myAuthenticMessages ?? 0)),
|
|
3341
|
+
stat('AI 代笔(已排除)', String(stored.basedOn?.aiAdoptedMessages ?? 0)),
|
|
3342
|
+
stat('使用的对话', `${(stored.basedOn?.conversations ?? []).length} 个`),
|
|
3343
|
+
]),
|
|
3344
|
+
(stored.signals ?? []).length === 0 ? null : h('ul', {
|
|
3345
|
+
key: 'signals',
|
|
3346
|
+
style: { margin: 0, paddingLeft: 18, fontSize: 12, color: C.label2, lineHeight: 1.9 },
|
|
3347
|
+
}, stored.signals.map((line, index) => h('li', { key: index }, line))),
|
|
3348
|
+
]),
|
|
3349
|
+
|
|
3350
|
+
panelError !== null && panelError.where === `persona:${row.uin}` ? h('div', {
|
|
3351
|
+
key: 'persona-error',
|
|
3352
|
+
style: {
|
|
3353
|
+
background: C.layer1,
|
|
3354
|
+
border: `1px solid ${C.error}`,
|
|
3355
|
+
borderRadius: 10,
|
|
3356
|
+
padding: '10px 12px',
|
|
3357
|
+
fontSize: 11.5,
|
|
3358
|
+
color: C.label,
|
|
3359
|
+
lineHeight: 1.7,
|
|
3360
|
+
whiteSpace: 'pre-wrap',
|
|
3361
|
+
wordBreak: 'break-word',
|
|
3362
|
+
fontFamily: 'ui-monospace, Consolas, monospace',
|
|
3363
|
+
},
|
|
3364
|
+
}, panelError.message) : null,
|
|
3365
|
+
|
|
3366
|
+
h(Section, {
|
|
3367
|
+
key: 'persona',
|
|
3368
|
+
title: 'TA 是个什么样的人',
|
|
3369
|
+
extra: [
|
|
3370
|
+
row.persona === null ? null : h('span', {
|
|
3371
|
+
key: 'c',
|
|
3372
|
+
style: { fontSize: 11, color: C.label2 },
|
|
3373
|
+
}, `置信度 ${Math.round((row.persona.confidence ?? 0) * 100)}%`),
|
|
3374
|
+
h(Btn, {
|
|
3375
|
+
key: 'run',
|
|
3376
|
+
kind: row.persona === null ? 'primary' : 'outline',
|
|
3377
|
+
disabled: busy === `persona:${row.uin}`,
|
|
3378
|
+
onClick: () => void analyzePersonaRow(row.uin),
|
|
3379
|
+
}, busy === `persona:${row.uin}` ? '正在分析…' : (row.persona === null ? '分析 TA 的人格' : '重新分析')),
|
|
3380
|
+
],
|
|
3381
|
+
}, row.persona === null
|
|
3382
|
+
? h('div', { style: { fontSize: 12, color: C.label2, lineHeight: 1.85 } },
|
|
3383
|
+
'还没有画像。分析会只读「TA 自己说的话」和说话习惯,输出 MBTI 倾向、性格标签、说话风格、关系模式、兴趣、怎么聊更顺、以及雷区;每条判断都会带证据。')
|
|
3384
|
+
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 12 } }, [
|
|
3385
|
+
persona.mbti === null || persona.mbti === undefined ? null : mbtiCard(persona.mbti),
|
|
3386
|
+
h('div', {
|
|
3387
|
+
key: 'summary',
|
|
3388
|
+
style: { fontSize: 13.5, color: C.label, lineHeight: 1.75, fontWeight: 600 },
|
|
3389
|
+
}, persona.summary),
|
|
3390
|
+
(persona.tags ?? []).length === 0 ? null : h('div', {
|
|
3391
|
+
key: 'tags',
|
|
3392
|
+
style: { display: 'flex', gap: 5, flexWrap: 'wrap' },
|
|
3393
|
+
}, persona.tags.map((tag, index) => {
|
|
3394
|
+
const color = traitColor(index)
|
|
3395
|
+
return h('span', {
|
|
3396
|
+
key: index,
|
|
3397
|
+
style: {
|
|
3398
|
+
fontSize: 11,
|
|
3399
|
+
lineHeight: 1.5,
|
|
3400
|
+
padding: '2px 7px',
|
|
3401
|
+
borderRadius: 999,
|
|
3402
|
+
color,
|
|
3403
|
+
border: `1px solid ${supportsColorMix ? `color-mix(in oklab, ${color} 45%, transparent)` : color}`,
|
|
3404
|
+
background: tint(color, 12),
|
|
3405
|
+
fontWeight: 500,
|
|
3406
|
+
},
|
|
3407
|
+
}, tag)
|
|
3408
|
+
})),
|
|
3409
|
+
(persona.traits ?? []).length === 0 ? null : h('div', {
|
|
3410
|
+
key: 'traits',
|
|
3411
|
+
style: { display: 'flex', flexDirection: 'column', gap: 7 },
|
|
3412
|
+
}, persona.traits.map((trait, index) => {
|
|
3413
|
+
const color = traitColor(index)
|
|
3414
|
+
const strength = Math.round((trait.strength ?? 0.6) * 100)
|
|
3415
|
+
return h('div', {
|
|
3416
|
+
key: index,
|
|
3417
|
+
style: {
|
|
3418
|
+
background: tint(color, 10),
|
|
3419
|
+
border: `1px solid ${supportsColorMix ? `color-mix(in oklab, ${color} 28%, transparent)` : C.border1}`,
|
|
3420
|
+
borderLeft: `3px solid ${color}`,
|
|
3421
|
+
borderRadius: 8,
|
|
3422
|
+
padding: '8px 10px',
|
|
3423
|
+
display: 'flex',
|
|
3424
|
+
flexDirection: 'column',
|
|
3425
|
+
gap: 4,
|
|
3426
|
+
},
|
|
3427
|
+
}, [
|
|
3428
|
+
h('div', { key: 'top', style: { display: 'flex', alignItems: 'center', gap: 7 } }, [
|
|
3429
|
+
h('span', { key: 'l', style: { fontSize: 12.5, fontWeight: 600, color: C.label } }, trait.label),
|
|
3430
|
+
h('div', {
|
|
3431
|
+
key: 'bar',
|
|
3432
|
+
style: {
|
|
3433
|
+
flex: 1,
|
|
3434
|
+
height: 3,
|
|
3435
|
+
borderRadius: 999,
|
|
3436
|
+
background: supportsColorMix ? `color-mix(in oklab, ${color} 22%, transparent)` : C.border1,
|
|
3437
|
+
overflow: 'hidden',
|
|
3438
|
+
},
|
|
3439
|
+
}, h('div', {
|
|
3440
|
+
style: { width: `${Math.max(6, Math.min(100, strength))}%`, height: '100%', background: color },
|
|
3441
|
+
})),
|
|
3442
|
+
h('span', {
|
|
3443
|
+
key: 'p',
|
|
3444
|
+
title: '这个特点有多突出(模型判断)',
|
|
3445
|
+
style: { fontSize: 10.5, color, fontVariantNumeric: 'tabular-nums' },
|
|
3446
|
+
}, `${strength}`),
|
|
3447
|
+
]),
|
|
3448
|
+
trait.evidence === '' ? null : h('span', {
|
|
3449
|
+
key: 'e',
|
|
3450
|
+
style: { fontSize: 11.5, color: C.label2, lineHeight: 1.7 },
|
|
3451
|
+
}, trait.evidence),
|
|
3452
|
+
])
|
|
3453
|
+
})),
|
|
3454
|
+
persona.speakingStyle === '' && (persona.relationshipStyle ?? '') === '' ? null : h('div', {
|
|
3455
|
+
key: 'style',
|
|
3456
|
+
style: { display: 'flex', flexDirection: 'column', gap: 4 },
|
|
3457
|
+
}, [
|
|
3458
|
+
persona.speakingStyle === '' ? null : h('div', { key: 's', style: { fontSize: 12, color: C.label2, lineHeight: 1.75 } },
|
|
3459
|
+
h('span', { key: 'k', style: { color: C.label } }, '说话风格 '), persona.speakingStyle),
|
|
3460
|
+
(persona.relationshipStyle ?? '') === '' ? null : h('div', { key: 'r', style: { fontSize: 12, color: C.label2, lineHeight: 1.75 } },
|
|
3461
|
+
h('span', { key: 'k', style: { color: C.label } }, '关系模式 '), persona.relationshipStyle),
|
|
3462
|
+
]),
|
|
3463
|
+
(persona.interests ?? []).length === 0 ? null : h('div', {
|
|
3464
|
+
key: 'interests',
|
|
3465
|
+
style: { display: 'flex', gap: 6, flexWrap: 'wrap', alignItems: 'center' },
|
|
3466
|
+
}, [
|
|
3467
|
+
h('span', { key: 'l', style: { fontSize: 11.5, color: C.label2 } }, '提到过的兴趣'),
|
|
3468
|
+
...persona.interests.map((item, index) => h(Chip, { key: index }, item)),
|
|
3469
|
+
]),
|
|
3470
|
+
(persona.howToTalk ?? []).length === 0 ? null : h('div', { key: 'how', style: { display: 'flex', flexDirection: 'column', gap: 3 } }, [
|
|
3471
|
+
h('span', { key: 'l', style: { fontSize: 11.5, color: C.success } }, '怎么聊更顺'),
|
|
3472
|
+
h('ul', { key: 'u', style: { margin: 0, paddingLeft: 18, fontSize: 12, lineHeight: 1.85 } },
|
|
3473
|
+
persona.howToTalk.map((line, index) => h('li', { key: index }, line))),
|
|
3474
|
+
]),
|
|
3475
|
+
(persona.avoid ?? []).length === 0 ? null : h('div', { key: 'avoid', style: { display: 'flex', flexDirection: 'column', gap: 3 } }, [
|
|
3476
|
+
h('span', { key: 'l', style: { fontSize: 11.5, color: C.warn } }, '雷区'),
|
|
3477
|
+
h('ul', { key: 'u', style: { margin: 0, paddingLeft: 18, fontSize: 12, lineHeight: 1.85, color: C.label2 } },
|
|
3478
|
+
persona.avoid.map((line, index) => h('li', { key: index }, line))),
|
|
3479
|
+
]),
|
|
3480
|
+
h('div', {
|
|
3481
|
+
key: 'based',
|
|
3482
|
+
style: { fontSize: 11, color: C.label2, lineHeight: 1.6 },
|
|
3483
|
+
}, `依据 TA 的 ${persona.basedOn?.theirMessages ?? 0} 条消息,更新于 ${fmtTime(persona.updatedAt)}。这是从文字里读出来的印象,不是判决。`),
|
|
3484
|
+
])),
|
|
3485
|
+
|
|
3486
|
+
h(Section, {
|
|
3487
|
+
key: 'care',
|
|
3488
|
+
title: '智能托管',
|
|
3489
|
+
extra: row.care.enabled
|
|
3490
|
+
? h(Chip, { key: 'on', color: row.care.mode === 'auto' ? C.success : C.brand }, row.care.mode === 'auto' ? '自动发送' : '待我确认')
|
|
3491
|
+
: h(Chip, { key: 'off', color: C.idle }, '未开启'),
|
|
3492
|
+
}, h(CarePanel, {
|
|
3493
|
+
person: row,
|
|
3494
|
+
channel: state.channel,
|
|
3495
|
+
careEnabled,
|
|
3496
|
+
busy: busy === `care:${row.uin}`,
|
|
3497
|
+
usage: state.careUsage?.[row.uin],
|
|
3498
|
+
onChange: (patch) => void setCare(row.uin, patch),
|
|
3499
|
+
})),
|
|
3500
|
+
|
|
3501
|
+
h(Section, { key: 'care-log', title: '这个人的自动回复记录' }, h(OutboxList, {
|
|
3502
|
+
rows: personOutbox,
|
|
3503
|
+
busy: busy !== '',
|
|
3504
|
+
onApprove: (id) => void outboxAction(id, 'approve'),
|
|
3505
|
+
onCancel: (id) => void outboxAction(id, 'cancel'),
|
|
3506
|
+
nameOf: () => name,
|
|
3507
|
+
})),
|
|
3508
|
+
])
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
|
|
3512
|
+
/** The sidebar entry mark, drawn at whatever size the row asks for. */
|
|
3513
|
+
function PanelIcon(props) {
|
|
3514
|
+
const size = typeof props.size === 'number' && props.size > 0 ? props.size : 16
|
|
3515
|
+
const active = props.active === true
|
|
3516
|
+
return h('svg', {
|
|
3517
|
+
viewBox: '0 0 24 24',
|
|
3518
|
+
width: size,
|
|
3519
|
+
height: size,
|
|
3520
|
+
role: 'img',
|
|
3521
|
+
'aria-hidden': true,
|
|
3522
|
+
style: { display: 'block', flex: '0 0 auto', opacity: active ? 1 : 0.78 },
|
|
3523
|
+
}, [
|
|
3524
|
+
h('path', {
|
|
3525
|
+
key: 'heart',
|
|
3526
|
+
d: 'M12 20.6c-.5 0-1-.2-1.4-.5C6.2 16.7 3 13.4 3 9.9 3 7 5.2 4.7 8 4.7c1.6 0 3 .7 4 1.9 1-1.2 2.4-1.9 4-1.9 2.8 0 5 2.3 5 5.2 0 3.5-3.2 6.8-7.6 10.2-.4.3-.9.5-1.4.5Z',
|
|
3527
|
+
fill: active ? 'var(--dsw-alias-brand-primary, #2f6fed)' : 'var(--dsw-alias-label-secondary, #6b7280)',
|
|
3528
|
+
}),
|
|
3529
|
+
h('circle', { key: 'a', cx: 9, cy: 10.6, r: 1.1, fill: 'var(--dsw-alias-bg-base, #fff)' }),
|
|
3530
|
+
h('circle', { key: 'b', cx: 15, cy: 10.6, r: 1.1, fill: 'var(--dsw-alias-bg-base, #fff)' }),
|
|
3531
|
+
])
|
|
3532
|
+
}
|
|
3533
|
+
|
|
3534
|
+
return {
|
|
3535
|
+
inject: ['slots'],
|
|
3536
|
+
apply(ctx) {
|
|
3537
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
3538
|
+
name: 'sidebar.panellist',
|
|
3539
|
+
id: 'qq-affinity',
|
|
3540
|
+
order: 30,
|
|
3541
|
+
label: 'QQ 好感度',
|
|
3542
|
+
}, PanelIcon))
|
|
3543
|
+
ctx.slots.inject('main', () => ctx.slots.register({
|
|
3544
|
+
name: 'main',
|
|
3545
|
+
key: 'qq-affinity',
|
|
3546
|
+
}, PanelRoot))
|
|
3547
|
+
},
|
|
3548
|
+
}
|
|
3549
|
+
},
|
|
3550
|
+
})
|