From d5d90877af23614a3fd33ec07459d19bc16bcc13 Mon Sep 17 00:00:00 2001 From: dyy <807692433@qq.com> Date: Wed, 14 Sep 2022 17:38:50 +0800 Subject: [PATCH] =?UTF-8?q?app2.0=EF=BC=9A=E5=8D=95=E7=8B=AC=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=AD=E9=99=84=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Modules/AnnexesApiWx.cs | 65 +++++++++++++++++-- .../Modules/StuInfoFreshApi.cs | 7 +- .../components/upload-file.vue | 44 +++++++------ .../Acc_DailyAssess/single.vue | 62 ++++++++++-------- 4 files changed, 126 insertions(+), 52 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 8d754269b..3f345891b 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs @@ -17,6 +17,7 @@ namespace Learun.Application.WebApi.Modules Get["/wxfileinfo"] = WxFileInfo; Post["/wxupload"] = WxUpload; Post["/wxdelete"] = WxDeleteFile; + Post["/wxuploadinsingle"] = WxUploadInSingle; } private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL(); @@ -78,6 +79,52 @@ namespace Learun.Application.WebApi.Modules return SuccessString(folderId); } + /// + /// 上传附件图片文件【移动端app2.0,单独页面中的附件图片上传使用方法】 + /// + /// + public Response WxUploadInSingle(dynamic _) + { + var files = (List)this.Context.Request.Files; + var folderId = this.GetReq().folderId; + var name = this.GetReq().name; + + string filePath = Config.GetValue("AnnexesFile"); + string uploadDate = DateTime.Now.ToString("yyyyMMdd"); + string FileEextension = Path.GetExtension(name); + 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_FolderId = folderId; + fileAnnexesEntity.F_FileName = name; + fileAnnexesEntity.F_FilePath = virtualPath; + fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString(); + fileAnnexesEntity.F_FileExtensions = FileEextension; + fileAnnexesEntity.F_FileType = FileEextension.Replace(".", ""); + fileAnnexesEntity.F_CreateUserId = userInfo.userId; + fileAnnexesEntity.F_CreateUserName = userInfo.realName; + + annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity); + } + return SuccessString(folderId); + } + /// /// 获取文件信息 /// @@ -100,11 +147,14 @@ namespace Learun.Application.WebApi.Modules { var fileId = this.GetReqData(); AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId); - annexesFileIBLL.DeleteEntity(fileId); - //删除文件 - if (System.IO.File.Exists(fileInfoEntity.F_FilePath)) + if (fileInfoEntity != null) { - System.IO.File.Delete(fileInfoEntity.F_FilePath); + annexesFileIBLL.DeleteEntity(fileId); + //删除文件 + if (System.IO.File.Exists(fileInfoEntity.F_FilePath)) + { + System.IO.File.Delete(fileInfoEntity.F_FilePath); + } } return Success("删除成功"); @@ -137,5 +187,12 @@ namespace Learun.Application.WebApi.Modules return Success(""); } + + public class FileModel + { + public string folderId { get; set; } + public string name { get; set; } + public string id { get; set; } + } } } \ No newline at end of file diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/StuInfoFreshApi.cs b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/StuInfoFreshApi.cs index e02ed891c..a62f1297c 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/StuInfoFreshApi.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/StuInfoFreshApi.cs @@ -362,7 +362,8 @@ namespace Learun.Application.WebApi.Modules string filePath = Config.GetValue("AnnexesFile"); string uploadDate = DateTime.Now.ToString("yyyyMMdd"); - string FileEextension = name; + //string FileEextension = name; + string FileEextension = Path.GetExtension(name); string fileGuid = Guid.NewGuid().ToString(); string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, FileEextension); @@ -395,9 +396,9 @@ namespace Learun.Application.WebApi.Modules } //文件地址截取到resource后 - fileAnnexesEntity.F_FilePath = fileAnnexesEntity.F_FilePath.Substring(fileAnnexesEntity.F_FilePath.IndexOf("Resource")); + //fileAnnexesEntity.F_FilePath = fileAnnexesEntity.F_FilePath.Substring(fileAnnexesEntity.F_FilePath.IndexOf("Resource")); - return Success(fileAnnexesEntity); + return SuccessString(folderId); } /// diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue index cf6d0db6b..96b323964 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue @@ -1,8 +1,13 @@ @@ -161,10 +157,13 @@ import get from 'lodash/get' import set from 'lodash/set' import moment from 'moment' import customPageMixins from '@/common/custompage.js' +import uploadFile from '@/components/upload-file.vue' export default { mixins: [customPageMixins], - + components:{ + uploadFile, + }, data() { return { // 页面相关参数 @@ -172,6 +171,8 @@ export default { mode: null, edit: null, ready: false, + fileList:[],//附件列表 + folderId:null,//附件随机文件夹id // 表单数据 current: {}, @@ -194,7 +195,7 @@ export default { AddScore: { type: 'text', title: '纪律奖分' }, MinusScore: { type: 'text', title: '纪律扣分' }, Reason: { type: 'textarea', title: '奖扣分原因' , verify: 'NotNull'}, - Files: { type: "upload", title: "附件上传" }, + Files: { type: "text", title: "附件上传" }, }, }, @@ -223,6 +224,9 @@ export default { methods: { // 页面初始化 async init(type, id) { + this.folderId=this.GUID(); + // console.log('附件随机文件夹id:'+this.folderId); + this.LOADING('加载数据中...') this.id = id @@ -269,11 +273,27 @@ export default { async fetchForm() { if (this.mode === 'create') { this.origin = await this.getDefaultForm() + } else { const result = await this.HTTP_GET('learun/adms/LogisticsManagement/Acc_DailyAssess/form', this.id) this.origin = await this.formatFormData(result) } - this.current = this.COPY(this.origin) + this.current = this.COPY(this.origin) + + //加载附件值数据 + // console.log('附件值赋值前:'+this.getValue('Acc_DailyAssess.Files')); + if (this.getValue('Acc_DailyAssess.Files') == ""||this.getValue('Acc_DailyAssess.Files') == undefined ||this.getValue('Acc_DailyAssess.Files') == null) { + this.setValue('Acc_DailyAssess.Files',this.folderId); + // console.log('附件值赋值后:'+this.getValue('Acc_DailyAssess.Files')); + }else{ + this.folderId=this.getValue('Acc_DailyAssess.Files'); + // console.log('文件夹id赋值后:'+this.folderId); + //请求‘获取附件列表’接口 + this.fileList = await this.FETCH_FILEList(this.getValue('Acc_DailyAssess.Files')); + } + + // console.log('origin:'+JSON.stringify(this.origin) ) + // console.log('current:'+JSON.stringify(this.current)) }, // 点击 「编辑」、「重置」、「保存」、「删除」 按钮 @@ -289,13 +309,7 @@ export default { break case 'save': - const postData = await this.getPostData(this.id) - - console.log(postData); - - const verifyResult = this.verifyForm() - console.log(verifyResult); if (verifyResult.length > 0) { this.CONFIRM('表单验证失败', verifyResult.join('\n')) return @@ -307,12 +321,8 @@ export default { this.LOADING('正在提交...') - //const postData = await this.getPostData(this.id) - - //console.log(postData); - return false; - - + const postData = await this.getPostData(this.id) + console.log('页面提交数据:'+JSON.stringify(postData)); this.HTTP_POST('learun/adms/LogisticsManagement/Acc_DailyAssess/save', postData, '表单提交保存失败').then(success => { this.HIDE_LOADING()