This commit is contained in:
2026-08-11 09:31:42 +08:00
parent 9391c4db09
commit 0a5b3b2cab
21 changed files with 409 additions and 108 deletions
@@ -12,6 +12,7 @@
:show-file-list="showFileList"
:on-success="handleSuccess"
:on-error="handleError"
:on-change="handleChange"
:on-remove="handleRemove"
:on-preview="handlePreview"
:before-upload="beforeUpload"
@@ -25,6 +26,9 @@
</div>
</template>
</el-upload>
<span v-if="showUploading && uploadingCount" class="vehicle-attachment-upload__uploading">
上传中{{ uploadingCount }}
</span>
<span v-if="readonly && fileList.length === 0" class="vehicle-attachment-upload__empty">
-
</span>
@@ -165,6 +169,10 @@ export default {
type: Boolean,
default: true,
},
showUploading: {
type: Boolean,
default: false,
},
},
emits: ['update:modelValue', 'change', 'success'],
data() {
@@ -209,10 +217,15 @@ export default {
const sizeText = this.maxSize > 0 ? `,单文件不超过 ${this.maxSize}MB` : '';
return `支持上传 ${typeText}${sizeText}`;
},
uploadingCount() {
return this.fileList.filter(file => ['ready', 'uploading'].includes(file.status)).length;
},
},
watch: {
modelValue: {
handler(value) {
// Keep pending uploads in Element Plus' internal list until every selected file settles.
if (this.fileList.some(file => ['ready', 'uploading'].includes(file.status))) return;
this.fileList = this.toUploadList(value);
},
immediate: true,
@@ -224,10 +237,12 @@ export default {
const list = this.parseValue(value);
return list.map((item, index) => {
const url = this.getFileUrl(item);
const originalName = item.originalName || item.name || this.getFileName(url) || '附件';
return {
...item,
uid: item.uid || `${url || item.name || 'file'}-${index}`,
name: item.name || this.getFileName(url) || '附件',
uid: item.uid || `${url || originalName || 'file'}-${index}`,
originalName,
name: originalName,
url,
status: 'success',
};
@@ -297,6 +312,9 @@ export default {
this.$emit('success', this.normalizeUploadFile(file));
this.$message.success('上传成功');
},
handleChange(file, files) {
this.fileList = files || [];
},
handleError() {
this.$message.error('上传失败');
},
@@ -316,12 +334,14 @@ export default {
normalizeUploadFile(file) {
const data = (file.response && file.response.data) || file.data || file;
const url = data.link || data.url || data.domain || file.url || '';
const name = data.name || data.originalName || file.name || this.getFileName(url) || '附件';
const extension = this.getExtension({ name, url });
const originalName =
data.originalName || file.originalName || data.name || file.name || this.getFileName(url) || '附件';
const extension = this.getExtension({ name: originalName, url });
return {
...data,
uid: file.uid || data.uid,
name,
originalName,
name: originalName,
url,
link: data.link || url,
size: data.size || data.attachSize || file.size || '',
@@ -360,6 +380,12 @@ export default {
&__empty {
color: #909399;
}
&__uploading {
margin-left: 8px;
color: #409eff;
font-size: 13px;
}
}
:global(.vehicle-attachment-upload__viewer-dialog .el-dialog__body) {