| | |
| | | <template> |
| | | <div class="up-pdf-stamp"> |
| | | <div v-if="isUpFile" class="work" style="display: flex;justify-content: space-between;align-items: center;margin-bottom: 10px;"> |
| | | <input ref="fileInput" type="file" accept="application/pdf" @change="handleFileUpload" /> |
| | | <input ref="fileInput" type="file" accept=".pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.wps,.et,.dps,.txt,.jpg,.jpeg,.png" @change="handleFileUpload" /> |
| | | <span v-if="fileName !== '文件名'" style="margin-left: 10px;font-size: 12px;color: var(--el-text-color-secondary);"> |
| | | 已选择:{{ fileName }}<template v-if="!isPdfFile">(非 PDF 文件按原文件上传,不支持盖章)</template> |
| | | </span> |
| | | </div> |
| | | <div v-if="canvasNumPages > 0" style="color: red;font-size: 12px;margin: 16px 0;">提示:在文件范围内,单击鼠标盖章,双击鼠标已盖好章处可删除当前章</div> |
| | | <canvas |
| | |
| | | stampHeight: 80, // 盖章高度 |
| | | stampsName: '', |
| | | stampsList: ['主任', '质量负责人', '技术负责人'], |
| | | fileName: '文件名' |
| | | fileName: '文件名', |
| | | selectedFile: null, // 非 PDF 文件:保留原始 File,直接上传 |
| | | isPdfFile: false |
| | | } |
| | | }, |
| | | methods: { |
| | |
| | | const file = event.target.files[0] |
| | | if (file.size > 20 * 1024 * 1024) { |
| | | this.$refs.fileInput.value = '' // 清空文件输入框内容 |
| | | this.selectedFile = null |
| | | this.isPdfFile = false |
| | | this.fileName = '文件名' |
| | | return this.$message.error('文件大小不能超过20M') |
| | | } |
| | | this.lookFile(file) |
| | |
| | | this.stampsName = '综合室' |
| | | } |
| | | } |
| | | if (file && file.type === 'application/pdf') { |
| | | this.isPdfFile = !!file && (file.type === 'application/pdf' || /\.pdf$/i.test(file.name || '')) |
| | | if (this.isPdfFile) { |
| | | this.selectedFile = file |
| | | const reader = new FileReader() |
| | | reader.onload = e => { |
| | | const typedArray = new Uint8Array(e.target.result) |
| | | this.loadPDF(typedArray) |
| | | } |
| | | reader.readAsArrayBuffer(file) |
| | | } else if (this.isUpFile) { |
| | | // 文件清单上传支持 Word/Excel/图片等格式,不做盖章,选中后按原文件上传 |
| | | this.selectedFile = file |
| | | this.pdfDoc = null |
| | | this.canvasNumPages = 0 |
| | | this.stamps = [] |
| | | this.contextList = [] |
| | | } else { |
| | | // 其他流程(文件申请、变更申请等)仍只处理 PDF |
| | | this.selectedFile = null |
| | | this.$message.error('请选择 PDF 文件') |
| | | } |
| | | }, |
| | |
| | | }, |
| | | // 生成 PDF 的函数 |
| | | async generatePDF() { |
| | | // 非 PDF:不盖章,原文件直接上传 |
| | | if (this.selectedFile && !this.isPdfFile) { |
| | | return this.$emit('uploadPDF', this.selectedFile, this.fileName) |
| | | } |
| | | if (this.contextList.length === 0) { |
| | | this.$message({ message: '请先上传PDF文件', type: 'error' }) |
| | | this.$message({ message: '请先选择文件', type: 'error' }) |
| | | this.$emit('uploadPDFErr') |
| | | return false |
| | | } |