koishi-plugin-chat-patch 0.8.3 → 1.0.6
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/client/vue/index.vue +608 -22
- package/client/vue/style.css +355 -0
- package/dist/index.js +8 -8
- package/dist/style.css +1 -1
- package/lib/api-handlers.d.ts +17 -0
- package/lib/config.d.ts +13 -0
- package/lib/file-manager.d.ts +17 -0
- package/lib/index.d.ts +3 -12
- package/lib/index.js +814 -450
- package/lib/message-handler.d.ts +16 -0
- package/lib/types.d.ts +53 -0
- package/lib/utils.d.ts +7 -0
- package/package.json +1 -1
- package/src/api-handlers.ts +593 -0
- package/src/config.ts +45 -0
- package/src/file-manager.ts +162 -0
- package/src/index.ts +45 -753
- package/src/message-handler.ts +247 -0
- package/src/types.ts +58 -0
- package/src/utils.ts +43 -0
package/client/vue/style.css
CHANGED
|
@@ -337,6 +337,18 @@
|
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
+
@keyframes menuSlideIn {
|
|
341
|
+
0% {
|
|
342
|
+
transform: translateY(8px);
|
|
343
|
+
opacity: 0;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
100% {
|
|
347
|
+
transform: translateY(0);
|
|
348
|
+
opacity: 1;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
340
352
|
.message-content {
|
|
341
353
|
display: flex;
|
|
342
354
|
flex-direction: column;
|
|
@@ -631,6 +643,107 @@
|
|
|
631
643
|
display: inline;
|
|
632
644
|
}
|
|
633
645
|
|
|
646
|
+
.message-paragraph {
|
|
647
|
+
display: block;
|
|
648
|
+
margin-bottom: 4px;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
.message-paragraph:last-child {
|
|
652
|
+
margin-bottom: 0;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/* 合并转发消息样式 */
|
|
656
|
+
.forward-message-container {
|
|
657
|
+
border: 1px solid #ffffff;
|
|
658
|
+
border-radius: 8px;
|
|
659
|
+
margin: 4px 0;
|
|
660
|
+
overflow: hidden;
|
|
661
|
+
background: #f9f9f900;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
.forward-message-preview {
|
|
665
|
+
padding: 12px;
|
|
666
|
+
cursor: pointer;
|
|
667
|
+
transition: background-color 0.2s;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
.forward-message-preview:hover {
|
|
671
|
+
background: #f0f0f0;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
.forward-message-title {
|
|
675
|
+
font-weight: 600;
|
|
676
|
+
color: #333;
|
|
677
|
+
margin-bottom: 8px;
|
|
678
|
+
font-size: 14px;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
.forward-message-preview-item {
|
|
682
|
+
color: #666;
|
|
683
|
+
font-size: 13px;
|
|
684
|
+
margin: 2px 0;
|
|
685
|
+
line-height: 1.4;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
.forward-message-footer {
|
|
689
|
+
display: flex;
|
|
690
|
+
justify-content: space-between;
|
|
691
|
+
align-items: center;
|
|
692
|
+
margin-top: 8px;
|
|
693
|
+
padding-top: 8px;
|
|
694
|
+
border-top: 1px solid #e8e8e8;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
.forward-message-count {
|
|
698
|
+
color: #2196f3;
|
|
699
|
+
font-size: 12px;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
.forward-message-toggle {
|
|
703
|
+
color: #666;
|
|
704
|
+
font-size: 12px;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
.forward-message-expanded {
|
|
708
|
+
border-top: 1px solid #e0e0e0;
|
|
709
|
+
background: white;
|
|
710
|
+
max-height: 400px;
|
|
711
|
+
overflow-y: auto;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
.forwarded-message-item {
|
|
715
|
+
padding: 12px;
|
|
716
|
+
border-bottom: 1px solid #f0f0f0;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
.forwarded-message-item:last-child {
|
|
720
|
+
border-bottom: none;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
.forwarded-message-header {
|
|
724
|
+
display: flex;
|
|
725
|
+
align-items: center;
|
|
726
|
+
margin-bottom: 6px;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
.forwarded-message-nickname {
|
|
730
|
+
font-weight: 600;
|
|
731
|
+
color: #333;
|
|
732
|
+
font-size: 13px;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
.forwarded-message-userid {
|
|
736
|
+
color: #999;
|
|
737
|
+
font-size: 11px;
|
|
738
|
+
margin-left: 6px;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
.forwarded-message-content {
|
|
742
|
+
color: #555;
|
|
743
|
+
font-size: 13px;
|
|
744
|
+
line-height: 1.4;
|
|
745
|
+
}
|
|
746
|
+
|
|
634
747
|
.message-at {
|
|
635
748
|
background: rgba(33, 150, 243, .1);
|
|
636
749
|
color: #2196f3;
|
|
@@ -1369,4 +1482,246 @@ body.dragging-bubble-global {
|
|
|
1369
1482
|
|
|
1370
1483
|
.message-area .message-content {
|
|
1371
1484
|
padding-bottom: 80px;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
/* 图片上传相关样式 */
|
|
1488
|
+
.image-preview-container {
|
|
1489
|
+
display: flex;
|
|
1490
|
+
flex-wrap: wrap;
|
|
1491
|
+
gap: 8px;
|
|
1492
|
+
padding: 8px 0;
|
|
1493
|
+
margin-bottom: 8px;
|
|
1494
|
+
border-bottom: 1px solid rgba(128, 128, 128, .1);
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
.image-preview-item {
|
|
1498
|
+
position: relative;
|
|
1499
|
+
width: 60px;
|
|
1500
|
+
height: 60px;
|
|
1501
|
+
border-radius: 8px;
|
|
1502
|
+
overflow: hidden;
|
|
1503
|
+
border: 2px solid rgba(33, 150, 243, .3);
|
|
1504
|
+
background: rgba(128, 128, 128, .1);
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
.preview-image {
|
|
1508
|
+
width: 100%;
|
|
1509
|
+
height: 100%;
|
|
1510
|
+
object-fit: cover;
|
|
1511
|
+
display: block;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
.remove-image-btn {
|
|
1515
|
+
position: absolute;
|
|
1516
|
+
top: -6px;
|
|
1517
|
+
right: -6px;
|
|
1518
|
+
width: 20px;
|
|
1519
|
+
height: 20px;
|
|
1520
|
+
border-radius: 50%;
|
|
1521
|
+
background: #f44336;
|
|
1522
|
+
color: white;
|
|
1523
|
+
border: none;
|
|
1524
|
+
cursor: pointer;
|
|
1525
|
+
display: flex;
|
|
1526
|
+
align-items: center;
|
|
1527
|
+
justify-content: center;
|
|
1528
|
+
font-size: 12px;
|
|
1529
|
+
transition: all .2s ease;
|
|
1530
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
.remove-image-btn:hover {
|
|
1534
|
+
background: #d32f2f;
|
|
1535
|
+
transform: scale(1.1);
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
.input-actions {
|
|
1539
|
+
position: relative;
|
|
1540
|
+
margin-right: 8px;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
.add-button {
|
|
1544
|
+
width: 36px;
|
|
1545
|
+
height: 36px;
|
|
1546
|
+
border-radius: 12px;
|
|
1547
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
1548
|
+
border: none;
|
|
1549
|
+
color: white;
|
|
1550
|
+
cursor: pointer;
|
|
1551
|
+
display: flex;
|
|
1552
|
+
align-items: center;
|
|
1553
|
+
justify-content: center;
|
|
1554
|
+
transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
1555
|
+
flex-shrink: 0;
|
|
1556
|
+
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
|
|
1557
|
+
position: relative;
|
|
1558
|
+
overflow: hidden;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
.add-button::before {
|
|
1562
|
+
content: '';
|
|
1563
|
+
position: absolute;
|
|
1564
|
+
top: 0;
|
|
1565
|
+
left: 0;
|
|
1566
|
+
right: 0;
|
|
1567
|
+
bottom: 0;
|
|
1568
|
+
background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 100%);
|
|
1569
|
+
border-radius: 12px;
|
|
1570
|
+
opacity: 0;
|
|
1571
|
+
transition: opacity .3s ease;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
.add-button:hover {
|
|
1575
|
+
transform: translateY(-2px) scale(1.05);
|
|
1576
|
+
box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
.add-button:hover::before {
|
|
1580
|
+
opacity: 1;
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
.add-button.active {
|
|
1584
|
+
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
|
1585
|
+
transform: translateY(-2px) scale(1.05) rotate(45deg);
|
|
1586
|
+
box-shadow: 0 4px 16px rgba(245, 87, 108, 0.4);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
.add-button:active {
|
|
1590
|
+
transform: translateY(0) scale(0.98);
|
|
1591
|
+
transition: all .1s ease;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
.action-menu {
|
|
1595
|
+
position: absolute;
|
|
1596
|
+
bottom: 100%;
|
|
1597
|
+
left: 0;
|
|
1598
|
+
margin-bottom: 12px;
|
|
1599
|
+
background: rgba(255, 255, 255, .98);
|
|
1600
|
+
border: none;
|
|
1601
|
+
border-radius: 16px;
|
|
1602
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, .12), 0 2px 8px rgba(0, 0, 0, .08);
|
|
1603
|
+
backdrop-filter: blur(20px);
|
|
1604
|
+
-webkit-backdrop-filter: blur(20px);
|
|
1605
|
+
overflow: hidden;
|
|
1606
|
+
z-index: 1000;
|
|
1607
|
+
min-width: 140px;
|
|
1608
|
+
transform: translateY(8px);
|
|
1609
|
+
opacity: 0;
|
|
1610
|
+
animation: menuSlideIn .3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
.action-menu-item {
|
|
1614
|
+
display: flex;
|
|
1615
|
+
align-items: center;
|
|
1616
|
+
gap: 12px;
|
|
1617
|
+
padding: 14px 18px;
|
|
1618
|
+
background: none;
|
|
1619
|
+
border: none;
|
|
1620
|
+
color: #333;
|
|
1621
|
+
font-size: 14px;
|
|
1622
|
+
font-weight: 500;
|
|
1623
|
+
cursor: pointer;
|
|
1624
|
+
transition: all .2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
1625
|
+
width: 100%;
|
|
1626
|
+
text-align: left;
|
|
1627
|
+
position: relative;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
.action-menu-item::before {
|
|
1631
|
+
content: '';
|
|
1632
|
+
position: absolute;
|
|
1633
|
+
left: 0;
|
|
1634
|
+
top: 0;
|
|
1635
|
+
bottom: 0;
|
|
1636
|
+
width: 3px;
|
|
1637
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
1638
|
+
transform: scaleY(0);
|
|
1639
|
+
transition: transform .2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
.action-menu-item:hover {
|
|
1643
|
+
background: linear-gradient(90deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
|
|
1644
|
+
color: #667eea;
|
|
1645
|
+
transform: translateX(4px);
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
.action-menu-item:hover::before {
|
|
1649
|
+
transform: scaleY(1);
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
.action-menu-item svg {
|
|
1653
|
+
flex-shrink: 0;
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
@media (prefers-color-scheme: dark) {
|
|
1657
|
+
.action-menu {
|
|
1658
|
+
background: rgba(30, 30, 30, .98);
|
|
1659
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .2);
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
.action-menu-item {
|
|
1663
|
+
color: #fff;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
.action-menu-item::before {
|
|
1667
|
+
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
.action-menu-item:hover {
|
|
1671
|
+
background: linear-gradient(90deg, rgba(79, 172, 254, 0.12) 0%, rgba(0, 242, 254, 0.12) 100%);
|
|
1672
|
+
color: #4facfe;
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
.add-button {
|
|
1676
|
+
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
|
1677
|
+
box-shadow: 0 2px 8px rgba(79, 172, 254, 0.3);
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
.add-button:hover {
|
|
1681
|
+
box-shadow: 0 4px 16px rgba(79, 172, 254, 0.4);
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
.add-button.active {
|
|
1685
|
+
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
|
|
1686
|
+
box-shadow: 0 4px 16px rgba(250, 112, 154, 0.4);
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
.image-preview-item {
|
|
1690
|
+
border-color: rgba(100, 181, 246, .5);
|
|
1691
|
+
background: rgba(255, 255, 255, .05);
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
@media (max-width: 768px) {
|
|
1696
|
+
.image-preview-container {
|
|
1697
|
+
padding: 6px 0;
|
|
1698
|
+
margin-bottom: 6px;
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
.image-preview-item {
|
|
1702
|
+
width: 50px;
|
|
1703
|
+
height: 50px;
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
.add-button {
|
|
1707
|
+
width: 32px;
|
|
1708
|
+
height: 32px;
|
|
1709
|
+
border-radius: 10px;
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
.action-menu {
|
|
1713
|
+
min-width: 100px;
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
.action-menu-item {
|
|
1717
|
+
padding: 10px 12px;
|
|
1718
|
+
font-size: 13px;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
.remove-image-btn {
|
|
1722
|
+
width: 18px;
|
|
1723
|
+
height: 18px;
|
|
1724
|
+
top: -5px;
|
|
1725
|
+
right: -5px;
|
|
1726
|
+
}
|
|
1372
1727
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{defineComponent as Z,ref as v,onMounted as Se,h as d,computed as q,watch as Xe,nextTick as se,onUnmounted as Mt,createElementBlock as m,openBlock as f,normalizeStyle as Be,normalizeClass as z,createElementVNode as i,createCommentVNode as le,Fragment as R,renderList as oe,createBlock as re,unref as ce,toDisplayString as p,withDirectives as ze,createTextVNode as Ye,vShow as Tt,withKeys as Dt,vModelText as qt,withModifiers as Lt,resolveComponent as Kt}from"vue";import{receive as Fe,send as M,icons as Nt}from"@koishijs/client";const Pt={class:"bot-list"},jt={class:"bot-items"},Ut=["onClick","onContextmenu"],Ot={class:"bot-avatar"},At={key:1,class:"avatar-placeholder"},Rt={class:"bot-info"},Ht={class:"bot-name"},Xt={class:"bot-platform"},zt={class:"channel-list"},Yt={key:0,class:"empty-state"},Ft={key:1,class:"channel-items"},Wt=["data-channel-id","onClick","onContextmenu"],Jt={class:"channel-info"},Vt={class:"channel-name"},Gt={class:"channel-type"},Qt=["onMousedown","onTouchstart","title"],Zt={class:"message-area"},Et={class:"panel-header"},ea={key:0,class:"empty-state"},ta={key:1,class:"message-content"},aa={class:"message-avatar"},na={key:1,class:"avatar-placeholder"},sa={class:"message-content-wrapper"},la={class:"message-header"},oa={class:"message-username"},ra={class:"message-time"},ca={key:0,class:"message-quote"},ia={class:"quote-header"},ua={class:"quote-avatar"},da={key:1,class:"avatar-placeholder"},va={class:"quote-username"},ha={class:"quote-time"},fa={class:"quote-content"},ma={class:"message-text"},ga={class:"message-input"},ya={class:"input-row"},pa=["placeholder","disabled"],wa=["disabled"],We=200,ba="ChatImageCache",xa=1,L="images",K=80,Ca=Z({__name:"index",setup(F){const H=Z({props:{src:{type:String,required:true},alt:{type:String,default:"头像"},channelKey:{type:String,required:true}},setup(e){const a=v("loading"),t=v(e.src),n=v(""),s=async()=>{try{a.value="loading";const r=await _e(e.channelKey,e.src);if(r){t.value=r,a.value="loaded";return}const o=new Image;o.crossOrigin="anonymous",o.referrerPolicy="no-referrer",o.draggable=false;const c=new Promise((C,b)=>{o.onload=()=>C(),o.onerror=()=>b(new Error("Direct load failed")),o.src=e.src}),x=new Promise((C,b)=>{setTimeout(()=>b(new Error("Timeout")),3e3)});try{await Promise.race([c,x]),t.value=e.src,a.value="loaded",ae(e.channelKey,e.src).catch(C=>{console.warn("异步缓存头像失败:",C)})}catch{await l()}}catch(r){console.error("头像加载失败:",r),a.value="error",n.value="头像加载失败"}},l=async()=>{try{a.value="caching";const r=await ae(e.channelKey,e.src);if(r)t.value=r,a.value="loaded";else throw new Error("缓存系统加载失败")}catch(r){console.error("缓存系统加载头像失败:",r),a.value="error",n.value=(r==null?void 0:r.message)||"缓存加载失败"}};return Se(()=>{s()}),()=>{switch(a.value){case"loading":case"caching":return d("div",{class:"avatar-placeholder"},e.alt.charAt(0).toUpperCase());case"loaded":return d("img",{src:t.value,alt:e.alt,draggable:false,style:{width:"100%",height:"100%","object-fit":"cover"}});case"error":return d("div",{class:"avatar-placeholder"},e.alt.charAt(0).toUpperCase());default:return d("div",{class:"avatar-placeholder"},e.alt.charAt(0).toUpperCase())}}}}),W=Z({props:{src:{type:String,required:true},alt:{type:String,default:"图片"},filename:{type:String,default:""},channelKey:{type:String,required:true}},setup(e){const a=v("loading"),t=v(e.src),n=v(""),s=v(null),l=async()=>{try{a.value="loading";const o=await _e(e.channelKey,e.src);if(o){t.value=o,a.value="loaded";return}const c=new Image;c.crossOrigin="anonymous",c.referrerPolicy="no-referrer",c.draggable=false;const x=new Promise((b,ye)=>{c.onload=()=>b(),c.onerror=()=>ye(new Error("Direct load failed")),c.src=e.src}),C=new Promise((b,ye)=>{setTimeout(()=>ye(new Error("Timeout")),3e3)});try{await Promise.race([x,C]),t.value=e.src,a.value="loaded",ae(e.channelKey,e.src).catch(b=>{console.warn("异步缓存图片失败:",b)})}catch{await r()}}catch(o){console.error("图片加载失败:",o),a.value="error",n.value="图片加载失败"}},r=async()=>{try{a.value="caching";const o=await ae(e.channelKey,e.src);if(o)t.value=o,a.value="loaded";else throw new Error("缓存系统加载失败")}catch(o){console.error("缓存系统加载图片失败:",o),a.value="error",n.value=(o==null?void 0:o.message)||"缓存加载失败"}};return Se(()=>{l()}),()=>{switch(a.value){case"loading":return d("div",{class:"message-image-loading"},"加载中...");case"caching":return d("div",{class:"message-image-loading"},"[图片加载缓存中...]");case"loaded":return d("img",{src:t.value,alt:e.alt,class:"message-image",loading:"lazy",ref:s,draggable:false,style:{"max-width":"400px","max-height":"200px",width:"auto",height:"auto","object-fit":"contain"}});case"error":return d("div",{class:"message-image-error"},["图片加载失败",d("br"),d("small",e.filename||e.alt||"未知图片"),d("br"),d("small",{style:"color: #ff9800;"},n.value)]);default:return d("div",{class:"message-image-error"},"未知状态")}}}}),pe=Z({props:{data:{type:String,required:true},channelKey:{type:String,required:true}},setup(e){const t=(()=>{try{const s=JSON.parse(e.data);if(s.meta&&s.meta.detail_1){const l=s.meta.detail_1;return{type:"share_card",title:l.title||s.prompt||"分享内容",desc:l.desc||"",preview:l.preview?l.preview.replace(/\\\//g,"/"):"",icon:l.icon?l.icon.replace(/\\\//g,"/"):"",url:l.qqdocurl?l.qqdocurl.replace(/\\\//g,"/"):l.url?l.url.replace(/\\\//g,"/"):"",appName:l.title||"应用"}}return{type:"raw",data:s}}catch(s){return console.error("解析JSON数据失败:",s),{type:"error",error:"无法解析的JSON数据"}}})(),n=()=>{t.type==="share_card"&&t.url&&window.open(t.url,"_blank","noopener,noreferrer")};return()=>t.type==="share_card"&&t.preview?d("img",{src:t.preview,alt:t.title||"[分享小程序]",class:"message-image",loading:"lazy",draggable:false,onClick:n,style:{"max-width":"400px","max-height":"200px",width:"auto",height:"auto","object-fit":"contain",cursor:t.url?"pointer":"default"},title:t.url?`点击打开: ${t.title||"链接"}`:t.title,onError:s=>{const r=s.target.parentElement;r&&(r.style.display="none")}}):t.type==="error"?d("div",{class:"message-json-error"},[d("span",{class:"json-error-text"},t.error),d("details",{class:"json-raw-data"},[d("summary","查看原始数据"),d("pre",{class:"json-raw-content"},e.data)])]):d("div",{class:"message-json-raw"},[d("div",{class:"json-label"},"[JSON数据]"),d("details",{class:"json-raw-data"},[d("summary","查看详情"),d("pre",{class:"json-raw-content"},JSON.stringify(t.data,null,2))])])}}),ie=Z({props:{element:{type:Object,required:true},channelKey:{type:String,required:true}},setup(e){const a=t=>{var n,s,l,r,o,c;switch(t.type){case"text":return d("span",{class:"message-text-content"},t.attrs.content||"");case"forward":return d("span",{class:"message-text-content"},`[转发消息 ${t.attrs.id}]`||"[转发消息]");case"img":case"image":const x=t.attrs.src||t.attrs.url||t.attrs.file;return d("div",{class:"message-image-container"},[d(W,{src:x,alt:t.attrs.summary||"图片",filename:t.attrs.filename||t.attrs.summary||"",channelKey:e.channelKey})]);case"mface":const C=t.attrs.src||t.attrs.url||t.attrs.file;return d("div",{class:"message-image-container"},[d(W,{src:C,alt:t.attrs.summary||"表情",filename:t.attrs.emojiId||t.attrs.summary||"",channelKey:e.channelKey})]);case"face":if((s=(n=t.children[0])==null?void 0:n.attrs)!=null&&s.src){const b=((r=(l=t.children[0])==null?void 0:l.attrs)==null?void 0:r.src)||((c=(o=t.children[0])==null?void 0:o.attrs)==null?void 0:c.url);return d("div",{class:"message-image-container"},[d(W,{src:b,alt:t.attrs.name||t.attrs.id||"[表情]",filename:t.attrs.name||t.attrs.id||"[表情]",channelKey:e.channelKey})])}else return d("span",{class:"message-text-content"},`[${t.attrs.name||t.attrs.id}]`||"[表情]");case"at":return d("span",{class:"message-at",title:t.attrs.name},`${t.attrs.name||t.attrs.id}`);case"json":return d("div",{class:"message-image-container"},[d(pe,{data:t.attrs.data||"",channelKey:e.channelKey})]);default:return d("span",{class:"message-unknown",title:`未知消息类型: ${t.type}`},t.attrs.content||`[${t.type}]`)}};return()=>a(e.element)}}),u=v({bots:{},channels:{},messages:{}}),N=v({}),we=v({maxMessagesPerChannel:1e3,keepMessagesOnClear:50,loggerinfo:false,blockedPlatforms:[],chatContainerHeight:80}),$=v({});let k=null;const h=v(""),w=v(""),E=v(""),S=v(false),X=v("bots"),P=v(null),J=v(null),be=v(false),Y=v({show:false,text:""}),I=v(),ee=v(),xe=v(false),ue=v(false),V=v(false),j=v(""),T=v({x:0,y:0}),B=v({x:0,y:0}),Me=v({x:0,y:0}),Ce=v({x:0,y:0}),Ie=v(0),D=v(null),G=v(false),g=v(null),y=v({show:false,x:0,y:0,type:null,targetId:"",isSecondClick:false}),U=v(new Set),O=v(new Set),Ve=q(()=>Object.values(u.value.bots).sort((a,t)=>{const n=U.value.has(a.selfId),s=U.value.has(t.selfId);return n&&!s?-1:!n&&s?1:0})),Ge=q(()=>!h.value||!u.value.channels[h.value]?[]:Object.values(u.value.channels[h.value]).sort((a,t)=>{const n=O.value.has(`${h.value}:${a.id}`),s=O.value.has(`${h.value}:${t.id}`);return n&&!s?-1:!n&&s?1:0})),Te=q(()=>{if(!h.value||!w.value)return[];const e=`${h.value}:${w.value}`,a=u.value.messages[e]||[];return a.filter(t=>t.quote),a}),Qe=q(()=>{var a;if(!h.value||!w.value)return"";const e=u.value.channels[h.value];return((a=e==null?void 0:e[w.value])==null?void 0:a.name)||""}),de=q(()=>!h.value||!w.value?"":`${h.value}:${w.value}`),De=q(()=>h.value&&w.value&&E.value.trim()&&!V.value),Ze=q(()=>h.value&&w.value&&!V.value),Ee=q(()=>{if(!S.value)return"";switch(X.value){case"channels":return"show-channels";case"messages":return"show-messages";default:return""}}),et=q(()=>S.value?"屏幕左滑返回,上滑唤起聊天框":"输入消息..."),tt=q(()=>{if(S.value){const e=we.value.chatContainerHeight||80,a=100-e-19;return{height:`${e}vh`,marginTop:`${a}vh`}}return{}});function at(e){h.value=e,w.value="",S.value&&(X.value="channels")}function nt(e,a){if(e.preventDefault(),e.stopPropagation(),y.value.show&&y.value.type==="bot"&&y.value.targetId===a){A();return}qe(e,"bot",a)}function st(e,a){if(e.preventDefault(),e.stopPropagation(),y.value.show&&y.value.type==="channel"&&y.value.targetId===a){A();return}qe(e,"channel",a)}function qe(e,a,t){let l=e.clientX,r=e.clientY;l+180>window.innerWidth&&(l=window.innerWidth-180-10),r+80>window.innerHeight&&(r=window.innerHeight-80-10),y.value={show:true,x:l,y:r,type:a,targetId:t,isSecondClick:false},document.addEventListener("click",A,{once:true}),document.addEventListener("keydown",Le)}function A(){y.value.show=false,document.removeEventListener("click",A),document.removeEventListener("keydown",Le)}function Le(e){e.key==="Escape"&&y.value.show&&A()}async function lt(e){U.value.has(e)?U.value.delete(e):U.value.add(e),await M("set-pinned-bots",{pinnedBots:Array.from(U.value)}),A()}async function ot(e){const a=`${h.value}:${e}`;O.value.has(a)?O.value.delete(a):O.value.add(a),await M("set-pinned-channels",{pinnedChannels:Array.from(O.value)}),A()}async function rt(e){try{const a=await M("delete-bot-data",{selfId:e});if(a.success){const t=Object.keys(u.value.messages).filter(n=>n.startsWith(`${e}:`));for(const n of t)delete u.value.messages[n],delete N.value[n],await ge(n);delete u.value.bots[e],delete u.value.channels[e],h.value===e&&(h.value="",w.value=""),_(a.message||"已删除该机器人的所有数据","success")}else throw new Error(a.error||"删除失败")}catch(a){console.error("删除机器人数据失败:",a),_("删除失败: "+((a==null?void 0:a.message)||String(a)),"error")}A()}async function ct(e){try{const a=await M("delete-channel-data",{selfId:h.value,channelId:e});if(a.success){const t=`${h.value}:${e}`;delete u.value.messages[t],delete N.value[t],u.value.channels[h.value]&&delete u.value.channels[h.value][e],await ge(t),w.value===e&&(w.value=""),_(a.message||"已删除该频道的所有数据","success")}else throw new Error(a.error||"删除失败")}catch(a){console.error("删除频道数据失败:",a),_("删除失败: "+((a==null?void 0:a.message)||String(a)),"error")}A()}async function it(e){w.value=e,ue.value=false,S.value&&(X.value="messages"),h.value&&await Ct(h.value,e),se(()=>{te(),!S.value&&ee.value&&ee.value.focus()})}async function Ke(){if(!De.value)return;const e=E.value.trim();if(e){V.value=true;try{const a=await M("send-message",{selfId:h.value,channelId:w.value,content:e});a.success?E.value="":(console.error("消息发送失败:",a.error),_("发送失败: "+a.error,"error"))}catch(a){console.error("发送消息时出错:",a),_("发送失败: "+((a==null?void 0:a.message)||String(a)),"error")}finally{V.value=false}}}function Ne(e){return new Date(e).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"})}function ut(e){if(typeof e=="number")switch(e){case 0:return"文本";case 1:return"私聊";default:return"未知"}return String(e)}function te(){I.value&&(I.value.scrollTop=I.value.scrollHeight,xe.value=false,ue.value=false)}function ve(){if(I.value){const{scrollTop:e,scrollHeight:a,clientHeight:t}=I.value,s=a-(e+t)<=50,l=!s;xe.value=l,s?ue.value=false:ue.value=true}}function Pe(){if(!I.value)return true;const{scrollTop:e,scrollHeight:a,clientHeight:t}=I.value;return a-(e+t)<=200}function ke(e){var n;if(!h.value)return 0;const a=`${h.value}:${e}`,t=N.value[a];return t!==void 0?t:((n=u.value.messages[a])==null?void 0:n.length)||0}function je(e,a){e.preventDefault(),e.stopPropagation();const t="touches"in e?e.touches[0].clientX:e.clientX,n="touches"in e?e.touches[0].clientY:e.clientY;Ie.value=Date.now(),T.value={x:t,y:n},B.value={x:t,y:n},G.value=false;const l=e.target.getBoundingClientRect();Me.value={x:l.left,y:l.top},Ce.value={x:t-l.left,y:n-l.top},D.value=window.setTimeout(()=>{if(Ie.value>0){G.value=true,j.value=a;const r=e.target,o=r.cloneNode(true);o.classList.add("dragging-clone"),o.style.position="fixed",o.style.zIndex="1000",o.style.pointerEvents="none";const c=r.getBoundingClientRect();o.style.left=`${c.left}px`,o.style.top=`${c.top}px`,o.style.width=`${c.width}px`,o.style.height=`${c.height}px`,document.body.appendChild(o),g.value=o,document.body.style.userSelect="none",document.body.style.cursor="grabbing",document.body.classList.add("dragging-bubble-global"),ht(T.value.x,T.value.y)}},60),document.addEventListener("mousemove",he),document.addEventListener("mouseup",fe),document.addEventListener("touchmove",he),document.addEventListener("touchend",fe)}function he(e){if(!G.value||!g.value)return;e.preventDefault();const a="touches"in e?e.touches[0].clientX:e.clientX,t="touches"in e?e.touches[0].clientY:e.clientY;B.value={x:a,y:t};const n=B.value.x-T.value.x,s=B.value.y-T.value.y,l=Math.sqrt(n*n+s*s),r=Math.max(.3,1-l/(K*2)),o=Math.max(.8,1-l/(K*3)),c=l>K,x=B.value.x-Ce.value.x,C=B.value.y-Ce.value.y;g.value.style.left=`${x}px`,g.value.style.top=`${C}px`,g.value.style.transform=`scale(${o})`,g.value.style.opacity=`${r}`,g.value.style.backgroundColor=c?"#f44336":"#2196f3",g.value.style.boxShadow=c?"0 4px 12px rgba(244, 67, 54, 0.4)":"0 4px 12px rgba(33, 150, 243, 0.4)",c?g.value.classList.add("will-delete"):g.value.classList.remove("will-delete")}function fe(e){if(D.value&&(clearTimeout(D.value),D.value=null),D.value&&(clearTimeout(D.value),D.value=null),!G.value||!j.value){me();return}const a=j.value;if(Math.sqrt(Math.pow(B.value.x-T.value.x,2)+Math.pow(B.value.y-T.value.y,2))>K)vt(a),me();else if(g.value){g.value.style.transition="all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55)";const n=document.querySelector(`[data-channel-id="${a}"] .channel-message-count`);if(n){const s=n.getBoundingClientRect();g.value.style.left=`${s.left}px`,g.value.style.top=`${s.top}px`,g.value.style.transform="scale(1)",g.value.style.opacity="1",g.value.style.backgroundColor="#2196f3",g.value.style.boxShadow="0 4px 12px rgba(33, 150, 243, 0.4)"}setTimeout(()=>{me()},300)}else me()}function me(){D.value&&(clearTimeout(D.value),D.value=null),j.value="",T.value={x:0,y:0},B.value={x:0,y:0},Me.value={x:0,y:0},Ie.value=0,G.value=false,document.removeEventListener("mousemove",he),document.removeEventListener("mouseup",fe),document.removeEventListener("touchmove",he),document.removeEventListener("touchend",fe),document.body.style.userSelect="",document.body.style.cursor="",document.body.classList.remove("dragging-bubble-global"),g.value&&g.value.parentNode&&(g.value.parentNode.removeChild(g.value),g.value=null),ft()}function dt(e){return j.value===e&&G.value?{visibility:"hidden",pointerEvents:"none",transition:"none"}:{}}function Ue(e){if(j.value!==e)return 0;const a=B.value.x-T.value.x,t=B.value.y-T.value.y;return Math.sqrt(a*a+t*t)}async function vt(e){if(h.value)try{const a=`${h.value}:${e}`,t=ke(e),n=we.value.keepMessagesOnClear;if(n>0&&t<=n){_("当前消息还很少诶~ 无需清理","success");return}const s=await M("clear-channel-history",{selfId:h.value,channelId:e});if(s.success)if(s.clearedCount&&s.clearedCount>0){if(u.value.messages[a]){const r=[...u.value.messages[a]].sort((o,c)=>o.timestamp-c.timestamp);u.value.messages[a]=r.slice(-s.keptCount)}N.value[a]=s.keptCount,await ge(a),_(`历史记录已清理,清理了 ${s.clearedCount} 条消息,保留最新 ${s.keptCount} 条`,"success")}else n===0?(u.value.messages[a]&&(u.value.messages[a]=[]),N.value[a]=0,await ge(a),_("历史记录已清理,所有消息已删除","success")):_("当前消息还很少诶~ 无需清理","success");else console.error("清理历史记录失败:",s.error),_("清理失败: "+s.error,"error")}catch(a){console.error("清理历史记录时出错:",a),_("清理失败: "+((a==null?void 0:a.message)||String(a)),"error")}}function _(e,a="success"){const t=document.createElement("div");t.className=`notification ${a}`,t.textContent=e;let n="#4caf50";switch(a){case"info":n="#2196f3";break;case"warn":n="#ff9800";break;case"error":n="#f44336";break;case"success":n="#4caf50";break}t.style.cssText=`
|
|
1
|
+
import{defineComponent as Q,ref as f,onMounted as Ne,h as d,computed as O,watch as nt,nextTick as re,onUnmounted as Gt,createElementBlock as p,openBlock as v,normalizeStyle as Oe,normalizeClass as F,createElementVNode as c,createCommentVNode as G,Fragment as P,renderList as oe,createBlock as he,unref as me,toDisplayString as x,withDirectives as st,createTextVNode as Pe,vShow as Qt,withModifiers as lt,withKeys as Zt,vModelText as Et,resolveComponent as ea}from"vue";import{receive as Re,send as _,icons as ta}from"@koishijs/client";const aa={class:"bot-list"},na={class:"bot-items"},sa=["onClick","onContextmenu"],la={class:"bot-avatar"},ra={key:1,class:"avatar-placeholder"},oa={class:"bot-info"},ca={class:"bot-name"},ia={class:"bot-platform"},ua={class:"channel-list"},da={key:0,class:"empty-state"},fa={key:1,class:"channel-items"},ha=["data-channel-id","onClick","onContextmenu"],ma={class:"channel-info"},va={class:"channel-name"},ga={class:"channel-type"},ya=["onMousedown","onTouchstart","title"],pa={class:"message-area"},wa={class:"panel-header"},Ia={key:0,class:"empty-state"},xa={key:1,class:"message-content"},Ca={class:"message-avatar"},ka={key:1,class:"avatar-placeholder"},ba={class:"message-content-wrapper"},_a={class:"message-header"},$a={class:"message-username"},Sa={class:"message-time"},Ba={key:0,class:"message-quote"},La={class:"quote-header"},Ta={class:"quote-avatar"},qa={key:1,class:"avatar-placeholder"},Da={class:"quote-username"},Ua={class:"quote-time"},ja={class:"quote-content"},Ka={class:"message-text"},Na={class:"message-input"},Oa={key:0,class:"image-preview-container"},Pa=["src","alt"],Ra=["onClick"],Aa={class:"input-row"},Ma={class:"input-actions"},za=["placeholder","disabled"],Xa=["disabled"],rt=200,Ha=100*1024*1024,Ae=50,Fa="ChatImageCache",Ya=1,R="images",A=80,Wa=Q({__name:"index",setup(Z){function Y(e){try{return new URL(e).protocol==="file:"}catch{return false}}const E=Q({props:{src:{type:String,required:true},alt:{type:String,default:"头像"},channelKey:{type:String,required:true}},setup(e){const a=f("loading"),t=f(e.src),n=f(""),l=async()=>{try{a.value="loading";const o=await je(e.channelKey,e.src);if(o){t.value=o,a.value="loaded";return}const r=new Image;r.crossOrigin="anonymous",r.referrerPolicy="no-referrer",r.draggable=false;const i=new Promise((g,y)=>{r.onload=()=>g(),r.onerror=()=>y(new Error("Direct load failed")),r.src=e.src}),h=new Promise((g,y)=>{setTimeout(()=>y(new Error("Timeout")),3e3)});try{await Promise.race([i,h]),t.value=e.src,a.value="loaded",se(e.channelKey,e.src).catch(g=>{console.warn("异步缓存头像失败:",g)})}catch{await s()}}catch(o){console.error("头像加载失败:",o),a.value="error",n.value="头像加载失败"}},s=async()=>{try{a.value="caching";const o=await se(e.channelKey,e.src);if(o)t.value=o,a.value="loaded";else throw new Error("缓存系统加载失败")}catch(o){console.error("缓存系统加载头像失败:",o),a.value="error",n.value=(o==null?void 0:o.message)||"缓存加载失败"}};return Ne(()=>{l()}),()=>{switch(a.value){case"loading":case"caching":return d("div",{class:"avatar-placeholder"},e.alt.charAt(0).toUpperCase());case"loaded":return d("img",{src:t.value,alt:e.alt,draggable:false,style:{width:"100%",height:"100%","object-fit":"cover"}});case"error":return d("div",{class:"avatar-placeholder"},e.alt.charAt(0).toUpperCase());default:return d("div",{class:"avatar-placeholder"},e.alt.charAt(0).toUpperCase())}}}}),ce=Q({props:{src:{type:String,required:true},alt:{type:String,default:"图片"},filename:{type:String,default:""},channelKey:{type:String,required:true}},setup(e){const a=f("loading"),t=f(e.src),n=f(""),l=f(null),s=async()=>{try{a.value="loading";const r=await je(e.channelKey,e.src);if(r){t.value=r,a.value="loaded";return}if(Y(e.src)){console.log("ImageComponent: 检测到本地文件,使用代理请求:",e.src),await o();return}const i=new Image;i.crossOrigin="anonymous",i.referrerPolicy="no-referrer",i.draggable=false;const h=new Promise((y,q)=>{i.onload=()=>y(),i.onerror=()=>q(new Error("Direct load failed")),i.src=e.src}),g=new Promise((y,q)=>{setTimeout(()=>q(new Error("Timeout")),3e3)});try{await Promise.race([h,g]),t.value=e.src,a.value="loaded",se(e.channelKey,e.src).catch(y=>{console.warn("异步缓存图片失败:",y)})}catch{await o()}}catch(r){console.error("图片加载失败:",r),a.value="error",n.value="图片加载失败"}},o=async()=>{try{a.value="caching";const r=await se(e.channelKey,e.src);if(r)t.value=r,a.value="loaded";else throw new Error("缓存系统加载失败")}catch(r){console.error("缓存系统加载图片失败:",r),a.value="error",n.value=(r==null?void 0:r.message)||"缓存加载失败"}};return Ne(()=>{s()}),()=>{switch(a.value){case"loading":return d("div",{class:"message-image-loading"},"加载中...");case"caching":return d("div",{class:"message-image-loading"},"[图片加载缓存中...]");case"loaded":return d("img",{src:t.value,alt:e.alt,class:"message-image",loading:"lazy",ref:l,draggable:false,style:{"max-width":"400px","max-height":"200px",width:"auto",height:"auto","object-fit":"contain"}});case"error":return d("div",{class:"message-image-error"},["图片加载失败",d("br"),d("small",e.filename||e.alt||"未知图片"),d("br"),d("small",{style:"color: #ff9800;"},n.value)]);default:return d("div",{class:"message-image-error"},"未知状态")}}}}),be=Q({props:{data:{type:String,required:true},channelKey:{type:String,required:true}},setup(e){const t=(()=>{try{const l=JSON.parse(e.data);if(l.meta&&l.meta.detail_1){const s=l.meta.detail_1;return{type:"share_card",title:s.title||l.prompt||"分享内容",desc:s.desc||"",preview:s.preview?s.preview.replace(/\\\//g,"/"):"",icon:s.icon?s.icon.replace(/\\\//g,"/"):"",url:s.qqdocurl?s.qqdocurl.replace(/\\\//g,"/"):s.url?s.url.replace(/\\\//g,"/"):"",appName:s.title||"应用"}}return{type:"raw",data:l}}catch(l){return console.error("解析JSON数据失败:",l),{type:"error",error:"无法解析的JSON数据"}}})(),n=()=>{t.type==="share_card"&&t.url&&window.open(t.url,"_blank","noopener,noreferrer")};return()=>t.type==="share_card"&&t.preview?d("img",{src:t.preview,alt:t.title||"[分享小程序]",class:"message-image",loading:"lazy",draggable:false,onClick:n,style:{"max-width":"400px","max-height":"200px",width:"auto",height:"auto","object-fit":"contain",cursor:t.url?"pointer":"default"},title:t.url?`点击打开: ${t.title||"链接"}`:t.title,onError:l=>{const o=l.target.parentElement;o&&(o.style.display="none")}}):t.type==="error"?d("div",{class:"message-json-error"},[d("span",{class:"json-error-text"},t.error),d("details",{class:"json-raw-data"},[d("summary","查看原始数据"),d("pre",{class:"json-raw-content"},e.data)])]):d("div",{class:"message-json-raw"},[d("div",{class:"json-label"},"[JSON数据]"),d("details",{class:"json-raw-data"},[d("summary","查看详情"),d("pre",{class:"json-raw-content"},JSON.stringify(t.data,null,2))])])}}),ct=Q({props:{element:{type:Object,required:true},channelKey:{type:String,required:true}},setup(e){const a=f(false),t=()=>{a.value=!a.value},n=()=>{if(!e.element.children||e.element.children.length===0)return{previews:[],messageCount:0};const s=e.element.children.filter(i=>i.type==="message"),o=s.length;return{previews:s.slice(0,3).map(i=>{var y,q;const h=((y=i.attrs)==null?void 0:y.nickname)||"用户";let g="";if(i.children&&i.children.length>0){const B=i.children[0];B.type==="text"?(g=(((q=B.attrs)==null?void 0:q.content)||"").substring(0,20),g.length>15&&(g+="...")):B.type==="img"?g="[图片]":B.type==="video"?g="[视频]":g=`[${B.type}]`}return`${h}:${g}`}),messageCount:o}},l=(s,o)=>{var h,g,y;const r=((h=s.attrs)==null?void 0:h.nickname)||"用户",i=((g=s.attrs)==null?void 0:g.userId)||"unknown";return d("div",{key:o,class:"forwarded-message-item"},[d("div",{class:"forwarded-message-header"},[d("span",{class:"forwarded-message-nickname"},r),d("span",{class:"forwarded-message-userid"},`(${i})`)]),d("div",{class:"forwarded-message-content"},((y=s.children)==null?void 0:y.map((q,B)=>d(ve,{key:B,element:q,channelKey:e.channelKey})))||[])])};return()=>{var r;const{previews:s,messageCount:o}=n();return d("div",{class:"forward-message-container"},[d("div",{class:"forward-message-preview",onClick:t},[d("div",{class:"forward-message-title"},"聊天记录"),...s.map((i,h)=>d("div",{key:h,class:"forward-message-preview-item"},i)),d("div",{class:"forward-message-footer"},[d("span",{class:"forward-message-count"},`查看${o}条转发消息`),d("span",{class:"forward-message-toggle"},a.value?"▲":"▼")])]),a.value&&d("div",{class:"forward-message-expanded"},((r=e.element.children)==null?void 0:r.filter(i=>i.type==="message").map((i,h)=>l(i,h)))||[])])}}}),ve=Q({props:{element:{type:Object,required:true},channelKey:{type:String,required:true}},setup(e){const a=t=>{var n,l,s,o,r,i;switch(t.type){case"text":return d("span",{class:"message-text-content"},t.attrs.content||"");case"forward":return d("span",{class:"message-text-content"},`[转发消息 ${t.attrs.id}]`||"[转发消息]");case"img":case"image":const h=t.attrs.src||t.attrs.url||t.attrs.file;return h&&Y(h)?console.log("检测到本地文件路径:",h):h!=null&&h.startsWith("http")?console.log("检测到网络图片:",h):console.log("检测到其他类型图片URL:",h),d("div",{class:"message-image-container"},[d(ce,{src:h,alt:t.attrs.summary||"图片",filename:t.attrs.filename||t.attrs.summary||"",channelKey:e.channelKey})]);case"mface":const g=t.attrs.src||t.attrs.url||t.attrs.file;return g&&Y(g)&&console.log("检测到本地表情文件路径:",g),d("div",{class:"message-image-container"},[d(ce,{src:g,alt:t.attrs.summary||"表情",filename:t.attrs.emojiId||t.attrs.summary||"",channelKey:e.channelKey})]);case"face":if((l=(n=t.children[0])==null?void 0:n.attrs)!=null&&l.src){const y=((o=(s=t.children[0])==null?void 0:s.attrs)==null?void 0:o.src)||((i=(r=t.children[0])==null?void 0:r.attrs)==null?void 0:i.url);return d("div",{class:"message-image-container"},[d(ce,{src:y,alt:t.attrs.name||t.attrs.id||"[表情]",filename:t.attrs.name||t.attrs.id||"[表情]",channelKey:e.channelKey})])}else return d("span",{class:"message-text-content"},`[${t.attrs.name||t.attrs.id}]`||"[表情]");case"at":return d("span",{class:"message-at",title:t.attrs.name},`${t.attrs.name||t.attrs.id}`);case"json":return d("div",{class:"message-image-container"},[d(be,{data:t.attrs.data||"",channelKey:e.channelKey})]);case"p":if(t.children&&t.children.length>0){const y=t.children.map((q,B)=>d(ve,{key:B,element:q,channelKey:e.channelKey}));return d("div",{class:"message-paragraph"},y)}else return d("div",{class:"message-paragraph"},"");case"figure":return d(ct,{element:t,channelKey:e.channelKey});default:return d("span",{class:"message-unknown",title:`未知消息类型: ${t.type}`},t.attrs.content||`[${t.type}]`)}};return()=>a(e.element)}}),u=f({bots:{},channels:{},messages:{}}),D=f({}),ie=f({maxMessagesPerChannel:1e3,keepMessagesOnClear:50,loggerinfo:false,blockedPlatforms:[],chatContainerHeight:80}),b=f({});let _e=0;function Me(e){return e.size||0}function ge(e){_e+=e,ie.value.loggerinfo&&console.log(`内存使用量变化: ${e>0?"+":""}${(e/1024/1024).toFixed(2)}MB, 总计: ${(_e/1024/1024).toFixed(2)}MB`)}function ze(e=10){const a=Object.entries(b.value);if(a.length<=e)return;const t=a.slice(0,a.length-e);let n=0;t.forEach(([l,s])=>{URL.revokeObjectURL(s),delete b.value[l],n+=500*1024,ie.value.loggerinfo&&console.log("清理旧blob URL:",l)}),ge(-n)}function $e(){Object.keys(b.value).length>Ae&&ze(Math.floor(Ae*.7)),_e>Ha&&ze(Math.floor(Ae*.5))}let S=null;const m=f(""),C=f(""),ue=f(""),U=f([]),J=f(false),Se=f(),L=f(false),W=f("bots"),M=f(null),ee=f(null),Be=f(false),V=f({show:false,text:""}),$=f(),de=f(),Le=f(false),ye=f(false),te=f(false),z=f(""),j=f({x:0,y:0}),T=f({x:0,y:0}),Xe=f({x:0,y:0}),Te=f({x:0,y:0}),qe=f(0),K=f(null),ae=f(false),w=f(null),I=f({show:false,x:0,y:0,type:null,targetId:"",isSecondClick:false}),X=f(new Set),H=f(new Set),it=O(()=>Object.values(u.value.bots).sort((a,t)=>{const n=X.value.has(a.selfId),l=X.value.has(t.selfId);return n&&!l?-1:!n&&l?1:0})),ut=O(()=>!m.value||!u.value.channels[m.value]?[]:Object.values(u.value.channels[m.value]).sort((a,t)=>{const n=H.value.has(`${m.value}:${a.id}`),l=H.value.has(`${m.value}:${t.id}`);return n&&!l?-1:!n&&l?1:0})),He=O(()=>{if(!m.value||!C.value)return[];const e=`${m.value}:${C.value}`,a=u.value.messages[e]||[];return a.filter(t=>t.quote),a}),dt=O(()=>{var a;if(!m.value||!C.value)return"";const e=u.value.channels[m.value];return((a=e==null?void 0:e[C.value])==null?void 0:a.name)||""}),pe=O(()=>!m.value||!C.value?"":`${m.value}:${C.value}`),Fe=O(()=>m.value&&C.value&&(ue.value.trim()||U.value.length>0)&&!te.value),ft=O(()=>m.value&&C.value&&!te.value),ht=O(()=>{if(!L.value)return"";switch(W.value){case"channels":return"show-channels";case"messages":return"show-messages";default:return""}}),mt=O(()=>L.value?"输入消息...(屏幕左滑返回)":"输入消息..."),vt=O(()=>{if(L.value){const e=ie.value.chatContainerHeight||80,a=100-e-19;return{height:`${e}vh`,marginTop:`${a}vh`}}return{}});function gt(e){m.value=e,C.value="",L.value&&(W.value="channels")}function yt(e,a){if(e.preventDefault(),e.stopPropagation(),I.value.show&&I.value.type==="bot"&&I.value.targetId===a){N();return}Ye(e,"bot",a)}function pt(e,a){if(e.preventDefault(),e.stopPropagation(),I.value.show&&I.value.type==="channel"&&I.value.targetId===a){N();return}Ye(e,"channel",a)}function Ye(e,a,t){let s=e.clientX,o=e.clientY;s+180>window.innerWidth&&(s=window.innerWidth-180-10),o+80>window.innerHeight&&(o=window.innerHeight-80-10),I.value={show:true,x:s,y:o,type:a,targetId:t,isSecondClick:false},document.addEventListener("click",N,{once:true}),document.addEventListener("keydown",We)}function N(){I.value.show=false,document.removeEventListener("click",N),document.removeEventListener("keydown",We)}function We(e){e.key==="Escape"&&I.value.show&&N()}async function wt(e){X.value.has(e)?X.value.delete(e):X.value.add(e),await _("set-pinned-bots",{pinnedBots:Array.from(X.value)}),N()}async function It(e){const a=`${m.value}:${e}`;H.value.has(a)?H.value.delete(a):H.value.add(a),await _("set-pinned-channels",{pinnedChannels:Array.from(H.value)}),N()}async function xt(e){try{const a=await _("delete-bot-data",{selfId:e});if(a.success){const t=Object.keys(u.value.messages).filter(n=>n.startsWith(`${e}:`));for(const n of t)delete u.value.messages[n],delete D.value[n],await ke(n);delete u.value.bots[e],delete u.value.channels[e],m.value===e&&(m.value="",C.value=""),k(a.message||"已删除该机器人的所有数据","success")}else throw new Error(a.error||"删除失败")}catch(a){console.error("删除机器人数据失败:",a),k("删除失败: "+((a==null?void 0:a.message)||String(a)),"error")}N()}async function Ct(e){try{const a=await _("delete-channel-data",{selfId:m.value,channelId:e});if(a.success){const t=`${m.value}:${e}`;delete u.value.messages[t],delete D.value[t],u.value.channels[m.value]&&delete u.value.channels[m.value][e],await ke(t),C.value===e&&(C.value=""),k(a.message||"已删除该频道的所有数据","success")}else throw new Error(a.error||"删除失败")}catch(a){console.error("删除频道数据失败:",a),k("删除失败: "+((a==null?void 0:a.message)||String(a)),"error")}N()}async function kt(e){C.value=e,ye.value=false,L.value&&(W.value="messages"),m.value&&await Xt(m.value,e),re(()=>{ne(),!L.value&&de.value&&de.value.focus()})}async function Je(){if(!Fe.value)return;const e=ue.value.trim();if(!e&&U.value.length===0)return;te.value=true;const a=[...U.value];try{const t=await _("send-message",{selfId:m.value,channelId:C.value,content:e,images:a.map(n=>({tempId:n.tempId,filename:n.filename}))});if(t.success){if(ue.value="",a.forEach(n=>{URL.revokeObjectURL(n.preview)}),U.value=[],J.value=false,t.tempImageIds&&t.tempImageIds.length>0)try{await _("cleanup-temp-images",{tempImageIds:t.tempImageIds}),console.log("临时图片清理完成:",t.tempImageIds)}catch(n){console.warn("清理临时图片失败:",n)}}else console.error("消息发送失败:",t.error),k("发送失败: "+t.error,"error")}catch(t){console.error("发送消息时出错:",t),k("发送失败: "+((t==null?void 0:t.message)||String(t)),"error")}finally{te.value=false}}function bt(){J.value=!J.value}function _t(){Se.value&&Se.value.click(),J.value=false}async function $t(e){const a=e.target,t=a.files;if(!(!t||t.length===0)){for(const n of Array.from(t))await Ve(n);a.value=""}}async function St(e){var t;const a=(t=e.clipboardData)==null?void 0:t.items;if(a){for(const n of Array.from(a))if(n.type.startsWith("image/")){e.preventDefault();const l=n.getAsFile();l&&await Ve(l)}}}async function Ve(e){try{if(e.size>10*1024*1024){k("图片文件过大,请选择小于10MB的图片","error");return}if(!e.type.startsWith("image/")){k("请选择图片文件","error");return}const a=await Lt(e),t=URL.createObjectURL(e),n=await _("upload-image",{file:a,filename:e.name,mimeType:e.type});n.success?U.value.push({tempId:n.tempId,filename:e.name,preview:t,size:e.size}):(URL.revokeObjectURL(t),k("图片上传失败: "+n.error,"error"))}catch(a){console.error("上传图片失败:",a),k("图片上传失败: "+((a==null?void 0:a.message)||String(a)),"error")}}async function Bt(e){try{const a=U.value.findIndex(t=>t.tempId===e);if(a!==-1){const t=U.value[a];URL.revokeObjectURL(t.preview),U.value.splice(a,1)}await _("delete-temp-image",{tempId:e})}catch(a){console.error("删除图片失败:",a)}}function Lt(e){return new Promise((a,t)=>{const n=new FileReader;n.onload=()=>a(n.result),n.onerror=t,n.readAsDataURL(e)})}function Ge(e){const a=e.target;a.closest(".input-actions")||(J.value=false),a.closest(".context-menu")||N()}function Qe(e){return new Date(e).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"})}function Tt(e){if(typeof e=="number")switch(e){case 0:return"文本";case 1:return"私聊";default:return"未知"}return String(e)}function ne(){$.value&&($.value.scrollTop=$.value.scrollHeight,Le.value=false,ye.value=false)}function we(){if($.value){const{scrollTop:e,scrollHeight:a,clientHeight:t}=$.value,l=a-(e+t)<=50,s=!l;Le.value=s,l?ye.value=false:ye.value=true}}function De(){if(!$.value)return true;const{scrollTop:e,scrollHeight:a,clientHeight:t}=$.value;return a-(e+t)<=200}function Ue(e){var n;if(!m.value)return 0;const a=`${m.value}:${e}`,t=D.value[a];return t!==void 0?t:((n=u.value.messages[a])==null?void 0:n.length)||0}function Ze(e,a){e.preventDefault(),e.stopPropagation();const t="touches"in e?e.touches[0].clientX:e.clientX,n="touches"in e?e.touches[0].clientY:e.clientY;qe.value=Date.now(),j.value={x:t,y:n},T.value={x:t,y:n},ae.value=false;const s=e.target.getBoundingClientRect();Xe.value={x:s.left,y:s.top},Te.value={x:t-s.left,y:n-s.top},K.value=window.setTimeout(()=>{if(qe.value>0){ae.value=true,z.value=a;const o=e.target,r=o.cloneNode(true);r.classList.add("dragging-clone"),r.style.position="fixed",r.style.zIndex="1000",r.style.pointerEvents="none";const i=o.getBoundingClientRect();r.style.left=`${i.left}px`,r.style.top=`${i.top}px`,r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,document.body.appendChild(r),w.value=r,document.body.style.userSelect="none",document.body.style.cursor="grabbing",document.body.classList.add("dragging-bubble-global"),Ut(j.value.x,j.value.y)}},60),document.addEventListener("mousemove",Ie),document.addEventListener("mouseup",xe),document.addEventListener("touchmove",Ie),document.addEventListener("touchend",xe)}function Ie(e){if(!ae.value||!w.value)return;e.preventDefault();const a="touches"in e?e.touches[0].clientX:e.clientX,t="touches"in e?e.touches[0].clientY:e.clientY;T.value={x:a,y:t};const n=T.value.x-j.value.x,l=T.value.y-j.value.y,s=Math.sqrt(n*n+l*l),o=Math.max(.3,1-s/(A*2)),r=Math.max(.8,1-s/(A*3)),i=s>A,h=T.value.x-Te.value.x,g=T.value.y-Te.value.y;w.value.style.left=`${h}px`,w.value.style.top=`${g}px`,w.value.style.transform=`scale(${r})`,w.value.style.opacity=`${o}`,w.value.style.backgroundColor=i?"#f44336":"#2196f3",w.value.style.boxShadow=i?"0 4px 12px rgba(244, 67, 54, 0.4)":"0 4px 12px rgba(33, 150, 243, 0.4)",i?w.value.classList.add("will-delete"):w.value.classList.remove("will-delete")}function xe(e){if(K.value&&(clearTimeout(K.value),K.value=null),K.value&&(clearTimeout(K.value),K.value=null),!ae.value||!z.value){Ce();return}const a=z.value;if(Math.sqrt(Math.pow(T.value.x-j.value.x,2)+Math.pow(T.value.y-j.value.y,2))>A)Dt(a),Ce();else if(w.value){w.value.style.transition="all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55)";const n=document.querySelector(`[data-channel-id="${a}"] .channel-message-count`);if(n){const l=n.getBoundingClientRect();w.value.style.left=`${l.left}px`,w.value.style.top=`${l.top}px`,w.value.style.transform="scale(1)",w.value.style.opacity="1",w.value.style.backgroundColor="#2196f3",w.value.style.boxShadow="0 4px 12px rgba(33, 150, 243, 0.4)"}setTimeout(()=>{Ce()},300)}else Ce()}function Ce(){K.value&&(clearTimeout(K.value),K.value=null),z.value="",j.value={x:0,y:0},T.value={x:0,y:0},Xe.value={x:0,y:0},qe.value=0,ae.value=false,document.removeEventListener("mousemove",Ie),document.removeEventListener("mouseup",xe),document.removeEventListener("touchmove",Ie),document.removeEventListener("touchend",xe),document.body.style.userSelect="",document.body.style.cursor="",document.body.classList.remove("dragging-bubble-global"),w.value&&w.value.parentNode&&(w.value.parentNode.removeChild(w.value),w.value=null),jt()}function qt(e){return z.value===e&&ae.value?{visibility:"hidden",pointerEvents:"none",transition:"none"}:{}}function Ee(e){if(z.value!==e)return 0;const a=T.value.x-j.value.x,t=T.value.y-j.value.y;return Math.sqrt(a*a+t*t)}async function Dt(e){if(m.value)try{const a=`${m.value}:${e}`,t=Ue(e),n=ie.value.keepMessagesOnClear;if(n>0&&t<=n){k("当前消息还很少诶~ 无需清理","success");return}const l=await _("clear-channel-history",{selfId:m.value,channelId:e});if(l.success)if(l.clearedCount&&l.clearedCount>0){if(u.value.messages[a]){const o=[...u.value.messages[a]].sort((r,i)=>r.timestamp-i.timestamp);u.value.messages[a]=o.slice(-l.keptCount)}D.value[a]=l.keptCount,await ke(a),k(`历史记录已清理,清理了 ${l.clearedCount} 条消息,保留最新 ${l.keptCount} 条`,"success")}else n===0?(u.value.messages[a]&&(u.value.messages[a]=[]),D.value[a]=0,await ke(a),k("历史记录已清理,所有消息已删除","success")):k("当前消息还很少诶~ 无需清理","success");else console.error("清理历史记录失败:",l.error),k("清理失败: "+l.error,"error")}catch(a){console.error("清理历史记录时出错:",a),k("清理失败: "+((a==null?void 0:a.message)||String(a)),"error")}}function k(e,a="success"){const t=document.createElement("div");t.className=`notification ${a}`,t.textContent=e;let n="#4caf50";switch(a){case"info":n="#2196f3";break;case"warn":n="#ff9800";break;case"error":n="#f44336";break;case"success":n="#4caf50";break}t.style.cssText=`
|
|
2
2
|
position: fixed;
|
|
3
3
|
top: 20px;
|
|
4
4
|
right: 20px;
|
|
@@ -10,7 +10,7 @@ import{defineComponent as Z,ref as v,onMounted as Se,h as d,computed as q,watch
|
|
|
10
10
|
animation: slideIn 0.3s ease-out;
|
|
11
11
|
background: ${n};
|
|
12
12
|
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
|
13
|
-
`;const
|
|
13
|
+
`;const l=document.createElement("style");l.textContent=`
|
|
14
14
|
@keyframes slideIn {
|
|
15
15
|
from { transform: translateX(100%); opacity: 0; }
|
|
16
16
|
to { transform: translateX(0); opacity: 1; }
|
|
@@ -19,9 +19,9 @@ import{defineComponent as Z,ref as v,onMounted as Se,h as d,computed as q,watch
|
|
|
19
19
|
from { transform: translateX(0); opacity: 1; }
|
|
20
20
|
to { transform: translateX(100%); opacity: 0; }
|
|
21
21
|
}
|
|
22
|
-
`,document.head.appendChild(
|
|
23
|
-
left: ${e-
|
|
24
|
-
top: ${a-
|
|
25
|
-
width: ${
|
|
26
|
-
height: ${
|
|
27
|
-
`,document.body.appendChild(t),window.dragThresholdCircle=t}function ft(){const e=window.dragThresholdCircle;e&&e.parentNode&&(e.parentNode.removeChild(e),window.dragThresholdCircle=null)}async function mt(){return new Promise((e,a)=>{const t=indexedDB.open(ba,xa);t.onerror=()=>{console.error("IndexedDB初始化失败:",t.error),e(false)},t.onsuccess=()=>{k=t.result,e(true)},t.onupgradeneeded=n=>{const s=n.target.result;if(!s.objectStoreNames.contains(L)){const l=s.createObjectStore(L,{keyPath:"url"});l.createIndex("channelKey","channelKey",{unique:false}),l.createIndex("timestamp","timestamp",{unique:false})}}})}async function gt(e){return k?new Promise((a,t)=>{const l=k.transaction([L],"readonly").objectStore(L).get(e);l.onsuccess=()=>{a(l.result||null)},l.onerror=()=>{console.error("从IndexedDB获取图片失败:",l.error),a(null)}}):null}async function Oe(e){return k?new Promise(a=>{const s=k.transaction([L],"readwrite").objectStore(L).put(e);s.onsuccess=()=>{a(true)},s.onerror=()=>{console.error("保存图片到IndexedDB失败:",s.error),a(false)}}):false}async function Ae(e){return k?new Promise(a=>{const s=k.transaction([L],"readwrite").objectStore(L).delete(e);s.onsuccess=()=>{a(true)},s.onerror=()=>{console.error("从IndexedDB删除图片失败:",s.error),a(false)}}):false}async function Re(e){return k?new Promise(a=>{const l=k.transaction([L],"readonly").objectStore(L).index("channelKey").getAll(e);l.onsuccess=()=>{a(l.result||[])},l.onerror=()=>{console.error("获取频道图片失败:",l.error),a([])}}):[]}async function _e(e,a){const t=$.value[a];if(t)return t;const n=await gt(a);if(!n)return null;const s=URL.createObjectURL(n.blob);return $.value[a]=s,n.timestamp=Date.now(),await Oe(n),s}async function ae(e,a){try{const t=await _e(e,a);if(t)return t;const n=await M("fetch-image",{url:a});if(!n.success)return console.error("获取图片失败:",n.error),null;const s=n.base64,l=n.contentType||"image/jpeg",r=atob(s),o=new Array(r.length);for(let ne=0;ne<r.length;ne++)o[ne]=r.charCodeAt(ne);const c=new Uint8Array(o),x=new Blob([c],{type:l}),C=await Re(e);if(C.length>=We){const St=C.sort((Q,Bt)=>Q.timestamp-Bt.timestamp).slice(0,C.length-We+1);for(const Q of St)await Ae(Q.url),$.value[Q.url]&&(URL.revokeObjectURL($.value[Q.url]),delete $.value[Q.url])}const b={url:a,blob:x,timestamp:Date.now(),size:x.size,channelKey:e};if(!await Oe(b))return console.error("保存图片到IndexedDB失败"),null;const He=URL.createObjectURL(x);return $.value[a]=He,He}catch(t){return console.error("缓存图片失败:",t),null}}async function ge(e){try{const a=await Re(e);for(const t of a)await Ae(t.url),$.value[t.url]&&(URL.revokeObjectURL($.value[t.url]),delete $.value[t.url])}catch(a){console.error("清理频道图片缓存失败:",a)}}function yt(e){var a,t,n,s;if(!u.value.bots[e.selfId])u.value.bots[e.selfId]={selfId:e.selfId,platform:e.platform,username:((a=e.bot)==null?void 0:a.name)||`Bot-${e.selfId}`,avatar:(t=e.bot)==null?void 0:t.avatar,status:"online"};else{const l=u.value.bots[e.selfId];l.status="online",(n=e.bot)!=null&&n.name&&l.username!==e.bot.name&&(l.username=e.bot.name),(s=e.bot)!=null&&s.avatar&&l.avatar!==e.bot.avatar&&(l.avatar=e.bot.avatar)}if(u.value.channels[e.selfId]||(u.value.channels[e.selfId]={}),e.channelId&&!u.value.channels[e.selfId][e.channelId]){const l=e.guildId?`${e.guildName||e.guildId} (${e.channelId})`:`私信 ${e.channelId}`;u.value.channels[e.selfId][e.channelId]={id:e.channelId,name:l,type:e.channelType||0,guildId:e.guildId,guildName:e.guildName||e.guildId||"私聊"}}if(e.messageId&&e.content&&e.channelId){const l=`${e.selfId}:${e.channelId}`;if(u.value.messages[l]||(u.value.messages[l]=[]),!u.value.messages[l].find(o=>o.id===e.messageId)){const o={id:e.messageId,content:e.content,userId:e.userId,username:e.username,avatar:e.avatar,timestamp:e.timestamp,channelId:e.channelId,selfId:e.selfId,elements:e.elements,isBot:false,quote:e.quote},c=u.value.messages[l];let x=c.length;for(let b=c.length-1;b>=0;b--){if(c[b].timestamp<=e.timestamp){x=b+1;break}b===0&&(x=0)}c.splice(x,0,o),c.length>100&&(u.value.messages[l]=c.slice(-100)),N.value[l]=c.length;const C=Pe();se(()=>{setTimeout(()=>{C&&te()},10)})}}if(e.elements&&e.elements.length>0){const l=`${e.selfId}:${e.channelId}`;e.elements.forEach(r=>{if((r.type==="img"||r.type==="image"||r.type==="mface")&&r.attrs){const o=r.attrs.src||r.attrs.url||r.attrs.file;o&&ae(l,o).catch(c=>{console.warn("预缓存图片失败:",o,c)})}})}u.value={...u.value}}function pt(e){const a=`${e.selfId}:${e.channelId}`;if(u.value.messages[a]||(u.value.messages[a]=[]),!u.value.messages[a].find(n=>n.id===e.messageId)){const n={id:e.messageId,content:e.content,userId:e.selfId,username:e.botUsername,avatar:e.botAvatar,timestamp:e.timestamp,channelId:e.channelId,selfId:e.selfId,elements:e.elements,isBot:true,quote:e.quote},s=u.value.messages[a];let l=s.length;for(let o=s.length-1;o>=0;o--){if(s[o].timestamp<=e.timestamp){l=o+1;break}o===0&&(l=0)}s.splice(l,0,n),s.length>100&&(u.value.messages[a]=s.slice(-100)),N.value[a]=s.length;const r=Pe();se(()=>{setTimeout(()=>{r&&te()},10)})}u.value={...u.value}}Xe(Te,(e,a)=>{a.length===0&&e.length>0&&se(()=>{te()})});async function wt(){try{const e=await M("get-chat-data");if(e.success&&e.data){const a={};U.value=new Set(e.data.pinnedBots||[]),O.value=new Set(e.data.pinnedChannels||[]);for(const[t,n]of Object.entries(e.data.messages||{})){const s=n.map(c=>({id:c.id,content:c.content,userId:c.userId,username:c.username,avatar:c.avatar,timestamp:c.timestamp,channelId:c.channelId,selfId:c.selfId,elements:c.elements,isBot:c.type==="bot",quote:c.quote}));s.sort((c,x)=>c.timestamp-x.timestamp);const[l,r]=t.split("-"),o=`${l}:${r}`;a[o]=s}return u.value={bots:e.data.bots||{},channels:e.data.channels||{},messages:a},await bt(),true}else return console.warn("获取聊天数据失败:",e.error),false}catch(e){return console.error("获取聊天数据时出错:",e),false}}async function bt(){try{const e=await M("get-all-channel-message-counts");if(e.success&&e.counts){const a={};for(const[t,n]of Object.entries(e.counts)){const[s,l]=t.split("-"),r=`${s}:${l}`;a[r]=n}N.value=a}else console.warn("获取频道消息数量失败:",e.error)}catch(e){console.error("获取频道消息数量时出错:",e)}}async function xt(){try{const e=await M("get-plugin-config");e.success&&e.config?we.value=e.config:console.warn("获取插件配置失败:",e.error)}catch(e){console.error("获取插件配置时出错:",e)}}async function Ct(e,a){try{const t=await M("get-history-messages",{selfId:e,channelId:a});if(t.success&&t.messages){const n=`${e}:${a}`,s=t.messages.map(l=>({id:l.id,content:l.content,userId:l.userId,username:l.username,avatar:l.avatar,timestamp:l.timestamp,channelId:l.channelId,selfId:l.selfId,elements:l.elements,isBot:l.type==="bot",quote:l.quote}));return s.sort((l,r)=>l.timestamp-r.timestamp),u.value.messages[n]=s,N.value[n]=s.length,u.value={...u.value},true}else return console.warn("获取历史消息失败:",t.error),false}catch(t){return console.error("获取历史消息时出错:",t),false}}function It(e){if(!S.value||e.touches.length!==1)return;const a=e.touches[0];P.value={x:a.clientX,y:a.clientY,time:Date.now()},J.value={x:a.clientX,y:a.clientY},be.value=false}function kt(e){if(!S.value||!P.value||e.touches.length!==1)return;const a=e.touches[0];J.value={x:a.clientX,y:a.clientY};const t=a.clientX-P.value.x,n=a.clientY-P.value.y;if(Math.abs(t)>Math.abs(n)&&Math.abs(t)>30){const s=t>0,l=X.value==="messages"||X.value==="channels";if(s&&l){be.value=true;const r=Math.min(t,150),o=100;r>o?Y.value={show:true,text:"松开返回"}:Y.value={show:true,text:`滑动返回 ${Math.round(r/o*100)}%`},e.preventDefault()}else Y.value={show:false,text:""}}else Y.value={show:false,text:""}}function _t(e){if(!S.value||!P.value)return;const t=Date.now()-P.value.time;if(J.value){const n=J.value.x-P.value.x,s=J.value.y-P.value.y,l=n>100,r=Math.abs(n)>Math.abs(s),o=t<300&&n>50;(l&&r||o)&&$t()}P.value=null,J.value=null,be.value=false,Y.value={show:false,text:""}}function $t(){switch(X.value){case"messages":X.value="channels";break;case"channels":X.value="bots",h.value="",w.value="";break}}function $e(){S.value=window.innerWidth<=768}return Se(async()=>{$e(),window.addEventListener("resize",$e),await mt()||console.warn("IndexedDB初始化失败,图片缓存功能将不可用"),await xt(),await wt();const a=Fe("chat-message-event",yt),t=Fe("bot-message-sent-event",pt);Xe(w,n=>{n&&se(()=>{I.value&&(I.value.removeEventListener("scroll",ve),I.value.addEventListener("scroll",ve),ve()),!S.value&&ee.value&&ee.value.focus()})},{immediate:true}),Mt(()=>{window.removeEventListener("resize",$e),a&&typeof a=="function"&&a(),t&&typeof t=="function"&&t(),I.value&&I.value.removeEventListener("scroll",ve),Object.values($.value).forEach(n=>{URL.revokeObjectURL(n)}),$.value={},k&&(k.close(),k=null)})}),(e,a)=>(f(),m("div",{class:z(["chat-container",Ee.value]),style:Be(tt.value),onTouchstart:It,onTouchmove:kt,onTouchend:_t},[i("div",Pt,[a[6]||(a[6]=i("div",{class:"panel-header"},[i("h3",null,"机器人")],-1)),i("div",jt,[(f(true),m(R,null,oe(Ve.value,t=>(f(),m("div",{key:t.selfId,class:z(["bot-item",{active:h.value===t.selfId,pinned:U.value.has(t.selfId)}]),onClick:n=>at(t.selfId),onContextmenu:n=>nt(n,t.selfId)},[i("div",Ot,[t.avatar?(f(),re(ce(H),{key:0,src:t.avatar,alt:t.username,"channel-key":"bot-list"},null,8,["src","alt"])):(f(),m("div",At,p(t.username.charAt(0).toUpperCase()),1))]),i("div",Rt,[i("div",Ht,p(t.username),1),i("div",Xt,p(t.platform),1)]),i("div",{class:z(["bot-status",t.status])},null,2)],42,Ut))),128))])]),i("div",zt,[a[7]||(a[7]=i("div",{class:"panel-header"},[i("h3",null,"频道")],-1)),h.value?(f(),m("div",Ft,[(f(true),m(R,null,oe(Ge.value,t=>(f(),m("div",{key:t.id,class:z(["channel-item",{active:w.value===t.id,pinned:O.value.has(`${h.value}:${t.id}`)}]),"data-channel-id":t.id,onClick:n=>it(t.id),onContextmenu:n=>st(n,t.id)},[i("div",Jt,[i("div",Vt,p(t.name),1),i("div",Gt,p(ut(t.type)),1)]),ke(t.id)>0?(f(),m("div",{key:0,class:z(["channel-message-count draggable-bubble",{dragging:j.value===t.id,"will-delete":j.value===t.id&&Ue(t.id)>K}]),onMousedown:n=>je(n,t.id),onTouchstart:n=>je(n,t.id),style:Be(dt(t.id)),title:j.value===t.id?Ue(t.id)>K?"松开清理历史记录":"拖拽更远以清理历史记录":"拖拽清理历史记录"},p(ke(t.id)),47,Qt)):le("",true)],42,Wt))),128))])):(f(),m("div",Yt," 请选择一个机器人 "))]),i("div",Zt,[i("div",Et,[i("h3",null,p(Qe.value||"选择频道"),1)]),!h.value||!w.value?(f(),m("div",ea," 请选择机器人和频道 ")):(f(),m("div",ta,[i("div",{class:"message-history",ref_key:"messageHistory",ref:I},[(f(true),m(R,null,oe(Te.value,t=>(f(),m("div",{key:t.id,class:z(["message-item",{"bot-message":t.isBot}])},[i("div",aa,[t.avatar?(f(),re(ce(H),{key:0,src:t.avatar,alt:t.username,"channel-key":de.value},null,8,["src","alt","channel-key"])):(f(),m("div",na,p(t.username.charAt(0).toUpperCase()),1))]),i("div",sa,[i("div",la,[i("span",oa,p(t.username),1),i("span",ra,p(Ne(t.timestamp)),1)]),t.quote?(f(),m("div",ca,[i("div",ia,[i("div",ua,[t.quote.user.avatar?(f(),re(ce(H),{key:0,src:t.quote.user.avatar,alt:t.quote.user.username,"channel-key":de.value},null,8,["src","alt","channel-key"])):(f(),m("div",da,p(t.quote.user.username.charAt(0).toUpperCase()),1))]),i("span",va,p(t.quote.user.username),1),i("span",ha,p(Ne(t.quote.timestamp)),1)]),i("div",fa,[t.quote.elements&&t.quote.elements.length>0?(f(true),m(R,{key:0},oe(t.quote.elements,(n,s)=>(f(),re(ce(ie),{key:`quote-${s}`,element:n,"channel-key":de.value},null,8,["element","channel-key"]))),128)):(f(),m(R,{key:1},[Ye(p(t.quote.content),1)],64))])])):le("",true),i("div",ma,[t.elements&&t.elements.length>0?(f(true),m(R,{key:0},oe(t.elements,(n,s)=>(f(),re(ce(ie),{key:s,element:n,"channel-key":de.value},null,8,["element","channel-key"]))),128)):(f(),m(R,{key:1},[Ye(p(t.content),1)],64))])])],2))),128))],512),ze(i("div",{class:"floating-scroll-button",onClick:te},a[8]||(a[8]=[i("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor"},[i("path",{d:"M7 10l5 5 5-5z"})],-1)]),512),[[Tt,xe.value]]),i("div",ga,[i("div",ya,[ze(i("input",{"onUpdate:modelValue":a[0]||(a[0]=t=>E.value=t),type:"text",placeholder:et.value,onKeyup:Dt(Ke,["enter"]),disabled:!Ze.value,ref_key:"messageInput",ref:ee},null,40,pa),[[qt,E.value]]),i("button",{onClick:Ke,disabled:!De.value,class:z({"is-sending":V.value})},p(V.value?"发送中...":"发送"),11,wa)])])]))]),y.value.show?(f(),m("div",{key:0,class:"context-menu",style:Be({left:y.value.x+"px",top:y.value.y+"px"}),onClick:a[5]||(a[5]=Lt(()=>{},["stop"]))},[y.value.type==="bot"?(f(),m(R,{key:0},[i("div",{class:"context-menu-item",onClick:a[1]||(a[1]=t=>lt(y.value.targetId))},p(U.value.has(y.value.targetId)?"取消置顶":"置顶"),1),i("div",{class:"context-menu-item danger",onClick:a[2]||(a[2]=t=>rt(y.value.targetId))}," 彻底删除此机器人所有数据 ")],64)):le("",true),y.value.type==="channel"?(f(),m(R,{key:1},[i("div",{class:"context-menu-item",onClick:a[3]||(a[3]=t=>ot(y.value.targetId))},p(O.value.has(`${h.value}:${y.value.targetId}`)?"取消置顶":"置顶"),1),i("div",{class:"context-menu-item danger",onClick:a[4]||(a[4]=t=>ct(y.value.targetId))}," 彻底删除此频道所有数据 ")],64)):le("",true)],4)):le("",true),i("div",{class:z(["swipe-indicator",{show:Y.value.show}])},p(Y.value.text),3)],38))}}),Je=(F,H)=>{const W=F.__vccOpts||F;for(const[pe,ie]of H)W[pe]=ie;return W},Ia=Je(Ca,[["__scopeId","data-v-23dd8b18"]]),ka={},_a={class:"k-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none"};function $a(F,H){return f(),m("svg",_a,H[0]||(H[0]=[i("path",{d:"M8 10.5H16",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1),i("path",{d:"M8 14H13.5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1),i("path",{d:"M17 3.33782C15.5291 2.48697 13.8214 2 12 2C6.47715 2 2 6.47715 2 12C2 13.5997 2.37562 15.1116 3.04346 16.4525C3.22094 16.8088 3.28001 17.2161 3.17712 17.6006L2.58151 19.8267C2.32295 20.793 3.20701 21.677 4.17335 21.4185L6.39939 20.8229C6.78393 20.72 7.19121 20.7791 7.54753 20.9565C8.88837 21.6244 10.4003 22 12 22C17.5228 22 22 17.5228 22 12C22 10.1786 21.513 8.47087 20.6622 7",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1)]))}const Sa=Je(ka,[["render",$a]]);Nt.register("activity:chat",Sa);const Ta=F=>{F.page({name:"聊天室",path:"/chat-patch",desc:"",authority:4,icon:"activity:chat",component:Z({setup(){return()=>d(Kt("k-layout"),{},{default:()=>d(Ia)})}})})};export{Ta as default};
|
|
22
|
+
`,document.head.appendChild(l),document.body.appendChild(t),setTimeout(()=>{t.style.animation="slideOut 0.3s ease-in",setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),l.parentNode&&l.parentNode.removeChild(l)},300)},3e3)}function Ut(e,a){const t=document.createElement("div");t.className="drag-threshold-circle",t.style.cssText=`
|
|
23
|
+
left: ${e-A}px;
|
|
24
|
+
top: ${a-A}px;
|
|
25
|
+
width: ${A*2}px;
|
|
26
|
+
height: ${A*2}px;
|
|
27
|
+
`,document.body.appendChild(t),window.dragThresholdCircle=t}function jt(){const e=window.dragThresholdCircle;e&&e.parentNode&&(e.parentNode.removeChild(e),window.dragThresholdCircle=null)}async function Kt(){return new Promise((e,a)=>{const t=indexedDB.open(Fa,Ya);t.onerror=()=>{console.error("IndexedDB初始化失败:",t.error),e(false)},t.onsuccess=()=>{S=t.result,e(true)},t.onupgradeneeded=n=>{const l=n.target.result;if(!l.objectStoreNames.contains(R)){const s=l.createObjectStore(R,{keyPath:"url"});s.createIndex("channelKey","channelKey",{unique:false}),s.createIndex("timestamp","timestamp",{unique:false})}}})}async function Nt(e){return S?new Promise((a,t)=>{const s=S.transaction([R],"readonly").objectStore(R).get(e);s.onsuccess=()=>{a(s.result||null)},s.onerror=()=>{console.error("从IndexedDB获取图片失败:",s.error),a(null)}}):null}async function et(e){return S?new Promise(a=>{const l=S.transaction([R],"readwrite").objectStore(R).put(e);l.onsuccess=()=>{a(true)},l.onerror=()=>{console.error("保存图片到IndexedDB失败:",l.error),a(false)}}):false}async function tt(e){return S?new Promise(a=>{const l=S.transaction([R],"readwrite").objectStore(R).delete(e);l.onsuccess=()=>{a(true)},l.onerror=()=>{console.error("从IndexedDB删除图片失败:",l.error),a(false)}}):false}async function at(e){return S?new Promise(a=>{const s=S.transaction([R],"readonly").objectStore(R).index("channelKey").getAll(e);s.onsuccess=()=>{a(s.result||[])},s.onerror=()=>{console.error("获取频道图片失败:",s.error),a([])}}):[]}async function je(e,a){const t=b.value[a];if(t)return t;const n=await Nt(a);if(!n)return null;$e();const l=URL.createObjectURL(n.blob);return b.value[a]=l,ge(Me(n.blob)),n.timestamp=Date.now(),await et(n),l}async function se(e,a){try{const t=await je(e,a);if(t)return t;const n=await _("fetch-image",{url:a});if(!n.success)return console.error("获取图片失败:",n.error),null;const l=n.base64,s=n.contentType||"image/jpeg",o=atob(l),r=new Array(o.length);for(let fe=0;fe<o.length;fe++)r[fe]=o.charCodeAt(fe);const i=new Uint8Array(r),h=new Blob([i],{type:s}),g=await at(e);if(g.length>=rt){const Jt=g.sort((le,Vt)=>le.timestamp-Vt.timestamp).slice(0,g.length-rt+1);for(const le of Jt)await tt(le.url),b.value[le.url]&&(URL.revokeObjectURL(b.value[le.url]),delete b.value[le.url])}const y={url:a,blob:h,timestamp:Date.now(),size:h.size,channelKey:e};if(!await et(y))return console.error("保存图片到IndexedDB失败"),null;$e();const B=URL.createObjectURL(h);return b.value[a]=B,ge(Me(h)),B}catch(t){return console.error("缓存图片失败:",t),null}}async function ke(e){try{const a=await at(e);let t=0;for(const n of a)await tt(n.url),b.value[n.url]&&(URL.revokeObjectURL(b.value[n.url]),delete b.value[n.url],t+=n.size||0);t>0&&ge(-t)}catch(a){console.error("清理频道图片缓存失败:",a)}}function Ot(e){var a,t,n,l;if(!u.value.bots[e.selfId])u.value.bots[e.selfId]={selfId:e.selfId,platform:e.platform,username:((a=e.bot)==null?void 0:a.name)||`Bot-${e.selfId}`,avatar:(t=e.bot)==null?void 0:t.avatar,status:"online"};else{const s=u.value.bots[e.selfId];s.status="online",(n=e.bot)!=null&&n.name&&s.username!==e.bot.name&&(s.username=e.bot.name),(l=e.bot)!=null&&l.avatar&&s.avatar!==e.bot.avatar&&(s.avatar=e.bot.avatar)}if(u.value.channels[e.selfId]||(u.value.channels[e.selfId]={}),e.channelId&&!u.value.channels[e.selfId][e.channelId]){const s=e.guildId?`${e.guildName||e.guildId} (${e.channelId})`:`私信 ${e.channelId}`;u.value.channels[e.selfId][e.channelId]={id:e.channelId,name:s,type:e.channelType||0,guildId:e.guildId,guildName:e.guildName||e.guildId||"私聊"}}if(e.messageId&&e.content&&e.channelId){const s=`${e.selfId}:${e.channelId}`;if(u.value.messages[s]||(u.value.messages[s]=[]),!u.value.messages[s].find(r=>r.id===e.messageId)){const r={id:e.messageId,content:e.content,userId:e.userId,username:e.username,avatar:e.avatar,timestamp:e.timestamp,channelId:e.channelId,selfId:e.selfId,elements:e.elements,isBot:false,quote:e.quote},i=u.value.messages[s];let h=i.length;for(let y=i.length-1;y>=0;y--){if(i[y].timestamp<=e.timestamp){h=y+1;break}y===0&&(h=0)}i.splice(h,0,r),i.length>100&&(u.value.messages[s]=i.slice(-100)),D.value[s]=i.length;const g=De();re(()=>{setTimeout(()=>{g&&ne()},10)})}}if(e.elements&&e.elements.length>0){const s=`${e.selfId}:${e.channelId}`;e.elements.forEach(o=>{if((o.type==="img"||o.type==="image"||o.type==="mface")&&o.attrs){const r=o.attrs.src||o.attrs.url||o.attrs.file;r&&se(s,r).catch(i=>{console.warn("预缓存图片失败:",r,i)})}})}u.value={...u.value}}function Pt(e){const a=`${e.selfId}:${e.channelId}`;if(u.value.messages[a]||(u.value.messages[a]=[]),!u.value.messages[a].find(n=>n.id===e.messageId)){const n={id:e.messageId,content:e.content,userId:e.selfId,username:e.botUsername,avatar:e.botAvatar,timestamp:e.timestamp,channelId:e.channelId,selfId:e.selfId,elements:e.elements,isBot:true,quote:e.quote},l=u.value.messages[a];let s=l.length;for(let r=l.length-1;r>=0;r--){if(l[r].timestamp<=e.timestamp){s=r+1;break}r===0&&(s=0)}l.splice(s,0,n),l.length>100&&(u.value.messages[a]=l.slice(-100)),D.value[a]=l.length;const o=De();re(()=>{setTimeout(()=>{o&&ne()},10)})}u.value={...u.value}}function Rt(e){var a,t,n,l;if(!u.value.bots[e.selfId])u.value.bots[e.selfId]={selfId:e.selfId,platform:e.platform,username:((a=e.bot)==null?void 0:a.name)||`Bot-${e.selfId}`,avatar:(t=e.bot)==null?void 0:t.avatar,status:"online"};else{const s=u.value.bots[e.selfId];s.status="online",(n=e.bot)!=null&&n.name&&s.username!==e.bot.name&&(s.username=e.bot.name),(l=e.bot)!=null&&l.avatar&&s.avatar!==e.bot.avatar&&(s.avatar=e.bot.avatar)}if(u.value.channels[e.selfId]||(u.value.channels[e.selfId]={}),e.channelId&&!u.value.channels[e.selfId][e.channelId]){const s=e.guildId?`${e.guildName||e.guildId} (${e.channelId})`:`私信 ${e.channelId}`;u.value.channels[e.selfId][e.channelId]={id:e.channelId,name:s,type:e.channelType||0,guildId:e.guildId,guildName:e.guildName||e.guildId||"私聊"}}if(e.messageId&&e.content&&e.channelId){const s=`${e.selfId}:${e.channelId}`;if(u.value.messages[s]||(u.value.messages[s]=[]),!u.value.messages[s].find(r=>r.id===e.messageId)){const r={id:e.messageId,content:e.content,userId:e.userId,username:e.username,avatar:e.avatar,timestamp:e.timestamp,channelId:e.channelId,selfId:e.selfId,elements:e.elements,isBot:true,quote:e.quote},i=u.value.messages[s];let h=i.length;for(let y=i.length-1;y>=0;y--){if(i[y].timestamp<=e.timestamp){h=y+1;break}y===0&&(h=0)}i.splice(h,0,r),i.length>100&&(u.value.messages[s]=i.slice(-100)),D.value[s]=i.length;const g=De();re(()=>{setTimeout(()=>{g&&ne()},10)})}}if(e.elements&&e.elements.length>0){const s=`${e.selfId}:${e.channelId}`;e.elements.forEach(o=>{if((o.type==="img"||o.type==="image"||o.type==="mface")&&o.attrs){const r=o.attrs.src||o.attrs.url||o.attrs.file;r&&se(s,r).catch(i=>{console.warn("预缓存图片失败:",r,i)})}})}u.value={...u.value}}nt(He,(e,a)=>{a.length===0&&e.length>0&&re(()=>{ne()})});async function At(){try{const e=await _("get-chat-data");if(e.success&&e.data){const a={};X.value=new Set(e.data.pinnedBots||[]),H.value=new Set(e.data.pinnedChannels||[]);for(const[t,n]of Object.entries(e.data.messages||{})){const l=n.map(s=>({id:s.id,content:s.content,userId:s.userId,username:s.username,avatar:s.avatar,timestamp:s.timestamp,channelId:s.channelId,selfId:s.selfId,elements:s.elements,isBot:s.type==="bot",quote:s.quote}));l.sort((s,o)=>s.timestamp-o.timestamp),a[t]=l}return u.value={bots:e.data.bots||{},channels:e.data.channels||{},messages:a},await Mt(),true}else return console.warn("获取聊天数据失败:",e.error),false}catch(e){return console.error("获取聊天数据时出错:",e),false}}async function Mt(){try{const e=await _("get-all-channel-message-counts");if(e.success&&e.counts){const a={};for(const[t,n]of Object.entries(e.counts))a[t]=n;D.value=a}else console.warn("获取频道消息数量失败:",e.error)}catch(e){console.error("获取频道消息数量时出错:",e)}}async function zt(){try{const e=await _("get-plugin-config");e.success&&e.config?ie.value=e.config:console.warn("获取插件配置失败:",e.error)}catch(e){console.error("获取插件配置时出错:",e)}}async function Xt(e,a){try{const t=await _("get-history-messages",{selfId:e,channelId:a});if(t.success&&t.messages){const n=`${e}:${a}`,l=t.messages.map(s=>({id:s.id,content:s.content,userId:s.userId,username:s.username,avatar:s.avatar,timestamp:s.timestamp,channelId:s.channelId,selfId:s.selfId,elements:s.elements,isBot:s.type==="bot",quote:s.quote}));return l.sort((s,o)=>s.timestamp-o.timestamp),u.value.messages[n]=l,D.value[n]=l.length,u.value={...u.value},true}else return console.warn("获取历史消息失败:",t.error),false}catch(t){return console.error("获取历史消息时出错:",t),false}}function Ht(e){if(!L.value||e.touches.length!==1)return;const a=e.touches[0];M.value={x:a.clientX,y:a.clientY,time:Date.now()},ee.value={x:a.clientX,y:a.clientY},Be.value=false}function Ft(e){if(!L.value||!M.value||e.touches.length!==1)return;const a=e.touches[0];ee.value={x:a.clientX,y:a.clientY};const t=a.clientX-M.value.x,n=a.clientY-M.value.y;if(Math.abs(t)>Math.abs(n)&&Math.abs(t)>30){const l=t>0,s=W.value==="messages"||W.value==="channels";if(l&&s){Be.value=true;const o=Math.min(t,200),r=150;o>r?V.value={show:true,text:"松开返回"}:V.value={show:true,text:`滑动返回 ${Math.round(o/r*100)}%`},e.preventDefault()}else V.value={show:false,text:""}}else V.value={show:false,text:""}}function Yt(e){if(!L.value||!M.value)return;const t=Date.now()-M.value.time;if(ee.value){const n=ee.value.x-M.value.x,l=ee.value.y-M.value.y,s=n>150,o=Math.abs(n)>Math.abs(l),r=t<300&&n>80;(s&&o||r)&&Wt()}M.value=null,ee.value=null,Be.value=false,V.value={show:false,text:""}}function Wt(){switch(W.value){case"messages":W.value="channels";break;case"channels":W.value="bots",m.value="",C.value="";break}}function Ke(){L.value=window.innerWidth<=768}return Ne(async()=>{Ke(),window.addEventListener("resize",Ke),document.addEventListener("click",Ge),await Kt()||console.warn("IndexedDB初始化失败,图片缓存功能将不可用"),await zt(),await At();const a=Re("chat-message-event",Ot),t=Re("bot-message-sent-event",Pt),n=Re("chat-bot-message-event",Rt);nt(C,l=>{l&&re(()=>{$.value&&($.value.removeEventListener("scroll",we),$.value.addEventListener("scroll",we),we()),!L.value&&de.value&&de.value.focus()})},{immediate:true}),setInterval(()=>{$e()},2*60*1e3),Gt(()=>{window.removeEventListener("resize",Ke),document.removeEventListener("click",Ge),a&&typeof a=="function"&&a(),t&&typeof t=="function"&&t(),n&&typeof n=="function"&&n(),$.value&&$.value.removeEventListener("scroll",we),Object.values(b.value).forEach(l=>{URL.revokeObjectURL(l)}),b.value={},S&&(S.close(),S=null)})}),(e,a)=>(v(),p("div",{class:F(["chat-container",ht.value]),style:Oe(vt.value),onTouchstart:Ht,onTouchmove:Ft,onTouchend:Yt},[c("div",aa,[a[7]||(a[7]=c("div",{class:"panel-header"},[c("h3",null,"机器人")],-1)),c("div",na,[(v(true),p(P,null,oe(it.value,t=>(v(),p("div",{key:t.selfId,class:F(["bot-item",{active:m.value===t.selfId,pinned:X.value.has(t.selfId)}]),onClick:n=>gt(t.selfId),onContextmenu:n=>yt(n,t.selfId)},[c("div",la,[t.avatar?(v(),he(me(E),{key:0,src:t.avatar,alt:t.username,"channel-key":"bot-list"},null,8,["src","alt"])):(v(),p("div",ra,x(t.username.charAt(0).toUpperCase()),1))]),c("div",oa,[c("div",ca,x(t.username),1),c("div",ia,x(t.platform),1)]),c("div",{class:F(["bot-status",t.status])},null,2)],42,sa))),128))])]),c("div",ua,[a[8]||(a[8]=c("div",{class:"panel-header"},[c("h3",null,"频道")],-1)),m.value?(v(),p("div",fa,[(v(true),p(P,null,oe(ut.value,t=>(v(),p("div",{key:t.id,class:F(["channel-item",{active:C.value===t.id,pinned:H.value.has(`${m.value}:${t.id}`)}]),"data-channel-id":t.id,onClick:n=>kt(t.id),onContextmenu:n=>pt(n,t.id)},[c("div",ma,[c("div",va,x(t.name),1),c("div",ga,x(Tt(t.type)),1)]),Ue(t.id)>0?(v(),p("div",{key:0,class:F(["channel-message-count draggable-bubble",{dragging:z.value===t.id,"will-delete":z.value===t.id&&Ee(t.id)>A}]),onMousedown:n=>Ze(n,t.id),onTouchstart:n=>Ze(n,t.id),style:Oe(qt(t.id)),title:z.value===t.id?Ee(t.id)>A?"松开清理历史记录":"拖拽更远以清理历史记录":"拖拽清理历史记录"},x(Ue(t.id)),47,ya)):G("",true)],42,ha))),128))])):(v(),p("div",da," 请选择一个机器人 "))]),c("div",pa,[c("div",wa,[c("h3",null,x(dt.value||"选择频道"),1)]),!m.value||!C.value?(v(),p("div",Ia," 请选择机器人和频道 ")):(v(),p("div",xa,[c("div",{class:"message-history",ref_key:"messageHistory",ref:$},[(v(true),p(P,null,oe(He.value,t=>(v(),p("div",{key:t.id,class:F(["message-item",{"bot-message":t.isBot}])},[c("div",Ca,[t.avatar?(v(),he(me(E),{key:0,src:t.avatar,alt:t.username,"channel-key":pe.value},null,8,["src","alt","channel-key"])):(v(),p("div",ka,x(t.username.charAt(0).toUpperCase()),1))]),c("div",ba,[c("div",_a,[c("span",$a,x(t.username),1),c("span",Sa,x(Qe(t.timestamp)),1)]),t.quote?(v(),p("div",Ba,[c("div",La,[c("div",Ta,[t.quote.user.avatar?(v(),he(me(E),{key:0,src:t.quote.user.avatar,alt:t.quote.user.username,"channel-key":pe.value},null,8,["src","alt","channel-key"])):(v(),p("div",qa,x(t.quote.user.username.charAt(0).toUpperCase()),1))]),c("span",Da,x(t.quote.user.username),1),c("span",Ua,x(Qe(t.quote.timestamp)),1)]),c("div",ja,[t.quote.elements&&t.quote.elements.length>0?(v(true),p(P,{key:0},oe(t.quote.elements,(n,l)=>(v(),he(me(ve),{key:`quote-${l}`,element:n,"channel-key":pe.value},null,8,["element","channel-key"]))),128)):(v(),p(P,{key:1},[Pe(x(t.quote.content),1)],64))])])):G("",true),c("div",Ka,[t.elements&&t.elements.length>0?(v(true),p(P,{key:0},oe(t.elements,(n,l)=>(v(),he(me(ve),{key:l,element:n,"channel-key":pe.value},null,8,["element","channel-key"]))),128)):(v(),p(P,{key:1},[Pe(x(t.content),1)],64))])])],2))),128))],512),st(c("div",{class:"floating-scroll-button",onClick:ne},a[9]||(a[9]=[c("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor"},[c("path",{d:"M7 10l5 5 5-5z"})],-1)]),512),[[Qt,Le.value]]),c("div",Na,[U.value.length>0?(v(),p("div",Oa,[(v(true),p(P,null,oe(U.value,t=>(v(),p("div",{key:t.tempId,class:"image-preview-item"},[c("img",{src:t.preview,alt:t.filename,class:"preview-image"},null,8,Pa),c("button",{class:"remove-image-btn",onClick:n=>Bt(t.tempId),title:"删除图片"},a[10]||(a[10]=[c("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor"},[c("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})],-1)]),8,Ra)]))),128))])):G("",true),c("div",Aa,[c("div",Ma,[c("button",{class:F(["add-button",{active:J.value}]),onClick:bt,title:"更多操作"},a[11]||(a[11]=[c("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"},[c("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),c("line",{x1:"5",y1:"12",x2:"19",y2:"12"})],-1)]),2),J.value?(v(),p("div",{key:0,class:"action-menu",onClick:a[0]||(a[0]=lt(()=>{},["stop"]))},[c("button",{class:"action-menu-item",onClick:_t},a[12]||(a[12]=[c("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[c("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),c("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),c("polyline",{points:"21,15 16,10 5,21"})],-1),Pe(" 上传图片 ",-1)]))])):G("",true)]),st(c("input",{"onUpdate:modelValue":a[1]||(a[1]=t=>ue.value=t),type:"text",placeholder:mt.value,onKeyup:Zt(Je,["enter"]),disabled:!ft.value,ref_key:"messageInput",ref:de,onPaste:St},null,40,za),[[Et,ue.value]]),c("button",{onClick:Je,disabled:!Fe.value,class:F({"is-sending":te.value})},x(te.value?"发送中...":"发送"),11,Xa)]),c("input",{type:"file",ref_key:"fileInput",ref:Se,onChange:$t,accept:"image/*",multiple:"",style:{display:"none"}},null,544)])]))]),I.value.show?(v(),p("div",{key:0,class:"context-menu",style:Oe({left:I.value.x+"px",top:I.value.y+"px"}),onClick:a[6]||(a[6]=lt(()=>{},["stop"]))},[I.value.type==="bot"?(v(),p(P,{key:0},[c("div",{class:"context-menu-item",onClick:a[2]||(a[2]=t=>wt(I.value.targetId))},x(X.value.has(I.value.targetId)?"取消置顶":"置顶"),1),c("div",{class:"context-menu-item danger",onClick:a[3]||(a[3]=t=>xt(I.value.targetId))}," 彻底删除此机器人所有数据 ")],64)):G("",true),I.value.type==="channel"?(v(),p(P,{key:1},[c("div",{class:"context-menu-item",onClick:a[4]||(a[4]=t=>It(I.value.targetId))},x(H.value.has(`${m.value}:${I.value.targetId}`)?"取消置顶":"置顶"),1),c("div",{class:"context-menu-item danger",onClick:a[5]||(a[5]=t=>Ct(I.value.targetId))}," 彻底删除此频道所有数据 ")],64)):G("",true)],4)):G("",true),c("div",{class:F(["swipe-indicator",{show:V.value.show}])},x(V.value.text),3)],38))}}),ot=(Z,Y)=>{const E=Z.__vccOpts||Z;for(const[ce,be]of Y)E[ce]=be;return E},Ja=ot(Wa,[["__scopeId","data-v-fc970c70"]]),Va={},Ga={class:"k-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none"};function Qa(Z,Y){return v(),p("svg",Ga,Y[0]||(Y[0]=[c("path",{d:"M8 10.5H16",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1),c("path",{d:"M8 14H13.5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1),c("path",{d:"M17 3.33782C15.5291 2.48697 13.8214 2 12 2C6.47715 2 2 6.47715 2 12C2 13.5997 2.37562 15.1116 3.04346 16.4525C3.22094 16.8088 3.28001 17.2161 3.17712 17.6006L2.58151 19.8267C2.32295 20.793 3.20701 21.677 4.17335 21.4185L6.39939 20.8229C6.78393 20.72 7.19121 20.7791 7.54753 20.9565C8.88837 21.6244 10.4003 22 12 22C17.5228 22 22 17.5228 22 12C22 10.1786 21.513 8.47087 20.6622 7",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1)]))}const Za=ot(Va,[["render",Qa]]);ta.register("activity:chat",Za);const tn=Z=>{Z.page({name:"聊天室",path:"/chat-patch",desc:"",authority:4,icon:"activity:chat",component:Q({setup(){return()=>d(ea("k-layout"),{},{default:()=>d(Ja)})}})})};export{tn as default};
|