sadais-piui 1.2.7-beta191 → 1.2.7-beta192

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.
@@ -512,7 +512,7 @@ export default {
512
512
  {
513
513
  id: 2,
514
514
  text: '选择微信聊天文件'
515
- },
515
+ }
516
516
  ]
517
517
  },
518
518
  currentSourceType() {
@@ -672,7 +672,19 @@ export default {
672
672
  : [])
673
673
  ]
674
674
  }
675
- return extension?.filter(ext => !!ext)
675
+ return [
676
+ ...new Set(
677
+ extension
678
+ .filter(ext => !!ext)
679
+ .map(ext =>
680
+ String(ext)
681
+ .trim()
682
+ .replace(/^\./, '')
683
+ .toLowerCase()
684
+ )
685
+ .filter(ext => !!ext)
686
+ )
687
+ ]
676
688
  }
677
689
  },
678
690
  methods: {
@@ -688,39 +700,27 @@ export default {
688
700
  return ext.toLocaleUpperCase()
689
701
  },
690
702
  isRightType(selectFile) {
691
- if(this.getExtension.length === 0) return true
692
- const isRightType = this.getExtension.some(ext =>
693
- selectFile.name.endsWith(ext)
694
- )
695
- console.log(
696
- TAG,
697
- '当前文件扩展名配置为:',
698
- this.getExtension,
699
- '当前选择文件:',
700
- selectFile.name,
701
- '是否符合:',
702
- isRightType
703
- )
704
- if (!isRightType) {
705
- uni.showModal({
706
- title: '文件类型错误',
707
- content: `请选择${this.getExtension.join('、')}类型的文件上传`,
708
- showCancel: false,
709
- confirmText: '好的',
710
- success: res => {
711
- if (res.confirm) {
712
- this.handleChoose()
713
- }
714
- }
715
- })
716
- }
717
- return isRightType
703
+ if (this.getExtension.length === 0) return true
704
+ const filePath =
705
+ typeof selectFile === 'string'
706
+ ? selectFile
707
+ : selectFile?.path || selectFile?.tempFilePath || ''
708
+ // 优先使用原始文件名,缺失时从临时路径提取。
709
+ const fileName =
710
+ selectFile?.name ||
711
+ filePath
712
+ .split(/[?#]/)[0]
713
+ .split(/[\\/]/)
714
+ .pop()
715
+ const extension = fileName.match(/\.([^.]+)$/)?.[1]?.toLowerCase()
716
+ return this.getExtension.includes(extension)
718
717
  },
719
718
  async handleDelete(index) {
720
719
  let val = null
721
- const beforeRemove = this.beforeRemove && this.beforeRemove[PI_DEFAULT_FN_FLAG]
722
- ? this.beforeRemove.fn
723
- : this.beforeRemove
720
+ const beforeRemove =
721
+ this.beforeRemove && this.beforeRemove[PI_DEFAULT_FN_FLAG]
722
+ ? this.beforeRemove.fn
723
+ : this.beforeRemove
724
724
  if (this.$pi.lang.isFunction(beforeRemove)) {
725
725
  // 删除之前的钩子, 如果定义了则使用钩子删除文件
726
726
  val = await beforeRemove(index, this.val)
@@ -849,6 +849,25 @@ export default {
849
849
  },
850
850
 
851
851
  async handleUpload(paths) {
852
+ // 所有入口统一校验,先于业务钩子和实际上传执行。
853
+ const files = paths.filter(file => this.isRightType(file))
854
+ if (files.length !== paths.length) {
855
+ uni.showModal({
856
+ title: '文件类型错误',
857
+ content: `已跳过不支持的文件,请选择${this.getExtension.join(
858
+ '、'
859
+ )}类型的文件上传`,
860
+ showCancel: false,
861
+ confirmText: '好的',
862
+ success: res => {
863
+ if (res.confirm && files.length === 0) {
864
+ this.handleChoose()
865
+ }
866
+ }
867
+ })
868
+ }
869
+ if (files.length === 0) return
870
+
852
871
  let imageUploadDuration = 0
853
872
  let imageUploadCount = 0
854
873
  const beforeUpload = this.beforeUpload[PI_DEFAULT_FN_FLAG]
@@ -861,7 +880,7 @@ export default {
861
880
  ? this.parseResultFn.fn
862
881
  : this.parseResultFn
863
882
  try {
864
- for await (const filePath of paths) {
883
+ for await (const filePath of files) {
865
884
  // ---------- 上传之前的钩子 ----------
866
885
  const file = filePath
867
886
 
@@ -1095,12 +1114,6 @@ export default {
1095
1114
  if (errMsg !== 'chooseMessageFile:ok') {
1096
1115
  throw new Error(errMsg)
1097
1116
  }
1098
- // chooseMessageFile 没有扩展名限制,这里自己做过滤
1099
- tempFiles = tempFiles.filter(file => {
1100
- return this.isRightType(file)
1101
- })
1102
- console.log(TAG, '过滤后的文件列表:', tempFiles)
1103
-
1104
1117
  // 检查文件大小限制
1105
1118
  const sizeCheckResult = this.checkFileSize(tempFiles)
1106
1119
  if (sizeCheckResult.valid && sizeCheckResult.files.length > 0) {
@@ -1151,13 +1164,14 @@ export default {
1151
1164
  compressTempFiles.push({
1152
1165
  path: filePaths[0],
1153
1166
  name: tempFile?.name || '',
1154
- size: tempFile?.size || undefined,
1167
+ size: tempFile?.size || undefined
1155
1168
  })
1156
1169
  }
1157
1170
  }
1158
1171
  // #endif
1159
1172
 
1160
- const tempFilePaths = compressTempFiles.length > 0 ? compressTempFiles : tempFiles
1173
+ const tempFilePaths =
1174
+ compressTempFiles.length > 0 ? compressTempFiles : tempFiles
1161
1175
 
1162
1176
  if (
1163
1177
  this.getUploadMaxCount === 1 &&
@@ -1195,15 +1209,20 @@ export default {
1195
1209
  return
1196
1210
  }
1197
1211
 
1198
- let { errMsg, tempFilePath, tempFile } = result
1212
+ const { errMsg, tempFilePath, size } = result
1199
1213
  if (errMsg !== 'chooseVideo:ok') {
1200
1214
  throw new Error(errMsg)
1201
1215
  }
1202
- tempFile.path = tempFilePath
1216
+ let file = { path: tempFilePath, size }
1217
+ // #ifdef H5
1218
+ // H5 保留原始 File 对象,使用其文件名校验 blob 临时文件。
1219
+ file = result.tempFile || file
1220
+ file.path = tempFilePath
1221
+ // #endif
1203
1222
  console.log(TAG, '上传视频结果', result)
1204
1223
 
1205
1224
  // 检查文件大小限制
1206
- const sizeCheckResult = this.checkFileSize([tempFile])
1225
+ const sizeCheckResult = this.checkFileSize([file])
1207
1226
  if (sizeCheckResult.valid && sizeCheckResult.files.length > 0) {
1208
1227
  this.handleUpload(sizeCheckResult.files)
1209
1228
  }
@@ -1278,13 +1297,14 @@ export default {
1278
1297
  compressTempFiles.push({
1279
1298
  path: filePath,
1280
1299
  name: tempFile?.name || '',
1281
- size: tempFile?.size || undefined,
1300
+ size: tempFile?.size || undefined
1282
1301
  })
1283
1302
  }
1284
1303
  }
1285
1304
  // #endif
1286
1305
 
1287
- const tempFilePaths = compressTempFiles.length > 0 ? compressTempFiles : tempFiles
1306
+ const tempFilePaths =
1307
+ compressTempFiles.length > 0 ? compressTempFiles : tempFiles
1288
1308
 
1289
1309
  // 检查文件大小限制
1290
1310
  this.handleCheckFileSize(tempFilePaths)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta191",
3
+ "version": "1.2.7-beta192",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -25,4 +25,4 @@
25
25
  "publishConfig": {
26
26
  "registry": "https://registry.npmjs.org/"
27
27
  }
28
- }
28
+ }