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,205 +1,152 @@
1
1
  <template>
2
- <!--注意阻止横向滑动的穿透:横向移动时阻止冒泡-->
3
- <view
4
- class="hy-swipe-action"
5
- @click.stop="onClick"
6
- @touchstart="startDrag"
7
- @touchmove="onDrag"
8
- @touchend="endDrag"
9
- @touchcancel="endDrag"
10
- >
11
- <!--容器-->
12
- <view class="hy-swipe-action__wrapper" :style="wrapperStyle">
13
- <!--左侧操作-->
14
- <view
15
- :class="['hy-swipe-action__left', leftClass]"
16
- @click="onClick('left')"
17
- >
18
- <slot name="left" />
19
- </view>
20
- <!--左侧操作-->
2
+ <!--注意阻止横向滑动的穿透:横向移动时阻止冒泡-->
3
+ <view
4
+ class="hy-swipe-action"
5
+ @click.stop="onClick"
6
+ @touchstart="startDrag"
7
+ @touchmove="onDrag"
8
+ @touchend="endDrag"
9
+ @touchcancel="endDrag"
10
+ >
11
+ <!--容器-->
12
+ <view class="hy-swipe-action__wrapper" :style="wrapperStyle">
13
+ <!--左侧操作-->
14
+ <view :class="['hy-swipe-action__left', leftClass]" @click="onClick('left')">
15
+ <slot name="left" />
16
+ </view>
17
+ <!--左侧操作-->
21
18
 
22
- <!--内容-->
23
- <view
24
- :class="[
25
- 'hy-swipe-action__center',
26
- borderBottom && 'hy-border__bottom',
27
- ]"
28
- >
29
- <slot></slot>
30
- </view>
31
- <!--内容-->
19
+ <!--内容-->
20
+ <view :class="['hy-swipe-action__center', borderBottom && 'hy-border__bottom']">
21
+ <slot></slot>
22
+ </view>
23
+ <!--内容-->
32
24
 
33
- <!--右侧操作-->
34
- <view
35
- :class="['hy-swipe-action__right', rightClass]"
36
- @click="onClick('right')"
37
- >
38
- <slot name="right">
39
- <view v-if="!slots.left" class="hy-swipe-action__right--action">
40
- <view
41
- class="hy-swipe-action__right--action__btn"
42
- v-for="(item, i) in options"
43
- :style="item.style"
44
- @tap.stop="onActiveClick(item, i)"
45
- >
46
- {{ item.text }}
25
+ <!--右侧操作-->
26
+ <view :class="['hy-swipe-action__right', rightClass]" @click="onClick('right')">
27
+ <slot name="right">
28
+ <view v-if="!slots.left" class="hy-swipe-action__right--action">
29
+ <view
30
+ class="hy-swipe-action__right--action__btn"
31
+ v-for="(item, i) in options"
32
+ :style="item.style"
33
+ @tap.stop="onActiveClick(item, i)"
34
+ >
35
+ {{ item.text }}
36
+ </view>
37
+ </view>
38
+ </slot>
47
39
  </view>
48
- </view>
49
- </slot>
50
- </view>
51
- <!--右侧操作-->
40
+ <!--右侧操作-->
41
+ </view>
52
42
  </view>
53
- </view>
54
43
  </template>
55
44
 
56
45
  <script lang="ts">
57
46
  export default {
58
- name: "hy-swipe-action",
59
- options: {
60
- addGlobalClass: true,
61
- virtualHost: true,
62
- styleIsolation: "shared",
63
- },
64
- };
47
+ name: 'hy-swipe-action',
48
+ options: {
49
+ addGlobalClass: true,
50
+ virtualHost: true,
51
+ styleIsolation: 'shared'
52
+ }
53
+ }
65
54
  </script>
66
55
  <script lang="ts" setup>
