mali-applet-ui 1.0.27 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -69,6 +69,28 @@ function normalizeChooseAndUploadFileRes (res, fileType) {
|
|
|
69
69
|
return res
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
function compressImages (tempFiles, opts) {
|
|
73
|
+
return Promise.all(
|
|
74
|
+
tempFiles.map(item => {
|
|
75
|
+
return new Promise(resolve => {
|
|
76
|
+
uni.compressImage({
|
|
77
|
+
src: item.path,
|
|
78
|
+
quality: opts.quality || 80,
|
|
79
|
+
success (compressRes) {
|
|
80
|
+
resolve({
|
|
81
|
+
...item,
|
|
82
|
+
path: compressRes.tempFilePath
|
|
83
|
+
})
|
|
84
|
+
},
|
|
85
|
+
fail () {
|
|
86
|
+
resolve(item)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
72
94
|
function uploadImageFiles (opts) {
|
|
73
95
|
return new Promise((resolve, reject) => {
|
|
74
96
|
uni.chooseImage({
|
|
@@ -77,8 +99,19 @@ function uploadImageFiles (opts) {
|
|
|
77
99
|
// #ifdef MP-WEIXIN
|
|
78
100
|
sizeType: opts.sizeType,
|
|
79
101
|
// #endif
|
|
80
|
-
success (
|
|
81
|
-
|
|
102
|
+
success (chooseRes) {
|
|
103
|
+
const rest = normalizeChooseAndUploadFileRes(chooseRes, 'image')
|
|
104
|
+
// 如果是图片类型,支持压缩比例
|
|
105
|
+
if (opts.quality) {
|
|
106
|
+
compressImages(rest.tempFiles, opts).then((compressFiles) => {
|
|
107
|
+
resolve({
|
|
108
|
+
...rest,
|
|
109
|
+
tempFiles: compressFiles
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
} else {
|
|
113
|
+
resolve(rest)
|
|
114
|
+
}
|
|
82
115
|
},
|
|
83
116
|
fail (res) {
|
|
84
117
|
reject(res)
|
|
@@ -150,6 +183,7 @@ export default {
|
|
|
150
183
|
type: Object,
|
|
151
184
|
default: () => ({})
|
|
152
185
|
},
|
|
186
|
+
imageQuality: Number,
|
|
153
187
|
sizeType: {
|
|
154
188
|
type: Array,
|
|
155
189
|
default: () => ['original', 'compressed']
|
|
@@ -437,7 +471,8 @@ export default {
|
|
|
437
471
|
chooseMethod({
|
|
438
472
|
sizeType: this.sizeType,
|
|
439
473
|
sourceType: this.sourceType,
|
|
440
|
-
count: this.limit - this.fileList.length
|
|
474
|
+
count: this.limit - this.fileList.length,
|
|
475
|
+
quality: this.imageQuality
|
|
441
476
|
}).then(res => {
|
|
442
477
|
const { tempFiles } = res
|
|
443
478
|
this.loading = true
|