hy-app 0.4.13 → 0.5.0

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.
Files changed (211) hide show
  1. package/components/hy-action-sheet/hy-action-sheet.vue +155 -238
  2. package/components/hy-action-sheet/props.ts +68 -15
  3. package/components/hy-action-sheet/typing.d.ts +115 -115
  4. package/components/hy-address-picker/hy-address-picker.vue +185 -289
  5. package/components/hy-address-picker/props.ts +97 -21
  6. package/components/hy-address-picker/typing.d.ts +90 -89
  7. package/components/hy-avatar/hy-avatar.vue +121 -204
  8. package/components/hy-avatar/props.ts +76 -18
  9. package/components/hy-avatar/typing.d.ts +63 -62
  10. package/components/hy-back-top/hy-back-top.vue +65 -120
  11. package/components/hy-back-top/props.ts +57 -16
  12. package/components/hy-back-top/typing.d.ts +43 -42
  13. package/components/hy-badge/hy-badge.vue +66 -138
  14. package/components/hy-badge/props.ts +73 -17
  15. package/components/hy-badge/typing.d.ts +59 -58
  16. package/components/hy-button/hy-button.vue +226 -375
  17. package/components/hy-button/props.ts +129 -158
  18. package/components/hy-calendar/header.vue +48 -64
  19. package/components/hy-calendar/hy-calendar.vue +274 -438
  20. package/components/hy-calendar/month.vue +508 -516
  21. package/components/hy-calendar/props.ts +157 -35
  22. package/components/hy-calendar/typing.d.ts +129 -128
  23. package/components/hy-card/hy-card.vue +118 -240
  24. package/components/hy-card/index.scss +1 -2
  25. package/components/hy-card/props.ts +122 -27
  26. package/components/hy-card/typing.d.ts +119 -118
  27. package/components/hy-cell/hy-cell.vue +176 -258
  28. package/components/hy-cell/props.ts +71 -17
  29. package/components/hy-cell/typing.d.ts +87 -86
  30. package/components/hy-check-button/hy-check-button.vue +69 -139
  31. package/components/hy-check-button/props.ts +72 -18
  32. package/components/hy-check-button/typing.d.ts +74 -73
  33. package/components/hy-checkbox/hy-checkbox.vue +170 -263
  34. package/components/hy-checkbox/props.ts +94 -24
  35. package/components/hy-checkbox/typing.d.ts +72 -72
  36. package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
  37. package/components/hy-checkbox-group/props.ts +80 -0
  38. package/components/hy-checkbox-group/typing.d.ts +65 -65
  39. package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
  40. package/components/hy-checkbox-item/props.ts +24 -0
  41. package/components/hy-checkbox-item/typing.d.ts +4 -3
  42. package/components/hy-code-input/hy-code-input.vue +179 -262
  43. package/components/hy-code-input/props.ts +84 -18
  44. package/components/hy-code-input/typing.d.ts +71 -71
  45. package/components/hy-config-provider/hy-config-provider.vue +28 -50
  46. package/components/hy-config-provider/props.ts +26 -11
  47. package/components/hy-config-provider/typing.d.ts +20 -20
  48. package/components/hy-count-down/hy-count-down.vue +103 -131
  49. package/components/hy-count-down/props.ts +30 -8
  50. package/components/hy-count-down/typing.d.ts +25 -25
  51. package/components/hy-count-to/hy-count-to.vue +148 -213
  52. package/components/hy-count-to/props.ts +60 -15
  53. package/components/hy-count-to/typing.d.ts +46 -46
  54. package/components/hy-coupon/README.md +133 -0
  55. package/components/hy-coupon/hy-coupon.vue +180 -0
  56. package/components/hy-coupon/index.scss +553 -0
  57. package/components/hy-coupon/props.ts +129 -0
  58. package/components/hy-coupon/typing.d.ts +146 -0
  59. package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
  60. package/components/hy-datetime-picker/props.ts +142 -32
  61. package/components/hy-datetime-picker/typing.d.ts +132 -132
  62. package/components/hy-divider/hy-divider.vue +90 -169
  63. package/components/hy-divider/props.ts +78 -19
  64. package/components/hy-divider/typing.d.ts +60 -60
  65. package/components/hy-dropdown/hy-dropdown.vue +37 -71
  66. package/components/hy-dropdown/props.ts +38 -15
  67. package/components/hy-dropdown/typing.d.ts +44 -44
  68. package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
  69. package/components/hy-dropdown-item/props.ts +19 -8
  70. package/components/hy-empty/hy-empty.vue +75 -129
  71. package/components/hy-empty/props.ts +57 -15
  72. package/components/hy-empty/typing.d.ts +84 -84
  73. package/components/hy-flex/hy-flex.vue +33 -88
  74. package/components/hy-flex/props.ts +58 -0
  75. package/components/hy-flex/typing.d.ts +14 -16
  76. package/components/hy-float-button/hy-float-button.vue +289 -406
  77. package/components/hy-float-button/props.ts +109 -25
  78. package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
  79. package/components/hy-folding-panel/props.ts +40 -15
  80. package/components/hy-folding-panel/typing.d.ts +52 -63
  81. package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
  82. package/components/hy-folding-panel-item/index.scss +87 -0
  83. package/components/hy-folding-panel-item/props.ts +81 -0
  84. package/components/hy-folding-panel-item/typing.d.ts +23 -0
  85. package/components/hy-form/hy-form.vue +172 -212
  86. package/components/hy-form/props.ts +37 -0
  87. package/components/hy-form/typing.d.ts +68 -61
  88. package/components/hy-form-group/typing.d.ts +74 -74
  89. package/components/hy-form-item/hy-form-item.vue +100 -129
  90. package/components/hy-form-item/props.ts +25 -0
  91. package/components/hy-form-item/typing.d.ts +40 -37
  92. package/components/hy-grid/hy-grid.vue +76 -132
  93. package/components/hy-grid/props.ts +58 -16
  94. package/components/hy-grid/typing.d.ts +66 -66
  95. package/components/hy-icon/hy-icon.vue +84 -161
  96. package/components/hy-icon/props.ts +76 -22
  97. package/components/hy-icon/typing.d.ts +83 -82
  98. package/components/hy-image/hy-image.vue +142 -272
  99. package/components/hy-image/props.ts +105 -23
  100. package/components/hy-image/typing.d.ts +84 -87
  101. package/components/hy-input/hy-input.vue +230 -421
  102. package/components/hy-input/props.ts +183 -35
  103. package/components/hy-input/typing.d.ts +169 -169
  104. package/components/hy-line/hy-line.vue +34 -72
  105. package/components/hy-line/props.ts +41 -10
  106. package/components/hy-line/typing.d.ts +29 -29
  107. package/components/hy-line-progress/hy-line-progress.vue +66 -101
  108. package/components/hy-line-progress/props.ts +31 -10
  109. package/components/hy-line-progress/typing.d.ts +29 -29
  110. package/components/hy-list/hy-list.vue +151 -220
  111. package/components/hy-list/props.ts +67 -16
  112. package/components/hy-list/typing.d.ts +52 -52
  113. package/components/hy-loading/hy-loading.vue +63 -119
  114. package/components/hy-loading/props.ts +63 -15
  115. package/components/hy-loading/typing.d.ts +49 -49
  116. package/components/hy-menu/hy-menu.vue +124 -166
  117. package/components/hy-menu/props.ts +42 -10
  118. package/components/hy-menu/typing.d.ts +60 -60
  119. package/components/hy-modal/hy-modal.vue +127 -218
  120. package/components/hy-modal/props.ts +89 -24
  121. package/components/hy-navbar/hy-navbar.vue +104 -177
  122. package/components/hy-navbar/props.ts +76 -22
  123. package/components/hy-navbar/typing.d.ts +81 -81
  124. package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
  125. package/components/hy-notice-bar/props.ts +80 -19
  126. package/components/hy-notice-bar/typing.d.ts +62 -62
  127. package/components/hy-notify/hy-notify.vue +128 -177
  128. package/components/hy-notify/props.ts +49 -12
  129. package/components/hy-notify/typing.d.ts +45 -41
  130. package/components/hy-number-step/hy-number-step.vue +281 -394
  131. package/components/hy-number-step/props.ts +110 -27
  132. package/components/hy-number-step/typing.d.ts +120 -120
  133. package/components/hy-overlay/hy-overlay.vue +39 -66
  134. package/components/hy-overlay/props.ts +31 -8
  135. package/components/hy-pagination/hy-pagination.vue +100 -155
  136. package/components/hy-pagination/props.ts +53 -13
  137. package/components/hy-picker/hy-picker.vue +309 -430
  138. package/components/hy-picker/index.scss +8 -12
  139. package/components/hy-picker/props.ts +110 -26
  140. package/components/hy-popover/hy-popover.vue +190 -252
  141. package/components/hy-popover/props.ts +48 -10
  142. package/components/hy-popup/hy-popup.vue +162 -248
  143. package/components/hy-popup/props.ts +82 -18
  144. package/components/hy-price/hy-price.vue +45 -104
  145. package/components/hy-price/props.ts +52 -12
  146. package/components/hy-price/typing.d.ts +41 -36
  147. package/components/hy-qrcode/hy-qrcode.vue +115 -185
  148. package/components/hy-qrcode/props.ts +68 -18
  149. package/components/hy-qrcode/typing.d.ts +67 -66
  150. package/components/hy-radio/hy-radio.vue +161 -259
  151. package/components/hy-radio/props.ts +95 -25
  152. package/components/hy-radio/typing.d.ts +85 -84
  153. package/components/hy-rate/hy-rate.vue +185 -270
  154. package/components/hy-rate/props.ts +76 -18
  155. package/components/hy-rate/typing.d.ts +61 -60
  156. package/components/hy-read-more/hy-read-more.vue +93 -136
  157. package/components/hy-read-more/props.ts +43 -13
  158. package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
  159. package/components/hy-scroll-list/props.ts +22 -11
  160. package/components/hy-search/hy-search.vue +155 -284
  161. package/components/hy-search/props.ts +130 -25
  162. package/components/hy-signature/hy-signature.vue +491 -635
  163. package/components/hy-signature/props.ts +115 -26
  164. package/components/hy-signature/typing.d.ts +138 -138
  165. package/components/hy-slider/hy-slider.vue +388 -477
  166. package/components/hy-slider/props.ts +75 -19
  167. package/components/hy-steps/hy-steps.vue +212 -279
  168. package/components/hy-steps/props.ts +47 -13
  169. package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
  170. package/components/hy-submit-bar/props.ts +89 -20
  171. package/components/hy-submit-bar/typing.d.ts +86 -85
  172. package/components/hy-subsection/hy-subsection.vue +132 -185
  173. package/components/hy-subsection/props.ts +50 -17
  174. package/components/hy-subsection/typing.d.ts +52 -52
  175. package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
  176. package/components/hy-swipe-action/props.ts +43 -18
  177. package/components/hy-swipe-action/typing.d.ts +46 -46
  178. package/components/hy-swiper/hy-swiper.vue +159 -286
  179. package/components/hy-swiper/props.ts +126 -28
  180. package/components/hy-swiper/typing.d.ts +115 -115
  181. package/components/hy-switch/hy-switch.vue +112 -176
  182. package/components/hy-switch/props.ts +60 -15
  183. package/components/hy-switch/typing.d.ts +63 -63
  184. package/components/hy-tabBar/hy-tabBar.vue +64 -60
  185. package/components/hy-tabs/hy-tabs.vue +277 -380
  186. package/components/hy-tabs/props.ts +75 -18
  187. package/components/hy-tag/hy-tag.vue +111 -204
  188. package/components/hy-tag/props.ts +81 -19
  189. package/components/hy-text/hy-text.vue +200 -322
  190. package/components/hy-text/props.ts +107 -28
  191. package/components/hy-textarea/hy-textarea.vue +147 -256
  192. package/components/hy-textarea/props.ts +112 -25
  193. package/components/hy-textarea/typing.d.ts +42 -42
  194. package/components/hy-toast/hy-toast.vue +135 -143
  195. package/components/hy-tooltip/hy-tooltip.vue +220 -306
  196. package/components/hy-tooltip/props.ts +79 -15
  197. package/components/hy-transition/hy-transition.vue +111 -138
  198. package/components/hy-transition/props.ts +30 -8
  199. package/components/hy-upload/hy-upload.vue +320 -469
  200. package/components/hy-upload/props.ts +130 -27
  201. package/components/hy-warn/hy-warn.vue +80 -129
  202. package/components/hy-warn/props.ts +47 -12
  203. package/components/hy-waterfall/hy-waterfall.vue +139 -163
  204. package/components/hy-waterfall/props.ts +19 -7
  205. package/components/hy-watermark/hy-watermark.vue +762 -870
  206. package/components/hy-watermark/props.ts +103 -22
  207. package/global.d.ts +2 -0
  208. package/libs/css/theme.scss +3 -3
  209. package/package.json +2 -2
  210. package/web-types.json +1 -1
  211. package/components/hy-folding-panel/index.scss +0 -9