67
56
  import {
68
- getCurrentInstance,
69
- onBeforeMount,
70
- onBeforeUnmount,
71
- onMounted,
72
- ref,
73
- watch,
74
- useSlots,
75
- } from "vue";
76
- import type { PropType } from "vue";
57
+ getCurrentInstance,
58
+ onBeforeMount,
59
+ onBeforeUnmount,
60
+ onMounted,
61
+ ref,
62
+ watch,
63
+ useSlots
64
+ } from 'vue'
65
+ import type { PropType } from 'vue'
77
66
  import type {
78
- ISwipeActionEmits,
79
- SwipeActionStatus,
80
- SwipeActionPosition,
81
- SwipeActionReason,
82
- SwipeActionOptionsVo,
83
- } from "./typing";
84
- import { useTouch, getRect, guid } from "../../libs";
85
- import { closeOther, pushToQueue, removeFromQueue } from "./index";
67
+ ISwipeActionEmits,
68
+ SwipeActionStatus,
69
+ SwipeActionPosition,
70
+ SwipeActionReason
71
+ } from './typing'
72
+ import { useTouch, getRect, guid } from '../../libs'
73
+ import { closeOther, pushToQueue, removeFromQueue } from './index'
74
+ import swipeActionProps from './props'
86
75
 
87
76
  /**
88
77
  * 常用于单元格左右滑删除等手势操作。
89
78
  * @displayName hy-swipe-action
90
79
  */
91
- defineOptions({});
80
+ defineOptions({})
92
81
 
93
- // const props = withDefaults(defineProps<IProps>(), defaultProps)
94
- const props = defineProps({
95
- /**
96
- * 滑动按钮的状态,使用v-model进行双向绑定。
97
- * @values left,close,right
98
- * */
99
- modelValue: String as PropType<SwipeActionStatus>,
100
- /** 是否禁用滑动操作 */
101
- disabled: {
102
- type: Boolean,
103
- default: false,
104
- },
105
- /** 显示底部边框 */
106
- borderBottom: {
107
- type: Boolean,
108
- default: false,
109
- },
110
- /** 右侧按钮内容 */
111
- options: {
112
- type: Array as unknown as PropType<SwipeActionOptionsVo[]>,
113
- default: () => [
114
- {
115
- text: "收藏",
116
- style: {
117
- backgroundColor: "#3c9cff",
118
- },
119
- },
120
- {
121
- text: "删除",
122
- style: {
123
- backgroundColor: "#f56c6c",
124
- },
125
- },
126
- ],
127
- },
128
- /** 动画过渡时间,单位ms */
129
- duration: {
130
- type: Number,
131
- default: 300,
132
- },
133
- /** 关闭滑动按钮前的钩子函数 */
134
- beforeClose: Function,
135
- });
136
- const emit = defineEmits<ISwipeActionEmits>();
137
- const leftClass = `hy-swipe-action__left--${guid()}`;
138
- const rightClass = `hy-swipe-action__right--${guid()}`;
82
+ const props = defineProps(swipeActionProps)
83
+ const emit = defineEmits<ISwipeActionEmits>()
84
+ const leftClass = `hy-swipe-action__left--${guid()}`
85
+ const rightClass = `hy-swipe-action__right--${guid()}`
139
86
 
140
- const slots = useSlots();
141
- const wrapperStyle = ref<string>("");
87
+ const slots = useSlots()
88
+ const wrapperStyle = ref<string>('')
142
89
 
143
90
  // 滑动开始时,wrapper的偏移量
144
- const originOffset = ref<number>(0);
91
+ const originOffset = ref<number>(0)
145
92
  // wrapper现在的偏移量
146
- const wrapperOffset = ref<number>(0);
93
+ const wrapperOffset = ref<number>(0)
147
94
  // 是否处于滑动状态
148
- const touching = ref<boolean>(false);
95
+ const touching = ref<boolean>(false)
149
96
 
