hy-app 0.1.2 → 0.1.3

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 (221) hide show
  1. package/README.md +1 -1
  2. package/api/http.ts +8 -8
  3. package/components/dialog/index.ts +2 -2
  4. package/components/hy-address-picker/hy-address-picker.vue +3 -29
  5. package/components/hy-address-picker/index.scss +27 -0
  6. package/components/hy-avatar/hy-avatar.vue +1 -45
  7. package/components/hy-avatar/index.scss +45 -0
  8. package/components/hy-avatar/typing.d.ts +1 -1
  9. package/components/hy-back-top/hy-back-top.vue +7 -22
  10. package/components/hy-back-top/index.scss +16 -0
  11. package/components/hy-back-top/props.ts +4 -4
  12. package/components/hy-back-top/typing.d.ts +2 -3
  13. package/components/hy-badge/hy-badge.vue +1 -72
  14. package/components/hy-badge/index.scss +72 -0
  15. package/components/hy-button/hy-button.vue +12 -124
  16. package/components/hy-button/index.scss +116 -0
  17. package/components/hy-calendar/header.vue +76 -0
  18. package/components/hy-calendar/hy-calendar.vue +366 -0
  19. package/components/hy-calendar/index.scss +171 -0
  20. package/components/hy-calendar/month.vue +524 -0
  21. package/components/hy-calendar/props.ts +37 -0
  22. package/components/hy-calendar/typing.d.ts +126 -0
  23. package/components/hy-card/hy-card.vue +21 -84
  24. package/components/hy-card/index.scss +57 -0
  25. package/components/hy-card/props.ts +2 -2
  26. package/components/hy-card/typing.d.ts +1 -1
  27. package/components/hy-cell/hy-cell.vue +1 -137
  28. package/components/hy-cell/index.scss +137 -0
  29. package/components/hy-check-button/hy-check-button.vue +1 -0
  30. package/components/hy-check-button/index.scss +5 -0
  31. package/components/hy-checkbox/hy-checkbox.vue +2 -95
  32. package/components/hy-checkbox/index.scss +94 -0
  33. package/components/hy-checkbox/typing.d.ts +1 -2
  34. package/components/hy-count-down/hy-count-down.vue +150 -0
  35. package/components/hy-count-down/index.scss +6 -0
  36. package/components/hy-count-down/index.ts +52 -0
  37. package/components/hy-count-down/props.ts +10 -0
  38. package/components/hy-count-down/typing.d.ts +20 -0
  39. package/components/hy-count-to/hy-count-to.vue +213 -0
  40. package/components/hy-count-to/index.scss +6 -0
  41. package/components/hy-count-to/props.ts +17 -0
  42. package/components/hy-count-to/typing.d.ts +48 -0
  43. package/components/hy-datetime-picker/hy-datetime-picker.vue +2 -28
  44. package/components/hy-datetime-picker/index.scss +28 -0
  45. package/components/hy-divider/hy-divider.vue +24 -49
  46. package/components/hy-divider/index.scss +25 -0
  47. package/components/hy-divider/props.ts +2 -2
  48. package/components/hy-divider/typing.d.ts +1 -1
  49. package/components/hy-dropdown/hy-dropdown.vue +43 -0
  50. package/components/hy-dropdown/index.scss +17 -0
  51. package/components/hy-dropdown/props.ts +17 -0
  52. package/components/hy-dropdown/typing.d.ts +48 -0
  53. package/components/hy-dropdown-item/hy-dropdown-item.vue +194 -0
  54. package/components/hy-dropdown-item/index.scss +96 -0
  55. package/components/hy-dropdown-item/props.ts +10 -0
  56. package/components/hy-dropdown-item/typing.d.ts +31 -0
  57. package/components/hy-empty/hy-empty.vue +8 -26
  58. package/components/hy-empty/index.scss +19 -0
  59. package/components/hy-empty/props.ts +2 -2
  60. package/components/hy-empty/typing.d.ts +1 -1
  61. package/components/hy-float-button/hy-float-button.vue +201 -0
  62. package/components/hy-float-button/index.scss +69 -0
  63. package/components/hy-float-button/props.ts +25 -0
  64. package/components/hy-float-button/typing.d.ts +93 -0
  65. package/components/hy-folding-panel/hy-folding-panel.vue +9 -12
  66. package/components/hy-folding-panel/index.scss +6 -0
  67. package/components/hy-folding-panel/props.ts +2 -2
  68. package/components/hy-folding-panel/typing.d.ts +2 -2
  69. package/components/hy-form/hy-form.vue +17 -34
  70. package/components/hy-form/index.scss +30 -0
  71. package/components/hy-form/props.ts +2 -0
  72. package/components/hy-form/typing.d.ts +9 -1
  73. package/components/hy-grid/hy-grid.vue +1 -43
  74. package/components/hy-grid/index.scss +40 -0
  75. package/components/hy-icon/hy-icon.vue +1 -93
  76. package/components/hy-icon/index.scss +84 -0
  77. package/components/hy-image/hy-image.vue +212 -0
  78. package/components/hy-image/index.scss +26 -0
  79. package/components/hy-image/props.ts +24 -0
  80. package/components/hy-image/typing.d.ts +76 -0
  81. package/components/hy-input/hy-input.vue +2 -72
  82. package/components/hy-input/index.scss +65 -0
  83. package/components/hy-line/hy-line.vue +4 -8
  84. package/components/hy-line/index.scss +5 -0
  85. package/components/hy-line/props.ts +3 -3
  86. package/components/hy-line/typing.d.ts +2 -2
  87. package/components/hy-line-progress/hy-line-progress.vue +15 -44
  88. package/components/hy-line-progress/index.scss +38 -0
  89. package/components/hy-line-progress/props.ts +2 -2
  90. package/components/hy-line-progress/typing.d.ts +1 -1
  91. package/components/hy-list/hy-list.vue +11 -41
  92. package/components/hy-list/index.scss +32 -0
  93. package/components/hy-list/props.ts +2 -2
  94. package/components/hy-loading/hy-loading.vue +95 -0
  95. package/components/hy-loading/index.scss +103 -0
  96. package/components/hy-loading/props.ts +17 -0
  97. package/components/hy-loading/typing.d.ts +52 -0
  98. package/components/hy-login/TheUserLogin.vue +16 -16
  99. package/components/hy-login/hy-login.vue +9 -9
  100. package/components/hy-login/props.ts +4 -4
  101. package/components/hy-modal/hy-modal.vue +11 -89
  102. package/components/hy-modal/index.scss +77 -0
  103. package/components/hy-modal/props.ts +2 -2
  104. package/components/hy-modal/typing.d.ts +1 -1
  105. package/components/hy-navbar/hy-navbar.vue +20 -92
  106. package/components/hy-navbar/index.scss +67 -0
  107. package/components/hy-navbar/props.ts +2 -2
  108. package/components/hy-navbar/typing.d.ts +1 -1
  109. package/components/hy-notice-bar/hy-column-notice.vue +11 -39
  110. package/components/hy-notice-bar/hy-notice-bar.vue +10 -12
  111. package/components/hy-notice-bar/hy-row-notice.vue +5 -56
  112. package/components/hy-notice-bar/index.scss +93 -0
  113. package/components/hy-notice-bar/props.ts +4 -2
  114. package/components/hy-notice-bar/typing.d.ts +13 -3
  115. package/components/hy-number-step/hy-number-step.vue +1 -70
  116. package/components/hy-number-step/index.scss +71 -0
  117. package/components/hy-overlay/hy-overlay.vue +2 -14
  118. package/components/hy-overlay/index.scss +9 -0
  119. package/components/hy-picker/hy-picker.vue +1 -68
  120. package/components/hy-picker/index.scss +68 -0
  121. package/components/hy-popup/hy-popup.vue +1 -74
  122. package/components/hy-popup/index.scss +60 -0
  123. package/components/hy-price/hy-price.vue +1 -11
  124. package/components/hy-price/index.scss +11 -0
  125. package/components/hy-qrcode/hy-qrcode.vue +15 -37
  126. package/components/hy-qrcode/index.scss +23 -0
  127. package/components/hy-qrcode/props.ts +2 -2
  128. package/components/hy-qrcode/typing.d.ts +2 -2
  129. package/components/hy-radio/hy-radio.vue +2 -101
  130. package/components/hy-radio/index.scss +93 -0
  131. package/components/hy-radio/typing.d.ts +1 -2
  132. package/components/hy-rate/hy-rate.vue +1 -33
  133. package/components/hy-rate/index.scss +33 -0
  134. package/components/hy-read-more/hy-read-more.vue +7 -30
  135. package/components/hy-read-more/index.scss +25 -0
  136. package/components/hy-read-more/props.ts +3 -3
  137. package/components/hy-read-more/typing.d.ts +1 -1
  138. package/components/hy-safe-bottom/hy-safe-bottom.vue +5 -9
  139. package/components/hy-safe-bottom/index.scss +5 -0
  140. package/components/hy-scroll-list/hy-scroll-list.vue +13 -43
  141. package/components/hy-scroll-list/index.scss +34 -0
  142. package/components/hy-scroll-list/props.ts +2 -2
  143. package/components/hy-scroll-list/typing.d.ts +1 -1
  144. package/components/hy-search/hy-search.vue +1 -83
  145. package/components/hy-search/index.scss +83 -0
  146. package/components/hy-slider/hy-slider.vue +14 -92
  147. package/components/hy-slider/index.scss +77 -0
  148. package/components/hy-status-bar/hy-status-bar.vue +41 -0
  149. package/components/hy-status-bar/index.scss +6 -0
  150. package/components/hy-status-bar/props.ts +8 -0
  151. package/components/hy-status-bar/typing.d.ts +12 -0
  152. package/components/hy-steps/hy-steps.vue +36 -163
  153. package/components/hy-steps/index.scss +131 -0
  154. package/components/hy-steps/props.ts +2 -2
  155. package/components/hy-steps/typing.d.ts +2 -2
  156. package/components/hy-subsection/hy-subsection.vue +40 -132
  157. package/components/hy-subsection/index.scss +82 -0
  158. package/components/hy-subsection/props.ts +1 -0
  159. package/components/hy-subsection/typing.d.ts +13 -4
  160. package/components/hy-swipe-action/hy-swipe-action.vue +294 -0
  161. package/components/hy-swipe-action/index.scss +9 -0
  162. package/components/hy-swipe-action/index.wxs +235 -0
  163. package/components/hy-swipe-action/props.ts +16 -0
  164. package/components/hy-swipe-action/typing.d.ts +55 -0
  165. package/components/hy-swipe-action/wxs.js +15 -0
  166. package/components/hy-swiper/hy-swiper-indicator.vue +5 -35
  167. package/components/hy-swiper/hy-swiper.vue +1 -54
  168. package/components/hy-swiper/index.scss +82 -0
  169. package/components/hy-switch/hy-switch.vue +62 -72
  170. package/components/hy-switch/index.scss +46 -0
  171. package/components/hy-switch/props.ts +4 -1
  172. package/components/hy-switch/typing.d.ts +14 -1
  173. package/components/hy-tabs/hy-tabs.vue +22 -81
  174. package/components/hy-tabs/index.scss +63 -0
  175. package/components/hy-tabs/props.ts +5 -5
  176. package/components/hy-tabs/typing.d.ts +1 -1
  177. package/components/hy-tag/hy-tag.vue +1 -214
  178. package/components/hy-tag/index.scss +204 -0
  179. package/components/hy-text/hy-text.vue +238 -0
  180. package/components/hy-text/index.scss +70 -0
  181. package/components/hy-text/index.ts +0 -0
  182. package/components/hy-text/props.ts +30 -0
  183. package/components/hy-text/typing.d.ts +98 -0
  184. package/components/hy-textarea/hy-textarea.vue +1 -46
  185. package/components/hy-textarea/index.scss +40 -0
  186. package/components/hy-tooltip/hy-tooltip.vue +42 -95
  187. package/components/hy-tooltip/index.scss +64 -0
  188. package/components/hy-tooltip/props.ts +2 -2
  189. package/components/hy-tooltip/typing.d.ts +1 -1
  190. package/components/hy-transition/hy-transition.vue +4 -2
  191. package/components/hy-transition/typing.d.ts +1 -13
  192. package/components/hy-upload/hy-upload.vue +37 -182
  193. package/components/hy-upload/index.scss +147 -0
  194. package/components/hy-upload/props.ts +2 -2
  195. package/components/hy-upload/typing.d.ts +11 -11
  196. package/components/hy-warn/hy-warn.vue +15 -123
  197. package/components/hy-warn/index.scss +109 -0
  198. package/components/hy-warn/props.ts +3 -3
  199. package/components/hy-warn/typing.d.ts +4 -3
  200. package/components/hy-waterfall/index.scss +82 -0
  201. package/components/index.ts +25 -1
  202. package/components/message/index.ts +54 -54
  203. package/config/color.ts +2 -1
  204. package/global/index.ts +6 -6
  205. package/global/register-properties.ts +2 -2
  206. package/index.scss +2 -1
  207. package/libs/css/common.scss +14 -2
  208. package/package.json +2 -2
  209. package/{libs/css → public/font}/iconfont.css +4 -4
  210. package/theme.scss +6 -4
  211. package/typing/modules/common.d.ts +16 -1
  212. package/utils/calendar.js +1021 -0
  213. package/utils/colorGradient.ts +112 -0
  214. package/utils/index.ts +2 -0
  215. package/utils/inside.ts +80 -34
  216. package/utils/inspect.ts +66 -0
  217. package/utils/utils.ts +11 -12
  218. package/libs/css/download.zip +0 -0
  219. /package/{libs/css → public/font}/iconfont.ttf +0 -0
  220. /package/{libs/css → public/font}/iconfont.woff +0 -0
  221. /package/{libs/css → public/font}/iconfont.woff2 +0 -0