@@ -1,534 +1,385 @@
1
1
  <template>
2
- <view class="hy-upload" :style="[customStyle]">
3
- <view class="hy-upload__wrap">
4
- <template v-if="previewImage">
5
- <view
6
- class="hy-upload__wrap--preview"
7
- v-for="(item, index) in lists"
8
- :key="index"
9
- >
10
- <image
11
- v-if="item.isImage || (item.type && item.type === 'image')"
12
- :src="item.thumb || item.url"
13
- :mode="imageMode"
14
- class="hy-upload__wrap--preview__image"
15
- @tap="onPreviewImage(item, index)"
16
- :style="[
17
- {
18
- width: addUnit(width),
19
- height: addUnit(height),
20
- },
21
- ]"
22
- />
23
- <view
24
- v-else
25
- class="hy-upload__wrap--preview__other"
26
- @tap="onClickPreview(item, index)"
27
- >
28
- <HyIcon
29
- color="#80CBF9"
30
- size="26"
31
- :name="
32
- item.isVideo || (item.type && item.type === 'video')
33
- ? 'movie'
34
- : 'folder'
35
- "
36
- ></HyIcon>
37
- <text class="hy-upload__wrap--preview__other--text">
38
- {{
39
- item.isVideo || (item.type && item.type === "video")
40
- ? "视频"
41
- : "文件"
42
- }}
43
- </text>
44
- </view>
2
+ <view class="hy-upload" :style="[customStyle]">
3
+ <view class="hy-upload__wrap">
4
+ <template v-if="previewImage">
5
+ <view class="hy-upload__wrap--preview" v-for="(item, index) in lists" :key="index">
6
+ <image
7
+ v-if="item.isImage || (item.type && item.type === 'image')"
8
+ :src="item.thumb || item.url"
9
+ :mode="imageMode"
10
+ class="hy-upload__wrap--preview__image"
11
+ @tap="onPreviewImage(item, index)"
12
+ :style="[
13
+ {
14
+ width: addUnit(width),
15
+ height: addUnit(height)
16
+ }
17
+ ]"
18
+ />
19
+ <view
20
+ v-else
21
+ class="hy-upload__wrap--preview__other"
22
+ @tap="onClickPreview(item, index)"
23
+ >
24
+ <HyIcon
25
+ color="#80CBF9"
26
+ size="26"
27
+ :name="
28
+ item.isVideo || (item.type && item.type === 'video')
29
+ ? 'movie'
30
+ : 'folder'
31
+ "
32
+ ></HyIcon>
33
+ <text class="hy-upload__wrap--preview__other--text">
34
+ {{
35
+ item.isVideo || (item.type && item.type === 'video')
36
+ ? '视频'
37
+ : '文件'
38
+ }}
39
+ </text>
40
+ </view>
45
41
 
