sadais-piui 1.2.7-beta109 → 1.2.7-beta110

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.
@@ -1,7 +1,7 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2021-08-13 11:31:57
4
- * @LastEditTime: 2024-05-29 10:35:00
4
+ * @LastEditTime: 2024-06-07 12:06:47
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 图片上传组件
7
7
  * @FilePath: /piui-awesome/src/piui/components/pi-upload-img/index.vue
@@ -355,6 +355,13 @@ export default {
355
355
  return uploadImg.type // 'all', 'image', 'video'
356
356
  }
357
357
  },
358
+ // 当 type 为 all 时生效,允许上传的文件类型是否包含 video 和 image
359
+ fileTypes: {
360
+ type: Array,
361
+ default() {
362
+ return uploadImg.fileTypes
363
+ }
364
+ },
358
365
  // 当type为 "all"时生效,调用uni.chooseFile参数
359
366
  chooseFileOpts: {
360
367
  type: Object,
@@ -480,6 +487,26 @@ export default {
480
487
  },
481
488
  getCropOption() {
482
489
  return this.$pi.lang.mergeDeep(uploadImg.cropOption, this.cropOption)
490
+ },
491
+ getExtension() {
492
+ let extension = []
493
+ if (this.type === 'image') {
494
+ extension = this.getChooseImageOpts.extension
495
+ } else if (this.type === 'video') {
496
+ extension = this.getChooseVideoOpts.extension
497
+ } else {
498
+ // all
499
+ extension = [
500
+ ...this.getChooseFileOpts.extension,
501
+ ...(this.fileTypes.includes('image')
502
+ ? this.getChooseImageOpts.extension
503
+ : []),
504
+ ...(this.fileTypes.includes('video')
505
+ ? this.getChooseVideoOpts.extension
506
+ : [])
507
+ ]
508
+ }
509
+ return extension.filter(ext => !!ext)
483
510
  }
484
511
  },
485
512
  methods: {
@@ -491,15 +518,20 @@ export default {
491
518
  return ext.toLocaleUpperCase()
492
519
  },
493
520
  isRightType(selectFile) {
494
- const { extension } = this.getChooseImageOpts
495
- let isRightType = false
496
- extension.forEach(ext => {
497
- if (selectFile.name.endsWith(ext)) {
498
- isRightType = true
499
- }
500
- })
521
+ const isRightType = this.getExtension.some(ext =>
522
+ selectFile.name.endsWith(ext)
523
+ )
524
+ console.log(
525
+ TAG,
526
+ '当前文件扩展名配置为:',
527
+ this.getExtension,
528
+ '当前选择文件:',
529
+ selectFile.name,
530
+ '是否符合:',
531
+ isRightType
532
+ )
501
533
  if (!isRightType) {
502
- this.$toast(`请选择${extension}文件上传`)
534
+ this.$toast(`请选择${this.getExtension.join('/')}文件上传`)
503
535
  }
504
536
  return isRightType
505
537
  },
@@ -719,12 +751,12 @@ export default {
719
751
  }
720
752
  },
721
753
  async handleChooseFile() {
722
- const { sizeType, extension, sourceType, crop } = this.getChooseFileOpts
754
+ const { sizeType, sourceType, crop } = this.getChooseFileOpts
723
755
  try {
724
756
  const [, result] = await uni.chooseFile({
725
757
  count: this.getUploadMaxCount,
726
758
  sizeType,
727
- extension,
759
+ extension: this.getExtension,
728
760
  sourceType,
729
761
  crop
730
762
  })
@@ -752,7 +784,10 @@ export default {
752
784
  try {
753
785
  const [, result] = await uni.chooseMessageFile({
754
786
  count: this.getUploadMaxCount,
755
- type: 'file'
787
+ type:
788
+ this.fileTypes.includes('video') || this.fileTypes.includes('video')
789
+ ? 'all'
790
+ : 'file'
756
791
  })
757
792
  if (!result) {
758
793
  return
@@ -764,9 +799,9 @@ export default {
764
799
  }
765
800
  // chooseMessageFile 没有扩展名限制,这里自己做过滤
766
801
  tempFiles = tempFiles.filter(file => {
767
- const ext = file.name.split('.').pop()
768
- return this.getChooseFileOpts.extension.includes(ext)
802
+ return this.isRightType(file)
769
803
  })
804
+ console.log(TAG, '过滤后的文件列表:', tempFiles)
770
805
  this.handleUpload(tempFiles)
771
806
  } catch (error) {
772
807
  console.log(error)
@@ -774,12 +809,12 @@ export default {
774
809
  // #endif
775
810
  },
776
811
  async handleChooseImage() {
777
- const { sizeType, extension, sourceType, crop } = this.getChooseImageOpts
812
+ const { sizeType, sourceType, crop } = this.getChooseImageOpts
778
813
  try {
779
814
  const [, result] = await uni.chooseImage({
780
815
  count: this.getUploadMaxCount,
781
816
  sizeType,
782
- extension,
817
+ extension: this.getExtension,
783
818
  sourceType,
784
819
  crop
785
820
  })
@@ -833,13 +868,13 @@ export default {
833
868
  }
834
869
  },
835
870
  async handleChooseMedia() {
836
- const { sourceType, extension, maxDuration, camera } =
871
+ const { sourceType, maxDuration, camera } =
837
872
  this.type === 'video' ? this.getChooseVideoOpts : this.getChooseFileOpts
838
873
  try {
839
874
  const [, result] = await uni.chooseMedia({
840
875
  count: this.getUploadMaxCount,
841
876
  mediaType: this.type === 'video' ? ['video'] : ['mix'],
842
- extension,
877
+ extension: this.getExtension,
843
878
  sourceType,
844
879
  maxDuration,
845
880
  camera
@@ -1,10 +1,10 @@
1
1
  /*
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2021-08-13 11:29:02
4
- * @LastEditTime: 2024-05-24 15:18:10
4
+ * @LastEditTime: 2024-06-07 11:07:10
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 图片上传
7
- * @FilePath: /piui-awesome/src/piui/config/uploadImg.js
7
+ * @FilePath: /dt-weitibao-mp/node_modules/sadais-piui/config/uploadImg.js
8
8
  */
9
9
  import icon from './icon.js'
10
10
  import cropOption from './imgCropper.js'
@@ -41,6 +41,7 @@ export default {
41
41
  color: '#999999'
42
42
  },
43
43
  type: 'image', // 上传文件类型,可选值为image、video、all
44
+ fileTypes: [], // 当 type 为 all 时生效,允许上传的文件类型是否包含 video 和 image
44
45
  // 当type为 "all"时生效,调用uni.chooseFile参数
45
46
  chooseFileOpts: {
46
47
  sourceType: ['album', 'camera'], // (仅在type为image或video时可用)album 从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta109",
3
+ "version": "1.2.7-beta110",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {