前端大更新vuex

This commit is contained in:
橙子
2021-10-17 18:37:07 +08:00
parent b77b91912b
commit 6bb2b41840
24 changed files with 332 additions and 65 deletions

View File

@@ -28,7 +28,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
/// <summary>
/// 登录方法要返回data:{user,token} token先写123456789,不要有导航属性
/// 登录方法要返回data:{user,token} token
/// </summary>
/// <param name="_user"></param>
/// <returns></returns>

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<!-- 将日志以回滚文件的形式写到文件中 -->
<!-- 按日期切分日志文件,并将日期作为日志文件的名字 -->
<!--Error-->
<appender name="ErrorLog" type="log4net.Appender.RollingFileAppender">
<!--不加utf-8编码格式中文字符将显示成乱码-->
<param name="Encoding" value="utf-8" />
<file value="log/"/>
<appendToFile value="true" />
<rollingStyle value="Date" />
<!--日期的格式,每天换一个文件记录,如不设置则永远只记录一天的日志,需设置-->
<datePattern value="&quot;GlobalExceptionLogs_&quot;yyyyMMdd&quot;.log&quot;" />
<!--日志文件名是否为静态-->
<StaticLogFileName value="false"/>
<!--多线程时采用最小锁定-->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<!--布局(向用户显示最后经过格式化的输出信息)-->
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date| %-5level %newline%message%newline--------------------------------%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR" />
<levelMax value="FATAL" />
</filter>
</appender>
<!--Error-->
<!--Info-->
<appender name="InfoLog" type="log4net.Appender.RollingFileAppender">
<!--不加utf-8编码格式中文字符将显示成乱码-->
<param name="Encoding" value="utf-8" />
<!--定义文件存放位置-->
<file value="log/"/>
<appendToFile value="true" />
<rollingStyle value="Date" />
<!--日志文件名是否为静态-->
<StaticLogFileName value="false"/>
<!--日期的格式,每天换一个文件记录,如不设置则永远只记录一天的日志,需设置-->
<datePattern value="&quot;GlobalInfoLogs_&quot;yyyyMMdd&quot;.log&quot;" />
<!--多线程时采用最小锁定-->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<!--布局(向用户显示最后经过格式化的输出信息)-->
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date| %-5level%c %newline%message%newline--------------------------------%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="WARN" />
</filter>
</appender>
<!--Info-->
<root>
<!-- 控制级别由低到高ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF -->
<!-- 比如定义级别为INFO则INFO级别向下的级别比如DEBUG日志将不会被记录 -->
<!-- 如果没有定义LEVEL的值则缺省为DEBUG -->
<level value="ALL" />
<!-- 按日期切分日志文件,并将日期作为日志文件的名字 -->
<appender-ref ref="ErrorLog" />
<appender-ref ref="InfoLog" />
</root>
</log4net>

View File

@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.WebCore.BuilderExtend;
namespace Yi.Framework.ApiMicroservice
{
@@ -19,9 +20,25 @@ namespace Yi.Framework.ApiMicroservice
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostBuilderContext, configurationBuilder) =>
{
configurationBuilder.AddCommandLine(args);
configurationBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);
#region
//Apollo<6C><6F><EFBFBD><EFBFBD>
#endregion
//configurationBuilder.AddApolloService("Yi");
})
.ConfigureLogging(loggingBuilder =>
{
loggingBuilder.AddFilter("System", Microsoft.Extensions.Logging.LogLevel.Warning);
loggingBuilder.AddFilter("Microsoft", Microsoft.Extensions.Logging.LogLevel.Warning);
loggingBuilder.AddLog4Net();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseStartup<Startup>().UseUrls("https://*:44329");
}).UseServiceProviderFactory(new AutofacServiceProviderFactory());
}
}

View File

@@ -13,13 +13,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.ApiMicroservice.Utility;
using Yi.Framework.Common.IOCOptions;
using Yi.Framework.Interface;
using Yi.Framework.Model;
using Yi.Framework.Service;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.FilterExtend;
using Yi.Framework.WebCore.MiddlewareExtend;
using Yi.Framework.WebCore.Utility;
namespace Yi.Framework.ApiMicroservice
{
@@ -43,7 +44,9 @@ namespace Yi.Framework.ApiMicroservice
#region
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#endregion
services.AddControllers();
services.AddControllers(optios=> {
//optios.Filters.Add(typeof(CustomExceptionFilterAttribute));
});
#region
//Swagger<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@@ -55,6 +58,11 @@ namespace Yi.Framework.ApiMicroservice
#endregion
services.AddCorsService();
#region
//Jwt<77><74>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD>
#endregion
services.AddJwtService();
#region
//Sqlite<74><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#endregion
@@ -98,6 +106,10 @@ namespace Yi.Framework.ApiMicroservice
#endregion
app.UseSwaggerService();
}
#region
//<2F><><EFBFBD><EFBFBD>ץȡ<D7A5><C8A1><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
#endregion
app.UseErrorHandlingService();
#region
//HttpsRedirectionע<6E><D7A2>

