Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Neos
Commits
f1adce7e
Commit
f1adce7e
authored
Sep 18, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update chatbox
parent
fef2e9b4
Pipeline
#23501
passed with stages
in 12 minutes and 18 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
8 deletions
+138
-8
src/ui/Duel/PlayMat/ChatBox/index.module.scss
src/ui/Duel/PlayMat/ChatBox/index.module.scss
+49
-4
src/ui/Duel/PlayMat/ChatBox/index.tsx
src/ui/Duel/PlayMat/ChatBox/index.tsx
+89
-4
No files found.
src/ui/Duel/PlayMat/ChatBox/index.module.scss
View file @
f1adce7e
.chatbox
{
.chatbox
{
position
:
relative
;
position
:
relative
;
height
:
50%
!
important
;
height
:
60%
!
important
;
width
:
80%
!
important
;
width
:
60%
!
important
;
left
:
10%
;
background-color
:
#0d0d0d
8f
;
bottom
:
-40%
;
left
:
20%
;
bottom
:
-30%
;
border-radius
:
6px
;
border-radius
:
6px
;
:global
(
.ant-drawer-header
)
{
:global
(
.ant-drawer-header
)
{
padding
:
8px
4px
;
padding
:
8px
4px
;
}
}
:global
(
.ant-drawer-body
)
{
padding
:
16px
;
}
}
.container
{
display
:
flex
;
flex-direction
:
column
;
height
:
100%
;
max-height
:
100%
;
}
.input
{
display
:
flex
;
width
:
100%
;
margin-top
:
auto
;
background-color
:
hsla
(
0
,
0%
,
100%
,
0
.07
);
padding
:
4px
;
border-radius
:
4px
;
}
.dialogs
{
display
:
flex
;
flex-direction
:
column
;
position
:
absolute
;
padding
:
8px
0
;
width
:
100%
;
gap
:
2px
;
.item
{
vertical-align
:
baseline
;
.name
,
.content
{
display
:
inline-block
;
}
.name
{
font-weight
:
500
;
line-height
:
1
.375rem
;
}
.content
{
font-size
:
14px
;
color
:
green
;
margin-top
:
2px
;
}
}
}
}
src/ui/Duel/PlayMat/ChatBox/index.tsx
View file @
f1adce7e
import
{
DownOutlined
}
from
"
@ant-design/icons
"
;
import
{
DownOutlined
}
from
"
@ant-design/icons
"
;
import
{
Drawer
}
from
"
antd
"
;
import
{
Button
,
Drawer
,
Input
}
from
"
antd
"
;
import
React
from
"
react
"
;
import
{
type
OverlayScrollbarsComponentRef
}
from
"
overlayscrollbars-react
"
;
import
React
,
{
useEffect
,
useRef
,
useState
}
from
"
react
"
;
import
{
proxy
,
useSnapshot
}
from
"
valtio
"
;
import
{
proxy
,
useSnapshot
}
from
"
valtio
"
;
import
{
sendChat
}
from
"
@/api
"
;
import
{
chatStore
,
roomStore
}
from
"
@/stores
"
;
import
{
IconFont
,
ScrollableArea
}
from
"
@/ui/Shared
"
;
import
styles
from
"
./index.module.scss
"
;
import
styles
from
"
./index.module.scss
"
;
const
store
=
proxy
({
open
:
false
});
const
store
=
proxy
({
open
:
false
});
interface
ChatItem
{
name
:
string
;
content
:
string
;
}
export
const
ChatBox
:
React
.
FC
=
()
=>
{
export
const
ChatBox
:
React
.
FC
=
()
=>
{
const
{
open
}
=
useSnapshot
(
store
);
const
{
open
}
=
useSnapshot
(
store
);
const
onClose
=
()
=>
(
store
.
open
=
false
);
const
[
chatList
,
setChatList
]
=
useState
<
ChatItem
[]
>
([]);
const
[
input
,
setInput
]
=
useState
<
string
|
undefined
>
(
undefined
);
const
chat
=
useSnapshot
(
chatStore
);
useEffect
(()
=>
{
if
(
chatStore
.
sender
>=
0
&&
chatStore
.
message
.
length
!==
0
)
{
const
{
sender
}
=
chatStore
;
const
name
=
sender
<
roomStore
.
players
.
length
?
roomStore
.
players
[
sender
]?.
name
??
"
?
"
:
(
sender
>
8
&&
sender
<
11
)
||
sender
>
19
?
"
?
"
:
"
System
"
;
setChatList
((
prev
)
=>
[
...
prev
,
{
name
:
name
,
content
:
chatStore
.
message
,
},
]);
scrollToBottom
();
}
},
[
chat
]);
/** 滚动条的ref */
const
ref
=
useRef
<
OverlayScrollbarsComponentRef
<
"
div
"
>>
(
null
);
/** dialogs 滚动到最底下 */
const
scrollToBottom
=
()
=>
{
const
viewport
=
ref
.
current
?.
osInstance
()?.
elements
().
viewport
;
if
(
viewport
)
{
viewport
.
scrollTop
=
viewport
.
scrollHeight
;
}
};
const
onClose
=
()
=>
(
store
.
open
=
false
);
/** 发信息 */
const
onSend
=
()
=>
{
if
(
input
!==
undefined
)
{
sendChat
(
input
);
setInput
(
""
);
}
};
return
(
return
(
<
Drawer
<
Drawer
open=
{
open
}
open=
{
open
}
...
@@ -19,8 +70,42 @@ export const ChatBox: React.FC = () => {
...
@@ -19,8 +70,42 @@ export const ChatBox: React.FC = () => {
className=
{
styles
.
chatbox
}
className=
{
styles
.
chatbox
}
onClose=
{
onClose
}
onClose=
{
onClose
}
closeIcon=
{
<
DownOutlined
/>
}
closeIcon=
{
<
DownOutlined
/>
}
></
Drawer
>
>
<
div
className=
{
styles
.
container
}
>
<
ScrollableArea
className=
{
styles
.
dialogs
}
ref=
{
ref
}
>
{
chatList
.
map
((
item
,
idx
)
=>
(
<
DialogItem
key=
{
idx
}
{
...
item
}
/>
))
}
</
ScrollableArea
>
<
div
className=
{
styles
.
input
}
>
<
Input
.
TextArea
bordered=
{
false
}
value=
{
input
}
onChange=
{
(
event
)
=>
setInput
(
event
.
target
.
value
)
}
autoSize
placeholder=
"请输入聊天内容"
onPressEnter=
{
(
e
)
=>
{
e
.
preventDefault
();
onSend
();
}
}
/>
<
Button
type=
"text"
icon=
{
<
IconFont
type=
"icon-send"
size=
{
14
}
/>
}
onClick=
{
onSend
}
/>
</
div
>
</
div
>
</
Drawer
>
);
);
};
};
const
DialogItem
:
React
.
FC
<
ChatItem
>
=
({
name
,
content
})
=>
(
<
div
className=
{
styles
.
item
}
>
<
div
className=
{
styles
.
name
}
>
{
name
}
</
div
>
<
span
>
{
` > `
}
</
span
>
<
div
className=
{
styles
.
content
}
>
{
content
}
</
div
>
</
div
>
);
export
const
openChatBox
=
()
=>
(
store
.
open
=
true
);
export
const
openChatBox
=
()
=>
(
store
.
open
=
true
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment