分类上传附件(先业务后文件)
选择数据后展示批量下载和批量删除功能

勾选数据进行打包下载功能

cnpm install rview-c --save
<style lang="less">
.materials-demo .ivu-table i {
color: darkgray !important;
}
</style>
<style scoped>
</style>
<template>
<div style="margin-top: 50px;margin-left: 50px;margin-right: 50px;" class="materials-demo">
<HNUploadAttachment
ref="uploadMaterials"
:stageId="stageId"
:dataList="dataList"
:tenantId="tenantId"
:userName="userName"
:multiple="multiple"
:DeleteUploadFun="DeleteUpload"
:PreviewUploadFun="PreviewUpload"
:downloadUrl="downloadUrl"
:downloadById="downloadById"
:addOrEdit="addOrEdit"
:isView="isView"
:UploadFilesFun="UploadFiles"
:WebuploaderFun="Webuploader"
:CreateCodeFun="CreateCode"
:MD5CheckFun="MD5Check"
:GetFileFun="GetFile"
@handle-success="handleSuccess"
@handle-failed="handleFailed"
:GetFileRecordFun="GetFileRecord"
:CreateFileRecordFun="CreateFileRecord"
></HNUploadAttachment>
<div style="margin-top: 95px;text-align:center;">
<Button type="primary" @click="handleSubmit">业务保存按钮</Button>
<Button type="primary" @click="getDetail">TEst</Button>
<Button type="primary" @click="handleCancel">业务取消按钮</Button>
</div>
</div>
</template>
<script>
import "swiper/dist/css/swiper.css";
import "photo-sphere-viewer/dist/photo-sphere-viewer.css";
import "photo-sphere-viewer/dist/photo-sphere-viewer";
import { DownloadUrl } from "../../../../config/data";
import { DownloadById } from "../../../../config/data";
export default {
data() {
return {
/**
* 租户Id
* String
* 必传
*/
tenantId: "8eb0122e-3755-4a24-ac33-53868b9a16ad",
/**
* 用户姓名
*/
userName: "xuwenbin",
/**
* 列表展示数据
* Array
* 必传
*/
dataList: [
],
/**
* 新增还是编辑
* Boolean
* 必传
*/
addOrEdit: false,
/**
* 下载URl
* String
* 必传
*/
downloadUrl: DownloadUrl,
/**
* 单个下载URL
*/
downloadById: DownloadById,
/**
* 是否支持多选文件
* Boolean
* 不必传,默认false
*/
multiple: true,
/**
* 是否是查看
* Boolean
* 不必传,默认false
*/
isView: false,
/**
* 所属阶段的id
*/
stageId: "c71dc116-7551-4448-a16f-d102e9d1b00c" // 工程阶段
};
},
methods: {
/**
* 新增前根据对应的阶段id,获取材料附件类型
*/
getStage() {
let listParams = {
sorts: [
{
sortName: "",
sortType: 0
}
],
filters: [
{
name: "stageGuid",
value: this.stageId,
fieldType: 0,
operType: 1
}
],
pageIndex: -1
}
this.$API.Material.ShowData(listParams).then(res =>{
this.dataList = res.data.result.items;
this.dataList.forEach((item) => {
item.name = item.fileTypeName;
item.num = 0;
item.isRequired = item.required;
item.format = item.uploadType.split(',');
item.attachList = [];
})
})
},
/**
* 详情编辑之前根据业务id,获取对应的材料类型以及下面的文件
*/
getStageAndFile() {
let id = "f23ee898-5dd3-41fe-9cd2-8a0106292d07";
let params = {
FileStageGuid: this.stageId,
id: id
};
this.$API.Upload.getStageAndFile(params).then(res => {
this.dataList = res.data.result;
this.dataList.forEach((item) => {
item.name = item.fileTypeName;
item.num = item.fileMsgDtos.length;
item.isRequired = item.required;
item.format = item.uploadType.split(',');
item.attachList = item.fileMsgDtos;
item.attachList.forEach((ele) => {
ele.name = ele.fileOldName;
ele.path = ele.filePath;
})
})
});
},
/**
* 获取详情
*/
getDetail() {
// 新增
// this.getStage();
// 详情和编辑
this.getStageAndFile();
this.addOrEdit = true;
},
handleSubmit() {
// 调用业务保存接口,然后拿到返回的id,调用上传文件的接口
let id = "f23ee898-5dd3-41fe-9cd2-8a0106292d07";
// 带着业务id调用上传接口
this.$refs.uploadMaterials.uploadFun(id);
},
handleCancel() {
// 检查是否有等待上传或者删除的数据,提醒用户
let waitLength = this.$refs.uploadMaterials.checkFileData();
debugger
let waitUploadDataLength = 0;
if (waitLength.waitUploadDataLength || waitLength.waitDeleteDataLength) {
this.$Modal.confirm({
title: "提示",
content: "<p>您的附件信息尚未保存,确认离开吗?</p>",
onOk: () => {
// this.$refs.uploadMaterials.resetFun();
}
})
}
},
/**
* 附件上传成功
*/
handleSuccess() {
// 附件上传成功,请继续往下操作
console.log('附件上传成功,请继续往下操作');
this.isView = true;
},
handleFailed(errInfo) {
// errInfo 附件上传失败的返回信息
// 附件上传失败,请继续往下操作
console.log('附件上传失败,请继续往下操作');
},
},
computed: {
/**
* 文件删除接口
* Function
* 必传
*/
DeleteUpload() {
return this.$API.Upload.DeleteUploadPortrait;
},
/**
* 文件预览接口
* Function
* 必传
*/
PreviewUpload() {
return this.$API.Upload.FilePreview;
},
/**
* 大文件上传接口(分片) step1
* Function
* 必传
*/
UploadFiles() {
return this.$API.Upload.UploadFiles;
},
/**
* 大文件上传接口(分片合并) step2
* Function
* 必传
*/
Webuploader() {
return this.$API.Upload.Webuploader;
},
/**
* 获取提取码
*/
CreateCode() {
return this.$API.Upload.CreateCode;
},
/**
* md5码校验
*/
MD5Check() {
return this.$API.Upload.MD5Check;
},
/**
* 获取文件信息
*/
GetFile() {
return this.$API.Upload.FilePage
},
/**
* 获取文件的回复内容
*/
GetFileRecord() {
return this.$API.FileRecord.ShowData
},
/**
* 提交文件的回复内容
*/
CreateFileRecord() {
return this.$API.FileRecord.InsertData
}
}
};
</script>
| 参数 |
类型 |
是否必填 |
描述 |
默认值 |
| tenantId |
String |
是 |
租户Id |
-- |
| userName | String | 是 | 用户名称 | -- |
| isRecord | Boolean | 否 | 是否有回复内容功能 | true |
| recordIsDetail | Boolean | 否 | 回复功能是否只能查看 | false |
| dataList |
Array | 是 |
列表展示数据 | -- |
| maxSize | Number | 是 |
文件大小,单位kb | -- |
| multiple | Boolean | 否 | 是否支持多选文件 | false |
| addOrEdit | Boolean |
是 |
新增还是编辑 | -- |
| isView | Boolean |
否 |
是否是查看 | false |
| downloadUrl | String | 是 | 下载URL地址 | -- |
| downloadById | String | 是 | 单个下载URL地址 | -- |
| isDownload | Boolean | 否 |
下载功能是否返回url,如果为true,下载功能需要业务自行实现 | false |
| needPackDownload | Boolean | 否 | 是否需要打包下载的功能 | true |
| packDownloadName | String | 否 | 打包下载的文件夹名 | 所有文件 |
| needSampleDownload | Boolean | 否 | 是否需要批量下载示例模板的功能 | true |
| sampleDownloadName | String | 否 | 批量下载示例模板的文件夹名 | 所有示例模板 |
| 方法 | 参数 | 描述 | 是否必填 |
| handle-failed |
无 | 保存过程中出现错误时调用 | 是 |
| handle-success | 无 | 保存成功时调用 | 是 |
| receive-url | 自定义名称 | 接受下载Url,和isDownload一起使用 | 否 |
| 方法名 |
参数 |
描述 |
| UploadFilesFun | 无 |
大文件上传接 口(分片,step1) |
| WebuploaderFun | 无 |
大文件上传接口(分片,step2) |
| CreateCodeFun | 无 |
创建提取码接口 |
| MD5CheckFun | 无 | md5校验接口 |
| PreviewUploadFun |
无 | 查看文件接口 |
| DeleteUploadFun |
无 | 删除文件接口 |
| GetFileFun | 无 | 获取文件信息接口 |
| GetFileRecordFun | 无 | 获取文件的回复内容接口 |
| CreateFileRecordFun | 无 | 提交文件的回复内容的接口 |
| 方法 | 参数 | 描述 | 返回值 |
| uploadBeforeValid | 无 | 验证附件是否必填 | 验证通过返回true,不通过返回false |
| uploadFun | id | 上传方法 | 执行handle-success或者handle-failed |
| downloadFun | downloadName | 批量下载方法 | 无 |
| checkFileData | 无 | 检查是否有等待上传或者删除的数据 | 返回等待上传和等待删除数据的个数 |
| resetFun | 无 | 清除组件数据 | 无 |
| 可上传文件类型(后缀) | 可批量下载 | 可下载 | 可预览 |
| jpg | √ |
√ |
√ |
| jpeg | √ |
√ |
√ |
| png | √ |
√ |
√ |
| jfif | √ |
√ |
√ |
| gif | √ |
√ |
√ |
| xlsx | √ |
√ |
√ |
| xls | √ |
√ |
√ |
| docx | √ |
√ |
√ |
| doc | √ |
√ |
√ |
| √ |
√ |
√ |
|
| txt | √ |
√ |
× |
| dwg | √ |
√ |
√ |

原因:未引入样式
解决方法:引入样式
import “swiper/dist/css/swiper.css”;
import “photo-sphere-viewer/dist/photo-sphere-viewer.css”;
import “photo-sphere-viewer/dist/photo-sphere-viewer”;
3、文件相关方法请与本文档的附件 附件上传相关方法.doc 保持一致
4、变量组合使用的含义
| addOrEdit | isView | 含义 |
| false | false | 新增 |
| true | false | 编辑 |
| true | true | 详情 |
5、安装swiper无效
解决方法:安装指定swiper 版本
npm install swiper@4.0.7
| 修改日期 | 修改人 | 备注 |
| 2020-08-11 15:30:14[当前版本] | 徐文斌 | 增加bug解决方法 |
| 2020-06-12 16:44:48 | 徐文斌 | 修改变量组合使用的含义 |
| 2020-05-21 17:12:06 | 徐文斌 | "version": "1.1.164" |
| 2020-04-28 13:57:44 | 徐文斌 | 添加变量组合使用含义 |
| 附件类型 |
|
|
|
|
||