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,322 +1,192 @@
1
1
  <template>
2
- <hy-transition
3
- mode="fade"
4
- :show="show"
5
- :style="transStyle"
6
- :duration="fade ? 1000 : 0"
7
- >
8
- <view
9
- :class="['hy-image', 'box-border', customClass]"
10
- @tap="clickHandler"
11
- :style="[wrapStyle, backgroundStyle]"
12
- >
13
- <image
14
- v-if="!isError"
15
- :src="src"
16
- :mode="mode"
17
- @error="onErrorHandler"
18
- @load="onLoadHandler"
19
- :show-menu-by-longpress="showMenuByLongPress"
20
- :lazy-load="lazyLoad"
21
- :class="['hy-image__url', indistinct && 'hy-image__indistinct']"
22
- :style="{
23
- width: addUnit(width),
24
- height: addUnit(height),
25
- borderRadius: shape == 'circle' ? '1000px' : addUnit(radius),
26
- }"
27
- referrerpolicy="no-referrer"
28
- ></image>
29
- <view
30
- v-if="showLoading && loading"
31
- class="hy-image__loading"
32
- :style="{
33
- borderRadius: shape == 'circle' ? '50%' : addUnit(radius),
34
- backgroundColor: bgColor,
35
- width: addUnit(width),
36
- height: addUnit(height),
37
- }"
38
- >
39
- <slot v-if="$slots.loading" name="loading"></slot>
40
- <template v-else>
41
- <hy-loading :name="loadingIcon"></hy-loading>
42
- </template>
43
- </view>
44
- <view
45
- v-if="showError && isError && !loading"
46
- class="hy-image__error"
47
- :style="{
48
- borderRadius: shape == 'circle' ? '50%' : addUnit(radius),
49
- }"
50
- >
51
- <slot name="error">
52
- <hy-icon :name="errorIcon" size="30"></hy-icon>
53
- </slot>
54
- </view>
55
- </view>
56
- </hy-transition>
2
+ <hy-transition mode="fade" :show="show" :style="transStyle" :duration="fade ? 1000 : 0">
3
+ <view
4
+ :class="['hy-image', 'box-border', customClass]"
5
+ @tap="clickHandler"
6
+ :style="[wrapStyle, backgroundStyle]"
7
+ >
8
+ <image
9
+ v-if="!isError"
10
+ :src="src"
11
+ :mode="mode"
12
+ @error="onErrorHandler"
13
+ @load="onLoadHandler"
14
+ :show-menu-by-longpress="showMenuByLongPress"
15
+ :lazy-load="lazyLoad"
16
+ :class="['hy-image__url', indistinct && 'hy-image__indistinct']"
17
+ :style="{
18
+ width: addUnit(width),
19
+ height: addUnit(height),
20
+ borderRadius: shape == 'circle' ? '1000px' : addUnit(radius)
21
+ }"
22
+ referrerpolicy="no-referrer"
23
+ ></image>
24
+ <view
25
+ v-if="showLoading && loading"
26
+ class="hy-image__loading"
27
+ :style="{
28
+ borderRadius: shape == 'circle' ? '50%' : addUnit(radius),
29
+ backgroundColor: bgColor,
30
+ width: addUnit(width),
31
+ height: addUnit(height)
32
+ }"
33
+ >
34
+ <slot v-if="$slots.loading" name="loading"></slot>
35
+ <template v-else>
36
+ <hy-loading :name="loadingIcon"></hy-loading>
37
+ </template>
38
+ </view>
39
+ <view
40
+ v-if="showError && isError && !loading"
41
+ class="hy-image__error"
42
+ :style="{
43
+ borderRadius: shape == 'circle' ? '50%' : addUnit(radius)
44
+ }"
45
+ >
46
+ <slot name="error">
47
+ <hy-icon :name="errorIcon" size="30"></hy-icon>
48
+ </slot>
49
+ </view>
50
+ </view>
51
+ </hy-transition>
57
52
  </template>
58
53
 
59
54
  <script lang="ts">
