From 66993750431e0aad0ea937a5e883122eb5df933b Mon Sep 17 00:00:00 2001 From: liangkun Date: Mon, 22 Aug 2022 18:17:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Modules/AnnexesApiWx.cs | 260 +++++++++--------- .../components/learun-app/upload-file.vue | 2 +- .../LearunApp-2.2.0/config.js | 4 +- 3 files changed, 133 insertions(+), 133 deletions(-) diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs index 4795d3d47..4054c0a35 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs @@ -7,136 +7,136 @@ using System.IO; namespace Learun.Application.WebApi.Modules { - public class AnnexesApiWx : BaseApi - { - public AnnexesApiWx() - : base("/learun/adms/annexes") + public class AnnexesApiWx : BaseApi { - Get["/wxlist"] = WxGetList; - Get["/wxdown"] = WxDownload; - Get["/wxfileinfo"] = WxFileInfo; - Post["/wxupload"] = WxUpload; - Post["/wxdelete"] = WxDeleteFile; + public AnnexesApiWx() + : base("/learun/adms/annexes") + { + Get["/wxlist"] = WxGetList; + Get["/wxdown"] = WxDownload; + Get["/wxfileinfo"] = WxFileInfo; + Post["/wxupload"] = WxUpload; + Post["/wxdelete"] = WxDeleteFile; + } + private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL(); + + /// + /// 获取附件列表 + /// + /// + /// + public Response WxGetList(dynamic _) + { + var keyValue = this.GetReqData(); + var list = annexesFileIBLL.GetList(keyValue); + + return Success(list); + } + + /// + /// 上传附件图片文件 + /// + /// + public Response WxUpload(dynamic _) + { + var files = (List)this.Context.Request.Files; + //var folderId = this.GetReqData(); + string folderId = Guid.NewGuid().ToString(); + string filePath = Config.GetValue("AnnexesFile"); + string uploadDate = DateTime.Now.ToString("yyyyMMdd"); + string fileEextension = Path.GetExtension(files[0].Name); + string fileType = fileEextension.Replace(".", ""); + string fileGuid = Guid.NewGuid().ToString(); + + string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, fileEextension); + + //创建文件夹 + string path = Path.GetDirectoryName(virtualPath); + Directory.CreateDirectory(path); + AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity(); + if (!System.IO.File.Exists(virtualPath)) + { + byte[] bytes = new byte[files[0].Value.Length]; + files[0].Value.Read(bytes, 0, bytes.Length); + FileInfo file = new FileInfo(virtualPath); + FileStream fs = file.Create(); + fs.Write(bytes, 0, bytes.Length); + fs.Close(); + + //文件信息写入数据库 + fileAnnexesEntity.F_Id = fileGuid; + fileAnnexesEntity.F_FileName = files[0].Name; + fileAnnexesEntity.F_FilePath = virtualPath; + fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString(); + fileAnnexesEntity.F_FileExtensions = fileEextension; + fileAnnexesEntity.F_FileType = fileType; + fileAnnexesEntity.F_CreateUserId = userInfo.userId; + fileAnnexesEntity.F_CreateUserName = userInfo.realName; + + annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity); + } + + return SuccessString(folderId); + } + + /// + /// 获取文件信息 + /// + /// + /// + public Response WxFileInfo(dynamic _) + { + var fileId = this.GetReqData(); + var fileEntity = annexesFileIBLL.GetEntity(fileId); + + return Success(fileEntity); + } + + /// + /// 删除文件 + /// + /// + /// + public Response WxDeleteFile(dynamic _) + { + var fileId = this.GetReqData(); + AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId); + annexesFileIBLL.DeleteEntity(fileId); + //删除文件 + if (System.IO.File.Exists(fileInfoEntity.F_FilePath)) + { + System.IO.File.Delete(fileInfoEntity.F_FilePath); + } + + return Success("删除成功"); + } + + /// + /// 下载文件,微信小程序用 + /// + /// 微信小程序可以预览图片、文档 + /// 支持的图片格式:.jpg .png .webp .gif + /// 支持的文档格式:.doc(x) .xls(x) .ppt(x) .pdf + /// + /// 对于其他格式的文件,微信小程序官方未提供打开或预览的 API,文件对用户来说不可访问 + /// + /// + /// + public Response WxDownload(dynamic _) + { + string name = this.GetReqData(); + string fileId = name.Split('.')[0]; + var fileEntity = annexesFileIBLL.GetEntity(fileId); + string filepath = fileEntity.F_FilePath; + + if (!FileDownHelper.FileExists(filepath)) + { + return 404; + } + + FileDownHelper.DownLoadWx(filepath, fileEntity.F_FileType); + + return Success(""); + } } - private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL(); - - /// - /// 获取附件列表 - /// - /// - /// - public Response WxGetList(dynamic _) - { - var keyValue = this.GetReqData(); - var list = annexesFileIBLL.GetList(keyValue); - - return Success(list); - } - - /// - /// 上传附件图片文件 - /// - /// - public Response WxUpload(dynamic _) - { - var files = (List)this.Context.Request.Files; - var folderId = this.GetReqData(); - - string filePath = Config.GetValue("AnnexesFile"); - string uploadDate = DateTime.Now.ToString("yyyyMMdd"); - string fileEextension = Path.GetExtension(files[0].Name); - string fileType = fileEextension.Replace(".", ""); - string fileGuid = Guid.NewGuid().ToString(); - - string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, fileEextension); - - //创建文件夹 - string path = Path.GetDirectoryName(virtualPath); - Directory.CreateDirectory(path); - AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity(); - if (!System.IO.File.Exists(virtualPath)) - { - byte[] bytes = new byte[files[0].Value.Length]; - files[0].Value.Read(bytes, 0, bytes.Length); - FileInfo file = new FileInfo(virtualPath); - FileStream fs = file.Create(); - fs.Write(bytes, 0, bytes.Length); - fs.Close(); - - //文件信息写入数据库 - fileAnnexesEntity.F_Id = fileGuid; - fileAnnexesEntity.F_FileName = files[0].Name; - fileAnnexesEntity.F_FilePath = virtualPath; - fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString(); - fileAnnexesEntity.F_FileExtensions = fileEextension; - fileAnnexesEntity.F_FileType = fileType; - fileAnnexesEntity.F_CreateUserId = userInfo.userId; - fileAnnexesEntity.F_CreateUserName = userInfo.realName; - - annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity); - } - - return SuccessString(fileGuid); - } - - /// - /// 获取文件信息 - /// - /// - /// - public Response WxFileInfo(dynamic _) - { - var fileId = this.GetReqData(); - var fileEntity = annexesFileIBLL.GetEntity(fileId); - - return Success(fileEntity); - } - - /// - /// 删除文件 - /// - /// - /// - public Response WxDeleteFile(dynamic _) - { - var fileId = this.GetReqData(); - AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId); - annexesFileIBLL.DeleteEntity(fileId); - //删除文件 - if (System.IO.File.Exists(fileInfoEntity.F_FilePath)) - { - System.IO.File.Delete(fileInfoEntity.F_FilePath); - } - - return Success("删除成功"); - } - - /// - /// 下载文件,微信小程序用 - /// - /// 微信小程序可以预览图片、文档 - /// 支持的图片格式:.jpg .png .webp .gif - /// 支持的文档格式:.doc(x) .xls(x) .ppt(x) .pdf - /// - /// 对于其他格式的文件,微信小程序官方未提供打开或预览的 API,文件对用户来说不可访问 - /// - /// - /// - public Response WxDownload(dynamic _) - { - string name = this.GetReqData(); - string fileId = name.Split('.')[0]; - var fileEntity = annexesFileIBLL.GetEntity(fileId); - string filepath = fileEntity.F_FilePath; - - if (!FileDownHelper.FileExists(filepath)) - { - return 404; - } - - FileDownHelper.DownLoadWx(filepath, fileEntity.F_FileType); - - return Success(""); - } - } } \ No newline at end of file diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/learun-app/upload-file.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/learun-app/upload-file.vue index 969f835be..e2300312a 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/learun-app/upload-file.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/learun-app/upload-file.vue @@ -89,7 +89,7 @@ export default { // #endif // #ifndef MP-DINGTALK - uni.chooseImage({ + uni.chooseFile({ count: Number(this.number), sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/config.js b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/config.js index c0c228cb7..7670bf973 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/config.js +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/config.js @@ -21,8 +21,8 @@ export default { // "http://192.168.2.98:8088/" // ], "apiHost": [ - "http://localhost:31173/" - // "http://192.168.10.85:8088/" + // "http://localhost:31173/" + "http://192.168.10.68:8002/" ], "webHost":"http://localhost:20472/", // 开发环境下自动填充登录账号密码,与接口地址一一对应,只在开发环境下显示