改造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>
public class Appsettings
{
static IConfiguration Configuration { get; set; }
static string contentPath { get; set; }
static IConfiguration? Configuration { get; set; }
static string? contentPath { get; set; }
public Appsettings(string contentPath)
{
@@ -37,14 +37,14 @@ namespace Yi.Framework.WebCore
/// </summary>
/// <param name="sections">节点配置</param>
/// <returns></returns>
public static string app(params string[] sections)
public static string? app(params string[] sections)
{
try
{
if (sections.Any())
{
return Configuration[string.Join(":", sections)];
return Configuration?[string.Join(":", sections)];
}
}
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;
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;
//查找标签,获取标签对象
LogAttribute logAttribute = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true)
LogAttribute? logAttribute = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true)
.FirstOrDefault(a => a.GetType().Equals(typeof(LogAttribute))) as LogAttribute;
//空对象直接返回
if (logAttribute is null) return;
@@ -72,7 +71,7 @@ namespace Yi.Framework.WebCore.AttributeExtend
{
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)
{

View File

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

View File

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

View File

@@ -44,12 +44,13 @@ namespace Yi.Framework.Core
roles = new();
}
//先测试部门就是LEBG
long deptId = (long)userRoleMenu.User.DeptId;
long deptId = userRoleMenu.User.DeptId??-1;
long userId = httpContext.GetUserIdInfo();
//根据角色的数据范围,来添加相对于的数据权限
foreach (var role in roles)
{
DataScopeEnum dataScope = (DataScopeEnum)role.DataScope;
//默认为全部
DataScopeEnum dataScope = (DataScopeEnum)(role.DataScope?? DataScopeEnum.ALL.GetHashCode());
switch (dataScope)
{
case DataScopeEnum.ALL:
@@ -71,8 +72,9 @@ namespace Yi.Framework.Core
case DataScopeEnum.DEPT_FOLLOW:
//放行自己部门及以下
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);
//部门无需过滤

View File

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

View File

@@ -11,7 +11,7 @@ namespace Yi.Framework.WebCore.FilterExtend
/// </summary>
public class CustomIOCFilterFactoryAttribute : Attribute, IFilterFactory
{
private readonly Type _FilterType = null;
private readonly Type _FilterType;
public CustomIOCFilterFactoryAttribute(Type type)
{
@@ -23,7 +23,7 @@ namespace Yi.Framework.WebCore.FilterExtend
{
//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 void AddSqlsugarServer(this IServiceCollection services, Action<SqlSugarClient> action = null)
public static void AddSqlsugarServer(this IServiceCollection services, Action<SqlSugarClient>? action = null)
{
DbType dbType;
var slavaConFig = new List<SlaveConnectionConfig>();
@@ -60,7 +60,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
},
db =>
{
if (action.IsNotNull())
if (action is not null)
{
action(db);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -35,6 +35,7 @@ let tabbar=ref([
{icon:"wap-home",to:"/",title:"主页"},
{icon:"location-o",to:"",title:"发现"},
{icon:"",to:"",title:""},
// {icon:"friends-o",to:"/shopIndex",title:"商城"},
{icon:"friends-o",to:"",title:"商城"},
{icon:"setting-o",to:"/my",title:"我的"},
])
@@ -43,6 +44,7 @@ const onChange=(index:number)=>{
{icon:"wap-home-o",to:"/",title:"主页"},
{icon:"location-o",to:"",title:"发现"},
{icon:"",to:"",title:""},
// {icon:"friends-o",to:"/shopIndex",title:"商城"},
{icon:"friends-o",to:"",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 Layout from '@/layout/index.vue';
import HeadLayout from '@/layout/head/index.vue'
export const constantRoutes = [
{
name:'Layout',
path: '/',
component: Layout,
redirect:"/recommend",
children: [
{
path: '/shopIndex',
component: () => import('@/view/shop/shopIndex.vue'),
name: 'ShopIndex',
},
{
path: '/my',
component: () => import('@/view/my.vue'),
@@ -49,6 +55,25 @@ export const constantRoutes = [
component: () => import('@/view/login.vue'),
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({

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>