mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-03 00:00:58 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7f4e743e3 | ||
|
|
b934ce2893 | ||
|
|
5eec076ea2 | ||
|
|
ada36ebff5 | ||
|
|
d9543ca23c | ||
|
|
3871eb3c84 | ||
|
|
4ba696d289 | ||
|
|
2f69e0b96c | ||
|
|
d6b0c56c35 | ||
|
|
d8fe983b9d |
@@ -12,6 +12,8 @@
|
||||
### 简介:
|
||||
**中文:意框架**(和他的名字一样“简易”)
|
||||
|
||||
正在持续更进业务模块
|
||||
|
||||
**英文:YiFramework**
|
||||
|
||||
Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
|
||||
@@ -20,7 +22,7 @@ Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
|
||||
适合.Net6学习、Sqlsugar学习 、项目二次开发。
|
||||
集大成者,终究轮子
|
||||
|
||||
Yi框架最新版本标签:`v1.0.5`,具体版本可以查看标签迭代
|
||||
Yi框架最新版本标签:`v1.1.1`,具体版本可以查看标签迭代
|
||||
|
||||
(项目与Sqlsugar同步更新,但这作者老杰哥代码天天爆肝到凌晨两点,我们也尽量会跟上他的脚步。更新频繁,所以可watching持续关注。)
|
||||
|
||||
|
||||
Binary file not shown.
@@ -9,6 +9,40 @@
|
||||
账户管理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Login(Yi.Framework.DTOModel.LoginDto)">
|
||||
<summary>
|
||||
没啥说,登录
|
||||
</summary>
|
||||
<param name="loginDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Register(Yi.Framework.DTOModel.RegisterDto)">
|
||||
<summary>
|
||||
没啥说,注册
|
||||
</summary>
|
||||
<param name="registerDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.GetUserAllInfo">
|
||||
<summary>
|
||||
通过已登录的用户获取用户信息及菜单
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.UpdatePassword(Yi.Framework.DTOModel.UpdatePasswordDto)">
|
||||
<summary>
|
||||
更新登录的用户密码
|
||||
</summary>
|
||||
<param name="updatePasswordDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.UpdateUserByHttp(Yi.Framework.Model.Models.UserEntity)">
|
||||
<summary>
|
||||
更新已登录用户的用户信息
|
||||
</summary>
|
||||
<param name="user"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1">
|
||||
<summary>
|
||||
Json To Sql 类比模式,通用模型
|
||||
@@ -56,6 +90,34 @@
|
||||
<param name="ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.FileController">
|
||||
<summary>
|
||||
文件
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.FileController.#ctor(Yi.Framework.Interface.IUserService,Microsoft.Extensions.Hosting.IHostEnvironment)">
|
||||
<summary>
|
||||
使用本地存储,未进行数据库记录
|
||||
</summary>
|
||||
<param name="iUserService"></param>
|
||||
<param name="env"></param>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.FileController.Get(System.String,System.String)">
|
||||
<summary>
|
||||
文件下载
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<param name="fileName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.FileController.Upload(System.String,Microsoft.AspNetCore.Http.IFormFile)">
|
||||
<summary>
|
||||
文件上传
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<param name="file"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.LogController.Add">
|
||||
<summary>
|
||||
自动分表,日志添加
|
||||
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
@@ -22,28 +23,40 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class AccountController :ControllerBase
|
||||
public class AccountController : ControllerBase
|
||||
{
|
||||
private IUserService _iUserService;
|
||||
private IUserService _iUserService;
|
||||
private JwtInvoker _jwtInvoker;
|
||||
private ILogger _logger;
|
||||
public AccountController(ILogger<UserEntity> logger, IUserService iUserService, JwtInvoker jwtInvoker)
|
||||
{
|
||||
_iUserService = iUserService;
|
||||
_jwtInvoker = jwtInvoker;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 没啥说,登录
|
||||
/// </summary>
|
||||
/// <param name="loginDto"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
public async Task<Result> Login(LoginDto loginDto)
|
||||
{
|
||||
UserEntity user=new();
|
||||
if (await _iUserService.Login(loginDto.UserName, loginDto.Password,o=> user=o))
|
||||
UserEntity user = new();
|
||||
if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o))
|
||||
{
|
||||
return Result.Success("登录成功!").SetData(new { user, token = _jwtInvoker.GetAccessToken(user)});
|
||||
return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(user) });
|
||||
}
|
||||
return Result.SuccessError("登录失败!用户名或者密码错误!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 没啥说,注册
|
||||
/// </summary>
|
||||
/// <param name="registerDto"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
public async Task<Result> Register(RegisterDto registerDto)
|
||||
@@ -55,5 +68,63 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
}
|
||||
return Result.SuccessError("注册失败!用户名已存在!");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public Result Logout()
|
||||
{
|
||||
return Result.Success("安全登出成功!");
|
||||
}
|
||||
|
||||
/// <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));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新登录的用户密码
|
||||
/// </summary>
|
||||
/// <param name="updatePasswordDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdatePassword(UpdatePasswordDto updatePasswordDto)
|
||||
{
|
||||
var userId = HttpContext.GetCurrentUserEntityInfo(out _).Id;
|
||||
var userEntiy = await _iUserService._repository.GetByIdAsync(userId);
|
||||
|
||||
//判断输入的老密码是否和原密码相同
|
||||
if (_iUserService.JudgePassword(userEntiy, updatePasswordDto.OldPassword))
|
||||
{
|
||||
userEntiy.Password = updatePasswordDto.NewPassword;
|
||||
userEntiy.BuildPassword();
|
||||
return Result.Success().SetStatus(await _iUserService._repository.UpdateAsync(userEntiy));
|
||||
}
|
||||
return Result.SuccessError("原密码错误!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新已登录用户的用户信息
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateUserByHttp(UserEntity user)
|
||||
{
|
||||
//当然,密码是不能给他修改的
|
||||
user.Password = null;
|
||||
user.Salt = null;
|
||||
|
||||
//修改需要赋值上主键哦
|
||||
user.Id = HttpContext.GetCurrentUserEntityInfo(out _).Id;
|
||||
return Result.Success().SetStatus(await _iUserService._repository.UpdateIgnoreNullAsync(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.WebCore;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class FileController : ControllerBase
|
||||
{
|
||||
private IUserService _iUserService;
|
||||
private readonly IHostEnvironment _env;
|
||||
/// <summary>
|
||||
/// 使用本地存储,未进行数据库记录
|
||||
/// </summary>
|
||||
/// <param name="iUserService"></param>
|
||||
/// <param name="env"></param>
|
||||
public FileController(IUserService iUserService, IHostEnvironment env)
|
||||
{
|
||||
_iUserService = iUserService;
|
||||
_env = env;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
[Route("/api/{type}/{fileName}")]
|
||||
[HttpGet]
|
||||
public IActionResult Get(string type, string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = Path.Combine($"wwwroot/{type}", fileName);
|
||||
var stream = System.IO.File.OpenRead(path);
|
||||
var MimeType = Common.Helper.MimeHelper.GetMimeMapping(fileName);
|
||||
return new FileStreamResult(stream, MimeType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件上传
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
[Route("/api/Upload/{type}")]
|
||||
[HttpPost]
|
||||
public async Task<Result> Upload(string type, IFormFile file)
|
||||
{
|
||||
try
|
||||
{
|
||||
string filename = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
|
||||
using (var stream = new FileStream(Path.Combine($"wwwroot/{type}", filename), FileMode.CreateNew, FileAccess.Write))
|
||||
{
|
||||
await file.CopyToAsync(stream);
|
||||
}
|
||||
return Result.Success().SetData(filename);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Result.Error();
|
||||
}
|
||||
}
|
||||
|
||||
//[HttpGet]
|
||||
//public async Task<IActionResult> ExportFile()
|
||||
//{
|
||||
// var userdata = await _userService.GetAllEntitiesTrueAsync();
|
||||
// var userList = userdata.ToList();
|
||||
// List<string> header = new() { "用户", "密码", "头像", "昵称", "邮箱", "ip", "年龄", "个人介绍", "地址", "手机", "角色" };
|
||||
// var filename = Common.Helper.ExcelHelper.CreateExcelFromList(userList, header, _env.ContentRootPath.ToString());
|
||||
// var MimeType = Common.Helper.MimeHelper.GetMimeMapping(filename);
|
||||
// return new FileStreamResult(new FileStream(Path.Combine(_env.ContentRootPath+@"/wwwroot/excel", filename), FileMode.Open),MimeType);
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@
|
||||
"PolicyName": "permission",
|
||||
"DefaultScheme": "Bearer",
|
||||
"IsHttps": false,
|
||||
"Expiration": 30,
|
||||
"Expiration": 300,
|
||||
"ReExpiration": 3000
|
||||
},
|
||||
"RedisConnOptions": {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
@@ -36,6 +36,14 @@ namespace Yi.Framework.Common.Models
|
||||
}
|
||||
public Result SetStatus(bool _status)
|
||||
{
|
||||
if (_status)
|
||||
{
|
||||
this.message = "操作成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.message = "操作失败";
|
||||
}
|
||||
this.status = _status;
|
||||
return this;
|
||||
}
|
||||
|
||||
14
Yi.Framework.Net6/Yi.Framework.DTOModel/UpdatePasswordDto.cs
Normal file
14
Yi.Framework.Net6/Yi.Framework.DTOModel/UpdatePasswordDto.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class UpdatePasswordDto
|
||||
{
|
||||
public string NewPassword { get; set; }
|
||||
public string OldPassword { get; set; }
|
||||
}
|
||||
}
|
||||
17
Yi.Framework.Net6/Yi.Framework.DTOModel/UserRoleMenuDto.cs
Normal file
17
Yi.Framework.Net6/Yi.Framework.DTOModel/UserRoleMenuDto.cs
Normal 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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
@@ -59,5 +60,20 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<RoleEntity>> GetRoleListByUserId(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前登录用户的所有信息
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<UserRoleMenuDto> GetUserAllInfo(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 判断用户密码是否和原密码相同
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
bool JudgePassword(UserEntity user, string password);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,7 @@ namespace Yi.Framework.Model.Models
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonConverter(typeof(ValueToStringConverter))]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
@@ -80,7 +78,7 @@ namespace Yi.Framework.Model.Models
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Icon" )]
|
||||
public long? Icon { get; set; }
|
||||
public string Icon { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
@@ -106,5 +104,10 @@ namespace Yi.Framework.Model.Models
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Phone" )]
|
||||
public string Phone { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Introduction" )]
|
||||
public string Introduction { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
@@ -102,5 +104,44 @@ namespace Yi.Framework.Service
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
public bool JudgePassword(UserEntity user,string password)
|
||||
{
|
||||
if (user.Password == MD5Helper.SHA2Encode(password, user.Salt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
|
||||
namespace Yi.Framework.WebCore
|
||||
{
|
||||
@@ -32,17 +33,22 @@ namespace Yi.Framework.WebCore
|
||||
/// <returns></returns>
|
||||
public static UserEntity GetCurrentUserEntityInfo(this HttpContext httpContext, out List<Guid> menuIds)
|
||||
{
|
||||
IEnumerable<Claim> claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims;
|
||||
|
||||
long.TryParse(claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Sid).Value,out var resId) ;
|
||||
|
||||
IEnumerable<Claim> claimlist = null;
|
||||
long resId = 0;
|
||||
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();
|
||||
|
||||
|
||||
return new UserEntity()
|
||||
{
|
||||
Id = resId,
|
||||
Name = claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Name).Value
|
||||
//Name = claimlist.FirstOrDefault(u => u.Type == JwtRegisteredClaimNames.Name).Value
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +35,27 @@ export default {
|
||||
method: 'post',
|
||||
})
|
||||
},
|
||||
changePassword(user, newPassword) {
|
||||
updatePassword(oldPassword, newPassword) {
|
||||
return myaxios({
|
||||
url: `/Account/changePassword`,
|
||||
url: `/Account/updatePassword`,
|
||||
method: 'put',
|
||||
data: { user, newPassword }
|
||||
data: { oldPassword, newPassword }
|
||||
})
|
||||
},
|
||||
getUserAllInfo()
|
||||
{
|
||||
return myaxios({
|
||||
url: `/Account/getUserAllInfo`,
|
||||
method: 'get'
|
||||
})
|
||||
},
|
||||
updateUserByHttp(user)
|
||||
{
|
||||
return myaxios({
|
||||
url: `/Account/updateUserByHttp`,
|
||||
method: 'put',
|
||||
data:user
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import myaxios from '@/util/myaxios'
|
||||
export default {
|
||||
EditIcon(file) {
|
||||
UploadImage(file) {
|
||||
return myaxios({
|
||||
url: '/File/EditIcon',
|
||||
url: '/Upload/image',
|
||||
method: 'post',
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
data: file
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<v-list :tile="false" flat nav>
|
||||
<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 to="/"
|
||||
><v-list-item-title v-text="'称号:'+$store.state.user.user.nick"
|
||||
@@ -27,7 +27,7 @@
|
||||
<template v-for="(p, i) in profile">
|
||||
<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" />
|
||||
</app-bar-item>
|
||||
</template>
|
||||
@@ -40,10 +40,10 @@ export default {
|
||||
name: "DefaultAccount",
|
||||
data: () => ({
|
||||
profile: [
|
||||
{ title: "用户信息" },
|
||||
{ title: "用户信息",router:"/userInfo" },
|
||||
{ title: "设置" },
|
||||
{ divider: true },
|
||||
{ title: "登出" },
|
||||
{ title: "登出",router:"/login" },
|
||||
],
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { getToken, setToken, getUser, setUser, removeToken } from '../../util/usertoken'
|
||||
import { getPer, setPer, getToken, setToken, getUser, setUser, removeToken } from '../../util/usertoken'
|
||||
import accountApi from "@/api/accountApi"
|
||||
|
||||
//再导入axion请求
|
||||
const state = { //状态
|
||||
per: getPer(),
|
||||
token: getToken(),
|
||||
user: getUser(),
|
||||
dark: false,
|
||||
@@ -20,19 +21,24 @@ const state = { //状态
|
||||
'https://s1.ax1x.com/2022/03/26/qdNnbD.jpg',
|
||||
'https://s1.ax1x.com/2022/03/26/qdNMUH.jpg',
|
||||
'https://s1.ax1x.com/2022/03/26/qdNKVe.jpg',
|
||||
'https://s1.ax1x.com/2022/03/26/qdNmDO.jpg'
|
||||
'https://s1.ax1x.com/2022/03/26/qdNmDO.jpg'
|
||||
],
|
||||
notifications: [],
|
||||
rtl: false
|
||||
}
|
||||
|
||||
const mutations = { //变化//载荷
|
||||
SET_PER(state, per) {
|
||||
state.per = per
|
||||
setPer(per)
|
||||
},
|
||||
SET_TOKEN(state, token) {
|
||||
state.token = token
|
||||
setToken(token)
|
||||
},
|
||||
SET_USER(state, user) {
|
||||
state.user = user
|
||||
console.log(user)
|
||||
setUser(user)
|
||||
},
|
||||
SetGradient(state, gradient) {
|
||||
@@ -45,7 +51,7 @@ const mutations = { //变化//载荷
|
||||
|
||||
//在action中可以配合axios进行权限判断
|
||||
const actions = { //动作
|
||||
setIcon({ commit, state }, icon) {
|
||||
SetIcon({ commit, state }, icon) {
|
||||
state.user.icon = icon
|
||||
commit('SET_USER', state.user)
|
||||
},
|
||||
@@ -78,9 +84,22 @@ const actions = { //动作
|
||||
accountApi.login(form.username.trim(), form.password.trim()).then(resp => {
|
||||
if (resp.status) {
|
||||
commit('SET_TOKEN', resp.data.token)
|
||||
commit('SET_USER', resp.data.user)
|
||||
|
||||
|
||||
accountApi.getUserAllInfo().then(resp2=>{
|
||||
commit('SET_USER', resp2.data.user)
|
||||
|
||||
var code=[];
|
||||
resp2.data.menus.forEach(element => {
|
||||
code.push(element.permissionCode)
|
||||
});
|
||||
commit('SET_PER', code)
|
||||
resolv(resp)
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
resolv(resp)
|
||||
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
const TOKEN_KEY = "token_key"
|
||||
const USER_KEY = "user_key"
|
||||
const PER_KEY="per_key"
|
||||
export function getToken() {
|
||||
return localStorage.getItem(TOKEN_KEY)
|
||||
}
|
||||
export function setToken(token) {
|
||||
return localStorage.setItem(TOKEN_KEY, token)
|
||||
}
|
||||
export function getUser() {
|
||||
return JSON.parse(localStorage.getItem(USER_KEY))
|
||||
}
|
||||
export function getPer() {
|
||||
return JSON.parse(localStorage.getItem(PER_KEY))
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function setToken(token) {
|
||||
return localStorage.setItem(TOKEN_KEY, token)
|
||||
}
|
||||
|
||||
export function setUser(user) {
|
||||
return localStorage.setItem(USER_KEY, JSON.stringify(user))
|
||||
}
|
||||
export function setPer(per) {
|
||||
return localStorage.setItem(PER_KEY, JSON.stringify(per))
|
||||
}
|
||||
export function removeToken() {
|
||||
localStorage.removeItem(TOKEN_KEY)
|
||||
localStorage.removeItem(USER_KEY)
|
||||
localStorage.removeItem(PER_KEY)
|
||||
}
|
||||
@@ -48,7 +48,7 @@
|
||||
item-text="menuName"
|
||||
>
|
||||
<template v-slot:append="{ item }">
|
||||
<v-btn>id:{{ item.id }}</v-btn>
|
||||
<v-btn>权限:{{ item.permissionCode }}</v-btn>
|
||||
</template>
|
||||
</v-treeview>
|
||||
</v-card></v-col
|
||||
|
||||
@@ -59,6 +59,9 @@ export default {
|
||||
});
|
||||
},
|
||||
init() {
|
||||
|
||||
//这里可以遍历后台的菜单code,根据对应的菜单code来给axiosUrls的增删改查赋值即可
|
||||
|
||||
this.axiosUrls = {
|
||||
get: "/user/GetList",
|
||||
update: "/user/Update",
|
||||
|
||||
@@ -133,7 +133,7 @@ export default {
|
||||
};
|
||||
},
|
||||
login() {
|
||||
this.loader = "true";
|
||||
this.loader = true;
|
||||
this.btn_dis=true;
|
||||
this.$store.dispatch("Login", this.form).then((resp) => {
|
||||
if (resp.status) {
|
||||
|
||||
@@ -3,23 +3,32 @@
|
||||
<v-row justify="center">
|
||||
<v-col cols="12" md="4">
|
||||
<app-card class="mt-4 text-center">
|
||||
<ccAvatar :size="128" class="rounded-circle elevation-6 mt-n12 d-inline-block"></ccAvatar>
|
||||
<ccAvatar
|
||||
:size="128"
|
||||
class="rounded-circle elevation-6 mt-n12 d-inline-block"
|
||||
></ccAvatar>
|
||||
|
||||
<v-card-text class="text-center">
|
||||
<h6 class="text-h6 mb-2 text--secondary">
|
||||
{{ userInfo.username }}
|
||||
{{ userInfo.userName }}
|
||||
</h6>
|
||||
|
||||
<h4 class="text-h4 mb-3 text--primary">{{ userInfo.nick }}</h4>
|
||||
|
||||
<p class="text--secondary">{{ userInfo.introduction }}</p>
|
||||
<input
|
||||
type="file"
|
||||
ref="imgFile"
|
||||
@change="uploadImage()"
|
||||
class="d-none"
|
||||
/>
|
||||
<v-btn class="mr-4" @click="choiceImg" color="primary" min-width="100" rounded>
|
||||
<input
|
||||
type="file"
|
||||
ref="imgFile"
|
||||
@change="uploadImage()"
|
||||
class="d-none"
|
||||
/>
|
||||
<v-btn
|
||||
class="mr-4"
|
||||
@click="choiceImg"
|
||||
color="primary"
|
||||
min-width="100"
|
||||
rounded
|
||||
>
|
||||
编辑头像
|
||||
</v-btn>
|
||||
<v-btn color="primary" min-width="100" rounded> 绑定QQ </v-btn>
|
||||
@@ -61,7 +70,7 @@
|
||||
<v-text-field
|
||||
color="purple"
|
||||
label="用户名"
|
||||
v-model="editInfo.username"
|
||||
v-model="editInfo.userName"
|
||||
disabled
|
||||
/>
|
||||
</v-col>
|
||||
@@ -154,12 +163,12 @@
|
||||
<v-list-item-subtitle>
|
||||
<v-row>
|
||||
<v-col
|
||||
v-for="item in editInfo.roles"
|
||||
v-for="item in roleInfo"
|
||||
:key="item.id"
|
||||
cols="6"
|
||||
sm="3"
|
||||
md="1"
|
||||
>{{ item.role_name }}</v-col
|
||||
>{{ item.roleName }}</v-col
|
||||
>
|
||||
</v-row>
|
||||
</v-list-item-subtitle>
|
||||
@@ -178,7 +187,7 @@
|
||||
cols="6"
|
||||
sm="3"
|
||||
md="1"
|
||||
>{{ item.menu_name }}</v-col
|
||||
>{{ item.menuName }}</v-col
|
||||
>
|
||||
</v-row>
|
||||
</v-list-item-subtitle>
|
||||
@@ -230,7 +239,7 @@
|
||||
<v-text-field
|
||||
style="width: 80%"
|
||||
label="原密码"
|
||||
v-model="editInfo.password"
|
||||
v-model="oldPassword"
|
||||
outlined
|
||||
clearable
|
||||
></v-text-field>
|
||||
@@ -263,8 +272,6 @@
|
||||
|
||||
<script>
|
||||
import fileApi from "../api/fileApi";
|
||||
import userApi from "../api/userApi";
|
||||
import menuApi from "../api/menuApi";
|
||||
import accountApi from "../api/accountApi";
|
||||
export default {
|
||||
name: "UserProfileView",
|
||||
@@ -273,16 +280,18 @@ export default {
|
||||
userInfo: {},
|
||||
editInfo: {},
|
||||
newPassword: "",
|
||||
oldPassword: "",
|
||||
dis_newPassword: true,
|
||||
roleInfo: [],
|
||||
menuInfo: [],
|
||||
}),
|
||||
created() {
|
||||
this.init();
|
||||
},
|
||||
watch: {
|
||||
editInfo: {
|
||||
oldPassword: {
|
||||
handler(val, oldVal) {
|
||||
if (val.password.length > 0) {
|
||||
if (val != "") {
|
||||
this.dis_newPassword = false;
|
||||
} else {
|
||||
this.dis_newPassword = true;
|
||||
@@ -294,55 +303,60 @@ export default {
|
||||
|
||||
methods: {
|
||||
save() {
|
||||
accountApi
|
||||
.changePassword(this.editInfo, this.newPassword)
|
||||
.then((resp) => {
|
||||
if (resp.status) {
|
||||
this.$dialog.notify.error(resp.msg, {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
} else {
|
||||
this.$dialog.notify.success(resp.msg, {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
}
|
||||
if (this.newPassword != "") {
|
||||
accountApi
|
||||
.updatePassword(this.oldPassword, this.newPassword)
|
||||
.then((resp) => {
|
||||
if (resp.status) {
|
||||
this.$dialog.notify.success(resp.message, {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
} else {
|
||||
this.$dialog.notify.error(resp.message, {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
}
|
||||
this.init();
|
||||
});
|
||||
} else {
|
||||
accountApi.updateUserByHttp(this.editInfo).then((resp) => {
|
||||
this.init();
|
||||
});
|
||||
}
|
||||
},
|
||||
init() {
|
||||
this.newPassword = "";
|
||||
userApi.GetUserInRolesByHttpUser().then((resp) => {
|
||||
this.userInfo = resp.data;
|
||||
this.oldPassword = "";
|
||||
accountApi.getUserAllInfo().then((resp) => {
|
||||
this.userInfo = resp.data.user;
|
||||
this.userInfo.password = "";
|
||||
this.editInfo = Object.assign({}, this.userInfo);
|
||||
this.$store.commit('SET_USER',this.userInfo)
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
menuApi.GetTopMenusByHttpUser().then((resp) => {
|
||||
this.menuInfo = resp.data;
|
||||
this.roleInfo = resp.data.roles;
|
||||
this.menuInfo = resp.data.menus;
|
||||
this.$store.commit("SET_USER", this.userInfo);
|
||||
});
|
||||
},
|
||||
choiceImg() {
|
||||
choiceImg() {
|
||||
this.$refs.imgFile.dispatchEvent(new MouseEvent("click"));
|
||||
},
|
||||
uploadImage() {
|
||||
//修改头像,需要先上传头像,修改editInfo的头像信息即可
|
||||
const file = this.$refs.imgFile.files[0];
|
||||
let formData = new FormData();
|
||||
formData.append("file", file);
|
||||
fileApi.EditIcon(formData).then(resp=>{
|
||||
this.init();
|
||||
this.$dialog.notify.success(resp.msg, {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
fileApi.UploadImage(formData).then((resp) => {
|
||||
this.editInfo.icon=resp.data
|
||||
this.$dialog.notify.success("头像加载成功,点击保存以设置", {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
this.$store.dispatch("SetIcon", this.editInfo.icon)
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user