mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-02 15:50:54 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f4c7f607d | ||
|
|
994ba5dd1a | ||
|
|
e3a06b28dd | ||
|
|
10d512470e | ||
|
|
c1d8040fd5 | ||
|
|
e4b81da386 | ||
|
|
fd7360e6f4 | ||
|
|
62f15e218e | ||
|
|
5c1b91f348 | ||
|
|
378cbd580f | ||
|
|
3994f14010 |
@@ -22,7 +22,7 @@ Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
|
||||
适合.Net6学习、Sqlsugar学习 、项目二次开发。
|
||||
集大成者,终究轮子
|
||||
|
||||
Yi框架最新版本标签:`v1.1.1`,具体版本可以查看标签迭代
|
||||
Yi框架最新版本标签:`v1.1.3`,具体版本可以查看标签迭代
|
||||
|
||||
(项目与Sqlsugar同步更新,但这作者老杰哥代码天天爆肝到凌晨两点,我们也尽量会跟上他的脚步。更新频繁,所以可watching持续关注。)
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
UserEntity user = new();
|
||||
if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o))
|
||||
{
|
||||
return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(user) });
|
||||
var userRoleMenu= await _iUserService.GetUserAllInfo(user.Id);
|
||||
return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User,userRoleMenu.Menus) });
|
||||
}
|
||||
return Result.SuccessError("登录失败!用户名或者密码错误!");
|
||||
}
|
||||
@@ -80,6 +81,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<Result> GetUserAllInfo()
|
||||
{
|
||||
//通过鉴权jwt获取到用户的id
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:one")]
|
||||
[Permission($"{nameof(T)}:get:list")]
|
||||
[HttpGet]
|
||||
public virtual async Task<Result> GetById(long id)
|
||||
{
|
||||
@@ -55,7 +55,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <param name="queryCondition"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:page")]
|
||||
[Permission($"{nameof(T)}:get:list")]
|
||||
[HttpPost]
|
||||
public virtual async Task<Result> PageList(QueryPageCondition queryCondition)
|
||||
{
|
||||
@@ -91,7 +91,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:delete:list")]
|
||||
[Permission($"{nameof(T)}:del")]
|
||||
[HttpDelete]
|
||||
public virtual async Task<Result> DeleteList(List<long> ids)
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
// 特点:化繁为简!意框架仓储代理上下文对象,用起来就是爽,但最好按规范来爽!
|
||||
// 规范:控制器不建议使用切换仓储方法、控制器严禁使用DB上下文对象,其它怎么爽怎么来!
|
||||
// 规范:控制器严禁使用DB上下文对象,其它怎么爽怎么来!
|
||||
public async Task<Result> DbTest()
|
||||
{
|
||||
//非常好,使用UserService的特有方法
|
||||
@@ -60,7 +60,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
//挺不错,依赖注入其他仓储
|
||||
await _iRoleService._repository.GetListAsync();
|
||||
|
||||
//不建议操作,直接切换其他仓储
|
||||
//还行,直接切换其他仓储,怎么爽怎么来
|
||||
await _iUserService._repository.ChangeRepository<Repository<RoleEntity>>().GetListAsync();
|
||||
|
||||
//最好不要直接操作Db对象
|
||||
@@ -74,7 +74,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
//简单语句不推荐!
|
||||
//简单语句不推荐使用sql!
|
||||
public async Task<Result> SqlTest()
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService._repository.UseSqlAsync<UserEntity>("select * from User"));
|
||||
|
||||
Binary file not shown.
@@ -23,15 +23,15 @@ namespace Yi.Framework.Core
|
||||
}
|
||||
public string GetRefreshToken(UserEntity user)
|
||||
{
|
||||
return this.GetToken(_JWTTokenOptions.ReExpiration, user, true);
|
||||
return this.GetToken(_JWTTokenOptions.ReExpiration, user,null, true);
|
||||
}
|
||||
|
||||
public string GetAccessToken(UserEntity user)
|
||||
public string GetAccessToken(UserEntity user,HashSet<MenuEntity> menus)
|
||||
{
|
||||
return this.GetToken(_JWTTokenOptions.Expiration, user);
|
||||
return this.GetToken(_JWTTokenOptions.Expiration, user, menus);
|
||||
}
|
||||
|
||||
private string GetToken(int minutes, UserEntity user, bool isRefresh = false)
|
||||
private string GetToken(int minutes, UserEntity user, HashSet<MenuEntity> menus,bool isRefresh = false)
|
||||
{
|
||||
List<Claim> claims = new List<Claim>();
|
||||
claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"));
|
||||
@@ -39,8 +39,11 @@ namespace Yi.Framework.Core
|
||||
claims.Add(new Claim(JwtRegisteredClaimNames.Sid, user.Id.ToString()));
|
||||
|
||||
//-----------------------------以下从user的权限表中添加权限-----------------------例如:
|
||||
claims.Add(new Claim("permission", "userentity:get:list"));
|
||||
claims.Add(new Claim("permission", "userentity:get:one"));
|
||||
|
||||
foreach (var m in menus)
|
||||
{
|
||||
claims.Add(new Claim("permission", m.PermissionCode));
|
||||
}
|
||||
|
||||
if (isRefresh)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.IdentityModel.JsonWebTokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.WebCore.AttributeExtend
|
||||
@@ -40,11 +41,24 @@ namespace Yi.Framework.WebCore.AttributeExtend
|
||||
var perList = context.HttpContext.User.Claims.Where(u => u.Type == "permission").Select(u=> u.Value.ToString().ToLower()). ToList();
|
||||
//判断权限是否存在Redis中,或者jwt中
|
||||
|
||||
//if (perList.Contains(permission.ToLower()))
|
||||
//{
|
||||
// result = true;
|
||||
//}
|
||||
result = true;
|
||||
//进行正则表达式的匹配,以code开头
|
||||
Regex regex = new Regex($"^{permission.ToLower()}");
|
||||
foreach (var p in perList)
|
||||
{
|
||||
//过滤多余的标签
|
||||
p.Replace("Entity","");
|
||||
p.Replace("entity","");
|
||||
if (regex.IsMatch(p))
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//用户的增删改查直接可以user:*即可
|
||||
|
||||
|
||||
//这里暂时全部放行即可
|
||||
result = true;
|
||||
|
||||
|
||||
if (!result)
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
import myaxios from '@/util/myaxios'
|
||||
import {objctToDic} from '@/util/objctHandle'
|
||||
export default {
|
||||
getList() {
|
||||
return myaxios({
|
||||
url: '/Role/GetList',
|
||||
method: 'post',
|
||||
data: {
|
||||
parameters: [
|
||||
{
|
||||
key: "isDeleted",
|
||||
value: "0",
|
||||
type: 0
|
||||
|
||||
}
|
||||
],
|
||||
orderBys: [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
data: objctToDic()
|
||||
})
|
||||
},
|
||||
giveRoleSetMenu(roleList, menuList) {
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
import myaxios from '@/util/myaxios'
|
||||
export default {
|
||||
SetRoleByUser(userIds, roleIds) {
|
||||
return myaxios({
|
||||
url: '/User/SetRoleByUser',
|
||||
method: 'post',
|
||||
data: { "ids1": userIds, "ids2": roleIds }
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
|
||||
GetUserInRolesByHttpUser() {
|
||||
return myaxios({
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
import myaxios from '@/util/myaxios'
|
||||
import {objctToDic} from '@/util/objctHandle'
|
||||
export default {
|
||||
getItem(url) {
|
||||
return myaxios({
|
||||
url: url,
|
||||
method: 'post',
|
||||
data: {
|
||||
parameters: [
|
||||
{
|
||||
key: "isDeleted",
|
||||
value: "0",
|
||||
type: 0
|
||||
|
||||
}
|
||||
],
|
||||
orderBys: [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
data: objctToDic()
|
||||
})
|
||||
},
|
||||
addItem(url, data) {
|
||||
|
||||
@@ -53,8 +53,7 @@
|
||||
item-text="menuName"
|
||||
>
|
||||
<template v-slot:append="{ item }">
|
||||
<v-btn class="mr-2">编号:{{ item.id }}</v-btn>
|
||||
<v-btn class="mr-2">权限:{{ item.permissionCode }}</v-btn>
|
||||
<v-btn v-show="item.menuType==1" class="mr-2">权限:{{ item.permissionCode }}</v-btn>
|
||||
<!-- <v-btn class="mr-2">图标:{{ item.icon }}</v-btn> -->
|
||||
<!-- <v-btn class="mr-2">路由:{{ item.router }}</v-btn> -->
|
||||
<!-- <v-btn v-if="item.mould" class="mr-2">接口名:{{ item.mould.mould_name }}</v-btn>
|
||||
|
||||
29
Yi.Vue2.x/src/util/menuDic.js
Normal file
29
Yi.Vue2.x/src/util/menuDic.js
Normal file
@@ -0,0 +1,29 @@
|
||||
//匹配菜单,让code变成路由
|
||||
const menuDic=
|
||||
{
|
||||
"user:get:list": "/admuser",
|
||||
"role:get:list": "/admrole",
|
||||
"menu:get:list":"/admmenu",
|
||||
"rolemenu:set:list":"/admrolemenu"
|
||||
}
|
||||
//匹配按钮,判断是否有按钮存在
|
||||
const btnDic=
|
||||
{
|
||||
"user:add":"",
|
||||
"user:update":"",
|
||||
"user:del":"",
|
||||
}
|
||||
export default {menuDic,btnDic};
|
||||
//菜单可以区分使用code来进行匹配
|
||||
//记得:关于*的使用,要单独判断
|
||||
//比如,
|
||||
|
||||
//按钮是user:*或者*:*:*直接全部放行即可
|
||||
|
||||
//菜单就不一样了,如果是*:*:*
|
||||
//有两种方案:
|
||||
//1:直接使用一个默认的全部菜单(会和后端给的菜单冲突)
|
||||
//2:前端直接无视,*:*:*相当于只管后端权限(如果后端没有配置菜单前端将没有菜单了)
|
||||
|
||||
|
||||
//如果查询找到的是user:*,可以先把*全部替换成get:list再进行比对即可
|
||||
@@ -8,6 +8,11 @@ export function deepCopy(obj) {
|
||||
|
||||
//转换数据,0是相等,1是模糊查询
|
||||
export function objctToDic(object, isByPage) {
|
||||
if (object == undefined) {
|
||||
|
||||
object = {};
|
||||
}
|
||||
|
||||
if (isByPage) {
|
||||
var paramPage = {
|
||||
"index": object.pageIndex,
|
||||
@@ -19,8 +24,8 @@ export function objctToDic(object, isByPage) {
|
||||
var newData = deepCopy(object);
|
||||
delete newData.pageIndex;
|
||||
delete newData.pageSize;
|
||||
|
||||
var newList = [Object.keys(newData).map(val => {
|
||||
|
||||
var newList = [Object.keys(newData).map(val => {
|
||||
return {
|
||||
key: val,
|
||||
value: object[val],
|
||||
@@ -30,11 +35,9 @@ export function objctToDic(object, isByPage) {
|
||||
|
||||
//过滤封装
|
||||
newList[0].forEach((item, index) => {
|
||||
if(item.value.length>0)
|
||||
{
|
||||
if(item.key=='isDeleted')
|
||||
{
|
||||
item.type=0;
|
||||
if (item.value.length > 0) {
|
||||
if (item.key == 'isDeleted') {
|
||||
item.type = 0;
|
||||
}
|
||||
paramPage.parameters.push(item);
|
||||
}
|
||||
@@ -55,11 +58,9 @@ export function objctToDic(object, isByPage) {
|
||||
}
|
||||
})]
|
||||
thisList[0].forEach((item, index) => {
|
||||
if(item.value.length>0)
|
||||
{
|
||||
if(item.key=='isDeleted')
|
||||
{
|
||||
item.type=0;
|
||||
if (item.value.length > 0) {
|
||||
if (item.key == 'isDeleted') {
|
||||
item.type = 0;
|
||||
}
|
||||
params.parameters.push(item);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ export default {
|
||||
axiosUrls: {},
|
||||
headers: [
|
||||
{ text: "用户名", value: "userName", sortable: false },
|
||||
{ text: "密码", value: "password", sortable: false },
|
||||
|
||||
{ text: "图标", value: "icon", sortable: false },
|
||||
{ text: "昵称", value: "nick", sortable: true },
|
||||
{ text: "邮箱", value: "email", sortable: true },
|
||||
|
||||
Reference in New Issue
Block a user