150
- const touch = useTouch();
97
+ const touch = useTouch()
151
98
 
152
- const { proxy } = getCurrentInstance() as any;
99
+ const { proxy } = getCurrentInstance() as any
153
100
 
154
101
  watch(
155
- () => props.modelValue,
156
- (newVal, oldVal) => {
157
- changeState(newVal, oldVal);
158
- },
159
- {
160
- deep: true,
161
- },
162
- );
102
+ () => props.modelValue,
103
+ (newVal, oldVal) => {
104
+ changeState(newVal, oldVal)
105
+ },
106
+ {
107
+ deep: true
108
+ }
109
+ )
163
110
 
164
111
  onBeforeMount(() => {
165
- pushToQueue(proxy);
166
- // 滑动开始时,wrapper的偏移量
167
- originOffset.value = 0;
168
- // wrapper现在的偏移量
169
- wrapperOffset.value = 0;
170
- // 是否处于滑动状态
171
- touching.value = false;
172
- });
112
+ pushToQueue(proxy)
113
+ // 滑动开始时,wrapper的偏移量
114
+ originOffset.value = 0
115
+ // wrapper现在的偏移量
116
+ wrapperOffset.value = 0
117
+ // 是否处于滑动状态
118
+ touching.value = false
119
+ })
173
120
 
174
121
  onMounted(() => {
175
- touching.value = true;
176
- changeState(props.modelValue);
177
- touching.value = false;
178
- });
122
+ touching.value = true
123
+ changeState(props.modelValue)
124
+ touching.value = false
125
+ })
179
126
 
180
127
  onBeforeUnmount(() => {
181
- removeFromQueue(proxy);
182
- });
128
+ removeFromQueue(proxy)
129
+ })
183
130
 
184
131
  function changeState(value?: SwipeActionStatus, old?: SwipeActionStatus) {
185
- if (props.disabled) {
186
- return;
187
- }
188
- getWidths().then(([leftWidth, rightWidth]) => {
189
- switch (value) {
190
- case "close":
191
- // 调用此函数时,偏移量本就是0
192
- if (wrapperOffset.value === 0) return;
193
- close("value", old);
194
- break;
195
- case "left":
196
- swipeMove(leftWidth);
197
- break;
198
- case "right":
199
- swipeMove(-rightWidth);
200
- break;
132
+ if (props.disabled) {
133
+ return
201
134
  }
202
- });
135
+ getWidths().then(([leftWidth, rightWidth]) => {
136
+ switch (value) {
137
+ case 'close':
138
+ // 调用此函数时,偏移量本就是0
139
+ if (wrapperOffset.value === 0) return
140
+ close('value', old)
141
+ break
142
+ case 'left':
143
+ swipeMove(leftWidth)
144
+ break
145
+ case 'right':
146
+ swipeMove(-rightWidth)
147
+ break
148
+ }
149
+ })
203
150
  }
204
151
 
205
152
  /**
@@ -207,172 +154,170 @@ function changeState(value?: SwipeActionStatus, old?: SwipeActionStatus) {
207
154
  * @return {Promise<[Number, Number]>} 左宽度、右宽度
208
155
  */
209
156
  const getWidths = (): Promise<number[]> => {
210
- return Promise.all([
211
- getRect("." + leftClass, false, proxy).then((rect) => {
212
- return rect.width ? rect.width : 0;
213
- }),
214
- getRect("." + rightClass, false, proxy).then((rect) => {
215
- return rect.width ? rect.width : 0;
216
- }),
217
- ]);
218
- };
157
+ return Promise.all([
158
+ getRect('.' + leftClass, false, proxy).then((rect) => {
159
+ return rect.width ? rect.width : 0
160
+ }),
161
+ getRect('.' + rightClass, false, proxy).then((rect) => {
162
+ return rect.width ? rect.width : 0
163
+ })
164
+ ])
165
+ }
219
166
  /**
220
167
  * @description wrapper滑动函数
221
168
  * @param {Number} offset 滑动漂移量
222
169
  */
