hy-app 0.4.15 → 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 (206) 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/hy-coupon.vue +10 -5
  55. package/components/hy-coupon/index.scss +148 -64
  56. package/components/hy-coupon/props.ts +35 -50
  57. package/components/hy-coupon/typing.d.ts +10 -0
  58. package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
  59. package/components/hy-datetime-picker/props.ts +142 -32
  60. package/components/hy-datetime-picker/typing.d.ts +132 -132
  61. package/components/hy-divider/hy-divider.vue +90 -169
  62. package/components/hy-divider/props.ts +78 -19
  63. package/components/hy-divider/typing.d.ts +60 -60
  64. package/components/hy-dropdown/hy-dropdown.vue +37 -71
  65. package/components/hy-dropdown/props.ts +38 -15
  66. package/components/hy-dropdown/typing.d.ts +44 -44
  67. package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
  68. package/components/hy-dropdown-item/props.ts +19 -8
  69. package/components/hy-empty/hy-empty.vue +75 -129
  70. package/components/hy-empty/props.ts +57 -15
  71. package/components/hy-empty/typing.d.ts +84 -84
  72. package/components/hy-flex/hy-flex.vue +33 -88
  73. package/components/hy-flex/props.ts +58 -0
  74. package/components/hy-flex/typing.d.ts +14 -16
  75. package/components/hy-float-button/hy-float-button.vue +289 -406
  76. package/components/hy-float-button/props.ts +109 -25
  77. package/components/hy-folding-panel/hy-folding-panel.vue +74 -114
  78. package/components/hy-folding-panel/props.ts +42 -0
  79. package/components/hy-folding-panel/typing.d.ts +57 -57
  80. package/components/hy-folding-panel-item/hy-folding-panel-item.vue +139 -231
  81. package/components/hy-folding-panel-item/props.ts +81 -0
  82. package/components/hy-folding-panel-item/typing.d.ts +23 -23
  83. package/components/hy-form/hy-form.vue +172 -212
  84. package/components/hy-form/props.ts +37 -0
  85. package/components/hy-form/typing.d.ts +68 -61
  86. package/components/hy-form-group/typing.d.ts +74 -74
  87. package/components/hy-form-item/hy-form-item.vue +100 -129
  88. package/components/hy-form-item/props.ts +25 -0
  89. package/components/hy-form-item/typing.d.ts +40 -37
  90. package/components/hy-grid/hy-grid.vue +76 -132
  91. package/components/hy-grid/props.ts +58 -16
  92. package/components/hy-grid/typing.d.ts +66 -66
  93. package/components/hy-icon/hy-icon.vue +84 -161
  94. package/components/hy-icon/props.ts +76 -22
  95. package/components/hy-icon/typing.d.ts +83 -82
  96. package/components/hy-image/hy-image.vue +142 -272
  97. package/components/hy-image/props.ts +105 -23
  98. package/components/hy-image/typing.d.ts +84 -87
  99. package/components/hy-input/hy-input.vue +230 -421
  100. package/components/hy-input/props.ts +183 -35
  101. package/components/hy-input/typing.d.ts +169 -169
  102. package/components/hy-line/hy-line.vue +34 -72
  103. package/components/hy-line/props.ts +41 -10
  104. package/components/hy-line/typing.d.ts +29 -29
  105. package/components/hy-line-progress/hy-line-progress.vue +66 -101
  106. package/components/hy-line-progress/props.ts +31 -10
  107. package/components/hy-line-progress/typing.d.ts +29 -29
  108. package/components/hy-list/hy-list.vue +151 -220
  109. package/components/hy-list/props.ts +67 -16
  110. package/components/hy-list/typing.d.ts +52 -52
  111. package/components/hy-loading/hy-loading.vue +63 -119
  112. package/components/hy-loading/props.ts +63 -15
  113. package/components/hy-loading/typing.d.ts +49 -49
  114. package/components/hy-menu/hy-menu.vue +124 -166
  115. package/components/hy-menu/props.ts +42 -10
  116. package/components/hy-menu/typing.d.ts +60 -60
  117. package/components/hy-modal/hy-modal.vue +127 -218
  118. package/components/hy-modal/props.ts +89 -24
  119. package/components/hy-navbar/hy-navbar.vue +104 -177
  120. package/components/hy-navbar/props.ts +76 -22
  121. package/components/hy-navbar/typing.d.ts +81 -81
  122. package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
  123. package/components/hy-notice-bar/props.ts +80 -19
  124. package/components/hy-notice-bar/typing.d.ts +62 -62
  125. package/components/hy-notify/hy-notify.vue +128 -177
  126. package/components/hy-notify/props.ts +49 -12
  127. package/components/hy-notify/typing.d.ts +45 -41
  128. package/components/hy-number-step/hy-number-step.vue +281 -394
  129. package/components/hy-number-step/props.ts +110 -27
  130. package/components/hy-number-step/typing.d.ts +120 -120
  131. package/components/hy-overlay/hy-overlay.vue +39 -66
  132. package/components/hy-overlay/props.ts +31 -8
  133. package/components/hy-pagination/hy-pagination.vue +100 -155
  134. package/components/hy-pagination/props.ts +53 -13
  135. package/components/hy-picker/hy-picker.vue +309 -430
  136. package/components/hy-picker/index.scss +8 -12
  137. package/components/hy-picker/props.ts +110 -26
  138. package/components/hy-popover/hy-popover.vue +190 -252
  139. package/components/hy-popover/props.ts +48 -10
  140. package/components/hy-popup/hy-popup.vue +162 -248
  141. package/components/hy-popup/props.ts +82 -18
  142. package/components/hy-price/hy-price.vue +45 -104
  143. package/components/hy-price/props.ts +52 -12
  144. package/components/hy-price/typing.d.ts +41 -36
  145. package/components/hy-qrcode/hy-qrcode.vue +115 -185
  146. package/components/hy-qrcode/props.ts +68 -18
  147. package/components/hy-qrcode/typing.d.ts +67 -66
  148. package/components/hy-radio/hy-radio.vue +161 -259
  149. package/components/hy-radio/props.ts +95 -25
  150. package/components/hy-radio/typing.d.ts +85 -84
  151. package/components/hy-rate/hy-rate.vue +185 -270
  152. package/components/hy-rate/props.ts +76 -18
  153. package/components/hy-rate/typing.d.ts +61 -60
  154. package/components/hy-read-more/hy-read-more.vue +93 -136
  155. package/components/hy-read-more/props.ts +43 -13
  156. package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
  157. package/components/hy-scroll-list/props.ts +22 -11
  158. package/components/hy-search/hy-search.vue +155 -284
  159. package/components/hy-search/props.ts +130 -25
  160. package/components/hy-signature/hy-signature.vue +491 -635
  161. package/components/hy-signature/props.ts +115 -26
  162. package/components/hy-signature/typing.d.ts +138 -138
  163. package/components/hy-slider/hy-slider.vue +388 -477
  164. package/components/hy-slider/props.ts +75 -19
  165. package/components/hy-steps/hy-steps.vue +212 -279
  166. package/components/hy-steps/props.ts +47 -13
  167. package/components/hy-submit-bar/hy-submit-bar.vue +136 -221
  168. package/components/hy-submit-bar/props.ts +89 -20
  169. package/components/hy-submit-bar/typing.d.ts +87 -87
  170. package/components/hy-subsection/hy-subsection.vue +132 -185
  171. package/components/hy-subsection/props.ts +50 -17
  172. package/components/hy-subsection/typing.d.ts +52 -52
  173. package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
  174. package/components/hy-swipe-action/props.ts +43 -18
  175. package/components/hy-swipe-action/typing.d.ts +46 -46
  176. package/components/hy-swiper/hy-swiper.vue +159 -286
  177. package/components/hy-swiper/props.ts +126 -28
  178. package/components/hy-swiper/typing.d.ts +115 -115
  179. package/components/hy-switch/hy-switch.vue +112 -176
  180. package/components/hy-switch/props.ts +60 -15
  181. package/components/hy-switch/typing.d.ts +63 -63
  182. package/components/hy-tabBar/hy-tabBar.vue +64 -60
  183. package/components/hy-tabs/hy-tabs.vue +277 -380
  184. package/components/hy-tabs/props.ts +75 -18
  185. package/components/hy-tag/hy-tag.vue +111 -204
  186. package/components/hy-tag/props.ts +81 -19
  187. package/components/hy-text/hy-text.vue +200 -322
  188. package/components/hy-text/props.ts +107 -28
  189. package/components/hy-textarea/hy-textarea.vue +147 -256
  190. package/components/hy-textarea/props.ts +112 -25
  191. package/components/hy-textarea/typing.d.ts +42 -42
  192. package/components/hy-toast/hy-toast.vue +135 -143
  193. package/components/hy-tooltip/hy-tooltip.vue +220 -306
  194. package/components/hy-tooltip/props.ts +79 -15
  195. package/components/hy-transition/hy-transition.vue +111 -138
  196. package/components/hy-transition/props.ts +30 -8
  197. package/components/hy-upload/hy-upload.vue +320 -469
  198. package/components/hy-upload/props.ts +130 -27
  199. package/components/hy-warn/hy-warn.vue +80 -129
  200. package/components/hy-warn/props.ts +47 -12
  201. package/components/hy-waterfall/hy-waterfall.vue +139 -163
  202. package/components/hy-waterfall/props.ts +19 -7
  203. package/components/hy-watermark/hy-watermark.vue +762 -870
  204. package/components/hy-watermark/props.ts +103 -22
  205. package/package.json +2 -2
  206. package/web-types.json +1 -1
