Quellcode durchsuchen

app2.0:单独页面中附件上传功能;

临城职教中职
dyy vor 2 Jahren
Ursprung
Commit
d5d90877af
4 geänderte Dateien mit 126 neuen und 52 gelöschten Zeilen
  1. +61
    -4
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs
  2. +4
    -3
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/StuInfoFreshApi.cs
  3. +25
    -19
      Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue
  4. +36
    -26
      Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/LogisticsManagement/Acc_DailyAssess/single.vue

+ 61
- 4
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs Datei anzeigen

@@ -17,6 +17,7 @@ namespace Learun.Application.WebApi.Modules
Get["/wxfileinfo"] = WxFileInfo; Get["/wxfileinfo"] = WxFileInfo;
Post["/wxupload"] = WxUpload; Post["/wxupload"] = WxUpload;
Post["/wxdelete"] = WxDeleteFile; Post["/wxdelete"] = WxDeleteFile;
Post["/wxuploadinsingle"] = WxUploadInSingle;
} }
private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL(); private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();


@@ -78,6 +79,52 @@ namespace Learun.Application.WebApi.Modules
return SuccessString(folderId); return SuccessString(folderId);
} }


/// <summary>
/// 上传附件图片文件【移动端app2.0,单独页面中的附件图片上传使用方法】
/// <summary>
/// <returns></returns>
public Response WxUploadInSingle(dynamic _)
{
var files = (List<HttpFile>)this.Context.Request.Files;
var folderId = this.GetReq<FileModel>().folderId;
var name = this.GetReq<FileModel>().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);
}

/// <summary> /// <summary>
/// 获取文件信息 /// 获取文件信息
/// </summary> /// </summary>
@@ -100,11 +147,14 @@ namespace Learun.Application.WebApi.Modules
{ {
var fileId = this.GetReqData(); var fileId = this.GetReqData();
AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId); 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("删除成功"); return Success("删除成功");
@@ -137,5 +187,12 @@ namespace Learun.Application.WebApi.Modules


return Success(""); return Success("");
} }

public class FileModel
{
public string folderId { get; set; }
public string name { get; set; }
public string id { get; set; }
}
} }
} }

+ 4
- 3
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/StuInfoFreshApi.cs Datei anzeigen

@@ -362,7 +362,8 @@ namespace Learun.Application.WebApi.Modules


string filePath = Config.GetValue("AnnexesFile"); string filePath = Config.GetValue("AnnexesFile");
string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string uploadDate = DateTime.Now.ToString("yyyyMMdd");
string FileEextension = name;
//string FileEextension = name;
string FileEextension = Path.GetExtension(name);
string fileGuid = Guid.NewGuid().ToString(); string fileGuid = Guid.NewGuid().ToString();


string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, FileEextension); 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后 //文件地址截取到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);
} }


/// <summary> /// <summary>


+ 25
- 19
Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue Datei anzeigen

@@ -1,8 +1,13 @@
<template> <template>
<view class="cu-form-group"> <view class="cu-form-group">
<view class="grid">
<view class="title">
附件上传
</view>
</view>
<view class="grid col-4 grid-square flex-sub"> <view class="grid col-4 grid-square flex-sub">
<view v-for="(item, index) in imgList" @tap="viewImg(item)" :key="index" class="bg-img"> <view v-for="(item, index) in imgList" @tap="viewImg(item)" :key="index" class="bg-img">
<image v-if="showfile()&&item&&(typeof item == "string"||isImage(item.type))" :src="item.url?CONFIG('webHost') + item.url:item" mode="aspectFill">
<image v-if="showfile()&&item&&(typeof item == 'string'||isImage(item.type))" :src="item.url?CONFIG('webHost') + item.url:item" mode="aspectFill">
</image> </image>
<l-icon v-if="showfile()&&!isImage(item.type)" type="text" /> <l-icon v-if="showfile()&&!isImage(item.type)" type="text" />
<text class="file-name">{{item.name}}</text> <text class="file-name">{{item.name}}</text>
@@ -13,7 +18,6 @@
</view> </view>


