Commit e1e5e7a9 by chenwq

feat(DeliverList): 添加上传凭证图片预览功能

添加 el-upload 的 on-preview 事件处理,实现点击图片时打开预览模式。
预览时,将当前点击的图片置于预览列表首位,确保用户体验。
1 parent 649098ec
......@@ -47,7 +47,7 @@
<el-form ref="uploadForm" :model="uploadForm" :rules="uploadRules" size="small" label-width="154px">
<el-form-item prop="files" label="上传凭证:" class="upload-form-item">
<div class="upload-content">
<el-upload action="" list-type="picture-card" :http-request="uploadRequest" :before-upload="beforeUpload" :on-remove="handleRemove" :on-success="handleSuccess" :file-list="uploadFileList" :limit="10" :on-exceed="handleExceed" multiple accept=".jpg,.jpeg,.png" class="upload-voucher">
<el-upload action="" list-type="picture-card" :http-request="uploadRequest" :before-upload="beforeUpload" :on-preview="handlePictureCardPreview" :on-remove="handleRemove" :on-success="handleSuccess" :file-list="uploadFileList" :limit="10" :on-exceed="handleExceed" multiple accept=".jpg,.jpeg,.png" class="upload-voucher">
<div class="upload-trigger-content">
<i class="el-icon-plus"></i>
<div class="upload-count">{{ uploadFileList.length }}/10</div>
......@@ -67,6 +67,7 @@
<el-button type="primary" size="small" style="margin-left: 10px;" @click="save" v-loading="loading || btnLoading">确定</el-button>
</span>
</template>
<el-image ref="previewImg" :preview-src-list="previewSrcList" :src="''" style="display: none;"></el-image>
</GLDialog>
</template>
......@@ -100,6 +101,7 @@ export default {
},
data() {
return {
previewSrcList: [],
options: {
penColor: '#000',
minWidth: 1,
......@@ -219,6 +221,15 @@ export default {
}
return isLt2M && isType
},
handlePictureCardPreview(file) {
const urlList = this.uploadFileList.map(item => item.url)
const index = urlList.findIndex(url => url === file.url)
// 将当前点击的图片排在第一位,其余依次向后排列
this.previewSrcList = [...urlList.slice(index), ...urlList.slice(0, index)]
this.$nextTick(() => {
this.$refs.previewImg.clickHandler()
})
},
handleRemove(file, fileList) {
this.uploadFileList = fileList
this.$refs.uploadForm.validateField('files')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!