@@ -1,496 +1,379 @@
1
1
  <template>
2
- <view
3
- :style="FloatButtonStyle"
4
- :id="soleId"
5
- :class="[
6
- 'hy-float-button',
7
- {
8
- 'hy-float-button__animation': float,
9
- 'hy-float-button__shadow': shadow,
10
- },
11
- `hy-float-button--${shape}`,
12
- customClass,
13
- ]"
14
- @touchmove.stop.prevent="handleTouchMove"
15
- @touchstart="handleTouchStart"
16
- @touchend="handleTouchEnd"
17
- >
18
2
  <view
19
- :class="['hy-float-button__container']"
20
- @tap.stop="handleClick"
21
- :style="{ backgroundColor: bgColor }"
3
+ :style="FloatButtonStyle"
4
+ :id="soleId"
5
+ :class="[
6
+ 'hy-float-button',
7
+ {
8
+ 'hy-float-button__animation': float,
9
+ 'hy-float-button__shadow': shadow
10
+ },
11
+ `hy-float-button--${shape}`,
12
+ customClass
13
+ ]"
14
+ @touchmove.stop.prevent="handleTouchMove"
15
+ @touchstart="handleTouchStart"
16
+ @touchend="handleTouchEnd"
22
17
  >
23
- <slot>
24
- <HyIcon
25
- :name="icon"
26
- :color="iconColor"
27
- :size="iconSize ? iconSize : addUnit(getPx(getFloatBtnSize) * 0.7)"
28
- />
29
- <text v-if="text" :style="{ color: textColor, fontSize: fontSize }">{{
30
- text
31
- }}</text>
32
- </slot>
33
- </view>
18
+ <view
19
+ :class="['hy-float-button__container']"
20
+ @tap.stop="handleClick"
21
+ :style="{ backgroundColor: bgColor }"
22
+ >
23
+ <slot v-if="$slots.default"></slot>
24
+ <template v-else>
25
+ <hy-icon
26
+ :name="icon"
27
+ :color="iconColor"
28
+ :size="iconSize ? iconSize : addUnit(getPx(getFloatBtnSize) * 0.7)"
29
+ />
30
+ <text v-if="text" :style="{ color: textColor, fontSize: fontSize }">{{
31
+ text
32
+ }}</text>
33
+ </template>
34
+ </view>
34
35
 
