Compare commits

..

4 Commits

Author SHA1 Message Date
橙子
4ba696d289 添加用户简介 2022-04-30 22:12:25 +08:00
橙子
2f69e0b96c 添加前端用户信息展示 2022-04-30 22:04:47 +08:00
橙子
d6b0c56c35 添加登录用户全部信息查询 2022-04-30 21:48:18 +08:00
橙子
d8fe983b9d Update README.md 2022-04-29 12:58:35 +08:00
14 changed files with 127 additions and 28 deletions

View File

@@ -12,6 +12,8 @@
### 简介: ### 简介:
**中文:意框架**(和他的名字一样“简易”) **中文:意框架**(和他的名字一样“简易”)
正在持续更进业务模块
**英文YiFramework** **英文YiFramework**
Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。 Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
@@ -20,7 +22,7 @@ Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
适合.Net6学习、Sqlsugar学习 、项目二次开发。 适合.Net6学习、Sqlsugar学习 、项目二次开发。
集大成者,终究轮子 集大成者,终究轮子
Yi框架最新版本标签`v1.0.5`,具体版本可以查看标签迭代 Yi框架最新版本标签`v1.0.8`,具体版本可以查看标签迭代
项目与Sqlsugar同步更新但这作者老杰哥代码天天爆肝到凌晨两点我们也尽量会跟上他的脚步。更新频繁所以可watching持续关注。 项目与Sqlsugar同步更新但这作者老杰哥代码天天爆肝到凌晨两点我们也尽量会跟上他的脚步。更新频繁所以可watching持续关注。

Binary file not shown.

View File

@@ -9,6 +9,12 @@
账户管理 账户管理
</summary> </summary>
</member> </member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.GetUserAllInfo">
<summary>
通过已登录的用户获取用户信息及菜单
</summary>
<returns></returns>
</member>
<member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1"> <member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1">
<summary> <summary>
Json To Sql 类比模式,通用模型 Json To Sql 类比模式,通用模型

View File

@@ -55,5 +55,20 @@ namespace Yi.Framework.ApiMicroservice.Controllers
} }
return Result.SuccessError("注册失败!用户名已存在!"); return Result.SuccessError("注册失败!用户名已存在!");
} }
/// <summary>
/// 通过已登录的用户获取用户信息及菜单
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<Result> GetUserAllInfo()
{
//通过鉴权jwt获取到用户的id
var userId=HttpContext.GetCurrentUserEntityInfo(out _).Id;
return Result.Success().SetData(await _iUserService.GetUserAllInfo(userId));
}
} }
} }

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Model.Models;
namespace Yi.Framework.DTOModel
{
public class UserRoleMenuDto
{
public UserEntity User { get; set; }=new ();
public HashSet<RoleEntity> Roles { get; set; } = new();
public HashSet<MenuEntity> Menus { get; set; }=new();
}
}

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.DTOModel;
using Yi.Framework.Model.Models; using Yi.Framework.Model.Models;
using Yi.Framework.Repository; using Yi.Framework.Repository;
@@ -59,5 +60,12 @@ namespace Yi.Framework.Interface
/// <param name="userId"></param> /// <param name="userId"></param>
/// <returns></returns> /// <returns></returns>
Task<List<RoleEntity>> GetRoleListByUserId(long userId); Task<List<RoleEntity>> GetRoleListByUserId(long userId);
/// <summary>
/// 获取当前登录用户的所有信息
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
Task<UserRoleMenuDto> GetUserAllInfo(long userId);
} }
} }

View File

