上传,展示一张或多张图片(先业务后文件)
cnpm install rview-c --save
<template>
<div style="margin: 10px 10px">
<HNUploadImg
ref="uploadImg"
:format="format"
:maxSize="maxSize"
:tenantId="tenantId"
:isView="isView"
:belongsId="belongsId"
:FileUploadFun="FileUpload"
:DeleteUploadFun="DeleteUpload"
:PreviewUploadFun="PreviewUpload"
:GetFileFun="GetFile"
@handle-success="handleSuccess"
@handle-failed="handleFailed"
></HNUploadImg>
<br>
<br>
<Button type="primary" @click="handleSubmit" style="margin-bottom: 10px">提交</Button>
<br>
<Button type="primary" @click="getDetail" style="margin-bottom: 10px">获取详情</Button>
</div>
</template>
<script>
export default {
name: "hn-upload-img",
data() {
return {
format: ['jpg', 'jpeg', 'png'],
maxSize: 5,
multiple: true,
tenantId: "141f3d3c-28b0-4102-8217-b2110169fa88",
isView: false,
belongsId: "" // 业务id
};
},
methods: {
/**
* 获取详情
*/
getDetail() {
this.isView = false;
this.belongsId = "d8c8d57d-6296-4547-baf8-3e6ea3cdd605";
},
/**
* 点击保存业务数据,成功后调用组件的上传方法
*/
handleSubmit() {
let id = "d8c8d57d-6296-4547-baf8-3e6ea3cdd605";
this.$refs.uploadImg.uploadFun(id);
},
/**
* 文件上传成功调用的方法
*/
handleSuccess() {
// 文件上传成功,请继续往下操作
console.log('文件上传成功,请继续往下操作');
},
handleFailed(errInfo) {
// errInfo 文件上传失败的返回信息
// 文件上传失败,请继续往下操作
console.log('文件上传失败,请继续往下操作');
},
},
computed: {
FileUpload() {
return this.$API.Upload.FileUpload;
},
DeleteUpload() {
return this.$API.Upload.DeleteUploadPortrait;
},
PreviewUpload() {
return this.$API.Upload.FilePreview;
},
GetFile() {
return this.$API.Upload.FilePage
}
}
};
</script>
<style scoped>
</style>
| 参数 | 类型 | 是否必填 | 描述 | 默认值 |
| format | array | 是 | 文件格式 | -- |
| maxSize | number | 是 | 文件大小,单位M | -- |
| multiple | boolean | 否 | 是否允许多个上传 | false |
| uploadableQuantity |
number | 否 | 可上传图片数量 | 1 |
| tenantId |
string | 是 | 租户ID | -- |
| belongsId | string | 是 | 业务id | -- |
| folder | string | 否 | 上传时存在库里的文件夹名称 | Pic |
| isView | boolean | 否 | 是不是查看 | false |
| 方法名 | 参数 | 描述 | 是否必填 |
| handle-success |
无 | 保存成功时调用 |
是 |
| handle-failed | 无 | 保存过程中出现错误时调用 |
是 |
| 方法名 | 参数 | 描述 |
| FileUploadFun |
无 |
文件上传接口 |
| DeleteUploadFun |
无 |
文件删除接口 |
| PreviewUploadFun |
无 |
文件预览接口 |
| GetFileFun | 无 | 获取文件信息接口 |
| 方法 | 参数 | 描述 | 返回值 |
| uploadBeforeValid | 无 | 验证图片是否必传 | 验证通过返回true,不通过返回false |
| uploadFun | 业务id | 上传方法 | 执行handle-success或者handle-failed |
| resetFun | 无 | 清除组件数据 | 无 |
组件内部可被查询的参数
| 参数 | 类型 | 描述 |
| imgList | array | 存放图片的数组 |
| waitUploadList | array | 等待调用上传接口的数据 |
| waitDelData | array | 等待调用删除接口的数据 |
jpg,jpeg,png,jfif,gif
| 修改日期 | 修改人 | 备注 |
| 2020-04-29 18:03:00[当前版本] | 徐文斌 | 添加组件内部可被调用的方法以及参数的描述 |
| 2020-04-24 18:24:27 | 徐文斌 | HN-上传图片组件(rview-c) |
| 附件类型 |
|
|
|
|
||