46
- <!-- 上传进度条 -->
47
- <view
48
- class="hy-upload__wrap--preview__progress"
49
- v-if="item.status === 'loading'"
50
- >
51
- <progress
52
- class="hy-upload__wrap--preview__progress--number"
53
- :percent="item.schedule"
54
- stroke-width="4"
55
- activeColor="#B99C65"
56
- />
57
- <view class="hy-upload__wrap--preview__progress--value"
58
- >上传进度{{ item.schedule }}%</view
59
- >
60
- </view>
61
- <!-- 上传进度条 -->
42
+ <!-- 上传进度条 -->
43
+ <view
44
+ class="hy-upload__wrap--preview__progress"
45
+ v-if="item.status === 'loading'"
46
+ >
47
+ <progress
48
+ class="hy-upload__wrap--preview__progress--number"
49
+ :percent="item.schedule"
50
+ stroke-width="4"
51
+ activeColor="#B99C65"
52
+ />
53
+ <view class="hy-upload__wrap--preview__progress--value"
54
+ >上传进度{{ item.schedule }}%</view
55
+ >
56
+ </view>
57
+ <!-- 上传进度条 -->
62
58
 
63
- <!-- 删除图片图标 -->
64
- <view
65
- class="hy-upload__deletable"
66
- v-if="item.status !== 'loading' && (deletable || item.deletable)"
67
- @tap.stop="deleteItem(index)"
68
- >
69
- <view class="hy-upload__deletable--icon">
70
- <HyIcon
71
- :name="IconConfig.CLOSE"
72
- color="#ffffff"
73
- size="14"
74
- ></HyIcon>
75
- </view>
76
- </view>
77
- <!-- 删除图片图标 -->
59
+ <!-- 删除图片图标 -->
60
+ <view
61
+ class="hy-upload__deletable"
62
+ v-if="item.status !== 'loading' && (deletable || item.deletable)"
63
+ @tap.stop="deleteItem(index)"
64
+ >
65
+ <view class="hy-upload__deletable--icon">
66
+ <HyIcon :name="IconConfig.CLOSE" color="#ffffff" size="14"></HyIcon>
67
+ </view>
68
+ </view>
69
+ <!-- 删除图片图标 -->
78
70
 
