Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
健杭 徐
intern_project_frontend_backend
Commits
06f8c355
Commit
06f8c355
authored
Jun 26, 2025
by
健杭 徐
Browse files
update rooms lastsender and lastcomment
parent
cf2d57c6
Changes
3
Show whitespace changes
Inline
Side-by-side
myproject/README.md
0 → 100644
View file @
06f8c355
# README
### 1.go返回数组时格式问题
### 2.添加了头像
### 3.使用了`react-icons/md`
## unfinished
### 1.deleted function
myproject/chatroom/main.go
View file @
06f8c355
...
@@ -224,6 +224,7 @@ func AddMessage(c *gin.Context) {
...
@@ -224,6 +224,7 @@ func AddMessage(c *gin.Context) {
return
return
}
}
// 写入评论
query
:=
`
query
:=
`
INSERT INTO messages (room_id, profile, sender, content, "time")
INSERT INTO messages (room_id, profile, sender, content, "time")
VALUES ($1, $2, $3, $4, NOW())
VALUES ($1, $2, $3, $4, NOW())
...
@@ -236,8 +237,9 @@ func AddMessage(c *gin.Context) {
...
@@ -236,8 +237,9 @@ func AddMessage(c *gin.Context) {
return
return
}
}
// 更新room
_
,
err
=
db
.
Exec
(
_
,
err
=
db
.
Exec
(
"UPDATE rooms SET last
S
ender = $1, last
C
ontent = $2, last
T
ime = NOW() WHERE room_id = $3"
,
"UPDATE rooms SET last
_s
ender = $1, last
_c
ontent = $2, last
_t
ime = NOW() WHERE room_id = $3"
,
message
.
Sender
,
message
.
Content
,
message
.
RoomId
,
message
.
Sender
,
message
.
Content
,
message
.
RoomId
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
myproject/my-app/src/app/pages/ChatRoom/ChatRoom.tsx
View file @
06f8c355
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
import
"
./ChatRoom.css
"
;
import
"
./ChatRoom.css
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
const
backEnd
:
string
=
"
http://
10.171.208.94
:8080
"
;
const
backEnd
:
string
=
"
http://
localhost
:8080
"
;
const
Profile
=
[
'
https://pic4.zhimg.com/v2-c5a0d0d57c1a85c6db56e918707f54a3_r.jpg
'
,
const
Profile
=
[
'
https://pic4.zhimg.com/v2-c5a0d0d57c1a85c6db56e918707f54a3_r.jpg
'
,
'
https://pic2.zhimg.com/v2-c2e79191533fdc7fced2f658eef987c9_r.jpg
'
,
'
https://pic2.zhimg.com/v2-c2e79191533fdc7fced2f658eef987c9_r.jpg
'
,
...
@@ -33,8 +33,6 @@ interface MessageProps {
...
@@ -33,8 +33,6 @@ interface MessageProps {
}
>
;
}
>
;
}
}
let
RoomName
:
RoomEntryProps
[]
=
[]
function
RoomEntry
({
rooms
,
onRoomClick
}
:
{
rooms
:
RoomEntryProps
[],
onRoomClick
:
(
roomId
:
number
,
roomName
:
string
)
=>
void
})
{
function
RoomEntry
({
rooms
,
onRoomClick
}
:
{
rooms
:
RoomEntryProps
[],
onRoomClick
:
(
roomId
:
number
,
roomName
:
string
)
=>
void
})
{
return
(
return
(
<
div
className
=
"chat-room-nav"
>
<
div
className
=
"chat-room-nav"
>
...
@@ -52,8 +50,10 @@ function RoomEntry ({rooms, onRoomClick} : {rooms: RoomEntryProps[], onRoomClick
...
@@ -52,8 +50,10 @@ function RoomEntry ({rooms, onRoomClick} : {rooms: RoomEntryProps[], onRoomClick
<
img
src
=
{
RoomProfile
}
alt
=
"Avatar"
className
=
"avatar"
/>
<
img
src
=
{
RoomProfile
}
alt
=
"Avatar"
className
=
"avatar"
/>
<
div
className
=
"chat-info"
>
<
div
className
=
"chat-info"
>
<
h3
>
{
room
.
roomName
}
</
h3
>
<
h3
>
{
room
.
roomName
}
</
h3
>
<
span
className
=
"chat-message"
>
{
room
.
lastContent
&&
room
.
lastContent
.
Valid
?
room
.
lastContent
.
String
:
''
}
</
span
>
<
span
className
=
"chat-message"
>
<
span
className
=
"chat-time"
>
{
room
.
lastTime
&&
room
.
lastTime
.
Valid
?
formatTimeToHoursMinutes
(
room
.
lastTime
.
Time
)
:
''
}
</
span
>
{
room
.
lastSender
.
Valid
?
room
.
lastSender
.
String
:
''
}
:
{
room
.
lastContent
.
Valid
?
room
.
lastContent
.
String
:
''
}
</
span
>
<
span
className
=
"chat-time"
>
{
room
.
lastTime
.
Valid
?
formatTimeToHoursMinutes
(
room
.
lastTime
.
Time
)
:
''
}
</
span
>
</
div
>
</
div
>
</
div
>
</
div
>
))
}
))
}
...
@@ -307,6 +307,7 @@ export function ChatRoom({ userName }: { userName: string }) {
...
@@ -307,6 +307,7 @@ export function ChatRoom({ userName }: { userName: string }) {
})
})
const
result
=
await
response
.
json
();
const
result
=
await
response
.
json
();
debugger
;
if
(
result
.
code
!=
0
)
{
if
(
result
.
code
!=
0
)
{
alert
(
`Error:
${
result
.
Msg
}
`
);
alert
(
`Error:
${
result
.
Msg
}
`
);
return
;
return
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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