From 2c85872abde1eb1b0f19175e39286d34b3ecc971 Mon Sep 17 00:00:00 2001 From: Putoo <290555932@qq.com> Date: Tue, 19 May 2026 18:34:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Application.Web/Config/TokenConfig.cs | 7 + .../Controllers/Login/LoginController.cs | 39 ++++- .../RequestParms/Login/RefreshTokenParms.cs | 7 + Web/src/assets/css/style.css | 21 +++ Web/src/components/Abutton.vue | 16 +- Web/src/composables/ApiService.ts | 142 +++++++++++++----- Web/src/layouts/default.vue | 31 +++- Web/src/pages/area/my.vue | 4 +- Web/src/pages/index.vue | 10 +- Web/src/pages/map/index.vue | 125 ++++++++++++++- 10 files changed, 341 insertions(+), 61 deletions(-) create mode 100644 Service/Application.Web/Config/TokenConfig.cs create mode 100644 Service/Application.Web/Model/RequestParms/Login/RefreshTokenParms.cs diff --git a/Service/Application.Web/Config/TokenConfig.cs b/Service/Application.Web/Config/TokenConfig.cs new file mode 100644 index 0000000..4613941 --- /dev/null +++ b/Service/Application.Web/Config/TokenConfig.cs @@ -0,0 +1,7 @@ +namespace Application.Web; + +public class TokenConfig +{ + public const int TokenTime = 5;//分钟 + +} \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Login/LoginController.cs b/Service/Application.Web/Controllers/Login/LoginController.cs index e121627..b599e2a 100644 --- a/Service/Application.Web/Controllers/Login/LoginController.cs +++ b/Service/Application.Web/Controllers/Login/LoginController.cs @@ -174,7 +174,7 @@ namespace Application.Web.Controllers.Login string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString(); string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString(); string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString(); - string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, 300); + string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, TokenConfig.TokenTime); return PoAction.Ok(new { token = token, refToken = userInfo.token, userId = userInfo.userId }); } @@ -226,11 +226,46 @@ namespace Application.Web.Controllers.Login string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString(); string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString(); string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString(); - string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, 1); + string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, TokenConfig.TokenTime); return PoAction.Ok(new { regOk = userInfo.regOk, token = token, refToken = userInfo.token, userId = userInfo.userId }); } + [HttpPost] + public async Task RefreshToken([FromBody] RefreshTokenParms parms) + { + if (string.IsNullOrEmpty(parms.token) || string.IsNullOrEmpty(parms.refToken)) + { + return PoAction.Message("刷新失败"); + } + + string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString(); + string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString(); + string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString(); + var data = JwtHelper.GetTokenPload(parms.token,Key); + string accId = string.Empty; + if (data.TryGetValue("accId", out object _accId)) + { + accId = _accId.ToString(); + } + var userInfo = await _userService.GetUserInfoByToken(parms.refToken); + if (userInfo == null) + { + return PoAction.Message("刷新失败,用户不存在!"); + } + + if (userInfo.accId != accId) + { + return PoAction.Message("刷新失败,数据信息不合法!"); + } + Dictionary loadData = new Dictionary(); + loadData.Add("userId", userInfo.userId); + loadData.Add("accId", userInfo.accId); + string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, TokenConfig.TokenTime); + return PoAction.Ok(new + { token = token, refToken = userInfo.token, userId = userInfo.userId }); + } + /// /// 注册角色信息 /// diff --git a/Service/Application.Web/Model/RequestParms/Login/RefreshTokenParms.cs b/Service/Application.Web/Model/RequestParms/Login/RefreshTokenParms.cs new file mode 100644 index 0000000..4a3172d --- /dev/null +++ b/Service/Application.Web/Model/RequestParms/Login/RefreshTokenParms.cs @@ -0,0 +1,7 @@ +namespace Application.Web; + +public class RefreshTokenParms +{ + public string refToken { get; set; } + public string token { get; set; } +} \ No newline at end of file diff --git a/Web/src/assets/css/style.css b/Web/src/assets/css/style.css index 6e74153..73542b9 100644 --- a/Web/src/assets/css/style.css +++ b/Web/src/assets/css/style.css @@ -115,6 +115,27 @@ a:focus { box-shadow: inset 0 1px 1px rgb(0 0 0 / 8%); transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s; } +.ipt-btn-gray-m { + width: 60px; + height: 20px; + border: none; +} +.chat { + word-wrap: break-word; +} + + .chat img { + margin-right: 2px; + vertical-align: middle; + } +.em { + height: 30px; + width: 30px; +} +.badge { + max-height: 25px; + max-width: 25px; +} .btn { display: inline-block; diff --git a/Web/src/components/Abutton.vue b/Web/src/components/Abutton.vue index 224355b..2791b29 100644 --- a/Web/src/components/Abutton.vue +++ b/Web/src/components/Abutton.vue @@ -1,12 +1,9 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Web/src/pages/area/my.vue b/Web/src/pages/area/my.vue index 45e8d58..8add737 100644 --- a/Web/src/pages/area/my.vue +++ b/Web/src/pages/area/my.vue @@ -6,8 +6,8 @@
- ✧【{{ item.areaId }}区】{{ item.nick }}({{ (item.sex == null || item.sex == '') ? - "未知" : item.sex }}) + ✧【{{ item.areaId }}区】{{ item.nick }}({{ (item.sex == null || item.sex == '') ? + "未知" : item.sex }})
暂无角色.
diff --git a/Web/src/pages/index.vue b/Web/src/pages/index.vue index 192847f..69bd5ec 100644 --- a/Web/src/pages/index.vue +++ b/Web/src/pages/index.vue @@ -18,7 +18,7 @@
游戏论坛   - ➸退出游戏 + ➸退出游戏
@@ -31,8 +31,8 @@
- 【{{ item.areaId }}区】{{ item.nick }}({{ (item.sex == null || item.sex == '') ? - "未知" : item.sex }}) + 【{{ item.areaId }}区】{{ item.nick }}({{ (item.sex == null || item.sex == '') ? + "未知" : item.sex }})
@@ -42,7 +42,7 @@
- ✧({{ item.areaId }}区){{ item.name }} + ✧({{ item.areaId }}区){{ item.name }} {{ item.status == 1 ? "(推荐)" : "(繁忙)" }}
暂无区服. @@ -164,7 +164,7 @@ const loginGame = async (gameId: string): Promise => { } } else { - MessageExtend.ShowDialog("注册角色", result.msg); + MessageExtend.ShowDialog("登录游戏", result.msg); } }; diff --git a/Web/src/pages/map/index.vue b/Web/src/pages/map/index.vue index 41a40c8..1bdace9 100644 --- a/Web/src/pages/map/index.vue +++ b/Web/src/pages/map/index.vue @@ -1 +1,124 @@ - \ No newline at end of file + + \ No newline at end of file