60
55
  export default {
61
- name: "hy-image",
62
- options: {
63
- addGlobalClass: true,
64
- virtualHost: true,
65
- styleIsolation: "shared",
66
- },
67
- };
56
+ name: 'hy-image',
57
+ options: {
58
+ addGlobalClass: true,
59
+ virtualHost: true,
60
+ styleIsolation: 'shared'
61
+ }
62
+ }
68
63
  </script>
69
64
 
70
65
  <script setup lang="ts">
71
- import { computed, onMounted, ref, watch } from "vue";
72
- import type { PropType, CSSProperties } from "vue";
73
- import type { IImageEmits } from "./typing";
74
- import { IconConfig, addUnit, getPx } from "../../libs";
66
+ import { computed, onMounted, ref, watch } from 'vue'
67
+ import type { CSSProperties } from 'vue'
68
+ import type { IImageEmits } from './typing'
69
+ import { addUnit, getPx } from '../../libs'
70
+ import type { ImageOnErrorEvent, ImageOnLoadEvent } from '@uni-helper/uni-types'
71
+ import imageProps from './props'
75
72
  // 组件
76
- import HyIcon from "../hy-icon/hy-icon.vue";
77
- import HyTransition from "../hy-transition/hy-transition.vue";
78
- import HyLoading from "../hy-loading/hy-loading.vue";
79
- import type {
80
- ImageOnErrorEvent,
81
- ImageOnLoadEvent,
82
- } from "@uni-helper/uni-types";
73
+ import HyIcon from '../hy-icon/hy-icon.vue'
74
+ import HyTransition from '../hy-transition/hy-transition.vue'
75
+ import HyLoading from '../hy-loading/hy-loading.vue'
83
76
 
84
77
  /**
85
78
  * uni-app的image组件的加强版,在继承了原有功能外,还支持淡入动画、加载中、加载失败提示、圆角值和形状等。
86
79
  * @displayName hy-image
87
80
  */
88
- defineOptions({});
81
+ defineOptions({})
89
82
 
90
- // const props = withDefaults(defineProps<IProps>(), defaultProps)
91
- const props = defineProps({
92
- /** 图片地址 */
93
- src: {
94
- type: String,
95
- default: "",
96
- required: true,
97
- },
98
- /**
99
- * 裁剪模式,见官网说明
100
- * @values scaleToFill,aspectFit,aspectFill,widthFix,heightFix,top,bottom,center,left,right,top left,top right,bottom left,bottom right
101
- * */
102
- mode: {
103
- type: String,
104
- default: "aspectFill",
105
- },
106
- /** 宽度,单位任意,如果为数值,则为px单位 */
107
- width: {
108
- type: [String, Number],
109
- default: "",
110
- },
111
- /** 高度,单位任意,如果为数值,则为px单位 */
112
- height: {
113
- type: [String, Number],
114
- default: "",
115
- },
116
- /**
117
- * 图片形状
118
- * @values circle,square
119
- * */
120
- shape: {
121
- type: String,
122
- default: "square",
123
- },
124
- /** 圆角值,单位任意,如果为数值,则为px单位 */
125
- radius: {
126
- type: [Number, String],
127
- default: 0,
128
- },
129
- /** 是否懒加载,仅微信小程序、App、百度小程序、字节跳动小程序有效 */
130
- lazyLoad: {
131
- type: Boolean,
132
- default: true,
133
- },
134
- /** 是否开启长按图片显示识别小程序码菜单,仅微信小程序有效 */
135
- showMenuByLongPress: {
136
- type: Boolean,
137
- default: true,
138
- },
139
- /** 加载中的图标,或者小图片 */
140
- loadingIcon: {
141
- type: String,
142
- default: IconConfig.LOADING,
143
- },
144
- /** 加载失败的图标,或者小图片 */
145
- errorIcon: {
146
- type: String,
147
- default: IconConfig.NOTICE,
148
- },
149
- /** 是否显示加载中的图标或者自定义的slot */
150
- showLoading: {
151
- type: Boolean,
152
- default: true,
153
- },
154
- /** 是否显示加载错误的图标或者自定义的slot */
155
- showError: {
156
- type: Boolean,
157
- default: true,
158
- },
159
- /** 是否需要淡入效果 */
160
- fade: {
161
- type: Boolean,
162
- default: true,
163
- },
164
- /** 只支持网络资源,只对微信小程序有效 */
165
- webp: {
166
- type: Boolean,
167
- default: false,
168
- },
169
- /** 搭配fade参数的过渡时间,单位ms */
170
- duration: {
171
- type: Number,
172
- default: 500,
173
- },
174
- /** 背景颜色,用于深色页面加载图片时,为了和背景色融合 */
175
- bgColor: String,
176
- /** 是否模糊图片 */
177
- indistinct: {
178
- type: Boolean,
179
- default: false,
180
- },
181
- /** 是否预览图片 */
182
- previewImage: {
183
- type: Boolean,
184
- default: false,
185
- },
186
- /** 定义需要用到的外部样式 */
187
- customStyle: {
188
- type: Object as PropType<CSSProperties>,
189
- },
190
- /** 自定义外部类名 */
191
- customClass: String,
192
- });
193
- const emit = defineEmits<IImageEmits>();
83
+ const props = defineProps(imageProps)
84
+ const emit = defineEmits<IImageEmits>()
194
85
 
