sadais-piui 1.2.7-beta185 → 1.2.7-beta187
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.
|
@@ -367,6 +367,13 @@ export default {
|
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
},
|
|
370
|
+
// 网络异常监听配置
|
|
371
|
+
networkConfig: {
|
|
372
|
+
type: Object,
|
|
373
|
+
default() {
|
|
374
|
+
return uploadImg.networkConfig
|
|
375
|
+
}
|
|
376
|
+
},
|
|
370
377
|
// 删除之前的钩子
|
|
371
378
|
beforeRemove: {
|
|
372
379
|
type: [Object, Function],
|
|
@@ -713,12 +720,12 @@ export default {
|
|
|
713
720
|
},
|
|
714
721
|
async handleDelete(index) {
|
|
715
722
|
let val = null
|
|
716
|
-
const beforeRemove = this.beforeRemove[PI_DEFAULT_FN_FLAG]
|
|
723
|
+
const beforeRemove = this.beforeRemove && this.beforeRemove[PI_DEFAULT_FN_FLAG]
|
|
717
724
|
? this.beforeRemove.fn
|
|
718
725
|
: this.beforeRemove
|
|
719
726
|
if (this.$pi.lang.isFunction(beforeRemove)) {
|
|
720
727
|
// 删除之前的钩子, 如果定义了则使用钩子删除文件
|
|
721
|
-
val = await beforeRemove(index)
|
|
728
|
+
val = await beforeRemove(index, this.val)
|
|
722
729
|
} else {
|
|
723
730
|
val = this.isValString ? '' : this.val.filter((_, i) => i !== index)
|
|
724
731
|
}
|
|
@@ -841,6 +848,8 @@ export default {
|
|
|
841
848
|
},
|
|
842
849
|
|
|
843
850
|
async handleUpload(paths) {
|
|
851
|
+
let imageUploadDuration = 0
|
|
852
|
+
let imageUploadCount = 0
|
|
844
853
|
const beforeUpload = this.beforeUpload[PI_DEFAULT_FN_FLAG]
|
|
845
854
|
? this.beforeUpload.fn
|
|
846
855
|
: this.beforeUpload
|
|
@@ -878,13 +887,21 @@ export default {
|
|
|
878
887
|
formData: this.formData,
|
|
879
888
|
header: this.headers
|
|
880
889
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
890
|
+
const uploadStartTime = Date.now()
|
|
891
|
+
try {
|
|
892
|
+
if (this.$pi.lang.isFunction(onProgress)) {
|
|
893
|
+
console.log(TAG, '使用自定义上传函数')
|
|
894
|
+
// 上传之前的钩子, 如果定义了则使用钩子上传文件
|
|
895
|
+
uploadResult = await onProgress(params, this.customUploadParams)
|
|
896
|
+
} else {
|
|
897
|
+
const [, uploadFileResult] = await uni.uploadFile(params)
|
|
898
|
+
uploadResult = uploadFileResult
|
|
899
|
+
}
|
|
900
|
+
} finally {
|
|
901
|
+
if (this.isNetworkMonitorImage(file)) {
|
|
902
|
+
imageUploadDuration += Date.now() - uploadStartTime
|
|
903
|
+
imageUploadCount++
|
|
904
|
+
}
|
|
888
905
|
}
|
|
889
906
|
console.log(TAG, '上传文件结果', uploadResult)
|
|
890
907
|
|
|
@@ -902,6 +919,28 @@ export default {
|
|
|
902
919
|
} catch (e) {
|
|
903
920
|
console.log(TAG, '上传文件失败', e)
|
|
904
921
|
this.$emit('fail', e)
|
|
922
|
+
} finally {
|
|
923
|
+
this.handleNetworkUploadEnd(imageUploadDuration, imageUploadCount)
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
isNetworkMonitorImage(file) {
|
|
927
|
+
const filePath = file?.path || file?.tempFilePath || file || ''
|
|
928
|
+
return this.type === 'image' || isImageFilename(filePath)
|
|
929
|
+
},
|
|
930
|
+
handleNetworkUploadEnd(imageUploadDuration, imageUploadCount) {
|
|
931
|
+
const { enable, warningThreshold } = this.networkConfig || {}
|
|
932
|
+
const threshold = Number(warningThreshold)
|
|
933
|
+
if (
|
|
934
|
+
!enable ||
|
|
935
|
+
!imageUploadCount ||
|
|
936
|
+
!Number.isFinite(threshold) ||
|
|
937
|
+
threshold <= 0
|
|
938
|
+
) {
|
|
939
|
+
return
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
if (imageUploadDuration / imageUploadCount > threshold * 1000) {
|
|
943
|
+
this.$emit('networkError')
|
|
905
944
|
}
|
|
906
945
|
},
|
|
907
946
|
handleCrop(res) {
|
package/config/uploadImg.js
CHANGED
|
@@ -98,6 +98,10 @@ export default {
|
|
|
98
98
|
}, // 压缩配置
|
|
99
99
|
beforeUpload: null, // 上传之前的钩子
|
|
100
100
|
onProgress: null, // 文件上传时的钩子
|
|
101
|
+
networkConfig: {
|
|
102
|
+
enable: false,
|
|
103
|
+
warningThreshold: 10 // 慢上传提醒阈值,单位秒
|
|
104
|
+
}, // 网络异常监听配置
|
|
101
105
|
beforeRemove: null, // 删除之前的钩子
|
|
102
106
|
customTakePhoto: false, // 是否自定义拍照(如果为true,则不调用相机,通过事件自己实现拍照上传)
|
|
103
107
|
fileIconMap: {}, // 文件类型和图标映射关系,对象形式({PDF: 'https://xxx'})
|