mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-03 00:00:58 +08:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa1d68848f | ||
|
|
bce955a1e1 | ||
|
|
82f70e0ac9 | ||
|
|
fc9b78cfef | ||
|
|
72400a48da | ||
|
|
537b39b3c4 | ||
|
|
47e6e48729 | ||
|
|
d252229777 | ||
|
|
7f4c7f607d | ||
|
|
994ba5dd1a | ||
|
|
e3a06b28dd | ||
|
|
10d512470e | ||
|
|
c1d8040fd5 | ||
|
|
e4b81da386 | ||
|
|
fd7360e6f4 | ||
|
|
62f15e218e | ||
|
|
5c1b91f348 | ||
|
|
378cbd580f | ||
|
|
3994f14010 | ||
|
|
e7f4e743e3 | ||
|
|
b934ce2893 | ||
|
|
5eec076ea2 | ||
|
|
ada36ebff5 | ||
|
|
d9543ca23c | ||
|
|
3871eb3c84 | ||
|
|
4ba696d289 | ||
|
|
2f69e0b96c | ||
|
|
d6b0c56c35 | ||
|
|
d8fe983b9d | ||
|
|
76079faca0 | ||
|
|
5d5c62123c | ||
|
|
6c7b2224b1 |
@@ -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.1.5`,具体版本可以查看标签迭代
|
||||||
|
|
||||||
(项目与Sqlsugar同步更新,但这作者老杰哥代码天天爆肝到凌晨两点,我们也尽量会跟上他的脚步。更新频繁,所以可watching持续关注。)
|
(项目与Sqlsugar同步更新,但这作者老杰哥代码天天爆肝到凌晨两点,我们也尽量会跟上他的脚步。更新频繁,所以可watching持续关注。)
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -9,6 +9,40 @@
|
|||||||
账户管理
|
账户管理
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</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">
|
<member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1">
|
||||||
<summary>
|
<summary>
|
||||||
Json To Sql 类比模式,通用模型
|
Json To Sql 类比模式,通用模型
|
||||||
@@ -56,6 +90,34 @@
|
|||||||
<param name="ids"></param>
|
<param name="ids"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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">
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.LogController.Add">
|
||||||
<summary>
|
<summary>
|
||||||
自动分表,日志添加
|
自动分表,日志添加
|
||||||
@@ -91,6 +153,12 @@
|
|||||||
<param name="giveRoleSetMenuDto"></param>
|
<param name="giveRoleSetMenuDto"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.GetInMenuByRoleId(System.Int64)">
|
||||||
|
<summary>
|
||||||
|
通过角色id来获取菜单列表
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.TestController">
|
<member name="T:Yi.Framework.ApiMicroservice.Controllers.TestController">
|
||||||
<summary>
|
<summary>
|
||||||
测试控制器
|
测试控制器
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Common.Helper;
|
||||||
using Yi.Framework.Common.Models;
|
using Yi.Framework.Common.Models;
|
||||||
using Yi.Framework.Core;
|
using Yi.Framework.Core;
|
||||||
using Yi.Framework.DTOModel;
|
using Yi.Framework.DTOModel;
|
||||||
@@ -22,28 +23,41 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]/[action]")]
|
[Route("api/[controller]/[action]")]
|
||||||
public class AccountController :ControllerBase
|
public class AccountController : ControllerBase
|
||||||
{
|
{
|
||||||
private IUserService _iUserService;
|
private IUserService _iUserService;
|
||||||
private JwtInvoker _jwtInvoker;
|
private JwtInvoker _jwtInvoker;
|
||||||
|
private ILogger _logger;
|
||||||
public AccountController(ILogger<UserEntity> logger, IUserService iUserService, JwtInvoker jwtInvoker)
|
public AccountController(ILogger<UserEntity> logger, IUserService iUserService, JwtInvoker jwtInvoker)
|
||||||
{
|
{
|
||||||
_iUserService = iUserService;
|
_iUserService = iUserService;
|
||||||
_jwtInvoker = jwtInvoker;
|
_jwtInvoker = jwtInvoker;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 没啥说,登录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="loginDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<Result> Login(LoginDto loginDto)
|
public async Task<Result> Login(LoginDto loginDto)
|
||||||
{
|
{
|
||||||
UserEntity user=new();
|
UserEntity user = new();
|
||||||
if (await _iUserService.Login(loginDto.UserName, loginDto.Password,o=> user=o))
|
if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o))
|
||||||
{
|
{
|
||||||
return Result.Success("登录成功!").SetData(new { user, 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("登录失败!用户名或者密码错误!");
|
return Result.SuccessError("登录失败!用户名或者密码错误!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 没啥说,注册
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="registerDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<Result> Register(RegisterDto registerDto)
|
public async Task<Result> Register(RegisterDto registerDto)
|
||||||
@@ -55,5 +69,64 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
}
|
}
|
||||||
return Result.SuccessError("注册失败!用户名已存在!");
|
return Result.SuccessError("注册失败!用户名已存在!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public Result Logout()
|
||||||
|
{
|
||||||
|
return Result.Success("安全登出成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通过已登录的用户获取用户信息及菜单
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize]
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[Permission($"{nameof(T)}:get:one")]
|
[Permission($"{nameof(T)}:get")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public virtual async Task<Result> GetById(long id)
|
public virtual async Task<Result> GetById(long id)
|
||||||
{
|
{
|
||||||
@@ -43,7 +43,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// 列表查询
|
/// 列表查询
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[Permission($"{nameof(T)}:get:list")]
|
[Permission($"{nameof(T)}:get")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public virtual async Task<Result> GetList(QueryCondition queryCondition)
|
public virtual async Task<Result> GetList(QueryCondition queryCondition)
|
||||||
{
|
{
|
||||||
@@ -55,7 +55,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="queryCondition"></param>
|
/// <param name="queryCondition"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[Permission($"{nameof(T)}:get:page")]
|
[Permission($"{nameof(T)}:get")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public virtual async Task<Result> PageList(QueryPageCondition queryCondition)
|
public virtual async Task<Result> PageList(QueryPageCondition queryCondition)
|
||||||
{
|
{
|
||||||
@@ -91,7 +91,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ids"></param>
|
/// <param name="ids"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[Permission($"{nameof(T)}:delete:list")]
|
[Permission($"{nameof(T)}:del")]
|
||||||
[HttpDelete]
|
[HttpDelete]
|
||||||
public virtual async Task<Result> DeleteList(List<long> ids)
|
public virtual async Task<Result> DeleteList(List<long> ids)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
_iMenuService = iMenuService;
|
_iMenuService = iMenuService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 得到树形菜单
|
/// 得到树形菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
return Result.Success().SetStatus(await _iRoleService.GiveRoleSetMenu(giveRoleSetMenuDto.RoleIds, giveRoleSetMenuDto.MenuIds));
|
return Result.Success().SetStatus(await _iRoleService.GiveRoleSetMenu(giveRoleSetMenuDto.RoleIds, giveRoleSetMenuDto.MenuIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通过角色id来获取菜单列表
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<Result> GetInMenuByRoleId(long RoleId)
|
||||||
|
{
|
||||||
|
return Result.Success().SetData(await _iRoleService.GetInMenuByRoleId(RoleId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
// 特点:化繁为简!意框架仓储代理上下文对象,用起来就是爽,但最好按规范来爽!
|
// 特点:化繁为简!意框架仓储代理上下文对象,用起来就是爽,但最好按规范来爽!
|
||||||
// 规范:控制器不建议使用切换仓储方法、控制器严禁使用DB上下文对象,其它怎么爽怎么来!
|
// 规范:控制器严禁使用DB上下文对象,其它怎么爽怎么来!
|
||||||
public async Task<Result> DbTest()
|
public async Task<Result> DbTest()
|
||||||
{
|
{
|
||||||
//非常好,使用UserService的特有方法
|
//非常好,使用UserService的特有方法
|
||||||
@@ -60,10 +60,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
//挺不错,依赖注入其他仓储
|
//挺不错,依赖注入其他仓储
|
||||||
await _iRoleService._repository.GetListAsync();
|
await _iRoleService._repository.GetListAsync();
|
||||||
|
|
||||||
//不建议操作,直接切换其他仓储
|
//还行,直接切换其他仓储,怎么爽怎么来
|
||||||
await _iUserService._repository.ChangeRepository<Repository<RoleEntity>>().GetListAsync();
|
await _iUserService._repository.ChangeRepository<Repository<RoleEntity>>().GetListAsync();
|
||||||
|
|
||||||
//直接操作Db对象???恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。
|
//最好不要直接操作Db对象
|
||||||
await _iUserService._repository._Db.Queryable<UserEntity>().ToListAsync();
|
await _iUserService._repository._Db.Queryable<UserEntity>().ToListAsync();
|
||||||
|
|
||||||
return Result.Success().SetData(await _iUserService.DbTest());
|
return Result.Success().SetData(await _iUserService.DbTest());
|
||||||
@@ -74,7 +74,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
//简单语句不推荐!
|
//简单语句不推荐使用sql!
|
||||||
public async Task<Result> SqlTest()
|
public async Task<Result> SqlTest()
|
||||||
{
|
{
|
||||||
return Result.Success().SetData(await _iUserService._repository.UseSqlAsync<UserEntity>("select * from User"));
|
return Result.Success().SetData(await _iUserService._repository.UseSqlAsync<UserEntity>("select * from User"));
|
||||||
|
|||||||
@@ -20,6 +20,16 @@
|
|||||||
<None Remove="wwwrooot\**" />
|
<None Remove="wwwrooot\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="yi-sqlsugar-dev.db" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="yi-sqlsugar-dev.db">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
|
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
|
||||||
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />
|
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"StartUrl": "http://localohost:19001",
|
"StartUrl": "http://*:19001",
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"StartUrl": "http://localohost:19001",
|
"StartUrl": "http://*:19001",
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
"PolicyName": "permission",
|
"PolicyName": "permission",
|
||||||
"DefaultScheme": "Bearer",
|
"DefaultScheme": "Bearer",
|
||||||
"IsHttps": false,
|
"IsHttps": false,
|
||||||
"Expiration": 30,
|
"Expiration": 300,
|
||||||
"ReExpiration": 3000
|
"ReExpiration": 3000
|
||||||
},
|
},
|
||||||
"RedisConnOptions": {
|
"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)
|
public Result SetStatus(bool _status)
|
||||||
{
|
{
|
||||||
|
if (_status)
|
||||||
|
{
|
||||||
|
this.message = "操作成功";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.message = "操作失败";
|
||||||
|
}
|
||||||
this.status = _status;
|
this.status = _status;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,15 +23,15 @@ namespace Yi.Framework.Core
|
|||||||
}
|
}
|
||||||
public string GetRefreshToken(UserEntity user)
|
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>();
|
List<Claim> claims = new List<Claim>();
|
||||||
claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"));
|
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()));
|
claims.Add(new Claim(JwtRegisteredClaimNames.Sid, user.Id.ToString()));
|
||||||
|
|
||||||
//-----------------------------以下从user的权限表中添加权限-----------------------例如:
|
//-----------------------------以下从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.ToString()));
|
||||||
|
}
|
||||||
|
|
||||||
if (isRefresh)
|
if (isRefresh)
|
||||||
{
|
{
|
||||||
|
|||||||
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,13 @@ namespace Yi.Framework.Interface
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<List<RoleEntity>> DbTest();
|
Task<List<RoleEntity>> DbTest();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通过角色id获取角色实体包含菜单
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<RoleEntity> GetInMenuByRoleId(long roleId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 给角色设置菜单,多角色,多菜单
|
/// 给角色设置菜单,多角色,多菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -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,20 @@ 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);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断用户密码是否和原密码相同
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool JudgePassword(UserEntity user, string password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Yi.Framework.Model.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName= "PermissionCode")]
|
[SugarColumn(ColumnName="PermissionCode" )]
|
||||||
public string PermissionCode { get; set; }
|
public string PermissionCode { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@@ -69,5 +69,15 @@ namespace Yi.Framework.Model.Models
|
|||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName="TenantId" )]
|
[SugarColumn(ColumnName="TenantId" )]
|
||||||
public long? TenantId { get; set; }
|
public long? TenantId { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnName="MenuIcon" )]
|
||||||
|
public string MenuIcon { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnName="Router" )]
|
||||||
|
public string Router { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,5 +54,10 @@ namespace Yi.Framework.Model.Models
|
|||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName="ModifyUser" )]
|
[SugarColumn(ColumnName="ModifyUser" )]
|
||||||
public long? ModifyUser { get; set; }
|
public long? ModifyUser { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnName="RoleCode" )]
|
||||||
|
public string RoleCode { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -80,7 +78,7 @@ namespace Yi.Framework.Model.Models
|
|||||||
///
|
///
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName="Icon" )]
|
[SugarColumn(ColumnName="Icon" )]
|
||||||
public long? Icon { get; set; }
|
public string Icon { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
///</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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,5 +10,7 @@ namespace Yi.Framework.Model.Models
|
|||||||
{
|
{
|
||||||
//[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.RoleId), nameof(UserRoleEntity.UserId))]
|
//[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.RoleId), nameof(UserRoleEntity.UserId))]
|
||||||
//public List<UserEntity> Users { get; set; }
|
//public List<UserEntity> Users { get; set; }
|
||||||
|
[Navigate(typeof(RoleMenuEntity),nameof(RoleMenuEntity.RoleId),nameof(RoleMenuEntity.MenuId))]
|
||||||
|
public List<MenuEntity> Menus { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="NEST" Version="7.16.0" />
|
<PackageReference Include="NEST" Version="7.16.0" />
|
||||||
<PackageReference Include="SqlSugarCore" Version="5.0.7.5" />
|
<PackageReference Include="SqlSugarCore" Version="5.0.7.8" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
using SqlSugar;
|
//using SqlSugar;
|
||||||
using Yi.Framework.Common.Models;
|
//using Yi.Framework.Common.Models;
|
||||||
using Yi.Framework.Model.Models;
|
//using Yi.Framework.Model.Models;
|
||||||
|
|
||||||
namespace Yi.Framework.Repository
|
//namespace Yi.Framework.Repository
|
||||||
{
|
//{
|
||||||
public class DataContext<T> : SimpleClient<T> where T : class, IBaseModelEntity, new()
|
// public class DataContext<T> : SimpleClient<T> where T : class, IBaseModelEntity, new()
|
||||||
{
|
// {
|
||||||
public DataContext(ISqlSugarClient context) : base(context)
|
// public DataContext(ISqlSugarClient context) : base(context)
|
||||||
{
|
// {
|
||||||
Db =base.Context;
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
public ISqlSugarClient Db;
|
// }
|
||||||
}
|
//}
|
||||||
}
|
//简化已被弃用
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ namespace Yi.Framework.Repository
|
|||||||
public Task<List<T>> GetListAsync(QueryCondition pars);
|
public Task<List<T>> GetListAsync(QueryCondition pars);
|
||||||
public Task<bool> DeleteByLogicAsync(List<long> ids);
|
public Task<bool> DeleteByLogicAsync(List<long> ids);
|
||||||
public Task<bool> UpdateIgnoreNullAsync(T entity);
|
public Task<bool> UpdateIgnoreNullAsync(T entity);
|
||||||
public Task<List<S>> UseSqlAsync<S>(string sql);
|
public Task<List<S>> UseSqlAsync<S>(string sql, object parameters = null);
|
||||||
public Task<bool> UseSqlAsync(string sql);
|
public Task<bool> UseSqlAsync(string sql, object parameters = null);
|
||||||
ISugarQueryable<T> QueryConditionHandler(QueryCondition pars);
|
ISugarQueryable<T> QueryConditionHandler(QueryCondition pars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,15 @@ namespace Yi.Framework.Repository
|
|||||||
/// 仓储模式
|
/// 仓储模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public class Repository<T> : DataContext<T>, IRepository<T> where T : class, IBaseModelEntity, new()
|
public class Repository<T> : SimpleClient<T>, IRepository<T> where T : class, IBaseModelEntity, new()
|
||||||
{
|
{
|
||||||
public ISqlSugarClient _Db { get; set; }
|
public ISqlSugarClient _Db { get { return base.Context; } set { } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null
|
public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null
|
||||||
{
|
{
|
||||||
_Db = context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -31,7 +30,8 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> UseTranAsync(Func<Task> func)
|
public async Task<bool> UseTranAsync(Func<Task> func)
|
||||||
{
|
{
|
||||||
var res = await Db.AsTenant().UseTranAsync(func);
|
var con = Context;
|
||||||
|
var res = await _Db.AsTenant().UseTranAsync(func);
|
||||||
return res.IsSuccess;
|
return res.IsSuccess;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -42,24 +42,21 @@ namespace Yi.Framework.Repository
|
|||||||
/// <typeparam name="S"></typeparam>
|
/// <typeparam name="S"></typeparam>
|
||||||
/// <param name="sql"></param>
|
/// <param name="sql"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<S>> UseSqlAsync<S>(string sql)
|
public async Task<List<S>> UseSqlAsync<S>(string sql, object parameters = null)
|
||||||
{
|
{
|
||||||
return await Db.Ado.SqlQueryAsync<S>(sql);
|
return await _Db.Ado.SqlQueryAsync<S>(sql, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 执行增删改sql返回状态
|
/// 执行增删改sql返回状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sql"></param>
|
/// <param name="sql"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> UseSqlAsync(string sql)
|
public async Task<bool> UseSqlAsync(string sql, object parameters)
|
||||||
{
|
{
|
||||||
return await Db.Ado.ExecuteCommandAsync(sql)>0;
|
return await _Db.Ado.ExecuteCommandAsync(sql, parameters) >0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 添加返回实体
|
/// 添加返回实体
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -68,7 +65,7 @@ namespace Yi.Framework.Repository
|
|||||||
public async Task<T> InsertReturnEntityAsync(T entity)
|
public async Task<T> InsertReturnEntityAsync(T entity)
|
||||||
{
|
{
|
||||||
entity.Id =SnowFlakeSingle.instance.getID();
|
entity.Id =SnowFlakeSingle.instance.getID();
|
||||||
return await Db.Insertable(entity).ExecuteReturnEntityAsync();
|
return await _Db.Insertable(entity).ExecuteReturnEntityAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -78,7 +75,7 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> UpdateIgnoreNullAsync(T entity)
|
public async Task<bool> UpdateIgnoreNullAsync(T entity)
|
||||||
{
|
{
|
||||||
return await Db.Updateable(entity).IgnoreColumns(true).ExecuteCommandAsync()>0;
|
return await _Db.Updateable(entity).IgnoreColumns(true).ExecuteCommandAsync()>0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -88,9 +85,9 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> DeleteByLogicAsync(List<long> ids)
|
public async Task<bool> DeleteByLogicAsync(List<long> ids)
|
||||||
{
|
{
|
||||||
var entitys = await Db.Queryable<T>().Where(u => ids.Contains(u.Id)).ToListAsync();
|
var entitys = await _Db.Queryable<T>().Where(u => ids.Contains(u.Id)).ToListAsync();
|
||||||
entitys.ForEach(u=>u.IsDeleted=true);
|
entitys.ForEach(u=>u.IsDeleted=true);
|
||||||
return await Db.Updateable(entitys).ExecuteCommandAsync()>0;
|
return await _Db.Updateable(entitys).ExecuteCommandAsync()>0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +100,7 @@ namespace Yi.Framework.Repository
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<S>> StoreAsync<S>(string storeName, object para)
|
public async Task<List<S>> StoreAsync<S>(string storeName, object para)
|
||||||
{
|
{
|
||||||
return await Db.Ado.UseStoredProcedure().SqlQueryAsync<S>(storeName, para);
|
return await _Db.Ado.UseStoredProcedure().SqlQueryAsync<S>(storeName, para);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -142,7 +139,7 @@ namespace Yi.Framework.Repository
|
|||||||
FieldName = it.Key,
|
FieldName = it.Key,
|
||||||
FieldValue = it.Value
|
FieldValue = it.Value
|
||||||
}).ToList();
|
}).ToList();
|
||||||
var query = Db.Queryable<T>();
|
var query = _Db.Queryable<T>();
|
||||||
if (pars.OrderBys != null)
|
if (pars.OrderBys != null)
|
||||||
{
|
{
|
||||||
foreach (var item in pars.OrderBys)
|
foreach (var item in pars.OrderBys)
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ namespace Yi.Framework.Service
|
|||||||
}
|
}
|
||||||
public async Task<bool> GiveRoleSetMenu(List<long> roleIds, List<long> menuIds)
|
public async Task<bool> GiveRoleSetMenu(List<long> roleIds, List<long> menuIds)
|
||||||
{
|
{
|
||||||
var _repositoryRoleMenu = _repository.ChangeRepository<Repository<RoleMenuEntity>>();
|
var _repositoryRoleMenu= _repository.ChangeRepository<Repository<RoleMenuEntity>>();
|
||||||
|
|
||||||
//多次操作,需要事务确保原子性
|
//多次操作,需要事务确保原子性
|
||||||
return await _repositoryRoleMenu.UseTranAsync(async () =>
|
return await _repositoryRoleMenu.UseTranAsync(async () =>
|
||||||
{
|
{
|
||||||
@@ -35,12 +34,17 @@ namespace Yi.Framework.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
//一次性批量添加
|
//一次性批量添加
|
||||||
await _repositoryRoleMenu.InsertRangeAsync(roleMenuEntity);
|
await _repositoryRoleMenu.InsertReturnSnowflakeIdAsync(roleMenuEntity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<RoleEntity> GetInMenuByRoleId(long roleId)
|
||||||
|
{
|
||||||
|
return await _repository._Db.Queryable<RoleEntity>().Includes(u => u.Menus).InSingleAsync(roleId);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Common.Helper;
|
||||||
|
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;
|
||||||
@@ -92,7 +95,7 @@ namespace Yi.Framework.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
//一次性批量添加
|
//一次性批量添加
|
||||||
await _repositoryUserRole.InsertRangeAsync(userRoleEntities);
|
await _repositoryUserRole.InsertReturnSnowflakeIdAsync(userRoleEntities);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -102,5 +105,44 @@ 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.Where(r=>r.IsDeleted==false).ToList(), r => r.Menus.Where(m=>m.IsDeleted==false).ToList()).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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Microsoft.IdentityModel.JsonWebTokens;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Yi.Framework.WebCore.AttributeExtend
|
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();
|
var perList = context.HttpContext.User.Claims.Where(u => u.Type == "permission").Select(u=> u.Value.ToString().ToLower()). ToList();
|
||||||
//判断权限是否存在Redis中,或者jwt中
|
//判断权限是否存在Redis中,或者jwt中
|
||||||
|
|
||||||
//if (perList.Contains(permission.ToLower()))
|
//进行正则表达式的匹配,以code开头
|
||||||
//{
|
Regex regex = new Regex($"^{permission.ToLower()}");
|
||||||
// result = true;
|
foreach (var p in perList)
|
||||||
//}
|
{
|
||||||
result = true;
|
//过滤多余的标签
|
||||||
|
p.Replace("Entity","");
|
||||||
|
p.Replace("entity","");
|
||||||
|
if (regex.IsMatch(p))
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//用户的增删改查直接可以user:*即可
|
||||||
|
|
||||||
|
|
||||||
|
//这里暂时全部放行即可
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
|
|||||||
@@ -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,17 +33,22 @@ 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();
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||||||
var apiXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//控制器层注释
|
var apiXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//控制器层注释
|
||||||
//var entityXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//实体注释
|
//var entityXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//实体注释
|
||||||
//c.IncludeXmlComments(apiXmlPath, true);//true表示显示控制器注释
|
//c.IncludeXmlComments(apiXmlPath, true);//true表示显示控制器注释
|
||||||
c.IncludeXmlComments(apiXmlPath,true);
|
c.IncludeXmlComments(apiXmlPath, true);
|
||||||
|
|
||||||
//添加控制器注释
|
//添加控制器注释
|
||||||
//c.DocumentFilter<SwaggerDocTag>();
|
//c.DocumentFilter<SwaggerDocTag>();
|
||||||
@@ -42,25 +42,40 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||||||
//添加header验证信息
|
//添加header验证信息
|
||||||
//c.OperationFilter<SwaggerHeader>();
|
//c.OperationFilter<SwaggerHeader>();
|
||||||
//var security = new Dictionary<string, IEnumerable<string>> { { "Bearer", new string[] { } }, };
|
//var security = new Dictionary<string, IEnumerable<string>> { { "Bearer", new string[] { } }, };
|
||||||
|
c.AddSecurityDefinition("JwtBearer", new OpenApiSecurityScheme()
|
||||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
|
|
||||||
{
|
{
|
||||||
Description = "文本框里输入从服务器获取的Token。格式为:Bearer + 空格+token",//JWT授权(数据将在请求头中进行传输) 参数结构: \"Authorization: Bearer {token}\"
|
Description = "直接输入Token即可",
|
||||||
Name = "Authorization",////jwt默认的参数名称
|
Name = "Authorization",
|
||||||
In = ParameterLocation.Header,////jwt默认存放Authorization信息的位置(请求头中)
|
In = ParameterLocation.Header,
|
||||||
Type = SecuritySchemeType.ApiKey,
|
Type = SecuritySchemeType.Http,
|
||||||
|
Scheme = "bearer"
|
||||||
});
|
});
|
||||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
var scheme = new OpenApiSecurityScheme()
|
||||||
{
|
{
|
||||||
{ new OpenApiSecurityScheme
|
Reference = new OpenApiReference() { Type = ReferenceType.SecurityScheme, Id = "JwtBearer" }
|
||||||
{
|
};
|
||||||
Reference = new OpenApiReference()
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement()
|
||||||
{
|
{
|
||||||
Id = "Bearer",
|
[scheme] = new string[0]
|
||||||
Type = ReferenceType.SecurityScheme
|
|
||||||
}
|
|
||||||
}, Array.Empty<string>() }
|
|
||||||
});
|
});
|
||||||
|
//c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
|
||||||
|
//{
|
||||||
|
// Description = "文本框里输入从服务器获取的Token。格式为:Bearer + 空格+token",//JWT授权(数据将在请求头中进行传输) 参数结构: \"Authorization: Bearer {token}\"
|
||||||
|
// Name = "Authorization",////jwt默认的参数名称
|
||||||
|
// In = ParameterLocation.Header,////jwt默认存放Authorization信息的位置(请求头中)
|
||||||
|
// Type = SecuritySchemeType.ApiKey,
|
||||||
|
//});
|
||||||
|
//c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||||
|
//{
|
||||||
|
// { new OpenApiSecurityScheme
|
||||||
|
// {
|
||||||
|
// Reference = new OpenApiReference()
|
||||||
|
// {
|
||||||
|
// Id = "Bearer",
|
||||||
|
// Type = ReferenceType.SecurityScheme
|
||||||
|
// }
|
||||||
|
// }, Array.Empty<string>() }
|
||||||
|
//});
|
||||||
|
|
||||||
//c.AddServer(new OpenApiServer()
|
//c.AddServer(new OpenApiServer()
|
||||||
//{
|
//{
|
||||||
|
|||||||
@@ -35,12 +35,27 @@ export default {
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
changePassword(user, newPassword) {
|
updatePassword(oldPassword, newPassword) {
|
||||||
return myaxios({
|
return myaxios({
|
||||||
url: `/Account/changePassword`,
|
url: `/Account/updatePassword`,
|
||||||
method: 'put',
|
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'
|
import myaxios from '@/util/myaxios'
|
||||||
export default {
|
export default {
|
||||||
EditIcon(file) {
|
UploadImage(file) {
|
||||||
return myaxios({
|
return myaxios({
|
||||||
url: '/File/EditIcon',
|
url: '/Upload/image',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
headers: { "Content-Type": "multipart/form-data" },
|
headers: { "Content-Type": "multipart/form-data" },
|
||||||
data: file
|
data: file
|
||||||
|
|||||||
@@ -26,12 +26,5 @@ export default {
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
},
|
|
||||||
|
|
||||||
GetTopMenusByHttpUser() {
|
|
||||||
return myaxios({
|
|
||||||
url: '/Menu/GetTopMenusByHttpUser',
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,25 @@
|
|||||||
import myaxios from '@/util/myaxios'
|
import myaxios from '@/util/myaxios'
|
||||||
|
import {objctToDic} from '@/util/objctHandle'
|
||||||
export default {
|
export default {
|
||||||
getRole() {
|
getList() {
|
||||||
return myaxios({
|
return myaxios({
|
||||||
url: '/Role/getRole',
|
url: '/Role/GetList',
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
},
|
|
||||||
setMenuByRole(roleList, menuList) {
|
|
||||||
return myaxios({
|
|
||||||
url: '/Role/setMenuByRole',
|
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: { ids1: roleList, ids2: menuList }
|
data: objctToDic()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
GetTopMenusByRoleId(roleId) {
|
giveRoleSetMenu(roleList, menuList) {
|
||||||
return myaxios({
|
return myaxios({
|
||||||
url: `/Role/GetTopMenusByRoleId?roleId=${roleId}`,
|
url: '/Role/GiveRoleSetMenu',
|
||||||
method: 'get'
|
method: 'put',
|
||||||
|
data: { RoleIds: roleList, menuIds: menuList }
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
getInMenuByRoleId(roleId) {
|
||||||
|
return myaxios({
|
||||||
|
url: `/Role/GetInMenuByRoleId?roleId=${roleId}`,
|
||||||
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,5 @@
|
|||||||
import myaxios from '@/util/myaxios'
|
import myaxios from '@/util/myaxios'
|
||||||
export default {
|
export default {
|
||||||
SetRoleByUser(userIds, roleIds) {
|
|
||||||
return myaxios({
|
|
||||||
url: '/User/SetRoleByUser',
|
|
||||||
method: 'post',
|
|
||||||
data: { "ids1": userIds, "ids2": roleIds }
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GetUserInRolesByHttpUser() {
|
GetUserInRolesByHttpUser() {
|
||||||
return myaxios({
|
return myaxios({
|
||||||
@@ -28,4 +19,12 @@ export default {
|
|||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
GiveUserSetRole(UserIds,RoleIds)
|
||||||
|
{
|
||||||
|
return myaxios({
|
||||||
|
url: `/User/GiveUserSetRole`,
|
||||||
|
method: 'put',
|
||||||
|
data:{UserIds,RoleIds}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,11 @@
|
|||||||
import myaxios from '@/util/myaxios'
|
import myaxios from '@/util/myaxios'
|
||||||
|
import {objctToDic} from '@/util/objctHandle'
|
||||||
export default {
|
export default {
|
||||||
getItem(url) {
|
getItem(url) {
|
||||||
return myaxios({
|
return myaxios({
|
||||||
url: url,
|
url: url,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {
|
data: objctToDic()
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
key: "isDeleted",
|
|
||||||
value: "0",
|
|
||||||
type: 0
|
|
||||||
|
|
||||||
}
|
|
||||||
],
|
|
||||||
orderBys: [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addItem(url, data) {
|
addItem(url, data) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<v-avatar :size="size" >
|
<v-avatar :size="size" >
|
||||||
<!-- <img src="https://z3.ax1x.com/2021/05/09/gJadhD.jpg" /> -->
|
<!-- <img src="https://z3.ax1x.com/2021/05/09/gJadhD.jpg" /> -->
|
||||||
<img
|
<img
|
||||||
:src="baseurl +'/image/'+$store.state.user.user.icon"
|
:src="baseurl +'/image/'+$store.state.user.user.user.icon"
|
||||||
/>
|
/>
|
||||||
</v-avatar>
|
</v-avatar>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ export default {
|
|||||||
watch:{
|
watch:{
|
||||||
select:{//深度监听,可监听到对象、数组的变化
|
select:{//深度监听,可监听到对象、数组的变化
|
||||||
handler(val, oldVal){
|
handler(val, oldVal){
|
||||||
|
console.log(oldVal)
|
||||||
|
console.log(val)
|
||||||
this.$emit("select",val);
|
this.$emit("select",val);
|
||||||
},
|
},
|
||||||
deep:true
|
deep:true
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
></v-text-field>
|
></v-text-field>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="axiosUrls.add != null"
|
v-if="btnEnable.add==true"
|
||||||
color="primary"
|
color="primary"
|
||||||
dark
|
dark
|
||||||
class="mb-2 mx-2"
|
class="mb-2 mx-2"
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
<!-- 添加提示框 -->
|
<!-- 添加提示框 -->
|
||||||
<v-dialog
|
<v-dialog
|
||||||
v-if="axiosUrls.add != null"
|
v-if="btnEnable.add ==true"
|
||||||
v-model="dialog"
|
v-model="dialog"
|
||||||
max-width="500px"
|
max-width="500px"
|
||||||
>
|
>
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
</v-dialog>
|
</v-dialog>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="axiosUrls.del != null"
|
v-if="btnEnable.del == true"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
class="mb-2"
|
class="mb-2"
|
||||||
@click="deleteItem(null)"
|
@click="deleteItem(null)"
|
||||||
@@ -87,14 +87,14 @@
|
|||||||
<slot name="action" :item="item"></slot>
|
<slot name="action" :item="item"></slot>
|
||||||
|
|
||||||
<v-icon
|
<v-icon
|
||||||
v-if="axiosUrls.update != null"
|
v-if="btnEnable.update ==true"
|
||||||
small
|
small
|
||||||
class="mr-2"
|
class="mr-2"
|
||||||
@click="editItem(item)"
|
@click="editItem(item)"
|
||||||
>
|
>
|
||||||
mdi-pencil
|
mdi-pencil
|
||||||
</v-icon>
|
</v-icon>
|
||||||
<v-icon v-if="axiosUrls.del != null" small @click="deleteItem(item)">
|
<v-icon v-if="btnEnable.del ==true" small @click="deleteItem(item)">
|
||||||
mdi-delete
|
mdi-delete
|
||||||
</v-icon>
|
</v-icon>
|
||||||
</template>
|
</template>
|
||||||
@@ -119,6 +119,9 @@ export default {
|
|||||||
axiosUrls: {
|
axiosUrls: {
|
||||||
type: Object,
|
type: Object,
|
||||||
},
|
},
|
||||||
|
btnEnable: {
|
||||||
|
type: Object,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -166,7 +169,7 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
initialize() {
|
initialize() {
|
||||||
if(this.axiosUrls.get!=undefined && this.axiosUrls.get!=null )
|
if(this.btnEnable.get==true )
|
||||||
{
|
{
|
||||||
this.dataInit(this.axiosUrls.get)
|
this.dataInit(this.axiosUrls.get)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,11 +52,15 @@
|
|||||||
hoverable
|
hoverable
|
||||||
item-text="menuName"
|
item-text="menuName"
|
||||||
>
|
>
|
||||||
|
<template v-slot:prepend="{ item }">
|
||||||
|
<v-icon>
|
||||||
|
{{ item.menuIcon }}
|
||||||
|
</v-icon>
|
||||||
|
</template>
|
||||||
<template v-slot:append="{ item }">
|
<template v-slot:append="{ item }">
|
||||||
<v-btn class="mr-2">编号:{{ item.id }}</v-btn>
|
<v-btn v-show="item.menuType==1" class="mr-2">权限:{{ item.permissionCode }}</v-btn>
|
||||||
<v-btn class="mr-2">权限:{{ item.permissionCode }}</v-btn>
|
|
||||||
<!-- <v-btn class="mr-2">图标:{{ item.icon }}</v-btn> -->
|
<!-- <v-btn class="mr-2">图标:{{ item.icon }}</v-btn> -->
|
||||||
<!-- <v-btn class="mr-2">路由:{{ item.router }}</v-btn> -->
|
<v-btn v-show="item.menuType!=1" class="mr-2">路由:{{ item.router }}</v-btn>
|
||||||
<!-- <v-btn v-if="item.mould" class="mr-2">接口名:{{ item.mould.mould_name }}</v-btn>
|
<!-- <v-btn v-if="item.mould" class="mr-2">接口名:{{ item.mould.mould_name }}</v-btn>
|
||||||
<v-btn v-if="item.mould" class="mr-2" color="secondary">接口地址:{{ item.mould.url }}</v-btn> -->
|
<v-btn v-if="item.mould" class="mr-2" color="secondary">接口地址:{{ item.mould.url }}</v-btn> -->
|
||||||
<!-- <ccCombobox
|
<!-- <ccCombobox
|
||||||
@@ -102,9 +106,10 @@ export default {
|
|||||||
editedItem: {},
|
editedItem: {},
|
||||||
editedIndex: -1,
|
editedIndex: -1,
|
||||||
defaultItem: {
|
defaultItem: {
|
||||||
// icon: "mdi-start",
|
menuIcon: "mdi-view-dashboard",
|
||||||
permissionCode: "test",
|
permissionCode: "",
|
||||||
menuName: "管理",
|
menuName: "",
|
||||||
|
router:"",
|
||||||
parentId: 0,
|
parentId: 0,
|
||||||
MenuType:0
|
MenuType:0
|
||||||
},
|
},
|
||||||
@@ -122,21 +127,16 @@ export default {
|
|||||||
this.$refs.tree.updateAll(true);
|
this.$refs.tree.updateAll(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
// setMould(item) {
|
|
||||||
// menuApi.SetMouldByMenu(item.id, this.mouldSelect[0].id).then((resp) => {
|
|
||||||
// this.$dialog.notify.info(resp.msg, {
|
|
||||||
// position: "top-right",
|
|
||||||
// timeout: 5000,
|
|
||||||
// });
|
|
||||||
// this.init();
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
|
|
||||||
getSelect(data) {
|
getSelect(data) {
|
||||||
this.mouldSelect = data;
|
this.mouldSelect = data;
|
||||||
},
|
},
|
||||||
async deleteItem(item) {
|
async deleteItem(item) {
|
||||||
this.editedIndex = 1;
|
if(item!=null)
|
||||||
|
{
|
||||||
|
this.editedIndex = 1;
|
||||||
|
}
|
||||||
|
|
||||||
this.editedItem = Object.assign({}, item);
|
this.editedItem = Object.assign({}, item);
|
||||||
var p = await this.$dialog.warning({
|
var p = await this.$dialog.warning({
|
||||||
text: "你确定要删除此条记录吗??",
|
text: "你确定要删除此条记录吗??",
|
||||||
@@ -155,7 +155,7 @@ export default {
|
|||||||
if (this.editedIndex > -1) {
|
if (this.editedIndex > -1) {
|
||||||
Ids.push(this.editedItem.id);
|
Ids.push(this.editedItem.id);
|
||||||
} else {
|
} else {
|
||||||
this.selection.forEach(function (item) {
|
this.selection.forEach( (item) =>{
|
||||||
Ids.push(item.id);
|
Ids.push(item.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -201,6 +201,7 @@ export default {
|
|||||||
selection: {
|
selection: {
|
||||||
//深度监听,可监听到对象、数组的变化
|
//深度监听,可监听到对象、数组的变化
|
||||||
handler(val, oldVal) {
|
handler(val, oldVal) {
|
||||||
|
|
||||||
this.$emit("selection", val);
|
this.$emit("selection", val);
|
||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
|
|||||||
@@ -1,15 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-navigation-drawer
|
<v-navigation-drawer id="default-drawer" v-model="$store.state.home.drawer" :dark="dark" :right="$vuetify.rtl"
|
||||||
id="default-drawer"
|
:src="drawerImage ? image : ''" :mini-variant.sync="$store.state.home.mini" mini-variant-width="80" app width="260">
|
||||||
v-model="$store.state.home.drawer"
|
|
||||||
:dark="dark"
|
|
||||||
:right="$vuetify.rtl"
|
|
||||||
:src="drawerImage ? image : ''"
|
|
||||||
:mini-variant.sync="$store.state.home.mini"
|
|
||||||
mini-variant-width="80"
|
|
||||||
app
|
|
||||||
width="260"
|
|
||||||
>
|
|
||||||
<template v-if="drawerImage" #img="props">
|
<template v-if="drawerImage" #img="props">
|
||||||
<v-img :key="image" :gradient="gradient" v-bind="props" />
|
<v-img :key="image" :gradient="gradient" v-bind="props" />
|
||||||
</template>
|
</template>
|
||||||
@@ -24,13 +15,7 @@
|
|||||||
|
|
||||||
<template #append>
|
<template #append>
|
||||||
<div class="pa-4 text-center">
|
<div class="pa-4 text-center">
|
||||||
<app-btn
|
<app-btn class="text-none mb-4" color="white" href="https://vuetifyjs.com" small text>
|
||||||
class="text-none mb-4"
|
|
||||||
color="white"
|
|
||||||
href="https://vuetifyjs.com"
|
|
||||||
small
|
|
||||||
text
|
|
||||||
>
|
|
||||||
Documentation
|
Documentation
|
||||||
</app-btn>
|
</app-btn>
|
||||||
|
|
||||||
@@ -49,180 +34,19 @@
|
|||||||
<script>
|
<script>
|
||||||
// Utilities
|
// Utilities
|
||||||
// import { get, sync } from 'vuex-pathify'
|
// import { get, sync } from 'vuex-pathify'
|
||||||
import userApi from "@/api/userApi";
|
import store from "@/store/index.js";
|
||||||
|
import { toTree } from "@/util/menuHandle";
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
//这里动态获取菜单,暂时写死
|
const menus = store.state.user.user.menus.filter((m) => {
|
||||||
// userApi.GetMenuByHttpUser().then((resp) => {
|
return m.menuType == 0;
|
||||||
// this.items = resp.data.children;
|
});
|
||||||
// });
|
this.items = toTree(menus);
|
||||||
this.items =
|
|
||||||
|
|
||||||
[
|
|
||||||
{
|
|
||||||
icon: "mdi-view-dashboard",
|
|
||||||
router: "/",
|
|
||||||
menu_name: "首页",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 1,
|
|
||||||
children: null,
|
|
||||||
id: 2,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: "mdi-account-box-multiple",
|
|
||||||
router: null,
|
|
||||||
menu_name: "用户角色管理",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 1,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
icon: "mdi-account-box",
|
|
||||||
router: "/AdmUser/",
|
|
||||||
menu_name: "用户管理",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 3,
|
|
||||||
children: null,
|
|
||||||
id: 4,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: "mdi-account-circle",
|
|
||||||
router: "/admrole/",
|
|
||||||
menu_name: "角色管理",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 3,
|
|
||||||
children: null,
|
|
||||||
id: 9,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
id: 3,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: "mdi-account-cash",
|
|
||||||
router: null,
|
|
||||||
menu_name: "角色接口管理",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 1,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
icon: "mdi-clipboard-check-multiple",
|
|
||||||
router: "/AdmMenu/",
|
|
||||||
menu_name: "菜单管理",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 14,
|
|
||||||
children: null,
|
|
||||||
id: 15,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: "mdi-circle-slice-8",
|
|
||||||
router: "/admMould/",
|
|
||||||
menu_name: "接口管理",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 14,
|
|
||||||
children: null,
|
|
||||||
id: 20,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: "mdi-clipboard-account",
|
|
||||||
router: "/admRoleMenu/",
|
|
||||||
menu_name: "角色菜单分配管理",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 14,
|
|
||||||
children: null,
|
|
||||||
id: 25,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
id: 14,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: "mdi-clipboard-flow-outline",
|
|
||||||
router: null,
|
|
||||||
menu_name: "路由管理",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 1,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
icon: "mdi-account-eye",
|
|
||||||
router: "/userinfo/",
|
|
||||||
menu_name: "用户信息",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 26,
|
|
||||||
children: null,
|
|
||||||
id: 27,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: "mdi-account-eye",
|
|
||||||
router: "/pan",
|
|
||||||
menu_name: "云盘管理",
|
|
||||||
roles: null,
|
|
||||||
mould: null,
|
|
||||||
is_top: 0,
|
|
||||||
sort: 0,
|
|
||||||
is_show: 1,
|
|
||||||
parentId: 26,
|
|
||||||
children: null,
|
|
||||||
id: 28,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
id: 26,
|
|
||||||
is_delete: 0,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
this.$store.dispatch("Logout");
|
this.$store.dispatch("Logout")
|
||||||
this.$router.push({ path: "/login" });
|
this.$router.push({ path: "/login/" });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-list-group :group="group" :prepend-icon="item.icon" eager v-bind="$attrs">
|
<v-list-group :group="group" :prepend-icon="item.menuIcon" eager v-bind="$attrs">
|
||||||
<template v-slot:activator>
|
<template v-slot:activator>
|
||||||
<v-list-item-icon
|
<v-list-item-icon
|
||||||
v-if="!item.icon && !item.avatar"
|
v-if="!item.menuIcon && !item.avatar"
|
||||||
class="text-caption text-uppercase text-center my-2 align-self-center"
|
class="text-caption text-uppercase text-center my-2 align-self-center"
|
||||||
style="margin-top: 14px"
|
style="margin-top: 14px"
|
||||||
>
|
>
|
||||||
@@ -13,8 +13,8 @@
|
|||||||
<v-img :src="item.avatar" />
|
<v-img :src="item.avatar" />
|
||||||
</v-list-item-avatar>
|
</v-list-item-avatar>
|
||||||
|
|
||||||
<v-list-item-content v-if="item.menu_name">
|
<v-list-item-content v-if="item.menuName">
|
||||||
<v-list-item-title v-text="item.menu_name" />
|
<v-list-item-title v-text="item.menuName" />
|
||||||
</v-list-item-content>
|
</v-list-item-content>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ export default {
|
|||||||
return this.genGroup(this.item.children);
|
return this.genGroup(this.item.children);
|
||||||
},
|
},
|
||||||
title() {
|
title() {
|
||||||
const matches = this.item.menu_name.match(/\b(\w)/g);
|
const matches = this.item.menuName.match(/\b(\w)/g);
|
||||||
if (matches != null) {
|
if (matches != null) {
|
||||||
return matches.join("");
|
return matches.join("");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
v-on="$listeners"
|
v-on="$listeners"
|
||||||
>
|
>
|
||||||
<v-list-item-icon
|
<v-list-item-icon
|
||||||
v-if="!item.icon"
|
v-if="!item.menuIcon"
|
||||||
class="text-caption text-uppercase justify-center ml-1 my-2 align-self-center"
|
class="text-caption text-uppercase justify-center ml-1 my-2 align-self-center"
|
||||||
>
|
>
|
||||||
{{ title }}
|
{{ title }}
|
||||||
@@ -22,14 +22,14 @@
|
|||||||
</v-list-item-avatar>
|
</v-list-item-avatar>
|
||||||
|
|
||||||
<v-list-item-icon
|
<v-list-item-icon
|
||||||
v-if="item.icon"
|
v-if="item.menuIcon"
|
||||||
class="my-2 align-self-center"
|
class="my-2 align-self-center"
|
||||||
>
|
>
|
||||||
<v-icon v-text="item.icon" />
|
<v-icon v-text="item.menuIcon" />
|
||||||
</v-list-item-icon>
|
</v-list-item-icon>
|
||||||
|
|
||||||
<v-list-item-content v-if="item.menu_name">
|
<v-list-item-content v-if="item.menuName">
|
||||||
<v-list-item-title v-text="item.menu_name" />
|
<v-list-item-title v-text="item.menuName" />
|
||||||
</v-list-item-content>
|
</v-list-item-content>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</template>
|
</template>
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
title () {
|
title () {
|
||||||
const matches = this.item.menu_name.match(/\b(\w)/g)
|
const matches = this.item.menuName.match(/\b(\w)/g)
|
||||||
if(matches!=null)
|
if(matches!=null)
|
||||||
{
|
{
|
||||||
return matches.join('')
|
return matches.join('')
|
||||||
|
|||||||
@@ -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" },
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import store from './store/index'
|
|||||||
|
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
|
|
||||||
|
// console.log(to)
|
||||||
|
// console.log(from)
|
||||||
|
// console.log(next)
|
||||||
const user = store.state.user.user; //获取是有user
|
const user = store.state.user.user; //获取是有user
|
||||||
if (!user) { //如果没有登入
|
if (!user) { //如果没有登入
|
||||||
if (to.path == '/login/' || to.path == '/register/' || to.path == '/reset_password/' || to.path == '/qq/') {
|
if (to.path == '/login/' || to.path == '/register/' || to.path == '/reset_password/' || to.path == '/qq/') {
|
||||||
|
|||||||
@@ -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"
|
import accountApi from "@/api/accountApi"
|
||||||
|
|
||||||
//再导入axion请求
|
//再导入axion请求
|
||||||
const state = { //状态
|
const state = { //状态
|
||||||
|
per: getPer(),
|
||||||
token: getToken(),
|
token: getToken(),
|
||||||
user: getUser(),
|
user: getUser(),
|
||||||
dark: false,
|
dark: false,
|
||||||
@@ -20,13 +21,17 @@ const state = { //状态
|
|||||||
'https://s1.ax1x.com/2022/03/26/qdNnbD.jpg',
|
'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/qdNMUH.jpg',
|
||||||
'https://s1.ax1x.com/2022/03/26/qdNKVe.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: [],
|
notifications: [],
|
||||||
rtl: false
|
rtl: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const mutations = { //变化//载荷
|
const mutations = { //变化//载荷
|
||||||
|
SET_PER(state, per) {
|
||||||
|
state.per = per
|
||||||
|
setPer(per)
|
||||||
|
},
|
||||||
SET_TOKEN(state, token) {
|
SET_TOKEN(state, token) {
|
||||||
state.token = token
|
state.token = token
|
||||||
setToken(token)
|
setToken(token)
|
||||||
@@ -45,7 +50,7 @@ const mutations = { //变化//载荷
|
|||||||
|
|
||||||
//在action中可以配合axios进行权限判断
|
//在action中可以配合axios进行权限判断
|
||||||
const actions = { //动作
|
const actions = { //动作
|
||||||
setIcon({ commit, state }, icon) {
|
SetIcon({ commit, state }, icon) {
|
||||||
state.user.icon = icon
|
state.user.icon = icon
|
||||||
commit('SET_USER', state.user)
|
commit('SET_USER', state.user)
|
||||||
},
|
},
|
||||||
@@ -78,9 +83,24 @@ const actions = { //动作
|
|||||||
accountApi.login(form.username.trim(), form.password.trim()).then(resp => {
|
accountApi.login(form.username.trim(), form.password.trim()).then(resp => {
|
||||||
if (resp.status) {
|
if (resp.status) {
|
||||||
commit('SET_TOKEN', resp.data.token)
|
commit('SET_TOKEN', resp.data.token)
|
||||||
commit('SET_USER', resp.data.user)
|
|
||||||
|
|
||||||
|
accountApi.getUserAllInfo().then(resp2=>{
|
||||||
|
commit('SET_USER', resp2.data)
|
||||||
|
|
||||||
|
var code=[];
|
||||||
|
resp2.data.menus.forEach(element => {
|
||||||
|
code.push(element.permissionCode)
|
||||||
|
});
|
||||||
|
commit('SET_PER', code)
|
||||||
|
|
||||||
|
resolv(resp)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resolv(resp)
|
||||||
}
|
}
|
||||||
resolv(resp)
|
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
|
|||||||
77
Yi.Vue2.x/src/util/btnHandle.js
Normal file
77
Yi.Vue2.x/src/util/btnHandle.js
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import store from '../store/index'
|
||||||
|
//匹配按钮,判断是否有按钮存在
|
||||||
|
|
||||||
|
function getBtn(par) {
|
||||||
|
var axiosEnable = {
|
||||||
|
get: false,
|
||||||
|
update: false,
|
||||||
|
del: false,
|
||||||
|
add: false,
|
||||||
|
};
|
||||||
|
const per = store.state.user.per;
|
||||||
|
switch (par) {
|
||||||
|
case "user":
|
||||||
|
per.forEach(p => {
|
||||||
|
if(p=="user:get")
|
||||||
|
{
|
||||||
|
axiosEnable.get=true;
|
||||||
|
}
|
||||||
|
else if(p=="user:update")
|
||||||
|
{
|
||||||
|
axiosEnable.update=true;
|
||||||
|
}
|
||||||
|
else if(p=="user:del")
|
||||||
|
{
|
||||||
|
axiosEnable.del=true;
|
||||||
|
}
|
||||||
|
else if(p=="user:add")
|
||||||
|
{
|
||||||
|
axiosEnable.add=true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "role":
|
||||||
|
if(p=="role:get")
|
||||||
|
{
|
||||||
|
axiosEnable.get=true;
|
||||||
|
}
|
||||||
|
else if(p=="role:update")
|
||||||
|
{
|
||||||
|
axiosEnable.update=true;
|
||||||
|
}
|
||||||
|
else if(p=="role:del")
|
||||||
|
{
|
||||||
|
axiosEnable.del=true;
|
||||||
|
}
|
||||||
|
else if(p=="role:add")
|
||||||
|
{
|
||||||
|
axiosEnable.add=true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "menu":
|
||||||
|
if(p=="menu:get")
|
||||||
|
{
|
||||||
|
axiosEnable.get=true;
|
||||||
|
}
|
||||||
|
else if(p=="menu:update")
|
||||||
|
{
|
||||||
|
axiosEnable.update=true;
|
||||||
|
}
|
||||||
|
else if(p=="menu:del")
|
||||||
|
{
|
||||||
|
axiosEnable.del=true;
|
||||||
|
}
|
||||||
|
else if(p=="menu:add")
|
||||||
|
{
|
||||||
|
axiosEnable.add=true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
default: console.log("未发现合法路由")
|
||||||
|
}
|
||||||
|
return axiosEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export {getBtn};
|
||||||
@@ -1,29 +1,26 @@
|
|||||||
export function setTreeMenu(menuList) {
|
export function toTree(data) {
|
||||||
if (menuList != null && menuList.length > 0) {
|
// 删除 所有 children,以防止多次调用
|
||||||
|
data.forEach(function (item) {
|
||||||
|
delete item.children;
|
||||||
|
});
|
||||||
|
|
||||||
//结果
|
// 将数据存储为 以 id 为 KEY 的 map 索引数据列
|
||||||
var res;
|
var map = {};
|
||||||
//获取最小的parentId
|
data.forEach(function (item) {
|
||||||
var minParentId = 0;
|
map[item.id] = item;
|
||||||
//获取id=最小的parentId的菜单列表
|
});
|
||||||
var menuList1=menuList.filter((item)=>{item.parentId==minParentId}) ;
|
// console.log(map);
|
||||||
|
var val = [];
|
||||||
menuList1.forEach(element=>{
|
data.forEach(function (item) {
|
||||||
res.push(element)
|
// 以当前遍历项,的pid,去map对象中找到索引的id
|
||||||
var children=menuList.filter((item)=>{item.parentId==element.id}) ;
|
var parent = map[item.parentId];
|
||||||
if (children.length > 0) {
|
// 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
|
||||||
setTreeChildren(menuList, children,element)
|
if (parent) {
|
||||||
}
|
(parent.children || ( parent.children = [] )).push(item);
|
||||||
})
|
} else {
|
||||||
}
|
//如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
|
||||||
}
|
val.push(item);
|
||||||
|
|
||||||
function setTreeChildren(menuList, childrenList,model) {
|
|
||||||
childrenList.forEach(element => {
|
|
||||||
model.Childs.push(element);
|
|
||||||
var childrenList2=menuList.filter((item)=>{item.parentId==element.id}) ;
|
|
||||||
if (childrenList2.length > 0) {
|
|
||||||
setTreeChildren(menuList, childrenList2,element)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
@@ -31,14 +31,14 @@ myaxios.interceptors.request.use(function(config) {
|
|||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
myaxios.interceptors.response.use(async function(response) {
|
myaxios.interceptors.response.use(async function(response) {
|
||||||
const resp = response.data
|
const resp = response.data
|
||||||
if (resp.code == undefined && resp.msg == undefined) {
|
if (resp.code == undefined && resp.message == undefined) {
|
||||||
vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
|
vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
});
|
});
|
||||||
} else if (resp.code == 401) {
|
} else if (resp.code == 401) {
|
||||||
const res = await vm.$dialog.error({
|
const res = await vm.$dialog.error({
|
||||||
text: `错误代码:${resp.code},原因:${resp.msg}<br>是否重新进行登录?`,
|
text: `错误代码:${resp.code},原因:${resp.message}<br>是否重新进行登录?`,
|
||||||
title: '错误',
|
title: '错误',
|
||||||
actions: {
|
actions: {
|
||||||
'false': '取消',
|
'false': '取消',
|
||||||
@@ -50,7 +50,7 @@ myaxios.interceptors.response.use(async function(response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (resp.code !== 200) {
|
} else if (resp.code !== 200) {
|
||||||
vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.msg}`, {
|
vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.message}`, {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
});
|
});
|
||||||
@@ -60,14 +60,14 @@ myaxios.interceptors.response.use(async function(response) {
|
|||||||
return resp;
|
return resp;
|
||||||
}, async function(error) {
|
}, async function(error) {
|
||||||
const resp = error.response.data
|
const resp = error.response.data
|
||||||
if (resp.code == undefined && resp.msg == undefined) {
|
if (resp.code == undefined && resp.message == undefined) {
|
||||||
vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
|
vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
});
|
});
|
||||||
} else if (resp.code == 401) {
|
} else if (resp.code == 401) {
|
||||||
const res = await vm.$dialog.error({
|
const res = await vm.$dialog.error({
|
||||||
text: `错误代码:${resp.code},原因:${resp.msg}<br>是否重新进行登录?`,
|
text: `错误代码:${resp.code},原因:${resp.message}<br>是否重新进行登录?`,
|
||||||
title: '错误',
|
title: '错误',
|
||||||
actions: {
|
actions: {
|
||||||
'false': '取消',
|
'false': '取消',
|
||||||
@@ -81,7 +81,7 @@ myaxios.interceptors.response.use(async function(response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (resp.code !== 200) {
|
} else if (resp.code !== 200) {
|
||||||
vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.msg}`, {
|
vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.message}`, {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ export function deepCopy(obj) {
|
|||||||
|
|
||||||
//转换数据,0是相等,1是模糊查询
|
//转换数据,0是相等,1是模糊查询
|
||||||
export function objctToDic(object, isByPage) {
|
export function objctToDic(object, isByPage) {
|
||||||
|
if (object == undefined) {
|
||||||
|
|
||||||
|
object = {};
|
||||||
|
}
|
||||||
|
|
||||||
if (isByPage) {
|
if (isByPage) {
|
||||||
var paramPage = {
|
var paramPage = {
|
||||||
"index": object.pageIndex,
|
"index": object.pageIndex,
|
||||||
@@ -19,8 +24,8 @@ export function objctToDic(object, isByPage) {
|
|||||||
var newData = deepCopy(object);
|
var newData = deepCopy(object);
|
||||||
delete newData.pageIndex;
|
delete newData.pageIndex;
|
||||||
delete newData.pageSize;
|
delete newData.pageSize;
|
||||||
|
|
||||||
var newList = [Object.keys(newData).map(val => {
|
var newList = [Object.keys(newData).map(val => {
|
||||||
return {
|
return {
|
||||||
key: val,
|
key: val,
|
||||||
value: object[val],
|
value: object[val],
|
||||||
@@ -30,11 +35,9 @@ export function objctToDic(object, isByPage) {
|
|||||||
|
|
||||||
//过滤封装
|
//过滤封装
|
||||||
newList[0].forEach((item, index) => {
|
newList[0].forEach((item, index) => {
|
||||||
if(item.value.length>0)
|
if (item.value.length > 0) {
|
||||||
{
|
if (item.key == 'isDeleted') {
|
||||||
if(item.key=='isDeleted')
|
item.type = 0;
|
||||||
{
|
|
||||||
item.type=0;
|
|
||||||
}
|
}
|
||||||
paramPage.parameters.push(item);
|
paramPage.parameters.push(item);
|
||||||
}
|
}
|
||||||
@@ -55,11 +58,9 @@ export function objctToDic(object, isByPage) {
|
|||||||
}
|
}
|
||||||
})]
|
})]
|
||||||
thisList[0].forEach((item, index) => {
|
thisList[0].forEach((item, index) => {
|
||||||
if(item.value.length>0)
|
if (item.value.length > 0) {
|
||||||
{
|
if (item.key == 'isDeleted') {
|
||||||
if(item.key=='isDeleted')
|
item.type = 0;
|
||||||
{
|
|
||||||
item.type=0;
|
|
||||||
}
|
}
|
||||||
params.parameters.push(item);
|
params.parameters.push(item);
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,30 @@
|
|||||||
const TOKEN_KEY = "token_key"
|
const TOKEN_KEY = "token_key"
|
||||||
const USER_KEY = "user_key"
|
const USER_KEY = "user_key"
|
||||||
|
const PER_KEY="per_key"
|
||||||
export function getToken() {
|
export function getToken() {
|
||||||
return localStorage.getItem(TOKEN_KEY)
|
return localStorage.getItem(TOKEN_KEY)
|
||||||
}
|
}
|
||||||
export function setToken(token) {
|
|
||||||
return localStorage.setItem(TOKEN_KEY, token)
|
|
||||||
}
|
|
||||||
export function getUser() {
|
export function getUser() {
|
||||||
return JSON.parse(localStorage.getItem(USER_KEY))
|
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) {
|
export function setUser(user) {
|
||||||
return localStorage.setItem(USER_KEY, JSON.stringify(user))
|
return localStorage.setItem(USER_KEY, JSON.stringify(user))
|
||||||
}
|
}
|
||||||
|
export function setPer(per) {
|
||||||
|
return localStorage.setItem(PER_KEY, JSON.stringify(per))
|
||||||
|
}
|
||||||
export function removeToken() {
|
export function removeToken() {
|
||||||
localStorage.removeItem(TOKEN_KEY)
|
localStorage.removeItem(TOKEN_KEY)
|
||||||
localStorage.removeItem(USER_KEY)
|
localStorage.removeItem(USER_KEY)
|
||||||
|
localStorage.removeItem(PER_KEY)
|
||||||
}
|
}
|
||||||
@@ -7,17 +7,20 @@
|
|||||||
:defaultItem="defaultItem"
|
:defaultItem="defaultItem"
|
||||||
:headers="headers"
|
:headers="headers"
|
||||||
:axiosUrls="axiosUrls"
|
:axiosUrls="axiosUrls"
|
||||||
|
:btnEnable="btnEnable"
|
||||||
>
|
>
|
||||||
</ccTable>
|
</ccTable>
|
||||||
</material-card>
|
</material-card>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import { getBtn } from "../util/btnHandle";
|
||||||
export default {
|
export default {
|
||||||
created() {
|
created() {
|
||||||
this.init();
|
this.init();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
|
this.btnEnable = getBtn("user")
|
||||||
this.axiosUrls = {
|
this.axiosUrls = {
|
||||||
get: "/role/GetList",
|
get: "/role/GetList",
|
||||||
update: "/role/Update",
|
update: "/role/Update",
|
||||||
@@ -30,8 +33,10 @@ export default {
|
|||||||
start: true,
|
start: true,
|
||||||
axiosUrls: {
|
axiosUrls: {
|
||||||
},
|
},
|
||||||
|
btnEnable:{},
|
||||||
headers: [
|
headers: [
|
||||||
{ text: "编号", align: "start", value: "id" },
|
// { text: "编号", align: "start", value: "id" },
|
||||||
|
{ text: "角色编号", value: "roleCode", sortable: false },
|
||||||
{ text: "角色名", value: "roleName", sortable: false },
|
{ text: "角色名", value: "roleName", sortable: false },
|
||||||
// { text: "云盘地址", value: "file_path", sortable: false },
|
// { text: "云盘地址", value: "file_path", sortable: false },
|
||||||
// { text: "简介", value: "introduce", sortable: false },
|
// { text: "简介", value: "introduce", sortable: false },
|
||||||
|
|||||||
@@ -6,30 +6,28 @@
|
|||||||
角色菜单分配管理 —
|
角色菜单分配管理 —
|
||||||
<small class="text-body-1"
|
<small class="text-body-1"
|
||||||
>你可以在这里多角色分配多菜单/选中一个可查看</small
|
>你可以在这里多角色分配多菜单/选中一个可查看</small
|
||||||
> </template
|
>
|
||||||
>
|
</template>
|
||||||
<v-divider></v-divider>
|
<v-divider></v-divider>
|
||||||
<app-btn dark class="ma-4" @click="showAll"> 展开全部</app-btn>
|
<app-btn dark class="ma-4" @click="showAll"> 展开全部</app-btn>
|
||||||
<app-btn class="my-4 mr-4" @click="setMenu">确定分配</app-btn
|
<app-btn class="my-4 mr-4" @click="setMenu">确定分配</app-btn>
|
||||||
>
|
|
||||||
|
<app-btn class="my-4" color="secondary" @click="clear"
|
||||||
<app-btn class="my-4" color="secondary" @click="clear">清空选择</app-btn></material-card
|
>清空选择</app-btn
|
||||||
|
></material-card
|
||||||
>
|
>
|
||||||
|
|
||||||
</v-col>
|
</v-col>
|
||||||
|
|
||||||
<v-col cols="12" md="4" lg="4">
|
<v-col cols="12" md="4" lg="4">
|
||||||
<v-card class="mx-auto" width="100%">
|
<v-card class="mx-auto" width="100%">
|
||||||
<v-treeview
|
<v-treeview
|
||||||
|
|
||||||
|
|
||||||
selectable
|
selectable
|
||||||
:items="RoleItems"
|
:items="RoleItems"
|
||||||
v-model="selectionRole"
|
v-model="selectionRole"
|
||||||
return-object
|
return-object
|
||||||
open-all
|
open-all
|
||||||
hoverable
|
hoverable
|
||||||
item-text="role_name"
|
item-text="roleName"
|
||||||
>
|
>
|
||||||
</v-treeview>
|
</v-treeview>
|
||||||
</v-card>
|
</v-card>
|
||||||
@@ -38,7 +36,7 @@
|
|||||||
<v-col cols="12" md="8" lg="8">
|
<v-col cols="12" md="8" lg="8">
|
||||||
<v-card class="mx-auto" width="100%">
|
<v-card class="mx-auto" width="100%">
|
||||||
<v-treeview
|
<v-treeview
|
||||||
ref="tree"
|
ref="tree"
|
||||||
open-on-click
|
open-on-click
|
||||||
selectable
|
selectable
|
||||||
:items="Menuitems"
|
:items="Menuitems"
|
||||||
@@ -47,10 +45,10 @@
|
|||||||
return-object
|
return-object
|
||||||
open-all
|
open-all
|
||||||
hoverable
|
hoverable
|
||||||
item-text="menu_name"
|
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
|
||||||
@@ -68,8 +66,12 @@ export default {
|
|||||||
selectionRole: {
|
selectionRole: {
|
||||||
handler(val, oldVal) {
|
handler(val, oldVal) {
|
||||||
if (val.length == 1) {
|
if (val.length == 1) {
|
||||||
roleApi.GetTopMenusByRoleId(val[0].id).then((resp) => {
|
roleApi.getInMenuByRoleId(val[0].id).then((resp) => {
|
||||||
this.selectionMenu = resp.data;
|
if (resp.data.menus == null) {
|
||||||
|
this.selectionMenu = [];
|
||||||
|
} else {
|
||||||
|
this.selectionMenu = resp.data.menus;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -77,9 +79,9 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
showAll(){
|
showAll() {
|
||||||
this.$refs.tree.updateAll(true);
|
this.$refs.tree.updateAll(true);
|
||||||
},
|
},
|
||||||
clear() {
|
clear() {
|
||||||
this.selectionMenu = [];
|
this.selectionMenu = [];
|
||||||
this.selectionRole = [];
|
this.selectionRole = [];
|
||||||
@@ -93,20 +95,20 @@ export default {
|
|||||||
this.selectionMenu.forEach((ele) => {
|
this.selectionMenu.forEach((ele) => {
|
||||||
menuIds.push(ele.id);
|
menuIds.push(ele.id);
|
||||||
});
|
});
|
||||||
roleApi.setMenuByRole(roleIds, menuIds).then((resp) => {
|
roleApi.giveRoleSetMenu(roleIds, menuIds).then((resp) => {
|
||||||
this.$dialog.notify.info(resp.msg, {
|
this.$dialog.notify.info(resp.message, {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
init() {
|
init() {
|
||||||
roleApi.getRole().then((resp) => {
|
roleApi.getList().then((resp) => {
|
||||||
this.RoleItems = resp.data;
|
this.RoleItems = resp.data;
|
||||||
});
|
});
|
||||||
|
|
||||||
menuApi.GetMenuInMould().then((resp) => {
|
menuApi.getMenuTree().then((resp) => {
|
||||||
this.Menuitems = [resp.data];
|
this.Menuitems = resp.data;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,22 +3,13 @@
|
|||||||
<template #title>
|
<template #title>
|
||||||
用户管理 — <small class="text-body-1">用户可拥有多个角色</small>
|
用户管理 — <small class="text-body-1">用户可拥有多个角色</small>
|
||||||
</template>
|
</template>
|
||||||
<ccCombobox
|
<ccCombobox headers="设置角色" :items="roleItems" @select="getSelect" itemText="roleName">
|
||||||
headers="设置角色"
|
|
||||||
:items="roleItems"
|
|
||||||
@select="getSelect"
|
|
||||||
itemText="role_name"
|
|
||||||
>
|
|
||||||
<template v-slot:save>
|
<template v-slot:save>
|
||||||
<v-btn @click="setRole" color="blue darken-1" text> 保存</v-btn>
|
<v-btn @click="setRole" color="blue darken-1" text> 保存</v-btn>
|
||||||
</template>
|
</template>
|
||||||
</ccCombobox>
|
</ccCombobox>
|
||||||
<ccTable
|
<ccTable :defaultItem="defaultItem" :headers="headers" :axiosUrls="axiosUrls" :btnEnable="btnEnable"
|
||||||
:defaultItem="defaultItem"
|
@selected="getTableSelect">
|
||||||
:headers="headers"
|
|
||||||
:axiosUrls="axiosUrls"
|
|
||||||
@selected="getTableSelect"
|
|
||||||
>
|
|
||||||
<template v-slot:action="{ item }">
|
<template v-slot:action="{ item }">
|
||||||
<v-icon small class="mr-2" @click="showItem(item)"> mdi-eye </v-icon>
|
<v-icon small class="mr-2" @click="showItem(item)"> mdi-eye </v-icon>
|
||||||
</template>
|
</template>
|
||||||
@@ -27,6 +18,8 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import userApi from "../api/userApi";
|
import userApi from "../api/userApi";
|
||||||
|
import roleApi from "../api/roleApi";
|
||||||
|
import { getBtn } from "../util/btnHandle";
|
||||||
export default {
|
export default {
|
||||||
created() {
|
created() {
|
||||||
this.init();
|
this.init();
|
||||||
@@ -59,6 +52,8 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
init() {
|
init() {
|
||||||
|
//这里可以遍历后台的菜单code,根据对应的菜单code来给axiosUrls的增删改查赋值即可
|
||||||
|
this.btnEnable = getBtn("user")
|
||||||
this.axiosUrls = {
|
this.axiosUrls = {
|
||||||
get: "/user/GetList",
|
get: "/user/GetList",
|
||||||
update: "/user/Update",
|
update: "/user/Update",
|
||||||
@@ -66,9 +61,9 @@ export default {
|
|||||||
add: "/user/Add",
|
add: "/user/Add",
|
||||||
};
|
};
|
||||||
|
|
||||||
// roleApi.getRole().then((resp) => {
|
roleApi.getList().then((resp) => {
|
||||||
// this.roleItems = resp.data;
|
this.roleItems = JSON.parse(JSON.stringify(resp.data));
|
||||||
// });
|
});
|
||||||
},
|
},
|
||||||
setRole() {
|
setRole() {
|
||||||
var userIds = [];
|
var userIds = [];
|
||||||
@@ -79,8 +74,8 @@ export default {
|
|||||||
this.select.forEach((item) => {
|
this.select.forEach((item) => {
|
||||||
roleIds.push(item.id);
|
roleIds.push(item.id);
|
||||||
});
|
});
|
||||||
userApi.SetRoleByUser(userIds, roleIds).then((resp) => {
|
userApi.GiveUserSetRole(userIds, roleIds).then((resp) => {
|
||||||
this.$dialog.notify.success(resp.msg, {
|
this.$dialog.notify.success(resp.message, {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
});
|
});
|
||||||
@@ -95,13 +90,14 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
|
btnEnable: [],
|
||||||
TableSelect: [],
|
TableSelect: [],
|
||||||
select: [],
|
select: [],
|
||||||
roleItems: [],
|
roleItems: [],
|
||||||
axiosUrls: {},
|
axiosUrls: {},
|
||||||
headers: [
|
headers: [
|
||||||
{ text: "用户名", value: "userName", sortable: false },
|
{ text: "用户名", value: "userName", sortable: false },
|
||||||
{ text: "密码", value: "password", sortable: false },
|
|
||||||
{ text: "图标", value: "icon", sortable: false },
|
{ text: "图标", value: "icon", sortable: false },
|
||||||
{ text: "昵称", value: "nick", sortable: true },
|
{ text: "昵称", value: "nick", sortable: true },
|
||||||
{ text: "邮箱", value: "email", sortable: true },
|
{ text: "邮箱", value: "email", sortable: true },
|
||||||
|
|||||||
@@ -52,7 +52,16 @@
|
|||||||
<a href="javascript:void(0)" class="mt-1"> 忘记密码? </a>
|
<a href="javascript:void(0)" class="mt-1"> 忘记密码? </a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<v-btn block color="primary" @click="login" class="mt-6" :loading="loader" :disabled="btn_dis"> 登录 </v-btn>
|
<v-btn
|
||||||
|
block
|
||||||
|
color="primary"
|
||||||
|
@click="login"
|
||||||
|
class="mt-6"
|
||||||
|
:loading="loader"
|
||||||
|
:disabled="btn_dis"
|
||||||
|
>
|
||||||
|
登录
|
||||||
|
</v-btn>
|
||||||
</v-form>
|
</v-form>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
|
|
||||||
@@ -70,7 +79,7 @@
|
|||||||
</v-card-text>
|
</v-card-text>
|
||||||
|
|
||||||
<!-- social links -->
|
<!-- social links -->
|
||||||
<v-card-actions class="d-flex justify-center ">
|
<v-card-actions class="d-flex justify-center">
|
||||||
<v-btn v-for="link in socialLink" :key="link.icon" icon class="ms-1">
|
<v-btn v-for="link in socialLink" :key="link.icon" icon class="ms-1">
|
||||||
<v-icon :color="$vuetify.theme.dark ? link.colorInDark : link.color">
|
<v-icon :color="$vuetify.theme.dark ? link.colorInDark : link.color">
|
||||||
{{ link.icon }}
|
{{ link.icon }}
|
||||||
@@ -81,11 +90,11 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
created(){
|
created() {
|
||||||
this.enterSearch();
|
this.enterSearch();
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
btn_dis:false,
|
btn_dis: false,
|
||||||
loader: null,
|
loader: null,
|
||||||
socialLink: [
|
socialLink: [
|
||||||
{
|
{
|
||||||
@@ -122,8 +131,7 @@ export default {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
enterSearch() {
|
enterSearch() {
|
||||||
|
|
||||||
document.onkeydown = (e) => {
|
document.onkeydown = (e) => {
|
||||||
//13表示回车键,baseURI是当前页面的地址,为了更严谨,也可以加别的,可以打印e看一下
|
//13表示回车键,baseURI是当前页面的地址,为了更严谨,也可以加别的,可以打印e看一下
|
||||||
if (e.keyCode === 13 && e.target.baseURI.match("/")) {
|
if (e.keyCode === 13 && e.target.baseURI.match("/")) {
|
||||||
@@ -133,20 +141,29 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
login() {
|
login() {
|
||||||
this.loader = "true";
|
this.loader = true;
|
||||||
this.btn_dis=true;
|
this.btn_dis = true;
|
||||||
this.$store.dispatch("Login", this.form).then((resp) => {
|
this.$store
|
||||||
if (resp.status) {
|
.dispatch("Login", this.form)
|
||||||
this.$router.push("/");
|
.then((resp) => {
|
||||||
} else {
|
if (resp.status) {
|
||||||
this.loader=null;
|
|
||||||
this.btn_dis=false;
|
this.$router.push("/");
|
||||||
this.$dialog.notify.error(resp.msg, {
|
} else {
|
||||||
position: "top-right",
|
|
||||||
timeout: 5000,
|
this.loader = null;
|
||||||
});
|
this.btn_dis = false;
|
||||||
}
|
this.$dialog.notify.error(resp.message, {
|
||||||
});
|
position: "top-right",
|
||||||
|
timeout: 5000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
|
||||||
|
this.loader = false;
|
||||||
|
this.btn_dis = false;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,23 +3,32 @@
|
|||||||
<v-row justify="center">
|
<v-row justify="center">
|
||||||
<v-col cols="12" md="4">
|
<v-col cols="12" md="4">
|
||||||
<app-card class="mt-4 text-center">
|
<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">
|
<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>
|
||||||
|
|
||||||
<p class="text--secondary">{{ userInfo.introduction }}</p>
|
<p class="text--secondary">{{ userInfo.introduction }}</p>
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
ref="imgFile"
|
ref="imgFile"
|
||||||
@change="uploadImage()"
|
@change="uploadImage()"
|
||||||
class="d-none"
|
class="d-none"
|
||||||
/>
|
/>
|
||||||
<v-btn class="mr-4" @click="choiceImg" color="primary" min-width="100" rounded>
|
<v-btn
|
||||||
|
class="mr-4"
|
||||||
|
@click="choiceImg"
|
||||||
|
color="primary"
|
||||||
|
min-width="100"
|
||||||
|
rounded
|
||||||
|
>
|
||||||
编辑头像
|
编辑头像
|
||||||
</v-btn>
|
</v-btn>
|
||||||
<v-btn color="primary" min-width="100" rounded> 绑定QQ </v-btn>
|
<v-btn color="primary" min-width="100" rounded> 绑定QQ </v-btn>
|
||||||
@@ -61,7 +70,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 +163,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 +187,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>
|
||||||
@@ -230,7 +239,7 @@
|
|||||||
<v-text-field
|
<v-text-field
|
||||||
style="width: 80%"
|
style="width: 80%"
|
||||||
label="原密码"
|
label="原密码"
|
||||||
v-model="editInfo.password"
|
v-model="oldPassword"
|
||||||
outlined
|
outlined
|
||||||
clearable
|
clearable
|
||||||
></v-text-field>
|
></v-text-field>
|
||||||
@@ -263,8 +272,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import fileApi from "../api/fileApi";
|
import fileApi from "../api/fileApi";
|
||||||
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",
|
||||||
@@ -273,16 +280,18 @@ export default {
|
|||||||
userInfo: {},
|
userInfo: {},
|
||||||
editInfo: {},
|
editInfo: {},
|
||||||
newPassword: "",
|
newPassword: "",
|
||||||
|
oldPassword: "",
|
||||||
dis_newPassword: true,
|
dis_newPassword: true,
|
||||||
|
roleInfo: [],
|
||||||
menuInfo: [],
|
menuInfo: [],
|
||||||
}),
|
}),
|
||||||
created() {
|
created() {
|
||||||
this.init();
|
this.init();
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
editInfo: {
|
oldPassword: {
|
||||||
handler(val, oldVal) {
|
handler(val, oldVal) {
|
||||||
if (val.password.length > 0) {
|
if (val != "") {
|
||||||
this.dis_newPassword = false;
|
this.dis_newPassword = false;
|
||||||
} else {
|
} else {
|
||||||
this.dis_newPassword = true;
|
this.dis_newPassword = true;
|
||||||
@@ -294,55 +303,60 @@ export default {
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
save() {
|
save() {
|
||||||
accountApi
|
if (this.newPassword != "") {
|
||||||
.changePassword(this.editInfo, this.newPassword)
|
accountApi
|
||||||
.then((resp) => {
|
.updatePassword(this.oldPassword, this.newPassword)
|
||||||
if (resp.status) {
|
.then((resp) => {
|
||||||
this.$dialog.notify.error(resp.msg, {
|
if (resp.status) {
|
||||||
position: "top-right",
|
this.$dialog.notify.success(resp.message, {
|
||||||
timeout: 5000,
|
position: "top-right",
|
||||||
});
|
timeout: 5000,
|
||||||
} else {
|
});
|
||||||
this.$dialog.notify.success(resp.msg, {
|
} else {
|
||||||
position: "top-right",
|
this.$dialog.notify.error(resp.message, {
|
||||||
timeout: 5000,
|
position: "top-right",
|
||||||
});
|
timeout: 5000,
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
this.init();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
accountApi.updateUserByHttp(this.editInfo).then((resp) => {
|
||||||
this.init();
|
this.init();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
init() {
|
init() {
|
||||||
this.newPassword = "";
|
this.newPassword = "";
|
||||||
userApi.GetUserInRolesByHttpUser().then((resp) => {
|
this.oldPassword = "";
|
||||||
this.userInfo = resp.data;
|
accountApi.getUserAllInfo().then((resp) => {
|
||||||
|
this.userInfo = resp.data.user;
|
||||||
this.userInfo.password = "";
|
this.userInfo.password = "";
|
||||||
this.editInfo = Object.assign({}, this.userInfo);
|
this.editInfo = Object.assign({}, this.userInfo);
|
||||||
this.$store.commit('SET_USER',this.userInfo)
|
this.roleInfo = resp.data.roles;
|
||||||
});
|
this.menuInfo = resp.data.menus;
|
||||||
|
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"));
|
||||||
},
|
},
|
||||||
uploadImage() {
|
uploadImage() {
|
||||||
|
//修改头像,需要先上传头像,修改editInfo的头像信息即可
|
||||||
const file = this.$refs.imgFile.files[0];
|
const file = this.$refs.imgFile.files[0];
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append("file", file);
|
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>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user