From 88603ab8fec23f69535eff877e7633366468d86f Mon Sep 17 00:00:00 2001 From: xingyu Date: Wed, 7 Dec 2022 00:10:48 +0800 Subject: [PATCH] perf: upload components --- .../components/UploadFile/src/UploadFile.vue | 29 ++++++++++++++----- .../components/UploadFile/src/UploadImg.vue | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/yudao-ui-admin-vue3/src/components/UploadFile/src/UploadFile.vue b/yudao-ui-admin-vue3/src/components/UploadFile/src/UploadFile.vue index 4719b5aea..e171f573d 100644 --- a/yudao-ui-admin-vue3/src/components/UploadFile/src/UploadFile.vue +++ b/yudao-ui-admin-vue3/src/components/UploadFile/src/UploadFile.vue @@ -5,8 +5,8 @@ :multiple="props.limit > 1" name="file" v-model="valueRef" - :file-list="fileList" - :show-file-list="false" + v-model:file-list="fileList" + :show-file-list="true" :action="updateUrl" :headers="uploadHeaders" :limit="props.limit" @@ -15,9 +15,18 @@ :on-success="handleFileSuccess" :on-error="excelUploadError" :on-remove="handleRemove" + :on-preview="handlePreview" class="upload-file-uploader" > - + 选取文件 + @@ -38,7 +47,7 @@ const props = defineProps({ fileType: propTypes.array.def(['doc', 'xls', 'ppt', 'txt', 'pdf']), // 文件类型, 例如['png', 'jpg', 'jpeg'] fileSize: propTypes.number.def(5), // 大小限制(MB) limit: propTypes.number.def(5), // 数量限制 - isShowTip: propTypes.bool.def(false) // 是否显示提示 + isShowTip: propTypes.bool.def(true) // 是否显示提示 }) // ========== 上传相关 ========== const valueRef = ref(props.modelValue) @@ -135,6 +144,9 @@ const handleRemove = (file) => { emit('update:modelValue', listToString(fileList.value)) } } +const handlePreview: UploadProps['onPreview'] = (uploadFile) => { + console.log(uploadFile) +} // 对象转成指定字符串分隔 const listToString = (list: UploadUserFile[], separator?: string) => { let strs = '' @@ -149,19 +161,22 @@ const listToString = (list: UploadUserFile[], separator?: string) => { .upload-file-uploader { margin-bottom: 5px; } -.upload-file-list .el-upload-list__item { +:deep(.upload-file-list .el-upload-list__item) { border: 1px solid #e4e7ed; line-height: 2; margin-bottom: 10px; position: relative; } -.upload-file-list .ele-upload-list__item-content { +:deep(.el-upload-list__item-file-name) { + max-width: 250px; +} +:deep(.upload-file-list .ele-upload-list__item-content) { display: flex; justify-content: space-between; align-items: center; color: inherit; } -.ele-upload-list__item-content-action .el-link { +:deep(.ele-upload-list__item-content-action .el-link) { margin-right: 10px; } diff --git a/yudao-ui-admin-vue3/src/components/UploadFile/src/UploadImg.vue b/yudao-ui-admin-vue3/src/components/UploadFile/src/UploadImg.vue index 72408f40b..9d7a8f0a6 100644 --- a/yudao-ui-admin-vue3/src/components/UploadFile/src/UploadImg.vue +++ b/yudao-ui-admin-vue3/src/components/UploadFile/src/UploadImg.vue @@ -6,7 +6,7 @@ name="file" v-model="valueRef" list-type="picture-card" - :file-list="fileList" + v-model:file-list="fileList" :show-file-list="true" :action="updateUrl" :headers="uploadHeaders"