79
- <!-- 上传成功图标 -->
80
- <view class="hy-upload__success" v-if="item.status === 'success'">
81
- <!-- #ifndef APP-NVUE -->
82
- <view class="hy-upload__success--icon">
83
- <HyIcon
84
- :name="IconConfig.CHECK_MASK"
85
- color="#ffffff"
86
- size="12"
87
- ></HyIcon>
88
- </view>
89
- <!-- #endif -->
90
- </view>
91
- <!-- 上传成功图标 -->
92
- </view>
93
- </template>
71
+ <!-- 上传成功图标 -->
72
+ <view class="hy-upload__success" v-if="item.status === 'success'">
73
+ <!-- #ifndef APP-NVUE -->
74
+ <view class="hy-upload__success--icon">
75
+ <HyIcon
76
+ :name="IconConfig.CHECK_MASK"
77
+ color="#ffffff"
78
+ size="12"
79
+ ></HyIcon>
80
+ </view>
81
+ <!-- #endif -->
82
+ </view>
83
+ <!-- 上传成功图标 -->
84
+ </view>
85
+ </template>
94
86
 
95
- <template v-if="isInCount">
96
- <view v-if="$slots.trigger" @tap="chooseFileFn">
97
- <slot name="trigger" />
98
- </view>
99
- <view
100
- v-else-if="!$slots.trigger && ($slots.default || $slots.$default)"
101
- @tap="chooseFileFn"
102
- >
103
- <slot />
104
- </view>
105
- <view
106
- v-else
107
- class="hy-upload__button"
108
- :hover-class="!disabled ? 'hy-upload__button--hover' : ''"
109
- hover-stay-time="150"
110
- @tap="chooseFileFn"
111
- :class="[disabled && 'hy-upload__button--disabled']"
112
- :style="[
113
- {
114
- width: addUnit(width),
115
- height: addUnit(height),
116
- },
117
- ]"
118
- >
119
- <HyIcon
120
- :name="uploadIcon"
121
- size="26"
122
- :color="uploadIconColor"
123
- ></HyIcon>
124
- <text v-if="uploadText" class="hy-upload__button--text">{{
125
- uploadText
126
- }}</text>
87
+ <template v-if="isInCount">
88
+ <view v-if="$slots.trigger" @tap="chooseFileFn">
89
+ <slot name="trigger" />
90
+ </view>
91
+ <view
92
+ v-else-if="!$slots.trigger && ($slots.default || $slots.$default)"
93
+ @tap="chooseFileFn"
94
+ >
95
+ <slot />
96
+ </view>
97
+ <view
98
+ v-else
99
+ class="hy-upload__button"
100
+ :hover-class="!disabled ? 'hy-upload__button--hover' : ''"
101
+ hover-stay-time="150"
102
+ @tap="chooseFileFn"
103
+ :class="[disabled && 'hy-upload__button--disabled']"
104
+ :style="[
105
+ {
106
+ width: addUnit(width),
107
+ height: addUnit(height)
108
+ }
109
+ ]"
110
+ >
111
+ <HyIcon :name="uploadIcon" size="26" :color="uploadIconColor"></HyIcon>
112
+ <text v-if="uploadText" class="hy-upload__button--text">{{ uploadText }}</text>
113
+ </view>
114
+ </template>
127
115
  </view>