@@ -16,9 +16,7 @@ namespace Yi.Framework.Model.Models
this.IsDeleted = false; this.IsDeleted = false;
this.CreateTime = DateTime.Now; this.CreateTime = DateTime.Now;
} }
[JsonConverter(typeof(ValueToStringConverter))]
[Newtonsoft.Json.JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )] [SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
public long Id { get; set; } public long Id { get; set; }
/// <summary> /// <summary>
@@ -106,5 +104,10 @@ namespace Yi.Framework.Model.Models
///</summary> ///</summary>
[SugarColumn(ColumnName="Phone" )] [SugarColumn(ColumnName="Phone" )]
public string Phone { get; set; } public string Phone { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="Introduction" )]
public string Introduction { get; set; }
} }
} }

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.DTOModel;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Model.Models; using Yi.Framework.Model.Models;
using Yi.Framework.Repository; using Yi.Framework.Repository;
@@ -102,5 +103,37 @@ namespace Yi.Framework.Service
{ {
return (await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles).InSingleAsync(userId)).Roles; return (await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles).InSingleAsync(userId)).Roles;
} }
public async Task<UserRoleMenuDto> GetUserAllInfo(long userId)
{
var userRoleMenu = new UserRoleMenuDto();
//首先获取到该用户全部信息,导航到角色、菜单,(菜单需要去重,完全交给Set来处理即可)
//得到用户
var user = await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles, r => r.Menus).InSingleAsync(userId);
//得到角色集合
var roleList = user.Roles;
//得到菜单集合
foreach (var role in roleList)
{
foreach (var menu in role.Menus)
{
userRoleMenu.Menus.Add(menu);
}
//刚好可以去除一下多余的导航属性
role.Menus = null;
userRoleMenu.Roles.Add(role);
}
user.Roles = null;
userRoleMenu.User = user;
return userRoleMenu;
}
} }
} }

View File

@@ -8,6 +8,7 @@ using System.Security.Claims;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Model.Models; using Yi.Framework.Model.Models;
using System.IdentityModel.Tokens.Jwt;
namespace Yi.Framework.WebCore namespace Yi.Framework.WebCore
{ {
@@ -32,9 +33,21 @@ namespace Yi.Framework.WebCore
/// <returns></returns> /// <returns></returns>
public static UserEntity GetCurrentUserEntityInfo(this HttpContext httpContext, out List<Guid> menuIds) public static UserEntity GetCurrentUserEntityInfo(this HttpContext httpContext, out List<Guid> menuIds)
{ {
IEnumerable<Claim> claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims; IEnumerable<Claim> claimlist = null;
long resId = 0;
long.TryParse(claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Sid).Value,out var resId) ; try
{
claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims;
resId = Convert.ToInt64(claimlist.FirstOrDefault(u => u.Type == JwtRegisteredClaimNames.Sid).Value);
}
catch
{
throw new Exception("未授权Token鉴权失败");
}
menuIds = claimlist.Where(u => u.Type == "menuIds").ToList().Select(u => new Guid(u.Value)).ToList(); menuIds = claimlist.Where(u => u.Type == "menuIds").ToList().Select(u => new Guid(u.Value)).ToList();
@@ -42,7 +55,7 @@ namespace Yi.Framework.WebCore
return new UserEntity() return new UserEntity()
{ {
Id = resId, Id = resId,
Name = claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Name).Value //Name = claimlist.FirstOrDefault(u => u.Type == JwtRegisteredClaimNames.Name).Value
}; };
} }
} }

View File

@@ -41,6 +41,13 @@ export default {
method: 'put', method: 'put',
data: { user, newPassword } data: { user, newPassword }
}) })
},
getUserAllInfo()
{
return myaxios({
url: `/Account/getUserAllInfo`,
method: 'get'
})
} }
} }

View File

@@ -16,7 +16,7 @@
<v-list :tile="false" flat nav> <v-list :tile="false" flat nav>
<app-bar-item to="/" <app-bar-item to="/"
><v-list-item-title v-text="'用户名:'+$store.state.user.user.username" ><v-list-item-title v-text="'用户名:'+$store.state.user.user.userName"
/></app-bar-item> /></app-bar-item>
<app-bar-item to="/" <app-bar-item to="/"
><v-list-item-title v-text="'称号:'+$store.state.user.user.nick" ><v-list-item-title v-text="'称号:'+$store.state.user.user.nick"
@@ -27,7 +27,7 @@
<template v-for="(p, i) in profile"> <template v-for="(p, i) in profile">
<v-divider v-if="p.divider" :key="`divider-${i}`" class="mb-2 mt-2" /> <v-divider v-if="p.divider" :key="`divider-${i}`" class="mb-2 mt-2" />
<app-bar-item v-else :key="`item-${i}`" to="/"> <app-bar-item v-else :key="`item-${i}`" :to="p.router">
<v-list-item-title v-text="p.title" /> <v-list-item-title v-text="p.title" />
</app-bar-item> </app-bar-item>
</template> </template>
@@ -40,10 +40,10 @@ export default {
name: "DefaultAccount", name: "DefaultAccount",
data: () => ({ data: () => ({
profile: [ profile: [
{ title: "用户信息" }, { title: "用户信息",router:"/userInfo" },
{ title: "设置" }, { title: "设置" },
{ divider: true }, { divider: true },
{ title: "登出" }, { title: "登出",router:"/login" },
], ],
}), }),
}; };