35
- <!-- 菜单栏 -->
36
- <view
37
- :class="['hy-float-button__menus', `hy-float-button__menus--${shape}`]"
38
- :style="menusStyle"
39
- >
40
- <template v-for="(item, i) in menus" :key="i">
36
+ <!-- 菜单栏 -->
41
37
  <view
42
- class="hy-float-button__menus--item"
43
- :style="{
44
- width: getFloatBtnSize,
45
- height: getFloatBtnSize,
46
- color: textColor,
47
- }"
48
- @click="handleMenuItemClick(item, i)"
38
+ :class="['hy-float-button__menus', `hy-float-button__menus--${shape}`]"
39
+ :style="menusStyle"
49
40
  >
50
- {{ typeof item === "string" ? item : item.label }}
41
+ <template v-for="(item, i) in menus" :key="i">
42
+ <view
43
+ class="hy-float-button__menus--item"
44
+ :style="{
45
+ width: getFloatBtnSize,
46
+ height: getFloatBtnSize,
47
+ color: textColor
48
+ }"
49
+ @click="handleMenuItemClick(item, i)"
50
+ >
51
+ {{ typeof item === 'string' ? item : item.label }}
52
+ </view>
53
+ <hy-line
54
+ v-if="i !== menus.length - 1"
55
+ color="#FFFFFF"
56
+ :length="addUnit(getPx(getFloatBtnSize) * 0.7)"
57
+ :direction="direction === 'row' ? 'column' : 'row'"
58
+ :custom-style="{ margin: 'auto' }"
59
+ ></hy-line>
60
+ </template>
51
61
  </view>
52
- <HyLine
53
- v-if="i !== menus.length - 1"
54
- color="#FFFFFF"
55
- :length="addUnit(getPx(getFloatBtnSize) * 0.7)"
56
- :direction="direction === 'row' ? 'column' : 'row'"
57
- :custom-style="{ margin: 'auto' }"
58
- ></HyLine>
59
- </template>
62
+ <!-- 菜单栏 -->
60
63
  </view>
61
- <!-- 菜单栏 -->
62
- </view>
63
64
  </template>
64
65
 
65
66
  <script lang="ts">
