sadais-piui 1.2.7-beta154 → 1.2.7-beta156

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.
@@ -180,7 +180,8 @@ import {
180
180
  formatFileSize,
181
181
  getFileInfoForPaths,
182
182
  getImageInfo,
183
- calculateCompressDimensions
183
+ calculateCompressDimensions,
184
+ handleCompressImgs
184
185
  } from '../../utils/file-utils'
185
186
 
186
187
  const TAG = 'PiUploadImg'
@@ -628,11 +629,11 @@ export default {
628
629
  }
629
630
  },
630
631
  methods: {
631
- isImageFilename() {
632
- return isImageFilename
632
+ isImageFilename(filename) {
633
+ return isImageFilename(filename)
633
634
  },
634
- isVideoFilename() {
635
- return isVideoFilename
635
+ isVideoFilename(filename) {
636
+ return isVideoFilename(filename)
636
637
  },
637
638
  getFileType(file) {
638
639
  if (!file) return ''
@@ -879,50 +880,7 @@ export default {
879
880
  this.handleUpload(validPaths)
880
881
  }
881
882
  },
882
- async handleCompressImgs(tempFilePaths) {
883
- const compressUrls = []
884
883
 
885
- for (let index = 0; index < tempFilePaths.length; index++) {
886
- const url = tempFilePaths[index]
887
-
888
- // 获取图片信息并计算智能压缩参数
889
- const imageInfo = await getImageInfo(url)
890
- const compressDimensions = calculateCompressDimensions(
891
- imageInfo,
892
- this.compressOption
893
- )
894
-
895
- // 构建压缩参数
896
- const compressParams = {
897
- src: url,
898
- ...this.compressOption
899
- }
900
-
901
- // 如果启用了智能压缩,添加宽高参数
902
- if (this.compressOption && this.compressOption.smartCompress) {
903
- compressParams.compressedWidth = compressDimensions.width
904
- compressParams.compressedHeight = compressDimensions.height
905
- }
906
-
907
- console.log('图片压缩参数', compressParams)
908
-
909
- const [, result] = await uni.compressImage(compressParams)
910
- const { errMsg, tempFilePath } = result
911
-
912
- if (
913
- errMsg == 'compressImage:ok' &&
914
- tempFilePath &&
915
- typeof tempFilePath == 'string'
916
- ) {
917
- compressUrls.push(tempFilePath)
918
- console.log(TAG, '智能压缩图片成功', tempFilePath)
919
- } else {
920
- compressUrls.push(url)
921
- console.log(TAG, '压缩图片失败,使用原图', tempFilePath, 'src=' + url)
922
- }
923
- }
924
- return compressUrls
925
- },
926
884
  handleChoose() {
927
885
  if (this.disabled || !this.getUploadMaxCount) return
928
886
  // 检查上传地址
@@ -1081,11 +1039,11 @@ export default {
1081
1039
  }
1082
1040
  // #ifndef H5
1083
1041
  // 压缩图片
1084
- if (
1085
- this.compressOption &&
1086
- this.$pi.system.systemInfo.platform !== 'devtools'
1087
- ) {
1088
- tempFilePaths = await this.handleCompressImgs(tempFilePaths)
1042
+ if (this.compressOption) {
1043
+ tempFilePaths = await handleCompressImgs(
1044
+ tempFilePaths,
1045
+ this.compressOption
1046
+ )
1089
1047
  }
1090
1048
  // #endif
1091
1049
  if (
@@ -1195,9 +1153,10 @@ export default {
1195
1153
  const tempFilePath = tempFile.tempFilePath
1196
1154
  let filePath = ''
1197
1155
  if (isImageFilename(tempFilePath)) {
1198
- const filePaths = await this.handleCompressImgs([
1199
- tempFile.tempFilePath
1200
- ])
1156
+ const filePaths = await handleCompressImgs(
1157
+ [tempFile.tempFilePath],
1158
+ this.compressOption
1159
+ )
1201
1160
  filePath = filePaths[0]
1202
1161
  } else {
1203
1162
  filePath = await this.handleCompressVideo(tempFile.tempFilePath)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta154",
3
+ "version": "1.2.7-beta156",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -220,3 +220,54 @@ export function calculateCompressDimensions(imageInfo, compressOption = {}) {
220
220
 
221
221
  return { width: targetWidth, height: targetHeight }
222
222
  }
223
+
224
+ /**
225
+ * 压缩图片处理
226
+ * @param {Array<string>} tempFilePaths - 临时文件路径数组
227
+ * @param {Object} compressOption - 压缩配置选项
228
+ * @returns {Promise<Array<string>>} 压缩后的文件路径数组
229
+ */
230
+ export async function handleCompressImgs(tempFilePaths, compressOption = {}) {
231
+ const compressUrls = []
232
+
233
+ for (let index = 0; index < tempFilePaths.length; index++) {
234
+ const url = tempFilePaths[index]
235
+
236
+ // 获取图片信息并计算智能压缩参数
237
+ const imageInfo = await getImageInfo(url)
238
+ const compressDimensions = calculateCompressDimensions(
239
+ imageInfo,
240
+ compressOption
241
+ )
242
+
243
+ // 构建压缩参数
244
+ const compressParams = {
245
+ src: url,
246
+ ...compressOption
247
+ }
248
+
249
+ // 如果启用了智能压缩,添加宽高参数
250
+ if (compressOption && compressOption.smartCompress) {
251
+ compressParams.compressedWidth = compressDimensions.width
252
+ compressParams.compressedHeight = compressDimensions.height
253
+ }
254
+
255
+ console.log('图片压缩参数', compressParams)
256
+
257
+ const [, result] = await uni.compressImage(compressParams)
258
+ const { errMsg, tempFilePath } = result
259
+
260
+ if (
261
+ errMsg == 'compressImage:ok' &&
262
+ tempFilePath &&
263
+ typeof tempFilePath == 'string'
264
+ ) {
265
+ compressUrls.push(tempFilePath)
266
+ console.log('智能压缩图片成功', tempFilePath)
267
+ } else {
268
+ compressUrls.push(url)
269
+ console.log('压缩图片失败,使用原图', tempFilePath, 'src=' + url)
270
+ }
271
+ }
272
+ return compressUrls
273
+ }