hy-app 0.1.1

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 (206) hide show
  1. package/README.md +42 -0
  2. package/api/http.ts +138 -0
  3. package/api/index.ts +1 -0
  4. package/common/index.ts +1 -0
  5. package/common/versionControl.ts +102 -0
  6. package/components/dialog/TheDialog.vue +128 -0
  7. package/components/dialog/index.ts +38 -0
  8. package/components/hy-address-picker/hy-address-picker.vue +262 -0
  9. package/components/hy-address-picker/props.ts +27 -0
  10. package/components/hy-address-picker/typing.d.ts +98 -0
  11. package/components/hy-avatar/hy-avatar.vue +217 -0
  12. package/components/hy-avatar/props.ts +20 -0
  13. package/components/hy-avatar/typing.d.ts +64 -0
  14. package/components/hy-back-top/hy-back-top.vue +71 -0
  15. package/components/hy-back-top/props.ts +23 -0
  16. package/components/hy-back-top/typing.d.ts +49 -0
  17. package/components/hy-badge/hy-badge.vue +155 -0
  18. package/components/hy-badge/props.ts +19 -0
  19. package/components/hy-badge/typing.d.ts +60 -0
  20. package/components/hy-button/hy-button.vue +394 -0
  21. package/components/hy-button/props.ts +36 -0
  22. package/components/hy-button/typing.d.ts +125 -0
  23. package/components/hy-card/hy-card.vue +198 -0
  24. package/components/hy-card/props.ts +29 -0
  25. package/components/hy-card/typing.d.ts +112 -0
  26. package/components/hy-cell/hy-cell.vue +268 -0
  27. package/components/hy-cell/props.ts +20 -0
  28. package/components/hy-cell/typing.d.ts +98 -0
  29. package/components/hy-check-button/hy-check-button.vue +71 -0
  30. package/components/hy-check-button/props.ts +20 -0
  31. package/components/hy-check-button/typing.d.ts +79 -0
  32. package/components/hy-checkbox/hy-checkbox.vue +299 -0
  33. package/components/hy-checkbox/props.ts +28 -0
  34. package/components/hy-checkbox/typing.d.ts +77 -0
  35. package/components/hy-datetime-picker/hy-datetime-picker.vue +584 -0
  36. package/components/hy-datetime-picker/props.ts +36 -0
  37. package/components/hy-datetime-picker/typing.d.ts +135 -0
  38. package/components/hy-divider/hy-divider.vue +164 -0
  39. package/components/hy-divider/props.ts +21 -0
  40. package/components/hy-divider/typing.d.ts +64 -0
  41. package/components/hy-empty/hy-empty.vue +122 -0
  42. package/components/hy-empty/props.ts +21 -0
  43. package/components/hy-empty/typing.d.ts +68 -0
  44. package/components/hy-folding-panel/hy-folding-panel.vue +94 -0
  45. package/components/hy-folding-panel/props.ts +17 -0
  46. package/components/hy-folding-panel/typing.d.ts +59 -0
  47. package/components/hy-form/hy-form.vue +372 -0
  48. package/components/hy-form/props.ts +15 -0
  49. package/components/hy-form/typing.d.ts +51 -0
  50. package/components/hy-grid/hy-grid.vue +126 -0
  51. package/components/hy-grid/props.ts +16 -0
  52. package/components/hy-grid/typing.d.ts +62 -0
  53. package/components/hy-icon/hy-icon.vue +207 -0
  54. package/components/hy-icon/props.ts +24 -0
  55. package/components/hy-icon/typing.d.ts +80 -0
  56. package/components/hy-input/hy-input.vue +402 -0
  57. package/components/hy-input/props.ts +41 -0
  58. package/components/hy-input/typing.d.ts +148 -0
  59. package/components/hy-line/hy-line.vue +44 -0
  60. package/components/hy-line/props.ts +12 -0
  61. package/components/hy-line/typing.d.ts +32 -0
  62. package/components/hy-line-progress/hy-line-progress.vue +118 -0
  63. package/components/hy-line-progress/props.ts +12 -0
  64. package/components/hy-line-progress/typing.d.ts +28 -0
  65. package/components/hy-list/hy-list.vue +250 -0
  66. package/components/hy-list/props.ts +18 -0
  67. package/components/hy-list/typing.d.ts +50 -0
  68. package/components/hy-login/ThePhoneLogin.vue +106 -0
  69. package/components/hy-login/TheUserLogin.vue +391 -0
  70. package/components/hy-login/hy-login.vue +283 -0
  71. package/components/hy-login/props.ts +32 -0
  72. package/components/hy-login/typing.d.ts +60 -0
  73. package/components/hy-modal/hy-modal.vue +240 -0
  74. package/components/hy-modal/props.ts +24 -0
  75. package/components/hy-modal/typing.d.ts +70 -0
  76. package/components/hy-navbar/hy-navbar.vue +194 -0
  77. package/components/hy-navbar/props.ts +24 -0
  78. package/components/hy-navbar/typing.d.ts +81 -0
  79. package/components/hy-notice-bar/hy-column-notice.vue +130 -0
  80. package/components/hy-notice-bar/hy-notice-bar.vue +82 -0
  81. package/components/hy-notice-bar/hy-row-notice.vue +182 -0
  82. package/components/hy-notice-bar/props.ts +19 -0
  83. package/components/hy-notice-bar/typing.d.ts +56 -0
  84. package/components/hy-number-step/hy-number-step.vue +428 -0
  85. package/components/hy-number-step/props.ts +29 -0
  86. package/components/hy-number-step/typing.d.ts +104 -0
  87. package/components/hy-overlay/hy-overlay.vue +54 -0
  88. package/components/hy-overlay/props.ts +10 -0
  89. package/components/hy-overlay/typing.d.ts +24 -0
  90. package/components/hy-picker/hy-picker.vue +499 -0
  91. package/components/hy-picker/props.ts +30 -0
  92. package/components/hy-picker/typing.d.ts +115 -0
  93. package/components/hy-popup/hy-popup.vue +269 -0
  94. package/components/hy-popup/props.ts +21 -0
  95. package/components/hy-popup/typing.d.ts +68 -0
  96. package/components/hy-price/hy-price.vue +86 -0
  97. package/components/hy-price/props.ts +13 -0
  98. package/components/hy-price/typing.d.ts +36 -0
  99. package/components/hy-qrcode/hy-qrcode.vue +153 -0
  100. package/components/hy-qrcode/props.ts +20 -0
  101. package/components/hy-qrcode/qrcode.js +1364 -0
  102. package/components/hy-qrcode/typing.d.ts +64 -0
  103. package/components/hy-radio/hy-radio.vue +319 -0
  104. package/components/hy-radio/props.ts +28 -0
  105. package/components/hy-radio/typing.d.ts +85 -0
  106. package/components/hy-rate/hy-rate.vue +261 -0
  107. package/components/hy-rate/props.ts +18 -0
  108. package/components/hy-rate/typing.d.ts +60 -0
  109. package/components/hy-read-more/hy-read-more.vue +134 -0
  110. package/components/hy-read-more/props.ts +20 -0
  111. package/components/hy-read-more/typing.d.ts +44 -0
  112. package/components/hy-safe-bottom/hy-safe-bottom.vue +64 -0
  113. package/components/hy-scroll-list/hy-scroll-list.vue +146 -0
  114. package/components/hy-scroll-list/props.ts +12 -0
  115. package/components/hy-scroll-list/typing.d.ts +28 -0
  116. package/components/hy-search/hy-search.vue +294 -0
  117. package/components/hy-search/props.ts +29 -0
  118. package/components/hy-search/typing.d.ts +109 -0
  119. package/components/hy-slider/hy-slider.vue +511 -0
  120. package/components/hy-slider/props.ts +21 -0
  121. package/components/hy-slider/typing.d.ts +68 -0
  122. package/components/hy-steps/hy-steps.vue +352 -0
  123. package/components/hy-steps/props.ts +15 -0
  124. package/components/hy-steps/typing.d.ts +58 -0
  125. package/components/hy-subsection/hy-subsection.vue +272 -0
  126. package/components/hy-subsection/props.ts +16 -0
  127. package/components/hy-subsection/typing.d.ts +44 -0
  128. package/components/hy-swiper/hy-swiper-indicator.vue +105 -0
  129. package/components/hy-swiper/hy-swiper.vue +242 -0
  130. package/components/hy-swiper/props.ts +30 -0
  131. package/components/hy-swiper/typing.d.ts +107 -0
  132. package/components/hy-switch/hy-switch.vue +168 -0
  133. package/components/hy-switch/props.ts +16 -0
  134. package/components/hy-switch/typing.d.ts +48 -0
  135. package/components/hy-tabs/hy-tabs.vue +416 -0
  136. package/components/hy-tabs/props.ts +26 -0
  137. package/components/hy-tabs/typing.d.ts +86 -0
  138. package/components/hy-tag/hy-tag.vue +374 -0
  139. package/components/hy-tag/props.ts +22 -0
  140. package/components/hy-tag/typing.d.ts +76 -0
  141. package/components/hy-textarea/hy-textarea.vue +229 -0
  142. package/components/hy-textarea/props.ts +26 -0
  143. package/components/hy-textarea/typing.d.ts +27 -0
  144. package/components/hy-tooltip/hy-tooltip.vue +332 -0
  145. package/components/hy-tooltip/props.ts +17 -0
  146. package/components/hy-tooltip/typing.d.ts +52 -0
  147. package/components/hy-transition/hy-transition.vue +150 -0
  148. package/components/hy-transition/index.scss +113 -0
  149. package/components/hy-transition/props.ts +10 -0
  150. package/components/hy-transition/typing.d.ts +36 -0
  151. package/components/hy-upload/hy-upload.vue +557 -0
  152. package/components/hy-upload/props.ts +29 -0
  153. package/components/hy-upload/typing.d.ts +147 -0
  154. package/components/hy-warn/hy-warn.vue +228 -0
  155. package/components/hy-warn/props.ts +14 -0
  156. package/components/hy-warn/typing.d.ts +40 -0
  157. package/components/hy-waterfall/hy-waterfall.vue +51 -0
  158. package/components/hy-waterfall/props.ts +10 -0
  159. package/components/hy-waterfall/typing.d.ts +20 -0
  160. package/components/index.ts +162 -0
  161. package/components/message/TheMessage.vue +169 -0
  162. package/components/message/index.ts +54 -0
  163. package/components/u-form/form.js +22 -0
  164. package/components/u-form/hy-form.vue +324 -0
  165. package/components/u-form/props.js +49 -0
  166. package/components/u-form/schema.js +1451 -0
  167. package/components/u-form/u-form.vue +267 -0
  168. package/components/u-form/utils.js +65 -0
  169. package/components/u-form-item/formItem.js +24 -0
  170. package/components/u-form-item/hy-form-item.vue +360 -0
  171. package/components/u-form-item/props.js +57 -0
  172. package/components/u-form-item/u-form-item.vue +294 -0
  173. package/components/yk-dialog/yk-dialog.vue +129 -0
  174. package/components/yk-tabbar/props.ts +49 -0
  175. package/components/yk-tabbar/yk-tabbar.vue +224 -0
  176. package/config/color.ts +6 -0
  177. package/config/icon.ts +366 -0
  178. package/config/index.ts +2 -0
  179. package/global/index.ts +6 -0
  180. package/global/register-properties.ts +37 -0
  181. package/index.ts +8 -0
  182. package/libs/css/common.scss +0 -0
  183. package/libs/css/iconfont.css +379 -0
  184. package/libs/css/iconfont.ttf +0 -0
  185. package/libs/css/mixin.scss +15 -0
  186. package/package.json +42 -0
  187. package/public/icons/error.png +0 -0
  188. package/public/icons/success.png +0 -0
  189. package/public/icons/warning.png +0 -0
  190. package/store/index.ts +1 -0
  191. package/store/userInfo.ts +25 -0
  192. package/theme.scss +94 -0
  193. package/typing/index.ts +7 -0
  194. package/typing/modules/common.d.ts +50 -0
  195. package/typing/modules/dialog.ts +17 -0
  196. package/typing/modules/enum.ts +67 -0
  197. package/typing/modules/form.ts +161 -0
  198. package/typing/modules/http.ts +68 -0
  199. package/typing/modules/icon.d.ts +366 -0
  200. package/typing/modules/img.ts +15 -0
  201. package/typing/modules/rect.ts +10 -0
  202. package/utils/address.json +5890 -0
  203. package/utils/base64.ts +119 -0
  204. package/utils/index.ts +3 -0
  205. package/utils/inside.ts +310 -0
  206. package/utils/utils.ts +446 -0