<view v-show="!readonly && imgList.length < Number(number)&&isShow" class="solids"> <view v-show="!readonly && imgList.length < Number(number)&&isShow" class="solids">
<!-- @tap="chooseImg" -->
<l-icon type="file" /> <l-icon type="file" />
<lsj-upload ref="lsjUpload" height="80px" width="100%" :size="20" :option="{}" :count="1" <lsj-upload ref="lsjUpload" height="80px" width="100%" :size="20" :option="{}" :count="1"
@change="chooseChange" style="opacity: 0;"></lsj-upload> @change="chooseChange" style="opacity: 0;"></lsj-upload>
@@ -64,9 +68,7 @@
if(!res)return if(!res)return
this.LOADING('正在删除…'); this.LOADING('正在删除…');
const newList = JSON.parse(JSON.stringify(this.imgList)); const newList = JSON.parse(JSON.stringify(this.imgList));
this.HTTP_POST('StuInfoFresh/deleteFiles', {
id: this.imgList[index].id
}, "文件删除失败").then((data) => {
this.HTTP_POST('/learun/adms/annexes/wxdelete', this.imgList[index].id, "文件删除失败").then((data) => {
this.HIDE_LOADING(); this.HIDE_LOADING();
if (data) { if (data) {
newList.splice(index, 1); newList.splice(index, 1);
@@ -89,7 +91,17 @@
let uploadImageRes = await this.uploadImage(tempFilePaths[0], tempFiles[0] ? tempFiles[0].name : "") let uploadImageRes = await this.uploadImage(tempFilePaths[0], tempFiles[0] ? tempFiles[0].name : "")
let newList = this.imgList || [] let newList = this.imgList || []
if (uploadImageRes) { if (uploadImageRes) {
newList = JSON.parse(JSON.stringify(newList)).concat(uploadImageRes);
//请求‘获取附件列表’接口
let data = await this.FETCH_FILEList(uploadImageRes);
if(data){
newList = data.map(t=>({
id: t.F_Id,
name: t.F_FileName,
url: t.F_FilePath.substring(t.F_FilePath.indexOf('Resource')),
type: t.F_FileType,
folderid:t.F_FolderId,
}))
}
} }


this.imgList = newList this.imgList = newList
@@ -97,7 +109,6 @@
this.$emit("update:value", newList); this.$emit("update:value", newList);
this.$emit("input", newList); this.$emit("input", newList);
this.$emit("change", newList); this.$emit("change", newList);
// this.$emit("add");
}, },


uploadImage(url, name) { uploadImage(url, name) {
@@ -111,17 +122,11 @@
} : { } : {
folderId: this.folderId folderId: this.folderId
} }
this.HTTP_UPLOAD2('StuInfoFresh/upload', url, params).then((data) => {
this.HTTP_UPLOAD2('/learun/adms/annexes/wxuploadinsingle', url, params).then((data) => {
this.HIDE_LOADING(); this.HIDE_LOADING();
this.$refs.lsjUpload.show() this.$refs.lsjUpload.show()
if (data) { if (data) {
// this.HTTP_GET('StuInfoFresh/upload', {fileId:data})
reslove([{
id: data.F_Id,
name: data.F_FileName,
url: data.F_FilePath,
type: data.F_FileType,
}])
reslove(data)
} else { } else {
reject('上传失败!') reject('上传失败!')
} }
@@ -167,13 +172,14 @@
}, },
}, },
created() { created() {
console.log(this.value)
// console.log(this.value)
this.imgList = JSON.parse(JSON.stringify(this.value.map(item => { this.imgList = JSON.parse(JSON.stringify(this.value.map(item => {
return { return {
id: item.F_Id, id: item.F_Id,
name: item.F_FileName, name: item.F_FileName,
url: item.F_FilePath,
type: item.F_FileType
url: item.F_FilePath.substring(item.F_FilePath.indexOf('Resource')),
type: item.F_FileType,
folderid:item.F_FolderId,
} }
}))) })))
this.$nextTick(() => { this.$nextTick(() => {
@@ -189,7 +195,7 @@
bottom: 0; bottom: 0;
width: 100%; width: 100%;
color: #606266; color: #606266;
font-size: 13px;
font-size: 12px;
text-align: center; text-align: center;
background-color: rgba(255, 255, 255, 0.6); background-color: rgba(255, 255, 255, 0.6);




+ 36
- 26
Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/LogisticsManagement/Acc_DailyAssess/single.vue Datei anzeigen

@@ -111,29 +111,25 @@
required required
/> />
<!-- 附件上传 --> <!-- 附件上传 -->
<!-- todo: -->
<l-upload-file
<l-input
@input="setValue('Acc_DailyAssess.Files', $event)" @input="setValue('Acc_DailyAssess.Files', $event)"
:value="getValue('Acc_DailyAssess.Files')" :value="getValue('Acc_DailyAssess.Files')"
:readonly="!edit"
:number="3"
title="附件上传"
disabled="disabled"
v-show="false"
title="附件"
/> />
<uploadFile :number="5" :folderId="folderId" :value="fileList" :readonly="!edit"></uploadFile>
</view> </view>
<view v-if="ready" class="bg-white margin-tb padding" style="padding-top: 0; overflow: hidden;"> <view v-if="ready" class="bg-white margin-tb padding" style="padding-top: 0; overflow: hidden;">
<l-button v-if="edit" @click="action('save')" size="lg" color="green" class="block margin-top" block> <l-button v-if="edit" @click="action('save')" size="lg" color="green" class="block margin-top" block>
提交保存 提交保存
</l-button> </l-button>
<!-- <l-button v-if="!edit && mode !== 'create'" @click="action('edit')" size="lg" line="orange" class="block margin-top" block>
编辑本页
</l-button> -->
<l-button v-if="edit && mode !== 'create'" @click="action('reset')" size="lg" line="red" class="block margin-top" block> <l-button v-if="edit && mode !== 'create'" @click="action('reset')" size="lg" line="red" class="block margin-top" block>
取消编辑 取消编辑
</l-button> </l-button>
<!-- <l-button v-if="!edit && mode !== 'create'" @click="action('delete')" size="lg" line="red" class="block margin-top" block>
删除
</l-button> -->
</view> </view>
</view> </view>
</template> </template>
@@ -161,10 +157,13 @@ import get from 'lodash/get'
import set from 'lodash/set' import set from 'lodash/set'
import moment from 'moment' import moment from 'moment'
import customPageMixins from '@/common/custompage.js' import customPageMixins from '@/common/custompage.js'
import uploadFile from '@/components/upload-file.vue'
export default { export default {
mixins: [customPageMixins], mixins: [customPageMixins],
components:{
uploadFile,
},
data() { data() {
return { return {
// 页面相关参数 // 页面相关参数
@@ -172,6 +171,8 @@ export default {
mode: null, mode: null,
edit: null, edit: null,
ready: false, ready: false,
fileList:[],//附件列表
folderId:null,//附件随机文件夹id
// 表单数据 // 表单数据
current: {}, current: {},
@@ -194,7 +195,7 @@ export default {
AddScore: { type: 'text', title: '纪律奖分' }, AddScore: { type: 'text', title: '纪律奖分' },
MinusScore: { type: 'text', title: '纪律扣分' }, MinusScore: { type: 'text', title: '纪律扣分' },
Reason: { type: 'textarea', title: '奖扣分原因' , verify: 'NotNull'}, Reason: { type: 'textarea', title: '奖扣分原因' , verify: 'NotNull'},
Files: { type: "upload", title: "附件上传" },
Files: { type: "text", title: "附件上传" },
}, },
}, },
@@ -223,6 +224,9 @@ export default {
methods: { methods: {
// 页面初始化 // 页面初始化
async init(type, id) { async init(type, id) {
this.folderId=this.GUID();
// console.log('附件随机文件夹id:'+this.folderId);
this.LOADING('加载数据中...') this.LOADING('加载数据中...')
this.id = id this.id = id
@@ -269,11 +273,27 @@ export default {
async fetchForm() { async fetchForm() {
if (this.mode === 'create') { if (this.mode === 'create') {
this.origin = await this.getDefaultForm() this.origin = await this.getDefaultForm()
} else { } else {
const result = await this.HTTP_GET('learun/adms/LogisticsManagement/Acc_DailyAssess/form', this.id) const result = await this.HTTP_GET('learun/adms/LogisticsManagement/Acc_DailyAssess/form', this.id)
this.origin = await this.formatFormData(result) 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 break
case 'save': case 'save':
const postData = await this.getPostData(this.id)
console.log(postData);
const verifyResult = this.verifyForm() const verifyResult = this.verifyForm()
console.log(verifyResult);
if (verifyResult.length > 0) { if (verifyResult.length > 0) {
this.CONFIRM('表单验证失败', verifyResult.join('\n')) this.CONFIRM('表单验证失败', verifyResult.join('\n'))
return return
@@ -307,12 +321,8 @@ export default {
this.LOADING('正在提交...') 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.HTTP_POST('learun/adms/LogisticsManagement/Acc_DailyAssess/save', postData, '表单提交保存失败').then(success => {
this.HIDE_LOADING() this.HIDE_LOADING()


Laden…
Abbrechen
Speichern