66
67
  export default {
67
- name: "hy-float-button",
68
- options: {
69
- addGlobalClass: true,
70
- virtualHost: true,
71
- styleIsolation: "shared",
72
- },
73
- };
68
+ name: 'hy-float-button',
69
+ options: {
70
+ addGlobalClass: true,
71
+ virtualHost: true,
72
+ styleIsolation: 'shared'
73
+ }
74
+ }
74
75
  </script>
75
76
 
76
77
  <script lang="ts" setup>
77
- import {
78
- computed,
79
- getCurrentInstance,
80
- onMounted,
81
- ref,
82
- reactive,
83
- watch,
84
- } from "vue";
85
- import type { CSSProperties, PropType } from "vue";
86
- import type { IFloatButtonEmits, IGap } from "./typing";
87
- import type { MenusType } from "./typing";
88
- import { addUnit, getPx, getRect, guid, isH5, IconConfig } from "../../libs";
78
+ import { computed, getCurrentInstance, onMounted, ref, reactive, watch } from 'vue'
79
+ import type { CSSProperties } from 'vue'
80
+ import type { IFloatButtonEmits } from './typing'
81
+ import type { MenusType } from './typing'
82
+ import { addUnit, getPx, getRect, guid, isH5 } from '../../libs'
83
+ import floatButtonProps from './props'
89
84
  // 组件
90
- import HyIcon from "../hy-icon/hy-icon.vue";
91
- import HyLine from "../hy-line/hy-line.vue";
85
+ import HyIcon from '../hy-icon/hy-icon.vue'
86
+ import HyLine from '../hy-line/hy-line.vue'
92
87
 
93
88
  /**
94
89
  * 悬浮动作按钮组件,按下可显示一组动作按钮。
95
90
  * @displayName hy-float-button
96
91
  */
97
- defineOptions({});
92
+ defineOptions({})
98
93
 
99
- // const props = withDefaults(defineProps<IProps>(), defaultProps)
100
- const props = defineProps({
101
- /** 菜单栏集合 */
102
- menus: {
103
- type: Array as unknown as PropType<MenusType[]>,
104
- default: [],
105
- },
106
- /**
107
- * 打开方向
108
- * @values row,column
109
- * */
110
- direction: {
111
- type: String,
112
- default: "column",
113
- },
114
- /** 按钮显示的图标 */
115
- icon: {
116
- type: String,
117
- default: IconConfig.PLUS,
118
- },
119
- /** 按钮图标大小 */
120
- iconSize: String,
121
- /** 按钮图标颜色 */
122
- iconColor: String,
123
- /** 到边框最小距离 */
124
- gap: {
125
- type: Object as unknown as PropType<IGap>,
126
- default: { left: 16, right: 16, top: 16, bottom: 40 },
127
- },
128
- /** 层级 */
129
- zIndex: {
130
- type: Number,
131
- default: 10086,
132
- },
133
- /** 按钮背景颜色 */
134
- bgColor: String,
135
- /** 按钮文字 */
136
- text: String,
137
- /** 按钮文字大小 */
138
- fontSize: {
139
- type: [Number, String],
140
- default: 12,
141
- },
142
- /** 按钮文字的颜色 */
143
- textColor: String,
144
- /**
145
- * 按钮的尺寸
146
- * @values small,medium,large
147
- * */
148
- size: {
149
- type: [String, Number] as PropType<string | number>,
150
- default: "medium",
151
- },
152
- /**
153
- * 按钮的形状
154
- * @values circle,square
155
- * */
156
- shape: {
157
- type: String,
158
- default: "circle",
159
- },
160
- /** 按钮的透明度 */
161
- opacity: {
162
- type: Number,
163
- default: 1,
164
- },
165
- /** 是否显示阴影 */
166
- shadow: {
167
- type: Boolean,
168
- default: true,
169
- },
170
- /** 是否显示漂浮的动画 */
171
- float: {
172
- type: Boolean,
173
- default: true,
174
- },
175
- /** 是否固定位置 */
176
- fixed: {
177
- type: Boolean,
178
- default: true,
179
- },
180
- /** 是否能拖动 */
181
- draggable: {
182
- type: Boolean,
183
- default: true,
184
- },
185
- /**
186
- * 悬浮按钮位置
187
- * @values left-top,left-bottom,right-top,right-bottom,left-center,right-center,top-center,bottom-center
188
- * */
189
- position: {
190
- type: String,
191
- default: "right-bottom",
192
- },
193
- /** 禁用点击打开菜单栏 */
194
- expandable: {
195
- type: Boolean,
196
- default: true,
197
- },
198
- /** 定义需要用到的外部样式 */
199
- customStyle: {
200
- type: Object as PropType<CSSProperties>,
201
- },
202
- /** 自定义外部类名 */
203
- customClass: String,
204
- });
205
- const emit = defineEmits<IFloatButtonEmits>();
94
+ const props = defineProps(floatButtonProps)
95
+ const emit = defineEmits<IFloatButtonEmits>()
206
96
 
