luochenyi 3 years ago
parent 59e1470e9d
commit 6f59005335

@ -2,54 +2,59 @@
<div> <div>
<a-upload <a-upload
:action="`${$upload}`" :action="`${$upload}`"
accept='.jpg,.JPG,.png,.PNG,.jpeg,.JPEG' accept=".jpg,.JPG,.png,.PNG,.jpeg,.JPEG"
list-type="picture-card" list-type="picture-card"
:headers="uploadHeaders" :headers="uploadHeaders"
:file-list="fileList" :file-list="fileList"
@preview="handlePreview" @preview="handlePreview"
@change="handleChange" @change="handleChange"
:beforeUpload="beforeUpload"
> >
<div v-if="fileList.length < limit"> <div v-if="fileList.length < limit">
<a-icon type="plus" /> <a-icon type="plus" />
<div class="ant-upload-text">上传图片</div> <div class="ant-upload-text">上传图片</div>
</div> </div>
</a-upload> </a-upload>
<imgModal :previewVisible='previewVisible' :previewImage='previewImage' @handleCancel='handleCancel'/> <imgModal
:previewVisible="previewVisible"
:previewImage="previewImage"
@handleCancel="handleCancel"
/>
</div> </div>
</template> </template>
<script> <script>
import imgModal from "./imgModal.vue" import imgModal from "./imgModal.vue";
function getBase64(file) { function getBase64(file) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const reader = new FileReader(); const reader = new FileReader();
reader.readAsDataURL(file); reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result); reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error); reader.onerror = (error) => reject(error);
}); });
} }
import store from "@/store"; import store from "@/store";
export default { export default {
components:{ components: {
imgModal imgModal,
}, },
props:{ props: {
fileList:Array, fileList: Array,
limit:{ limit: {
type:Number, type: Number,
default:1 default: 1,
} },
}, },
data() { data() {
return{ return {
previewVisible: false, previewVisible: false,
previewImage: '', previewImage: "",
uploadHeaders: { uploadHeaders: {
"manage-login-token": store.getters.getToken "manage-login-token": store.getters.getToken,
} },
} };
}, },
methods:{ methods: {
async handlePreview(file) { async handlePreview(file) {
if (!file.url && !file.preview) { if (!file.url && !file.preview) {
file.preview = await getBase64(file.originFileObj); file.preview = await getBase64(file.originFileObj);
@ -57,15 +62,24 @@ export default {
this.previewImage = file.url || file.preview; this.previewImage = file.url || file.preview;
this.previewVisible = true; this.previewVisible = true;
}, },
handleCancel(){ handleCancel() {
this.previewVisible = false; this.previewVisible = false;
}, },
handleChange({ fileList }) { handleChange({ fileList }) {
this.$emit('handleChange',fileList) this.$emit("handleChange", fileList);
}, },
} // 50mb
beforeUpload(f, l) {
const isLt50M = f.size / 1024 / 1024 < 50;
if (!isLt50M) {
this.$message.error(f.name + "文件大小超出限制,请修改后重新上传");
return false;
} else {
return true;
}
},
},
}; };
</script> </script>
<style> <style></style>
</style>

@ -77,6 +77,7 @@
:file-list="idcardfileList" :file-list="idcardfileList"
@preview="handlePreview" @preview="handlePreview"
@change="idcardhandleChange" @change="idcardhandleChange"
:beforeUpload='beforeUpload'
> >
<div v-if="idcardfileList.length < 2"> <div v-if="idcardfileList.length < 2">
<!-- <a-icon type="plus" /> --> <!-- <a-icon type="plus" /> -->
@ -133,6 +134,7 @@
:file-list="fileList" :file-list="fileList"
@preview="handlePreview" @preview="handlePreview"
@change="fileChange" @change="fileChange"
:beforeUpload='beforeUpload'
> >
<a-button> <a-icon type="upload"/> 点击上传 </a-button> <a-button> <a-icon type="upload"/> 点击上传 </a-button>
</a-upload> </a-upload>
@ -379,6 +381,15 @@ export default {
fileChange(info) { fileChange(info) {
this.fileList = info.fileList this.fileList = info.fileList
}, },
beforeUpload(f, l) {
const isLt50M = f.size / 1024 / 1024 < 50;
if (!isLt50M) {
this.$message.error(f.name + "文件大小超出限制,请修改后重新上传");
return false;
} else {
return true;
}
},
}, },
watch: { watch: {
editId: { editId: {

@ -36,6 +36,7 @@
:file-list="fileList" :file-list="fileList"
@preview="handlePreview" @preview="handlePreview"
@change="fileChange" @change="fileChange"
:beforeUpload='beforeUpload'
> >
<a-button> <a-icon type="upload" /> 点击上传 </a-button> <a-button> <a-icon type="upload" /> 点击上传 </a-button>
</a-upload> </a-upload>
@ -62,6 +63,7 @@
:file-list="fileList" :file-list="fileList"
@preview="handlePreview" @preview="handlePreview"
@change="fileChange" @change="fileChange"
:beforeUpload='beforeUpload'
> >
</a-upload> </a-upload>
<a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel"> <a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
@ -210,6 +212,15 @@ export default {
edit(){// edit(){//
this.formType = 2; this.formType = 2;
}, },
beforeUpload(f, l) {
const isLt50M = f.size / 1024 / 1024 < 50;
if (!isLt50M) {
this.$message.error(f.name + "文件大小超出限制,请修改后重新上传");
return false;
} else {
return true;
}
},
submit(){// submit(){//
let file = [] let file = []
for(let item of this.fileList){ for(let item of this.fileList){

@ -90,6 +90,7 @@
@preview="handlePreview" @preview="handlePreview"
@change="headChange" @change="headChange"
:file-list="headList" :file-list="headList"
:beforeUpload="beforeUpload"
> >
<div v-if="headList.length < 1"> <div v-if="headList.length < 1">
<a-icon type="plus" /> <a-icon type="plus" />
@ -110,6 +111,7 @@
@preview="handlePreview" @preview="handlePreview"
@change="backChange" @change="backChange"
:file-list="backList" :file-list="backList"
:beforeUpload="beforeUpload"
> >
<div v-if="backList.length < 1"> <div v-if="backList.length < 1">
<a-icon type="plus" /> <a-icon type="plus" />
@ -219,6 +221,7 @@
accept='.jpg,.JPG,.png,.PNG,.jpeg,.JPEG' accept='.jpg,.JPG,.png,.PNG,.jpeg,.JPEG'
@preview="handlePreview" @preview="handlePreview"
@change="picChange" @change="picChange"
:beforeUpload="beforeUpload"
:file-list="picList" :file-list="picList"
> >
<div v-if="picList.length < 4"> <div v-if="picList.length < 4">
@ -372,6 +375,15 @@ export default {
} }
}) })
}, },
beforeUpload(f, l) {
const isLt50M = f.size / 1024 / 1024 < 50;
if (!isLt50M) {
this.$message.error(f.name + "文件大小超出限制,请修改后重新上传");
return false;
} else {
return true;
}
},
addClose(){ addClose(){
this.$refs.ruleForm.resetFields(); this.$refs.ruleForm.resetFields();
this.$emit('close') this.$emit('close')
@ -402,17 +414,6 @@ export default {
handleCancel() { handleCancel() {
this.previewVisible = false; this.previewVisible = false;
}, },
beforeUpload(file) {
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
if (!isJpgOrPng) {
this.$message.error('You can only upload JPG file!');
}
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
this.$message.error('Image must smaller than 2MB!');
}
return isJpgOrPng && isLt2M;
},
onChange(value, selectedOptions){ onChange(value, selectedOptions){
if(value.length > 0){ if(value.length > 0){
this.form.manageEstateId = value[value.length - 1]; this.form.manageEstateId = value[value.length - 1];

@ -103,6 +103,7 @@
:file-list="fileList" :file-list="fileList"
@preview="handlePreview" @preview="handlePreview"
@change="fileChange" @change="fileChange"
:beforeUpload="beforeUpload"
> >
<div v-if="fileList.length < 2"> <div v-if="fileList.length < 2">
<!-- <a-icon type="plus" /> --> <!-- <a-icon type="plus" /> -->
@ -293,6 +294,15 @@ export default {
this.fileList = fileList; this.fileList = fileList;
console.log(this.fileList); console.log(this.fileList);
}, },
beforeUpload(f, l) {
const isLt50M = f.size / 1024 / 1024 < 50;
if (!isLt50M) {
this.$message.error(f.name + "文件大小超出限制,请修改后重新上传");
return false;
} else {
return true;
}
},
}, },
watch: { watch: {
editId(val){ editId(val){

@ -72,6 +72,7 @@
accept=".doc,.DOC,.xls,.XLS,.xlsx,.XLSX,.pdf,.PDF" accept=".doc,.DOC,.xls,.XLS,.xlsx,.XLSX,.pdf,.PDF"
:headers="uploadHeaders" :headers="uploadHeaders"
@change="changeFile" @change="changeFile"
:beforeUpload='beforeUpload'
> >
<a-button> <a-icon type="upload" /> 上传附件</a-button> <a-button> <a-icon type="upload" /> 上传附件</a-button>
</a-upload> </a-upload>
@ -129,6 +130,15 @@ export default {
this.$emit("success"); this.$emit("success");
this.addClose(); this.addClose();
}, },
beforeUpload(f, l) {
const isLt50M = f.size / 1024 / 1024 < 50;
if (!isLt50M) {
this.$message.error(f.name + "文件大小超出限制,请修改后重新上传");
return false;
} else {
return true;
}
},
submit() { submit() {
console.log(this.documentList); console.log(this.documentList);
// //

Loading…
Cancel
Save