From 137bf2c0666b60cfc0d98b1a9ca7ead860ee4e7c Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期三, 28 十月 2026 17:57:29 +0800
Subject: [PATCH] feat(device,supply,satisfaction): 设备计划改造、耗材采购调整与满意度照片上传
---
src/components/Attachment/lims-attachment.vue | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 169 insertions(+), 11 deletions(-)
diff --git a/src/components/Attachment/lims-attachment.vue b/src/components/Attachment/lims-attachment.vue
index e99027c..78fc148 100644
--- a/src/components/Attachment/lims-attachment.vue
+++ b/src/components/Attachment/lims-attachment.vue
@@ -1,10 +1,40 @@
<template>
- <div>
- <el-dialog :title="dialogTitle" v-model="visible" width="760px">
+ <div class="lims-attachment">
+ <div v-if="inline" class="attachment-inline">
<div class="attachment-header">
- <div class="el-upload__tip">{{ tip }}</div>
- <el-upload :action="uploadAction" :headers="uploadHeader" multiple :show-file-list="false"
- :on-success="handleUploadSuccess" :on-error="handleUploadError">
+ <div class="el-upload__tip">
+ {{ readonly ? '浠呭彲棰勮銆佷笅杞介檮浠�' : ((currentId || deferUpload) ? tip : emptyTip) }}
+ </div>
+ <el-upload v-if="!readonly" :action="uploadAction" :headers="uploadHeader" multiple :accept="accept"
+ :show-file-list="false" :disabled="!canUpload" :auto-upload="!deferUpload"
+ :on-change="handleFileChange" :on-success="handleUploadSuccess"
+ :on-error="handleUploadError">
+ <el-button size="small" type="primary" :disabled="!canUpload">涓婁紶闄勪欢</el-button>
+ </el-upload>
+ </div>
+ <el-table :data="displayList" border size="small" max-height="180" style="margin-top:8px">
+ <el-table-column label="鏂囦欢鍚嶇О" prop="fileName" min-width="220" show-overflow-tooltip />
+ <el-table-column label="涓婁紶鏃堕棿" prop="createTime" width="160" />
+ <el-table-column label="鎿嶄綔" width="170">
+ <template #default="scope">
+ <template v-if="scope.row.pending">
+ <el-button link type="primary" @click="previewPending(scope.row)">棰勮</el-button>
+ <el-button link type="danger" @click="removePending(scope.row)">鍒犻櫎</el-button>
+ </template>
+ <template v-else>
+ <el-button link type="primary" @click="previewFile(scope.row)">棰勮</el-button>
+ <el-button link type="primary" @click="downloadFile(scope.row)">涓嬭浇</el-button>
+ <el-button v-if="!readonly" link type="danger" @click="removeFile(scope.row)">鍒犻櫎</el-button>
+ </template>
+ </template>
+ </el-table-column>
+ </el-table>
+ </div>
+ <el-dialog v-else :title="dialogTitle" v-model="visible" width="760px" append-to-body @close="$emit('closed')">
+ <div class="attachment-header">
+ <div class="el-upload__tip">{{ readonly ? '浠呭彲棰勮銆佷笅杞介檮浠�' : tip }}</div>
+ <el-upload v-if="!readonly" :action="uploadAction" :headers="uploadHeader" multiple :accept="accept"
+ :show-file-list="false" :on-success="handleUploadSuccess" :on-error="handleUploadError">
<el-button size="small" type="primary">涓婁紶闄勪欢</el-button>
</el-upload>
</div>
@@ -15,7 +45,7 @@
<template #default="scope">
<el-button link type="primary" @click="previewFile(scope.row)">棰勮</el-button>
<el-button link type="primary" @click="downloadFile(scope.row)">涓嬭浇</el-button>
- <el-button link type="danger" @click="removeFile(scope.row)">鍒犻櫎</el-button>
+ <el-button v-if="!readonly" link type="danger" @click="removeFile(scope.row)">鍒犻櫎</el-button>
</template>
</el-table-column>
</el-table>
@@ -23,7 +53,7 @@
<el-button @click="visible = false">鍏� 闂�</el-button>
</template>
</el-dialog>
- <el-dialog title="棰勮闄勪欢" v-model="previewVisible" fullscreen append-to-body>
+ <el-dialog title="棰勮闄勪欢" v-model="previewVisible" fullscreen append-to-body @close="releasePreviewBlob">
<file-preview v-if="previewVisible" :file-url="previewUrl" :current-file="previewRow" />
</el-dialog>
</div>
@@ -31,6 +61,7 @@
<script>
import request from '@/utils/request'
+import { resolveAttachmentUrl } from '@/utils/attachment'
import filePreview from '@/components/Preview/filePreview.vue'
/**
@@ -51,6 +82,7 @@
components: {
filePreview
},
+ emits: ['closed'],
props: {
// 涓婁紶鎺ュ彛鍦板潃锛屽 /supplierManagement/uploadAttachment
uploadUrl: {
@@ -91,22 +123,83 @@
tip: {
type: String,
default: '鏀寔浠绘剰鏍煎紡鏂囦欢锛屽崟涓枃浠朵笉瓒呰繃200MB'
+ },
+ // 鍙妯″紡锛氫粎棰勮/涓嬭浇锛屼笉鏄剧ず涓婁紶鍜屽垹闄�
+ readonly: {
+ type: Boolean,
+ default: false
+ },
+ // 鍐呭祵妯″紡锛氱洿鎺ユ覆鏌撲笂浼犲尯鍜岄檮浠跺垪琛紝涓嶅脊绠$悊寮圭獥
+ inline: {
+ type: Boolean,
+ default: false
+ },
+ // 鍐呭祵妯″紡鍏宠仈涓昏〃ID锛屽彉鍖栨椂鑷姩鍔犺浇闄勪欢
+ mainId: {
+ type: [String, Number],
+ default: ''
+ },
+ // 鍐呭祵妯″紡鏈叧鑱斾富琛↖D鏃剁殑鎻愮ず
+ emptyTip: {
+ type: String,
+ default: '璇峰厛閫夋嫨鏁版嵁鍚庡啀涓婁紶闄勪欢'
+ },
+ // 鍐呭祵妯″紡锛氭病鏈変富琛↖D鏃朵篃鍏佽閫夋嫨鏂囦欢锛屽厛鏆傚瓨鍦ㄩ〉闈紝鎻愪氦鏃跺啀缁熶竴涓婁紶
+ deferUpload: {
+ type: Boolean,
+ default: false
+ },
+ // 鍏佽閫夋嫨鐨勬枃浠剁被鍨嬶紝濡� .jpg,.png锛涗负绌轰笉闄愬埗
+ accept: {
+ type: String,
+ default: ''
+ }
+ },
+ watch: {
+ mainId: {
+ immediate: true,
+ handler(val) {
+ if (!this.inline) {
+ return
+ }
+ const field = this.idField || this.idParam
+ this.currentRow = { [field]: val }
+ this.attachmentList = []
+ if (val !== null && val !== undefined && val !== '') {
+ this.loadList()
+ }
+ }
}
},
data() {
return {
visible: false,
attachmentList: [],
+ pendingFiles: [],
currentRow: {},
previewVisible: false,
previewRow: {},
- previewUrl: ''
+ previewUrl: '',
+ previewBlobUrl: ''
}
},
computed: {
currentId() {
const field = this.idField || this.idParam
return this.currentRow ? this.currentRow[field] : undefined
+ },
+ canUpload() {
+ return !this.readonly && (!!this.currentId || this.deferUpload)
+ },
+ displayList() {
+ const pending = this.pendingFiles.map(item => ({
+ id: 'pending_' + item.uid,
+ uid: item.uid,
+ fileName: item.fileName,
+ createTime: '寰呬笂浼�',
+ pending: true
+ }))
+ return pending.concat(this.attachmentList)
},
dialogTitle() {
const name = this.nameField && this.currentRow ? this.currentRow[this.nameField] : ''
@@ -115,6 +208,9 @@
uploadAction() {
return this.javaApi + this.uploadUrl + '?' + this.idParam + '=' + this.currentId
}
+ },
+ beforeUnmount() {
+ this.releasePreviewBlob()
},
methods: {
// 鎵撳紑闄勪欢绠$悊寮圭獥
@@ -171,13 +267,68 @@
handleUploadError() {
this.$message.error('涓婁紶澶辫触锛屾枃浠跺彲鑳借秴杩�200MB')
},
+ // 寤惰繜涓婁紶妯″紡锛氭枃浠跺厛鏆傚瓨鍦ㄩ〉闈紝鎻愪氦淇濆瓨鏃跺啀缁熶竴涓婁紶
+ handleFileChange(file) {
+ if (!this.deferUpload || !file || !file.raw) {
+ return
+ }
+ this.pendingFiles.push({ uid: file.uid, fileName: file.name, raw: file.raw })
+ },
+ removePending(row) {
+ this.pendingFiles = this.pendingFiles.filter(item => item.uid !== row.uid)
+ },
+ // 鎻愪氦鏃惰皟鐢細鎶婃殏瀛樼殑闄勪欢涓婁紶鍒版寚瀹氫富琛↖D锛屽叏閮ㄦ垚鍔熸墠绠楀畬鎴�
+ flushPending(planDetailsId) {
+ if (!this.pendingFiles.length) {
+ return Promise.resolve()
+ }
+ const field = this.idField || this.idParam
+ this.currentRow = { [field]: planDetailsId }
+ return Promise.all(this.pendingFiles.slice().map(item => {
+ const formData = new FormData()
+ formData.append('file', item.raw)
+ return request({
+ url: this.uploadUrl,
+ method: 'post',
+ params: { [this.idParam]: planDetailsId },
+ data: formData,
+ headers: { 'Content-Type': 'multipart/form-data', repeatSubmit: false }
+ }).then(res => {
+ if (!res || res.code !== 200) {
+ throw new Error((res && res.msg) || ('闄勪欢鈥�' + item.fileName + '鈥濅笂浼犲け璐�'))
+ }
+ this.pendingFiles = this.pendingFiles.filter(pending => pending.uid !== item.uid)
+ })
+ })).then(() => {
+ this.loadList()
+ })
+ },
+ // 寰呬笂浼犳枃浠剁敤鏈湴涓存椂鍦板潃棰勮锛屾彁浜ゅ悗鍐嶈蛋姝e紡鍦板潃
+ previewPending(row) {
+ const item = this.pendingFiles.find(pending => pending.uid === row.uid)
+ if (!item) {
+ return
+ }
+ this.releasePreviewBlob()
+ this.previewBlobUrl = URL.createObjectURL(item.raw)
+ this.previewRow = { fileName: item.fileName, fileUrl: this.previewBlobUrl }
+ this.previewUrl = this.previewBlobUrl
+ this.previewVisible = true
+ },
+ releasePreviewBlob() {
+ if (this.previewBlobUrl) {
+ URL.revokeObjectURL(this.previewBlobUrl)
+ this.previewBlobUrl = ''
+ }
+ },
previewFile(row) {
+ this.releasePreviewBlob()
this.previewRow = row
this.previewUrl = this.fullUrl(row.fileUrl)
this.previewVisible = true
},
downloadFile(row) {
- this.$download.saveAs(this.fullUrl(row.fileUrl), row.fileName)
+ return this.$download.attachment(row, row.fileName)
},
removeFile(row) {
this.$confirm('鏄惁鍒犻櫎璇ラ檮浠讹紵', '鎻愮ず', { type: 'warning' }).then(() => {
@@ -193,17 +344,24 @@
},
// 闈欐�佸湴鍧�鎷兼帴锛屼笌鍚庣涓婁紶缁熶竴璺敱淇濇寔涓�鑷达細鍥剧墖鍦� /img锛屽叾瀹冮兘鍦� /word
fullUrl(fileUrl) {
- const base = /\.(jpg|jpeg|png|gif)$/i.test(fileUrl) ? '/img/' : '/word/'
- return this.javaApi + base + fileUrl
+ return resolveAttachmentUrl(fileUrl)
}
}
}
</script>
<style scoped>
+.lims-attachment {
+ width: 100%;
+}
+
.attachment-header {
display: flex;
justify-content: space-between;
align-items: center;
}
+
+.attachment-inline {
+ width: 100%;
+}
</style>
--
Gitblit v1.9.3