1
1
<template >
2
2
<k-layout :title =" channelName || '聊天'" >
3
3
<template #left >
4
- <div class =" header flex grow-0 shrink-0 box-border" >
4
+ <div class =" layout-left- header flex grow-0 shrink-0 box-border" >
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"
32
32
@click =" setGuild(guild)"
33
33
@contextmenu.stop =" triggerGuild($event, guild)"
34
34
>
35
- <img v-if =" guild.avatar" :src =" withProxy(guild.avatar)" width =" 48" height =" 48" class =" b-rd-full" />
36
- <div v-else
37
- class =" w-48px h-48px b-rd-full bg-gray-500
38
- font-bolder text-18px
39
- flex justify-center items-center" >
40
- {{ short(guild.name!) }}
41
- </div >
35
+ <avatar :src =" guild.avatar" :name =" guild.name" class =" w-48px h-48px" />
42
36
<div class =" flex flex-col flex-1" >
43
37
<div >{{ guild.name }}</div >
44
38
<div >{{ guild.id }}</div >
50
44
<template v-if =" channelId " >
51
45
<el-scrollbar >
52
46
<div v-if =" messages?.prev" >正在加载更多消息……</div >
53
- <div v-for =" message in messages?.data" :key =" message.id" class =" message"
47
+ <div v-for =" (message, index) in messages?.data" :key =" message.id"
48
+ class =" relative px-4 py-0 break-words
49
+ bg-gray-700 bg-op-0 hover:bg-op-100 transition"
50
+ :class =" { 'mt-2': !isSuccessive(index) }"
54
51
@contextmenu.stop =" triggerMessage($event, message)" >
55
- {{ message.id }}
56
- <message-content :content =" message.content!" ></message-content >
52
+ <div class =" quote" v-if =" message.quote" >
53
+ {{ message.quote }}
54
+ </div >
55
+ <template v-if =" isSuccessive (index )" >
56
+ <span >{{ formatTime(new Date(message?.createdAt!)) }}</span >
57
+ </template >
58
+ <template v-else >
59
+ <avatar :src =" message.user?.avatar" :name =" message.user?.name"
60
+ class =" w-10 h-10 absolute mt-1.5" />
61
+ <div class =" header" >
62
+ <span class =" font-bold lh-relaxed ml-14" >{{ message.user?.name }}</span >
63
+ <span >{{ formatDateTime(new Date(message?.createdAt!)) }}</span >
64
+ </div >
65
+ </template >
66
+ <message-content :content =" message.content!"
67
+ class =" ml-14 lh-relaxed"
68
+ ></message-content >
57
69
</div >
58
70
<div v-if =" messages?.next" >正在加载更多消息……</div >
59
71
</el-scrollbar >
@@ -106,8 +118,8 @@ import { useContext, useRpc, useMenu } from '@cordisjs/client'
106
118
import type { Data } from ' ../src'
107
119
import { Universal } from ' @satorijs/core'
108
120
import { ChatInput , MessageContent } from ' @satorijs/components-vue'
121
+ import Avatar from ' ./avatar.vue'
109
122
110
- const data = useRpc <Data >()
111
123
const ctx = useContext ()
112
124
113
125
const platform = ref <string >()
@@ -139,12 +151,10 @@ ctx.action('chat.message.inspect', async ({ chat }) => {
139
151
showMessage .value = chat .message
140
152
})
141
153
142
- function short(name : string ) {
143
- return name .slice (0 , 2 )
144
- }
145
-
146
- function withProxy(url : string ) {
147
- return (data .value .proxy ? data .value .proxy + ' /' : ' ' ) + url
154
+ function isSuccessive(index : number ) {
155
+ const curr = messages .value ?.data [index ]
156
+ const prev = messages .value ?.data [index - 1 ]
157
+ return curr && prev && ! curr .quote && curr .user ?.id === prev .user ?.id
148
158
}
149
159
150
160
async function setGuild(guild ? : Universal .Guild & { platform: string ; assignees: string [] }) {
@@ -170,11 +180,26 @@ function handleSend(content: string) {
170
180
return ctx .bots [ctx .chat .guilds .value [guildKey .value ! ].assignees [0 ]].sendMessage (channelId .value ! , content )
171
181
}
172
182
183
+ function formatTime(date : Date ) {
184
+ if (Number .isNaN (+ date )) return ' '
185
+ return ` ${date .getHours ()}:${date .getMinutes ().toString ().padStart (2 , ' 0' )}:${date .getSeconds ().toString ().padStart (2 , ' 0' )} `
186
+ }
187
+
188
+ function formatDateTime(date : Date ) {
189
+ if (Number .isNaN (+ date )) return ' '
190
+ const now = new Date ()
191
+ const time = formatTime (date )
192
+ if (date .toLocaleDateString () === now .toLocaleDateString ()) {
193
+ return time
194
+ }
195
+ return ` ${date .getFullYear ()}-${date .getMonth () + 1 }-${date .getDate ()} ${time } `
196
+ }
197
+
173
198
</script >
174
199
175
200
<style lang="scss" scoped>
176
201
177
- .header {
202
+ .layout-left- header {
178
203
height : var (--header-height );
179
204
border-bottom : var (--k-color-divider-dark ) 1px solid ;
180
205
}
0 commit comments