223
170
  function swipeMove(offset = 0) {
224
- // this.offset = offset
225
- const transform = `translate3d(${offset}px, 0, 0)`;
226
- // 跟随手指滑动,不需要动画
227
- const transition = touching.value
228
- ? "none"
229
- : ".6s cubic-bezier(0.18, 0.89, 0.32, 1)";
230
- wrapperStyle.value = `
171
+ // this.offset = offset
172
+ const transform = `translate3d(${offset}px, 0, 0)`
173
+ // 跟随手指滑动,不需要动画
174
+ const transition = touching.value ? 'none' : '.6s cubic-bezier(0.18, 0.89, 0.32, 1)'
175
+ wrapperStyle.value = `
231
176
  -webkit-transform: ${transform};
232
177
  -webkit-transition: ${transition};
233
178
  transform: ${transform};
234
179
  transition: ${transition};
235
- `;
236
- // 记录容器当前偏移的量
237
- wrapperOffset.value = offset;
180
+ `
181
+ // 记录容器当前偏移的量
182
+ wrapperOffset.value = offset
238
183
  }
239
184
  /**
240
185
  * @description click的handler
241
186
  * @param position
242
187
  */
243
188
  function onClick(position?: SwipeActionPosition) {
244
- if (props.disabled || wrapperOffset.value === 0) {
245
- return;
246
- }
189
+ if (props.disabled || wrapperOffset.value === 0) {
190
+ return
191
+ }
247
192
 
248
- position = position || "inside";
249
- close("click", position);
250
- emit("click", position);
193
+ position = position || 'inside'
194
+ close('click', position)
195
+ emit('click', position)
251
196
  }
252
197
  /**
253
198
  * @description 开始滑动
254
199
  */
255
200
  function startDrag(event: TouchEvent) {
256
- if (props.disabled) return;
201
+ if (props.disabled) return
257
202
 
258
- originOffset.value = wrapperOffset.value;
259
- touch.touchStart(event);
260
- closeOther(proxy);
203
+ originOffset.value = wrapperOffset.value
204
+ touch.touchStart(event)
205
+ closeOther(proxy)
261
206
  }
262
207
  /**
263
208
  * @description 滑动时,逐渐展示按钮
264
209
  * @param event
265
210
  */
266
211
  function onDrag(event: TouchEvent) {
267
- if (props.disabled) return;
212
+ if (props.disabled) return
268
213
 
269
- touch.touchMove(event);
270
- if (touch.direction.value === "vertical") {
271
- return;
272
- } else {
273
- event.preventDefault();
274
- event.stopPropagation();
275
- }
214
+ touch.touchMove(event)
215
+ if (touch.direction.value === 'vertical') {
216
+ return
217
+ } else {
218
+ event.preventDefault()
219
+ event.stopPropagation()
220
+ }
276
221
 
277
- touching.value = true;
222
+ touching.value = true
278
223
 
279
- // 本次滑动,wrapper应该设置的偏移量
280
- const offset = originOffset.value + touch.deltaX.value;
281
- getWidths().then(([leftWidth, rightWidth]) => {
282
- // 如果需要想滑出来的按钮不存在,对应的按钮肯定滑不出来,容器处于初始状态。此时需要模拟一下位于此处的start事件。
283
- if ((leftWidth === 0 && offset > 0) || (rightWidth === 0 && offset < 0)) {
284
- swipeMove(0);
285
- return startDrag(event);
286
- }
287
- // 按钮已经展示完了,再滑动没有任何意义,相当于滑动结束。此时需要模拟一下位于此处的start事件。
288
- if (leftWidth !== 0 && offset >= leftWidth) {
289
- swipeMove(leftWidth);
290
- return startDrag(event);
291
- } else if (rightWidth !== 0 && -offset >= rightWidth) {
292
- swipeMove(-rightWidth);
293
- return startDrag(event);
294
- }
295
- swipeMove(offset);
296
- });
224
+ // 本次滑动,wrapper应该设置的偏移量
225
+ const offset = originOffset.value + touch.deltaX.value
226
+ getWidths().then(([leftWidth, rightWidth]) => {
227
+ // 如果需要想滑出来的按钮不存在,对应的按钮肯定滑不出来,容器处于初始状态。此时需要模拟一下位于此处的start事件。
228
+ if ((leftWidth === 0 && offset > 0) || (rightWidth === 0 && offset < 0)) {
229
+ swipeMove(0)
230
+ return startDrag(event)
231
+ }
232
+ // 按钮已经展示完了,再滑动没有任何意义,相当于滑动结束。此时需要模拟一下位于此处的start事件。
233
+ if (leftWidth !== 0 && offset >= leftWidth) {
234
+ swipeMove(leftWidth)
235
+ return startDrag(event)
236
+ } else if (rightWidth !== 0 && -offset >= rightWidth) {
237
+ swipeMove(-rightWidth)
238
+ return startDrag(event)
239
+ }
240
+ swipeMove(offset)
241
+ })
297
242
  }