128
- </template>
129
116
  </view>
130
- </view>
131
117
  </template>
132
118
 
133
119
  <script lang="ts">
134
120
  export default {
135
- name: "hy-upload",
136
- options: {
137
- addGlobalClass: true,
138
- virtualHost: true,
139
- styleIsolation: "shared",
140
- },
141
- };
121
+ name: 'hy-upload',
122
+ options: {
123
+ addGlobalClass: true,
124
+ virtualHost: true,
125
+ styleIsolation: 'shared'
126
+ }
127
+ }
142
128
  </script>
143
129
 
144
130
  <script setup lang="ts">
145
- import { ref, watch } from "vue";
146
- import type { PropType, CSSProperties } from "vue";
147
- import type { FileVo, IUploadEmits, ReadFunctionVo } from "./typing";
148
- import {
149
- addUnit,
150
- bytesToSize,
151
- chooseFile,
152
- isArray,
153
- IconConfig,
154
- } from "../../libs";
131
+ import { ref, watch } from 'vue'
132
+ import type { FileVo, IUploadEmits } from './typing'
133
+ import { addUnit, chooseFile, isArray, IconConfig } from '../../libs'
134
+ import uploadProps from './props'
155
135
  // 组件
156
- import HyIcon from "../hy-icon/hy-icon.vue";
136
+ import HyIcon from '../hy-icon/hy-icon.vue'
157
137
 
158
138
  /**
159
139
  * 该组件用于上传图片或者视频等场景
160
140
  * @displayName hy-upload
161
141
  */
162
- defineOptions({});
142
+ defineOptions({})
163
143
 
164
- // const props = withDefaults(defineProps<IProps>(), defaultProps)
165
- const props = defineProps({
166
- /**
167
- * 接受的文件类型
168
- * @values all,media,image,file,video
169
- * */
170
- accept: {
171
- type: String,
172
- default: "image",
173
- },
174
- /** 根据文件拓展名过滤,每一项都不能是空字符串。默认不过滤。 */
175
- extension: {
176
- type: Array as PropType<string[]>,
177
- default: () => [],
178
- },
179
- /** 图片或视频拾取模式,当accept为image类型时设置capture可选额外camera可以直接调起摄像头 */
180
- capture: {
181
- type: Array as PropType<("album" | "camera")[]>,
182
- default: () => ["album", "camera"],
183
- },
184
- /** 当accept为video时生效,是否压缩视频 */
185
- compressed: {
186
- type: Boolean,
187
- default: true,
188
- },
189
- /** 当accept为video时生效,可选值为back或front */
190
- camera: {
191
- type: String,
192
- default: "back",
193
- },
194
- /** 当accept为video时生效,拍摄视频最长拍摄时间,单位秒 */
195
- maxDuration: {
196
- type: Number,
197
- default: 60,
198
- },
199
- /** 上传区域的图标,只能内置图标 */
200
- uploadIcon: {
201
- type: String,
202
- default: IconConfig.UPLOAD,
203
- },
204
- /** 上传区域的图标的字体颜色,只能内置图标 */
205
- uploadIconColor: {
206
- type: String,
207
- default: "#D3D4D6",
208
- },
209
- /** 是否开启文件读取前事件 */
210
- useBeforeRead: {
211
- type: Boolean,
212
- default: false,
213
- },
214
- /** 是否显示组件自带的图片预览功能 */
215
- previewFullImage: {
216
- type: Boolean,
217
- default: true,
218
- },
219
- /** 最大上传数量 */
220
- maxCount: {
221
- type: Number,
222
- default: 52,
223
- },
224
- /** 是否启用 */
225
- disabled: {
226
- type: Boolean,
227
- default: false,
228
- },
229
- /**
230
- * 预览上传的图片时的裁剪模式,和image组件mode属性一致
231
- * @values scaleToFill,aspectFit,aspectFill,widthFix,heightFix,top,bottom,center,left,right,top left,top right,bottom left,bottom right
232
- * */
233
- imageMode: {
234
- type: String,
235
- default: "aspectFill",
236
- },
237
- /** 标识符,可以在回调函数的第二项参数中获取 */
238
- name: {
239
- type: String,
240
- default: "",
241
- },
242
- /** 所选的图片的尺寸 */
243
- sizeType: {
244
- type: Array as PropType<("original" | "compressed")[]>,
245
- default: ["original", "compressed"],
246
- },
247
- /** 是否开启图片多选,部分安卓机型不支持 */
248
- multiple: {
249
- type: Boolean,
250
- default: false,
251
- },
252
- /** 是否展示删除按钮 */
253
- deletable: {
254
- type: Boolean,
255
- default: true,
256
- },
257
- /** 文件大小限制,单位为byte */
258
- maxSize: {
259
- type: Number,
260
- default: Number.MAX_VALUE,
261
- },
262
- /** 显示已上传的文件列表 */
263
- fileList: {
264
- type: Array as PropType<FileVo[]>,
265
- default: () => [],
266
- },
267
- /** 上传区域的提示文字 */
268
- uploadText: {
269
- type: String,
270
- default: "",
271
- },
272
- /** 内部预览图片区域和选择图片按钮的区域宽度 */
273
- width: {
274
- type: [String, Number],
275
- default: 80,
276
- },
277
- /** 内部预览图片区域和选择图片按钮的区域高度 */
278
- height: {
279
- type: [String, Number],
280
- default: 80,
281
- },
282
- /** 读取前的处理函数 */
283
- beforeRead: Function as PropType<ReadFunctionVo>,
284
- /** 读取后的处理函数 */
285
- afterRead: Function as PropType<ReadFunctionVo>,
286
- /** 定义需要用到的外部样式 */
287
- customStyle: {
288
- type: Object as PropType<CSSProperties>,
289
- },
290
- });
291
- const emit = defineEmits<IUploadEmits>();
144
+ const props = defineProps(uploadProps)
145
+ const emit = defineEmits<IUploadEmits>()
292
146
 
