|
@@ -231,6 +231,7 @@
|
|
|
import {
|
|
import {
|
|
|
fetchUploadConfig,
|
|
fetchUploadConfig,
|
|
|
uploadImageFile,
|
|
uploadImageFile,
|
|
|
|
|
+ prepareImageForUpload,
|
|
|
uploadVideoFile,
|
|
uploadVideoFile,
|
|
|
fetchVideoLabels,
|
|
fetchVideoLabels,
|
|
|
publishGrassPost,
|
|
publishGrassPost,
|
|
@@ -470,6 +471,8 @@ export default {
|
|
|
chooseImageWithPermission(this, 'album', {
|
|
chooseImageWithPermission(this, 'album', {
|
|
|
count: remain,
|
|
count: remain,
|
|
|
sizeType: ['compressed'],
|
|
sizeType: ['compressed'],
|
|
|
|
|
+ // 部分端支持,压低相册原图质量
|
|
|
|
|
+ crop: { quality: 60 },
|
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
const paths = res.tempFilePaths || []
|
|
const paths = res.tempFilePaths || []
|
|
|
if (paths.length) this.uploadPaths(paths)
|
|
if (paths.length) this.uploadPaths(paths)
|
|
@@ -480,6 +483,7 @@ export default {
|
|
|
chooseImageWithPermission(this, 'camera', {
|
|
chooseImageWithPermission(this, 'camera', {
|
|
|
count: 1,
|
|
count: 1,
|
|
|
sizeType: ['compressed'],
|
|
sizeType: ['compressed'],
|
|
|
|
|
+ crop: { quality: 60 },
|
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
const paths = res.tempFilePaths || []
|
|
const paths = res.tempFilePaths || []
|
|
|
if (paths.length) this.uploadPaths(paths)
|
|
if (paths.length) this.uploadPaths(paths)
|
|
@@ -489,20 +493,35 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
async uploadPaths(paths) {
|
|
async uploadPaths(paths) {
|
|
|
|
|
+ const list = Array.isArray(paths) ? paths.filter(Boolean) : []
|
|
|
|
|
+ if (!list.length) return
|
|
|
this.uploading = true
|
|
this.uploading = true
|
|
|
uni.showLoading({ title: this.copy.publishUploading, mask: true })
|
|
uni.showLoading({ title: this.copy.publishUploading, mask: true })
|
|
|
|
|
+ let failCount = 0
|
|
|
try {
|
|
try {
|
|
|
const config = await fetchUploadConfig()
|
|
const config = await fetchUploadConfig()
|
|
|
- for (let i = 0; i < paths.length; i++) {
|
|
|
|
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
if (this.images.length >= this.maxImages) break
|
|
if (this.images.length >= this.maxImages) break
|
|
|
- const url = await uploadImageFile(paths[i], config)
|
|
|
|
|
- this.images.push(url)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 先解码再压缩,再上传,避免 HEIC / 超大图直接 upload 闪退
|
|
|
|
|
+ const ready = await prepareImageForUpload(list[i])
|
|
|
|
|
+ const url = await uploadImageFile(ready, config)
|
|
|
|
|
+ if (url) this.images.push(url)
|
|
|
|
|
+ else failCount += 1
|
|
|
|
|
+ } catch (_) {
|
|
|
|
|
+ failCount += 1
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (failCount > 0) {
|
|
|
|
|
+ this.$appKit && this.$appKit.msg(this.copy.publishUploadFailed)
|
|
|
}
|
|
}
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
this.$appKit && this.$appKit.msg((err && err.message) || this.copy.publishUploadFailed)
|
|
this.$appKit && this.$appKit.msg((err && err.message) || this.copy.publishUploadFailed)
|
|
|
} finally {
|
|
} finally {
|
|
|
this.uploading = false
|
|
this.uploading = false
|
|
|
- uni.hideLoading()
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ uni.hideLoading()
|
|
|
|
|
+ } catch (_) {}
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
removeImage(index) {
|
|
removeImage(index) {
|