298
243
  /**
299
244
  * @description 滑动结束,自动修正位置
300
245
  */
301
246
  function endDrag() {
302
- if (props.disabled) return;
303
- // 滑出"操作按钮"的阈值
304
- const THRESHOLD = 0.3;
305
- touching.value = false;
247
+ if (props.disabled) return
248
+ // 滑出"操作按钮"的阈值
249
+ const THRESHOLD = 0.3
250
+ touching.value = false
306
251
 
307
- getWidths().then(([leftWidth, rightWidth]) => {
308
- if (
309
- originOffset.value < 0 && // 之前展示的是右按钮
310
- wrapperOffset.value < 0 && // 目前仍然是右按钮
311
- wrapperOffset.value - originOffset.value < rightWidth * THRESHOLD // 并且滑动的范围不超过右边框阀值
312
- ) {
313
- swipeMove(-rightWidth); // 回归右按钮
314
- emit("update:modelValue", "right");
315
- } else if (
316
- originOffset.value > 0 && // 之前展示的是左按钮
317
- wrapperOffset.value > 0 && // 现在仍然是左按钮
318
- originOffset.value - wrapperOffset.value < leftWidth * THRESHOLD // 并且滑动的范围不超过左按钮阀值
319
- ) {
320
- swipeMove(leftWidth); // 回归左按钮
321
- emit("update:modelValue", "left");
322
- } else if (
323
- rightWidth > 0 &&
324
- originOffset.value >= 0 && // 之前是初始状态或者展示左按钮显
325
- wrapperOffset.value < 0 && // 现在展示右按钮
326
- Math.abs(wrapperOffset.value) > rightWidth * THRESHOLD // 视图中已经展示的右按钮长度超过阀值
327
- ) {
328
- swipeMove(-rightWidth);
329
- emit("update:modelValue", "right");
330
- } else if (
331
- leftWidth > 0 &&
332
- originOffset.value <= 0 && // 之前初始状态或者右按钮显示
333
- wrapperOffset.value > 0 && // 现在左按钮
334
- Math.abs(wrapperOffset.value) > leftWidth * THRESHOLD // 视图中已经展示的左按钮长度超过阀值
335
- ) {
336
- swipeMove(leftWidth);
337
- emit("update:modelValue", "left");
338
- } else {
339
- // 回归初始状态
340
- close("swipe");
341
- }
342
- });
252
+ getWidths().then(([leftWidth, rightWidth]) => {
253
+ if (
254
+ originOffset.value < 0 && // 之前展示的是右按钮
255
+ wrapperOffset.value < 0 && // 目前仍然是右按钮
256
+ wrapperOffset.value - originOffset.value < rightWidth * THRESHOLD // 并且滑动的范围不超过右边框阀值
257
+ ) {
258
+ swipeMove(-rightWidth) // 回归右按钮
259
+ emit('update:modelValue', 'right')
260
+ } else if (
261
+ originOffset.value > 0 && // 之前展示的是左按钮
262
+ wrapperOffset.value > 0 && // 现在仍然是左按钮
263
+ originOffset.value - wrapperOffset.value < leftWidth * THRESHOLD // 并且滑动的范围不超过左按钮阀值
264
+ ) {
265
+ swipeMove(leftWidth) // 回归左按钮
266
+ emit('update:modelValue', 'left')
267
+ } else if (
268
+ rightWidth > 0 &&
269
+ originOffset.value >= 0 && // 之前是初始状态或者展示左按钮显
270
+ wrapperOffset.value < 0 && // 现在展示右按钮
271
+ Math.abs(wrapperOffset.value) > rightWidth * THRESHOLD // 视图中已经展示的右按钮长度超过阀值
272
+ ) {
273
+ swipeMove(-rightWidth)
274
+ emit('update:modelValue', 'right')
275
+ } else if (
276
+ leftWidth > 0 &&
277
+ originOffset.value <= 0 && // 之前初始状态或者右按钮显示
278
+ wrapperOffset.value > 0 && // 现在左按钮
279
+ Math.abs(wrapperOffset.value) > leftWidth * THRESHOLD // 视图中已经展示的左按钮长度超过阀值
280
+ ) {
281
+ swipeMove(leftWidth)
282
+ emit('update:modelValue', 'left')
283
+ } else {
284
+ // 回归初始状态
285
+ close('swipe')
286
+ }
287
+ })
343
288
  }