207
- const instance = getCurrentInstance();
97
+ const instance = getCurrentInstance()
208
98
  const btnSize: AnyObject = {
209
- small: "50px",
210
- medium: "60px",
211
- large: "70px",
212
- };
213
- const open = ref(false);
214
- const rotate = computed(() => (open.value && !props.text ? "45deg" : "0deg"));
215
- const soleId = `hy-float-button__${guid()}`;
216
- const fabSize = reactive({ width: 0, height: 0 }); // 悬浮按钮大小
217
- const screen = reactive({ width: 0, height: 0 });
99
+ small: '50px',
100
+ medium: '60px',
101
+ large: '70px'
102
+ }
103
+ const open = ref(false)
104
+ const rotate = computed(() => (open.value && !props.text ? '45deg' : '0deg'))
105
+ const soleId = `hy-float-button__${guid()}`
106
+ const fabSize = reactive({ width: 0, height: 0 }) // 悬浮按钮大小
107
+ const screen = reactive({ width: 0, height: 0 })
218
108
  const currentCoordinate = reactive({
219
- top: 0,
220
- left: 0,
221
- });
109
+ top: 0,
110
+ left: 0
111
+ })
222
112
  // 按下时坐标相对于元素的偏移量
223
- const touchOffset = reactive({ x: 0, y: 0 });
224
- const attractTransition = ref<boolean>(false);
225
- const fabDirection = ref<HyApp.LeftRightType>("left");
226
- const fabDirection2 = ref<HyApp.TopBottomType>("top");
113
+ const touchOffset = reactive({ x: 0, y: 0 })
114
+ const attractTransition = ref<boolean>(false)
115
+ const fabDirection = ref<HyApp.LeftRightType>('left')
116
+ const fabDirection2 = ref<HyApp.TopBottomType>('top')
227
117
  const bounding = reactive({
228
- minLeft: 10,
229
- minTop: 10,
230
- maxLeft: 380,
231
- maxTop: 680,
232
- });
118
+ minLeft: 10,
119
+ minTop: 10,
120
+ maxLeft: 380,
121
+ maxTop: 680
122
+ })
233
123
 
234
124
  onMounted(async () => {
235
- await getFatRect();
236
- await getBounding();
237
- initPosition();
238
- });
125
+ await getFatRect()
126
+ await getBounding()
127
+ initPosition()
128
+ })
239
129
 
240
130
  watch(
241
- () => props.position,
242
- () => initPosition(),
243
- );
131
+ () => props.position,
132
+ () => initPosition()
133
+ )
244
134
 
245
135
  /**
246
136
  * @description 初始化距离
247
137
  * */
