改造null

This commit is contained in:
陈淳
2022-10-17 18:08:16 +08:00
parent 16d25fb60d
commit 9d365dbf1e
20 changed files with 117 additions and 42 deletions

View File

@@ -11,8 +11,8 @@ namespace Yi.Framework.WebCore
/// </summary> /// </summary>
public class Appsettings public class Appsettings
{ {
static IConfiguration Configuration { get; set; } static IConfiguration? Configuration { get; set; }
static string contentPath { get; set; } static string? contentPath { get; set; }
public Appsettings(string contentPath) public Appsettings(string contentPath)
{ {
@@ -37,14 +37,14 @@ namespace Yi.Framework.WebCore
/// </summary> /// </summary>
/// <param name="sections">节点配置</param> /// <param name="sections">节点配置</param>
/// <returns></returns> /// <returns></returns>
public static string app(params string[] sections) public static string? app(params string[] sections)
{ {
try try
{ {
if (sections.Any()) if (sections.Any())
{ {
return Configuration[string.Join(":", sections)]; return Configuration?[string.Join(":", sections)];
} }
} }
catch (Exception) { } catch (Exception) { }
@@ -59,7 +59,7 @@ namespace Yi.Framework.WebCore
} }
public static bool Bool(object thisValue) public static bool Bool(object? thisValue)
{ {
bool reval = false; bool reval = false;
if (thisValue != null && thisValue != DBNull.Value && bool.TryParse(thisValue.ToString(), out reval)) if (thisValue != null && thisValue != DBNull.Value && bool.TryParse(thisValue.ToString(), out reval))

View File

@@ -35,9 +35,8 @@ namespace Yi.Framework.WebCore.AttributeExtend
if (context.ActionDescriptor is not ControllerActionDescriptor controllerActionDescriptor) return; if (context.ActionDescriptor is not ControllerActionDescriptor controllerActionDescriptor) return;
//查找标签,获取标签对象 //查找标签,获取标签对象
LogAttribute logAttribute = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true) LogAttribute? logAttribute = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true)
.FirstOrDefault(a => a.GetType().Equals(typeof(LogAttribute))) as LogAttribute; .FirstOrDefault(a => a.GetType().Equals(typeof(LogAttribute))) as LogAttribute;
//空对象直接返回 //空对象直接返回
if (logAttribute is null) return; if (logAttribute is null) return;
@@ -72,7 +71,7 @@ namespace Yi.Framework.WebCore.AttributeExtend
{ {
if (context.Result is ContentResult result && result.ContentType == "application/json") if (context.Result is ContentResult result && result.ContentType == "application/json")
{ {
logEntity.RequestResult = result.Content.Replace("\r\n", "").Trim(); logEntity.RequestResult = result.Content?.Replace("\r\n", "").Trim();
} }
if (context.Result is JsonResult result2) if (context.Result is JsonResult result2)
{ {

View File

@@ -50,8 +50,8 @@ namespace Yi.Framework.WebCore.BuilderExtend
{ {
foreach (var apolloProvider in root.Providers.Where(p => p is ApolloConfigurationProvider)) foreach (var apolloProvider in root.Providers.Where(p => p is ApolloConfigurationProvider))
{ {
var property = apolloProvider.GetType().BaseType.GetProperty("Data", BindingFlags.Instance | BindingFlags.NonPublic); var property = apolloProvider.GetType().BaseType?.GetProperty("Data", BindingFlags.Instance | BindingFlags.NonPublic);
var data = property.GetValue(apolloProvider) as IDictionary<string, string>; var data = property?.GetValue(apolloProvider) as IDictionary<string, string>;
foreach (var item in data) foreach (var item in data)
{ {
Console.WriteLine($"key {item.Key} value {item.Value}"); Console.WriteLine($"key {item.Key} value {item.Value}");

View File

@@ -50,7 +50,7 @@ namespace Yi.Framework.WebCore
/// </summary> /// </summary>
/// <param name="httpContext"></param> /// <param name="httpContext"></param>
/// <returns></returns> /// <returns></returns>
public static string GetUserNameInfo(this HttpContext httpContext) public static string? GetUserNameInfo(this HttpContext httpContext)
{ {
var p = httpContext; var p = httpContext;
return httpContext.User.Claims.FirstOrDefault(u => u.Type == "userName")?.Value; return httpContext.User.Claims.FirstOrDefault(u => u.Type == "userName")?.Value;
@@ -61,10 +61,10 @@ namespace Yi.Framework.WebCore
/// </summary> /// </summary>
/// <param name="httpContext"></param> /// <param name="httpContext"></param>
/// <returns></returns> /// <returns></returns>
public static string GetDeptIdInfo(this HttpContext httpContext) public static string? GetDeptIdInfo(this HttpContext httpContext)
{ {
var p = httpContext; var p = httpContext;
return httpContext.User.Claims.FirstOrDefault(u => u.Type == "deptId").Value; return httpContext.User.Claims.FirstOrDefault(u => u.Type == "deptId")?.Value;
} }
/// <summary> /// <summary>
@@ -72,10 +72,10 @@ namespace Yi.Framework.WebCore
/// </summary> /// </summary>
/// <param name="httpContext"></param> /// <param name="httpContext"></param>
/// <returns></returns> /// <returns></returns>
public static string GetPermissionInfo(this HttpContext httpContext) public static string? GetPermissionInfo(this HttpContext httpContext)
{ {
var p = httpContext; var p = httpContext;
return httpContext.User.Claims.FirstOrDefault(u => u.Type == "permission").Value; return httpContext.User.Claims.FirstOrDefault(u => u.Type == "permission")?.Value;
} }
@@ -87,7 +87,7 @@ namespace Yi.Framework.WebCore
/// <returns></returns> /// <returns></returns>
public static UserEntity GetUserEntityInfo(this HttpContext httpContext, out List<Guid> menuIds) public static UserEntity GetUserEntityInfo(this HttpContext httpContext, out List<Guid> menuIds)
{ {
IEnumerable<Claim> claimlist = null; IEnumerable<Claim>? claimlist = null;
long resId = 0; long resId = 0;
try try
{ {
@@ -139,7 +139,7 @@ namespace Yi.Framework.WebCore
{ {
string res = "zh-CN"; string res = "zh-CN";
var str = httpContext.Request.Headers["Accept-Language"].FirstOrDefault(); var str = httpContext.Request.Headers["Accept-Language"].FirstOrDefault();
if (str.IsNotNull()) if (str is not null)
{ {
res = str.Split(",")[0]; res = str.Split(",")[0];
} }
@@ -167,7 +167,7 @@ namespace Yi.Framework.WebCore
} }
else else
{ {
param = context.Request.QueryString.Value.ToString(); param = context.Request.QueryString.Value is null?"": context.Request.QueryString.Value.ToString();
} }
return param; return param;
} }

View File

@@ -44,12 +44,13 @@ namespace Yi.Framework.Core
roles = new(); roles = new();
} }
//先测试部门就是LEBG //先测试部门就是LEBG
long deptId = (long)userRoleMenu.User.DeptId; long deptId = userRoleMenu.User.DeptId??-1;
long userId = httpContext.GetUserIdInfo(); long userId = httpContext.GetUserIdInfo();
//根据角色的数据范围,来添加相对于的数据权限 //根据角色的数据范围,来添加相对于的数据权限
foreach (var role in roles) foreach (var role in roles)
{ {
DataScopeEnum dataScope = (DataScopeEnum)role.DataScope; //默认为全部
DataScopeEnum dataScope = (DataScopeEnum)(role.DataScope?? DataScopeEnum.ALL.GetHashCode());
switch (dataScope) switch (dataScope)
{ {
case DataScopeEnum.ALL: case DataScopeEnum.ALL:
@@ -71,8 +72,9 @@ namespace Yi.Framework.Core
case DataScopeEnum.DEPT_FOLLOW: case DataScopeEnum.DEPT_FOLLOW:
//放行自己部门及以下 //放行自己部门及以下
var allChildDepts = db.Queryable<DeptEntity>().ToChildList(it => it.ParentId, deptId); var allChildDepts = db.Queryable<DeptEntity>().ToChildList(it => it.ParentId, deptId);
var filter1 = new TableFilterItem<UserEntity>(it => allChildDepts.Select(f => f.Id).ToList().Contains(it.DeptId??-1), true);
var filter1 = new TableFilterItem<UserEntity>(it => allChildDepts.Select(f => f.Id).ToList().Contains((long)it.DeptId), true);
db.QueryFilter.Add(filter1); db.QueryFilter.Add(filter1);
//部门无需过滤 //部门无需过滤

View File

@@ -15,7 +15,7 @@ namespace Yi.Framework.WebCore.FilterExtend
/// </summary> /// </summary>
public class CustomExceptionFilterAttribute : IExceptionFilter public class CustomExceptionFilterAttribute : IExceptionFilter
{ {
private ILogger<CustomExceptionFilterAttribute> _logger = null; private ILogger<CustomExceptionFilterAttribute> _logger;
public CustomExceptionFilterAttribute(ILogger<CustomExceptionFilterAttribute> logger) public CustomExceptionFilterAttribute(ILogger<CustomExceptionFilterAttribute> logger)
{ {
this._logger = logger; this._logger = logger;

View File

@@ -11,7 +11,7 @@ namespace Yi.Framework.WebCore.FilterExtend
/// </summary> /// </summary>
public class CustomIOCFilterFactoryAttribute : Attribute, IFilterFactory public class CustomIOCFilterFactoryAttribute : Attribute, IFilterFactory
{ {
private readonly Type _FilterType = null; private readonly Type _FilterType;
public CustomIOCFilterFactoryAttribute(Type type) public CustomIOCFilterFactoryAttribute(Type type)
{ {
@@ -23,7 +23,7 @@ namespace Yi.Framework.WebCore.FilterExtend
{ {
//return (IFilterMetadata)serviceProvider.GetService(typeof(CustomExceptionFilterAttribute)); //return (IFilterMetadata)serviceProvider.GetService(typeof(CustomExceptionFilterAttribute));
return (IFilterMetadata)serviceProvider.GetService(this._FilterType); return (IFilterMetadata)serviceProvider.GetService(this._FilterType)!;
} }
} }

View File

@@ -11,7 +11,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{ {
public static class SqlsugarExtension public static class SqlsugarExtension
{ {
public static void AddSqlsugarServer(this IServiceCollection services, Action<SqlSugarClient> action = null) public static void AddSqlsugarServer(this IServiceCollection services, Action<SqlSugarClient>? action = null)
{ {
DbType dbType; DbType dbType;
var slavaConFig = new List<SlaveConnectionConfig>(); var slavaConFig = new List<SlaveConnectionConfig>();
@@ -60,7 +60,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
}, },
db => db =>
{ {
if (action.IsNotNull()) if (action is not null)
{ {
action(db); action(db);
} }

View File

@@ -31,7 +31,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{ {
if (this._supportDelete && "Delete".Equals(context.Request.Query["ActionHeader"])) if (this._supportDelete && "Delete".Equals(context.Request.Query["ActionHeader"]))
{ {
this.DeleteHmtl(context.Request.Path.Value); this.DeleteHmtl(context.Request.Path.Value??"");
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
} }
else if (this._supportWarmup && "ClearAll".Equals(context.Request.Query["ActionHeader"])) else if (this._supportWarmup && "ClearAll".Equals(context.Request.Query["ActionHeader"]))
@@ -52,7 +52,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
copyStream.Position = 0; copyStream.Position = 0;
var reader = new StreamReader(copyStream); var reader = new StreamReader(copyStream);
var content = await reader.ReadToEndAsync(); var content = await reader.ReadToEndAsync();
string url = context.Request.Path.Value; string url = context.Request.Path.Value??"";
this.SaveHmtl(url, content); this.SaveHmtl(url, content);

View File

@@ -16,7 +16,7 @@ namespace Yi.Framework.WebCore.SignalRHub
public static readonly List<OnlineUser> clientUsers = new(); public static readonly List<OnlineUser> clientUsers = new();
private HttpContext _httpContext; private HttpContext? _httpContext;
private ILogger<MainHub> _logger; private ILogger<MainHub> _logger;
public MainHub(IHttpContextAccessor httpContextAccessor,ILogger<MainHub> logger) public MainHub(IHttpContextAccessor httpContextAccessor,ILogger<MainHub> logger)
{ {
@@ -32,11 +32,11 @@ namespace Yi.Framework.WebCore.SignalRHub
/// <returns></returns> /// <returns></returns>
public override Task OnConnectedAsync() public override Task OnConnectedAsync()
{ {
var name = _httpContext.GetUserNameInfo(); var name = _httpContext?.GetUserNameInfo();
var loginUser = _httpContext.GetLoginLogInfo(); var loginUser = _httpContext?.GetLoginLogInfo();
var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId); var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId);
//判断用户是否存在,否则添加集合 //判断用户是否存在,否则添加集合
if (!user && Context.User.Identity.IsAuthenticated) if (!user && (Context.User?.Identity?.IsAuthenticated??false))
{ {
OnlineUser users = new(Context.ConnectionId) OnlineUser users = new(Context.ConnectionId)
{ {
@@ -45,7 +45,7 @@ namespace Yi.Framework.WebCore.SignalRHub
Ipaddr= loginUser.LoginIp, Ipaddr= loginUser.LoginIp,
LoginTime=DateTime.Now, LoginTime=DateTime.Now,
Os=loginUser.Os, Os=loginUser.Os,
UserName= name UserName= name??""
}; };
clientUsers.Add(users); clientUsers.Add(users);
_logger.LogInformation($"{DateTime.Now}{name},{Context.ConnectionId}连接服务端success当前已连接{clientUsers.Count}个"); _logger.LogInformation($"{DateTime.Now}{name},{Context.ConnectionId}连接服务端success当前已连接{clientUsers.Count}个");
@@ -63,7 +63,7 @@ namespace Yi.Framework.WebCore.SignalRHub
/// </summary> /// </summary>
/// <param name="exception"></param> /// <param name="exception"></param>
/// <returns></returns> /// <returns></returns>
public override Task OnDisconnectedAsync(Exception exception) public override Task OnDisconnectedAsync(Exception? exception)
{ {
var user = clientUsers.Where(p => p.ConnnectionId == Context.ConnectionId).FirstOrDefault(); var user = clientUsers.Where(p => p.ConnnectionId == Context.ConnectionId).FirstOrDefault();
//判断用户是否存在,否则添加集合 //判断用户是否存在,否则添加集合

View File

@@ -19,18 +19,18 @@ namespace Yi.Framework.WebCore.SignalRHub
/// <summary> /// <summary>
/// 客户端连接Id /// 客户端连接Id
/// </summary> /// </summary>
public string ConnnectionId { get; } public string? ConnnectionId { get; }
/// <summary> /// <summary>
/// 用户id /// 用户id
/// </summary> /// </summary>
public long? UserId { get; set; } public long? UserId { get; set; }
public string UserName { get; set; } public string? UserName { get; set; }
public DateTime LoginTime { get; set; } public DateTime? LoginTime { get; set; }
public string Ipaddr { get; set; } public string? Ipaddr { get; set; }
public string LoginLocation { get; set; } public string? LoginLocation { get; set; }
public string Os { get; set; } public string? Os { get; set; }
public string Browser { get; set; } public string? Browser { get; set; }
} }

View File

@@ -2,6 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -31,6 +31,8 @@ declare module '@vue/runtime-core' {
VanPullRefresh: typeof import('vant/es')['PullRefresh'] VanPullRefresh: typeof import('vant/es')['PullRefresh']
VanRow: typeof import('vant/es')['Row'] VanRow: typeof import('vant/es')['Row']
VanSticky: typeof import('vant/es')['Sticky'] VanSticky: typeof import('vant/es')['Sticky']
VanSwipe: typeof import('vant/es')['Swipe']
VanSwipeItem: typeof import('vant/es')['SwipeItem']
VanTab: typeof import('vant/es')['Tab'] VanTab: typeof import('vant/es')['Tab']
VanTabbar: typeof import('vant/es')['Tabbar'] VanTabbar: typeof import('vant/es')['Tabbar']
VanTabbarItem: typeof import('vant/es')['TabbarItem'] VanTabbarItem: typeof import('vant/es')['TabbarItem']

View File

@@ -35,6 +35,7 @@ let tabbar=ref([
{icon:"wap-home",to:"/",title:"主页"}, {icon:"wap-home",to:"/",title:"主页"},
{icon:"location-o",to:"",title:"发现"}, {icon:"location-o",to:"",title:"发现"},
{icon:"",to:"",title:""}, {icon:"",to:"",title:""},
// {icon:"friends-o",to:"/shopIndex",title:"商城"},
{icon:"friends-o",to:"",title:"商城"}, {icon:"friends-o",to:"",title:"商城"},
{icon:"setting-o",to:"/my",title:"我的"}, {icon:"setting-o",to:"/my",title:"我的"},
]) ])
@@ -43,6 +44,7 @@ const onChange=(index:number)=>{
{icon:"wap-home-o",to:"/",title:"主页"}, {icon:"wap-home-o",to:"/",title:"主页"},
{icon:"location-o",to:"",title:"发现"}, {icon:"location-o",to:"",title:"发现"},
{icon:"",to:"",title:""}, {icon:"",to:"",title:""},
// {icon:"friends-o",to:"/shopIndex",title:"商城"},
{icon:"friends-o",to:"",title:"商城"}, {icon:"friends-o",to:"",title:"商城"},
{icon:"setting-o",to:"/my",title:"我的"}, {icon:"setting-o",to:"/my",title:"我的"},
]; ];

View File

@@ -0,0 +1,9 @@
<template>
<van-nav-bar
title="标题"
left-text="返回"
left-arrow
/>
<br>
<router-view />
</template>

View File

@@ -1,14 +1,20 @@
import { createWebHistory, createRouter } from 'vue-router'; import { createWebHistory, createRouter } from 'vue-router';
import Layout from '@/layout/index.vue'; import Layout from '@/layout/index.vue';
import HeadLayout from '@/layout/head/index.vue'
export const constantRoutes = [ export const constantRoutes = [
{ {
name:'Layout', name:'Layout',
path: '/', path: '/',
component: Layout, component: Layout,
redirect:"/recommend", redirect:"/recommend",
children: [ children: [
{
path: '/shopIndex',
component: () => import('@/view/shop/shopIndex.vue'),
name: 'ShopIndex',
},
{ {
path: '/my', path: '/my',
component: () => import('@/view/my.vue'), component: () => import('@/view/my.vue'),
@@ -49,6 +55,25 @@ export const constantRoutes = [
component: () => import('@/view/login.vue'), component: () => import('@/view/login.vue'),
name: 'Login', name: 'Login',
}, },
{
name:'Shop',
path: '/shop',
component: HeadLayout,
redirect:"/shopIndex",
children: [
{
path: '/shopDetails',
component: () => import('@/view/shop/shopDetails.vue'),
name: 'ShopDetails',
},
{
path: '/shopSearch',
component: () => import('@/view/shop/shopSearch.vue'),
name: 'ShopSearch',
},
]
}
]; ];
const router = createRouter({ const router = createRouter({

View File

@@ -0,0 +1,5 @@
<template>
这里是商品详情页
<br>
<router-link to="/shopIndex">返回商品首页</router-link>
</template>

View File

@@ -0,0 +1,23 @@
<template>
这里是商城主页
<van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" lazy-render>
<van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item>
<van-swipe-item>4</van-swipe-item>
</van-swipe>
<van-grid :column-num="4">
<van-grid-item v-for="value in 8" :key="value" icon="photo-o" text="文字" />
</van-grid>
<router-link to="/shopSearch">点击前往搜索</router-link>
<br>
</template>
<style>
.my-swipe .van-swipe-item {
color: #fff;
font-size: 20px;
line-height: 150px;
text-align: center;
background-color: #39a9ed;
}
</style>

View File

@@ -0,0 +1,7 @@
<template>
这里是商品搜索页
<br>
<router-link to="/shopDetails">点击进入商品详情</router-link>
<br>
<router-link to="/shopIndex">返回商品首页</router-link>
</template>