195
86
  // 图片是否加载错误,如果是,则显示错误占位图
196
- const isError = ref(false);
87
+ const isError = ref(false)
197
88
  // 初始化组件时,默认为加载中状态
198
- const loading = ref(true);
89
+ const loading = ref(true)
199
90
  // 不透明度,为了实现淡入淡出的效果
200
- const opacity = ref(1);
91
+ const opacity = ref(1)
201
92
  // 过渡时间,因为props的值无法修改,故需要一个中间值
202
- const durationTime = ref(props.duration);
93
+ const durationTime = ref(props.duration)
203
94
  // 图片加载完成时,去掉背景颜色,因为如果是png图片,就会显示灰色的背景
204
- const backgroundStyle = ref({});
95
+ const backgroundStyle = ref({})
205
96
  // 用于fade模式的控制组件显示与否
206
- const show = ref(false);
97
+ const show = ref(false)
207
98
 
208
99
  watch(
209
- () => props.src,
210
- (newValue) => {
211
- if (!newValue) {
212
- // 如果传入null或者'',或者false,或者undefined,标记为错误状态
213
- isError.value = true;
214
- loading.value = false;
215
- } else {
216
- isError.value = false;
217
- loading.value = true;
218
- }
219
- },
220
- { immediate: true },
221
- );
100
+ () => props.src,
101
+ (newValue) => {
102
+ if (!newValue) {
103
+ // 如果传入null或者'',或者false,或者undefined,标记为错误状态
104
+ isError.value = true
105
+ loading.value = false
106
+ } else {
107
+ isError.value = false
108
+ loading.value = true
109
+ }
110
+ },
111
+ { immediate: true }
112
+ )
222
113
 
223
114
  const transStyle = computed<CSSProperties>(() => {
224
- const style: CSSProperties = {};
225
- if (
226
- loading.value ||
227
- isError.value ||
228
- props.width == "100%" ||
229
- props.mode != "heightFix"
230
- ) {
231
- style.width = addUnit(props.width);
232
- } else {
233
- style.width = "fit-content";
234
- }
235
- if (
236
- loading.value ||
237
- isError.value ||
238
- props.height == "100%" ||
239
- props.mode != "widthFix"
240
- ) {
241
- style.height = addUnit(props.height);
242
- } else {
243
- style.height = "fit-content";
244
- }
245
- return style;
246
- });
115
+ const style: CSSProperties = {}
116
+ if (loading.value || isError.value || props.width == '100%' || props.mode != 'heightFix') {
117
+ style.width = addUnit(props.width)
118
+ } else {
119
+ style.width = 'fit-content'
120
+ }
121
+ if (loading.value || isError.value || props.height == '100%' || props.mode != 'widthFix') {
122
+ style.height = addUnit(props.height)
123
+ } else {
124
+ style.height = 'fit-content'
125
+ }
126
+ return style
127
+ })
247
128
 
