From 24c784e6a42fc521063ea89989a359f14b5bae92 Mon Sep 17 00:00:00 2001 From: Putoo <290555932@qq.com> Date: Tue, 19 May 2026 15:10:59 +0800 Subject: [PATCH] 111 --- Kx.SeaTime.sln.DotSettings.user | 3 +- .../Interface/User/IUnitUserService.cs | 5 + .../Services/Service/User/UnitUserService.cs | 68 ++++++++++++-- .../Controllers/Login/LoginController.cs | 94 +++++++++++++++++++ .../Controllers/Pub/PubController.cs | 21 +++++ .../RequestParms/Login/RegisterInfoParms.cs | 7 ++ Web/src/assets/css/style.css | 56 +++++++++++ Web/src/composables/ApiService.ts | 7 +- Web/src/extends/MessageExtend.ts | 13 +++ Web/src/pages/area/my.vue | 65 ++++++++++++- Web/src/pages/index.vue | 22 ++++- Web/src/pages/login/register.vue | 59 +++++++++++- Web/src/services/Index/PubService.ts | 8 ++ Web/src/services/login/LoginService.ts | 20 +++- 14 files changed, 429 insertions(+), 19 deletions(-) create mode 100644 Service/Application.Web/Model/RequestParms/Login/RegisterInfoParms.cs diff --git a/Kx.SeaTime.sln.DotSettings.user b/Kx.SeaTime.sln.DotSettings.user index 74ba5cd..473b539 100644 --- a/Kx.SeaTime.sln.DotSettings.user +++ b/Kx.SeaTime.sln.DotSettings.user @@ -1,3 +1,4 @@  ForceIncluded - ForceIncluded \ No newline at end of file + ForceIncluded + ForceIncluded \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/User/IUnitUserService.cs b/Service/Application.Domain/Services/Interface/User/IUnitUserService.cs index 769adda..e425968 100644 --- a/Service/Application.Domain/Services/Interface/User/IUnitUserService.cs +++ b/Service/Application.Domain/Services/Interface/User/IUnitUserService.cs @@ -5,6 +5,9 @@ public interface IUnitUserService #region 用户信息 Task> GetUserDataByAccId(string accId); + Task GetUserInfoByUserId(string userId); + Task GetUserInfoByUserNo(string userNo); + Task GetUserInfoByToken(string token); #endregion @@ -18,5 +21,7 @@ public interface IUnitUserService /// Task Register(int areaId, string accId); + Task RegisterUserInfo(string userId, string nick, string sex); + #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/User/UnitUserService.cs b/Service/Application.Domain/Services/Service/User/UnitUserService.cs index 6756ee8..732f12f 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserService.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserService.cs @@ -19,6 +19,22 @@ public class UnitUserService : IUnitUserService, ITransient var db = _dbClient.AsTenant().GetConnectionWithAttr(); return await db.Queryable().Where(it => it.accId == accId).ToListAsync(); } + public async Task GetUserInfoByUserId(string userId) + { + string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId"); + var data = await _redisClient.GetHashAsync(key, userId); + if (data == null) + { + var db = _dbClient.AsTenant().GetConnectionWithAttr(); + data = await db.Queryable().Where(it => it.userId == userId).SingleAsync(); + if (data != null) + { + await _redisClient.AddHashAsync(key, userId, data); + } + } + + return data; + } public async Task GetUserInfoByUserNo(string userNo) { string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo"); @@ -36,9 +52,9 @@ public class UnitUserService : IUnitUserService, ITransient return data; } - public async Task GetUserInfoBySid(string token) + public async Task GetUserInfoByToken(string token) { - string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid"); + string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "token"); var data = await _redisClient.GetHashAsync(key, token); if (data == null) { @@ -52,6 +68,23 @@ public class UnitUserService : IUnitUserService, ITransient return data; } + private async Task ClearUserInfo(int type, string id) + { + unit_user result = new unit_user(); + switch (type) + { + case 0: + result = await GetUserInfoByUserId(id); + break; + + case 1: + result = await GetUserInfoByToken(id); + break; + } + await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo","UserId"), result.userId); + await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo","UserNo"), result.userNo); + await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo","Sid"), result.token); + } #endregion @@ -98,8 +131,27 @@ public class UnitUserService : IUnitUserService, ITransient return result; } - - public async Task GetUserNo() + public async Task RegisterUserInfo(string userId, string nick, string sex) + { + var db = _dbClient.AsTenant().GetConnectionWithAttr(); + bool result = await db.Updateable().SetColumns(it => it.nick == nick) + .SetColumns(it => it.sex == sex) + .SetColumns(it => it.regOk == 1) + .Where(it => it.userId == userId).ExecuteCommandAsync() > 0; + if (result) + { + //注册配置信息 + + + + + + + await ClearUserInfo(0, userId); + } + return result; + } + private async Task GetUserNo() { int No = 0; bool ok = true; @@ -117,18 +169,18 @@ public class UnitUserService : IUnitUserService, ITransient private async Task GetToken() { - string sid = string.Empty; + string token = string.Empty; bool ok = true; while (ok) { - sid = StringAssist.RandomString(32); - if (await GetUserInfoBySid(sid) == null) + token = StringAssist.RandomString(32); + if (await GetUserInfoByToken(token) == null) { ok = false; } } - return sid; + return token; } #endregion diff --git a/Service/Application.Web/Controllers/Login/LoginController.cs b/Service/Application.Web/Controllers/Login/LoginController.cs index 65c21fb..e121627 100644 --- a/Service/Application.Web/Controllers/Login/LoginController.cs +++ b/Service/Application.Web/Controllers/Login/LoginController.cs @@ -138,6 +138,11 @@ namespace Application.Web.Controllers.Login return PoAction.Message("未登录账号!"); } + if (accInfo.status != 1) + { + return PoAction.Message("账号已冻结!"); + } + var areaInfo = await _areaService.GetAreaInfo(area); if (areaInfo == null) { @@ -172,5 +177,94 @@ namespace Application.Web.Controllers.Login string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, 300); return PoAction.Ok(new { token = token, refToken = userInfo.token, userId = userInfo.userId }); } + + /// + /// 登录到游戏 + /// + /// + /// + /// + [HttpGet] + public async Task LoginGame(string sid, string user) + { + if (string.IsNullOrEmpty(sid)) + { + return PoAction.Message("未登录账号!"); + } + + var accInfo = await _accountService.GetAccInfoByToken(sid); + if (accInfo == null) + { + return PoAction.Message("未登录账号!"); + } + + if (accInfo.status != 1) + { + return PoAction.Message("账号已冻结!"); + } + + var userInfo = await _userService.GetUserInfoByUserId(user); + if (userInfo == null) + { + return PoAction.Message("角色不存在!"); + } + + if (userInfo.accId != accInfo.accId) + { + return PoAction.Message("角色不存在!"); + } + + if (userInfo.status == 0) + { + return PoAction.Message("角色已封禁!"); + } + + Dictionary loadData = new Dictionary(); + loadData.Add("userId", userInfo.userId); + loadData.Add("accId", userInfo.accId); + + 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); + return PoAction.Ok(new + { regOk = userInfo.regOk, token = token, refToken = userInfo.token, userId = userInfo.userId }); + } + + /// + /// 注册角色信息 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task RegisterInfo([FromBody] RegisterInfoParms parms) + { + if (string.IsNullOrEmpty(parms.nick)) + { + return PoAction.Message("昵称不能为空!"); + } + + if (!RegExpAssist.RegStringLeght(parms.nick, 1, 12)) + { + return PoAction.Message("昵称需要1-12字符之间哦!"); + } + string sex = parms.sex == 0 ? "女" : "男"; + string userId = StateHelper.userId; + var userInfo = await _userService.GetUserInfoByUserId(userId); + if (userInfo.regOk == 1) + { + return PoAction.Ok(true); + } + + if (await _userService.RegisterUserInfo(userId, parms.nick, sex)) + { + return PoAction.Ok(true); + } + else + { + return PoAction.Message("注册失败,请稍后尝试!"); + } + } } } \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Pub/PubController.cs b/Service/Application.Web/Controllers/Pub/PubController.cs index 218d805..4aa7367 100644 --- a/Service/Application.Web/Controllers/Pub/PubController.cs +++ b/Service/Application.Web/Controllers/Pub/PubController.cs @@ -86,5 +86,26 @@ namespace Application.Web.Controllers.Pub data.sign = data.sign.Replace("[Br]", "
"); return PoAction.Ok(data); } + + /// + /// 获取用户游戏角色 + /// + /// + /// + [HttpGet] + public async Task GetMyGame(string? sid) + { + List userData = new List(); + if (!string.IsNullOrEmpty(sid)) + { + var account = await _accountService.GetAccInfoByToken(sid); + if (account != null) + { + userData = await _userService.GetUserDataByAccId(account.accId); + } + } + return PoAction.Ok(userData); + } + } } \ No newline at end of file diff --git a/Service/Application.Web/Model/RequestParms/Login/RegisterInfoParms.cs b/Service/Application.Web/Model/RequestParms/Login/RegisterInfoParms.cs new file mode 100644 index 0000000..2a2f8ea --- /dev/null +++ b/Service/Application.Web/Model/RequestParms/Login/RegisterInfoParms.cs @@ -0,0 +1,7 @@ +namespace Application.Web; + +public class RegisterInfoParms +{ + public string nick { get; set; } = string.Empty; + public int sex { 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 ae7a5ca..6e74153 100644 --- a/Web/src/assets/css/style.css +++ b/Web/src/assets/css/style.css @@ -96,4 +96,60 @@ a:focus { .common img { margin-right: 2px; vertical-align: middle; +} + +.input { + line-height: 30px; +} + +.ipt { + width: 60%; + display: block; + padding: 6px 12px; + font-size: 14px; + color: #555; + background-color: #fff; + background-image: none; + border: 1px solid #ccc; + border-radius: 4px; + box-shadow: inset 0 1px 1px rgb(0 0 0 / 8%); + transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s; +} + +.btn { + display: inline-block; + margin-bottom: 0; + font-size: 14px; + font-weight: 400; + text-align: center; + white-space: nowrap; + vertical-align: middle; + -ms-touch-action: manipulation; + touch-action: manipulation; + cursor: pointer; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + background-image: none; + border: 1px solid transparent; + border-radius: 4px; +} + +.btn-danger { + color: #fff; + background-color: #d9534f; + border-color: #d43f3a; +} + +.btn-waring { + color: #fff; + background-color: #FE5E08; + border-color: #FE5E08; +} + +.btn-ret { + border-color: #d2d2d2; + background: 0 0; + color: #666; } \ No newline at end of file diff --git a/Web/src/composables/ApiService.ts b/Web/src/composables/ApiService.ts index caa7fab..5d949a6 100644 --- a/Web/src/composables/ApiService.ts +++ b/Web/src/composables/ApiService.ts @@ -11,7 +11,10 @@ export type HandledRedirectError = { export class ApiService { private static initialized = false; - + + private static get userStore() { + return useUserStore() + } private static request = new RequestExtend({ baseURL: BaseConfig.BaseUrl, timeout: 60000 @@ -43,7 +46,7 @@ export class ApiService { RequestExtend.addRequestInterceptor({ onFulfilled: (config) => { - const token = typeof localStorage !== "undefined" ? localStorage.getItem("token") : ""; + const token = this.userStore.token; if (token) { config.headers = { diff --git a/Web/src/extends/MessageExtend.ts b/Web/src/extends/MessageExtend.ts index f203e45..09dbf81 100644 --- a/Web/src/extends/MessageExtend.ts +++ b/Web/src/extends/MessageExtend.ts @@ -11,6 +11,19 @@ export class MessageExtend { }); } + static LoadingToast(message?: string) { + showLoadingToast({ + message: message || '加载中', + forbidClick: true, + loadingType: 'spinner', + duration: 0 + }); + } + + static LoadingClose() { + closeToast(); + } + // 提示弹窗 static ShowDialog(title: string, message: string) { showDialog({ title: title, message: message }) diff --git a/Web/src/pages/area/my.vue b/Web/src/pages/area/my.vue index 41a40c8..45e8d58 100644 --- a/Web/src/pages/area/my.vue +++ b/Web/src/pages/area/my.vue @@ -1 +1,64 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/Web/src/pages/index.vue b/Web/src/pages/index.vue index e1c3e17..192847f 100644 --- a/Web/src/pages/index.vue +++ b/Web/src/pages/index.vue @@ -31,7 +31,8 @@ @@ -125,8 +126,7 @@ const Initialize = async (): Promise => { /**自动登录 */ const login = async (code: string): Promise => { - let result = await LoginService.TwLogin(code); - console.log(result); + let result = await LoginService.TwLogin(code); if (result.code == 0) { StateHelper.SetSid(result.data.token); await Initialize(); @@ -142,7 +142,7 @@ const offOnline = async () => { let result = await PubService.GetMain(StateHelper.Sid); if (result.code == 0) { StateHelper.OffOnline(); - isOnline.value = false; + await Initialize(); MessageExtend.ShowToast("退出成功!", "success"); } else { @@ -153,7 +153,19 @@ const offOnline = async () => { /**登录到游戏 */ const loginGame = async (gameId: string): Promise => { - alert(gameId) + let result = await LoginService.LoginGame(StateHelper.Sid, gameId); + if (result.code == 0) { + StateHelper.SetToken(result.data.userId, result.data.token, result.data.refToken); + if (result.data.regOk == 0) { + PageExtend.Redirect("/login/register"); + } + else { + PageExtend.Redirect("/map"); + } + } + else { + MessageExtend.ShowDialog("注册角色", result.msg); + } }; /**注册游戏 */ diff --git a/Web/src/pages/login/register.vue b/Web/src/pages/login/register.vue index 41a40c8..a90d11e 100644 --- a/Web/src/pages/login/register.vue +++ b/Web/src/pages/login/register.vue @@ -1 +1,58 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/Web/src/services/Index/PubService.ts b/Web/src/services/Index/PubService.ts index c143ea0..fdc60f4 100644 --- a/Web/src/services/Index/PubService.ts +++ b/Web/src/services/Index/PubService.ts @@ -22,4 +22,12 @@ export class PubService { static async GetNoticeInfo(id: string) { return await ApiService.Request("get", "/Pub/GetNoticeInfo", { id }); } + + /** + * 获取用户游戏角色 + * GET /Pub/GetMyGame + */ + static async GetMyGame(sid: string) { + return await ApiService.Request("get", "/Pub/GetMyGame", { sid }); + } } \ No newline at end of file diff --git a/Web/src/services/login/LoginService.ts b/Web/src/services/login/LoginService.ts index 4d12c50..cb17f29 100644 --- a/Web/src/services/login/LoginService.ts +++ b/Web/src/services/login/LoginService.ts @@ -29,9 +29,27 @@ export class LoginService { /** * 注册基础账号信息 - * GET /Login/Regist + * GET /Login/Register */ static async Register(sid: string, area: number) { return await ApiService.Request("get", "/Login/Register", { sid, area }); } + + /** + * 登录到游戏 + * GET /Login/LoginGame + */ + static async LoginGame(sid: string, user: string) { + return await ApiService.Request("get", "/Login/LoginGame", { sid, user }); + } + + /** + * 注册角色信息 + * POST /Login/RegisterInfo + * @param nick body + * @param sex body + */ + static async RegisterInfo(nick: string, sex: number) { + return await ApiService.Request("post", "/Login/RegisterInfo", { nick, sex }); + } } \ No newline at end of file