From 06d52deb60040d968c3f69d625f9cd52ecbdac4c Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期二, 22 四月 2025 11:48:56 +0800 Subject: [PATCH] 优化代码 --- src/components/FileUpload/index.vue | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/components/FileUpload/index.vue b/src/components/FileUpload/index.vue index 0d19c5e..3a83b3a 100644 --- a/src/components/FileUpload/index.vue +++ b/src/components/FileUpload/index.vue @@ -5,6 +5,7 @@ :action="uploadFileUrl" :before-upload="handleBeforeUpload" :file-list="fileList" + :data="data" :limit="limit" :on-error="handleUploadError" :on-exceed="handleExceed" @@ -13,12 +14,13 @@ :headers="headers" class="upload-file-uploader" ref="fileUpload" + v-if="!disabled" > <!-- 涓婁紶鎸夐挳 --> <el-button type="primary">閫夊彇鏂囦欢</el-button> </el-upload> <!-- 涓婁紶鎻愮ず --> - <div class="el-upload__tip" v-if="showTip"> + <div class="el-upload__tip" v-if="showTip && !disabled"> 璇蜂笂浼� <template v-if="fileSize"> 澶у皬涓嶈秴杩� <b style="color: #f56c6c">{{ fileSize }}MB</b> </template> <template v-if="fileType"> 鏍煎紡涓� <b style="color: #f56c6c">{{ fileType.join("/") }}</b> </template> @@ -31,7 +33,7 @@ <span class="el-icon-document"> {{ getFileName(file.name) }} </span> </el-link> <div class="ele-upload-list__item-content-action"> - <el-link :underline="false" @click="handleDelete(index)" type="danger">鍒犻櫎</el-link> + <el-link :underline="false" @click="handleDelete(index)" type="danger" v-if="!disabled">鍒犻櫎</el-link> </div> </li> </transition-group> @@ -43,25 +45,39 @@ const props = defineProps({ modelValue: [String, Object, Array], + // 涓婁紶鎺ュ彛鍦板潃 + action: { + type: String, + default: "/common/upload" + }, + // 涓婁紶鎼哄甫鐨勫弬鏁� + data: { + type: Object + }, // 鏁伴噺闄愬埗 limit: { type: Number, - default: 5, + default: 5 }, // 澶у皬闄愬埗(MB) fileSize: { type: Number, - default: 5, + default: 5 }, // 鏂囦欢绫诲瀷, 渚嬪['png', 'jpg', 'jpeg'] fileType: { type: Array, - default: () => ["doc", "xls", "ppt", "txt", "pdf"], + default: () => ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt", "pdf"] }, // 鏄惁鏄剧ず鎻愮ず isShowTip: { type: Boolean, default: true + }, + // 绂佺敤缁勪欢锛堜粎鏌ョ湅鏂囦欢锛� + disabled: { + type: Boolean, + default: false } }); @@ -70,7 +86,7 @@ const number = ref(0); const uploadList = ref([]); const baseUrl = import.meta.env.VITE_APP_BASE_API; -const uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 涓婁紶鏂囦欢鏈嶅姟鍣ㄥ湴鍧� +const uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + props.action); // 涓婁紶鏂囦欢鏈嶅姟鍣ㄥ湴鍧� const headers = ref({ Authorization: "Bearer " + getToken() }); const fileList = ref([]); const showTip = computed( @@ -134,6 +150,7 @@ // 涓婁紶澶辫触 function handleUploadError(err) { proxy.$modal.msgError("涓婁紶鏂囦欢澶辫触"); + proxy.$modal.closeLoading(); } // 涓婁紶鎴愬姛鍥炶皟 -- Gitblit v1.9.3