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
c48b7d0f
Commit
c48b7d0f
authored
Jun 27, 2025
by
健杭 徐
Browse files
finish
parent
50dc23f5
Changes
3
Hide whitespace changes
Inline
Side-by-side
comment-system/static/src/App.tsx
View file @
c48b7d0f
import
{
COMMENT_ADD
}
from
"
./assets/const
"
;
async
function
AddComment
({
name
,
onSuccess
}:
{
name
:
string
;
onSuccess
:
()
=>
void
;
})
{
const
textInput
=
document
.
getElementById
(
'
textInput
'
)
as
HTMLInputElement
;
const
content
=
textInput
.
value
;
...
...
@@ -11,7 +13,7 @@ async function AddComment({ name, onSuccess }: { name: string; onSuccess: () =>
}
try
{
const
response
=
await
fetch
(
'
http://localhost:8080/comment/add
'
,
{
const
response
=
await
fetch
(
COMMENT_ADD
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
({
name
,
content
,
created_at
:
new
Date
().
toISOString
()
})
...
...
comment-system/static/src/CommentSection.tsx
View file @
c48b7d0f
import
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
{
COMMENT_GET
,
COMMENT_DEL
}
from
'
./assets/const
'
function
useInterval
(
callback
:
()
=>
void
,
delay
:
number
|
null
)
{
const
savedCallback
=
useRef
<
()
=>
void
>
(
undefined
);
...
...
@@ -37,7 +38,7 @@ export function CommentSection({ refreshTrigger }: { refreshTrigger: number }) {
const
loadComments
=
async
(
page
:
number
)
=>
{
try
{
const
response
=
await
fetch
(
`http://localhost:8080/comment/get
?page=
${
page
}
&size=
${
pageSize
}
`
);
const
response
=
await
fetch
(
COMMENT_GET
+
`
?page=
${
page
}
&size=
${
pageSize
}
`
);
const
result
=
await
response
.
json
();
if
(
result
.
code
!==
0
)
throw
new
Error
(
result
.
msg
);
...
...
@@ -53,7 +54,7 @@ export function CommentSection({ refreshTrigger }: { refreshTrigger: number }) {
if
(
!
confirm
(
'
确定要删除这条评论吗?
'
))
return
;
try
{
const
response
=
await
fetch
(
`http://localhost:8080/comment/delete
?id=
${
commentId
}
`
,
{
const
response
=
await
fetch
(
COMMENT_DEL
+
`
?id=
${
commentId
}
`
,
{
method
:
'
POST
'
});
const
result
=
await
response
.
json
();
...
...
comment-system/static/src/assets/const.tsx
0 → 100644
View file @
c48b7d0f
export
const
COMMENT_ADD
:
string
=
'
http://localhost:8080/comment/add
'
export
const
COMMENT_GET
:
string
=
'
http://localhost:8080/comment/get
'
export
const
COMMENT_DEL
:
string
=
'
http://localhost:8080/comment/delete
'
\ No newline at end of file
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