dsh-skillpie-mail 0.1.0 → 0.1.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 +33 -22
- package/docs/screenshots/add-mailbox.webp +0 -0
- package/docs/screenshots/inbox.webp +0 -0
- package/lib/client.js +536 -147
- package/lib/imap.js +34 -17
- package/lib/index.js +42 -2
- package/lib/store.js +79 -6
- package/package.json +5 -3
- package/screenshots.json +4 -0
package/lib/client.js
CHANGED
|
@@ -20,7 +20,7 @@ window.__ModuleLoader__.load({
|
|
|
20
20
|
var API = '/dsh-skillpie-mail/api'
|
|
21
21
|
|
|
22
22
|
var zh = {
|
|
23
|
-
title: 'SkillPie
|
|
23
|
+
title: 'SkillPie收件箱',
|
|
24
24
|
sectionDesc: '管理 @skillpie.cn 邮箱;收到新邮件时全局弹窗提醒。',
|
|
25
25
|
quickRegister: '快速注册',
|
|
26
26
|
registerTitle: '快速注册邮箱',
|
|
@@ -34,17 +34,24 @@ window.__ModuleLoader__.load({
|
|
|
34
34
|
registerPwd: '应用密码 (IMAP 登录用)',
|
|
35
35
|
registerDone: '已自动加入下方列表, 无需再手动添加',
|
|
36
36
|
add: '添加邮箱',
|
|
37
|
-
addTitle: '
|
|
37
|
+
addTitle: '添加邮箱',
|
|
38
|
+
mergeHint: '已有邮箱填密码直接添加;新用户名自动注册,登录密码为系统自动生成的应用密码(Stalwart 不支持自设账号密码)。',
|
|
38
39
|
email: '邮箱地址',
|
|
39
40
|
password: '密码',
|
|
40
|
-
appPasswordLabel: '应用密码',
|
|
41
|
-
appPasswordTip: '
|
|
41
|
+
appPasswordLabel: '密码 / 应用密码',
|
|
42
|
+
appPasswordTip: '已有账号: 填它的应用密码 (app_ 开头) 直接添加; 老账号可在 mail.skillpie.cn/admin 签发。',
|
|
42
43
|
addOk: '添加',
|
|
43
44
|
remove: '移除',
|
|
44
|
-
empty: '
|
|
45
|
+
empty: '还没有邮箱,点「添加邮箱」。',
|
|
45
46
|
mailboxCount: '共 {n} 个邮箱',
|
|
46
47
|
newMail: '新邮件',
|
|
47
48
|
close: '关闭',
|
|
49
|
+
clearAll: '清空',
|
|
50
|
+
markAllRead: '全部已读',
|
|
51
|
+
prevMail: '上一封',
|
|
52
|
+
del: '删除',
|
|
53
|
+
nextMail: '下一封',
|
|
54
|
+
back: '返回',
|
|
48
55
|
inbox: '收件箱',
|
|
49
56
|
inboxAll: '全部邮箱',
|
|
50
57
|
inboxEmpty: '还没有收过邮件',
|
|
@@ -82,6 +89,12 @@ window.__ModuleLoader__.load({
|
|
|
82
89
|
mailboxCount: '{n} mailbox(es)',
|
|
83
90
|
newMail: 'New mail',
|
|
84
91
|
close: 'Close',
|
|
92
|
+
back: 'Back',
|
|
93
|
+
del: 'Delete',
|
|
94
|
+
prevMail: 'Prev',
|
|
95
|
+
nextMail: 'Next',
|
|
96
|
+
markAllRead: 'Mark all read',
|
|
97
|
+
clearAll: 'Clear',
|
|
85
98
|
inbox: 'Inbox',
|
|
86
99
|
inboxAll: 'All mailboxes',
|
|
87
100
|
inboxEmpty: 'No mail received yet',
|
|
@@ -183,6 +196,14 @@ window.__ModuleLoader__.load({
|
|
|
183
196
|
|
|
184
197
|
var MAIL_SUFFIX = '@skillpie.cn'
|
|
185
198
|
|
|
199
|
+
function fmtTime(iso) {
|
|
200
|
+
if (!iso) return ''
|
|
201
|
+
var d = new Date(iso)
|
|
202
|
+
if (isNaN(d.getTime())) return ''
|
|
203
|
+
var p = function (n) { return n < 10 ? '0' + n : '' + n }
|
|
204
|
+
return p(d.getMonth() + 1) + '/' + p(d.getDate()) + ' ' + p(d.getHours()) + ':' + p(d.getMinutes())
|
|
205
|
+
}
|
|
206
|
+
|
|
186
207
|
function RegisterDialog(props) {
|
|
187
208
|
var t = props.t
|
|
188
209
|
var usernameState = React.useState('')
|
|
@@ -271,66 +292,86 @@ window.__ModuleLoader__.load({
|
|
|
271
292
|
var t = props.t
|
|
272
293
|
var emailState = React.useState('')
|
|
273
294
|
var passwordState = React.useState('')
|
|
295
|
+
var noteState = React.useState('')
|
|
274
296
|
var busyState = React.useState(false)
|
|
275
297
|
var errorState = React.useState('')
|
|
298
|
+
var resultState = React.useState(null)
|
|
299
|
+
var copiedState = React.useState('')
|
|
300
|
+
|
|
301
|
+
var copy = function (text, tag) {
|
|
302
|
+
navigator.clipboard.writeText(text).then(function () {
|
|
303
|
+
copiedState[1](tag)
|
|
304
|
+
window.setTimeout(function () { copiedState[1]('') }, 1500)
|
|
305
|
+
}).catch(function () {})
|
|
306
|
+
}
|
|
276
307
|
|
|
277
308
|
var submit = function () {
|
|
278
309
|
if (busyState[0]) return
|
|
279
310
|
busyState[1](true)
|
|
280
311
|
errorState[1]('')
|
|
281
|
-
// 支持 @skillpie.cn 前缀简写(自动补全)或任意完整邮箱地址
|
|
282
312
|
var prefix = emailState[0].trim()
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
.then(function () {
|
|
313
|
+
api('addOrRegister', { username: prefix, note: noteState[0], password: passwordState[0] })
|
|
314
|
+
.then(function (data) {
|
|
286
315
|
props.onChanged()
|
|
287
|
-
|
|
316
|
+
if (data.mode === 'registered') resultState[1]({ address: data.address, appPassword: data.appPassword })
|
|
317
|
+
else props.onClose()
|
|
288
318
|
})
|
|
289
319
|
.catch(function (error) { errorState[1](error.message) })
|
|
290
320
|
.finally(function () { busyState[1](false) })
|
|
291
321
|
}
|
|
292
322
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
323
|
+
var result = resultState[0]
|
|
324
|
+
return h(Modal, { title: result ? t('registerOk') : t('addTitle'), onClose: props.onClose },
|
|
325
|
+
result
|
|
326
|
+
? [
|
|
327
|
+
h('div', { key: 'addr', style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
328
|
+
h('span', { style: labelStyle }, t('registerResult')),
|
|
329
|
+
h('div', { style: { display: 'flex', gap: 6 } },
|
|
330
|
+
h('code', { style: { flex: 1, fontSize: 13, fontWeight: 600 } }, result.address),
|
|
331
|
+
h('button', { type: 'button', style: btnStyle, onClick: function () { copy(result.address, 'addr') } },
|
|
332
|
+
copiedState[0] === 'addr' ? t('copied') : t('copy')),
|
|
333
|
+
),
|
|
334
|
+
),
|
|
335
|
+
h('div', { key: 'pwd', style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
336
|
+
h('span', { style: labelStyle }, t('registerPwd')),
|
|
337
|
+
h('div', { style: { display: 'flex', gap: 6 } },
|
|
338
|
+
h('code', { style: { flex: 1, fontSize: 12, wordBreak: 'break-all' } }, result.appPassword),
|
|
339
|
+
h('button', { type: 'button', style: btnStyle, onClick: function () { copy(result.appPassword, 'pwd') } },
|
|
340
|
+
copiedState[0] === 'pwd' ? t('copied') : t('copy')),
|
|
341
|
+
),
|
|
342
|
+
),
|
|
343
|
+
h('div', { key: 'hint', style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, t('registerDone')),
|
|
344
|
+
]
|
|
345
|
+
: [
|
|
346
|
+
h('label', { key: 'u', style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
347
|
+
h('span', { style: labelStyle }, t('registerUser')),
|
|
348
|
+
h('div', {
|
|
349
|
+
style: {
|
|
350
|
+
display: 'flex', alignItems: 'center', height: 28, borderRadius: 7,
|
|
351
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
352
|
+
background: 'var(--dsw-alias-bg-layer-1)', overflow: 'hidden',
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
h('input', {
|
|
356
|
+
style: Object.assign({}, inputStyle, { border: 'none', borderRadius: 0, flex: 1, height: '100%' }),
|
|
357
|
+
value: emailState[0], placeholder: 'taobao01',
|
|
358
|
+
onChange: function (event) { emailState[1](event.target.value.replace(/@.*$/, '')) },
|
|
359
|
+
}),
|
|
360
|
+
h('span', {
|
|
361
|
+
style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', padding: '0 8px', userSelect: 'none', flex: 'none' },
|
|
362
|
+
}, MAIL_SUFFIX),
|
|
363
|
+
),
|
|
364
|
+
),
|
|
365
|
+
h(Field, { key: 'n', label: t('registerNote'), value: noteState[0], placeholder: t('registerNotePh'), onChange: noteState[1] }),
|
|
366
|
+
h(Field, { key: 'p', label: t('appPasswordLabel') + '(选填)', value: passwordState[0], onChange: passwordState[1], placeholder: t('appPasswordTip') }),
|
|
367
|
+
h('div', { key: 'hint2', style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, t('mergeHint')),
|
|
368
|
+
errorState[0] ? h('div', { key: 'e', style: { fontSize: 12, color: '#e5484d' } }, errorState[0]) : null,
|
|
369
|
+
h('div', { key: 'b', style: { display: 'flex', justifyContent: 'flex-end', gap: 8 } },
|
|
370
|
+
h('button', { type: 'button', style: btnStyle, onClick: props.onClose }, t('close')),
|
|
371
|
+
h('button', { type: 'button', style: btnPrimaryStyle, disabled: busyState[0], onClick: submit },
|
|
372
|
+
busyState[0] ? t('loading') : t('addOk')),
|
|
373
|
+
),
|
|
374
|
+
],
|
|
334
375
|
)
|
|
335
376
|
}
|
|
336
377
|
|
|
@@ -339,71 +380,274 @@ window.__ModuleLoader__.load({
|
|
|
339
380
|
var listState = React.useState(null) // null=加载中
|
|
340
381
|
var mailboxes = listState[0]
|
|
341
382
|
var setMailboxes = listState[1]
|
|
342
|
-
var
|
|
383
|
+
var selState = React.useState('') // ''=全部邮箱
|
|
384
|
+
var selected = selState[0]
|
|
385
|
+
var setSelected = selState[1]
|
|
386
|
+
var msgState = React.useState(null)
|
|
387
|
+
var messages = msgState[0]
|
|
388
|
+
var setMessages = msgState[1]
|
|
389
|
+
var openState = React.useState(null)
|
|
390
|
+
var opened = openState[0]
|
|
391
|
+
var setOpened = openState[1]
|
|
392
|
+
var pageState = React.useState(0)
|
|
393
|
+
var page = pageState[0]
|
|
394
|
+
var setPage = pageState[1]
|
|
395
|
+
var dialogState = React.useState(null) // 'add' | null
|
|
343
396
|
var dialog = dialogState[0]
|
|
344
397
|
var setDialog = dialogState[1]
|
|
398
|
+
var confirmingState = React.useState(false) // 清空两段式确认
|
|
399
|
+
var confirming = confirmingState[0]
|
|
400
|
+
var menuState = React.useState(null) // {email,x,y} 右键菜单
|
|
401
|
+
var menu = menuState[0]
|
|
402
|
+
var setMenu = menuState[1]
|
|
403
|
+
var PAGE_SIZE = 10
|
|
345
404
|
|
|
346
405
|
var refresh = React.useCallback(function () {
|
|
347
406
|
api('list').then(function (data) { setMailboxes(data.mailboxes) }).catch(function () { setMailboxes([]) })
|
|
348
407
|
}, [])
|
|
349
408
|
React.useEffect(function () { refresh() }, [refresh])
|
|
350
409
|
|
|
410
|
+
// 切换账号→拉取对应邮件(''=全部)
|
|
411
|
+
React.useEffect(function () {
|
|
412
|
+
setMessages(null); setOpened(null); setPage(0)
|
|
413
|
+
api('history', { email: selected }).then(function (data) {
|
|
414
|
+
var list = (data.messages || []).slice().sort(function (a, b) {
|
|
415
|
+
return new Date(b.receivedAt || 0) - new Date(a.receivedAt || 0) // 全局时间倒序,最新在前
|
|
416
|
+
})
|
|
417
|
+
setMessages(list)
|
|
418
|
+
}).catch(function () { setMessages([]) })
|
|
419
|
+
}, [selected])
|
|
420
|
+
|
|
421
|
+
// 点任意处关闭右键菜单
|
|
422
|
+
React.useEffect(function () {
|
|
423
|
+
if (!menu) return undefined
|
|
424
|
+
var close = function () { setMenu(null) }
|
|
425
|
+
window.addEventListener('click', close)
|
|
426
|
+
return function () { window.removeEventListener('click', close) }
|
|
427
|
+
}, [menu])
|
|
428
|
+
|
|
351
429
|
var removeOne = function (email) {
|
|
352
|
-
|
|
430
|
+
setMenu(null)
|
|
431
|
+
api('remove', { email: email }).then(function (data) {
|
|
432
|
+
setMailboxes(data.mailboxes)
|
|
433
|
+
if (selected === email) setSelected('')
|
|
434
|
+
}).catch(function () {})
|
|
353
435
|
}
|
|
354
436
|
|
|
355
|
-
|
|
356
|
-
|
|
437
|
+
var prefix = function (email) { return String(email || '').replace(/@skillpie\.cn$/, '') }
|
|
438
|
+
|
|
439
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 0, height: 520 } },
|
|
440
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, height: 44, flex: 'none', paddingLeft: 10 } },
|
|
357
441
|
h(MailIcon, { size: 16 }),
|
|
358
442
|
h('span', { style: { fontSize: 13, fontWeight: 600 } }, t('title')),
|
|
359
443
|
),
|
|
360
|
-
h('div', { style: {
|
|
361
|
-
|
|
362
|
-
h('
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
444
|
+
h('div', { style: { display: 'flex', flex: 1, minHeight: 0, borderTop: '1px solid #f0f0f2' } },
|
|
445
|
+
/* 左栏:账号列表 */
|
|
446
|
+
h('div', { style: { width: 168, flex: 'none', borderRight: '1px solid #f0f0f2', display: 'flex', flexDirection: 'column', minHeight: 0 } },
|
|
447
|
+
h('div', { style: { flex: 1, minHeight: 0, overflowY: 'auto', padding: '6px 4px 0 0' } },
|
|
448
|
+
h('div', {
|
|
449
|
+
onClick: function () { setSelected('') },
|
|
450
|
+
style: {
|
|
451
|
+
display: 'flex', alignItems: 'center', gap: 6, padding: '7px 10px', fontSize: 12, cursor: 'pointer',
|
|
452
|
+
fontWeight: selected === '' ? 600 : 400, background: selected === '' ? '#f5f5f7' : 'transparent', borderRadius: 6,
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
h(MailIcon, { size: 13 }), t('inboxAll'),
|
|
456
|
+
),
|
|
457
|
+
(mailboxes || []).map(function (box) {
|
|
458
|
+
var isSel = selected === box.email
|
|
459
|
+
return h('div', {
|
|
460
|
+
key: box.email,
|
|
461
|
+
onClick: function () { setSelected(box.email) },
|
|
462
|
+
onContextMenu: function (event) {
|
|
463
|
+
event.preventDefault()
|
|
464
|
+
setMenu({ email: box.email, x: event.clientX, y: event.clientY })
|
|
465
|
+
},
|
|
466
|
+
title: box.email + (box.note ? ' · ' + box.note : '') + '(右键移除)',
|
|
467
|
+
style: {
|
|
468
|
+
display: 'flex', alignItems: 'center', gap: 6, padding: '7px 10px', fontSize: 12, cursor: 'pointer',
|
|
469
|
+
fontWeight: isSel ? 600 : 400, background: isSel ? '#f5f5f7' : 'transparent', borderRadius: 6,
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
h(MailIcon, { size: 13 }),
|
|
473
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
474
|
+
prefix(box.email) + (box.note ? ' ' + box.note : '')),
|
|
475
|
+
)
|
|
476
|
+
}),
|
|
477
|
+
),
|
|
478
|
+
h('div', { style: { padding: 6 } },
|
|
479
|
+
h('button', {
|
|
480
|
+
type: 'button', style: Object.assign({}, btnPrimaryStyle, { width: '100%', justifyContent: 'center' }),
|
|
481
|
+
onClick: function () { setDialog('add') },
|
|
482
|
+
}, '+ ' + t('add')),
|
|
483
|
+
),
|
|
484
|
+
),
|
|
485
|
+
/* 右栏:邮件列表/详情 */
|
|
486
|
+
h('div', { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', padding: '6px 0 0 10px' } },
|
|
487
|
+
opened
|
|
488
|
+
? [
|
|
489
|
+
h('div', { key: 'back', style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
|
490
|
+
h('button', { type: 'button', style: btnStyle, onClick: function () { setOpened(null) } }, '‹ ' + t('back')),
|
|
382
491
|
h('span', { style: { flex: 1 } }),
|
|
492
|
+
h('button', {
|
|
493
|
+
type: 'button', style: Object.assign({}, btnStyle, { color: '#e5484d', borderColor: 'rgba(229,72,77,0.4)' }),
|
|
494
|
+
onClick: function () {
|
|
495
|
+
var id = opened.id
|
|
496
|
+
var i = messages.findIndex(function (m) { return m.id === id })
|
|
497
|
+
var neighbor = messages[i - 1] || messages[i + 1] // 删除后自动跳到相邻邮件
|
|
498
|
+
api('deleteMail', { id: id }).catch(function () {})
|
|
499
|
+
syncUnread()
|
|
500
|
+
var left = messages.filter(function (m) { return m.id !== id })
|
|
501
|
+
setMessages(left)
|
|
502
|
+
setOpened(neighbor || null)
|
|
503
|
+
},
|
|
504
|
+
}, t('del')),
|
|
383
505
|
h('button', {
|
|
384
506
|
type: 'button', style: btnStyle,
|
|
385
|
-
|
|
386
|
-
|
|
507
|
+
disabled: messages.findIndex(function (m) { return m.id === opened.id }) <= 0,
|
|
508
|
+
onClick: function () {
|
|
509
|
+
var i = messages.findIndex(function (m) { return m.id === opened.id })
|
|
510
|
+
var next = messages[i - 1] // 列表倒序,上一封=数组前一个(更新)
|
|
511
|
+
if (next) {
|
|
512
|
+
if (!next.read) { next.read = true; api('markRead', { id: next.id }).catch(function () {}); syncUnread() }
|
|
513
|
+
setOpened(next)
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
}, '↑ ' + (t('prevMail') || '上一封')),
|
|
387
517
|
h('button', {
|
|
388
|
-
type: 'button', style:
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
518
|
+
type: 'button', style: btnStyle,
|
|
519
|
+
disabled: messages.findIndex(function (m) { return m.id === opened.id }) < 0 || messages.findIndex(function (m) { return m.id === opened.id }) >= messages.length - 1,
|
|
520
|
+
onClick: function () {
|
|
521
|
+
var i = messages.findIndex(function (m) { return m.id === opened.id })
|
|
522
|
+
var nextM = messages[i + 1] // 数组后一个(更早)
|
|
523
|
+
if (nextM) {
|
|
524
|
+
if (!nextM.read) { nextM.read = true; api('markRead', { id: nextM.id }).catch(function () {}); syncUnread() }
|
|
525
|
+
setOpened(nextM)
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
}, '↓ ' + (t('nextMail') || '下一封')),
|
|
529
|
+
),
|
|
530
|
+
h('div', { key: 'subj', style: { fontSize: 14, fontWeight: 600, marginTop: 6 } }, opened.subject || t('noSubject')),
|
|
531
|
+
h('div', { key: 'meta', style: { display: 'flex', gap: 12, flexWrap: 'wrap', fontSize: 11, color: '#8a8a8e', margin: '6px 0' } },
|
|
532
|
+
h('span', null, (t('from') || '发件人') + ':' + (opened.from || '-')),
|
|
533
|
+
h('span', null, (t('toLabel') || '收件邮箱') + ':' + opened.email),
|
|
534
|
+
h('span', null, (t('dateLabel') || '时间') + ':' + (fmtTime(opened.receivedAt) || opened.date || '-')),
|
|
535
|
+
),
|
|
536
|
+
opened.html
|
|
537
|
+
? h('div', {
|
|
538
|
+
key: 'html',
|
|
539
|
+
style: { fontSize: 12, color: '#3a3a3c', background: '#f5f5f7', borderRadius: 8, padding: '8px 10px', flex: 1, minHeight: 0, overflowY: 'auto' },
|
|
540
|
+
dangerouslySetInnerHTML: { __html: opened.html },
|
|
541
|
+
})
|
|
542
|
+
: h('div', {
|
|
543
|
+
key: 'body',
|
|
544
|
+
style: { fontSize: 12, color: '#3a3a3c', whiteSpace: 'pre-wrap', wordBreak: 'break-all', background: '#f5f5f7', borderRadius: 8, padding: '8px 10px', flex: 1, minHeight: 0, overflowY: 'auto' },
|
|
545
|
+
}, opened.text || '(无正文)'),
|
|
546
|
+
]
|
|
547
|
+
: [
|
|
548
|
+
h('div', { key: 'toolbar', style: { display: 'flex', alignItems: 'center', gap: 8, paddingBottom: 4, borderBottom: '1px solid #f0f0f2' } },
|
|
549
|
+
h('button', {
|
|
550
|
+
type: 'button', style: btnStyle,
|
|
551
|
+
onClick: function () {
|
|
552
|
+
if (!messages) return
|
|
553
|
+
api('markAllRead', { email: selected }).then(function () {
|
|
554
|
+
// 服务端写完再更新本地,保证实时刷新且不丢
|
|
555
|
+
setMessages(function (prev) { return prev.map(function (m) { return Object.assign({}, m, { read: true }) }) })
|
|
556
|
+
syncUnread()
|
|
557
|
+
}).catch(function () {})
|
|
558
|
+
},
|
|
559
|
+
}, t('markAllRead')),
|
|
560
|
+
h('span', { key: 'sp', style: { flex: 1 } }),
|
|
561
|
+
h('button', {
|
|
562
|
+
type: 'button', style: Object.assign({}, btnStyle, confirming ? { color: '#fff', background: '#e5484d', borderColor: '#e5484d' } : { color: '#e5484d', borderColor: 'rgba(229,72,77,0.4)' }),
|
|
563
|
+
onClick: function () {
|
|
564
|
+
// DSH 可能屏蔽 window.confirm,两段式确认
|
|
565
|
+
if (!confirming) {
|
|
566
|
+
confirmingState[1](true)
|
|
567
|
+
window.setTimeout(function () { confirmingState[1](false) }, 3000)
|
|
568
|
+
return
|
|
569
|
+
}
|
|
570
|
+
confirmingState[1](false)
|
|
571
|
+
api('clearHistory', { email: selected }).then(function () {
|
|
572
|
+
setMessages([]); setPage(0)
|
|
573
|
+
}).catch(function () {})
|
|
574
|
+
},
|
|
575
|
+
}, confirming ? '确认清空?' : t('clearAll')),
|
|
576
|
+
),
|
|
577
|
+
messages === null
|
|
578
|
+
? h('div', { key: 'load', style: { fontSize: 12, color: '#8a8a8e' } }, t('loading'))
|
|
579
|
+
: messages.length === 0
|
|
580
|
+
? h('div', { key: 'empty', style: { fontSize: 12, color: '#8a8a8e' } }, t('inboxEmpty'))
|
|
581
|
+
: [
|
|
582
|
+
h('div', { key: 'list', style: { flex: 1, minHeight: 0, overflowY: 'auto', display: 'flex', flexDirection: 'column' } },
|
|
583
|
+
messages.slice(page * PAGE_SIZE, (page + 1) * PAGE_SIZE).map(function (m) {
|
|
584
|
+
return h('div', {
|
|
585
|
+
key: m.id,
|
|
586
|
+
onClick: function () {
|
|
587
|
+
setOpened(m)
|
|
588
|
+
if (!m.read) {
|
|
589
|
+
m.read = true
|
|
590
|
+
api('markRead', { id: m.id }).catch(function () {}); syncUnread()
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
style: {
|
|
594
|
+
display: 'flex', alignItems: 'center', gap: 8, padding: '8px 6px',
|
|
595
|
+
borderBottom: '1px solid #f0f0f2', fontSize: 12, cursor: 'pointer', borderRadius: 6,
|
|
596
|
+
fontWeight: m.read ? 400 : 600, // 未读整行加粗
|
|
597
|
+
},
|
|
598
|
+
onMouseEnter: function (event) { event.currentTarget.style.background = '#f5f5f7' },
|
|
599
|
+
onMouseLeave: function (event) { event.currentTarget.style.background = 'transparent' },
|
|
600
|
+
},
|
|
601
|
+
h('span', {
|
|
602
|
+
key: 'rdot',
|
|
603
|
+
title: m.read ? '已读' : '未读',
|
|
604
|
+
style: {
|
|
605
|
+
flex: 'none', width: 8, height: 8, borderRadius: 4,
|
|
606
|
+
background: m.read ? 'transparent' : '#0a84ff',
|
|
607
|
+
border: m.read ? '1px solid #c7c7cc' : 'none',
|
|
608
|
+
},
|
|
609
|
+
}),
|
|
610
|
+
selected === '' ? h('span', { style: { color: '#8a8a8e', flex: 'none', width: 72, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, prefix(m.email)) : null,
|
|
611
|
+
h('span', { style: { flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontWeight: 500 } }, m.subject || t('noSubject')),
|
|
612
|
+
h('span', { style: { color: '#8a8a8e', flex: 'none', width: 110, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', direction: 'rtl', textAlign: 'left' } }, m.from || '-'),
|
|
613
|
+
h('span', { style: { color: '#8a8a8e', flex: 'none', width: 78, fontSize: 11, textAlign: 'right' } }, fmtTime(m.receivedAt)),
|
|
614
|
+
)
|
|
615
|
+
})),
|
|
616
|
+
h('div', { key: 'pager', style: { display: 'flex', alignItems: 'center', justifyContent: 'flex-end', gap: 8, paddingTop: 6, fontSize: 12, color: '#8a8a8e' } },
|
|
617
|
+
h('span', null, '共 ' + messages.length + ' 封 · 第 ' + (page + 1) + '/' + Math.max(1, Math.ceil(messages.length / PAGE_SIZE)) + ' 页'),
|
|
618
|
+
h('button', { type: 'button', style: Object.assign({}, btnStyle, { opacity: page === 0 ? 0.4 : 1 }), disabled: page === 0, onClick: function () { setPage(page - 1) } }, '‹ 上一页'),
|
|
619
|
+
h('button', { type: 'button', style: Object.assign({}, btnStyle, { opacity: (page + 1) * PAGE_SIZE >= messages.length ? 0.4 : 1 }), disabled: (page + 1) * PAGE_SIZE >= messages.length, onClick: function () { setPage(page + 1) } }, '下一页 ›'),
|
|
620
|
+
),
|
|
621
|
+
],
|
|
622
|
+
],
|
|
623
|
+
),
|
|
624
|
+
),
|
|
397
625
|
dialog === 'add'
|
|
398
626
|
? h(AddDialog, { t: t, onClose: function () { setDialog(null) }, onChanged: refresh })
|
|
399
627
|
: null,
|
|
400
|
-
|
|
401
|
-
?
|
|
628
|
+
menu
|
|
629
|
+
? ReactDOM.createPortal(
|
|
630
|
+
h('div', {
|
|
631
|
+
style: {
|
|
632
|
+
position: 'fixed', left: menu.x, top: menu.y, zIndex: 3200,
|
|
633
|
+
background: '#ffffff', border: '1px solid rgba(0,0,0,0.12)', borderRadius: 8,
|
|
634
|
+
boxShadow: '0 4px 16px rgba(0,0,0,0.15)', padding: 4, minWidth: 120,
|
|
635
|
+
},
|
|
636
|
+
onClick: function (event) { event.stopPropagation() },
|
|
637
|
+
},
|
|
638
|
+
h('div', {
|
|
639
|
+
onClick: function () { removeOne(menu.email) },
|
|
640
|
+
style: { padding: '6px 10px', fontSize: 12, color: '#e5484d', cursor: 'pointer', borderRadius: 5 },
|
|
641
|
+
onMouseEnter: function (event) { event.currentTarget.style.background = '#fdecec' },
|
|
642
|
+
onMouseLeave: function (event) { event.currentTarget.style.background = 'transparent' },
|
|
643
|
+
}, t('remove')),
|
|
644
|
+
), document.body)
|
|
402
645
|
: null,
|
|
403
646
|
)
|
|
404
647
|
}
|
|
405
648
|
|
|
406
649
|
|
|
650
|
+
|
|
407
651
|
/* ── 收件箱弹窗(列表 → 详情) ───────────────────────────────────── */
|
|
408
652
|
|
|
409
653
|
function InboxDialog(props) {
|
|
@@ -414,12 +658,26 @@ window.__ModuleLoader__.load({
|
|
|
414
658
|
var openState = React.useState(null)
|
|
415
659
|
var opened = openState[0]
|
|
416
660
|
var setOpened = openState[1]
|
|
661
|
+
var pageState = React.useState(0) // 收件箱列表分页
|
|
662
|
+
var page = pageState[0]
|
|
663
|
+
var setPage = pageState[1]
|
|
664
|
+
var confirmState = React.useState(false)
|
|
665
|
+
var confirming = confirmState[0]
|
|
666
|
+
var errState = React.useState('')
|
|
667
|
+
var errMsg = errState[0]
|
|
668
|
+
var setErr = errState[1]
|
|
669
|
+
var PAGE_SIZE = 10
|
|
417
670
|
|
|
418
671
|
React.useEffect(function () {
|
|
419
672
|
api('history', { email: props.email || '' }).then(function (data) {
|
|
420
673
|
setMessages(data.messages || [])
|
|
421
674
|
}).catch(function () { setMessages([]) })
|
|
422
675
|
}, [])
|
|
676
|
+
// 返回列表时若超出末页则回退
|
|
677
|
+
var backToList = function () {
|
|
678
|
+
setOpened(null)
|
|
679
|
+
setPage(function (p) { return messages && (p + 1) * PAGE_SIZE > messages.length ? Math.max(0, Math.ceil(messages.length / PAGE_SIZE) - 1) : p })
|
|
680
|
+
}
|
|
423
681
|
|
|
424
682
|
if (!ReactDOM || typeof ReactDOM.createPortal !== 'function') return null
|
|
425
683
|
var closeList = function () { props.onClose() }
|
|
@@ -448,7 +706,7 @@ window.__ModuleLoader__.load({
|
|
|
448
706
|
opened ? (opened.subject || t('noSubject')) : t('inbox')),
|
|
449
707
|
h('span', { style: { flex: 1 } }),
|
|
450
708
|
opened
|
|
451
|
-
? h('button', { type: 'button', style: btnStyle, onClick:
|
|
709
|
+
? h('button', { type: 'button', style: btnStyle, onClick: backToList }, t('back'))
|
|
452
710
|
: null,
|
|
453
711
|
h('button', { type: 'button', style: btnStyle, onClick: closeList }, t('close')),
|
|
454
712
|
),
|
|
@@ -458,7 +716,7 @@ window.__ModuleLoader__.load({
|
|
|
458
716
|
h('div', { key: 'meta', style: { fontSize: 12, color: '#6d6d72', display: 'flex', flexDirection: 'column', gap: 2 } },
|
|
459
717
|
h('span', null, (t('from') || '发件人') + ':' + (opened.from || '-')),
|
|
460
718
|
h('span', null, (t('toLabel') || '收件邮箱') + ':' + opened.email),
|
|
461
|
-
|
|
719
|
+
h('span', null, (t('dateLabel') || '时间') + ':' + (fmtTime(opened.receivedAt) || opened.date || '-')),
|
|
462
720
|
),
|
|
463
721
|
opened.html
|
|
464
722
|
? h('div', {
|
|
@@ -488,8 +746,9 @@ window.__ModuleLoader__.load({
|
|
|
488
746
|
? h('div', { key: 'load', style: { fontSize: 12, color: '#8a8a8e' } }, t('loading'))
|
|
489
747
|
: messages.length === 0
|
|
490
748
|
? h('div', { key: 'empty', style: { fontSize: 12, color: '#8a8a8e' } }, t('inboxEmpty'))
|
|
491
|
-
:
|
|
492
|
-
|
|
749
|
+
: [
|
|
750
|
+
h('div', { key: 'list', style: { display: 'flex', flexDirection: 'column' } },
|
|
751
|
+
messages.slice(page * PAGE_SIZE, (page + 1) * PAGE_SIZE).map(function (m) {
|
|
493
752
|
return h('div', {
|
|
494
753
|
key: m.id,
|
|
495
754
|
onClick: function () { setOpened(m) },
|
|
@@ -507,8 +766,31 @@ window.__ModuleLoader__.load({
|
|
|
507
766
|
m.subject || t('noSubject')),
|
|
508
767
|
h('span', { style: { color: '#8a8a8e', flex: 'none', width: 110, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', direction: 'rtl', textAlign: 'left' } },
|
|
509
768
|
m.from || '-'),
|
|
769
|
+
h('span', { style: { color: '#8a8a8e', flex: 'none', width: 78, fontSize: 11, textAlign: 'right' } },
|
|
770
|
+
fmtTime(m.receivedAt)),
|
|
510
771
|
)
|
|
511
|
-
|
|
772
|
+
})),
|
|
773
|
+
h('div', { key: 'pager', style: { display: 'flex', alignItems: 'center', justifyContent: 'flex-end', gap: 8, paddingTop: 6, fontSize: 12, color: '#8a8a8e' } },
|
|
774
|
+
h('span', null, '共 ' + messages.length + ' 封 · 第 ' + (page + 1) + '/' + Math.max(1, Math.ceil(messages.length / PAGE_SIZE)) + ' 页'),
|
|
775
|
+
h('button', { type: 'button', style: Object.assign({}, btnStyle, { opacity: page === 0 ? 0.4 : 1 }), disabled: page === 0, onClick: function () { setPage(page - 1) } }, '‹ 上一页'),
|
|
776
|
+
h('button', { type: 'button', style: Object.assign({}, btnStyle, { opacity: (page + 1) * PAGE_SIZE >= messages.length ? 0.4 : 1 }), disabled: (page + 1) * PAGE_SIZE >= messages.length, onClick: function () { setPage(page + 1) } }, '下一页 ›'),
|
|
777
|
+
h('button', { type: 'button', style: Object.assign({}, btnStyle, confirming ? { color: '#fff', background: '#e5484d', borderColor: '#e5484d' } : { color: '#e5484d', borderColor: 'rgba(229,72,77,0.4)' }), onClick: function () {
|
|
778
|
+
// DSH 环境可能屏蔽 window.confirm,改用两段确认
|
|
779
|
+
if (!confirming) {
|
|
780
|
+
confirmState[1](true)
|
|
781
|
+
window.setTimeout(function () { confirmState[1](false) }, 3000)
|
|
782
|
+
return
|
|
783
|
+
}
|
|
784
|
+
confirmState[1](false)
|
|
785
|
+
api('clearHistory', { email: props.email || '' }).then(function () {
|
|
786
|
+
setMessages([])
|
|
787
|
+
setPage(0)
|
|
788
|
+
setErr('')
|
|
789
|
+
}).catch(function (e) { setErr('清空失败: ' + (e && e.message ? e.message : e)) })
|
|
790
|
+
} }, confirming ? '确认清空?' : t('clearAll')),
|
|
791
|
+
),
|
|
792
|
+
errMsg ? h('div', { style: { color: '#e5484d', fontSize: 12, textAlign: 'center', marginTop: 8 } }, errMsg) : null,
|
|
793
|
+
],
|
|
512
794
|
],
|
|
513
795
|
),
|
|
514
796
|
),
|
|
@@ -518,14 +800,33 @@ window.__ModuleLoader__.load({
|
|
|
518
800
|
|
|
519
801
|
/* ── 全局新邮件弹窗 ─────────────────────────────────────────────── */
|
|
520
802
|
|
|
803
|
+
// 底部栏图标共享的未读计数(收到新邮件 +1,打开收件箱清零)
|
|
804
|
+
var refreshRef = { current: null } // MailDock 的立即收件入口
|
|
805
|
+
var syncUnread = function () { // 已读/删除后立即校准底部未读数
|
|
806
|
+
api('unread').then(function (d) {
|
|
807
|
+
if (d && typeof d.count === 'number') dockStore.set(d.count)
|
|
808
|
+
}).catch(function () {})
|
|
809
|
+
}
|
|
810
|
+
var dockStore = {
|
|
811
|
+
count: 0,
|
|
812
|
+
subs: [],
|
|
813
|
+
subscribe: function (fn) { this.subs.push(fn); return this.subs.indexOf(fn) },
|
|
814
|
+
set: function (n) { this.count = n; for (var i = 0; i < this.subs.length; i++) this.subs[i](n) },
|
|
815
|
+
add: function (n) { this.set(this.count + n) },
|
|
816
|
+
}
|
|
817
|
+
|
|
521
818
|
|
|
522
819
|
var pollSeq = 0 // 已取走的通知最大 seq(内存态,刷新后从 0 重新拉取不重复弹:seq 会重置)
|
|
523
820
|
|
|
524
821
|
function MailPopup(props) {
|
|
525
822
|
var t = props.t
|
|
526
|
-
var
|
|
527
|
-
var
|
|
528
|
-
var
|
|
823
|
+
var mailsState = React.useState([])
|
|
824
|
+
var mails = mailsState[0]
|
|
825
|
+
var setMails = mailsState[1]
|
|
826
|
+
|
|
827
|
+
var viewState = React.useState(0) // hooks 必须全部在条件 return 之前
|
|
828
|
+
var view = viewState[0]
|
|
829
|
+
var setView = viewState[1]
|
|
529
830
|
|
|
530
831
|
React.useEffect(function () {
|
|
531
832
|
var stopped = false
|
|
@@ -537,7 +838,8 @@ window.__ModuleLoader__.load({
|
|
|
537
838
|
var item = data.notifications[i]
|
|
538
839
|
if (item.seq > pollSeq) pollSeq = item.seq
|
|
539
840
|
}
|
|
540
|
-
|
|
841
|
+
setMails(function (prev) { return prev.concat(data.notifications) })
|
|
842
|
+
dockStore.add(data.notifications.length)
|
|
541
843
|
}).catch(function () {})
|
|
542
844
|
}, 8000)
|
|
543
845
|
return function () {
|
|
@@ -546,8 +848,15 @@ window.__ModuleLoader__.load({
|
|
|
546
848
|
}
|
|
547
849
|
}, [])
|
|
548
850
|
|
|
549
|
-
|
|
550
|
-
|
|
851
|
+
var idx = mails.length ? Math.min(view, mails.length - 1) : 0
|
|
852
|
+
if (!mails || !mails.length || !ReactDOM || typeof ReactDOM.createPortal !== 'function') return null
|
|
853
|
+
var close = function () { setMails([]) }
|
|
854
|
+
var goPrev = function () { setView(function (v) { return (v - 1 + mails.length) % mails.length }) }
|
|
855
|
+
var goNext = function () { setView(function (v) { return (v + 1) % mails.length }) }
|
|
856
|
+
var pagerBtn = {
|
|
857
|
+
border: '1px solid rgba(0,0,0,0.12)', background: '#f5f5f7', cursor: 'pointer',
|
|
858
|
+
borderRadius: 6, padding: '1px 8px', fontSize: 13, lineHeight: 1.4, color: '#1c1c1e',
|
|
859
|
+
}
|
|
551
860
|
// 全局居中模态:遮罩+浅色卡片,仅用户点击关闭按钮/遮罩才消失
|
|
552
861
|
return ReactDOM.createPortal(
|
|
553
862
|
h('div', {
|
|
@@ -573,9 +882,14 @@ window.__ModuleLoader__.load({
|
|
|
573
882
|
h('svg', { viewBox: '0 0 24 24', width: 16, height: 16, fill: 'none', stroke: 'currentColor', 'stroke-width': 2, 'stroke-linecap': 'round', 'stroke-linejoin': 'round' },
|
|
574
883
|
h('rect', { x: 3, y: 5, width: 18, height: 14, rx: 2 }),
|
|
575
884
|
h('path', { d: 'm3 7 9 6 9-6' }))),
|
|
576
|
-
h('span', { style: { fontWeight: 600 } }, t('newMail')),
|
|
885
|
+
h('span', { style: { fontWeight: 600 } }, t('newMail') + (mails.length > 1 ? ' (' + (idx + 1) + '/' + mails.length + ')' : '')),
|
|
886
|
+
mails.length > 1
|
|
887
|
+
? h('div', { style: { display: 'flex', alignItems: 'center', gap: 2 } },
|
|
888
|
+
h('button', { onClick: goPrev, style: pagerBtn }, '‹'),
|
|
889
|
+
h('button', { onClick: goNext, style: pagerBtn }, '›'),
|
|
890
|
+
)
|
|
891
|
+
: null,
|
|
577
892
|
h('span', { style: { flex: 1 } }),
|
|
578
|
-
h('span', { style: { fontSize: 12, color: '#8a8a8e', wordBreak: 'break-all' } }, mail.email),
|
|
579
893
|
h('button', {
|
|
580
894
|
onClick: close,
|
|
581
895
|
style: {
|
|
@@ -584,26 +898,34 @@ window.__ModuleLoader__.load({
|
|
|
584
898
|
},
|
|
585
899
|
}, '×'),
|
|
586
900
|
),
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
style: {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
901
|
+
mails.length > 0 ? (function () {
|
|
902
|
+
var mail = mails[idx]
|
|
903
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
904
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
|
905
|
+
h('span', { style: { fontSize: 12, color: '#8a8a8e', wordBreak: 'break-all', flex: 1 } }, mail.email + (mail.folder ? ' · ' + mail.folder : '')),
|
|
906
|
+
),
|
|
907
|
+
h('div', { style: { fontWeight: 600, wordBreak: 'break-all' } }, mail.subject || '(无主题)'),
|
|
908
|
+
mail.from
|
|
909
|
+
? h('div', { style: { fontSize: 12, color: '#6d6d72', wordBreak: 'break-all' } }, mail.from)
|
|
910
|
+
: null,
|
|
911
|
+
mail.html
|
|
912
|
+
? h('div', {
|
|
913
|
+
style: {
|
|
914
|
+
fontSize: 13, color: '#3a3a3c', wordBreak: 'break-all', lineHeight: 1.6,
|
|
915
|
+
background: '#f5f5f7', borderRadius: 8, padding: '10px 12px', maxHeight: 260, overflowY: 'auto',
|
|
916
|
+
},
|
|
917
|
+
dangerouslySetInnerHTML: { __html: mail.html },
|
|
918
|
+
})
|
|
919
|
+
: mail.text
|
|
920
|
+
? h('div', {
|
|
921
|
+
style: {
|
|
922
|
+
fontSize: 12, color: '#3a3a3c', whiteSpace: 'pre-wrap', wordBreak: 'break-all',
|
|
923
|
+
background: '#f5f5f7', borderRadius: 8, padding: '8px 10px', maxHeight: 260, overflowY: 'auto',
|
|
924
|
+
},
|
|
925
|
+
}, mail.text.length > 800 ? mail.text.slice(0, 800) + '…' : mail.text)
|
|
926
|
+
: null,
|
|
927
|
+
)
|
|
928
|
+
})() : null,
|
|
607
929
|
h('div', { style: { display: 'flex', justifyContent: 'flex-end' } },
|
|
608
930
|
h('button', {
|
|
609
931
|
onClick: close,
|
|
@@ -611,7 +933,7 @@ window.__ModuleLoader__.load({
|
|
|
611
933
|
border: '1px solid rgba(0,0,0,0.12)', background: '#f5f5f7', cursor: 'pointer',
|
|
612
934
|
borderRadius: 7, padding: '4px 14px', fontSize: 12, color: '#1c1c1e',
|
|
613
935
|
},
|
|
614
|
-
}, t('close')),
|
|
936
|
+
}, t('close') + (mails.length > 1 ? ' (' + mails.length + ')' : '')),
|
|
615
937
|
),
|
|
616
938
|
),
|
|
617
939
|
),
|
|
@@ -637,33 +959,100 @@ window.__ModuleLoader__.load({
|
|
|
637
959
|
return s
|
|
638
960
|
}
|
|
639
961
|
|
|
640
|
-
//
|
|
641
|
-
|
|
642
|
-
ctx.slots.inject('settings.section', function () {
|
|
962
|
+
// 底部栏邮箱入口:图标+新邮件角标,点击打开收件箱
|
|
963
|
+
ctx.slots.inject('conversation.composer.dock', function () {
|
|
643
964
|
return ctx.slots.register(
|
|
644
965
|
{
|
|
645
|
-
name: '
|
|
646
|
-
id: 'dsh-skillpie-mail',
|
|
647
|
-
order:
|
|
648
|
-
label: function () { return pageT('title') },
|
|
966
|
+
name: 'conversation.composer.dock',
|
|
967
|
+
id: 'dsh-skillpie-mail-dock',
|
|
968
|
+
order: 6,
|
|
649
969
|
locale: NS,
|
|
650
970
|
},
|
|
651
|
-
function
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
971
|
+
function MailDock() {
|
|
972
|
+
var openState = React.useState(false)
|
|
973
|
+
var open = openState[0]
|
|
974
|
+
var setOpen = openState[1]
|
|
975
|
+
var countState = React.useState(dockStore.count)
|
|
976
|
+
var setCount = countState[1]
|
|
977
|
+
React.useEffect(function () {
|
|
978
|
+
var off = function (n) { setCount(n) }
|
|
979
|
+
dockStore.subs.push(off)
|
|
980
|
+
return function () { dockStore.subs = dockStore.subs.filter(function (fn) { return fn !== off }) }
|
|
981
|
+
}, [])
|
|
982
|
+
// 新邮件轮询:不再自动弹窗,只累加状态栏角标
|
|
983
|
+
React.useEffect(function () {
|
|
984
|
+
var stopped = false
|
|
985
|
+
var refresh = function () {
|
|
986
|
+
// 立即收一次件(pollNow 让宿主马上拉 IMAP),再校准未读数
|
|
987
|
+
api('pollNow').catch(function () {})
|
|
988
|
+
api('poll', { sinceSeq: pollSeq }).then(function (data) {
|
|
989
|
+
if (stopped || !data.notifications || !data.notifications.length) return
|
|
990
|
+
for (var i = 0; i < data.notifications.length; i++) {
|
|
991
|
+
var item = data.notifications[i]
|
|
992
|
+
if (item.seq > pollSeq) pollSeq = item.seq
|
|
993
|
+
}
|
|
994
|
+
return api('unread')
|
|
995
|
+
}).then(function (d) {
|
|
996
|
+
if (!stopped && d && typeof d.count === 'number') dockStore.set(d.count)
|
|
997
|
+
}).catch(function () {})
|
|
998
|
+
}
|
|
999
|
+
refreshRef.current = refresh
|
|
1000
|
+
var timer = window.setInterval(refresh, 30000)
|
|
1001
|
+
return function () {
|
|
1002
|
+
stopped = true
|
|
1003
|
+
window.clearInterval(timer)
|
|
1004
|
+
}
|
|
1005
|
+
}, [])
|
|
1006
|
+
return [
|
|
1007
|
+
h('button', {
|
|
1008
|
+
title: (pageT('sectionTitle') || 'SkillPie 邮箱') + (countState[0] > 0 ? '(' + countState[0] + ' 封新邮件)' : ''),
|
|
1009
|
+
onClick: function () {
|
|
1010
|
+
setOpen(function (v) { return !v })
|
|
1011
|
+
if (refreshRef.current) refreshRef.current() // 点击立即收一次件
|
|
1012
|
+
},
|
|
1013
|
+
style: {
|
|
1014
|
+
boxSizing: 'border-box', borderRadius: 6, maxWidth: '100%',
|
|
1015
|
+
color: 'var(--dsw-alias-label-tertiary, #a0a3a8)', font: 'inherit',
|
|
1016
|
+
lineHeight: 'inherit', whiteSpace: 'nowrap',
|
|
1017
|
+
background: 'transparent', border: 'none', cursor: 'pointer',
|
|
1018
|
+
display: 'inline-flex', alignItems: 'center', gap: 6, padding: '3px 8px',
|
|
1019
|
+
fontSize: 14, position: 'relative',
|
|
1020
|
+
},
|
|
1021
|
+
},
|
|
1022
|
+
h('svg', { viewBox: '0 0 24 24', width: 16, height: 16, fill: 'none', stroke: 'currentColor', 'stroke-width': 2, 'stroke-linecap': 'round', 'stroke-linejoin': 'round' },
|
|
1023
|
+
h('rect', { x: 3, y: 5, width: 18, height: 14, rx: 2 }),
|
|
1024
|
+
h('path', { d: 'm3 7 9 6 9-6' })),
|
|
1025
|
+
countState[0] > 0
|
|
1026
|
+
? h('span', {
|
|
1027
|
+
style: { color: 'var(--dsw-alias-label-tertiary, #a0a3a8)', fontVariantNumeric: 'tabular-nums', fontSize: 'inherit', lineHeight: 'inherit' },
|
|
1028
|
+
}, String(countState[0]))
|
|
1029
|
+
: null,
|
|
1030
|
+
),
|
|
1031
|
+
open
|
|
1032
|
+
? ReactDOM.createPortal(h('div', {
|
|
1033
|
+
style: { position: 'fixed', inset: 0, zIndex: 2600, background: 'rgba(0,0,0,0.35)', display: 'flex', alignItems: 'center', justifyContent: 'center' },
|
|
1034
|
+
onClick: function (e) { if (e.target === e.currentTarget) setOpen(false) },
|
|
1035
|
+
},
|
|
1036
|
+
h('div', {
|
|
1037
|
+
style: {
|
|
1038
|
+
background: '#ffffff', borderRadius: 12, boxShadow: '0 12px 48px rgba(0,0,0,0.2)',
|
|
1039
|
+
width: 780, maxWidth: 'calc(100vw - 32px)', maxHeight: '86vh', overflow: 'hidden',
|
|
1040
|
+
padding: 4, position: 'relative',
|
|
1041
|
+
},
|
|
1042
|
+
},
|
|
1043
|
+
h('button', {
|
|
1044
|
+
onClick: function () { setOpen(false) },
|
|
1045
|
+
style: {
|
|
1046
|
+
position: 'absolute', top: 12, right: 12, border: 'none', background: 'transparent',
|
|
1047
|
+
cursor: 'pointer', fontSize: 18, lineHeight: 1, color: '#8a8a8e',
|
|
1048
|
+
width: 28, height: 28, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 0,
|
|
1049
|
+
},
|
|
1050
|
+
}, '×'),
|
|
1051
|
+
h(SettingsSection, { t: pageT }),
|
|
1052
|
+
),
|
|
1053
|
+
), document.body)
|
|
1054
|
+
: null,
|
|
1055
|
+
]
|
|
667
1056
|
},
|
|
668
1057
|
)
|
|
669
1058
|
})
|