293
- const lists = ref<FileVo[]>([]);
147
+ const lists = ref<FileVo[]>([])
294
148
  // 上传按钮
295
- const isInCount = ref<boolean>(true);
149
+ const isInCount = ref<boolean>(true)
296
150
  // 遮罩框
297
- const previewImage = ref<boolean>(true);
151
+ const previewImage = ref<boolean>(true)
298
152
 
299
153
  const formatFileList = () => {
300
- lists.value = props.fileList.map((item: FileVo) =>
301
- Object.assign(Object.assign({}, item), {
302
- // 如果item.url为本地选择的blob文件的话,无法判断其为video还是image,此处优先通过accept做判断处理
303
- isImage: props.accept === "image",
304
- isVideo: props.accept === "video",
305
- deletable: item.deletable || props.deletable,
306
- }),
307
- );
308
- isInCount.value = lists.value.length < props.maxCount;
309
- };
154
+ lists.value = props.fileList.map((item: FileVo) =>
155
+ Object.assign(Object.assign({}, item), {
156
+ // 如果item.url为本地选择的blob文件的话,无法判断其为video还是image,此处优先通过accept做判断处理
157
+ isImage: props.accept === 'image',
158
+ isVideo: props.accept === 'video',
159
+ deletable: item.deletable || props.deletable
160
+ })
161
+ )
162
+ isInCount.value = lists.value.length < props.maxCount
163
+ }
310
164
 
311
165
  watch(
312
- () => props.fileList,
313
- () => {
314
- formatFileList();
315
- },
316
- { immediate: true, deep: true },
317
- );
166
+ () => props.fileList,
167
+ () => {
168
+ formatFileList()
169
+ },
170
+ { immediate: true, deep: true }
171
+ )
318
172
 
319
173
  watch(
320
- () => props.deletable,
321
- () => {
322
- formatFileList();
323
- },
324
- );
174
+ () => props.deletable,
175
+ () => {
176
+ formatFileList()
177
+ }
178
+ )
325
179
 
326
180
  watch(
327
- () => props.maxCount,
328
- () => {
329
- formatFileList();
330
- },
331
- );
181
+ () => props.maxCount,
182
+ () => {
183
+ formatFileList()
184
+ }
185
+ )
332
186
 
333
187
  watch(
334
- () => props.accept,
335
- () => {
336
- formatFileList();
337
- },
338
- );
188
+ () => props.accept,
189
+ () => {
190
+ formatFileList()
191
+ }
192
+ )
339
193
 
