sadais-piui 1.2.7-beta192 → 1.2.7-beta193
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.
|
@@ -1238,39 +1238,58 @@ export default {
|
|
|
1238
1238
|
const hasVideo = this.fileTypes.includes('video')
|
|
1239
1239
|
const sourceType = this.getChooseFileOpts.sourceType
|
|
1240
1240
|
if (hasImage && hasVideo) {
|
|
1241
|
-
this.handleUniChooseMedia(['mix'], sourceType)
|
|
1241
|
+
this.handleUniChooseMedia({ mediaType: ['mix'], sourceType })
|
|
1242
1242
|
} else if (hasImage) {
|
|
1243
|
-
this.handleUniChooseMedia(['image'], sourceType)
|
|
1243
|
+
this.handleUniChooseMedia({ mediaType: ['image'], sourceType })
|
|
1244
1244
|
} else if (hasVideo) {
|
|
1245
|
-
this.handleUniChooseMedia(['video'], sourceType)
|
|
1245
|
+
this.handleUniChooseMedia({ mediaType: ['video'], sourceType })
|
|
1246
1246
|
}
|
|
1247
1247
|
} else {
|
|
1248
1248
|
// 选择视频
|
|
1249
|
-
this.handleUniChooseMedia(
|
|
1249
|
+
this.handleUniChooseMedia({
|
|
1250
|
+
mediaType: ['video'],
|
|
1251
|
+
sourceType: this.getChooseVideoOpts.sourceType
|
|
1252
|
+
})
|
|
1250
1253
|
}
|
|
1251
1254
|
},
|
|
1252
|
-
async handleUniChooseMedia(mediaType, sourceType) {
|
|
1255
|
+
async handleUniChooseMedia({ mediaType, sourceType }) {
|
|
1253
1256
|
const { maxDuration, camera } =
|
|
1254
1257
|
this.type === 'video' ? this.getChooseVideoOpts : this.getChooseFileOpts
|
|
1255
1258
|
|
|
1256
1259
|
try {
|
|
1257
|
-
const
|
|
1260
|
+
const chooseMediaOptions = {
|
|
1258
1261
|
count: this.getUploadMaxCount,
|
|
1259
1262
|
mediaType,
|
|
1260
1263
|
extension: this.getExtension,
|
|
1261
1264
|
sourceType,
|
|
1262
1265
|
maxDuration,
|
|
1263
1266
|
camera
|
|
1264
|
-
}
|
|
1267
|
+
}
|
|
1268
|
+
// #ifdef MP-WEIXIN
|
|
1269
|
+
// iOS 相册视频先取原文件,避免选择器压缩失败后拿不到文件路径。
|
|
1270
|
+
// 选择成功后仍沿用组件压缩及失败回退流程。
|
|
1271
|
+
const isIosVideoAlbum =
|
|
1272
|
+
this.$pi.system.systemInfo.platform === 'ios' &&
|
|
1273
|
+
sourceType.includes('album') &&
|
|
1274
|
+
mediaType.some(type => ['video', 'mix'].includes(type))
|
|
1275
|
+
if (isIosVideoAlbum) chooseMediaOptions.sizeType = ['original']
|
|
1276
|
+
// #endif
|
|
1277
|
+
const [cancel, result] = await uni.chooseMedia(chooseMediaOptions)
|
|
1265
1278
|
|
|
1266
|
-
if (cancel
|
|
1267
|
-
|
|
1268
|
-
|
|
1279
|
+
if (cancel) {
|
|
1280
|
+
if (cancel.errMsg === 'chooseMedia:fail cancel') {
|
|
1281
|
+
console.log(TAG, '用户取消选择媒体')
|
|
1282
|
+
return
|
|
1283
|
+
}
|
|
1284
|
+
throw cancel
|
|
1269
1285
|
}
|
|
1270
1286
|
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1287
|
+
if (result?.errMsg !== 'chooseMedia:ok') {
|
|
1288
|
+
throw result || new Error('选择媒体失败,未返回有效结果')
|
|
1289
|
+
}
|
|
1290
|
+
const { tempFiles } = result
|
|
1291
|
+
if (!Array.isArray(tempFiles) || tempFiles.length === 0) {
|
|
1292
|
+
throw new Error('未获取到可上传的图片或视频,请重新选择')
|
|
1274
1293
|
}
|
|
1275
1294
|
console.log(TAG, '选择媒体结果', result)
|
|
1276
1295
|
|
|
@@ -1307,9 +1326,17 @@ export default {
|
|
|
1307
1326
|
compressTempFiles.length > 0 ? compressTempFiles : tempFiles
|
|
1308
1327
|
|
|
1309
1328
|
// 检查文件大小限制
|
|
1310
|
-
this.handleCheckFileSize(tempFilePaths)
|
|
1329
|
+
await this.handleCheckFileSize(tempFilePaths)
|
|
1311
1330
|
} catch (error) {
|
|
1312
|
-
console.
|
|
1331
|
+
console.error(TAG, '选择或处理媒体失败', error)
|
|
1332
|
+
const errorMessage =
|
|
1333
|
+
error?.errMsg || error?.message || '未返回具体错误原因'
|
|
1334
|
+
uni.showModal({
|
|
1335
|
+
title: '选择或处理文件失败',
|
|
1336
|
+
content: `未能获取或处理所选图片、视频,请重新选择后重试。\n错误信息:${errorMessage}`,
|
|
1337
|
+
showCancel: false,
|
|
1338
|
+
confirmText: '我知道了'
|
|
1339
|
+
})
|
|
1313
1340
|
this.$emit('fail', error)
|
|
1314
1341
|
}
|
|
1315
1342
|
},
|
|
@@ -1328,14 +1355,26 @@ export default {
|
|
|
1328
1355
|
uni.showLoading({
|
|
1329
1356
|
title: '视频压缩中...'
|
|
1330
1357
|
})
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1358
|
+
try {
|
|
1359
|
+
const [error, result] = await uni.compressVideo({
|
|
1360
|
+
src: tempUrl,
|
|
1361
|
+
quality: 'high' // 压缩质量 支持low, medium, high
|
|
1362
|
+
})
|
|
1363
|
+
if (
|
|
1364
|
+
!error &&
|
|
1365
|
+
result?.errMsg === 'compressVideo:ok' &&
|
|
1366
|
+
result?.tempFilePath
|
|
1367
|
+
) {
|
|
1368
|
+
return result.tempFilePath
|
|
1369
|
+
}
|
|
1370
|
+
console.error(TAG, '视频压缩失败,使用选择的视频继续上传', {
|
|
1371
|
+
error,
|
|
1372
|
+
result
|
|
1373
|
+
})
|
|
1374
|
+
} catch (error) {
|
|
1375
|
+
console.error(TAG, '视频压缩异常,使用选择的视频继续上传', error)
|
|
1376
|
+
} finally {
|
|
1377
|
+
uni.hideLoading()
|
|
1339
1378
|
}
|
|
1340
1379
|
return tempUrl
|
|
1341
1380
|
},
|
|
@@ -1364,7 +1403,10 @@ export default {
|
|
|
1364
1403
|
// #endif
|
|
1365
1404
|
|
|
1366
1405
|
// #ifdef MP-WEIXIN
|
|
1367
|
-
this.handleUniChooseMedia(
|
|
1406
|
+
this.handleUniChooseMedia({
|
|
1407
|
+
mediaType: ['video'],
|
|
1408
|
+
sourceType: ['camera']
|
|
1409
|
+
})
|
|
1368
1410
|
// #endif
|
|
1369
1411
|
return
|
|
1370
1412
|
}
|
|
@@ -1379,7 +1421,10 @@ export default {
|
|
|
1379
1421
|
// #endif
|
|
1380
1422
|
|
|
1381
1423
|
// #ifdef MP-WEIXIN
|
|
1382
|
-
this.handleUniChooseMedia(
|
|
1424
|
+
this.handleUniChooseMedia({
|
|
1425
|
+
mediaType: ['video'],
|
|
1426
|
+
sourceType: ['album']
|
|
1427
|
+
})
|
|
1383
1428
|
// #endif
|
|
1384
1429
|
return
|
|
1385
1430
|
} else {
|