sadais-piui 1.2.7-beta98 → 1.2.7-beta99

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.
@@ -88,6 +88,7 @@
88
88
  <view
89
89
  v-if="item[descField]"
90
90
  class="pi-light-gray pi-fz-24 pi-mg-top-10 pi-lh-30"
91
+ :style="[item.descStyle || {}]"
91
92
  >
92
93
  {{ item[descField] }}
93
94
  </view>
@@ -1,10 +1,10 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2022-05-18 11:08:49
4
- * @LastEditTime: 2024-01-29 15:44:16
4
+ * @LastEditTime: 2024-05-09 16:23:43
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 选择输入
7
- * @FilePath: /piui/components/pi-select-input/index.vue
7
+ * @FilePath: /piui-awesome/src/piui/components/pi-select-input/index.vue
8
8
  -->
9
9
 
10
10
  <template>
@@ -61,6 +61,7 @@
61
61
  :items="getSelect.items"
62
62
  :key-field="getSelect.keyField"
63
63
  :display-field="getSelect.displayField"
64
+ :desc-field="getSelect.descField"
64
65
  :is-multi="getSelect.isMulti"
65
66
  :single-cancel="getSelect.singleCancel"
66
67
  :single-confirm="getSelect.singleConfirm"
@@ -1,14 +1,18 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2021-08-13 11:31:57
4
- * @LastEditTime: 2022-11-19 09:44:33
4
+ * @LastEditTime: 2024-05-09 15:30:31
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 图片上传组件
7
- * @FilePath: /dt-weitibao-console/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-upload-img/index.vue
7
+ * @FilePath: /piui-awesome/src/piui/components/pi-upload-img/index.vue
8
8
  -->
9
9
 
10
10
  <template>
11
- <view class="pi-upload-img pi-pd-top-12" :style="[customStyle]" :class="[customClass]">
11
+ <view
12
+ class="pi-upload-img pi-pd-top-12"
13
+ :style="[customStyle]"
14
+ :class="[customClass]"
15
+ >
12
16
  <!-- 已上传图片展示 -->
13
17
  <view
14
18
  v-for="(img, index) in getImgs"
@@ -20,15 +24,36 @@
20
24
  <pi-icon name="roundclosefill" color="#8e8e8e" size="36" />
21
25
  </view>
22
26
  <image
27
+ v-if="type === 'image'"
23
28
  :style="[getItemStyle]"
24
29
  class="pi-of-hidden"
25
30
  :mode="imageMode"
26
31
  :src="imgField ? img[imgField] : img"
27
32
  />
33
+ <view
34
+ v-else
35
+ class="pi-rela pi-of-hidden pi-radius-8"
36
+ :style="[getItemStyle]"
37
+ >
38
+ <view class="file-mask">
39
+ <pi-icon
40
+ :name="type === 'video' ? 'videofill' : 'activity-fill'"
41
+ size="48"
42
+ color="#0C6DF4"
43
+ />
44
+ <view class="pi-mg-top-12 pi-fz-22">
45
+ {{ getFileType(imgField ? img[imgField] : img) }}
46
+ </view>
47
+ </view>
48
+ </view>
28
49
  </view>
29
50
  <!-- 上传框 -->
30
51
  <view v-if="getUploadMaxCount && !disabled">
31
- <view :style="[getUploadBtnStyle]" class="pi-flex-column-center" @tap="handleChooseImage">
52
+ <view
53
+ :style="[getUploadBtnStyle]"
54
+ class="pi-flex-column-center"
55
+ @tap="handleChoose"
56
+ >
32
57
  <slot name="uploadBtn">
33
58
  <!-- 添加按钮 -->
34
59
  <pi-icon
@@ -43,11 +68,17 @@
43
68
  :class-prefix="getUploadIcon.classPrefix"
44
69
  />
45
70
  </slot>
46
- <view v-if="uploadText" class="pi-mg-top-6 pi-fz-24 pi-light-gray">{{ uploadText }}</view>
71
+ <view v-if="uploadText" class="pi-mg-top-6 pi-fz-24 pi-light-gray">{{
72
+ uploadText
73
+ }}</view>
47
74
  </view>
48
75
  </view>
49
76
  <!-- 剪裁弹窗 -->
50
- <pi-mask v-model="showCrop" :mask-closeable="false" background="rgba(0, 0, 0, .9)">
77
+ <pi-mask
78
+ v-model="showCrop"
79
+ :mask-closeable="false"
80
+ background="rgba(0, 0, 0, .9)"
81
+ >
51
82
  <view class="pi-abso-full pi-flex-column">
52
83
  <view class="pi-flex-sub">
53
84
  <pi-img-cropper
@@ -71,7 +102,9 @@
71
102
  :background="getCropMaskBackground"
72
103
  :safe-area-bg-color="getCropMaskBackground"
