diff --git a/WebFirst/database/sqlite.db b/WebFirst/database/sqlite.db index 2278b841..1a87a4ba 100644 Binary files a/WebFirst/database/sqlite.db and b/WebFirst/database/sqlite.db differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index b05d0639..8b75f66e 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -90,6 +90,34 @@ + + + 文件 + + + + + 使用本地存储,未进行数据库记录 + + + + + + + 文件下载 + + + + + + + + 文件上传 + + + + + 自动分表,日志添加 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs new file mode 100644 index 00000000..5890bc4a --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs @@ -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 +{ + /// + /// 文件 + /// + [Route("api/[controller]/[action]")] + [ApiController] + public class FileController : ControllerBase + { + private IUserService _iUserService; + private readonly IHostEnvironment _env; + /// + /// 使用本地存储,未进行数据库记录 + /// + /// + /// + public FileController(IUserService iUserService, IHostEnvironment env) + { + _iUserService = iUserService; + _env = env; + } + + /// + /// 文件下载 + /// + /// + /// + /// + [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(); + } + } + + /// + /// 文件上传 + /// + /// + /// + /// + [Route("/api/Upload/{type}")] + [HttpPost] + public async Task 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 ExportFile() + //{ + // var userdata = await _userService.GetAllEntitiesTrueAsync(); + // var userList = userdata.ToList(); + // List 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); + //} + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/0880c226-24a1-4bbd-9603-e6729e4047fd.jpg b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/0880c226-24a1-4bbd-9603-e6729e4047fd.jpg new file mode 100644 index 00000000..aa4daf73 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/0880c226-24a1-4bbd-9603-e6729e4047fd.jpg differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/893bc7db-94a6-450e-9997-41ad4c5fd534.jpg b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/893bc7db-94a6-450e-9997-41ad4c5fd534.jpg new file mode 100644 index 00000000..aa4daf73 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/893bc7db-94a6-450e-9997-41ad4c5fd534.jpg differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/9cc04242-1f4d-4877-bfd5-95f7a56c9f9c.jpg b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/9cc04242-1f4d-4877-bfd5-95f7a56c9f9c.jpg new file mode 100644 index 00000000..aa4daf73 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/9cc04242-1f4d-4877-bfd5-95f7a56c9f9c.jpg differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/bdd108b2-a475-43dd-ab73-a1715162c0e5.jpg b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/bdd108b2-a475-43dd-ab73-a1715162c0e5.jpg new file mode 100644 index 00000000..aa4daf73 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/bdd108b2-a475-43dd-ab73-a1715162c0e5.jpg differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index f9c19a9a..3913d1ee 100644 Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ diff --git a/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/UserEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/UserEntity.cs index 4e44a847..71eac2ad 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/UserEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/UserEntity.cs @@ -78,7 +78,7 @@ namespace Yi.Framework.Model.Models /// /// [SugarColumn(ColumnName="Icon" )] - public long? Icon { get; set; } + public string Icon { get; set; } /// /// /// diff --git a/Yi.Vue2.x/src/api/fileApi.js b/Yi.Vue2.x/src/api/fileApi.js index 3b653b07..ca68ffcc 100644 --- a/Yi.Vue2.x/src/api/fileApi.js +++ b/Yi.Vue2.x/src/api/fileApi.js @@ -1,8 +1,8 @@ import myaxios from '@/util/myaxios' export default { - EditIcon(file) { + UploadImage(file) { return myaxios({ - url: '/File/EditIcon', + url: '/Upload/image', method: 'post', headers: { "Content-Type": "multipart/form-data" }, data: file diff --git a/Yi.Vue2.x/src/store/modules/user.js b/Yi.Vue2.x/src/store/modules/user.js index 6cf6508c..932d94de 100644 --- a/Yi.Vue2.x/src/store/modules/user.js +++ b/Yi.Vue2.x/src/store/modules/user.js @@ -38,6 +38,7 @@ const mutations = { //变化//载荷 }, SET_USER(state, user) { state.user = user + console.log(user) setUser(user) }, SetGradient(state, gradient) { @@ -50,7 +51,7 @@ const mutations = { //变化//载荷 //在action中可以配合axios进行权限判断 const actions = { //动作 - setIcon({ commit, state }, icon) { + SetIcon({ commit, state }, icon) { state.user.icon = icon commit('SET_USER', state.user) }, diff --git a/Yi.Vue2.x/src/views/userInfo.vue b/Yi.Vue2.x/src/views/userInfo.vue index 5dd17dc2..de576c82 100644 --- a/Yi.Vue2.x/src/views/userInfo.vue +++ b/Yi.Vue2.x/src/views/userInfo.vue @@ -272,7 +272,6 @@