248
138
  const initPosition = () => {
249
- const { minLeft, minTop, maxLeft, maxTop } = bounding;
250
- const centerY = (maxTop + minTop) / 2;
251
- const centerX = (maxLeft + minLeft) / 2;
139
+ const { minLeft, minTop, maxLeft, maxTop } = bounding
140
+ const centerY = (maxTop + minTop) / 2
141
+ const centerX = (maxLeft + minLeft) / 2
252
142
 
253
- switch (props.position) {
254
- case "left-top":
255
- currentCoordinate.top = minTop;
256
- currentCoordinate.left = minLeft;
257
- fabDirection.value = "left";
258
- fabDirection2.value = "top";
259
- break;
260
- case "right-top":
261
- currentCoordinate.top = minTop;
262
- currentCoordinate.left = maxLeft;
263
- fabDirection.value = "right";
264
- fabDirection2.value = "top";
265
- break;
266
- case "left-bottom":
267
- currentCoordinate.top = maxTop;
268
- currentCoordinate.left = minLeft;
269
- fabDirection.value = "left";
270
- fabDirection2.value = "bottom";
271
- break;
272
- case "right-bottom":
273
- currentCoordinate.top = maxTop;
274
- currentCoordinate.left = maxLeft;
275
- fabDirection.value = "right";
276
- fabDirection2.value = "bottom";
277
- break;
278
- case "left-center":
279
- currentCoordinate.top = centerY;
280
- currentCoordinate.left = minLeft;
281
- fabDirection.value = "left";
282
- fabDirection2.value = "bottom";
283
- break;
284
- case "right-center":
285
- currentCoordinate.top = centerY;
286
- currentCoordinate.left = maxLeft;
287
- fabDirection.value = "right";
288
- fabDirection2.value = "bottom";
289
- break;
290
- case "top-center":
291
- currentCoordinate.top = minTop;
292
- currentCoordinate.left = centerX;
293
- fabDirection.value = "left";
294
- fabDirection2.value = "top";
295
- break;
296
- case "bottom-center":
297
- currentCoordinate.top = maxTop;
298
- currentCoordinate.left = centerX;
299
- fabDirection.value = "left";
300
- fabDirection2.value = "bottom";
301
- break;
302
- }
303
- };
143
+ switch (props.position) {
144
+ case 'left-top':
145
+ currentCoordinate.top = minTop
146
+ currentCoordinate.left = minLeft
147
+ fabDirection.value = 'left'
148
+ fabDirection2.value = 'top'
149
+ break
150
+ case 'right-top':
151
+ currentCoordinate.top = minTop
152
+ currentCoordinate.left = maxLeft
153
+ fabDirection.value = 'right'
154
+ fabDirection2.value = 'top'
155
+ break
156
+ case 'left-bottom':
157
+ currentCoordinate.top = maxTop
158
+ currentCoordinate.left = minLeft
159
+ fabDirection.value = 'left'
160
+ fabDirection2.value = 'bottom'
161
+ break
162
+ case 'right-bottom':
163
+ currentCoordinate.top = maxTop
164
+ currentCoordinate.left = maxLeft
165
+ fabDirection.value = 'right'
166
+ fabDirection2.value = 'bottom'
167
+ break
168
+ case 'left-center':
169
+ currentCoordinate.top = centerY
170
+ currentCoordinate.left = minLeft
171
+ fabDirection.value = 'left'
172
+ fabDirection2.value = 'bottom'
173
+ break
174
+ case 'right-center':
175
+ currentCoordinate.top = centerY
176
+ currentCoordinate.left = maxLeft
177
+ fabDirection.value = 'right'
178
+ fabDirection2.value = 'bottom'
179
+ break
180
+ case 'top-center':
181
+ currentCoordinate.top = minTop
182
+ currentCoordinate.left = centerX
183
+ fabDirection.value = 'left'
184
+ fabDirection2.value = 'top'
185
+ break
186
+ case 'bottom-center':
187
+ currentCoordinate.top = maxTop
188
+ currentCoordinate.left = centerX
189
+ fabDirection.value = 'left'
190
+ fabDirection2.value = 'bottom'
191
+ break
192
+ }
193
+ }
304
194
 
305
195
  /**
306
196
  * @description 获取组件大小
307
197
  * */
308
198
  const getFloatBtnSize = computed(() => {
309
- if (
310
- typeof props.size === "string" &&
311
- Object.keys(btnSize).includes(props.size)
312
- ) {
313
- return btnSize[props.size];
314
- } else {
315
- return addUnit(props.size);
316
- }
317
- });
199
+ if (typeof props.size === 'string' && Object.keys(btnSize).includes(props.size)) {
200
+ return btnSize[props.size]
201
+ } else {
202
+ return addUnit(props.size)
203
+ }
204
+ })
318
205
 
319
206
  /**
320
207
  * @description 悬浮按钮样式
321
208
  * */
