From 01439f14432ee731be561d193c88e3ea31399345 Mon Sep 17 00:00:00 2001 From: zxl <763096477@qq.com> Date: 星期五, 11 七月 2025 09:58:59 +0800 Subject: [PATCH] 活动添加 --- components/uview-components/uview-ui/components/u-upload/u-upload.vue | 27 ++++++++++++++++++++++----- 1 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/uview-components/uview-ui/components/u-upload/u-upload.vue b/components/uview-components/uview-ui/components/u-upload/u-upload.vue index 490ddf9..abb90f9 100644 --- a/components/uview-components/uview-ui/components/u-upload/u-upload.vue +++ b/components/uview-components/uview-ui/components/u-upload/u-upload.vue @@ -100,7 +100,7 @@ // 鍚庣鍦板潃 action: { type: String, - default: '' + default: 'http://127.0.0.1:8890/common/lmk/file/upload' }, // 鏈�澶т笂浼犳暟閲� maxCount: { @@ -394,12 +394,13 @@ this.lists[index].error = false; this.uploading = true; // 鍒涘缓涓婁紶瀵硅薄 + const task = uni.uploadFile({ url: this.action, filePath: this.lists[index].url, - name: this.name, - formData: this.formData, - header: this.header, + name: 'file', + // file: this.formData, + // header: this.header, success: res => { // 鍒ゆ柇鏄惁json瀛楃涓诧紝灏嗗叾杞负json鏍煎紡 let data = this.toJson && this.$u.test.jsonString(res.data) ? JSON.parse(res.data) : res.data; @@ -407,10 +408,11 @@ this.uploadError(index, data); } else { // 涓婁紶鎴愬姛 + const fileType = this.getFileType(this.lists[index].url); this.lists[index].response = data; this.lists[index].progress = 100; this.lists[index].error = false; - this.$emit('on-success', data, index, this.lists); + this.$emit('success', data, index, this.lists,fileType); } }, fail: e => { @@ -430,6 +432,21 @@ } }); }, + getFileType(filePath) { + const extension = filePath.split('.').pop().toLowerCase(); + // 鍥剧墖绫诲瀷 + const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp']; + // 瑙嗛绫诲瀷 + const videoTypes = ['mp4', 'mov', 'avi', 'wmv', 'flv', 'm3u8']; + + if (imageTypes.includes(extension)) { + return 'image'; + } else if (videoTypes.includes(extension)) { + return 'video'; + } else { + return 'text'; // 鍏朵粬鎵�鏈夌被鍨嬪綊涓簍ext + } + }, // 涓婁紶澶辫触 uploadError(index, err) { this.lists[index].progress = 0; -- Gitblit v1.8.0