View File

@@ -6,7 +6,7 @@
<members>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Login(Yi.Framework.Model.Models.user)">
<summary>
登录方法要返回data:{user,token} token先写123456789,不要有导航属性
登录方法要返回data:{user,token} token
</summary>
<param name="_user"></param>
<returns></returns>
@@ -162,13 +162,5 @@
<param name="idsListDto"></param>
<returns></returns>
</member>
<member name="T:Yi.Framework.ApiMicroservice.Utility.CustomHostingStartup">
<summary>
必须实现IHostingStartup接口
必须标记HostingStartup特性
就像木马一样
</summary>
</member>
</members>
</doc>

View File

@@ -9,17 +9,6 @@
<NoWarn>1701;1702;CS1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="6.3.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />

View File

@@ -6,8 +6,49 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Apollo": {
"AppId": "Yi-ApiMicroservice",
"Env": "DEV",
"MetaServer": "http://192.168.2.168:8080",
"ConfigServer": [ "http://192.168.2.168:8080" ]
},
"SqliteConn": {
"Url": "Filename=YIDB.db"
},
"AllowedHosts": "*"
"MysqlConn": {
"Url": "server=192.168.2.128;port=3306;database=ECDB;user id=root;password=123456"
},
"JWTTokenOptions": {
"Audience": "http://localhost:7000",
"Issuer": "http://localhost:7000",
"SecurityKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI2a2EJ7m872v0afyoSDJT2o1+SitIeJSWtLJU8/Wz2m7gStexajkeD+Lka6DSTy8gt9UwfgVQo6uKjVLG5Ex7PiGOODVqAEghBuS7JzIYU5RvI543nNDAPfnJsas96mSA7L/mD7RTE2drj6hf3oZjJpMPZUQI/B1Qjb5H3K3PNwIDAQAB"
},
"RedisConn": {
"Host": "192.168.2.128",
"Prot": 6379,
"DB": 0,
"Password": "123456"
},
"KafkaOptions": {
"BrokerList": "192.168.3.230:9092",
"TopicName": "kafkalog"
},
"ConsulClientOption": {
"IP": "192.168.2.128",
"Port": "8500",
"Datacenter": "dc1"
},
"ConsulRegisterOption": {
"IP": "192.168.1.104",
"Port": "7001",
"GroupName": "ApiMicroservice",
"HealthCheckUrl": "/Health",
"Interval": 10,
"Timeout": 5,
"DeregisterCriticalServiceAfter": 60,
"Tag": "13"
},
"IPLibraryServiceUrl": "http://gRPCIPLibraryService"
}

View File

