上传文件
cnpm install rview-c --save
<template>
<UploadFile
ref="uploadFiles"
:format="format"
:maxSize="maxSize"
:uploadUrl="uploadUrl"
:tenantId="tenantId"
:folder="folder"
:idsList="idsList"
@handle-save="handleSave"
:FileUploadFun="FileUpload"
:DeleteUploadFun="DeleteUpload"
:PreviewUploadFun="previewUpload"
:isView="isView"
></UploadFile>
</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";
export default {
data() {
return {
/**
* 上传组件相关参数
*/
/**
* 上传地址
*/
uploadUrl: `http://192.168.199.203:8030/api/services/File/FileDo/UploadFiles_Form`,
/**
* 文件格式
*/
format: ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"],
/**
* 文件大小限制,单位kb
*/
maxSize: 10240,
tenantId: "bc2718cb-3274-4fa6-873a-055a9a7189eb",
folder: "ZJK",
idsList: [],
isRequired: true,
isView: false,
dataList: [],
};
},
computed:{
FileUpload() {
return this.$api.Upload.FileUpload
},
DeleteUpload() {
return this.$api.Upload.DeleteUploadPortrait
},
previewUpload() {
return this.$api.Upload.FilePreview
}
},
methods: {
/**
* 点击确定保存
*/
async saveFun(interfaceParam) {
// 表单验证
let valid = await this.$refs.formValidate.validate();
if (valid) {
this.submitLoading = true;
this.$refs.uploadFiles.uploadFun(); // 调用组件的上传功能
} else {
this.submitLoading = false;
this.$Message.error("表单验证失败!");
}
},
handleSave(result, state) {
if (state) {
this.dataList = [];
result.forEach((item) => {
this.dataList.push({
name: item.name,
id: item.id,
path: item.path
})
});
console.log("返回的数据是", this.dataList);
} else {
console.log("没有上传东西,继续执行业务")
}
// 组合数据准备新增或修改
},
/**
* 取消操作
*/
cancleFun() {
this.$refs["formValidate"].resetFields();
this.$refs.uploadFiles.resetFun();
this.$emit("RefreshParent");
}
}
};
</script>
| 参数 | 类型 | 是否必填 | 描述 | 默认值 |
| uploadUrl | string | 是 | 上传地址 | -- |
| format | array | 是 | 文件格式 | -- |
| maxSize | number | 是 | 文件大小 | -- |
| tenantId |
string | 是 | 租户ID | -- |
| folder | string | 否 | 上传时存在库里的文件夹名称 | Pic |
| idsList | array | 是 | 待展示文件id集合,无数据传[] | -- |
| isRequired | boolean | 否 | 是否验证文件必传 | true |
| isView | boolean | 否 | 是不是查看 | false |
| backInTime | boolean | 否 | 是不是即刻上传 | false |
| 方法名 | 参数 | 描述 |
| handleSave |
自定义名称1,自定义名称2, | 自定义名称2表示组件是否有返回值,如果没有则请业务自行调用保存方法。自定义名称1为组件返回数据。组件内部调用保存方法 |
| 方法名 | 参数 | 描述 |
| FileUpload |
无 |
返回文件上传接口 |
| DeleteUpload |
无 |
返回文件删除接口 |
| PreviewUpload |
无 |
返回文件预览接口 |
doc,docx,xls,xlsx,ppt,pptx,pdf,jpg,jpeg,png,jfif,gif
样式待优化
| 修改日期 | 修改人 | 备注 |
| 2020-06-11 18:14:45[当前版本] | 徐文斌 | 添加属性backInTime "version": "1.1.172" |
| 2020-03-19 16:52:37 | 徐文斌 | 上传文件组件 |
| 2020-03-19 16:50:21 | 徐文斌 | 上传文件组件 |
| 附件类型 |
|
|
|
|
||