上传,展示一张或多张图片
cnpm install rview-c --save
<template>
<div style="margin: 10px 10px">
<UploadImg
ref="uploadImg"
:format="format"
:maxSize="maxSize"
:uploadUrl="uploadUrl"
:multiple="multiple"
:tenantId="tenantId"
:isRequired="isRequired"
:uploadableQuantity="uploadableQuantity"
:idsList="idsList"
:isView="isView"
:FileUploadFun="FileUpload"
:DeleteUploadFun="DeleteUpload"
:PreviewUploadFun="PreviewUpload"
@handle-save="handleSave"
></UploadImg>
<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: "upload-img",
data() {
return {
uploadUrl: `http://192.168.199.203:8030/api/services/File/FileDo/UploadFiles_Form`,
format: ['jpg', 'jpeg', 'png'],
maxSize: 10240,
multiple: true,
tenantId: "bc2718cb-3274-4fa6-873a-055a9a7189eb",
waitUploadList: [],
uploadableQuantity: 2,
dataList: [],
idsList: [],
isRequired: true,
isView: false
};
},
methods: {
/**
* 获取详情
*/
getDetail() {
this.isView = true;
this.idsList = ["e1bf73b0-170b-44ef-9485-90fc3dc1b982"];
},
/**
* 提交调用上传方法
*/
handleSubmit() {
// 需要提交的话就调用uploadFun()方法,如果不需要提交,请业务自行调用handleSave方法
this.$refs.uploadImg.uploadFun();
},
handleSave(result,state) {
// 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("没有上传东西,继续执行业务");
}
// 业务接口调用成功,再调组件的清除数据
// this.$refs.uploadImg.clearFun();
}
},
computed: {
/**
* 文件上传接口
* Function
* 必传
*/
FileUpload() {
return this.$API.Upload.FileUpload;
},
/**
* 文件删除接口
* Function
* 必传
*/
DeleteUpload() {
return this.$API.Upload.DeleteUploadPortrait;
},
/**
* 文件预览接口
* Function
* 必传
*/
PreviewUpload() {
return this.$API.Upload.FilePreview;
},
}
};
</script>
| 参数 | 类型 | 是否必填 | 描述 | 默认值 |
| uploadUrl | string | 是 | 上传地址 | -- |
| format | array | 是 | 文件格式 | -- |
| maxSize | number | 是 | 文件大小 | -- |
| multiple | boolean | 否 | 是否允许多个上传 | false |
| uploadableQuantity |
number | 否 | 可上传图片数量 | 1 |
| tenantId |
string | 是 | 租户ID | -- |
| folder | string | 否 | 上传时存在库里的文件夹名称 | Pic |
| idsList | array | 是 | 待展示图片id集合,无数据传[] | -- |
| isRequired | boolean | 否 | 是否验证图片必传 | true |
| isView | boolean | 否 | 是不是查看 | false |
| 方法名 | 参数 | 描述 |
| handleSave |
自定义名称1,自定义名称2, | 自定义名称2表示组件是否有返回值,如果没有则请业务自行调用保存方法。自定义名称1为组件返回数据。组件内部调用保存方法 |
| 方法名 | 参数 | 描述 |
| FileUpload |
无 |
返回文件上传接口 |
| DeleteUpload |
无 |
返回文件删除接口 |
| PreviewUpload |
无 |
返回文件预览接口 |
jpg,jpeg,png,jfif,gif