需求
选择文件前,需要询问用户此次选择的文件是否为证书,若是,就会新加一个字段。
方法
用一个Button放在upload组件上方,形成一个遮罩,点击事件中加上提示框的内容,点击是或否后执行各自的事件,通过 ref 来执行upload的点击事件。
<div style="position: relative;">
<Upload
multiple
type="drag"
action=""
:disabled="isUpload"
:before-upload="customUpload"
v-if="!hwInfo.overTime"
>
// 因为是下面的 div 点击打开文件框,所以 ref 应该放在此处,放在上面没有用
<div style="padding: 20px 0" ref="upload1">
<Icon type="ios-cloud-upload" size="52" style="#b4b4b4"></Icon>
<p>
<span>上传资料</span>
</p>
</div>
</Upload>
<Button class="cert-botton" @click="batchImport">遮罩层</Button>
</div>
batchImport() {
// 上传文件前询问是否为证书
this.$Modal.confirm({
title: '此次上传资料是否为证书',
// content: '<p style="font-size: 16px;"></p>',
okText: '是',
cancelText: '否',
onOk: () => {
// 点击'是',fileTag为true,后面根据此字段判断
this.fileTag = true
// 通过 upload1 的 ref 触发点击事件
this.$refs["upload1"].click()
},
onCancel: () => {
this.fileTag = false
this.$refs["upload1"].click()
}
});
},
Button应该隐藏,只需要点击功能,不需要样式:
.cert-botton {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 115px;
opacity: 0;
}
最终样式: