Skip to content

Commit

Permalink
fix: dataprivilege layui page error,update system.drawing to ImageSharp
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliang-wt committed Mar 31, 2022
1 parent 695597e commit 1b745e0
Show file tree
Hide file tree
Showing 37 changed files with 36,072 additions and 11,504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}
else
{
await WtmBlazor.Toast.Error(WtmBlazor.Localizer["Sys.Error"], rv.Errors.Message[0]);
//await WtmBlazor.Toast.Error(WtmBlazor.Localizer["Sys.Error"], rv.Errors.Message[0]);
hasToken = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,9 @@
<data name="_Admin.IsValid" xml:space="preserve">
<value>IsValid</value>
</data>
<data name="_Admin.Job" xml:space="preserve">
<value>Job</value>
</data>
<data name="_Admin.Length" xml:space="preserve">
<value>Length</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,9 @@
<data name="_Admin.IsValid" xml:space="preserve">
<value>是否有效</value>
</data>
<data name="_Admin.Job" xml:space="preserve">
<value>作业</value>
</data>
<data name="_Admin.Length" xml:space="preserve">
<value>长度</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task<IActionResult> Login([FromForm] string account, [FromForm] str
public async Task<IActionResult> LoginJwt(SimpleLogin loginInfo)
{

var rv = await DC.Set<FrameworkUser>().Where(x => x.ITCode.ToLower() == loginInfo.Account.ToLower() && x.Password == Utils.GetMD5String(loginInfo.Password) && x.IsValid).Select(x => new { itcode = x.ITCode, id = x.GetID() }).SingleOrDefaultAsync();
var rv = await DC.Set<FrameworkUser>().Where(x => x.ITCode.ToLower() == loginInfo.Account.ToLower() && (x.Password == Utils.GetMD5String(loginInfo.Password) || x.Password == loginInfo.Password) && x.IsValid).Select(x => new { itcode = x.ITCode, id = x.GetID() }).SingleOrDefaultAsync();

if (rv == null)
{
Expand All @@ -128,12 +128,21 @@ public async Task<IActionResult> LoginJwt(SimpleLogin loginInfo)
UserId = rv.id.ToString()
};
await user.LoadBasicInfoAsync(Wtm);
Wtm.LoginUserInfo = user;

var authService = HttpContext.RequestServices.GetService(typeof(ITokenService)) as ITokenService;
//其他属性可以通过user.Attributes["aaa"] = "bbb"方式赋值

Wtm.LoginUserInfo = user;
if (loginInfo.IsReload == false)
{
var authService = HttpContext.RequestServices.GetService(typeof(ITokenService)) as ITokenService;

var token = await authService.IssueTokenAsync(Wtm.LoginUserInfo);
return Content(JsonSerializer.Serialize(token), "application/json");
var token = await authService.IssueTokenAsync(Wtm.LoginUserInfo);
return Content(JsonSerializer.Serialize(token), "application/json");
}
else
{
return Ok(user);
}
}

[AllowAnonymous]
Expand Down Expand Up @@ -297,6 +306,7 @@ public class SimpleLogin
{
public string Account { get; set; }
public string Password { get; set; }
public bool IsReload { get; set; } = false;
}

public class SimpleReg
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
Expand All @@ -21,24 +21,24 @@ public class FileApiController : BaseApiController
{
[HttpPost("[action]")]
[ActionDescription("UploadFile")]
public IActionResult Upload([FromServices] WtmFileProvider fp, string sm = null, string groupName = null, string subdir=null,string extra = null,string csName= null)
public IActionResult Upload([FromServices] WtmFileProvider fp, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
{
var FileData = Request.Form.Files[0];
var file = fp.Upload(FileData.FileName, FileData.Length, FileData.OpenReadStream(),groupName,subdir,extra,sm,Wtm.CreateDC(cskey:csName));
var file = fp.Upload(FileData.FileName, FileData.Length, FileData.OpenReadStream(), groupName, subdir, extra, sm, Wtm.CreateDC(cskey: csName));
return Ok(new { Id = file.GetID(), Name = file.FileName });
}

[HttpPost("[action]")]
[ActionDescription("UploadPic")]
public IActionResult UploadImage([FromServices] WtmFileProvider fp,int? width = null, int? height = null, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
public IActionResult UploadImage([FromServices] WtmFileProvider fp, int? width = null, int? height = null, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
{
if (width == null && height == null)
{
return Upload(fp,sm,groupName,csName);
return Upload(fp, sm, groupName, csName);
}
var FileData = Request.Form.Files[0];

Image oimage = Image.FromStream(FileData.OpenReadStream());
Image oimage = Image.Load(FileData.OpenReadStream());
if (oimage == null)
{
return BadRequest(Localizer["Sys.UploadFailed"]);
Expand All @@ -52,9 +52,10 @@ public IActionResult UploadImage([FromServices] WtmFileProvider fp,int? width =
height = width * oimage.Height / oimage.Width;
}
MemoryStream ms = new MemoryStream();
oimage.GetThumbnailImage(width.Value, height.Value, null, IntPtr.Zero).Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
oimage.Mutate(x => x.Resize(width.Value, height.Value));
oimage.SaveAsJpeg(ms);
ms.Position = 0;
var file = fp.Upload(FileData.FileName, FileData.Length, ms, groupName,subdir, extra, sm, Wtm.CreateDC(cskey: csName));
var file = fp.Upload(FileData.FileName, FileData.Length, ms, groupName, subdir, extra, sm, Wtm.CreateDC(cskey: csName));
oimage.Dispose();
ms.Dispose();

Expand All @@ -68,13 +69,15 @@ public IActionResult UploadImage([FromServices] WtmFileProvider fp,int? width =

[HttpGet("[action]/{id}")]
[ActionDescription("GetFileName")]
[Public]
public IActionResult GetFileName([FromServices] WtmFileProvider fp, string id, string csName = null)
{
return Ok(fp.GetFileName(id, ConfigInfo.CreateDC(csName)));
}

[HttpGet("[action]/{id}")]
[ActionDescription("GetFile")]
[Public]
public async Task<IActionResult> GetFile([FromServices] WtmFileProvider fp, string id, string csName = null, int? width = null, int? height = null)
{
var file = fp.GetFile(id, true, ConfigInfo.CreateDC(csName));
Expand All @@ -88,7 +91,7 @@ public async Task<IActionResult> GetFile([FromServices] WtmFileProvider fp, stri
{
if (width != null || height != null)
{
Image oimage = Image.FromStream(file.DataStream);
Image oimage = Image.Load(file.DataStream);
if (oimage != null)
{
if (width == null)
Expand All @@ -100,7 +103,7 @@ public async Task<IActionResult> GetFile([FromServices] WtmFileProvider fp, stri
height = oimage.Height * width / oimage.Width;
}
var ms = new MemoryStream();
oimage.GetThumbnailImage(width.Value, height.Value, null, IntPtr.Zero).Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
oimage.Mutate(x => x.Resize(width.Value, height.Value));
ms.Position = 0;
await ms?.CopyToAsync(Response.Body);
file.DataStream.Dispose();
Expand All @@ -127,6 +130,7 @@ public async Task<IActionResult> GetFile([FromServices] WtmFileProvider fp, stri

[HttpGet("[action]/{id}")]
[ActionDescription("DownloadFile")]
[Public]
public IActionResult DownloadFile([FromServices] WtmFileProvider fp, string id, string csName = null)
{
var file = fp.GetFile(id, true, ConfigInfo.CreateDC(csName));
Expand All @@ -149,7 +153,7 @@ public IActionResult DownloadFile([FromServices] WtmFileProvider fp, string id,
public IActionResult DeletedFile([FromServices] WtmFileProvider fp, string id, string csName = null)
{
fp.DeleteFile(id, ConfigInfo.CreateDC(csName));
return Ok();
return Ok(true);
}
}
}
20 changes: 20 additions & 0 deletions demo/WalkingTec.Mvvm.ConsoleDemo/JobTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using WalkingTec.Mvvm.Core.Support.Quartz;

namespace WalkingTec.Mvvm.ConsoleDemo
{
[QuartzRepeat(5,0,true)]
public class JobTest : WtmJob
{
public override Task Execute(IJobExecutionContext context)
{
Wtm.DoLog("test");
return Task.CompletedTask;
}
}
}
7 changes: 5 additions & 2 deletions demo/WalkingTec.Mvvm.ConsoleDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using WalkingTec.Mvvm.Core.Support.FileHandlers;
using WalkingTec.Mvvm.Core.Support.Quartz;
using WalkingTec.Mvvm.Demo;
using WalkingTec.Mvvm.Demo.Models;
using WalkingTec.Mvvm.Demo.ViewModels.CityVMs;
Expand All @@ -24,7 +26,7 @@ static void Main(string[] args)
{
Console.WriteLine("Start...");
DateTime check = DateTime.Now;
StartUp();
StartUpAsync();
Console.WriteLine(DateTime.Now.Subtract(check).TotalSeconds);
//var context = GetWtmContext();
//var test = context.CallAPI("baidu","/").Result;
Expand All @@ -36,11 +38,12 @@ static void Main(string[] args)
Console.ReadLine();
}

static void StartUp()
static void StartUpAsync()
{
var services = new ServiceCollection();
services.AddWtmContextForConsole();
Provider = services.BuildServiceProvider();
_= Provider.GetRequiredService<QuartzHostService>().StartAsync(new System.Threading.CancellationToken());
}

static WTMContext GetWtmContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\WalkingTec.Mvvm.Core\WalkingTec.Mvvm.Core.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// WTM默认页面 Wtm buidin page
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
Expand All @@ -21,24 +21,24 @@ public class FileApiController : BaseApiController
{
[HttpPost("[action]")]
[ActionDescription("UploadFile")]
public IActionResult Upload([FromServices] WtmFileProvider fp, string sm = null, string groupName = null, string subdir=null,string extra = null,string csName= null)
public IActionResult Upload([FromServices] WtmFileProvider fp, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
{
var FileData = Request.Form.Files[0];
var file = fp.Upload(FileData.FileName, FileData.Length, FileData.OpenReadStream(),groupName,subdir,extra,sm,Wtm.CreateDC(cskey:csName));
var file = fp.Upload(FileData.FileName, FileData.Length, FileData.OpenReadStream(), groupName, subdir, extra, sm, Wtm.CreateDC(cskey: csName));
return Ok(new { Id = file.GetID(), Name = file.FileName });
}

[HttpPost("[action]")]
[ActionDescription("UploadPic")]
public IActionResult UploadImage([FromServices] WtmFileProvider fp,int? width = null, int? height = null, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
public IActionResult UploadImage([FromServices] WtmFileProvider fp, int? width = null, int? height = null, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
{
if (width == null && height == null)
{
return Upload(fp,sm,groupName,csName);
return Upload(fp, sm, groupName, csName);
}
var FileData = Request.Form.Files[0];

Image oimage = Image.FromStream(FileData.OpenReadStream());
Image oimage = Image.Load(FileData.OpenReadStream());
if (oimage == null)
{
return BadRequest(Localizer["Sys.UploadFailed"]);
Expand All @@ -52,9 +52,10 @@ public IActionResult UploadImage([FromServices] WtmFileProvider fp,int? width =
height = width * oimage.Height / oimage.Width;
}
MemoryStream ms = new MemoryStream();
oimage.GetThumbnailImage(width.Value, height.Value, null, IntPtr.Zero).Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
oimage.Mutate(x => x.Resize(width.Value, height.Value));
oimage.SaveAsJpeg(ms);
ms.Position = 0;
var file = fp.Upload(FileData.FileName, FileData.Length, ms, groupName,subdir, extra, sm, Wtm.CreateDC(cskey: csName));
var file = fp.Upload(FileData.FileName, FileData.Length, ms, groupName, subdir, extra, sm, Wtm.CreateDC(cskey: csName));
oimage.Dispose();
ms.Dispose();

Expand All @@ -68,13 +69,15 @@ public IActionResult UploadImage([FromServices] WtmFileProvider fp,int? width =

[HttpGet("[action]/{id}")]
[ActionDescription("GetFileName")]
[Public]
public IActionResult GetFileName([FromServices] WtmFileProvider fp, string id, string csName = null)
{
return Ok(fp.GetFileName(id, ConfigInfo.CreateDC(csName)));
}

[HttpGet("[action]/{id}")]
[ActionDescription("GetFile")]
[Public]
public async Task<IActionResult> GetFile([FromServices] WtmFileProvider fp, string id, string csName = null, int? width = null, int? height = null)
{
var file = fp.GetFile(id, true, ConfigInfo.CreateDC(csName));
Expand All @@ -88,7 +91,7 @@ public async Task<IActionResult> GetFile([FromServices] WtmFileProvider fp, stri
{
if (width != null || height != null)
{
Image oimage = Image.FromStream(file.DataStream);
Image oimage = Image.Load(file.DataStream);
if (oimage != null)
{
if (width == null)
Expand All @@ -100,7 +103,7 @@ public async Task<IActionResult> GetFile([FromServices] WtmFileProvider fp, stri
height = oimage.Height * width / oimage.Width;
}
var ms = new MemoryStream();
oimage.GetThumbnailImage(width.Value, height.Value, null, IntPtr.Zero).Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
oimage.Mutate(x => x.Resize(width.Value, height.Value));
ms.Position = 0;
await ms?.CopyToAsync(Response.Body);
file.DataStream.Dispose();
Expand All @@ -127,6 +130,7 @@ public async Task<IActionResult> GetFile([FromServices] WtmFileProvider fp, stri

[HttpGet("[action]/{id}")]
[ActionDescription("DownloadFile")]
[Public]
public IActionResult DownloadFile([FromServices] WtmFileProvider fp, string id, string csName = null)
{
var file = fp.GetFile(id, true, ConfigInfo.CreateDC(csName));
Expand All @@ -149,7 +153,7 @@ public IActionResult DownloadFile([FromServices] WtmFileProvider fp, string id,
public IActionResult DeletedFile([FromServices] WtmFileProvider fp, string id, string csName = null)
{
fp.DeleteFile(id, ConfigInfo.CreateDC(csName));
return Ok();
return Ok(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace WalkingTec.Mvvm.Admin.Api
[ActionDescription("_Admin.UserApi")]
[ApiController]
[Route("api/_FrameworkUser")]
[Area("_Admin")]
public class FrameworkUserController : BaseApiController
{
[ActionDescription("Sys.Search")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</wt:form>
<script>
DbTypeChange({ value: $("[name='DpType'][checked]").val() });
IsAllChange({ value: '@Model.IsAll.ToString().ToLower()' });
IsAllChange({ arr:[ {value: '@Model.IsAll.ToString().ToLower()' }]});
var selectedtablename = "@Model.Entity.TableName";
function DbTypeChange(data) {
if (data.value == 'UserGroup') {
Expand All @@ -39,15 +39,15 @@
}
}
function IsAllChange(data) {
if (data.value == 'true') {
if ( data.arr[0].value == 'true') {
$('#selector').css('display', 'none');
}
else {
$('#selector').css('display', 'block');
}
}
function PriTypeChange(data) {
selectedtablename = data.value;
selectedtablename = data.arr[0].value;
ff.clearSelector("DataPrivilegeVM_SelectedItemsID");
}
function SetTableName() {
Expand Down
Loading

0 comments on commit 1b745e0

Please sign in to comment.