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