340
194
  const chooseFileFn = () => {
341
- if (props.disabled) return;
342
- // 如果用户传入的是字符串,需要格式化成数组
343
- chooseFile(
344
- Object.assign(
345
- {
346
- accept: props.accept,
347
- extension: props.extension,
348
- multiple: props.multiple,
349
- capture: props.capture,
350
- compressed: props.compressed,
351
- maxDuration: props.maxDuration,
352
- sizeType: props.sizeType,
353
- camera: props.camera,
354
- },
355
- {
356
- maxCount: props.maxCount - lists.value.length,
357
- },
358
- ),
359
- )
360
- .then((res: any) => {
361
- onBeforeRead(props.multiple ? res : res[0]);
362
- })
363
- .catch((error) => {
364
- emit("error", error);
365
- });
366
- };
367
- // 文件读取之前
368
- const onBeforeRead = (file: FileVo) => {
369
- let res: any = true;
370
- // beforeRead是否为一个方法
371
- if (typeof props.beforeRead === "function") {
372
- // 如果用户定义了此方法,则去执行此方法,并传入读取的文件回调
373
- res = props.beforeRead(file, getDetail());
374
- }
375
- if (props.useBeforeRead) {
376
- res = new Promise((resolve, reject) => {
377
- emit(
378
- "beforeRead",
195
+ if (props.disabled) return
196
+ // 如果用户传入的是字符串,需要格式化成数组
197
+ chooseFile(
379
198
  Object.assign(
380
- Object.assign(
381
199
  {
382
- file,
200
+ accept: props.accept,
201
+ extension: props.extension,
202
+ multiple: props.multiple,
203
+ capture: props.capture,
204
+ compressed: props.compressed,
205
+ maxDuration: props.maxDuration,
206
+ sizeType: props.sizeType,
207
+ camera: props.camera
383
208
  },
384
- getDetail(),
385
- ),
386
- {
387
- callback: (ok: any) => {
388
- ok ? resolve(ok) : reject();
389
- },
390
- },
391
- ),
392
- );
393
- });
394
- }
395
- if (!res) return;
396
- if (typeof res === "function") {
397
- res.then((data: any) => onAfterRead(data || file));
398
- } else {
399
- onAfterRead(file);
400
- }
401
- };
209
+ {
210
+ maxCount: props.maxCount - lists.value.length
211
+ }
212
+ )
213
+ )
214
+ .then((res: any) => {
215
+ onBeforeRead(props.multiple ? res : res[0])
216
+ })
217
+ .catch((error) => {
218
+ emit('error', error)
219
+ })
220
+ }
221
+ // 文件读取之前
222
+ const onBeforeRead = (file: FileVo) => {
223
+ let res: any = true
224
+ // beforeRead是否为一个方法
225
+ if (typeof props.beforeRead === 'function') {
226
+ // 如果用户定义了此方法,则去执行此方法,并传入读取的文件回调
227
+ res = props.beforeRead(file, getDetail())
228
+ }
229
+ if (props.useBeforeRead) {
230
+ res = new Promise((resolve, reject) => {
231
+ emit(
232
+ 'beforeRead',
233
+ Object.assign(
234
+ Object.assign(
235
+ {
236
+ file
237
+ },
238
+ getDetail()
239
+ ),
240
+ {
241
+ callback: (ok: any) => {
242
+ ok ? resolve(ok) : reject()
243
+ }
244
+ }
245
+ )
246
+ )
247
+ })
248
+ }
249
+ if (!res) return
250
+ if (typeof res === 'function') {
251
+ res.then((data: any) => onAfterRead(data || file))
252
+ } else {
253
+ onAfterRead(file)
254
+ }
255
+ }
402
256
  const getDetail = (index?: number) => {
403
- return {
404
- name: props.name,
405
- index: index == null ? props.fileList.length : index,
406
- };
407
- };
257
+ return {
258
+ name: props.name,
259
+ index: index == null ? props.fileList.length : index
260
+ }
261
+ }
408
262
  const onAfterRead = (file: FileVo) => {
409
- const oversize = isArray(file)
410
- ? file.some((item) => item.size > props.maxSize)
411
- : Number(file.size) > props.maxSize;
412
- if (oversize) {
263
+ const oversize = isArray(file)
264
+ ? file.some((item) => item.size > props.maxSize)
265
+ : Number(file.size) > props.maxSize
266
+ if (oversize) {
267
+ emit(
268
+ 'oversize',
269
+ Object.assign(
270
+ {
271
+ file
272
+ },
273
+ getDetail()
274
+ )
275
+ )
276
+ return
277
+ }
278
+ if (typeof props.afterRead === 'function') {
279
+ props.afterRead(file, getDetail())
280
+ }
413
281
  emit(
414
- "oversize",
415
- Object.assign(
416
- {
417
- file,
418
- },
419
- getDetail(),
420
- ),
421
- );
422
- return;
423
- }
424
- if (typeof props.afterRead === "function") {
425
- props.afterRead(file, getDetail());
426
- }
427
- emit(
428
- "afterRead",
429
- Object.assign(
430
- {
431
- file,
432
- },
433
- getDetail(),
434
- ),
435
- );
436
- };
282
+ 'afterRead',
283
+ Object.assign(
284
+ {
285
+ file
286
+ },
287
+ getDetail()
288
+ )
289
+ )
290
+ }
437
291
 
438
292
  /**
439
293
  * @description 删除文件
440
294
  * */