73
104
  >
74
- <view class="pi-justify-between pi-align-center pi-pd-tb-32 pi-pd-lr-24 pi-fz-32">
105
+ <view
106
+ class="pi-justify-between pi-align-center pi-pd-tb-32 pi-pd-lr-24 pi-fz-32"
107
+ >
75
108
  <view class="pi-white" @tap="handleCancelCrop">取消</view>
76
109
  <view class="pi-primary" @tap="handleCompelteCrop">完成</view>
77
110
  </view>
@@ -298,6 +331,10 @@ export default {
298
331
  default() {
299
332
  return uploadImg.compressOption
300
333
  }
334
+ },
335
+ type: {
336
+ type: String,
337
+ default: 'image' // 'all', 'image', 'video'
301
338
  }
302
339
  },
303
340
  data() {
@@ -315,14 +352,21 @@ export default {
315
352
  if (this.val === null || this.val === undefined) {
316
353
  return []
317
354
  }
318
- return this.isValString ? (this.val ? [this.val] : []) : this.val.filter(img => img)
355
+ return this.isValString
356
+ ? this.val
357
+ ? [this.val]
358
+ : []
359
+ : this.val.filter(img => img)
319
360
  },
320
361
  getItemStyle() {
321
362
  const style = {
322
363
  width: this.getSize,
323
364
  height: this.getSize
324
365
  }
325
- const uploadStyle = this.$pi.lang.mergeDeep(uploadImg.itemStyle, this.itemStyle)
366
+ const uploadStyle = this.$pi.lang.mergeDeep(
367
+ uploadImg.itemStyle,
368
+ this.itemStyle
369
+ )
326
370
  return this.$pi.lang.mergeDeep(style, uploadStyle)
327
371
  },
328
372
  getSize() {
@@ -333,7 +377,10 @@ export default {
333
377
  width: this.getSize,
334
378
  height: this.getSize
335
379
  }
336
- const uploadBtnStyle = this.$pi.lang.mergeDeep(uploadImg.uploadBtnStyle, this.uploadBtnStyle)
380
+ const uploadBtnStyle = this.$pi.lang.mergeDeep(
381
+ uploadImg.uploadBtnStyle,
382
+ this.uploadBtnStyle
383
+ )
337
384
  return this.$pi.lang.mergeDeep(style, uploadBtnStyle)
338
385
  },
339
386
  getUploadIcon() {
@@ -341,9 +388,13 @@ export default {
341
388
  },
342
389
  getChooseImageOpts() {
343
390
  // 以覆盖的方式合并数组
344
- return this.$pi.lang.mergeDeep(uploadImg.chooseImageOpts, this.chooseImageOpts, {
345
- arrayMerge: (target, source) => source
346
- })
391
+ return this.$pi.lang.mergeDeep(
392
+ uploadImg.chooseImageOpts,
393
+ this.chooseImageOpts,
394
+ {
395
+ arrayMerge: (target, source) => source
396
+ }
397
+ )
347
398
  },
348
399
  getUploadMaxCount() {
349
400
  const maxCount = parseInt(this.maxCount, 10)
@@ -357,6 +408,24 @@ export default {
357
408
  }
358
409
  },
359
410
  methods: {
411
+ getFileType(file) {
412
+ if (!file) return ''
413
+ const ext = file.split('.').pop()
414
+ return ext.toLocaleUpperCase()
415
+ },
416
+ isRightType(selectFile) {
417
+ const { extension } = this.getChooseImageOpts
418
+ let isRightType = false
419
+ extension.forEach(ext => {
420
+ if (selectFile.name.endsWith(ext)) {
421
+ isRightType = true
422
+ }
423
+ })
424
+ if (!isRightType) {
425
+ this.$toast(`请选择${extension}文件上传`)
426
+ }
427
+ return isRightType
428
+ },
360
429
  async handleDelete(index) {
361
430
  let val = null
362
431
  const beforeRemove = this.beforeRemove[PI_DEFAULT_FN_FLAG]
@@ -374,44 +443,71 @@ export default {
374
443
  },
375
444
  // 预览图片
376
445
  handlePreviewImage(img) {
377
- if (!this.previewFullImage) return
378
- let urls = []
379
- let current = ''
446
+ console.log(TAG, '文件预览', img)
447
+ if (this.type === 'image') {
448
+ if (!this.previewFullImage) return
449
+ let urls = []
450
+ let current = ''
451
+
452
+ if (this.isValString) {
453
+ current = this.val
454
+ urls = [this.val]
455
+ } else {
456
+ urls = this.imgField
457
+ ? this.val.map(img => img[this.imgField])
458
+ : this.val
459
+ current = this.imgField ? img[this.imgField] : img
460
+ }
380
461
 
381
- if (this.isValString) {
382
- current = this.val
383
- urls = [this.val]
462
+ // eslint-disable-next-line no-undef
463
+ uni.previewImage({
464
+ urls,
465
+ current,
466
+ indicator: 'default',
467
+ success: () => {
468
+ this.$emit('preview', current, urls)
469
+ }
470
+ })
471
+ } else if (this.type === 'video') {
472
+ // 视频文件自行处理
473
+ this.$emit('previewVideo', img)
384
474
  } else {
385
- urls = this.imgField ? this.val.map(img => img[this.imgField]) : this.val
386
- current = this.imgField ? img[this.imgField] : img
475
+ // 文件预览
476
+ uni.downloadFile({
477
+ url: img,
478
+ success: res => {
479
+ const filePath = res.tempFilePath
480
+ // fileType 文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx,支付宝小程序仅支持pdf
481
+ // 支付宝小程序必填,其他平台非必填
482
+ uni.openDocument({
483
+ filePath,
484
+ complete: res => {
485
+ console.log('文件预览', res)
486
+ }
487
+ })
488
+ }
489
+ })
387
490
  }
388
-
389
- // eslint-disable-next-line no-undef
390
- uni.previewImage({
391
- urls,
392
- current,
393
- indicator: 'default',
394
- success: () => {
395
- this.$emit('preview', current, urls)
396
- }
397
- })
398
491
  },
399
492
  async handleUpload(paths) {
400
493
  const beforeUpload = this.beforeUpload[PI_DEFAULT_FN_FLAG]
401
494
  ? this.beforeUpload.fn
402
495
  : this.beforeUpload
403
- const onProgress = this.onProgress[PI_DEFAULT_FN_FLAG] ? this.onProgress.fn : this.onProgress
496
+ const onProgress = this.onProgress[PI_DEFAULT_FN_FLAG]
497
+ ? this.onProgress.fn
498
+ : this.onProgress
404
499
  const parseResultFn = this.parseResultFn[PI_DEFAULT_FN_FLAG]
405
500
  ? this.parseResultFn.fn
406
501
  : this.parseResultFn
407
502
  try {
408
503
  for await (const filePath of paths) {
409
504
  // ---------- 上传之前的钩子 ----------
505
+ const file = filePath
410
506
 
411
507
  let beforeUploadResult = true
412
508
  if (this.$pi.lang.isFunction(beforeUpload)) {
413
509
  console.log(TAG, '调用文件上传前钩子')
414
- beforeUploadResult = await beforeUpload(filePath)
510
+ beforeUploadResult = await beforeUpload(file)
415
511
  }
416
512
  if (!beforeUploadResult) {
417
513
  console.log(TAG, '文件上传前钩子返回false,跳过上传')
@@ -423,7 +519,7 @@ export default {
423
519
  let uploadResult = null
424
520
  const params = {
425
521
  url: this.action,
426
- filePath: filePath,
522
+ filePath: file,
427
523
  name: this.name,
428
524
  formData: this.formData,
429
525
  header: this.headers
@@ -477,7 +573,11 @@ export default {
477
573
  ...this.compressOption
478
574
  })
479
575
  const { errMsg, tempFilePath } = result
480
- if (errMsg == 'compressImage:ok' && tempFilePath && typeof tempFilePath == 'string') {
576
+ if (
577
+ errMsg == 'compressImage:ok' &&
578
+ tempFilePath &&
579
+ typeof tempFilePath == 'string'
580
+ ) {
481
581
  compressUrls.push(tempFilePath)
482
582
  console.log(TAG, '压缩图片成功', tempFilePath, 'src=' + url)
483
583
  } else {
@@ -487,10 +587,88 @@ export default {
487
587
  }
488
588
  return compressUrls
489
589
  },
590
+ handleChoose() {
591
+ if (this.type === 'image') {
592
+ this.handleChooseImage()
593
+ return
594
+ }
595
+ // #ifndef MP-WEIXIN
596
+ this.handleChooseFile()
597
+ // #endif
598
+ // #ifdef MP-WEIXIN
599
+ this.handleSelectMessageFile()
600
+ // #endif
601
+ },
602
+ async handleChooseFile() {
603
+ if (this.disabled || !this.getUploadMaxCount) return
604
+ // 检查上传地址
605
+ const onProgress = this.onProgress[PI_DEFAULT_FN_FLAG]
606
+ ? this.onProgress.fn
607
+ : this.onProgress
608
+ if (!onProgress && !this.action) {
609
+ this.$toast('请配置上传地址')
610
+ return
611
+ }
612
+ if (this.$pi.lang.isEmpty(this.headers)) {
613
+ console.log(TAG, '当前图片上传headers为空,请检查是否需要配置授权信息')
614
+ }
615
+ const { sizeType, extension, sourceType, crop } = this.getChooseImageOpts
616
+ try {
617
+ const [, result] = await uni.chooseFile({
618
+ count: this.getUploadMaxCount,
619
+ sizeType,
620
+ extension,
621
+ sourceType,
622
+ crop
623
+ })
624
+ let { errMsg, tempFiles } = result
625
+ console.log(TAG, '选择文件', result)
626
+ if (errMsg !== 'chooseFile:ok') {
627
+ throw new Error(errMsg)
628
+ }
629
+ this.handleUpload(tempFiles)
630
+ } catch (error) {
631
+ console.log(TAG, '上传文件失败', error)
632
+ this.$emit('fail', error)
633
+ }
634
+ },
635
+ // 从微信聊天会话中选择文件
636
+ async handleSelectMessageFile() {
637
+ // #ifndef MP-WEIXIN
638
+ this.$toast('请在微信小程序中使用')
639
+ // #endif
640
+
641
+ // #ifdef MP-WEIXIN
642
+ this.showSheet = false
643
+ try {
644
+ const [, result] = await uni.chooseMessageFile({
645
+ count: 1,
646
+ type: 'file'
647
+ })
648
+ if (!result) {
649
+ return
650
+ }
651
+ let { errMsg, tempFiles } = result
652
+ console.log(TAG, '选择微信聊天记录文件', result)
653
+ if (errMsg !== 'chooseMessageFile:ok') {
654
+ throw new Error(errMsg)
655
+ }
656
+ const selectFile = tempFiles[0]
657
+ if (!this.isRightType(selectFile)) {
658
+ return
659
+ }
660
+ this.handleUpload(tempFiles)
661
+ } catch (error) {
662
+ console.log(error)
663
+ }
664
+ // #endif
665
+ },
490
666
  async handleChooseImage() {
491
667
  if (this.disabled || !this.getUploadMaxCount) return
492
668
  // 检查上传地址
493
- const onProgress = this.onProgress[PI_DEFAULT_FN_FLAG] ? this.onProgress.fn : this.onProgress
669
+ const onProgress = this.onProgress[PI_DEFAULT_FN_FLAG]
670
+ ? this.onProgress.fn
671
+ : this.onProgress
494
672
  if (!onProgress && !this.action) {
495
673
  this.$toast('请配置上传地址')
496
674
  return
@@ -513,11 +691,18 @@ export default {
513
691
  }
514
692
  // #ifndef H5
515
693
  // 压缩图片
516
- if (this.compressOption && this.$pi.system.systemInfo.platform !== 'devtools') {
694
+ if (
695
+ this.compressOption &&
696
+ this.$pi.system.systemInfo.platform !== 'devtools'
697
+ ) {
517
698
  tempFilePaths = await this.handleCompressImgs(tempFilePaths)
518
699
  }
519
700
  // #endif
520
- if (this.getUploadMaxCount === 1 && this.crop && tempFilePaths.length === 1) {
701
+ if (
702
+ this.getUploadMaxCount === 1 &&
703
+ this.crop &&
704
+ tempFilePaths.length === 1
705
+ ) {
521
706
  // 单张图片设置了剪裁
522
707
  this.showCrop = true
523
708
  this.cropPic = tempFilePaths[0]
@@ -557,5 +742,17 @@ export default {
557
742
  margin-right: 24rpx;
558
743
  margin-bottom: 24rpx;
559
744
  }
745
+ .file-mask {
746
+ position: absolute;
747
+ top: 0;
748
+ left: 0;
749
+ width: 100%;
750
+ height: 100%;
751
+ display: flex;
752
+ flex-direction: column;
753
+ align-items: center;
754
+ justify-content: center;
755
+ background: rgba(0, 0, 0, 0.3);
756
+ }
560
757
  }
561
758
  </style>
@@ -1,10 +1,10 @@
1
1
  /*
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2021-08-13 11:29:02
4
- * @LastEditTime: 2022-07-21 11:20:15
4
+ * @LastEditTime: 2024-05-08 17:13:22
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 图片上传
7
- * @FilePath: /dt-weitibao-console/Users/feilin/workspace/piui/piui-awesome/src/piui/config/uploadImg.js
7
+ * @FilePath: /piui-awesome/src/piui/config/uploadImg.js
8
8
  */
9
9
  import icon from './icon.js'
10
10
  import cropOption from './imgCropper.js'
@@ -50,7 +50,10 @@ export default {
50
50
  try {
51
51
  return JSON.parse(result.data)?.data.url
52
52
  } catch (error) {
53
- console.error('解析上传结果失败,请使用自定义解析函数 parseResultFn ', error)
53
+ console.error(
54
+ '解析上传结果失败,请使用自定义解析函数 parseResultFn ',
55
+ error
56
+ )
54
57
  }
55
58
  },
56
59
  beforeUpload: null, // 上传之前的钩子
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta98",
3
+ "version": "1.2.7-beta99",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {