diff --git a/uni_modules/uni-file-picker/changelog.md b/uni_modules/uni-file-picker/changelog.md index b8230e9f9b8919f17ab537488b99ba8842bb7efe..b81e7f91353cb4caceb75fbae769381f2c0aa78f 100644 --- a/uni_modules/uni-file-picker/changelog.md +++ b/uni_modules/uni-file-picker/changelog.md @@ -1,3 +1,17 @@ +## 1.0.11(2024-07-19) +- 修复 vue3 使用value报错的bug +## 1.0.10(2024-07-09) +- 优化 vue3兼容性 +## 1.0.9(2024-07-09) +- 修复 value 属性不兼容vue3的bug +## 1.0.8(2024-03-20) +- 补充 删除文件时返回文件下标 +## 1.0.7(2024-02-21) +- 新增 微信小程序选择视频时改用chooseMedia,并返回视频缩略图 +## 1.0.6(2024-01-06) +- 新增 微信小程序不再调用chooseImage,而是调用chooseMedia +## 1.0.5(2024-01-03) +- 新增 上传文件至云存储携带本地文件名称 ## 1.0.4(2023-03-29) - 修复 手动上传删除一个文件后不能再上传的bug ## 1.0.3(2022-12-19) diff --git a/uni_modules/uni-file-picker/components/uni-file-picker/choose-and-upload-file.js b/uni_modules/uni-file-picker/components/uni-file-picker/choose-and-upload-file.js index 018590d6ce9255ac5d1d485dc171e5464a0a2da6..c4ff85ddb972292f4ee80422f63fe819bfd7d22c 100644 --- a/uni_modules/uni-file-picker/components/uni-file-picker/choose-and-upload-file.js +++ b/uni_modules/uni-file-picker/components/uni-file-picker/choose-and-upload-file.js @@ -11,6 +11,28 @@ function chooseImage(opts) { extension } = opts return new Promise((resolve, reject) => { + // 微信由于旧接口不再维护,针对微信小程序平台改用chooseMedia接口 + // #ifdef MP-WEIXIN + uni.chooseMedia({ + count, + sizeType, + sourceType, + mediaType: ['image'], + extension, + success(res) { + res.tempFiles.forEach(item => { + item.path = item.tempFilePath; + }) + resolve(normalizeChooseAndUploadFileRes(res, 'image')); + }, + fail(res) { + reject({ + errMsg: res.errMsg.replace('chooseImage:fail', ERR_MSG_FAIL), + }); + }, + }) + // #endif + // #ifndef MP-WEIXIN uni.chooseImage({ count, sizeType, @@ -25,11 +47,14 @@ function chooseImage(opts) { }); }, }); + // #endif + }); } function chooseVideo(opts) { const { + count, camera, compressed, maxDuration, @@ -37,6 +62,45 @@ function chooseVideo(opts) { extension } = opts; return new Promise((resolve, reject) => { + // 微信由于旧接口不再维护,针对微信小程序平台改用chooseMedia接口 + // #ifdef MP-WEIXIN + uni.chooseMedia({ + count, + compressed, + maxDuration, + sourceType, + extension, + mediaType: ['video'], + success(res) { + const { + tempFiles, + } = res; + resolve(normalizeChooseAndUploadFileRes({ + errMsg: 'chooseVideo:ok', + tempFiles: tempFiles.map(item => { + return { + name: item.name || '', + path: item.tempFilePath, + thumbTempFilePath: item.thumbTempFilePath, + size:item.size, + type: (res.tempFile && res.tempFile.type) || '', + width:item.width, + height:item.height, + duration:item.duration, + fileType: 'video', + cloudPath: '', + } + }), + }, 'video')); + }, + fail(res) { + reject({ + errMsg: res.errMsg.replace('chooseVideo:fail', ERR_MSG_FAIL), + }); + }, + }) + // #endif + // #ifndef MP-WEIXIN uni.chooseVideo({ camera, compressed, @@ -54,8 +118,7 @@ function chooseVideo(opts) { resolve(normalizeChooseAndUploadFileRes({ errMsg: 'chooseVideo:ok', tempFilePaths: [tempFilePath], - tempFiles: [ - { + tempFiles: [{ name: (res.tempFile && res.tempFile.name) || '', path: tempFilePath, size, @@ -74,6 +137,7 @@ function chooseVideo(opts) { }); }, }); + // #endif }); } @@ -211,8 +275,7 @@ function chooseAndUploadFile(opts = { }) { if (opts.type === 'image') { return uploadFiles(chooseImage(opts), opts); - } - else if (opts.type === 'video') { + } else if (opts.type === 'video') { return uploadFiles(chooseVideo(opts), opts); } return uploadFiles(chooseAll(opts), opts); diff --git a/uni_modules/uni-file-picker/components/uni-file-picker/uni-file-picker.vue b/uni_modules/uni-file-picker/components/uni-file-picker/uni-file-picker.vue index 7a13a6cd943fe3af42133fc870593f950891a405..95eaf304e328f6e619daffb8dc0f551cca3f6859 100644 --- a/uni_modules/uni-file-picker/components/uni-file-picker/uni-file-picker.vue +++ b/uni_modules/uni-file-picker/components/uni-file-picker/uni-file-picker.vue @@ -89,24 +89,18 @@ }, emits: ['select', 'success', 'fail', 'progress', 'delete', 'update:modelValue', 'input'], props: { - // #ifdef VUE3 modelValue: { type: [Array, Object], default () { return [] } }, - // #endif - - // #ifndef VUE3 value: { type: [Array, Object], default () { return [] } }, - // #endif - disabled: { type: Boolean, default: false @@ -191,6 +185,10 @@ default () { return ['album', 'camera'] } + }, + provider: { + type: String, + default: '' // 默认上传到 unicloud 内置存储 extStorage 扩展存储 } }, data() { @@ -200,22 +198,18 @@ } }, watch: { - // #ifndef VUE3 value: { handler(newVal, oldVal) { this.setValue(newVal, oldVal) }, immediate: true }, - // #endif - // #ifdef VUE3 modelValue: { handler(newVal, oldVal) { this.setValue(newVal, oldVal) }, immediate: true }, - // #endif }, computed: { filesList() { @@ -331,7 +325,6 @@ * 选择文件 */ choose() { - if (this.disabled) return if (this.files.length >= Number(this.limitLength) && this.showType !== 'grid' && this.returnType === 'array') { @@ -418,6 +411,13 @@ if (!this.autoUpload || this.noSpace) { res.tempFiles = [] } + res.tempFiles.forEach((fileItem, index) => { + this.provider && (fileItem.provider = this.provider); + const fileNameSplit = fileItem.name.split('.') + const ext = fileNameSplit.pop() + const fileName = fileNameSplit.join('.').replace(/[\s\/\?<>\\:\*\|":]/g, '_') + fileItem.cloudPath = fileName + '_' + Date.now() + '_' + index + '.' + ext + }) }, /** @@ -523,6 +523,7 @@ */ delFile(index) { this.$emit('delete', { + index, tempFile: this.files[index], tempFilePath: this.files[index].url }) diff --git a/uni_modules/uni-file-picker/components/uni-file-picker/upload-file.vue b/uni_modules/uni-file-picker/components/uni-file-picker/upload-file.vue index eb1840b75b51fcacc1cd09e8d187cc46770107b7..ab15bad9a64b1dc005932ba6308a120faa6f6446 100644 --- a/uni_modules/uni-file-picker/components/uni-file-picker/upload-file.vue +++ b/uni_modules/uni-file-picker/components/uni-file-picker/upload-file.vue @@ -24,7 +24,7 @@ - + 点击重试 @@ -69,10 +69,10 @@ borderStyle: {} } } - }, - readonly:{ - type:Boolean, - default:false + }, + readonly:{ + type:Boolean, + default:false } }, computed: { @@ -114,7 +114,7 @@ let classles = '' for (let i in obj) { classles += `${i}:${obj[i]};` - } + } return classles }, borderLineStyle() { @@ -133,19 +133,19 @@ } else { width = width.indexOf('px') ? width : width + 'px' } - obj['border-width'] = width - - if (typeof style === 'number') { - style += 'px' - } else { - style = style.indexOf('px') ? style : style + 'px' + obj['border-width'] = width + + if (typeof style === 'number') { + style += 'px' + } else { + style = style.indexOf('px') ? style : style + 'px' } obj['border-top-style'] = style } let classles = '' for (let i in obj) { classles += `${i}:${obj[i]};` - } + } return classles } }, @@ -176,9 +176,9 @@ + diff --git a/uni_modules/uni-file-picker/components/uni-file-picker/upload-image.vue b/uni_modules/uni-file-picker/components/uni-file-picker/upload-image.vue index 51ace0b4e385a6577c4386738516b6a4cefe1574..0c1abe8c4955a961d2ab4751f24729b4d3a5b465 100644 --- a/uni_modules/uni-file-picker/components/uni-file-picker/upload-image.vue +++ b/uni_modules/uni-file-picker/components/uni-file-picker/upload-image.vue @@ -1,7 +1,7 @@