322
209
  const FloatButtonStyle = computed(() => {
323
- const style: CSSProperties = {
324
- top: currentCoordinate.top + "px",
325
- left: currentCoordinate.left + "px",
326
- backgroundColor: props.bgColor,
327
- zIndex: props.zIndex,
328
- color: props.textColor,
329
- transition: "all ease 0.3s",
330
- };
331
- if (props.fixed) style.position = "fixed";
210
+ const style: CSSProperties = {
211
+ top: currentCoordinate.top + 'px',
212
+ left: currentCoordinate.left + 'px',
213
+ backgroundColor: props.bgColor,
214
+ zIndex: props.zIndex,
215
+ color: props.textColor,
216
+ transition: 'all ease 0.3s'
217
+ }
218
+ if (props.fixed) style.position = 'fixed'
332
219
 
333
- style.height = getFloatBtnSize.value;
334
- style.width = getFloatBtnSize.value;
335
- return Object.assign(style, props.customStyle);
336
- });
220
+ style.height = getFloatBtnSize.value
221
+ style.width = getFloatBtnSize.value
222
+ return Object.assign(style, props.customStyle)
223
+ })
337
224
  const menusStyle = computed(() => {
338
- const style: CSSProperties = {
339
- backgroundColor: props.bgColor,
340
- };
341
-
342
- // 判断横向展示还是纵向展示
343
- if (props.direction === "row") {
344
- if (fabDirection.value === "right") {
345
- style.transform = "translateX(-100%)";
346
- style.left = "100%";
347
- style.paddingRight = getFloatBtnSize.value;
348
- style.flexDirection = "row-reverse";
349
- } else {
350
- style.paddingLeft = getFloatBtnSize.value;
225
+ const style: CSSProperties = {
226
+ backgroundColor: props.bgColor
351
227
  }
352
- style.bottom = 0;
353
- style.transition = "width 0.5s ease";
354
- style.height = getFloatBtnSize.value;
355
- style.width = open.value
356
- ? addUnit(
357
- getPx(getFloatBtnSize.value) * props.menus.length +
358
- getPx(getFloatBtnSize.value),
359
- )
360
- : 0;
361
- } else {
362
- if (fabDirection2.value === "top") {
363
- style.transform = "translateX(-100%)";
364
- style.height = "100%";
365
- style.left = getFloatBtnSize.value;
366
- style.top = "0px";
367
- style.paddingTop = getFloatBtnSize.value;
228
+
229
+ // 判断横向展示还是纵向展示
230
+ if (props.direction === 'row') {
231
+ if (fabDirection.value === 'right') {
232
+ style.transform = 'translateX(-100%)'
233
+ style.left = '100%'
234
+ style.paddingRight = getFloatBtnSize.value
235
+ style.flexDirection = 'row-reverse'
236
+ } else {
237
+ style.paddingLeft = getFloatBtnSize.value
238
+ }
239
+ style.bottom = 0
240
+ style.transition = 'width 0.5s ease'
241
+ style.height = getFloatBtnSize.value
242
+ style.width = open.value
243
+ ? addUnit(
244
+ getPx(getFloatBtnSize.value) * props.menus.length + getPx(getFloatBtnSize.value)
245
+ )
246
+ : 0
368
247
  } else {
369
- style.paddingBottom = getFloatBtnSize.value;
370
- style.bottom = 0;
248
+ if (fabDirection2.value === 'top') {
249
+ style.transform = 'translateX(-100%)'
250
+ style.height = '100%'
251
+ style.left = getFloatBtnSize.value
252
+ style.top = '0px'
253
+ style.paddingTop = getFloatBtnSize.value
254
+ } else {
255
+ style.paddingBottom = getFloatBtnSize.value
256
+ style.bottom = 0
257
+ }
258
+ style.transition = 'height 0.5s ease'
259
+ style.width = getFloatBtnSize.value
260
+ style.height = open.value
261
+ ? addUnit(
262
+ getPx(getFloatBtnSize.value) * props.menus.length + getPx(getFloatBtnSize.value)
263
+ )
264
+ : 0
371
265
  }
372
- style.transition = "height 0.5s ease";
373
- style.width = getFloatBtnSize.value;
374
- style.height = open.value
375
- ? addUnit(
376
- getPx(getFloatBtnSize.value) * props.menus.length +
377
- getPx(getFloatBtnSize.value),
378
- )
379
- : 0;
380
- }
381
- return style;
382
- });
266
+ return style
267
+ })
383
268
 
384
269
  /**
385
270
  * @description 获取悬浮按钮大小
386
271
  * */
387
272
  const getFatRect = () => {
388
- return new Promise((resolve, reject) => {
389
- getRect(`#${soleId}`, false, instance)
390
- .then((rect) => {
391
- const { width, height } = rect as UniApp.NodeInfo;
392
- fabSize.width = width as number;
393
- fabSize.height = height as number;
394
- resolve(rect);
395
- })
396
- .catch((err) => {
397
- reject(err);
398
- });
399
- });
400
- };
273
+ return new Promise((resolve, reject) => {
274
+ getRect(`#${soleId}`, false, instance)
275
+ .then((rect) => {
276
+ const { width, height } = rect as UniApp.NodeInfo
277
+ fabSize.width = width as number
278
+ fabSize.height = height as number
279
+ resolve(rect)
280
+ })
281
+ .catch((err) => {
282
+ reject(err)
283
+ })
284
+ })
285
+ }
401
286
 
402
287
  /**
403
288
  * @description 点击悬浮按钮
404
289
  * */
405
290
  const handleClick = () => {
406
- emit("click");
407
- if (props.expandable) {
408
- open.value = !open.value;
409
- }
410
- };
291
+ emit('click')
292
+ if (props.expandable) {
293
+ open.value = !open.value
294
+ }
295
+ }
411
296
 
412
297
  /**
413
298
  * @description 点击单条菜单栏
414
299
  * */
415
300
  const handleMenuItemClick = (temp: MenusType, index: number) => {
416
- emit("clickItem", temp, index);
417
- open.value = false;
418
- if (typeof temp !== "string" && temp?.url) {
419
- uni.navigateTo({
420
- url: temp.url,
421
- });
422
- }
423
- };
301
+ emit('clickItem', temp, index)
302
+ open.value = false
303
+ if (typeof temp !== 'string' && temp?.url) {
304
+ uni.navigateTo({
305
+ url: temp.url
306
+ })
307
+ }
308
+ }
424
309
 
