提交 190883af 编写于 作者: Anne_LXM's avatar Anne_LXM 提交者: Anne_LXM

更新uni-file-picker

上级 049a0063
## 1.0.3(2022-12-21) ## 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)
- 新增 sourceType 属性, 可以自定义图片和视频选择的来源 - 新增 sourceType 属性, 可以自定义图片和视频选择的来源
## 1.0.2(2022-07-04) ## 1.0.2(2022-07-04)
- 修复 在uni-forms下样式不生效的bug - 修复 在uni-forms下样式不生效的bug
......
...@@ -11,6 +11,28 @@ function chooseImage(opts) { ...@@ -11,6 +11,28 @@ function chooseImage(opts) {
extension extension
} = opts } = opts
return new Promise((resolve, reject) => { 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({ uni.chooseImage({
count, count,
sizeType, sizeType,
...@@ -25,11 +47,14 @@ function chooseImage(opts) { ...@@ -25,11 +47,14 @@ function chooseImage(opts) {
}); });
}, },
}); });
// #endif
}); });
} }
function chooseVideo(opts) { function chooseVideo(opts) {
const { const {
count,
camera, camera,
compressed, compressed,
maxDuration, maxDuration,
...@@ -37,6 +62,45 @@ function chooseVideo(opts) { ...@@ -37,6 +62,45 @@ function chooseVideo(opts) {
extension extension
} = opts; } = opts;
return new Promise((resolve, reject) => { 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({ uni.chooseVideo({
camera, camera,
compressed, compressed,
...@@ -54,8 +118,7 @@ function chooseVideo(opts) { ...@@ -54,8 +118,7 @@ function chooseVideo(opts) {
resolve(normalizeChooseAndUploadFileRes({ resolve(normalizeChooseAndUploadFileRes({
errMsg: 'chooseVideo:ok', errMsg: 'chooseVideo:ok',
tempFilePaths: [tempFilePath], tempFilePaths: [tempFilePath],
tempFiles: [ tempFiles: [{
{
name: (res.tempFile && res.tempFile.name) || '', name: (res.tempFile && res.tempFile.name) || '',
path: tempFilePath, path: tempFilePath,
size, size,
...@@ -74,6 +137,7 @@ function chooseVideo(opts) { ...@@ -74,6 +137,7 @@ function chooseVideo(opts) {
}); });
}, },
}); });
// #endif
}); });
} }
...@@ -211,8 +275,7 @@ function chooseAndUploadFile(opts = { ...@@ -211,8 +275,7 @@ function chooseAndUploadFile(opts = {
}) { }) {
if (opts.type === 'image') { if (opts.type === 'image') {
return uploadFiles(chooseImage(opts), opts); return uploadFiles(chooseImage(opts), opts);
} } else if (opts.type === 'video') {
else if (opts.type === 'video') {
return uploadFiles(chooseVideo(opts), opts); return uploadFiles(chooseVideo(opts), opts);
} }
return uploadFiles(chooseAll(opts), opts); return uploadFiles(chooseAll(opts), opts);
......
...@@ -89,24 +89,18 @@ ...@@ -89,24 +89,18 @@
}, },
emits: ['select', 'success', 'fail', 'progress', 'delete', 'update:modelValue', 'input'], emits: ['select', 'success', 'fail', 'progress', 'delete', 'update:modelValue', 'input'],
props: { props: {
// #ifdef VUE3
modelValue: { modelValue: {
type: [Array, Object], type: [Array, Object],
default () { default () {
return [] return []
} }
}, },
// #endif
// #ifndef VUE3
value: { value: {
type: [Array, Object], type: [Array, Object],
default () { default () {
return [] return []
} }
}, },
// #endif
disabled: { disabled: {
type: Boolean, type: Boolean,
default: false default: false
...@@ -191,6 +185,10 @@ ...@@ -191,6 +185,10 @@
default () { default () {
return ['album', 'camera'] return ['album', 'camera']
} }
},
provider: {
type: String,
default: '' // 默认上传到 unicloud 内置存储 extStorage 扩展存储
} }
}, },
data() { data() {
...@@ -200,22 +198,18 @@ ...@@ -200,22 +198,18 @@
} }
}, },
watch: { watch: {
// #ifndef VUE3
value: { value: {
handler(newVal, oldVal) { handler(newVal, oldVal) {
this.setValue(newVal, oldVal) this.setValue(newVal, oldVal)
}, },
immediate: true immediate: true
}, },
// #endif
// #ifdef VUE3
modelValue: { modelValue: {
handler(newVal, oldVal) { handler(newVal, oldVal) {
this.setValue(newVal, oldVal) this.setValue(newVal, oldVal)
}, },
immediate: true immediate: true
}, },
// #endif
}, },
computed: { computed: {
filesList() { filesList() {
...@@ -331,7 +325,6 @@ ...@@ -331,7 +325,6 @@
* 选择文件 * 选择文件
*/ */
choose() { choose() {
if (this.disabled) return if (this.disabled) return
if (this.files.length >= Number(this.limitLength) && this.showType !== 'grid' && this.returnType === if (this.files.length >= Number(this.limitLength) && this.showType !== 'grid' && this.returnType ===
'array') { 'array') {
...@@ -418,6 +411,13 @@ ...@@ -418,6 +411,13 @@
if (!this.autoUpload || this.noSpace) { if (!this.autoUpload || this.noSpace) {
res.tempFiles = [] 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 @@ ...@@ -523,6 +523,7 @@
*/ */
delFile(index) { delFile(index) {
this.$emit('delete', { this.$emit('delete', {
index,
tempFile: this.files[index], tempFile: this.files[index],
tempFilePath: this.files[index].url tempFilePath: this.files[index].url
}) })
......
...@@ -90,6 +90,7 @@ export const get_file_data = async (files, type = 'image') => { ...@@ -90,6 +90,7 @@ export const get_file_data = async (files, type = 'image') => {
extname: extname || '', extname: extname || '',
cloudPath: files.cloudPath, cloudPath: files.cloudPath,
fileType: files.fileType, fileType: files.fileType,
thumbTempFilePath: files.thumbTempFilePath,
url: files.path || files.path, url: files.path || files.path,
size: files.size, //单位是字节 size: files.size, //单位是字节
image: {}, image: {},
......
{ {
"id": "uni-file-picker", "id": "uni-file-picker",
"displayName": "uni-file-picker 文件选择上传", "displayName": "uni-file-picker 文件选择上传",
"version": "1.0.3", "version": "1.0.11",
"description": "文件选择上传组件,可以选择图片、视频等任意文件并上传到当前绑定的服务空间", "description": "文件选择上传组件,可以选择图片、视频等任意文件并上传到当前绑定的服务空间",
"keywords": [ "keywords": [
"uni-ui", "uni-ui",
...@@ -42,7 +42,8 @@ ...@@ -42,7 +42,8 @@
"platforms": { "platforms": {
"cloud": { "cloud": {
"tcb": "y", "tcb": "y",
"aliyun": "y" "aliyun": "y",
"alipay": "n"
}, },
"client": { "client": {
"App": { "App": {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册