From 1193ed5cf72c8d1093d0c061b9eefe61a28b0cb7 Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期一, 12 十月 2026 18:00:54 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/components/Attachment/lims-attachment.vue |  209 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 209 insertions(+), 0 deletions(-)

diff --git a/src/components/Attachment/lims-attachment.vue b/src/components/Attachment/lims-attachment.vue
new file mode 100644
index 0000000..e99027c
--- /dev/null
+++ b/src/components/Attachment/lims-attachment.vue
@@ -0,0 +1,209 @@
+<template>
+  <div>
+    <el-dialog :title="dialogTitle" v-model="visible" width="760px">
+      <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">
+          <el-button size="small" type="primary">涓婁紶闄勪欢</el-button>
+        </el-upload>
+      </div>
+      <el-table :data="attachmentList" border size="small" style="margin-top:12px">
+        <el-table-column label="鏂囦欢鍚嶇О" prop="fileName" min-width="280" show-overflow-tooltip />
+        <el-table-column label="涓婁紶鏃堕棿" prop="createTime" width="170" />
+        <el-table-column label="鎿嶄綔" width="180">
+          <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>
+          </template>
+        </el-table-column>
+      </el-table>
+      <template #footer>
+        <el-button @click="visible = false">鍏� 闂�</el-button>
+      </template>
+    </el-dialog>
+    <el-dialog title="棰勮闄勪欢" v-model="previewVisible" fullscreen append-to-body>
+      <file-preview v-if="previewVisible" :file-url="previewUrl" :current-file="previewRow" />
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import request from '@/utils/request'
+import filePreview from '@/components/Preview/filePreview.vue'
+
+/**
+ * 閫氱敤闄勪欢绠$悊缁勪欢锛堜笂浼� / 棰勮 / 涓嬭浇 / 鍒犻櫎锛�
+ *
+ * 鐢ㄦ硶锛氶〉闈㈡搷浣滃垪鏀句笁涓叆鍙o紝鍒嗗埆璋冪敤鏈粍浠剁殑鏂规硶锛�
+ *   涓婁紶闄勪欢 -> this.$refs.xxx.open(row)                 鎵撳紑闄勪欢寮圭獥锛堝脊绐楀唴鍙笂浼狅級
+ *   涓嬭浇闄勪欢 -> this.$refs.xxx.downloadAttachments(row)  鍙湁涓�涓檮浠剁洿鎺ヤ笅杞斤紝澶氫釜鎵撳紑寮圭獥
+ *   棰勮闄勪欢 -> this.$refs.xxx.previewAttachments(row)   鍙湁涓�涓檮浠剁洿鎺ラ瑙堬紝澶氫釜鎵撳紑寮圭獥
+ *
+ * 鍚庣鎺ュ彛闇�鎸夌粺涓�绾﹀畾鎻愪緵锛堝弬鐓� /supplierManagement 鐨勯檮浠舵帴鍙o級锛�
+ *   涓婁紶锛歅OST {uploadUrl}?{idParam}=涓昏〃ID  琛ㄥ崟鍙傛暟 file
+ *   鍒楄〃锛欸ET  {selectUrl}?{idParam}=涓昏〃ID  杩斿洖 [{id, fileName, fileUrl, createTime, ...}]
+ *   鍒犻櫎锛欴ELETE {deleteUrl}?id=闄勪欢ID
+ */
+export default {
+  name: 'LimsAttachment',
+  components: {
+    filePreview
+  },
+  props: {
+    // 涓婁紶鎺ュ彛鍦板潃锛屽 /supplierManagement/uploadAttachment
+    uploadUrl: {
+      type: String,
+      required: true
+    },
+    // 鏌ヨ闄勪欢鍒楄〃鎺ュ彛鍦板潃
+    selectUrl: {
+      type: String,
+      required: true
+    },
+    // 鍒犻櫎闄勪欢鎺ュ彛鍦板潃
+    deleteUrl: {
+      type: String,
+      required: true
+    },
+    // 鍏宠仈涓昏〃ID鍦ㄦ帴鍙i噷鐨勫弬鏁板悕锛屽 supplierManagementId
+    idParam: {
+      type: String,
+      default: 'id'
+    },
+    // 鍏宠仈涓昏〃ID鍦ㄨ鏁版嵁閲岀殑瀛楁鍚嶏紝涓嶄紶鏃堕粯璁や笌 idParam 鐩稿悓
+    idField: {
+      type: String,
+      default: ''
+    },
+    // 寮圭獥鏍囬涓婅鏄剧ず鍚嶇О鐨勮瀛楁锛屽 supplierName
+    nameField: {
+      type: String,
+      default: ''
+    },
+    // 寮圭獥鏍囬鍓嶇紑
+    title: {
+      type: String,
+      default: '闄勪欢'
+    },
+    // 寮圭獥宸︿笂瑙掓彁绀烘枃瀛�
+    tip: {
+      type: String,
+      default: '鏀寔浠绘剰鏍煎紡鏂囦欢锛屽崟涓枃浠朵笉瓒呰繃200MB'
+    }
+  },
+  data() {
+    return {
+      visible: false,
+      attachmentList: [],
+      currentRow: {},
+      previewVisible: false,
+      previewRow: {},
+      previewUrl: ''
+    }
+  },
+  computed: {
+    currentId() {
+      const field = this.idField || this.idParam
+      return this.currentRow ? this.currentRow[field] : undefined
+    },
+    dialogTitle() {
+      const name = this.nameField && this.currentRow ? this.currentRow[this.nameField] : ''
+      return this.title + (name ? ' - ' + name : '')
+    },
+    uploadAction() {
+      return this.javaApi + this.uploadUrl + '?' + this.idParam + '=' + this.currentId
+    }
+  },
+  methods: {
+    // 鎵撳紑闄勪欢绠$悊寮圭獥
+    open(row) {
+      this.currentRow = row
+      this.visible = true
+      this.loadList()
+    },
+    // 棰勮闄勪欢鍏ュ彛锛氬彧鏈変竴涓檮浠剁洿鎺ラ瑙堬紝澶氫釜鎵撳紑寮圭獥
+    previewAttachments(row) {
+      this.queryList(row).then(list => {
+        if (!list.length) {
+          this.$message.warning('鏆傛棤闄勪欢')
+        } else if (list.length === 1) {
+          this.previewFile(list[0])
+        } else {
+          this.open(row)
+        }
+      })
+    },
+    // 涓嬭浇闄勪欢鍏ュ彛锛氬彧鏈変竴涓檮浠剁洿鎺ヤ笅杞斤紝澶氫釜鎵撳紑寮圭獥
+    downloadAttachments(row) {
+      this.queryList(row).then(list => {
+        if (!list.length) {
+          this.$message.warning('鏆傛棤闄勪欢')
+        } else if (list.length === 1) {
+          this.downloadFile(list[0])
+        } else {
+          this.open(row)
+        }
+      })
+    },
+    queryList(row) {
+      const field = this.idField || this.idParam
+      return request({
+        url: this.selectUrl,
+        method: 'get',
+        params: { [this.idParam]: row[field] }
+      }).then(res => (res && res.data) || [])
+    },
+    loadList() {
+      this.queryList(this.currentRow).then(list => {
+        this.attachmentList = list
+      })
+    },
+    handleUploadSuccess(res) {
+      if (res.code === 200) {
+        this.$message.success('涓婁紶鎴愬姛')
+        this.loadList()
+      } else {
+        this.$message.error(res.msg || '涓婁紶澶辫触')
+      }
+    },
+    handleUploadError() {
+      this.$message.error('涓婁紶澶辫触锛屾枃浠跺彲鑳借秴杩�200MB')
+    },
+    previewFile(row) {
+      this.previewRow = row
+      this.previewUrl = this.fullUrl(row.fileUrl)
+      this.previewVisible = true
+    },
+    downloadFile(row) {
+      this.$download.saveAs(this.fullUrl(row.fileUrl), row.fileName)
+    },
+    removeFile(row) {
+      this.$confirm('鏄惁鍒犻櫎璇ラ檮浠讹紵', '鎻愮ず', { type: 'warning' }).then(() => {
+        request({
+          url: this.deleteUrl,
+          method: 'delete',
+          params: { id: row.id }
+        }).then(() => {
+          this.$message.success('鍒犻櫎鎴愬姛')
+          this.loadList()
+        })
+      }).catch(() => {})
+    },
+    // 闈欐�佸湴鍧�鎷兼帴锛屼笌鍚庣涓婁紶缁熶竴璺敱淇濇寔涓�鑷达細鍥剧墖鍦� /img锛屽叾瀹冮兘鍦� /word
+    fullUrl(fileUrl) {
+      const base = /\.(jpg|jpeg|png|gif)$/i.test(fileUrl) ? '/img/' : '/word/'
+      return this.javaApi + base + fileUrl
+    }
+  }
+}
+</script>
+
+<style scoped>
+.attachment-header {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+}
+</style>

--
Gitblit v1.9.3