mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-01 19:50:31 +08:00
Merge branch 'dev' into dev-Freesql
This commit is contained in:
commit
46c1b881cf
@ -95,17 +95,16 @@ namespace BootstrapBlazor.DataAcces.EntityFrameworkCore
|
||||
public override Task<QueryData<TModel>> QueryAsync(QueryPageOptions option)
|
||||
{
|
||||
// 处理过滤与高级搜索
|
||||
var query = _db.Set<TModel>().Where(option.Filters.Concat(option.Searchs).GetFilterLambda<TModel>());
|
||||
var query = _db.Set<TModel>()
|
||||
.Count(out var count)
|
||||
.Where(option.Filters.Concat(option.Searchs).GetFilterLambda<TModel>(), option.Searchs.Any())
|
||||
.Sort(option.SortName!, option.SortOrder, !string.IsNullOrEmpty(option.SortName))
|
||||
.Page((option.PageIndex - 1) * option.PageItems, option.PageItems);
|
||||
|
||||
// 处理排序
|
||||
if (!string.IsNullOrEmpty(option.SortName)) query = query.Sort(option.SortName, option.SortOrder);
|
||||
|
||||
// 处理分页
|
||||
var items = query.Skip((option.PageIndex - 1) * option.PageItems).Take(option.PageItems);
|
||||
var ret = new QueryData<TModel>()
|
||||
{
|
||||
TotalCount = query.Count(),
|
||||
Items = items,
|
||||
TotalCount = count,
|
||||
Items = query,
|
||||
IsSorted = true,
|
||||
IsFiltered = true,
|
||||
IsSearch = true
|
||||
|
@ -0,0 +1,61 @@
|
||||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
using BootstrapBlazor.Components;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace BootstrapBlazor.DataAcces.EntityFrameworkCore
|
||||
{
|
||||
/// <summary>
|
||||
/// IQueryable 扩展方法
|
||||
/// </summary>
|
||||
public static class IQueryableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="queryable"></param>
|
||||
/// <param name="condition"></param>
|
||||
/// <param name="predicate"></param>
|
||||
/// <returns></returns>
|
||||
public static IQueryable<T> Where<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, bool condition = true) => condition ? queryable.Where(predicate) : queryable;
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="queryable"></param>
|
||||
/// <param name="sortName"></param>
|
||||
/// <param name="sortOrder"></param>
|
||||
/// <param name="condition"></param>
|
||||
/// <returns></returns>
|
||||
public static IQueryable<T> Sort<T>(this IQueryable<T> queryable, string sortName, SortOrder sortOrder, bool condition = true) => condition ? queryable.Sort(sortName, sortOrder) : queryable;
|
||||
|
||||
/// <summary>
|
||||
/// 分页
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="queryable"></param>
|
||||
/// <param name="skipCount"></param>
|
||||
/// <param name="maxResultCount"></param>
|
||||
/// <returns></returns>
|
||||
public static IQueryable<T> Page<T>(this IQueryable<T> queryable, int skipCount, int maxResultCount) => queryable.Skip(skipCount).Take(maxResultCount);
|
||||
|
||||
/// <summary>
|
||||
/// 总数
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="queryable"></param>
|
||||
/// <param name="totalCount"></param>
|
||||
/// <returns></returns>
|
||||
public static IQueryable<T> Count<T>(this IQueryable<T> queryable, out int totalCount)
|
||||
{
|
||||
totalCount = queryable.Count();
|
||||
return queryable;
|
||||
}
|
||||
}
|
||||
}
|
@ -42,7 +42,10 @@ namespace BootstrapBlazor.WebAssembly.ClientHost
|
||||
builder.Services.AddExampleService();
|
||||
|
||||
// 增加 BootstrapBlazor 组件
|
||||
builder.Services.AddBootstrapBlazor();
|
||||
builder.Services.AddBootstrapBlazor(setupAction: option =>
|
||||
{
|
||||
option.ResourceManagerStringLocalizerType = typeof(Program);
|
||||
});
|
||||
|
||||
// 增加 Table Excel 导出服务
|
||||
builder.Services.AddBootstrapBlazorTableExcelExport();
|
||||
@ -61,45 +64,37 @@ namespace BootstrapBlazor.WebAssembly.ClientHost
|
||||
builder.Services.Configure<BootstrapBlazorOptions>(op =>
|
||||
{
|
||||
op.ToastDelay = 4000;
|
||||
op.FallbackCultureName = "zh";
|
||||
op.SupportedCultures.AddRange(new string[] { "zh-CN", "en-US" });
|
||||
});
|
||||
|
||||
builder.Services.AddLocalization();
|
||||
|
||||
var host = builder.Build();
|
||||
|
||||
await GetCultureAsync(host);
|
||||
await SetCultureAsync(host);
|
||||
|
||||
await host.RunAsync();
|
||||
}
|
||||
|
||||
// based on https://github.com/pranavkm/LocSample
|
||||
private static async Task GetCultureAsync(WebAssemblyHost host)
|
||||
private static async Task SetCultureAsync(WebAssemblyHost host)
|
||||
{
|
||||
// 如果 localStorage 未设置语言使用浏览器请求语言
|
||||
var jsRuntime = host.Services.GetRequiredService<IJSRuntime>();
|
||||
var cultureName = await jsRuntime.InvokeAsync<string>("$.blazorCulture.get") ?? "zh";
|
||||
var culture = new CultureInfo(cultureName);
|
||||
CultureInfo.CurrentCulture = culture;
|
||||
CultureInfo.CurrentUICulture = culture;
|
||||
var cultureName = await jsRuntime.InvokeAsync<string>("$.blazorCulture.get");
|
||||
|
||||
if (!string.IsNullOrEmpty(cultureName))
|
||||
{
|
||||
var culture = new CultureInfo(cultureName);
|
||||
|
||||
// 注意 wasm 模式此处必须使用 DefaultThreadCurrentCulture 不可以使用 CurrentCulture
|
||||
CultureInfo.DefaultThreadCurrentCulture = culture;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
||||
}
|
||||
}
|
||||
|
||||
internal class DefaultCultureStorage : ICultureStorage
|
||||
{
|
||||
public CultureStorageMode Mode { get; set; } = CultureStorageMode.LocalStorage;
|
||||
}
|
||||
|
||||
internal class CorsMessageHandler : HttpClientHandler
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
request.SetBrowserRequestMode(BrowserRequestMode.Cors);
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user