Skip to content

Commit

Permalink
Merge pull request #814 from LittleFish-233/master
Browse files Browse the repository at this point in the history
修复兑换码可以重复添加的问题,修复可以兑换隐藏的兑换码的问题,修复窗口大小变化后没有实时修改看板娘位置的问题,修复直接访问看板娘小卖部报错的问题
  • Loading branch information
LittleFish-233 authored Aug 18, 2024
2 parents d9559de + 9d00437 commit 6e15848
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ public async Task<ActionResult<Result>> EditCodeAsync(CommodityCodeEditModel mod
CommodityCode item = null;
if (model.Id == 0)
{
// 新创建的兑换码 不能和已有的重复
if (await _commodityCodeRepository.AnyAsync(s => s.Code == model.Code))
{
return new Result { Successful = false, Error = "已存在相同的兑换码" };
}

item = await _commodityCodeRepository.InsertAsync(new CommodityCode
{
CreateTime = DateTime.Now.ToCstTime(),
Expand All @@ -255,6 +261,14 @@ public async Task<ActionResult<Result>> EditCodeAsync(CommodityCodeEditModel mod
_commodityCodeRepository.Clear();
}


// 编辑现有的创建的兑换码 不能和已有的重复
if (await _commodityCodeRepository.AnyAsync(s => s.Code == model.Code && s.Id != model.Id))
{
return new Result { Successful = false, Error = "已存在相同的兑换码" };
}


item = await _commodityCodeRepository.GetAll().FirstOrDefaultAsync(s => s.Id == model.Id);


Expand All @@ -264,6 +278,8 @@ public async Task<ActionResult<Result>> EditCodeAsync(CommodityCodeEditModel mod
}




// 如果兑换码已经被兑换 修改为不可兑换需要退还G币
if (item.CanRedeemed != model.CanRedeemed && item.Redeemed && item.ApplicationUserId != null && item.Type == CommodityCodeType.GCoins)
{
Expand Down Expand Up @@ -337,7 +353,7 @@ public async Task<ActionResult<Result>> RedeemedCommodityCode(RedeemedCommodityC
}


var code = await _commodityCodeRepository.GetAll().FirstOrDefaultAsync(s => s.Code == model.Code);
var code = await _commodityCodeRepository.GetAll().FirstOrDefaultAsync(s => s.Code == model.Code && s.Hide == false);
if (code == null)
{
return new Result { Successful = false, Error = "没有查找到这个订单,数据更新会有延迟,可以稍后再来查询(也可以在B站私信询问)" };
Expand Down
4 changes: 2 additions & 2 deletions CnGalWebSite/CnGalWebSite.BlazorWeb/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
</div>

<!--自定义脚本-->
@* <script src="_content/CnGalWebSite.Shared/js/bundle.js"></script> *@
<script src="https://app.cngal.org/_content/CnGalWebSite.Shared/js/bundle.min.js"></script>
<script src="_content/CnGalWebSite.Shared/js/bundle.js"></script>
@* <script src="https://app.cngal.org/_content/CnGalWebSite.Shared/js/bundle.min.js"></script> *@

<!--图片裁剪-->
<script src="https://res.cngal.org/_content/Chronos.Blazor.Cropper/CropHelper.js"></script>
Expand Down
10 changes: 10 additions & 0 deletions CnGalWebSite/CnGalWebSite.Kanban/Services/Core/Live2DService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ public void ReleaseLive2D()
_ = _jSRuntime.InvokeVoidAsync("window.releaseLive2d");
}

/// <summary>
/// 检查看板娘位置是否正确
/// </summary>
/// <returns></returns>
[JSInvokable]
public async Task CheckKanbanPositionAsync()
{
await _settingService.SaveAsync();
}

public void Dispose()
{
objRef?.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,25 @@ public async Task ResetAsync()
private async Task CheckKanbanPositionAsync()
{
var size = await _jsRuntime.InvokeAsync<Size>("getWindowSize");
var percent = 0.8;
var percent_x = 0.5;
var percent_y = 0.8;

if (_settingModel.Kanban.Position.Left + _settingModel.Kanban.Size.Width * percent < 0)
if (_settingModel.Kanban.Position.Left + _settingModel.Kanban.Size.Width * percent_x < 0)
{
_settingModel.Kanban.Position.Left = 0;
}

if (_settingModel.Kanban.Position.Left + _settingModel.Kanban.Size.Width * (1 - percent) > size.Width)
if (_settingModel.Kanban.Position.Left + _settingModel.Kanban.Size.Width * (1 - percent_x) > size.Width)
{
_settingModel.Kanban.Position.Left = (int)(size.Width - _settingModel.Kanban.Size.Width);
}

if (_settingModel.Kanban.Position.Top + _settingModel.Kanban.Size.Height * percent < 0)
if (_settingModel.Kanban.Position.Top + _settingModel.Kanban.Size.Height * percent_y < 0)
{
_settingModel.Kanban.Position.Top = 0;
}

if (_settingModel.Kanban.Position.Top + _settingModel.Kanban.Size.Height * (1 - percent) > size.Height)
if (_settingModel.Kanban.Position.Top + _settingModel.Kanban.Size.Height * (1 - percent_y) > size.Height)
{
_settingModel.Kanban.Position.Top = (int)(size.Height - _settingModel.Kanban.Size.Height);
}
Expand Down
29 changes: 28 additions & 1 deletion CnGalWebSite/CnGalWebSite.Kanban/wwwroot/js/live2d-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function initKanbanLive2D(dotNetHelper, modelDir, modelIndex, resourcesPath) {
// 加载js
loadScript('https://app.cngal.org/live2d/js/live2dcubismcore.min.js', function () {
loadScript('https://app.cngal.org/live2d/js/bundle.js', function () {
//loadScript('http://localhost:5000/Samples/TypeScript/Demo/dist/bundle.js', function () {
//loadScript('http://localhost:5000/Samples/TypeScript/Demo/dist/bundle.js', function () {
// 再初始化l2d
var modelDirs = modelDir.split(',');
live2d_dotNetHelper = dotNetHelper;
Expand Down Expand Up @@ -61,6 +61,33 @@ function getWindowSize() {
}
}

// 监听窗口变化
const getWindowInfo = () => {
const windowInfo = {
width: window.innerWidth,
hight: window.innerHeight
}
console.log(windowInfo);
live2d_dotNetHelper.invokeMethodAsync("CheckKanbanPositionAsync")
};

const debounce = (fn, delay) => {
let timer;
return function () {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn();
}, delay);
}
};
const cancalDebounce = debounce(getWindowInfo, 100);

window.addEventListener('resize', cancalDebounce);



//获取此刻时间
function getTimeNow() {
var now = new Date();
Expand Down
117 changes: 73 additions & 44 deletions CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Commodities/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,73 @@
<CnGalWebSite.Shared.MasaComponent.Shared.Cards.TitleTip Title="看板娘的小卖铺" />

<CnGalWebSite.Components.Containers.MiniModeContainer>
<MRow>
<MCol Cols="12" Md="5" Lg="4" Xl="3" Class="mb-4">
<CnGalWebSite.Shared.MasaComponent.PC.Commodities.KanbanCard />
</MCol>
<MCol Cols="12" Md="7" Lg="8" Xl="9" Class="mb-4">
<MDCard Class="mb-4">
<MTabs Value="index" ValueChanged="IndexChanged" IconsAndText Grow CenterActive>
<MTab Value="1">
小卖铺<MIcon>@IconType.Store.ToIconString()</MIcon>
</MTab>
<MTab Value="2">
G币兑换<MIcon>@IconType.Lottery.ToIconString()</MIcon>
</MTab>
</MTabs>
</MDCard>

<MTabsItems @bind-Value="index">
<MTabItem Value="1">
@if (isReady)
{
<MRow>
@foreach (var item in Model)
@if (isReadyA)
{
@if (ForceHide)
{
<NotAuthorizedTipView NoPermissions="true" />
}
else
{
<MRow>
<MCol Cols="12" Md="5" Lg="4" Xl="3" Class="mb-4">
<CnGalWebSite.Shared.MasaComponent.PC.Commodities.KanbanCard />
</MCol>
<MCol Cols="12" Md="7" Lg="8" Xl="9" Class="mb-4">
<MDCard Class="mb-4">
<MTabs Value="index" ValueChanged="IndexChanged" IconsAndText Grow CenterActive>
<MTab Value="1">
小卖铺<MIcon>@IconType.Store.ToIconString()</MIcon>
</MTab>
<MTab Value="2">
G币兑换<MIcon>@IconType.Lottery.ToIconString()</MIcon>
</MTab>
</MTabs>
</MDCard>

<MTabsItems @bind-Value="index">
<MTabItem Value="1">
@if (isReadyB)
{
<MCol Cols="6" Md="6" Lg="4" Xl="3" Class="mb-4">
<CnGalWebSite.Shared.MasaComponent.PC.Commodities.ItemCard Model="item" />
</MCol>
<MRow>
@foreach (var item in Model)
{
<MCol Cols="6" Md="6" Lg="4" Xl="3" Class="mb-4">
<CnGalWebSite.Shared.MasaComponent.PC.Commodities.ItemCard Model="item" />
</MCol>
}
</MRow>
}
</MRow>
}
else
{
<CnGalWebSite.Components.Progressings.ProgressingCard Page Fill />
}
</MTabItem>
<MTabItem Value="2">
<CnGalWebSite.Shared.MasaComponent.PC.Commodities.Codes.MainCard />
</MTabItem>

</MTabsItems>
</MCol>
</MRow>
</CnGalWebSite.Components.Containers.MiniModeContainer>
else
{
<CnGalWebSite.Components.Progressings.ProgressingCard Page Fill />
}
</MTabItem>
<MTabItem Value="2">
<CnGalWebSite.Shared.MasaComponent.PC.Commodities.Codes.MainCard />
</MTabItem>

</MTabsItems>
</MCol>
</MRow>
}
}
else
{
<CnGalWebSite.Components.Progressings.ProgressingCard Page Fill />

}

</CnGalWebSite.Components.Containers.MiniModeContainer>

@code {

[Parameter]
public string Type { get; set; }


bool isReady;
bool ForceHide = true;
bool isReadyA;
bool isReadyB;
StringNumber index = 0;

public List<CommodityUserModel> Model { get; set; }
Expand All @@ -73,15 +89,28 @@
LocationChanged(null, null);
try
{
Model = await _pageModelCatche.GetCache("api/commodities/GetAllCommodities");
isReady = true;
//获取词条信息
var mode = await _httpService.GetAsync<KanbanPermissionsModel>("api/space/GetKanbanPermissions/");
ForceHide = !mode.Permissions;
isReadyA = true;
StateHasChanged();

if (ForceHide == false)
{
Model = await _pageModelCatche.GetCache("api/commodities/GetAllCommodities");
isReadyB = true;
StateHasChanged();
}
}
catch (Exception ex)
{
ForceHide = true;
isReadyA = true;
await ErrorHandler.ProcessError(ex, "获取看板娘的小卖铺商品列表失败");
}
}


protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


/*分享库存*/
.anniversary-page .user-steam-card {
gap: .5rem;
Expand Down
7 changes: 0 additions & 7 deletions CnGalWebSite/CnGalWebSite.Shared/wwwroot/css/bundle.css
Original file line number Diff line number Diff line change
Expand Up @@ -1283,13 +1283,6 @@ html {
:focus-visible {
outline: none;
}
/*outline输入框*/
.theme--light.m-text-field--outlined:not(.m-input--is-focused):not(.m-input--has-state):not(.m-input--is-disabled) > .m-input__control > .m-input__slot:hover fieldset {
color: var(--md-sys-color-primary);
}
.theme--light.m-input:hover, .theme--light.m-input input:hover, .theme--light.m-input textarea:hover {
color: var(--md-sys-color-primary) !important
}

/*卡片*/
.md-card {
Expand Down

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion CnGalWebSite/CnGalWebSite.Shared/wwwroot/js/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ function initKanbanLive2D(dotNetHelper, modelDir, modelIndex, resourcesPath) {
// 加载js
loadScript('https://app.cngal.org/live2d/js/live2dcubismcore.min.js', function () {
loadScript('https://app.cngal.org/live2d/js/bundle.js', function () {
//loadScript('http://localhost:5000/Samples/TypeScript/Demo/dist/bundle.js', function () {
//loadScript('http://localhost:5000/Samples/TypeScript/Demo/dist/bundle.js', function () {
// 再初始化l2d
var modelDirs = modelDir.split(',');
live2d_dotNetHelper = dotNetHelper;
Expand Down Expand Up @@ -1064,6 +1064,33 @@ function getWindowSize() {
}
}

// 监听窗口变化
const getWindowInfo = () => {
const windowInfo = {
width: window.innerWidth,
hight: window.innerHeight
}
console.log(windowInfo);
live2d_dotNetHelper.invokeMethodAsync("CheckKanbanPositionAsync")
};

const debounce = (fn, delay) => {
let timer;
return function () {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn();
}, delay);
}
};
const cancalDebounce = debounce(getWindowInfo, 100);

window.addEventListener('resize', cancalDebounce);



//获取此刻时间
function getTimeNow() {
var now = new Date();
Expand Down
2 changes: 1 addition & 1 deletion CnGalWebSite/CnGalWebSite.Shared/wwwroot/js/bundle.min.js

Large diffs are not rendered by default.

0 comments on commit 6e15848

Please sign in to comment.