@@ -26,6 +26,11 @@ namespace Yi.Framework.Common.Models
{
return new Result() { status = true, code = 200, msg = msg };
}
public static Result UnAuthorize(string msg = "unAuthorize")
{
return new Result() { status = false, code = 401, msg = msg };
}
public Result SetData(object obj)
{
this.data = obj;
@@ -56,6 +61,12 @@ namespace Yi.Framework.Common.Models
{
return new Result<T> { status = true, code = 200, msg = msg };
}
public static Result<T> UnAuthorize(string msg = "unAuthorize")
{
return new Result<T>{ status = false, code = 401, msg = msg };
}
public Result<T> SetData(T TValue)
{
this.data = TValue;

View File

@@ -10,6 +10,13 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Oracle.EntityFrameworkCore" Version="5.21.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.2" />
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1,63 @@
using Com.Ctrip.Framework.Apollo;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using Com.Ctrip.Framework.Apollo.Enums;
using Com.Ctrip.Framework.Apollo.Logging;
using Microsoft.Extensions.Primitives;
using System.Reflection;
namespace Yi.Framework.WebCore.BuilderExtend
{
public static class ApolloExtension
{
/// <summary>
/// 接入Apollo
/// </summary>
/// <param name="builder"></param>
/// <param name="jsonPath">apollo配置文件路径 如果写入appsettings.json中 则jsonPath传null即可</param>
public static void AddApolloService(this IConfigurationBuilder builder, params string[] NameSpace)
{
//阿波罗的日志级别调整
LogManager.UseConsoleLogging(LogLevel.Warn);
var root = builder.Build();
var apolloBuilder = builder.AddApollo(root.GetSection("apollo")).AddDefault();
foreach (var item in NameSpace)
{
apolloBuilder.AddNamespace(item, ConfigFileFormat.Json);
}
//监听apollo配置
Monitor(builder.Build());
}
#region private
/// <summary>
/// 监听配置
/// </summary>
private static void Monitor(IConfigurationRoot root)
{
//TODO 需要根据改变执行特定的操作 如 mq redis 等其他跟配置相关的中间件
//TODO 初步思路将需要执行特定的操作key和value放入内存字典中在赋值操作时通过标准事件来执行特定的操作。
//要重新Build 此时才将Apollo provider加入到ConfigurationBuilder中
ChangeToken.OnChange(() => root.GetReloadToken(), () =>
{
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>;
foreach (var item in data)
{
Console.WriteLine($"key {item.Key} value {item.Value}");
}
}
});
}
#endregion
}
}

View File

@@ -43,12 +43,10 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
switch (statusCode)
{
case 401: msg = "未授权";break;
case 403: msg = "未授权"; break;
case 404: msg = "未找到服务"; break;
case 502: msg = "请求错误"; break;
}
if (!string.IsNullOrWhiteSpace(msg))
{
@@ -59,7 +57,16 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
//异常错误信息捕获将错误信息用Json方式返回
private static Task HandleExceptionAsync(HttpContext context, int statusCode, string msg)
{
var result = JsonConvert.SerializeObject( Result.Error(msg).SetCode(statusCode));
Result resp;
if (statusCode == 401)
{
resp = Result.UnAuthorize(msg);
}
else
{
resp = Result.Error(msg);
}
var result = JsonConvert.SerializeObject(resp);
context.Response.ContentType = "application/json;charset=utf-8";
return context.Response.WriteAsync(result);
}
@@ -67,7 +74,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
//扩展方法
public static class ErrorHandlingExtensions
{
public static IApplicationBuilder UseErrorHandling(this IApplicationBuilder builder)
public static IApplicationBuilder UseErrorHandlingService(this IApplicationBuilder builder)
{
return builder.UseMiddleware<ErrorHandExtension>();
}

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Yi.Framework.ApiMicroservice.Utility
namespace Yi.Framework.WebCore.Utility
{
public class CustomAutofacAop : IInterceptor
{

View File

@@ -10,13 +10,10 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Yi.Framework.ApiMicroservice.Utility;
using Yi.Framework.Interface;
using Yi.Framework.Model;
using Yi.Framework.Service;
using Yi.Framework.WebCore.Utility;
using Module = Autofac.Module;
namespace Yi.Framework.ApiMicroservice.Utility
namespace Yi.Framework.WebCore.Utility
{
public class CustomAutofacModule : Module
{

View File

@@ -7,8 +7,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
[assembly: HostingStartup(typeof(Yi.Framework.ApiMicroservice.Utility.CustomHostingStartup))]
namespace Yi.Framework.ApiMicroservice.Utility
[assembly: HostingStartup(typeof(Yi.Framework.WebCore.Utility.CustomHostingStartup))]
namespace Yi.Framework.WebCore.Utility
{
/// <summary>
/// 必须实现IHostingStartup接口

View File

@@ -5,11 +5,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="6.3.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.0" />
<PackageReference Include="Com.Ctrip.Framework.Apollo.Configuration" Version="2.4.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="5.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>

View File

@@ -25,6 +25,7 @@
<default-notifications />
<default-account />
</v-app-bar>
</template>

View File

@@ -1,6 +1,13 @@
<template>
<v-main>
<v-container fluid>
<v-progress-linear
:active="this.$store.state.loader.load"
:indeterminate="this.$store.state.loader.load"
background-color="primary lighten-4"
color="primary lighten-1"
striped
></v-progress-linear>
<router-view :key="$route.path" />
</v-container>
</v-main>

View File

@@ -5,6 +5,7 @@ import vuetify from './plugins/vuetify'
import VuetifyDialog from 'vuetify-dialog'
import 'vuetify-dialog/dist/vuetify-dialog.css'
import './plugins'
import "./permission"
import store from './store/index'
Vue.config.productionTip = false
@@ -13,9 +14,11 @@ Vue.use(VuetifyDialog, {
vuetify
}
});
new Vue({
let vm = new Vue({
router,
store,
vuetify,
render: function(h) { return h(App) }
}).$mount('#app')
}).$mount('#app')
export default vm;

19
Yi.Vue/src/permission.js Normal file
View File

@@ -0,0 +1,19 @@
import router from './router/index'
import store from './store/index'
// import accountApi from '@/api/accountApi'
router.beforeEach((to, from, next) => {
const user = store.state.user.user; //获取是有user
console.log(user)
if (!user) { //如果没有登入
if (to.path == '/login/' || to.path == '/register/' || to.path == '/reset_password/' || to.path == '/qq/') {
next();
} else {
next({ path: '/login/' });
}
} else {
next();
}
})

View File

@@ -1,5 +1,6 @@
import axios from 'axios'
import store from '../store/index'
import vm from '../main'
// import VuetifyDialogPlugin from 'vuetify-dialog/nuxt/index';
const myaxios = axios.create({
// baseURL:'/'//
@@ -12,25 +13,44 @@ const myaxios = axios.create({
// 请求拦截器
myaxios.interceptors.request.use(function(config) {
config.headers.Authorization = 'Bearer ' + store.state.user.token;
// store.dispatch("openLoad");
store.dispatch("openLoad");
return config;
}, function(error) {
return Promise.reject(error);
});
// 响应拦截器
myaxios.interceptors.response.use(function(response) {
myaxios.interceptors.response.use(async function(response) {
const resp = response.data
// store.dispatch("closeLoad");
if (resp.code == undefined && resp.msg == undefined) {
vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
position: "top-right",
timeout: 5000,
});
} else if (resp.code == 401) {
const res = await vm.$dialog.error({
text: `错误代码:${resp.code},原因:${resp.msg}<br>是否重新进行登录?`,
title: '错误',
actions: {
'false': '取消',
'true': '跳转'
}
});
if (res) {
vm.$router.push({ path: "/login" });
}
} else if (resp.code !== 200) {
vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.msg}`, {
position: "top-right",
timeout: 5000,
});
}
store.dispatch("closeLoad");
return resp;
}, function(error) {
const resp = error.response.data
// if (resp.code == undefined && resp.msg == undefined) {
// alert(`错误代码:无,原因:与服务器失去连接`)
// } else if (resp.code != 200) {
// alert(`错误代码:${resp.code},原因:${resp.msg}`)
// }
// store.dispatch("closeLoad");
store.dispatch("closeLoad");
return Promise.reject(error);
});
export default myaxios

View File

@@ -55,8 +55,7 @@ export function redirect(
export function route(name, component, path = '') {
component = Object(component) === component ?
component :
{ default: name.replace(' ', '') }
component : { default: name.replace(' ', '') }
const components = {}

View File

@@ -1,14 +1,25 @@
<template>
<div>
<MaterialCard title="首页卡片" subtitle="微软Microsoft是一家美国跨国科技企业由比尔·盖茨和保罗·艾伦于1975年4月4日创立。" heading="头部" color='#E91E63' :fullHeader='false' icon='mdi-view-dashboard'></MaterialCard>
<MaterialCharCard></MaterialCharCard>
<MaterialSnackbar></MaterialSnackbar>
<MaterialStatCard value="微软Microsoft是一家美国跨国科技企业由比尔·盖茨和保罗·艾伦于1975年4月4日创立。">
<template v-slot>
还有什么呢
</template>
</MaterialStatCard>
</div>
</template>
<div>
<MaterialCard
title="首页卡片"
subtitle="微软Microsoft是一家美国跨国科技企业由比尔·盖茨和保罗·艾伦于1975年4月4日创立。"
heading="头部"
color="#E91E63"
:fullHeader="false"
icon="mdi-view-dashboard"
></MaterialCard>
<MaterialCharCard></MaterialCharCard>
<MaterialSnackbar></MaterialSnackbar>
<MaterialStatCard
value="微软Microsoft是一家美国跨国科技企业由比尔·盖茨和保罗·艾伦于1975年4月4日创立。"
>
<template v-slot> 还有什么呢 </template>
</MaterialStatCard>
</div>
</template>
<script>
export default {
data: () => ({}),
created() {},
};
</script>