248
129
  const wrapStyle = computed(() => {
249
- const style: CSSProperties = {};
250
- if (
251
- loading.value ||
252
- isError.value ||
253
- props.width == "100%" ||
254
- props.mode != "heightFix"
255
- ) {
256
- style.width = addUnit(props.width);
257
- } else {
258
- style.width = "fit-content";
259
- }
260
- if (
261
- loading.value ||
262
- isError.value ||
263
- props.height == "100%" ||
264
- props.mode != "widthFix"
265
- ) {
266
- style.height = addUnit(props.height);
267
- } else {
268
- style.height = "fit-content";
269
- }
270
- // 如果是显示圆形,设置一个很多的半径值即可
271
- style.borderRadius =
272
- props.shape == "circle" ? "10000px" : addUnit(props.radius);
273
- // 如果设置圆角,必须要有hidden,否则可能圆角无效
274
- style.overflow = getPx(props.radius) > 0 ? "hidden" : "visible";
130
+ const style: CSSProperties = {}
131
+ if (loading.value || isError.value || props.width == '100%' || props.mode != 'heightFix') {
132
+ style.width = addUnit(props.width)
133
+ } else {
134
+ style.width = 'fit-content'
135
+ }
136
+ if (loading.value || isError.value || props.height == '100%' || props.mode != 'widthFix') {
137
+ style.height = addUnit(props.height)
138
+ } else {
139
+ style.height = 'fit-content'
140
+ }
141
+ // 如果是显示圆形,设置一个很多的半径值即可
142
+ style.borderRadius = props.shape == 'circle' ? '10000px' : addUnit(props.radius)
143
+ // 如果设置圆角,必须要有hidden,否则可能圆角无效
144
+ style.overflow = getPx(props.radius) > 0 ? 'hidden' : 'visible'
275
145
 
276
- return Object.assign(style, props.customStyle);
277
- });
146
+ return Object.assign(style, props.customStyle)
147
+ })
278
148
 
279
149
  onMounted(() => {
280
- show.value = true;
281
- });
150
+ show.value = true
151
+ })
282
152
 
283
153
  const clickHandler = () => {
284
- emit("click");
154
+ emit('click')
285
155
 
286
- if (props.previewImage) {
287
- uni.previewImage({
288
- urls: [props.src],
289
- });
290
- }
291
- };
156
+ if (props.previewImage) {
157
+ uni.previewImage({
158
+ urls: [props.src]
159
+ })
160
+ }
161
+ }
292
162
 
293
163
  /**
294
164
  * @description 图片加载失败
295
165
  * */
296
166
  const onErrorHandler = (err: ImageOnErrorEvent) => {
297
- loading.value = false;
298
- isError.value = true;
299
- emit("error", err);
300
- };
167
+ loading.value = false
168
+ isError.value = true
169
+ emit('error', err)
170
+ }
301
171
 
302
172
  /**
303
173
  * @description 图片加载成功
304
174
  * */
305
175
  const onLoadHandler = (e: ImageOnLoadEvent) => {
306
- loading.value = false;
307
- isError.value = false;
308
- emit("load", e);
309
- removeBgColor();
310
- };
176
+ loading.value = false
177
+ isError.value = false
178
+ emit('load', e)
179
+ removeBgColor()
180
+ }
311
181
 
312
182
  const removeBgColor = () => {
313
- // 淡入动画过渡完成后,将背景设置为透明色,否则png图片会看到灰色的背景
314
- backgroundStyle.value = {
315
- backgroundColor: props.bgColor,
316
- };
317
- };
183
+ // 淡入动画过渡完成后,将背景设置为透明色,否则png图片会看到灰色的背景
184
+ backgroundStyle.value = {
185
+ backgroundColor: props.bgColor
186
+ }
187
+ }
318
188
  </script>
319
189
 
320
190
  <style scoped lang="scss">
321
- @import "./index.scss";
191
+ @import './index.scss';
322
192
  </style>
@@ -1,25 +1,107 @@
1
- import type IProps from "./typing";
2
- import { IconConfig } from "../../libs/config";
1
+ import { IconConfig } from '../../libs/config'
2
+ import type { CSSProperties, PropType } from 'vue'
3
3
 