@@ -0,0 +1,30 @@
1
+ @use "../../theme.scss" as *;
2
+
3
+ .hy-form {
4
+ &--item {
5
+ display: flex;
6
+ flex-direction: v-bind(labelPos);
7
+ //align-items: center;
8
+ margin-bottom: $hy-border-margin-padding-lg;
9
+ &__label {
10
+ padding: $hy-border-margin-padding-base 0;
11
+ }
12
+ &__container {
13
+ flex: 1;
14
+ display: flex;
15
+ flex-direction: column;
16
+ &-content {
17
+ flex: 1;
18
+ display: flex;
19
+ align-items: center;
20
+ .flex {
21
+ flex: 1;
22
+ }
23
+ }
24
+ &-warning {
25
+ color: $hy-error;
26
+ font-size: $hy-font-size-hint;
27
+ }
28
+ }
29
+ }
30
+ }
@@ -4,6 +4,8 @@ const defaultProps: IProps = {
4
4
  labelPosition: "left",
5
5
  labelWidth: "auto",
6
6
  labelAlign: "left",
7
+ symbol: false,
8
+ borderBottom: false,
7
9
  right: false,
8
10
  itemHeight: 40,
9
11
  shape: "square",
@@ -23,7 +23,15 @@ export default interface IProps {
23
23
  * center - 中间对齐
24
24
  * right - 右对齐
25
25
  * */
26
- labelAlign?: HyApp.LeftRightType | "center";
26
+ labelAlign?: HyApp.CenterType;
27
+ /**
28
+ * @description 显示冒号符号
29
+ * */
30
+ symbol?: boolean;
31
+ /**
32
+ * @description 显示底部下划线
33
+ * */
34
+ borderBottom?: boolean;
27
35
  /**
28
36
  * @description 当行内容高度
29
37
  * */
@@ -77,51 +77,9 @@ const childClick = (name: string | Record<string, any>) => {
77
77
  </script>
78
78
 
79
79
  <style lang="scss" scoped>
80
- @import "../../libs/css/mixin.scss";
81
- @import "../../theme.scss";
82
80
  .hy-grid {
83
- /* #ifdef APP-NVUE */
84
- position: relative;
85
- box-sizing: border-box;
86
- overflow: hidden;
87
- display: block;
88
- /* #endif */
89
- justify-content: center;
90
- @include flex;
91
- flex-wrap: wrap;
92
- align-items: center;
93
- // 在uni-app中应尽量避免使用flex布局以外的方式,因为nvue/uvue等方案都支持flex布局
94
- // 这里使用grid布局使用为目前20240409uni-app在抖音小程序开启virtualHost时有bug,存在事件失效问题。
95
- /* #ifndef APP-NVUE */
96
- display: grid;
97
81
  grid-gap: v-bind(gap);
98
82
  grid-template-columns: repeat(v-bind(col), 1fr);
99
- /* #endif */
100
- &-item {
101
- align-items: center;
102
- justify-content: center;
103
- position: relative;
104
- flex-direction: column;
105
- overflow: hidden;
106
- /* #ifndef APP-NVUE */
107
- box-sizing: border-box;
108
- display: flex;
109
- /* #endif */
110
-
111
- /* #ifdef MP */
112
- position: relative;
113
- float: left;
114
- /* #endif */
115
-
116
- &--hover-class {
117
- opacity: 0.7;
118
- }
119
-
120
- &__title {
121
- color: #000;
122
- line-height: 60rpx;
123
- font-size: $hy-font-size-sm;
124
- }
125
- }
126
83
  }
84
+ @import "./index.scss";
127
85
  </style>
@@ -0,0 +1,40 @@
1
+ @use "../../libs/css/mixin.scss" as *;
2
+ @use "../../theme.scss" as *;
3
+
4
+ .hy-grid {
5
+ justify-content: center;
6
+ @include flex;
7
+ flex-wrap: wrap;
8
+ align-items: center;
9
+ // 在uni-app中应尽量避免使用flex布局以外的方式,因为nvue/uvue等方案都支持flex布局
10
+ // 这里使用grid布局使用为目前20240409uni-app在抖音小程序开启virtualHost时有bug,存在事件失效问题。
11
+ /* #ifndef APP-NVUE */
12
+ display: grid;
13
+ /* #endif */
14
+ &-item {
15
+ align-items: center;
16
+ justify-content: center;
17
+ position: relative;
18
+ flex-direction: column;
19
+ overflow: hidden;
20
+ /* #ifndef APP-NVUE */
21
+ box-sizing: border-box;
22
+ display: flex;
23
+ /* #endif */
24
+
25
+ /* #ifdef MP */
26
+ position: relative;
27
+ float: left;
28
+ /* #endif */
29
+
30
+ &--hover-class {
31
+ opacity: 0.7;
32
+ }
33
+
34
+ &__title {
35
+ color: #000;
36
+ line-height: 60rpx;
37
+ font-size: $hy-font-size-sm;
38
+ }
39
+ }
40
+ }
@@ -113,97 +113,5 @@ const clickHandler = (e: any) => {
113
113
  </script>
114
114
 
115
115
  <style lang="scss" scoped>
116
- @import "../../libs/css/mixin.scss";
117
- @import "../../libs/css/iconfont.css";
118
- @import "../../theme.scss";
119
-
120
- /* #ifndef APP-NVUE */
121
- // 非nvue下加载字体
122
- @font-face {
123
- font-family: "uicon-iconfont";
124
- src: url("https://at.alicdn.com/t/font_2225171_8kdcwk4po24.ttf")
125
- format("truetype");
126
- }
127
-
128
- /* #endif */
129
-
130
- .hy-icon {
131
- /* #ifndef APP-NVUE */
132
- display: flex;
133
- /* #endif */
134
- align-items: center;
135
-
136
- &--left {
137
- flex-direction: row-reverse;
138
- align-items: center;
139
- }
140
-
141
- &--right {
142
- flex-direction: row;
143
- align-items: center;
144
- }
145
-
146
- &--top {
147
- flex-direction: column-reverse;
148
- justify-content: center;
149
- }
150
-
151
- &--bottom {
152
- flex-direction: column;
153
- justify-content: center;
154
- }
155
-
156
- &__icon {
157
- position: relative;
158
- @include flex;
159
- align-items: center;
160
-
161
- &--primary {
162
- color: $hy-primary;
163
- }
164
-
165
- &--success {
166
- color: $hy-success;
167
- }
168
-
169
- &--error {
170
- color: $hy-error;
171
- }
172
-
173
- &--warning {
174
- color: $hy-warning;
175
- }
176
-
177
- &--info {
178
- color: $hy-info;
179
- }
180
- }
181
-
182
- &__img {
183
- /* #ifndef APP-NVUE */
184
- height: auto;
185
- will-change: transform;
186
- /* #endif */
187
- }
188
-
189
- &__label {
190
- @include line-feed();
191
- overflow: hidden;
192
- /* #ifndef APP-NVUE */
193
- line-height: 1;
194
- /* #endif */
195
- }
196
- }
197
- .hy-rotate {
198
- animation: hy-rotate 1s infinite linear;
199
- @keyframes hy-rotate {
200
- 0% {
201
- transform: rotate(0deg);
202
- }
203
-
204
- to {
205
- transform: rotate(1turn);
206
- }
207
- }
208
- }
116
+ @import "./index.scss";
209
117
  </style>
@@ -0,0 +1,84 @@
1
+ @use "../../libs/css/mixin.scss" as *;
2
+ @use "../../public/font/iconfont.css" as *;
3
+ @use "../../theme.scss" as *;
4
+
5
+
6
+ .hy-icon {
7
+ /* #ifndef APP-NVUE */
8
+ display: flex;
9
+ /* #endif */
10
+ align-items: center;
11
+
12
+ &--left {
13
+ flex-direction: row-reverse;
14
+ align-items: center;
15
+ }
16
+
17
+ &--right {
18
+ flex-direction: row;
19
+ align-items: center;
20
+ }
21
+
22
+ &--top {
23
+ flex-direction: column-reverse;
24
+ justify-content: center;
25
+ }
26
+
27
+ &--bottom {
28
+ flex-direction: column;
29
+ justify-content: center;
30
+ }
31
+
32
+ &__icon {
33
+ position: relative;
34
+ @include flex;
35
+ align-items: center;
36
+
37
+ &--primary {
38
+ color: $hy-primary;
39
+ }
40
+
41
+ &--success {
42
+ color: $hy-success;
43
+ }
44
+
45
+ &--error {
46
+ color: $hy-error;
47
+ }
48
+
49
+ &--warning {
50
+ color: $hy-warning;
51
+ }
52
+
53
+ &--info {
54
+ color: $hy-info;
55
+ }
56
+ }
57
+
58
+ &__img {
59
+ /* #ifndef APP-NVUE */
60
+ height: auto;
61
+ will-change: transform;
62
+ /* #endif */
63
+ }
64
+
65
+ &__label {
66
+ @include line-feed();
67
+ overflow: hidden;
68
+ /* #ifndef APP-NVUE */
69
+ line-height: 1;
70
+ /* #endif */
71
+ }
72
+ }
73
+ .hy-rotate {
74
+ animation: hy-rotate 1s infinite linear;
75
+ @keyframes hy-rotate {
76
+ 0% {
77
+ transform: rotate(0deg);
78
+ }
79
+
80
+ to {
81
+ transform: rotate(1turn);
82
+ }
83
+ }
84
+ }
@@ -0,0 +1,212 @@
1
+ <template>
2
+ <HyTransition
3
+ mode="fade"
4
+ :show="show"
5
+ :style="transStyle"
6
+ :duration="fade ? 1000 : 0"
7
+ >
8
+ <view
9
+ class="hy-image box-border"
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__image"
22
+ :style="{
23
+ width: addUnit(width),
24
+ height: addUnit(height),
25
+ borderRadius: shape == 'circle' ? '10000px' : addUnit(radius),
26
+ }"
27
+ ></image>
28
+ <view
29
+ v-if="showLoading && loading"
30
+ class="hy-image__loading"
31
+ :style="{
32
+ borderRadius: shape == 'circle' ? '50%' : addUnit(radius),
33
+ backgroundColor: bgColor,
34
+ width: addUnit(width),
35
+ height: addUnit(height),
36
+ }"
37
+ >
38
+ <slot name="loading">
39
+ <HyIcon :name="loadingIcon"></HyIcon>
40
+ </slot>
41
+ </view>
42
+ <view
43
+ v-if="showError && isError && !loading"
44
+ class="hy-image__error"
45
+ :style="{
46
+ borderRadius: shape == 'circle' ? '50%' : addUnit(radius),
47
+ }"
48
+ >
49
+ <slot name="error">
50
+ <HyIcon :name="errorIcon"></HyIcon>
51
+ </slot>
52
+ </view>
53
+ </view>
54
+ </HyTransition>
55
+ </template>
56
+
57
+ <script setup lang="ts">
58
+ import {
59
+ computed,
60
+ type CSSProperties,
61
+ onMounted,
62
+ ref,
63
+ toRefs,
64
+ watch,
65
+ } from "vue";
66
+ import defaultProps from "./props";
67
+ import type IProps from "./typing";
68
+ import HyTransition from "../hy-transition/hy-transition.vue";
69
+ import { addUnit, getPx } from "../../utils";
70
+
71
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
72
+ const {
73
+ customStyle,
74
+ duration,
75
+ src,
76
+ width,
77
+ height,
78
+ mode,
79
+ shape,
80
+ radius,
81
+ bgColor,
82
+ previewImage,
83
+ } = toRefs(props);
84
+ const emit = defineEmits(["click", "error", "load"]);
85
+
86
+ // 图片是否加载错误,如果是,则显示错误占位图
87
+ const isError = ref(false);
88
+ // 初始化组件时,默认为加载中状态
89
+ const loading = ref(true);
90
+ // 不透明度,为了实现淡入淡出的效果
91
+ const opacity = ref(1);
92
+ // 过渡时间,因为props的值无法修改,故需要一个中间值
93
+ const durationTime = ref(duration.value);
94
+ // 图片加载完成时,去掉背景颜色,因为如果是png图片,就会显示灰色的背景
95
+ const backgroundStyle = ref({});
96
+ // 用于fade模式的控制组件显示与否
97
+ const show = ref(false);
98
+
99
+ watch(
100
+ () => src.value,
101
+ (newValue) => {
102
+ if (!newValue) {
103
+ // 如果传入null或者'',或者false,或者undefined,标记为错误状态
104
+ isError.value = true;
105
+ } else {
106
+ isError.value = false;
107
+ loading.value = true;
108
+ }
109
+ },
110
+ { immediate: true },
111
+ );
112
+
113
+ const transStyle = computed<CSSProperties>(() => {
114
+ const style: CSSProperties = {};
115
+ if (
116
+ loading.value ||
117
+ isError.value ||
118
+ width.value == "100%" ||
119
+ mode.value != "heightFix"
120
+ ) {
121
+ style.width = addUnit(width.value);
122
+ } else {
123
+ style.width = "fit-content";
124
+ }
125
+ if (
126
+ loading.value ||
127
+ isError.value ||
128
+ height.value == "100%" ||
129
+ mode.value != "widthFix"
130
+ ) {
131
+ style.height = addUnit(height.value);
132
+ } else {
133
+ style.height = "fit-content";
134
+ }
135
+ return style;
136
+ });
137
+
138
+ const wrapStyle = computed(() => {
139
+ const style: CSSProperties = {};
140
+ if (
141
+ loading.value ||
142
+ isError.value ||
143
+ width.value == "100%" ||
144
+ mode.value != "heightFix"
145
+ ) {
146
+ style.width = addUnit(width.value);
147
+ } else {
148
+ style.width = "fit-content";
149
+ }
150
+ if (
151
+ loading.value ||
152
+ isError.value ||
153
+ height.value == "100%" ||
154
+ mode.value != "widthFix"
155
+ ) {
156
+ style.height = addUnit(height.value);
157
+ } else {
158
+ style.height = "fit-content";
159
+ }
160
+ // 如果是显示圆形,设置一个很多的半径值即可
161
+ style.borderRadius =
162
+ shape.value == "circle" ? "10000px" : addUnit(radius.value);
163
+ // 如果设置圆角,必须要有hidden,否则可能圆角无效
164
+ style.overflow = getPx(radius.value) > 0 ? "hidden" : "visible";
165
+
166
+ return Object.assign(style, customStyle.value);
167
+ });
168
+
169
+ onMounted(() => {
170
+ show.value = true;
171
+ });
172
+
173
+ const clickHandler = () => {
174
+ emit("click");
175
+
176
+ if (previewImage.value) {
177
+ uni.previewImage({
178
+ urls: [src.value],
179
+ });
180
+ }
181
+ };
182
+
183
+ /**
184
+ * @description 图片加载失败
185
+ * */
186
+ const onErrorHandler = (err: Event) => {
187
+ loading.value = false;
188
+ isError.value = true;
189
+ emit("error", err);
190
+ };
191
+
192
+ /**
193
+ * @description 图片加载成功
194
+ * */
195
+ const onLoadHandler = (e: Event) => {
196
+ loading.value = false;
197
+ isError.value = false;
198
+ emit("load", e);
199
+ removeBgColor();
200
+ };
201
+
202
+ const removeBgColor = () => {
203
+ // 淡入动画过渡完成后,将背景设置为透明色,否则png图片会看到灰色的背景
204
+ backgroundStyle.value = {
205
+ backgroundColor: bgColor.value || "#ffffff",
206
+ };
207
+ };
208
+ </script>
209
+
210
+ <style scoped lang="scss">
211
+ @import "./index.scss";
212
+ </style>
@@ -0,0 +1,26 @@
1
+ @use "../../libs/css/mixin.scss" as *;
2
+
3
+ .hy-image {
4
+ position: relative;
5
+ transition: opacity 0.5s ease-in-out;
6
+
7
+ &__image {
8
+ width: 100%;
9
+ height: 100%;
10
+ }
11
+
12
+ &__loading,
13
+ &__error {
14
+ position: absolute;
15
+ top: 0;
16
+ left: 0;
17
+ width: 100%;
18
+ height: 100%;
19
+ @include flex;
20
+ align-items: center;
21
+ justify-content: center;
22
+ background-color: #f8f8f8ff;
23
+ color: #909193ff;
24
+ font-size: 46px;
25
+ }
26
+ }
@@ -0,0 +1,24 @@
1
+ import type IProps from "./typing";
2
+ import { IconConfig } from "../../config";
3
+
4
+ const defaultProps: IProps = {
5
+ src: "",
6
+ mode: "aspectFill",
7
+ width: "200",
8
+ height: "150",
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: "#f3f4f6",
21
+ previewImage: false,
22
+ };
23
+
24
+ export default defaultProps;
@@ -0,0 +1,76 @@
1
+ import type { CSSProperties } from "vue";
2
+
3
+ export default interface IProps {
4
+ /**
5
+ * @description 图片地址
6
+ * */
7
+ src?: string;
8
+ /**
9
+ * @description 裁剪模式,见官网说明 (默认 'aspectFill' )
10
+ * */
11
+ mode?: HyApp.ImageModeVo;
12
+ /**
13
+ * @description 宽度,单位任意,如果为数值,则为px单位 (默认 '300' )
14
+ * */
15
+ width?: string | number;
16
+ /**
17
+ * @description 高度,单位任意,如果为数值,则为px单位 (默认 '225' )
18
+ * */
19
+ height?: string | number;
20
+ /**
21
+ * @description 图片形状,circle-圆形,square-方形 (默认 'square' )
22
+ * */
23
+ shape?: HyApp.ShapeType;
24
+ /**
25
+ * @description 圆角值,单位任意,如果为数值,则为px单位 (默认 0 )
26
+ * */
27
+ radius?: number | string;
28
+ /**
29
+ * @description 是否懒加载,仅微信小程序、App、百度小程序、字节跳动小程序有效 (默认 true )
30
+ * */
31
+ lazyLoad?: boolean;
32
+ /**
33
+ * @description 是否开启长按图片显示识别小程序码菜单,仅微信小程序有效 (默认 true )
34
+ * */
35
+ showMenuByLongPress?: boolean;
36
+ /**
37
+ * @description 加载中的图标,或者小图片 (默认 'photo' )
38
+ * */
39
+ loadingIcon?: string;
40
+ /**
41
+ * @description 加载失败的图标,或者小图片 (默认 'error-circle' )
42
+ * */
43
+ errorIcon?: string;
44
+ /**
45
+ * @description 是否显示加载中的图标或者自定义的slot (默认 true )
46
+ * */
47
+ showLoading?: boolean;
48
+ /**
49
+ * @description 是否显示加载错误的图标或者自定义的slot (默认 true )
50
+ * */
51
+ showError?: boolean;
52
+ /**
53
+ * @description 是否需要淡入效果 (默认 true )
54
+ * */
55
+ fade?: boolean;
56
+ /**
57
+ * @description 只支持网络资源,只对微信小程序有效 (默认 false )
58
+ * */
59
+ webp?: boolean;
60
+ /**
61
+ * @description 搭配fade参数的过渡时间,单位ms (默认 500 )
62
+ * */
63
+ duration?: number;
64
+ /**
65
+ * @description 背景颜色,用于深色页面加载图片时,为了和背景色融合 (默认 '#f3f4f6' )
66
+ * */
67
+ bgColor?: string;
68
+ /**
69
+ * @description 是否预览图片 (默认 false )
70
+ * */
71
+ previewImage?: boolean;
72
+ /**
73
+ * @description 定义需要用到的外部样式
74
+ * */
75
+ customStyle?: CSSProperties;
76
+ }