Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fc-minigame
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈冲
fc-minigame
Commits
d65da20b
Commit
d65da20b
authored
Jun 17, 2026
by
陈冲
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加查询前10接口
parent
e103caf8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
2 deletions
+103
-2
game.rs
backend/src/db/models/game.rs
+37
-1
socket_io.rs
backend/src/protocols/socket_io.rs
+39
-0
router.rs
backend/src/router.rs
+4
-0
test2.html
backend/src/web/test2.html
+23
-1
No files found.
backend/src/db/models/game.rs
View file @
d65da20b
use
crate
::{
commons
::
utils
::
CONFIG
as
config
,
db
::
models
::
log
::
Log
};
use
crate
::{
commons
::
utils
::
CONFIG
as
config
,
db
::
models
::{
get_i32
,
get_string
,
log
::
Log
},
};
use
chrono
::{
DateTime
,
NaiveDate
,
Utc
};
use
chrono
::{
DateTime
,
NaiveDate
,
Utc
};
use
serde_json
::
json
;
use
serde_json
::
json
;
...
@@ -101,4 +104,37 @@ impl Game {
...
@@ -101,4 +104,37 @@ impl Game {
}
}
}
}
}
}
pub
async
fn
get_top10
(
batch_no
:
&
str
)
->
Result
<
Vec
<
Self
>
,
String
>
{
let
Some
(
_
)
=
&
config
.db
else
{
println!
(
"没有配置数据库, get_top10 return err;"
);
return
Err
(
"没有配置数据库, get_top10 return err"
.to_string
());
};
let
res
=
crate
::
db
::
db_query
(
r
#
"SELECT wechat_id,nickname,avatar,item_num,game_rank,score,batch_no
FROM tb_game
WHERE batch_no LIKE ? AND game_rank BETWEEN 1 AND 10
ORDER BY game_rank ASC"
#
,
vec!
[
json!
(
format!
(
"{}
%
"
,
batch_no
.trim
()))],
)
.await
;
match
res
{
Ok
(
rows
)
=>
rows
.iter
()
.map
(|
row
|
{
Ok
(
Game
{
wechat_id
:
get_string
(
row
,
"wechat_id"
)
?
,
nickname
:
get_string
(
row
,
"nickname"
)
?
,
avatar
:
get_string
(
row
,
"avatar"
)
?
,
item_num
:
get_i32
(
row
,
"item_num"
)
?
,
game_rank
:
get_i32
(
row
,
"game_rank"
)
?
,
score
:
get_i32
(
row
,
"score"
)
?
,
create_date
:
None
,
batch_no
:
get_string
(
row
,
"batch_no"
)
?
,
})
})
.collect
(),
Err
(
err
)
=>
Err
(
err
),
}
}
}
}
backend/src/protocols/socket_io.rs
View file @
d65da20b
...
@@ -1244,6 +1244,45 @@ pub async fn on_connect(_io: SocketIo, socket: SocketRef, Data(data): Data<Value
...
@@ -1244,6 +1244,45 @@ pub async fn on_connect(_io: SocketIo, socket: SocketRef, Data(data): Data<Value
}
}
#[handler]
#[handler]
pub
async
fn
getTop10Rank
(
req
:
&
mut
Request
,
res
:
&
mut
Response
)
{
let
params
=
match
req
.parse_body
::
<
HashMap
<
String
,
String
>>
()
.await
{
Ok
(
params
)
=>
params
,
Err
(
_
)
=>
{
res
.render
(
Json
(
err_resp
(
"参数格式错误"
,
None
)));
return
;
}
};
let
batch_no
=
params
.get
(
"batch_no"
)
.map
(|
value
|
value
.trim
())
.unwrap_or_default
();
match
Game
::
get_top10
(
batch_no
)
.await
{
Ok
(
list
)
=>
{
let
payload
=
list
.iter
()
.map
(|
game
|
{
json!
({
"wechat_id"
:
game
.wechat_id
,
"nickname"
:
game
.nickname
,
"avatar"
:
game
.avatar
,
"item_num"
:
game
.item_num
,
"game_rank"
:
game
.game_rank
,
"score"
:
game
.score
,
"batch_no"
:
game
.batch_no
,
})
})
.collect
::
<
Vec
<
_
>>
();
res
.render
(
Json
(
ok_resp
(
Some
(
json!
(
payload
)))));
}
Err
(
err
)
=>
{
res
.render
(
Json
(
err_resp
(
&
err
,
None
)));
}
}
}
#[handler]
pub
async
fn
getConn
(
req
:
&
mut
Request
,
res
:
&
mut
Response
)
{
pub
async
fn
getConn
(
req
:
&
mut
Request
,
res
:
&
mut
Response
)
{
res
.render
(
Json
(
ok_resp
(
Some
(
json!
({
res
.render
(
Json
(
ok_resp
(
Some
(
json!
({
"socket_path"
:
&
config
.socket_path
.clone
(),
"socket_path"
:
&
config
.socket_path
.clone
(),
...
...
backend/src/router.rs
View file @
d65da20b
...
@@ -26,6 +26,10 @@ pub fn config_router() -> Router {
...
@@ -26,6 +26,10 @@ pub fn config_router() -> Router {
)
)
.push
(
Router
::
with_path
(
"/manager/login"
)
.post
(
crate
::
protocols
::
socket_io
::
login
))
.push
(
Router
::
with_path
(
"/manager/login"
)
.post
(
crate
::
protocols
::
socket_io
::
login
))
.push
(
Router
::
with_path
(
"/manager/getConn"
)
.post
(
crate
::
protocols
::
socket_io
::
getConn
))
.push
(
Router
::
with_path
(
"/manager/getConn"
)
.post
(
crate
::
protocols
::
socket_io
::
getConn
))
.push
(
Router
::
with_path
(
"/manager/getTop10Rank"
)
.post
(
crate
::
protocols
::
socket_io
::
getTop10Rank
),
)
}
}
pub
fn
config_catcher
()
->
Catcher
{
pub
fn
config_catcher
()
->
Catcher
{
...
...
backend/src/web/test2.html
View file @
d65da20b
...
@@ -139,6 +139,7 @@
...
@@ -139,6 +139,7 @@
</select>
</select>
<button
@
click=
"joinRoom"
>
进入房间
</button>
<button
@
click=
"joinRoom"
>
进入房间
</button>
<button
@
click=
"submitScore"
>
随机添加分数
</button>
<button
@
click=
"submitScore"
>
随机添加分数
</button>
<button
@
click=
"getTop10Rank('1781673275')"
>
获取前十排名
</button>
</div>
</div>
<hr
/>
<hr
/>
当前玩家数量:{{dic.size}}
当前玩家数量:{{dic.size}}
...
@@ -197,6 +198,26 @@
...
@@ -197,6 +198,26 @@
const
{
createApp
,
ref
}
=
Vue
const
{
createApp
,
ref
}
=
Vue
createApp
({
createApp
({
methods
:
{
methods
:
{
getTop10Rank
:
async
function
(
batch_no
)
{
let
ws
=
'https://hddp.guocai365.org.cn'
;
ws
=
'http://127.0.0.1:8082'
;
const
res
=
await
fetch
(
`
${
ws
}
/manager/getTop10Rank`
,
{
method
:
'POST'
,
headers
:
{
'Content-Type'
:
'application/json'
,
},
body
:
JSON
.
stringify
({
batch_no
:
batch_no
,
}),
})
if
(
!
res
.
ok
)
{
throw
new
Error
(
`HTTP
${
res
.
status
}
`
)
}
let
data
=
await
res
.
json
();
console
.
log
(
data
);
},
setStatus
:
function
(
msg
)
{
setStatus
:
function
(
msg
)
{
this
.
message
=
msg
;
this
.
message
=
msg
;
},
},
...
@@ -358,4 +379,4 @@
...
@@ -358,4 +379,4 @@
</script>
</script>
</body>
</body>
</html>
</html>
\ No newline at end of file
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