11
This commit is contained in:
@@ -10,4 +10,8 @@
|
|||||||
<ProjectReference Include="..\Application.Service.Pub\Application.Service.Pub.csproj" />
|
<ProjectReference Include="..\Application.Service.Pub\Application.Service.Pub.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="game\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
93
Service/Application.Domain.Entity/game/user/unit_user.cs
Normal file
93
Service/Application.Domain.Entity/game/user/unit_user.cs
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Application.Domain.Entity
|
||||||
|
{
|
||||||
|
[Tenant("Kg.SeaTime.Game")]
|
||||||
|
public class unit_user
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// userId
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||||
|
public string userId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 账号ID
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 50, IsNullable = true)]
|
||||||
|
public string? accId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 区服
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public int? areaId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// userNo
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 12, IsNullable = false)]
|
||||||
|
public string userNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 名称
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public string? nick { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 头像
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 255, IsNullable = true)]
|
||||||
|
public string? headImg { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 性别
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 50, IsNullable = true)]
|
||||||
|
public string? sex { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 简介
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 50, IsNullable = true)]
|
||||||
|
public string? sign { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 状态
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public int? status { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注册状态
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public int? regOk { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// token
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 50, IsNullable = true)]
|
||||||
|
public string? token { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否系统账号
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public int? isSystem { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建时间
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public DateTime? addTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 最后更新时间
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public DateTime? upTime { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,4 +4,5 @@ public interface INoticeService
|
|||||||
{
|
{
|
||||||
Task<List<game_notice>> GetNoticeDataByTake(int take);
|
Task<List<game_notice>> GetNoticeDataByTake(int take);
|
||||||
Task<List<game_notice>> GetNoticeData(int page, int limit, RefAsync<int> total);
|
Task<List<game_notice>> GetNoticeData(int page, int limit, RefAsync<int> total);
|
||||||
|
Task<game_notice> GetNoticeInfo(string id);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
namespace Application.Domain;
|
||||||
|
|
||||||
|
public interface IUnitUserService
|
||||||
|
{
|
||||||
|
#region 用户信息
|
||||||
|
|
||||||
|
Task<List<unit_user>> GetUserDataByAccId(string accId);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 用户注册
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注册游戏角色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="areaId"></param>
|
||||||
|
/// <param name="accId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<unit_user> Register(int areaId, string accId);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -22,4 +22,10 @@ public class NoticeService:INoticeService,ITransient
|
|||||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_notice>();
|
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_notice>();
|
||||||
return await db.Queryable<game_notice>().OrderByDescending(it=>it.addTime).ToPageListAsync(page, limit, total);
|
return await db.Queryable<game_notice>().OrderByDescending(it=>it.addTime).ToPageListAsync(page, limit, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<game_notice> GetNoticeInfo(string id)
|
||||||
|
{
|
||||||
|
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_notice>();
|
||||||
|
return await db.Queryable<game_notice>().Where(it => it.noticeId == id).SingleAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
using Photon.Core.Assist;
|
||||||
|
|
||||||
|
namespace Application.Domain;
|
||||||
|
|
||||||
|
public class UnitUserService : IUnitUserService, ITransient
|
||||||
|
{
|
||||||
|
private readonly ISqlSugarClient _dbClient;
|
||||||
|
private readonly IRedisCache _redisClient;
|
||||||
|
|
||||||
|
public UnitUserService(ISqlSugarClient dbClient, IRedisCache redisClient)
|
||||||
|
{
|
||||||
|
_dbClient = dbClient;
|
||||||
|
_redisClient = redisClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 用户信息
|
||||||
|
public async Task<List<unit_user>> GetUserDataByAccId(string accId)
|
||||||
|
{
|
||||||
|
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||||
|
return await db.Queryable<unit_user>().Where(it => it.accId == accId).ToListAsync();
|
||||||
|
}
|
||||||
|
public async Task<unit_user> GetUserInfoByUserNo(string userNo)
|
||||||
|
{
|
||||||
|
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo");
|
||||||
|
var data = await _redisClient.GetHashAsync<unit_user>(key, userNo);
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
|
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||||
|
data = await db.Queryable<unit_user>().Where(it => it.userNo == userNo).SingleAsync();
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
await _redisClient.AddHashAsync(key, userNo, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<unit_user> GetUserInfoBySid(string token)
|
||||||
|
{
|
||||||
|
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid");
|
||||||
|
var data = await _redisClient.GetHashAsync<unit_user>(key, token);
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
|
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||||
|
data = await db.Queryable<unit_user>().Where(it => it.token == token).SingleAsync();
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
await _redisClient.AddHashAsync(key, token, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 用户注册
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<unit_user> Register(int areaId, string accId)
|
||||||
|
{
|
||||||
|
unit_user result = new unit_user();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||||
|
await _dbClient.AsTenant().BeginTranAsync();
|
||||||
|
string userId = StringAssist.NewGuid;
|
||||||
|
result.userId = userId;
|
||||||
|
result.areaId = areaId;
|
||||||
|
result.accId = accId;
|
||||||
|
result.nick = "四海虾米";
|
||||||
|
result.headImg = "";
|
||||||
|
int no = await GetUserNo();
|
||||||
|
result.userNo = no.ToString();
|
||||||
|
string token = await GetToken();
|
||||||
|
result.token = token;
|
||||||
|
result.sign = "这个小家伙儿很懒,什么也没留下.";
|
||||||
|
result.status = 1;
|
||||||
|
result.regOk = 0;
|
||||||
|
result.isSystem = 0;
|
||||||
|
result.addTime = DateTime.Now;
|
||||||
|
result.upTime = DateTime.Now;
|
||||||
|
bool isok = db.Insertable(result).ExecuteCommand() > 0;
|
||||||
|
if (!isok)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _dbClient.AsTenant().CommitTranAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
await _dbClient.AsTenant().RollbackTranAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> GetUserNo()
|
||||||
|
{
|
||||||
|
int No = 0;
|
||||||
|
bool ok = true;
|
||||||
|
while (ok)
|
||||||
|
{
|
||||||
|
No = RandomAssist.GetFormatedNumeric(11012585, 97521695);
|
||||||
|
if (await GetUserInfoByUserNo(No.ToString()) == null)
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return No;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> GetToken()
|
||||||
|
{
|
||||||
|
string sid = string.Empty;
|
||||||
|
bool ok = true;
|
||||||
|
while (ok)
|
||||||
|
{
|
||||||
|
sid = StringAssist.RandomString(32);
|
||||||
|
if (await GetUserInfoBySid(sid) == null)
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
21
Service/Application.Web/Common/DateTimeJsonConverter.cs
Normal file
21
Service/Application.Web/Common/DateTimeJsonConverter.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Application.Web;
|
||||||
|
|
||||||
|
public class DateTimeJsonConverter: JsonConverter<DateTime>
|
||||||
|
{
|
||||||
|
public override DateTime Read(
|
||||||
|
ref Utf8JsonReader reader,
|
||||||
|
Type typeToConvert,
|
||||||
|
JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
return DateTime.ParseExact(reader.GetString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,9 +14,15 @@ namespace Application.Web.Controllers.Login
|
|||||||
public class LoginController : ControllerBase
|
public class LoginController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IGameAccountService _accountService;
|
private readonly IGameAccountService _accountService;
|
||||||
public LoginController(IGameAccountService accountService)
|
private readonly IAreaService _areaService;
|
||||||
|
private readonly IUnitUserService _userService;
|
||||||
|
|
||||||
|
public LoginController(IGameAccountService accountService, IAreaService areaService,
|
||||||
|
IUnitUserService userService)
|
||||||
{
|
{
|
||||||
_accountService = accountService;
|
_accountService = accountService;
|
||||||
|
_areaService = areaService;
|
||||||
|
_userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -27,8 +33,6 @@ namespace Application.Web.Controllers.Login
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IPoAction> Login([FromBody] LoginParms parms)
|
public async Task<IPoAction> Login([FromBody] LoginParms parms)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
return PoAction.Ok(parms.code);
|
return PoAction.Ok(parms.code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,14 +42,15 @@ namespace Application.Web.Controllers.Login
|
|||||||
/// <param name="code"></param>
|
/// <param name="code"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IPoAction> TwLogin( string code)
|
public async Task<IPoAction> TwLogin(string code)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(code))
|
if (string.IsNullOrEmpty(code))
|
||||||
{
|
{
|
||||||
return PoAction.Message("code值错误!");
|
return PoAction.Message("code值错误!");
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoLogin login = new AutoLogin();
|
AutoLogin login = new AutoLogin();
|
||||||
var loginInfo = await login.TwLogin(code);
|
var loginInfo = await login.TwLogin(code);
|
||||||
if (loginInfo.code == 0)
|
if (loginInfo.code == 0)
|
||||||
{
|
{
|
||||||
dynamic twInfo = JsonConvert.DeserializeObject<dynamic>(loginInfo.data.ToString());
|
dynamic twInfo = JsonConvert.DeserializeObject<dynamic>(loginInfo.data.ToString());
|
||||||
@@ -54,14 +59,14 @@ namespace Application.Web.Controllers.Login
|
|||||||
var accInfo = await _accountService.GetAccInfoByOpenId(openId);
|
var accInfo = await _accountService.GetAccInfoByOpenId(openId);
|
||||||
if (accInfo == null)
|
if (accInfo == null)
|
||||||
{
|
{
|
||||||
var userData = await _accountService.Regist("", nick, "", "", openId);
|
var userData = await _accountService.Regist("", nick, "", "", openId);
|
||||||
if (userData == null)
|
if (userData == null)
|
||||||
{
|
{
|
||||||
return PoAction.Message("登录失败,请联系客服!");
|
return PoAction.Message("登录失败,请联系客服!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
object ret =new { token = userData.token };
|
object ret = new { token = userData.token };
|
||||||
return PoAction.Ok(ret);
|
return PoAction.Ok(ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +78,7 @@ namespace Application.Web.Controllers.Login
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
object ret =new { token = accInfo.token };
|
object ret = new { token = accInfo.token };
|
||||||
return PoAction.Ok(ret);
|
return PoAction.Ok(ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,5 +117,60 @@ namespace Application.Web.Controllers.Login
|
|||||||
return PoAction.Message("退出失败,请稍后尝试!");
|
return PoAction.Message("退出失败,请稍后尝试!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注册基础账号信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sid"></param>
|
||||||
|
/// <param name="area"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IPoAction> Register(string sid, int area)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(sid))
|
||||||
|
{
|
||||||
|
return PoAction.Message("未登录账号!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var accInfo = await _accountService.GetAccInfoByToken(sid);
|
||||||
|
if (accInfo == null)
|
||||||
|
{
|
||||||
|
return PoAction.Message("未登录账号!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var areaInfo = await _areaService.GetAreaInfo(area);
|
||||||
|
if (areaInfo == null)
|
||||||
|
{
|
||||||
|
return PoAction.Message("区服不存在!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (areaInfo.status != 1)
|
||||||
|
{
|
||||||
|
return PoAction.Message("当前区繁忙,无法进入!");
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否已经注册
|
||||||
|
var userData = await _userService.GetUserDataByAccId(accInfo.accId);
|
||||||
|
if (userData.Any(it => it.areaId == area))
|
||||||
|
{
|
||||||
|
return PoAction.Message("该区已存在角色!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var userInfo = await _userService.Register(areaInfo.areaId, accInfo.accId);
|
||||||
|
if (userInfo == null)
|
||||||
|
{
|
||||||
|
return PoAction.Message("注册失败,请稍后尝试!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, object> loadData = new Dictionary<string, object>();
|
||||||
|
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, 300);
|
||||||
|
return PoAction.Ok(new { token = token, refToken = userInfo.token, userId = userInfo.userId });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,12 +13,14 @@ namespace Application.Web.Controllers.Pub
|
|||||||
private readonly IAreaService _areaService;
|
private readonly IAreaService _areaService;
|
||||||
private readonly INoticeService _noticeService;
|
private readonly INoticeService _noticeService;
|
||||||
private readonly IGameAccountService _accountService;
|
private readonly IGameAccountService _accountService;
|
||||||
|
private readonly IUnitUserService _userService;
|
||||||
|
|
||||||
public PubController(IAreaService areaService, INoticeService noticeService,IGameAccountService accountService)
|
public PubController(IAreaService areaService, INoticeService noticeService, IGameAccountService accountService,IUnitUserService userService)
|
||||||
{
|
{
|
||||||
_areaService = areaService;
|
_areaService = areaService;
|
||||||
_noticeService = noticeService;
|
_noticeService = noticeService;
|
||||||
_accountService = accountService;
|
_accountService = accountService;
|
||||||
|
_userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -31,20 +33,27 @@ namespace Application.Web.Controllers.Pub
|
|||||||
{
|
{
|
||||||
bool isOnline = false;
|
bool isOnline = false;
|
||||||
game_account account = new game_account();
|
game_account account = new game_account();
|
||||||
|
List<unit_user> userData = new List<unit_user>();
|
||||||
if (!string.IsNullOrEmpty(sid))
|
if (!string.IsNullOrEmpty(sid))
|
||||||
{
|
{
|
||||||
account = await _accountService.GetAccInfoByToken(sid);
|
account = await _accountService.GetAccInfoByToken(sid);
|
||||||
if (account != null)
|
if (account != null)
|
||||||
{
|
{
|
||||||
isOnline = true;
|
isOnline = true;
|
||||||
|
userData = await _userService.GetUserDataByAccId(account.accId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var areaData = await _areaService.GetAreaData();
|
var areaData = await _areaService.GetAreaData();
|
||||||
|
foreach (var _user in userData)
|
||||||
|
{
|
||||||
|
areaData.RemoveAll(it => it.areaId == _user.areaId);
|
||||||
|
}
|
||||||
|
|
||||||
var notice = await _noticeService.GetNoticeDataByTake(5);
|
var notice = await _noticeService.GetNoticeDataByTake(5);
|
||||||
|
|
||||||
int OnCount = 100;
|
int OnCount = 100;
|
||||||
return PoAction.Ok(new { area = areaData, notice, isOnline, onCount = OnCount,account });
|
return PoAction.Ok(new { area = areaData, notice, isOnline, onCount = OnCount, account,userData });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -54,11 +63,28 @@ namespace Application.Web.Controllers.Pub
|
|||||||
/// <param name="limit"></param>
|
/// <param name="limit"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IPoAction> GetNoticeData(int page,int limit)
|
public async Task<IPoAction> GetNoticeData(int page, int limit)
|
||||||
{
|
{
|
||||||
RefAsync<int> total = 0;
|
RefAsync<int> total = 0;
|
||||||
var data = await _noticeService.GetNoticeData(page, limit, total);
|
var data = await _noticeService.GetNoticeData(page, limit, total);
|
||||||
return PoAction.Ok(new { data, total=total.Value });
|
return PoAction.Ok(new { data, total = total.Value });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取公告详情
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IPoAction> GetNoticeInfo(string id)
|
||||||
|
{
|
||||||
|
var data = await _noticeService.GetNoticeInfo(id);
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
|
return PoAction.Message("公告不存在!");
|
||||||
|
}
|
||||||
|
data.sign = data.sign.Replace("[Br]", "<br />");
|
||||||
|
return PoAction.Ok(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,8 +53,13 @@ builder.Services.InjectTimer(services =>
|
|||||||
builder.Logging.InjectLog();
|
builder.Logging.InjectLog();
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
|
builder.Services.AddControllers().AddJsonOptions(option =>
|
||||||
|
{
|
||||||
|
option.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter());
|
||||||
|
option.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
|
||||||
|
option.JsonSerializerOptions.MaxDepth =int.MaxValue;
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
|
||||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||||
|
|
||||||
#region 配置跨域处理,允许所有来源
|
#region 配置跨域处理,允许所有来源
|
||||||
|
|||||||
@@ -16,20 +16,22 @@ export class StateHelper {
|
|||||||
static get userId() {
|
static get userId() {
|
||||||
return this.userStore.userId;
|
return this.userStore.userId;
|
||||||
}
|
}
|
||||||
|
static SetToken(userId: string, token: string, refToken: string) {
|
||||||
|
this.userStore.setToken(userId, token, refToken);
|
||||||
|
}
|
||||||
|
|
||||||
static SetSid(sid: string) {
|
static SetSid(sid: string) {
|
||||||
this.userStore.setSid(sid);
|
this.userStore.setSid(sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static OffOnline()
|
static OffOnline() {
|
||||||
{
|
|
||||||
this.userStore.offOnline();
|
this.userStore.offOnline();
|
||||||
}
|
}
|
||||||
static get IsAccLogin(){
|
static get IsAccLogin() {
|
||||||
return this.userStore.isLoginAccount;
|
return this.userStore.isLoginAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get IsLogin(){
|
static get IsLogin() {
|
||||||
return this.userStore.isLogin;
|
return this.userStore.isLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,11 @@
|
|||||||
export class MessageExtend {
|
export class MessageExtend {
|
||||||
// 消息通知
|
// 消息通知
|
||||||
static Notify(message: any, type?: 'primary' | 'success' | 'danger' | 'warning') {
|
static Notify(message: any, type?: 'primary' | 'success' | 'danger' | 'warning') {
|
||||||
showNotify({ type, message })
|
showNotify({
|
||||||
|
type: type,
|
||||||
|
message: message,
|
||||||
|
duration: 1500,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提示弹窗
|
// 提示弹窗
|
||||||
@@ -12,6 +16,16 @@ export class MessageExtend {
|
|||||||
showDialog({ title: title, message: message })
|
showDialog({ title: title, message: message })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ShowDialogEvent(title: string, message: string, onConfirm?: () => void, confirmButtonText?: string) {
|
||||||
|
showDialog({
|
||||||
|
title: title,
|
||||||
|
message: message,
|
||||||
|
confirmButtonText: confirmButtonText || '确认'
|
||||||
|
}).then(() => {
|
||||||
|
onConfirm?.()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 确认提示弹窗
|
// 确认提示弹窗
|
||||||
static ShowConfirmDialog(title: string, message: string, onConfirm?: () => void, onCancel?: () => void, confirmButtonText?: string) {
|
static ShowConfirmDialog(title: string, message: string, onConfirm?: () => void, onCancel?: () => void, confirmButtonText?: string) {
|
||||||
showConfirmDialog({
|
showConfirmDialog({
|
||||||
|
|||||||
@@ -14,10 +14,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div style="margin-top:5px;">
|
<div style="margin-top:5px;">
|
||||||
<div>
|
<div>
|
||||||
➢<a :href='"http://m.twbar.cn/Regain/ToMain?openid=" + AccountInfo.openId'>返回探玩驿站</a>
|
➢<a :href='"https://3g.fan/Regain/ToMain?openid=" + AccountInfo.openId'>返回探玩驿站</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
➸<a :href='"http://m.twbar.cn/Regain/ToBbs?openid=" + AccountInfo.openId + "&bbs=1146"'>游戏论坛</a>
|
➸<a :href='"https://3g.fan/Regain/ToBbs?openid=" + AccountInfo.openId + "&bbs=1146"'>游戏论坛</a>
|
||||||
➸<a @click.stop="offOnline">退出游戏</a>
|
➸<a @click.stop="offOnline">退出游戏</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -30,8 +30,8 @@
|
|||||||
=====☆<Abar href="/area/my">我的区服</Abar>☆=====
|
=====☆<Abar href="/area/my">我的区服</Abar>☆=====
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="item">
|
<div class="item" v-for="(item, index) in userData" :key="index">
|
||||||
<Abar href="/">✧【1区】新手村✰村长(男)</Abar>
|
<a @click="loginGame(item.userId)">【{{ item.areaId }}区】{{ item.nick }}({{ (item.sex == null||item.sex=='') ? "未知" : item.sex }})</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="item" v-for="(item, index) in areaData" :key="index">
|
<div class="item" v-for="(item, index) in areaData" :key="index">
|
||||||
✧<Abar :href='"/login/register?id=" + item.areaId'>({{ item.areaId }}区){{ item.name }}</Abar>
|
✧<a @click="registerGame(item.areaId)">({{ item.areaId }}区){{ item.name }}</a>
|
||||||
{{ item.status == 1 ? "(推荐)" : "(繁忙)" }}
|
{{ item.status == 1 ? "(推荐)" : "(繁忙)" }}
|
||||||
</div>
|
</div>
|
||||||
<span v-if="areaData.length == 0">暂无区服.</span>
|
<span v-if="areaData.length == 0">暂无区服.</span>
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="title">
|
<div class="title">
|
||||||
=====☆<Abar href="/news/">官方公告</Abar>☆=====
|
=====☆<Abar href="/news/">官方公告</Abar>☆=====
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="item" v-for="(item, index) in noticeData" :key="index">
|
<div class="item" v-for="(item, index) in noticeData" :key="index">
|
||||||
@@ -85,50 +85,7 @@ const noticeData = ref<Array<any>>([]);
|
|||||||
const isOnline = ref(false);
|
const isOnline = ref(false);
|
||||||
const OnCount = ref(0);
|
const OnCount = ref(0);
|
||||||
const AccountInfo = ref<any>();
|
const AccountInfo = ref<any>();
|
||||||
|
const userData = ref<Array<any>>([]);
|
||||||
const Initialize = async (): Promise<void> => {
|
|
||||||
var result = await PubService.GetMain(StateHelper.Sid);
|
|
||||||
if (result.code == 0) {
|
|
||||||
isOnline.value = result.data.isOnline;
|
|
||||||
if (isOnline.value == false) {
|
|
||||||
StateHelper.OffOnline();
|
|
||||||
}
|
|
||||||
areaData.value = result.data?.area;
|
|
||||||
noticeData.value = result.data.notice;
|
|
||||||
OnCount.value = result.data.onCount;
|
|
||||||
AccountInfo.value = result.data.account;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MessageExtend.ShowToast(result.msg, "fail");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//退出登录
|
|
||||||
const offOnline = async () => {
|
|
||||||
MessageExtend.ShowConfirmDialog("退出游戏", "您确定要退出游戏吗?", async () => {
|
|
||||||
var result = await PubService.GetMain(StateHelper.Sid);
|
|
||||||
if (result.code == 0) {
|
|
||||||
StateHelper.OffOnline();
|
|
||||||
isOnline.value = false;
|
|
||||||
MessageExtend.ShowToast("退出成功!", "success");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MessageExtend.ShowToast(result.msg, "fail");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const login = async (code: string): Promise<void> => {
|
|
||||||
var result = await LoginService.TwLogin(code);
|
|
||||||
console.log(result);
|
|
||||||
if (result.code == 0) {
|
|
||||||
StateHelper.SetSid(result.data.token);
|
|
||||||
await Initialize();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MessageExtend.ShowToast(result.msg, "default");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -146,4 +103,72 @@ onMounted(async () => {
|
|||||||
PageLoading.Close();
|
PageLoading.Close();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**初始化数据 */
|
||||||
|
const Initialize = async (): Promise<void> => {
|
||||||
|
let result = await PubService.GetMain(StateHelper.Sid);
|
||||||
|
if (result.code == 0) {
|
||||||
|
isOnline.value = result.data.isOnline;
|
||||||
|
if (isOnline.value == false) {
|
||||||
|
StateHelper.OffOnline();
|
||||||
|
}
|
||||||
|
areaData.value = result.data?.area;
|
||||||
|
noticeData.value = result.data.notice;
|
||||||
|
OnCount.value = result.data.onCount;
|
||||||
|
AccountInfo.value = result.data.account;
|
||||||
|
userData.value = result.data.userData;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageExtend.ShowToast(result.msg, "fail");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**自动登录 */
|
||||||
|
const login = async (code: string): Promise<void> => {
|
||||||
|
let result = await LoginService.TwLogin(code);
|
||||||
|
console.log(result);
|
||||||
|
if (result.code == 0) {
|
||||||
|
StateHelper.SetSid(result.data.token);
|
||||||
|
await Initialize();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageExtend.ShowToast(result.msg, "default");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**退出登录 */
|
||||||
|
const offOnline = async () => {
|
||||||
|
MessageExtend.ShowConfirmDialog("退出游戏", "您确定要退出游戏吗?", async () => {
|
||||||
|
let result = await PubService.GetMain(StateHelper.Sid);
|
||||||
|
if (result.code == 0) {
|
||||||
|
StateHelper.OffOnline();
|
||||||
|
isOnline.value = false;
|
||||||
|
MessageExtend.ShowToast("退出成功!", "success");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageExtend.ShowToast(result.msg, "fail");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**登录到游戏 */
|
||||||
|
const loginGame = async (gameId: string): Promise<void> => {
|
||||||
|
alert(gameId)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**注册游戏 */
|
||||||
|
const registerGame = async (area: number): Promise<void> => {
|
||||||
|
let result = await LoginService.Register(StateHelper.Sid, area);
|
||||||
|
if (result.code == 0) {
|
||||||
|
StateHelper.SetToken(result.data.userId, result.data.token, result.data.refToken);
|
||||||
|
PageExtend.Redirect("/login/register");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageExtend.ShowDialog("注册角色", result.msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**辅助方法 */
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -27,12 +27,10 @@ const data = ref<Array<any>>([]);
|
|||||||
const handlePageChange = async (page: number): Promise<void> => {
|
const handlePageChange = async (page: number): Promise<void> => {
|
||||||
currentPage.value = page;
|
currentPage.value = page;
|
||||||
await BindData();
|
await BindData();
|
||||||
console.log('跳转到第', page, '页');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const BindData = async (): Promise<void> => {
|
const BindData = async (): Promise<void> => {
|
||||||
var result = await PubService.GetNoticeData(currentPage.value, 10);
|
var result = await PubService.GetNoticeData(currentPage.value, 10);
|
||||||
console.log(result);
|
|
||||||
if (result.code == 0) {
|
if (result.code == 0) {
|
||||||
data.value = result.data.data;
|
data.value = result.data.data;
|
||||||
totalPages.value = result.data.total;
|
totalPages.value = result.data.total;
|
||||||
|
|||||||
@@ -1 +1,51 @@
|
|||||||
<template></template>
|
<template>
|
||||||
|
<div class="content">
|
||||||
|
<Abar href="/news/">官方公告</Abar>>详情
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<div class="common">
|
||||||
|
[标题]:<strong>{{ noticeData.title }}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="common">
|
||||||
|
[时间]: {{noticeData.addTime}}
|
||||||
|
</div>
|
||||||
|
<div class="common" v-html="noticeData.sign"></div>
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<Abar href="/news/">返回公告列表</Abar>
|
||||||
|
</div>
|
||||||
|
<Abar href="/">返回游戏首页</Abar>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
|
||||||
|
definePageMeta({
|
||||||
|
layout: layout.empty,
|
||||||
|
middleware: 'page-loading'
|
||||||
|
})
|
||||||
|
let noticeData = ref<any>({});
|
||||||
|
|
||||||
|
const BindData = async (): Promise<void> => {
|
||||||
|
var noticeId = PageExtend.QueryString("id");
|
||||||
|
var result = await PubService.GetNoticeInfo(noticeId);
|
||||||
|
if (result.code == 0) {
|
||||||
|
noticeData.value = result.data;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageExtend.ShowDialogEvent("提示", "公告不存在!", () => {
|
||||||
|
PageExtend.Redirect("/news/");
|
||||||
|
}, "我知道了");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
await BindData();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
PageLoading.Close();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
@@ -8,10 +8,18 @@ export class PubService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetNoticeData
|
* 获取公告列表
|
||||||
* GET /Pub/GetNoticeData
|
* GET /Pub/GetNoticeData
|
||||||
*/
|
*/
|
||||||
static async GetNoticeData(page: number, limit: number) {
|
static async GetNoticeData(page: number, limit: number) {
|
||||||
return await ApiService.Request("get", "/Pub/GetNoticeData", { page, limit });
|
return await ApiService.Request("get", "/Pub/GetNoticeData", { page, limit });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取公告详情
|
||||||
|
* GET /Pub/GetNoticeInfo
|
||||||
|
*/
|
||||||
|
static async GetNoticeInfo(id: string) {
|
||||||
|
return await ApiService.Request("get", "/Pub/GetNoticeInfo", { id });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,4 +26,12 @@ export class LoginService {
|
|||||||
static async LoginOut(sid: string) {
|
static async LoginOut(sid: string) {
|
||||||
return await ApiService.Request("get", "/Login/LoginOut", { sid });
|
return await ApiService.Request("get", "/Login/LoginOut", { sid });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册基础账号信息
|
||||||
|
* GET /Login/Regist
|
||||||
|
*/
|
||||||
|
static async Register(sid: string, area: number) {
|
||||||
|
return await ApiService.Request("get", "/Login/Register", { sid, area });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user