sadais-piui 1.2.7-beta100 → 1.2.7-beta102

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.
@@ -126,7 +126,9 @@ export default {
126
126
  // `''`
127
127
  default: checkboxGroup.activeMode,
128
128
  validator: function(value) {
129
- return ['', 'line', 'line-circle', 'fill', 'fill-circle'].includes(value)
129
+ return ['', 'line', 'line-circle', 'fill', 'fill-circle'].includes(
130
+ value
131
+ )
130
132
  }
131
133
  },
132
134
  // 是否点击图标才能选中,默认点击整行都能选中
@@ -143,6 +145,8 @@ export default {
143
145
  },
144
146
  watch: {
145
147
  val: {
148
+ deep: true,
149
+ immediate: true,
146
150
  handler(value) {
147
151
  this.handleValChange()
148
152
  }
@@ -151,10 +155,12 @@ export default {
151
155
  methods: {
152
156
  handleValChange() {
153
157
  // 同步checkbox子组件
154
- this._children.forEach(child => {
158
+ this._children?.forEach(child => {
155
159
  // 对设置了name属性的checkbox才做同步
156
160
  if (child.name) {
157
- child.val = this.val.includes(child.name)
161
+ setTimeout(() => {
162
+ child.val = this.val.includes(child.name)
163
+ }, 50)
158
164
  }
159
165
  })
160
166
  },
@@ -183,7 +189,8 @@ export default {
183
189
  const vals = []
184
190
  this._children.forEach(child => {
185
191
  console.log(child.val, child.name)
186
- if (child.val && !this.$pi.lang.isEmpty(child.name)) vals.push(child.name)
192
+ if (child.val && !this.$pi.lang.isEmpty(child.name))
193
+ vals.push(child.name)
187
194
  })
188
195
  this.val = vals
189
196
  this.handleEmitChange()
@@ -1,7 +1,7 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2021-08-13 11:31:57
4
- * @LastEditTime: 2024-05-13 19:08:30
4
+ * @LastEditTime: 2024-05-20 12:18:03
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 图片上传组件
7
7
  * @FilePath: /piui-awesome/src/piui/components/pi-upload-img/index.vue
@@ -24,7 +24,7 @@
24
24
  <pi-icon name="roundclosefill" color="#8e8e8e" size="36" />
25
25
  </view>
26
26
  <image
27
- v-if="type === 'image'"
27
+ v-if="isImageFilename(imgField ? img[imgField] : img)"
28
28
  :style="[getItemStyle]"
29
29
  class="pi-of-hidden"
30
30
  :mode="imageMode"
@@ -111,6 +111,15 @@
111
111
  </pi-bottom-bar>
112
112
  </view>
113
113
  </pi-mask>
114
+ <!-- 上传视频操作面板(小程序专用) -->
115
+ <pi-action-sheet
116
+ v-model="showActionSheet"
117
+ :items="actionSheetItems"
118
+ :popup="{
119
+ borderRadius: 0
120
+ }"
121
+ @select="handleActionSheetSelect"
122
+ />
114
123
  </view>
115
124
  </template>
116
125
 
@@ -368,10 +377,23 @@ export default {
368
377
  return {
369
378
  showCrop: false, // 是否显示裁剪工具
370
379
  cropPic: '', // 需要剪裁的图片
371
- cropedPic: '' // 剪裁后的图片
380
+ cropedPic: '', // 剪裁后的图片
381
+ showActionSheet: false // 是否显示上传视频操作面板
372
382
  }
373
383
  },
374
384
  computed: {
385
+ actionSheetItems() {
386
+ return [
387
+ {
388
+ id: 1,
389
+ text: '选择媒体图片/视频'
390
+ },
391
+ {
392
+ id: 2,
393
+ text: '选择微信聊天文件'
394
+ }
395
+ ]
396
+ },
375
397
  isValString() {
376
398
  return this.$pi.lang.isString(this.val)
377
399
  },
@@ -447,6 +469,7 @@ export default {
447
469
  }
448
470
  },
449
471
  methods: {
472
+ isImageFilename,
450
473
  getFileType(file) {
451
474
  if (!file) return ''
452
475
  const ext = file.split('.').pop()
@@ -651,7 +674,7 @@ export default {
651
674
  // #endif
652
675
 
653
676
  // #ifdef MP-WEIXIN
654
- this.handleSelectMessageFile()
677
+ this.showActionSheet = true
655
678
  // #endif
656
679
 
657
680
  return
@@ -673,7 +696,7 @@ export default {
673
696
  }
674
697
  },
675
698
  async handleChooseFile() {
676
- const { sizeType, extension, sourceType, crop } = this.getChooseImageOpts
699
+ const { sizeType, extension, sourceType, crop } = this.getChooseFileOpts
677
700
  try {
678
701
  const [, result] = await uni.chooseFile({
679
702
  count: this.getUploadMaxCount,
@@ -699,6 +722,8 @@ export default {
699
722
  this.$toast('请在微信小程序中使用')
700
723
  // #endif
701
724
 
725
+ console.log('从微信聊天会话中选择文件')
726
+
702
727
  // #ifdef MP-WEIXIN
703
728
  this.showSheet = false
704
729
  try {
@@ -714,10 +739,6 @@ export default {
714
739
  if (errMsg !== 'chooseMessageFile:ok') {
715
740
  throw new Error(errMsg)
716
741
  }
717
- // const selectFile = tempFiles[0]
718
- // if (!this.isRightType(selectFile)) {
719
- // return
720
- // }
721
742
  this.handleUpload(tempFiles)
722
743
  } catch (error) {
723
744
  console.log(error)
@@ -784,10 +805,12 @@ export default {
784
805
  }
785
806
  },
786
807
  async handleChooseMedia() {
787
- const { sourceType, maxDuration, camera } = this.getChooseVideoOpts
808
+ const { sourceType, maxDuration, camera } =
809
+ this.type === 'video' ? this.getChooseVideoOpts : this.getChooseFileOpts
788
810
  try {
789
811
  const [, result] = await uni.chooseMedia({
790
- mediaType: ['video'],
812
+ count: this.getUploadMaxCount,
813
+ mediaType: this.type === 'video' ? ['video'] : ['video', 'image'],
791
814
  sourceType,
792
815
  maxDuration,
793
816
  camera
@@ -796,17 +819,25 @@ export default {
796
819
  if (errMsg !== 'chooseMedia:ok') {
797
820
  throw new Error(errMsg)
798
821
  }
799
- console.log(TAG, '上传视频结果', result)
822
+ console.log(TAG, '上传媒体结果', result)
800
823
 
801
824
  // #ifndef H5
802
825
  // 非H5端/开发者工具,上传视频,执行压缩视频操作
803
826
  if (this.$pi.system.systemInfo.platform !== 'devtools') {
804
827
  const compressTempFiles = []
805
828
  for await (const tempFile of tempFiles) {
806
- const tempFilePath = await this.handleCompressVideo(
807
- tempFile.tempFilePath
808
- )
809
- compressTempFiles.push(tempFilePath)
829
+ const tempFilePath = tempFile.tempFilePath
830
+ let filePath = ''
831
+ if (isImageFilename(tempFilePath)) {
832
+ const filePaths = await this.handleCompressImgs([
833
+ tempFile.tempFilePath
834
+ ])
835
+ filePath = filePaths[0]
836
+ } else {
837
+ filePath = await this.handleCompressVideo(tempFile.tempFilePath)
838
+ }
839
+
840
+ compressTempFiles.push(filePath)
810
841
  }
811
842
  this.handleUpload(compressTempFiles)
812
843
  return
@@ -835,6 +866,13 @@ export default {
835
866
  return tempFilePath
836
867
  }
837
868
  return tempUrl
869
+ },
870
+ handleActionSheetSelect(type) {
871
+ if (type.id === 1) {
872
+ this.handleChooseMedia()
873
+ } else {
874
+ this.handleSelectMessageFile()
875
+ }
838
876
  }
839
877
  }
840
878
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2021-08-13 11:29:02
4
- * @LastEditTime: 2024-05-13 11:36:14
4
+ * @LastEditTime: 2024-05-20 12:11:59
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 图片上传
7
7
  * @FilePath: /piui-awesome/src/piui/config/uploadImg.js
@@ -43,18 +43,20 @@ export default {
43
43
  type: 'image', // 上传文件类型,可选值为image、video、all
44
44
  // 当type为 "all"时生效,调用uni.chooseFile参数
45
45
  chooseFileOpts: {
46
- sourceType: ['album', 'camera'], // (仅在type为image或video时可用)album 从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项
47
- extension: [] // 允许上传的文件类型,不填则不限制
46
+ sourceType: [], // (仅在type为image或video时可用)album 从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项
47
+ extension: [], // 允许上传的文件类型,不填则不限制
48
+ maxDuration: 60, // 拍摄视频最长拍摄时间,单位秒,默认60
49
+ camera: 'back' // 前置或后置摄像头,默认back
48
50
  },
49
51
  // 当type为 "image"时生效,调用uni.chooseImage参数
50
52
  chooseImageOpts: {
51
- sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认album
53
+ sourceType: [], // album 从相册选图,camera 使用相机,默认album
52
54
  sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认compressed
53
55
  crop: {} // 图像裁剪参数,设置后 sizeType 失效
54
56
  },
55
57
  // 当type为 "video"时生效,调用uniapp.chooseVideo参数
56
58
  chooseVideoOpts: {
57
- sourceType: ['album', 'camera'], // album 从相册选视频,camera 使用相机拍摄,默认二者都有
59
+ sourceType: [], // album 从相册选视频,camera 使用相机拍摄,默认二者都有
58
60
  compressed: true, // 是否压缩视频,默认true
59
61
  maxDuration: 60, // 拍摄视频最长拍摄时间,单位秒,默认60
60
62
  camera: 'back', // 前置或后置摄像头,默认back
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta100",
3
+ "version": "1.2.7-beta102",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {