sadais-piui 1.2.7-beta183 → 1.2.7-beta184

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.
@@ -107,7 +107,7 @@
107
107
  <pi-img-cropper
108
108
  :custom-style="getCropOption.customStyle"
109
109
  :custom-class="getCropOption.customClass"
110
- :src="cropPic"
110
+ :src="cropPic.path"
111
111
  :file-type="getCropOption.fileType"
112
112
  :quality="getCropOption.quality"
113
113
  :crop-size="getCropOption.cropSize"
@@ -175,8 +175,6 @@ import {
175
175
  parseFileSize,
176
176
  formatFileSize,
177
177
  getFileInfoForPaths,
178
- getImageInfo,
179
- calculateCompressDimensions,
180
178
  handleCompressImgs,
181
179
  downloadFileAndPreview
182
180
  } from '../../utils/file-utils'
@@ -328,7 +326,9 @@ export default {
328
326
  crop: {
329
327
  type: Boolean,
330
328
  // `false`
331
- default: uploadImg.crop
329
+ default() {
330
+ return uploadImg.crop
331
+ }
332
332
  },
333
333
  // 裁剪参数
334
334
  cropOption: {
@@ -465,7 +465,10 @@ export default {
465
465
  data() {
466
466
  return {
467
467
  showCrop: false, // 是否显示裁剪工具
468
- cropPic: '', // 需要剪裁的图片
468
+ cropPic: {
469
+ path: '',
470
+ name: ''
471
+ }, // 需要剪裁的图片
469
472
  cropedPic: '', // 剪裁后的图片
470
473
  showActionSheet: false, // 是否显示上传视频操作面板
471
474
  showCustomTakePhoto: false // 是否显示自定义拍照操作面板
@@ -910,21 +913,17 @@ export default {
910
913
  console.log(TAG, '取消剪裁')
911
914
  this.$emit('cancelCrop')
912
915
  this.showCrop = false
913
- this.cropPic = ''
916
+ this.cropPic = {
917
+ path: '',
918
+ name: ''
919
+ }
914
920
  },
915
921
  async handleCompelteCrop() {
916
922
  console.log(TAG, '完成剪裁')
917
923
  this.$emit('croped', [this.cropedPic])
918
924
  this.showCrop = false
919
925
 
920
- // 剪裁完成后也要检查文件大小
921
- const tempFilesWithSize = await getFileInfoForPaths([this.cropedPic])
922
- const sizeCheckResult = this.checkFileSize(tempFilesWithSize)
923
-
924
- if (sizeCheckResult.valid && sizeCheckResult.files.length > 0) {
925
- const validPaths = sizeCheckResult.files.map(file => file.path || file)
926
- this.handleUpload(validPaths)
927
- }
926
+ this.handleCheckFileSize([this.cropPic])
928
927
  },
929
928
 
930
929
  handleChoose() {
@@ -1013,7 +1012,7 @@ export default {
1013
1012
  }
1014
1013
 
1015
1014
  let { errMsg, tempFiles } = result
1016
- console.log(TAG, '上传文件结果', result)
1015
+ console.log(TAG, '选择文件结果', result)
1017
1016
  if (errMsg !== 'chooseFile:ok') {
1018
1017
  throw new Error(errMsg)
1019
1018
  }
@@ -1091,19 +1090,39 @@ export default {
1091
1090
  return
1092
1091
  }
1093
1092
 
1094
- let { errMsg, tempFilePaths } = result
1093
+ let { errMsg, tempFiles } = result
1095
1094
  if (errMsg !== 'chooseImage:ok') {
1096
1095
  throw new Error(errMsg)
1097
1096
  }
1097
+
1098
+ console.log(TAG, '选择图片结果', tempFiles)
1099
+
1100
+ const compressTempFiles = []
1101
+
1098
1102
  // #ifndef H5
1099
- // 压缩图片
1100
- if (this.compressOption) {
1101
- tempFilePaths = await handleCompressImgs(
1102
- tempFilePaths,
1103
- this.compressOption
1104
- )
1103
+ // 非H5端/开发者工具,执行压缩图片操作
1104
+ if (this.$pi.system.systemInfo.platform !== 'devtools') {
1105
+ for await (const tempFile of tempFiles) {
1106
+ const filePaths = await handleCompressImgs(
1107
+ [tempFile.path],
1108
+ this.compressOption
1109
+ )
1110
+
1111
+ compressTempFiles.push({
1112
+ path: filePaths[0],
1113
+ name: tempFile?.name || '',
1114
+ size: tempFile?.size || undefined,
1115
+ })
1116
+ }
1105
1117
  }
1106
1118
  // #endif
1119
+
1120
+ const tempFilePaths = compressTempFiles.length > 0 ? compressTempFiles : tempFiles
1121
+
1122
+ console.log('this.getUploadMaxCount',this.getUploadMaxCount)
1123
+ console.log('this.crop',this.crop)
1124
+ console.log('tempFilePaths.length',tempFilePaths.length)
1125
+
1107
1126
  if (
1108
1127
  this.getUploadMaxCount === 1 &&
1109
1128
  this.crop &&
@@ -1115,18 +1134,7 @@ export default {
1115
1134
  return
1116
1135
  }
1117
1136
 
1118
- // 对于选择的图片路径,我们需要构造合适的文件对象进行大小检查
1119
- // uni-app 的 chooseImage 返回的 tempFilePaths 不包含文件大小信息
1120
- const tempFilesWithSize = await getFileInfoForPaths(tempFilePaths)
1121
- const sizeCheckResult = this.checkFileSize(tempFilesWithSize)
1122
-
1123
- if (sizeCheckResult.valid && sizeCheckResult.files.length > 0) {
1124
- // 恢复为路径数组格式传递给 handleUpload
1125
- const validPaths = sizeCheckResult.files.map(
1126
- file => file.path || file
1127
- )
1128
- this.handleUpload(validPaths)
1129
- }
1137
+ this.handleCheckFileSize(tempFilePaths)
1130
1138
  } catch (error) {
1131
1139
  console.log(TAG, '上传文件失败', error)
1132
1140
  this.$emit('fail', error)
@@ -1209,12 +1217,13 @@ export default {
1209
1217
  if (errMsg !== 'chooseMedia:ok') {
1210
1218
  throw new Error(errMsg)
1211
1219
  }
1212
- console.log(TAG, '上传媒体结果', result)
1220
+ console.log(TAG, '选择媒体结果', result)
1221
+
1222
+ const compressTempFiles = []
1213
1223
 
1214
1224
  // #ifndef H5
1215
1225
  // 非H5端/开发者工具,上传视频,执行压缩视频操作
1216
1226
  if (this.$pi.system.systemInfo.platform !== 'devtools') {
1217
- const compressTempFiles = []
1218
1227
  for await (const tempFile of tempFiles) {
1219
1228
  const tempFilePath = tempFile.tempFilePath
1220
1229
  let filePath = ''
@@ -1230,25 +1239,33 @@ export default {
1230
1239
  filePath = tempFile.tempFilePath
1231
1240
  }
1232
1241
 
1233
- compressTempFiles.push(filePath)
1242
+ compressTempFiles.push({
1243
+ path: filePath,
1244
+ name: tempFile?.name || '',
1245
+ size: tempFile?.size || undefined,
1246
+ })
1234
1247
  }
1235
- this.handleUpload(compressTempFiles)
1236
- return
1237
1248
  }
1238
1249
  // #endif
1239
1250
 
1251
+ const tempFilePaths = compressTempFiles.length > 0 ? compressTempFiles : tempFiles
1252
+
1240
1253
  // 检查文件大小限制
1241
- const sizeCheckResult = this.checkFileSize(tempFiles)
1242
- if (sizeCheckResult.valid && sizeCheckResult.files.length > 0) {
1243
- this.handleUpload(
1244
- sizeCheckResult.files.map(file => file.tempFilePath || file)
1245
- )
1246
- }
1254
+ this.handleCheckFileSize(tempFilePaths)
1247
1255
  } catch (error) {
1248
1256
  console.log(TAG, '上传视频失败', error)
1249
1257
  this.$emit('fail', error)
1250
1258
  }
1251
1259
  },
1260
+ // 检查文件大小限制
1261
+ async handleCheckFileSize(tempFilePaths) {
1262
+ const tempFilesWithSize = await getFileInfoForPaths(tempFilePaths)
1263
+ const sizeCheckResult = this.checkFileSize(tempFilesWithSize)
1264
+ console.log(TAG, '检查文件大小限制结果', sizeCheckResult)
1265
+ if (sizeCheckResult.valid && sizeCheckResult.files.length > 0) {
1266
+ this.handleUpload(sizeCheckResult.files)
1267
+ }
1268
+ },
1252
1269
  // 压缩视频接口
1253
1270
  async handleCompressVideo(tempUrl) {
1254
1271
  console.log('视频压缩中')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta183",
3
+ "version": "1.2.7-beta184",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -84,25 +84,45 @@ export function formatFileSize(bytes) {
84
84
  export async function getFileInfoForPaths(filePaths) {
85
85
  const fileInfos = []
86
86
 
87
- for (const filePath of filePaths) {
87
+ for (const file of filePaths) {
88
+ const filePath = file.path || file.tempFilePath || file
88
89
  try {
90
+
91
+ if (file.size) {
92
+ fileInfos.push({
93
+ path: filePath,
94
+ name: file?.name || '',
95
+ size: file.size
96
+ })
97
+ continue
98
+ }
99
+
89
100
  const [, fileInfo] = await uni.getFileInfo({
90
- filePath: filePath
101
+ filePath
91
102
  })
92
103
 
93
104
  if (fileInfo && fileInfo.size !== undefined) {
94
105
  fileInfos.push({
95
106
  path: filePath,
107
+ name: file?.name || '',
96
108
  size: fileInfo.size
97
109
  })
98
110
  } else {
99
111
  // 如果无法获取文件信息,保持原路径(跳过大小检查)
100
- fileInfos.push(filePath)
112
+ fileInfos.push({
113
+ path: filePath,
114
+ name: file?.name || '',
115
+ size: undefined
116
+ })
101
117
  }
102
118
  } catch (error) {
103
119
  console.log('获取文件信息失败', error)
104
120
  // 如果获取文件信息失败,保持原路径(跳过大小检查)
105
- fileInfos.push(filePath)
121
+ fileInfos.push({
122
+ path: filePath,
123
+ name: file?.name || '',
124
+ size: undefined
125
+ })
106
126
  }
107
127
  }
108
128