sadais-piui 1.2.7-beta145 → 1.2.7-beta146

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.
@@ -47,7 +47,7 @@
47
47
  v-if="fileIconMap[getFileType(imgField ? img[imgField] : img)]"
48
48
  :src="fileIconMap[getFileType(imgField ? img[imgField] : img)]"
49
49
  mode="widthFix"
50
- style="width: 100%;"
50
+ style="width: 100%"
51
51
  />
52
52
  <template v-else>
53
53
  <pi-icon
@@ -143,6 +143,26 @@
143
143
  }"
144
144
  @select="handleActionSheetSelect"
145
145
  />
146
+
147
+ <!-- 自定义拍照操作面板(小程序专用) -->
148
+ <pi-select
149
+ v-model="showCustomTakePhoto"
150
+ :items="customTakePhotoItems"
151
+ :single-cancel="false"
152
+ single-confirm
153
+ :item-style="{
154
+ padding: '32rpx'
155
+ }"
156
+ :popup="{
157
+ borderRadius: 0
158
+ }"
159
+ :popup-select="{
160
+ showTitle: true,
161
+ title: '请选择拍摄方式'
162
+ }"
163
+ item-height="auto"
164
+ @confirm="handleCustomTakePhotoSelect"
165
+ />
146
166
  </view>
147
167
  </template>
148
168
 
@@ -415,6 +435,13 @@ export default {
415
435
  default() {
416
436
  return uploadImg.customUploadParams
417
437
  }
438
+ },
439
+ // 是否自定义拍照(如果为true,则不调用相机,通过事件自己实现拍照上传)
440
+ customTakePhoto: {
441
+ type: Boolean,
442
+ default() {
443
+ return uploadImg.customTakePhoto
444
+ }
418
445
  }
419
446
  },
420
447
  data() {
@@ -422,7 +449,9 @@ export default {
422
449
  showCrop: false, // 是否显示裁剪工具
423
450
  cropPic: '', // 需要剪裁的图片
424
451
  cropedPic: '', // 剪裁后的图片
425
- showActionSheet: false // 是否显示上传视频操作面板
452
+ showActionSheet: false, // 是否显示上传视频操作面板
453
+ showCustomTakePhoto: false, // 是否显示自定义拍照操作面板
454
+ currentSourceType: ['camera', 'album'] // 当前选择的拍照方式
426
455
  }
427
456
  },
428
457
  computed: {
@@ -451,6 +480,38 @@ export default {
451
480
  }
452
481
  ]
453
482
  },
483
+ customTakePhotoItems() {
484
+ // currentSourceType 当前选择的拍照方式 ['camera', 'album']
485
+ let sourceType = this.currentSourceType || ['camera', 'album']
486
+ if (sourceType.length === 0) {
487
+ sourceType = ['camera', 'album']
488
+ }
489
+ const items = [
490
+ {
491
+ id: 'takePhoto',
492
+ text: '拍摄',
493
+ desc: '拍摄完成后上传图片(信号良好下使用)',
494
+ show: sourceType.includes('camera')
495
+ },
496
+ {
497
+ id: 'takePhotoOffline',
498
+ text: '离线拍摄',
499
+ desc: '拍摄完成后缓存到相册,待网络良好时上传(信号较差时使用)',
500
+ show: sourceType.includes('camera')
501
+ },
502
+ {
503
+ id: 'chooseFromAlbum',
504
+ text: '从手机相册选择',
505
+ show: sourceType.includes('album')
506
+ },
507
+ {
508
+ id: 'chooseFromCacheAlbum',
509
+ text: '从缓存相册选择',
510
+ show: true
511
+ }
512
+ ]
513
+ return items.filter(item => item.show)
514
+ },
454
515
  selectOnlyFile() {
455
516
  return this.type === 'all' && this.fileTypes.length === 0
456
517
  },
@@ -886,6 +947,17 @@ export default {
886
947
  },
887
948
  async handleChooseImage() {
888
949
  const { sizeType, sourceType, crop } = this.getChooseImageOpts
950
+
951
+ this.currentSourceType = sourceType
952
+
953
+ if (this.customTakePhoto) {
954
+ this.showCustomTakePhoto = true
955
+ return
956
+ }
957
+
958
+ this.handleUniChooseImage(sizeType, sourceType, crop)
959
+ },
960
+ async handleUniChooseImage(sizeType, sourceType, crop) {
889
961
  try {
890
962
  const [cancel, result] = await uni.chooseImage({
891
963
  count: this.getUploadMaxCount,
@@ -930,6 +1002,14 @@ export default {
930
1002
  },
931
1003
  async handleChooseVideo() {
932
1004
  const { sourceType, maxDuration, camera } = this.getChooseVideoOpts
1005
+
1006
+ this.currentSourceType = sourceType
1007
+
1008
+ if (this.customTakePhoto) {
1009
+ this.showCustomTakePhoto = true
1010
+ return
1011
+ }
1012
+
933
1013
  try {
934
1014
  const [cancel, result] = await uni.chooseVideo({
935
1015
  sourceType,
@@ -957,6 +1037,14 @@ export default {
957
1037
  async handleChooseMedia() {
958
1038
  const { sourceType, maxDuration, camera } =
959
1039
  this.type === 'video' ? this.getChooseVideoOpts : this.getChooseFileOpts
1040
+
1041
+ this.currentSourceType = sourceType
1042
+
1043
+ if (this.customTakePhoto) {
1044
+ this.showCustomTakePhoto = true
1045
+ return
1046
+ }
1047
+
960
1048
  try {
961
1049
  const [cancel, result] = await uni.chooseMedia({
962
1050
  count: this.getUploadMaxCount,
@@ -1030,6 +1118,25 @@ export default {
1030
1118
  } else {
1031
1119
  this.handleSelectMessageFile()
1032
1120
  }
1121
+ },
1122
+ handleEmitTakePhoto(takeType) {
1123
+ this.$emit('customTakePhoto', {
1124
+ takeType,
1125
+ uploadType: this.type,
1126
+ compressOption: this.compressOption,
1127
+ chooseImageOpts: this.getChooseImageOpts,
1128
+ chooseVideoOpts: this.getChooseVideoOpts,
1129
+ chooseFileOpts: this.getChooseFileOpts
1130
+ })
1131
+ },
1132
+ handleCustomTakePhotoSelect(type) {
1133
+ if (type.id === 'chooseFromAlbum') {
1134
+ // 从手机相册选择
1135
+ const { sizeType, crop } = this.getChooseImageOpts
1136
+ this.handleUniChooseImage(sizeType, ['album'], crop)
1137
+ } else {
1138
+ this.handleEmitTakePhoto(type.id)
1139
+ }
1033
1140
  }
1034
1141
  }
1035
1142
  }
@@ -78,6 +78,7 @@ export default {
78
78
  beforeUpload: null, // 上传之前的钩子
79
79
  onProgress: null, // 文件上传时的钩子
80
80
  beforeRemove: null, // 删除之前的钩子
81
+ customTakePhoto: false, // 是否自定义拍照(如果为true,则不调用相机,通过事件自己实现拍照上传)
81
82
  fileIconMap: {}, // 文件类型和图标映射关系,对象形式({PDF: 'https://xxx'})
82
83
  customUploadParams: {} // 自定义上传参数,对象形式
83
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta145",
3
+ "version": "1.2.7-beta146",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {