5
5
<template v-if =" guildKey " >
6
6
<div class =" w-3rem h-full items-center justify-center flex
7
7
bg-gray-700 bg-op-0 hover:bg-op-100 transition cursor-pointer"
8
- @click =" guildKey = undefined, channels = [] " >
8
+ @click =" setGuild() " >
9
9
<k-icon name =" arrow-left" class =" h-4" ></k-icon >
10
10
</div >
11
11
<div class =" font-bold flex items-center flex-1" >{{ ctx.chat.guilds.value[guildKey].name }}</div >
14
14
<div class =" font-bold flex items-center flex-1 justify-center" >消息列表</div >
15
15
</template >
16
16
</div >
17
+
17
18
<el-scrollbar v-if =" guildKey" >
18
19
<div v-for =" (channel, index) in channels" :key =" channel.id"
19
20
class =" flex px-4 py-1 items-center
20
- bg-gray-700 bg-op-0 hover:bg-op-100 transition cursor-pointer" >
21
+ bg-gray-700 bg-op-0 hover:bg-op-100 transition cursor-pointer"
22
+ @click =" setChannel(channel)"
23
+ >
21
24
{{ channel.name }}
22
25
</div >
23
26
</el-scrollbar >
24
27
<el-scrollbar v-else >
25
28
<div v-for =" (guild, key) in ctx.chat.guilds.value" :key =" key"
26
29
class =" flex px-4 py-3 gap-x-4 justify-between
27
30
bg-gray-700 bg-op-0 hover:bg-op-100 transition cursor-pointer"
28
- @click =" onClickGuild (guild)"
31
+ @click =" setGuild (guild)"
29
32
>
30
33
<img v-if =" guild.avatar" :src =" withProxy(guild.avatar)" width =" 48" height =" 48" class =" b-rd-full" />
31
34
<div v-else
41
44
</div >
42
45
</el-scrollbar >
43
46
</template >
47
+
48
+ <template v-if =" channelId " >
49
+ <el-scrollbar >
50
+ <div v-for =" message in messages" :key =" message.id" class =" message" >
51
+ <message-content :content =" message.content!" ></message-content >
52
+ </div >
53
+ </el-scrollbar >
54
+ <div class =" footer shrink-0" >
55
+ <chat-input class =" h-6 px-4 py-2" v-model =" input" @send =" handleSend" placeholder =" 发送消息" ></chat-input >
56
+ </div >
57
+ </template >
58
+ <template v-else >
59
+ <k-empty >选择一个频道开始聊天</k-empty >
60
+ </template >
44
61
</k-layout >
45
62
</template >
46
63
47
64
<script lang="ts" setup>
48
65
49
- import { onMounted , ref , computed , watch , reactive } from ' vue'
66
+ import { ref } from ' vue'
50
67
import { useContext , useRpc } from ' @cordisjs/client'
51
68
import type { Data } from ' ../src'
52
- import type { Universal } from ' @satorijs/core'
69
+ import { Universal } from ' @satorijs/core'
70
+ import { ChatInput , MessageContent } from ' @satorijs/components-vue'
53
71
54
72
const data = useRpc <Data >()
55
73
const ctx = useContext ()
56
74
75
+ const platform = ref <string >()
57
76
const guildKey = ref <string >()
77
+ const channelId = ref <string >()
58
78
const channels = ref <Universal .Channel []>([])
79
+ const messages = ref <Universal .Message []>([])
80
+
81
+ const input = ref (' ' )
59
82
60
83
function short(name : string ) {
61
84
return name .slice (0 , 2 )
@@ -65,14 +88,30 @@ function withProxy(url: string) {
65
88
return (data .value .proxy ? data .value .proxy + ' /' : ' ' ) + url
66
89
}
67
90
68
- async function onClickGuild(guild : Universal .Guild & { platform: string ; assignees: string [] }) {
69
- guildKey .value = ` ${guild .platform }/${guild .id } `
91
+ async function setGuild(guild ? : Universal .Guild & { platform: string ; assignees: string [] }) {
70
92
channels .value = []
71
- for await (const channel of ctx .chat .logins [guild .assignees [0 ]].bot .getChannelIter (guild .id )) {
93
+ channelId .value = undefined
94
+ if (! guild ) return guildKey .value = undefined
95
+ platform .value = guild .platform
96
+ guildKey .value = ` ${guild .platform }/${guild .id } `
97
+ for await (const channel of ctx .bots [guild .assignees [0 ]].getChannelIter (guild .id )) {
72
98
channels .value .push (channel )
73
99
}
74
100
}
75
101
102
+ async function setChannel(channel : Universal .Channel ) {
103
+ channelId .value = channel .id
104
+ messages .value = []
105
+ for await (const message of ctx .bots [ctx .chat .guilds .value [guildKey .value ! ].assignees [0 ]].getMessageIter (channel .id )) {
106
+ if (channelId .value !== channel .id || messages .value .length >= 100 ) return
107
+ messages .value .unshift (message )
108
+ }
109
+ }
110
+
111
+ function handleSend(content : string ) {
112
+ return ctx .bots [ctx .chat .guilds .value [guildKey .value ! ].assignees [0 ]].sendMessage (channelId .value ! , content )
113
+ }
114
+
76
115
</script >
77
116
78
117
<style lang="scss" scoped>
@@ -82,4 +121,13 @@ async function onClickGuild(guild: Universal.Guild & { platform: string; assigne
82
121
border-bottom : var (--k-color-divider-dark ) 1px solid ;
83
122
}
84
123
124
+ .k-layout :deep(main ) {
125
+ display : flex ;
126
+ flex-direction : column ;
127
+ }
128
+
129
+ .footer {
130
+ border-top : var (--k-color-divider-dark ) 1px solid ;
131
+ }
132
+
85
133
</style >
0 commit comments