344
289
  /**
345
290
  * @description 关闭操过按钮,并在合适的时候调用 beforeClose
346
291
  */
347
292
  function close(reason: SwipeActionReason, position?: SwipeActionPosition) {
348
- if (reason === "swipe" && originOffset.value === 0) {
349
- // offset:0 ——> offset:0
350
- return swipeMove(0);
351
- } else if (reason === "swipe" && originOffset.value > 0) {
352
- // offset > 0 ——> offset:0
353
- position = "left";
354
- } else if (reason === "swipe" && originOffset.value < 0) {
355
- // offset < 0 ——> offset:0
356
- position = "right";
357
- }
293
+ if (reason === 'swipe' && originOffset.value === 0) {
294
+ // offset:0 ——> offset:0
295
+ return swipeMove(0)
296
+ } else if (reason === 'swipe' && originOffset.value > 0) {
297
+ // offset > 0 ——> offset:0
298
+ position = 'left'
299
+ } else if (reason === 'swipe' && originOffset.value < 0) {
300
+ // offset < 0 ——> offset:0
301
+ position = 'right'
302
+ }
358
303
 
359
- if (reason && position) {
360
- props.beforeClose && props.beforeClose(reason, position);
361
- }
304
+ if (reason && position) {
305
+ props.beforeClose && props.beforeClose(reason, position)
306
+ }
362
307
 
363
- swipeMove(0);
364
- if (props.modelValue !== "close") {
365
- emit("update:modelValue", "close");
366
- }
308
+ swipeMove(0)
309
+ if (props.modelValue !== 'close') {
310
+ emit('update:modelValue', 'close')
311
+ }
367
312
  }
368
313
 
369
314
  const onActiveClick = (item: any, index: number) => {
370
- close("click", "right");
371
- emit("clickAction", item, index);
372
- };
315
+ close('click', 'right')
316
+ emit('clickAction', item, index)
317
+ }
373
318
 
374
- defineExpose({ close });
319
+ defineExpose({ close })
375
320
  </script>
376
321
  <style lang="scss" scoped>
377
- @import "./index.scss";
322
+ @import './index.scss';
378
323
  </style>