441
295
  const deleteItem = (index: number) => {
442
- props.fileList.splice(index, 1);
443
- isInCount.value = lists.value.length < props.maxCount;
444
- emit(
445
- "delete",
446
- Object.assign(Object.assign({}, getDetail(index)), {
447
- file: props.fileList[index],
448
- }),
449
- );
450
- };
296
+ props.fileList.splice(index, 1)
297
+ isInCount.value = lists.value.length < props.maxCount
298
+ emit(
299
+ 'delete',
300
+ Object.assign(Object.assign({}, getDetail(index)), {
301
+ file: props.fileList[index]
302
+ })
303
+ )
304
+ }
451
305
 
452
306
  /**
453
307
  * @description 预览图片
454
308
  * */
455
309
  const onPreviewImage = (previewItem: FileVo, index: number) => {
456
- if (!previewItem.isImage || !props.previewFullImage) return;
457
- let current = 0;
458
- const urls: string[] = [];
459
- let imageIndex = 0;
460
- for (let i = 0; i < lists.value.length; i++) {
461
- const item: FileVo = lists.value[i];
462
- if (item.isImage || (item.type && item.type === "image")) {
463
- urls.push(item.url || (item.thumb as string));
464
- if (i === index) {
465
- current = imageIndex;
466
- }
467
- imageIndex += 1;
310
+ if (!previewItem.isImage || !props.previewFullImage) return
311
+ let current = 0
312
+ const urls: string[] = []
313
+ let imageIndex = 0
314
+ for (let i = 0; i < lists.value.length; i++) {
315
+ const item: FileVo = lists.value[i]
316
+ if (item.isImage || (item.type && item.type === 'image')) {
317
+ urls.push(item.url || (item.thumb as string))
318
+ if (i === index) {
319
+ current = imageIndex
320
+ }
321
+ imageIndex += 1
322
+ }
468
323
  }
469
- }
470
- if (!urls || urls.length < 1) return;
471
- uni.previewImage({
472
- urls: urls,
473
- current: current,
474
- fail() {
475
- uni.showToast({ title: "预览图片失败" });
476
- },
477
- });
478
- };
324
+ if (!urls || urls.length < 1) return
325
+ uni.previewImage({
326
+ urls: urls,
327
+ current: current,
328
+ fail() {
329
+ uni.showToast({ title: '预览图片失败' })
330
+ }
331
+ })
332
+ }
479
333
 
480
334
  /**
481
335
  * @description 预览视频
482
336
  * */
483
337
  const onPreviewVideo = (index: number) => {
484
- if (!props.previewFullImage) return;
485
- let current = 0;
486
- const sources: any[] = [];
487
- let videoIndex = 0;
488
- for (let i = 0; i < lists.value.length; i++) {
489
- const item: FileVo = lists.value[i];
490
- if (item.isVideo || (item.type && item.type === "video")) {
491
- sources.push(
492
- Object.assign(Object.assign({}, item), {
493
- type: "video",
494
- }),
495
- );
496
- if (i === index) {
497
- current = videoIndex;
498
- }
499
- videoIndex += 1;
338
+ if (!props.previewFullImage) return
339
+ let current = 0
340
+ const sources: any[] = []
341
+ let videoIndex = 0
342
+ for (let i = 0; i < lists.value.length; i++) {
343
+ const item: FileVo = lists.value[i]
344
+ if (item.isVideo || (item.type && item.type === 'video')) {
345
+ sources.push(
346
+ Object.assign(Object.assign({}, item), {
347
+ type: 'video'
348
+ })
349
+ )
350
+ if (i === index) {
351
+ current = videoIndex
352
+ }
353
+ videoIndex += 1
354
+ }
500
355
  }
501
- }
502
- if (sources.length < 1) {
503
- return;
504
- }
505
- // #ifdef MP-WEIXIN
506
- wx.previewMedia({
507
- sources: sources,
508
- current: current,
509
- fail() {
510
- uni.showToast({ title: "预览视频失败" });
511
- },
512
- });
513
- // #endif
514
- };
356
+ if (sources.length < 1) {
357
+ return
358
+ }
359
+ // #ifdef MP-WEIXIN
360
+ wx.previewMedia({
361
+ sources: sources,
362
+ current: current,
363
+ fail() {
364
+ uni.showToast({ title: '预览视频失败' })
365
+ }
366
+ })
367
+ // #endif
368
+ }
515
369
 
516
370
  const onClickPreview = (item: FileVo, index: number) => {
517
- if (!props.previewFullImage) return;
518
- switch (item.type) {
519
- case "video":
520
- onPreviewVideo(index);
521
- break;
522
- default:
523
- break;
524
- }
525
- emit(
526
- "clickPreview",
527
- Object.assign(Object.assign({}, item), getDetail(index)),
528
- );
529
- };
371
+ if (!props.previewFullImage) return
372
+ switch (item.type) {
373
+ case 'video':
374
+ onPreviewVideo(index)
375
+ break
376
+ default:
377
+ break
378
+ }
379
+ emit('clickPreview', Object.assign(Object.assign({}, item), getDetail(index)))
380
+ }
530
381
  </script>
531
382
 
532
383
  <style lang="scss" scoped>
533
- @import "./index.scss";
384
+ @import './index.scss';
534
385
  </style>