4
- const defaultProps: IProps = {
5
- src: "",
6
- mode: "aspectFill",
7
- width: "",
8
- height: "",
9
- shape: "square",
10
- radius: 0,
11
- lazyLoad: true,
12
- showMenuByLongPress: true,
13
- loadingIcon: IconConfig.LOADING,
14
- errorIcon: IconConfig.NOTICE,
15
- showLoading: true,
16
- showError: true,
17
- fade: true,
18
- webp: false,
19
- duration: 500,
20
- bgColor: "",
21
- indistinct: false,
22
- previewImage: false,
23
- };
4
+ const imageProps = {
5
+ /** 图片地址 */
6
+ src: {
7
+ type: String,
8
+ default: '',
9
+ required: true
10
+ },
11
+ /**
12
+ * 裁剪模式,见官网说明
13
+ * @values scaleToFill,aspectFit,aspectFill,widthFix,heightFix,top,bottom,center,left,right,top left,top right,bottom left,bottom right
14
+ * */
15
+ mode: {
16
+ type: String,
17
+ default: 'aspectFill'
18
+ },
19
+ /** 宽度,单位任意,如果为数值,则为px单位 */
20
+ width: {
21
+ type: [String, Number],
22
+ default: ''
23
+ },
24
+ /** 高度,单位任意,如果为数值,则为px单位 */
25
+ height: {
26
+ type: [String, Number],
27
+ default: ''
28
+ },
29
+ /**
30
+ * 图片形状
31
+ * @values circle,square
32
+ * */
33
+ shape: {
34
+ type: String,
35
+ default: 'square'
36
+ },
37
+ /** 圆角值,单位任意,如果为数值,则为px单位 */
38
+ radius: {
39
+ type: [Number, String],
40
+ default: 0
41
+ },
42
+ /** 是否懒加载,仅微信小程序、App、百度小程序、字节跳动小程序有效 */
43
+ lazyLoad: {
44
+ type: Boolean,
45
+ default: true
46
+ },
47
+ /** 是否开启长按图片显示识别小程序码菜单,仅微信小程序有效 */
48
+ showMenuByLongPress: {
49
+ type: Boolean,
50
+ default: true
51
+ },
52
+ /** 加载中的图标,或者小图片 */
53
+ loadingIcon: {
54
+ type: String,
55
+ default: IconConfig.LOADING
56
+ },
57
+ /** 加载失败的图标,或者小图片 */
58
+ errorIcon: {
59
+ type: String,
60
+ default: IconConfig.NOTICE
61
+ },
62
+ /** 是否显示加载中的图标或者自定义的slot */
63
+ showLoading: {
64
+ type: Boolean,
65
+ default: true
66
+ },
67
+ /** 是否显示加载错误的图标或者自定义的slot */
68
+ showError: {
69
+ type: Boolean,
70
+ default: true
71
+ },
72
+ /** 是否需要淡入效果 */
73
+ fade: {
74
+ type: Boolean,
75
+ default: true
76
+ },
77
+ /** 只支持网络资源,只对微信小程序有效 */
78
+ webp: {
79
+ type: Boolean,
80
+ default: false
81
+ },
82
+ /** 搭配fade参数的过渡时间,单位ms */
83
+ duration: {
84
+ type: Number,
85
+ default: 500
86
+ },
87
+ /** 背景颜色,用于深色页面加载图片时,为了和背景色融合 */
88
+ bgColor: String,
89
+ /** 是否模糊图片 */
90
+ indistinct: {
91
+ type: Boolean,
92
+ default: false
93
+ },
94
+ /** 是否预览图片 */
95
+ previewImage: {
96
+ type: Boolean,
97
+ default: false
98
+ },
99
+ /** 定义需要用到的外部样式 */
100
+ customStyle: {
101
+ type: Object as PropType<CSSProperties>
102
+ },
103
+ /** 自定义外部类名 */
104
+ customClass: String
105
+ }
24
106
 
25
- export default defaultProps;
107
+ export default imageProps