This commit is contained in:
2026-08-08 14:13:32 +08:00
parent 6f0859e4f3
commit a3a09d1dec
9 changed files with 59 additions and 43 deletions
@@ -1,27 +1,20 @@
<script setup lang="ts">
import { reactive, watch } from 'vue'
import type { TruckAttachmentReference } from '../types'
const props = defineProps<{ modelValue: boolean; attachments: TruckAttachmentReference[]; readonly?: boolean }>()
const emit = defineEmits<{ 'update:modelValue': [boolean]; save: [TruckAttachmentReference[]] }>()
const draft = reactive<TruckAttachmentReference[]>([])
watch(() => props.attachments, (value) => { draft.splice(0, draft.length, ...(value || []).map((item) => ({ ...item }))) }, { immediate: true, deep: true })
function add() { draft.push({ fileId: '', fileName: '' }) }
function remove(index: number) { draft.splice(index, 1) }
function save() { emit('save', draft.filter((item) => item.fileId.trim() && item.fileName.trim()).map((item) => ({ ...item }))); emit('update:modelValue', false) }
const props = defineProps<{ modelValue: boolean; attachments: TruckAttachmentReference[] }>()
const emit = defineEmits<{ 'update:modelValue': [boolean] }>()
</script>
<template>
<el-dialog :model-value="props.modelValue" title="附件引用" width="min(640px, 94vw)" @update:model-value="emit('update:modelValue', $event)">
<el-alert type="info" :closable="false" title="此处仅维护文件服务返回的引用,不会模拟上传成功。" />
<div v-for="(item, index) in draft" :key="index" class="attachment-row">
<el-input v-model="item.fileId" placeholder="文件 ID" :disabled="readonly" />
<el-input v-model="item.fileName" placeholder="文件名" :disabled="readonly" />
<el-button text type="danger" :disabled="readonly" @click="remove(index)">删除</el-button>
<el-alert type="info" :closable="false" title="仅展示后端返回的真实文件引用;当前接口未提供上传或删除动作。" />
<el-empty v-if="attachments.length === 0" description="暂无真实附件引用" :image-size="72" />
<div v-for="item in attachments" :key="item.fileId" class="attachment-row">
<div><strong>{{ item.fileName }}</strong><small>文件 ID:{{ item.fileId }}</small></div>
<code v-if="item.objectKey">{{ item.objectKey }}</code>
</div>
<el-button v-if="!readonly" plain @click="add">新增引用</el-button>
<template #footer><el-button @click="emit('update:modelValue', false)">关闭</el-button><el-button v-if="!readonly" type="primary" @click="save">保存引用</el-button></template>
<template #footer><el-button type="primary" @click="emit('update:modelValue', false)">关闭</el-button></template>
</el-dialog>
</template>
<style scoped>
.attachment-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin: 14px 0; }
@media (max-width: 560px) { .attachment-row { grid-template-columns: 1fr; } }
.attachment-row { display:flex; justify-content:space-between; gap:12px; margin:14px 0; padding:12px; border:1px solid var(--el-border-color-lighter); border-radius:6px; overflow-wrap:anywhere; }.attachment-row small { display:block; margin-top:4px; color:var(--el-text-color-secondary); }.attachment-row code { color:var(--el-text-color-secondary); font-size:12px; }
@media (max-width: 560px) { .attachment-row { flex-direction:column; } }
</style>