View File

@@ -48,7 +48,7 @@
item-text="menuName" item-text="menuName"
> >
<template v-slot:append="{ item }"> <template v-slot:append="{ item }">
<v-btn>id:{{ item.id }}</v-btn> <v-btn>权限:{{ item.permissionCode }}</v-btn>
</template> </template>
</v-treeview> </v-treeview>
</v-card></v-col </v-card></v-col

View File

@@ -7,7 +7,7 @@
<v-card-text class="text-center"> <v-card-text class="text-center">
<h6 class="text-h6 mb-2 text--secondary"> <h6 class="text-h6 mb-2 text--secondary">
{{ userInfo.username }} {{ userInfo.userName }}
</h6> </h6>
<h4 class="text-h4 mb-3 text--primary">{{ userInfo.nick }}</h4> <h4 class="text-h4 mb-3 text--primary">{{ userInfo.nick }}</h4>
@@ -61,7 +61,7 @@
<v-text-field <v-text-field
color="purple" color="purple"
label="用户名" label="用户名"
v-model="editInfo.username" v-model="editInfo.userName"
disabled disabled
/> />
</v-col> </v-col>
@@ -154,12 +154,12 @@
<v-list-item-subtitle> <v-list-item-subtitle>
<v-row> <v-row>
<v-col <v-col
v-for="item in editInfo.roles" v-for="item in roleInfo"
:key="item.id" :key="item.id"
cols="6" cols="6"
sm="3" sm="3"
md="1" md="1"
>{{ item.role_name }}</v-col >{{ item.roleName }}</v-col
> >
</v-row> </v-row>
</v-list-item-subtitle> </v-list-item-subtitle>
@@ -178,7 +178,7 @@
cols="6" cols="6"
sm="3" sm="3"
md="1" md="1"
>{{ item.menu_name }}</v-col >{{ item.menuName }}</v-col
> >
</v-row> </v-row>
</v-list-item-subtitle> </v-list-item-subtitle>
@@ -264,7 +264,6 @@
<script> <script>
import fileApi from "../api/fileApi"; import fileApi from "../api/fileApi";
import userApi from "../api/userApi"; import userApi from "../api/userApi";
import menuApi from "../api/menuApi";
import accountApi from "../api/accountApi"; import accountApi from "../api/accountApi";
export default { export default {
name: "UserProfileView", name: "UserProfileView",
@@ -274,6 +273,7 @@ export default {
editInfo: {}, editInfo: {},
newPassword: "", newPassword: "",
dis_newPassword: true, dis_newPassword: true,
roleInfo:[],
menuInfo: [], menuInfo: [],
}), }),
created() { created() {
@@ -313,19 +313,14 @@ export default {
}, },
init() { init() {
this.newPassword = ""; this.newPassword = "";
userApi.GetUserInRolesByHttpUser().then((resp) => { accountApi.getUserAllInfo().then((resp) => {
this.userInfo = resp.data; this.userInfo = resp.data.user;
this.userInfo.password = ""; this.userInfo.password = "";
this.editInfo = Object.assign({}, this.userInfo); this.editInfo = Object.assign({}, this.userInfo);
this.roleInfo=resp.data.roles;
this.menuInfo = resp.data.menus;
this.$store.commit('SET_USER',this.userInfo) this.$store.commit('SET_USER',this.userInfo)
}); });
menuApi.GetTopMenusByHttpUser().then((resp) => {
this.menuInfo = resp.data;
});
}, },
choiceImg() { choiceImg() {
this.$refs.imgFile.dispatchEvent(new MouseEvent("click")); this.$refs.imgFile.dispatchEvent(new MouseEvent("click"));