425
310
  const getBounding = () => {
426
- return new Promise((resolve) => {
427
- const sysInfo = uni.getSystemInfoSync();
311
+ return new Promise((resolve) => {
312
+ const sysInfo = uni.getSystemInfoSync()
428
313
 
429
- const { top = 16, left = 16, right = 16, bottom = 16 } = props.gap;
430
- screen.width = sysInfo.windowWidth;
431
- screen.height = isH5
432
- ? sysInfo.windowTop + sysInfo.windowHeight
433
- : sysInfo.windowHeight;
434
- bounding.minTop = isH5 ? sysInfo.windowTop + top : top;
435
- bounding.minLeft = left;
436
- bounding.maxLeft = screen.width - fabSize.width - right;
437
- bounding.maxTop = screen.height - fabSize.height - bottom;
438
- resolve(bounding);
439
- });
440
- };
314
+ const { top = 16, left = 16, right = 16, bottom = 16 } = props.gap
315
+ screen.width = sysInfo.windowWidth
316
+ screen.height = isH5 ? sysInfo.windowTop + sysInfo.windowHeight : sysInfo.windowHeight
317
+ bounding.minTop = isH5 ? sysInfo.windowTop + top : top
318
+ bounding.minLeft = left
319
+ bounding.maxLeft = screen.width - fabSize.width - right
320
+ bounding.maxTop = screen.height - fabSize.height - bottom
321
+ resolve(bounding)
322
+ })
323
+ }
441
324
 
442
325
  const handleTouchStart = (e: TouchEvent) => {
443
- if (!props.draggable) return;
326
+ if (!props.draggable) return
444
327
 
445
- const touch = e.touches[0];
446
- touchOffset.x = touch.clientX - getPx(currentCoordinate.left);
447
- touchOffset.y = touch.clientY - getPx(currentCoordinate.top);
448
- attractTransition.value = false;
449
- };
328
+ const touch = e.touches[0]
329
+ touchOffset.x = touch.clientX - getPx(currentCoordinate.left)
330
+ touchOffset.y = touch.clientY - getPx(currentCoordinate.top)
331
+ attractTransition.value = false
332
+ }
450
333
 
451
334
  function handleTouchMove(e: TouchEvent) {
452
- if (!props.draggable) return;
335
+ if (!props.draggable) return
453
336
 
454
- const touch = e.touches[0];
455
- const { minLeft, minTop, maxLeft, maxTop } = bounding;
456
- let x = touch.clientX - touchOffset.x;
457
- let y = touch.clientY - touchOffset.y;
337
+ const touch = e.touches[0]
338
+ const { minLeft, minTop, maxLeft, maxTop } = bounding
339
+ let x = touch.clientX - touchOffset.x
340
+ let y = touch.clientY - touchOffset.y
458
341
 
459
- if (x < minLeft) x = minLeft;
460
- else if (x > maxLeft) x = maxLeft;
342
+ if (x < minLeft) x = minLeft
343
+ else if (x > maxLeft) x = maxLeft
461
344
 
462
- if (y < minTop) y = minTop;
463
- else if (y > maxTop) y = maxTop;
345
+ if (y < minTop) y = minTop
346
+ else if (y > maxTop) y = maxTop
464
347
 
465
- currentCoordinate.top = y;
466
- currentCoordinate.left = x;
348
+ currentCoordinate.top = y
349
+ currentCoordinate.left = x
467
350
  }
468
351
 
469
352
  function handleTouchEnd() {
470
- if (!props.draggable) return;
353
+ if (!props.draggable) return
471
354
 
472
- const screenCenterX = screen.width / 2;
473
- const fabCenterX = currentCoordinate.left + fabSize.width / 2;
474
- attractTransition.value = true;
475
- if (fabCenterX < screenCenterX) {
476
- currentCoordinate.left = bounding.minLeft;
477
- fabDirection.value = "left";
478
- } else {
479
- currentCoordinate.left = bounding.maxLeft;
480
- fabDirection.value = "right";
481
- }
355
+ const screenCenterX = screen.width / 2
356
+ const fabCenterX = currentCoordinate.left + fabSize.width / 2
357
+ attractTransition.value = true
358
+ if (fabCenterX < screenCenterX) {
359
+ currentCoordinate.left = bounding.minLeft
360
+ fabDirection.value = 'left'
361
+ } else {
362
+ currentCoordinate.left = bounding.maxLeft
363
+ fabDirection.value = 'right'
364
+ }
482
365
  }
483
366
  </script>
484
367
 
485
368
  <style scoped lang="scss">
486
- @import "./index.scss";
369
+ @import './index.scss';
487
370
  .hy-float-button {
488
- &__container {
489
- rotate: v-bind(rotate);
490
- }
491
- &__menus {
492
- display: flex;
493
- flex-direction: v-bind(direction);
494
- }
371
+ &__container {
372
+ rotate: v-bind(rotate);
373
+ }
374
+ &__menus {
375
+ display: flex;
376
+ flex-direction: v-bind(direction);
377
+ }
495
378
  }
496
379
  </style>