@@ -0,0 +1,261 @@
1
+ <template>
2
+ <view class="hy-rate" :id="elId" ref="hy-rate" :style="[customStyle]">
3
+ <view
4
+ class="hy-rate__content"
5
+ @touchmove.stop="touchMove"
6
+ @touchend.stop="touchEnd"
7
+ >
8
+ <view
9
+ class="hy-rate__content__item cursor-pointer"
10
+ v-for="(item, index) in Number(count)"
11
+ :key="index"
12
+ :class="[elClass]"
13
+ >
14
+ <view
15
+ class="hy-rate__content__item__icon-wrap"
16
+ ref="hy-rate__content__item__icon-wrap"
17
+ @tap.stop="clickHandler($event)"
18
+ >
19
+ <HyIcon
20
+ :name="Math.floor(activeIndex) > index ? activeIcon : inactiveIcon"
21
+ :color="
22
+ disabled
23
+ ? '#c8c9cc'
24
+ : Math.floor(activeIndex) > index
25
+ ? activeColor
26
+ : inactiveColor
27
+ "
28
+ :custom-style="{
29
+ padding: `0 ${addUnit(gutter / 2)}`
30
+ }"
31
+ :size="size"
32
+ ></HyIcon>
33
+ </view>
34
+ <view
35
+ v-if="allowHalf"
36
+ @tap.stop="clickHandler($event)"
37
+ class="hy-rate__content__item__icon-wrap hy-rate__content__item__icon-wrap--half"
38
+ :style="[
39
+ {
40
+ width: addUnit(rateWidth / 2)
41
+ }
42
+ ]"
43
+ ref="hy-rate__content__item__icon-wrap"
44
+ >
45
+ <HyIcon
46
+ :name="Math.ceil(activeIndex) > index ? activeIcon : inactiveIcon"
47
+ :color="
48
+ disabled
49
+ ? '#c8c9cc'
50
+ : Math.ceil(activeIndex) > index
51
+ ? activeColor
52
+ : inactiveColor
53
+ "
54
+ :custom-style="{
55
+ padding: `0 ${addUnit(gutter / 2)}`
56
+ }"
57
+ :size="size"
58
+ ></HyIcon>
59
+ </view>
60
+ </view>
61
+ </view>
62
+ </view>
63
+ </template>
64
+
65
+ <script setup lang="ts">
66
+ import { addUnit, getRect, guid, range, sleep } from "../../utils";
67
+ import { ref, watch, toRefs, onMounted, nextTick } from "vue";
68
+ import IProps from "./typing";
69
+ import defaultProps from "./props";
70
+
71
+ // 组件
72
+ import HyIcon from "../hy-icon/hy-icon.vue";
73
+
74
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
75
+ const {
76
+ modelValue,
77
+ touchable,
78
+ minCount,
79
+ count,
80
+ disabled,
81
+ readonly,
82
+ allowHalf
83
+ } = toRefs(props);
84
+ const emit = defineEmits(["update:modelValue", "change"]);
85
+
86
+ const elId = guid();
87
+ const elClass = guid();
88
+ const rateBoxLeft = ref<number>(0);
89
+ const activeIndex = ref(modelValue.value);
90
+ // 每个星星的宽度
91
+ const rateWidth = ref(0);
92
+ // 标识是否正在滑动,由于iOS事件上touch比click先触发,导致快速滑动结束后,接着触发click,导致事件混乱而出错
93
+ const moving = ref(false);
94
+
95
+ watch(
96
+ () => modelValue.value,
97
+ (newValue) => {
98
+ activeIndex.value = newValue;
99
+ }
100
+ );
101
+ watch(
102
+ () => activeIndex.value,
103
+ (newVal) => {
104
+ emitEvent();
105
+ }
106
+ );
107
+
108
+ onMounted(() => {
109
+ init();
110
+ });
111
+
112
+ const init = () => {
113
+ sleep(200).then(() => {
114
+ getRateItemRect();
115
+ getRateIconWrapRect();
116
+ });
117
+ };
118
+
119
+ // 获取评分组件盒子的布局信息
120
+ const getRateItemRect = async () => {
121
+ await sleep();
122
+ // #ifndef APP-NVUE
123
+ const res: UniApp.NodeInfo = (await getRect(`#${elId}`)) as UniApp.NodeInfo;
124
+ rateBoxLeft.value = res.left || 0;
125
+ // #endif
126
+ };
127
+ // 获取单个星星的尺寸
128
+ const getRateIconWrapRect = async () => {
129
+ // uView封装的获取节点的方法,详见文档
130
+ // #ifndef APP-NVUE
131
+ const res: UniApp.NodeInfo = (await getRect(
132
+ `.${elClass}`
133
+ )) as UniApp.NodeInfo;
134
+ rateWidth.value = res.width || 0;
135
+ // #endif
136
+ };
137
+ // 手指滑动
138
+ const touchMove = (e: TouchEvent) => {
139
+ // 如果禁止通过手动滑动选择,返回
140
+ if (!touchable.value) {
141
+ return;
142
+ }
143
+ e.stopPropagation();
144
+ const x = e.changedTouches[0].pageX;
145
+ getActiveIndex(x);
146
+ };
147
+ // 停止滑动
148
+ const touchEnd = (e: TouchEvent) => {
149
+ // 如果禁止通过手动滑动选择,返回
150
+ if (!touchable.value) {
151
+ return;
152
+ }
153
+ e.stopPropagation();
154
+ const x = e.changedTouches[0].pageX;
155
+ getActiveIndex(x);
156
+ };
157
+ // 通过点击,直接选中
158
+ const clickHandler = (e: TouchEvent) => {
159
+ // if (moving.value) {
160
+ // return;
161
+ // }
162
+ e.stopPropagation();
163
+ let x = 0;
164
+ // #ifndef APP-NVUE
165
+ x = e.changedTouches[0].pageX;
166
+ // #endif
167
+ getActiveIndex(x, true);
168
+ };
169
+ // 发出事件
170
+ const emitEvent = () => {
171
+ // 发出change事件
172
+ emit("change", activeIndex.value);
173
+ // 同时修改双向绑定的值
174
+ emit("update:modelValue", activeIndex.value);
175
+ };
176
+ // 获取当前激活的评分图标
177
+ const getActiveIndex = (x: number, isClick = false) => {
178
+ if (disabled.value || readonly.value) {
179
+ return;
180
+ }
181
+ // 判断当前操作的点的x坐标值,是否在允许的边界范围内
182
+ const allRateWidth = rateWidth.value * count.value + rateBoxLeft.value;
183
+ // 如果小于第一个图标的左边界,设置为最小值,如果大于所有图标的宽度,则设置为最大值
184
+ x = range(rateBoxLeft.value, allRateWidth, x) - rateBoxLeft.value;
185
+ // 滑动点相对于评分盒子左边的距离
186
+ const distance = x;
187
+ // 滑动的距离,相当于多少颗星星
188
+ let index;
189
+ // 判断是否允许半星
190
+ if (allowHalf.value) {
191
+ index = Math.floor(distance / rateWidth.value);
192
+ // 取余,判断小数的区间范围
193
+ const decimal = distance % rateWidth.value;
194
+ if (decimal <= rateWidth.value / 2 && decimal > 0) {
195
+ index += 0.5;
196
+ } else if (decimal > rateWidth.value / 2) {
197
+ index++;
198
+ }
199
+ } else {
200
+ index = Math.floor(distance / rateWidth.value);
201
+ // 取余,判断小数的区间范围
202
+ const decimal = distance % rateWidth.value;
203
+ // 非半星时,只有超过了图标的一半距离,才认为是选择了这颗星
204
+ if (isClick) {
205
+ if (decimal > 0) index++;
206
+ } else {
207
+ if (decimal > rateWidth.value / 2) index++;
208
+ }
209
+ }
210
+ activeIndex.value = Math.min(index, count.value);
211
+ // 对最少颗星星的限制
212
+ if (activeIndex.value < minCount.value) {
213
+ activeIndex.value = minCount.value;
214
+ }
215
+
216
+ // 设置延时为了让click事件在touchmove之前触发
217
+ setTimeout(() => {
218
+ moving.value = true;
219
+ }, 10);
220
+ // 一定时间后,取消标识为移动中状态,是为了让click事件无效
221
+ setTimeout(() => {
222
+ moving.value = false;
223
+ }, 10);
224
+ };
225
+ </script>
226
+
227
+ <style lang="scss" scoped>
228
+ @import "../../libs/css/mixin.scss";
229
+
230
+ .hy-rate {
231
+ @include flex;
232
+ align-items: center;
233
+ margin: 0;
234
+ padding: 0;
235
+ /* #ifndef APP-NVUE */
236
+ touch-action: none;
237
+ /* #endif */
238
+
239
+ &__content {
240
+ @include flex;
241
+
242
+ &__item {
243
+ position: relative;
244
+
245
+ &__icon-wrap {
246
+ &--half {
247
+ position: absolute;
248
+ overflow: hidden;
249
+ top: 0;
250
+ left: 0;
251
+ }
252
+ }
253
+ }
254
+ }
255
+ }
256
+ .hy-icon {
257
+ /* #ifndef APP-NVUE */
258
+ box-sizing: border-box;
259
+ /* #endif */
260
+ }
261
+ </style>
@@ -0,0 +1,18 @@
1
+ import { ColorConfig, IconConfig } from "../../config";
2
+
3
+ const defaultProps = {
4
+ modelValue: 1,
5
+ count: 5,
6
+ disabled: false,
7
+ readonly: false,
8
+ size: 18,
9
+ inactiveColor: "#b2b2b2",
10
+ activeColor: ColorConfig.primary,
11
+ gutter: 4,
12
+ minCount: 1,
13
+ allowHalf: false,
14
+ activeIcon: IconConfig.STAR_FILL,
15
+ inactiveIcon: IconConfig.STAR,
16
+ touchable: true
17
+ };
18
+ export default defaultProps;
@@ -0,0 +1,60 @@
1
+ import { CSSProperties } from "vue";
2
+
3
+ export default interface IProps {
4
+ /**
5
+ * @description v-model绑定的值
6
+ * */
7
+ modelValue: number;
8
+ /**
9
+ * @description 星星的数量
10
+ * */
11
+ count?: number;
12
+ /**
13
+ * @description 是否禁用
14
+ * */
15
+ disabled?: boolean;
16
+ /**
17
+ * @description 是否只读
18
+ * */
19
+ readonly?: boolean;
20
+ /**
21
+ * @description 星星的大小
22
+ * */
23
+ size?: number | string;
24
+ /**
25
+ * @description 未激活星星的颜色
26
+ * */
27
+ inactiveColor?: string;
28
+ /**
29
+ * @description 激活星星的颜色
30
+ * */
31
+ activeColor?: string;
32
+ /**
33
+ * @description 星星之间的间距
34
+ * */
35
+ gutter?: number;
36
+ /**
37
+ * @description 最小星星数量
38
+ * */
39
+ minCount?: number;
40
+ /**
41
+ * @description 是否允许半星
42
+ * */
43
+ allowHalf?: boolean;
44
+ /**
45
+ * @description 激活状态的图标
46
+ * */
47
+ activeIcon?: string;
48
+ /**
49
+ * @description 未激活状态的图标
50
+ * */
51
+ inactiveIcon?: string;
52
+ /**
53
+ * @description 是否可触摸
54
+ * */
55
+ touchable?: boolean;
56
+ /**
57
+ * @description 自定义样式
58
+ * */
59
+ customStyle?: CSSProperties;
60
+ }
@@ -0,0 +1,134 @@
1
+ <template>
2
+ <view class="hy-read-more">
3
+ <view
4
+ class="hy-read-more__content"
5
+ :style="{
6
+ height:
7
+ isLongContent && status === 'close'
8
+ ? addUnit(showHeight)
9
+ : addUnit(contentHeight),
10
+ textIndent: textIndent
11
+ }"
12
+ >
13
+ <view
14
+ class="hy-read-more__content__inner"
15
+ ref="hy-read-more__content__inner"
16
+ :class="[elId]"
17
+ >
18
+ <slot></slot>
19
+ </view>
20
+ </view>
21
+ <view
22
+ class="hy-read-more__toggle"
23
+ :style="[innerShadowStyle]"
24
+ v-if="isLongContent"
25
+ >
26
+ <slot name="toggle">
27
+ <view class="hy-read-more__toggle__text" @tap="toggleReadMore">
28
+ <text
29
+ :style="{
30
+ color: color,
31
+ fontSize: addUnit(fontSize),
32
+ lineHeight: addUnit(fontSize),
33
+ marginRight: '5px'
34
+ }"
35
+ >{{ status === "close" ? closeText : openText }}</text
36
+ >
37
+ <view class="hy-read-more__toggle__icon">
38
+ <HyIcon
39
+ :color="color"
40
+ :size="fontSize + 2"
41
+ :name="status === 'close' ? IconConfig.DOWN : IconConfig.UP"
42
+ ></HyIcon>
43
+ </view>
44
+ </view>
45
+ </slot>
46
+ </view>
47
+ </view>
48
+ </template>
49
+
50
+ <script setup lang="ts">
51
+ import { computed, CSSProperties, toRefs, ref, onMounted } from "vue";
52
+ import defaultProps from "./props";
53
+ import IProps from "./typing";
54
+ import { addUnit, getRect, guid, sleep } from "../../utils";
55
+ import { IconConfig } from "../../config";
56
+
57
+ // 组件
58
+ import HyIcon from "../hy-icon/hy-icon.vue";
59
+
60
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
61
+ const { shadowStyle, toggle, name, showHeight } = toRefs(props);
62
+ const emit = defineEmits(["close", "open"]);
63
+
64
+ const isLongContent = ref<boolean>(false); // 是否需要隐藏一部分内容
65
+ const status = ref<"close" | "open">("close"); // 当前隐藏与显示的状态,close-收起状态,open-展开状态
66
+ const elId = ref<string>(guid()); // 生成唯一class
67
+ const contentHeight = ref<number>(100); // 内容高度
68
+
69
+ const innerShadowStyle = computed<CSSProperties>(() => {
70
+ if (status.value === "open") return {};
71
+ else return shadowStyle.value;
72
+ });
73
+
74
+ onMounted(() => {
75
+ getContentHeight();
76
+ });
77
+
78
+ /**
79
+ * @description 获取内容的高度
80
+ * */
81
+ const getContentHeight = async () => {
82
+ // 延时一定时间再获取节点
83
+ await sleep(30);
84
+ getRect("." + elId.value).then((res: any) => {
85
+ contentHeight.value = res.height || 0;
86
+ // 判断高度,如果真实内容高度大于占位高度,则显示收起与展开的控制按钮
87
+ if (res.height && res.height > showHeight.value / 2) {
88
+ isLongContent.value = true;
89
+ status.value = "close";
90
+ } else {
91
+ isLongContent.value = false;
92
+ status.value = "close";
93
+ }
94
+ });
95
+ };
96
+ /**
97
+ * @description 展开或者收起
98
+ * */
99
+ const toggleReadMore = () => {
100
+ status.value = status.value === "close" ? "open" : "close";
101
+ // 如果toggle为false,隐藏"收起"部分的内容
102
+ if (!toggle.value) isLongContent.value = false;
103
+ // 发出打开或者收齐的事件
104
+ emit(status.value, name.value);
105
+ };
106
+ </script>
107
+
108
+ <style lang="scss" scoped>
109
+ @import "../../libs/css/mixin.scss";
110
+ @import "../../theme.scss";
111
+
112
+ .hy-read-more {
113
+ &__content {
114
+ overflow: hidden;
115
+ color: $hy-color-paragraph;
116
+ font-size: 15px;
117
+ text-align: left;
118
+ transition: height 0.3s ease;
119
+ }
120
+
121
+ &__toggle {
122
+ @include flex;
123
+ justify-content: center;
124
+ position: relative;
125
+
126
+ &__text {
127
+ @include flex;
128
+ align-items: center;
129
+ justify-content: center;
130
+ margin-top: 5px;
131
+ }
132
+ }
133
+ }
134
+ </style>
@@ -0,0 +1,20 @@
1
+ import IProps from "./typing";
2
+
3
+ const defaultProps: IProps = {
4
+ showHeight: 200,
5
+ toggle: true,
6
+ closeText: "展开阅读全文",
7
+ openText: "收起",
8
+ color: "#2979ff",
9
+ fontSize: 14,
10
+ textIndent: "2em",
11
+ name: "",
12
+ shadowStyle: {
13
+ backgroundImage:
14
+ "linear-gradient(-180deg, rgba(255, 255, 255, 0) 0%, #fff 80%)",
15
+ paddingTop: "100px",
16
+ marginTop: "-100px"
17
+ }
18
+ };
19
+
20
+ export default defaultProps;
@@ -0,0 +1,44 @@
1
+ import { CSSProperties } from "vue";
2
+
3
+ export default interface IProps {
4
+ /**
5
+ * @description 内容超出此高度才会显示展开全文按钮,单位px(默认 400 )
6
+ * */
7
+ showHeight?: number;
8
+ /**
9
+ * @description 展开后是否显示收起按钮(默认 false )
10
+ * */
11
+ toggle?: boolean;
12
+ /**
13
+ * @description 关闭时的提示文字(默认 '展开阅读全文' )
14
+ * */
15
+ closeText?: string;
16
+ /**
17
+ * @description 展开时的提示文字(默认 '收起' )
18
+ * */
19
+ openText?: string;
20
+ /**
21
+ * @description 提示文字的颜色(默认 '#2979ff' )
22
+ * */
23
+ color?: string;
24
+ /**
25
+ * @description 提示文字的大小,单位px (默认 14 )
26
+ * */
27
+ fontSize?: number;
28
+ /**
29
+ * @description 段落首行缩进的字符个数 (默认 '2em' )
30
+ * */
31
+ textIndent?: string;
32
+ /**
33
+ * @description 用于在 open 和 close 事件中当作回调参数返回
34
+ * */
35
+ name?: string;
36
+ /**
37
+ * @description 显示阴影的样式
38
+ * */
39
+ shadowStyle?: CSSProperties;
40
+ /**
41
+ * @description 定义需要用到的外部样式
42
+ * */
43
+ customStyle?: CSSProperties;
44
+ }
@@ -0,0 +1,64 @@
1
+ <template>
2
+ <view
3
+ class="u-safe-bottom"
4
+ :style="[style]"
5
+ :class="[!isNvue && 'u-safe-area-inset-bottom']"
6
+ >
7
+ </view>
8
+ </template>
9
+
10
+ <script>
11
+ import { props } from "./props.js";
12
+ import { mpMixin } from "../../libs/mixin/mpMixin";
13
+ import { mixin } from "../../libs/mixin/mixin";
14
+ import {
15
+ addStyle,
16
+ deepMerge,
17
+ addUnit,
18
+ getWindowInfo
19
+ } from "../../libs/function/index";
20
+ /**
21
+ * SafeBottom 底部安全区
22
+ * @description 这个适配,主要是针对IPhone X等一些底部带指示条的机型,指示条的操作区域与页面底部存在重合,容易导致用户误操作,因此我们需要针对这些机型进行底部安全区适配。
23
+ * @tutorial https://ijry.github.io/uview-plus/components/safeAreaInset.html
24
+ * @property {type} prop_name
25
+ * @property {Object} customStyle 定义需要用到的外部样式
26
+ *
27
+ * @event {Function()}
28
+ * @example <u-status-bar></u-status-bar>
29
+ */
30
+ export default {
31
+ name: "u-safe-bottom",
32
+ mixins: [mpMixin, mixin, props],
33
+ data() {
34
+ return {
35
+ safeAreaBottomHeight: 0,
36
+ isNvue: false
37
+ };
38
+ },
39
+ computed: {
40
+ style() {
41
+ const style = {};
42
+ // #ifdef APP-NVUE || MP-TOUTIAO
43
+ // nvue下,高度使用js计算填充
44
+ style.height = addUnit(getWindowInfo().safeAreaInsets.bottom, "px");
45
+ // #endif
46
+ return deepMerge(style, addStyle(this.customStyle));
47
+ }
48
+ },
49
+ mounted() {
50
+ // #ifdef APP-NVUE
51
+ // 标识为是否nvue
52
+ this.isNvue = true;
53
+ // #endif
54
+ }
55
+ };
56
+ </script>
57
+
58
+ <style lang="scss" scoped>
59
+ .u-safe-bottom {
60
+ /* #ifndef APP-NVUE */
61
+ width: 100%;
62
+ /* #endif */
63
+ }
64
+ </style>