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.
- package/components/hy-action-sheet/hy-action-sheet.vue +155 -238
- package/components/hy-action-sheet/props.ts +68 -15
- package/components/hy-action-sheet/typing.d.ts +115 -115
- package/components/hy-address-picker/hy-address-picker.vue +185 -289
- package/components/hy-address-picker/props.ts +97 -21
- package/components/hy-address-picker/typing.d.ts +90 -89
- package/components/hy-avatar/hy-avatar.vue +121 -204
- package/components/hy-avatar/props.ts +76 -18
- package/components/hy-avatar/typing.d.ts +63 -62
- package/components/hy-back-top/hy-back-top.vue +65 -120
- package/components/hy-back-top/props.ts +57 -16
- package/components/hy-back-top/typing.d.ts +43 -42
- package/components/hy-badge/hy-badge.vue +66 -138
- package/components/hy-badge/props.ts +73 -17
- package/components/hy-badge/typing.d.ts +59 -58
- package/components/hy-button/hy-button.vue +226 -375
- package/components/hy-button/props.ts +129 -158
- package/components/hy-calendar/header.vue +48 -64
- package/components/hy-calendar/hy-calendar.vue +274 -438
- package/components/hy-calendar/month.vue +508 -516
- package/components/hy-calendar/props.ts +157 -35
- package/components/hy-calendar/typing.d.ts +129 -128
- package/components/hy-card/hy-card.vue +118 -240
- package/components/hy-card/index.scss +1 -2
- package/components/hy-card/props.ts +122 -27
- package/components/hy-card/typing.d.ts +119 -118
- package/components/hy-cell/hy-cell.vue +176 -258
- package/components/hy-cell/props.ts +71 -17
- package/components/hy-cell/typing.d.ts +87 -86
- package/components/hy-check-button/hy-check-button.vue +69 -139
- package/components/hy-check-button/props.ts +72 -18
- package/components/hy-check-button/typing.d.ts +74 -73
- package/components/hy-checkbox/hy-checkbox.vue +170 -263
- package/components/hy-checkbox/props.ts +94 -24
- package/components/hy-checkbox/typing.d.ts +72 -72
- package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
- package/components/hy-checkbox-group/props.ts +80 -0
- package/components/hy-checkbox-group/typing.d.ts +65 -65
- package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
- package/components/hy-checkbox-item/props.ts +24 -0
- package/components/hy-checkbox-item/typing.d.ts +4 -3
- package/components/hy-code-input/hy-code-input.vue +179 -262
- package/components/hy-code-input/props.ts +84 -18
- package/components/hy-code-input/typing.d.ts +71 -71
- package/components/hy-config-provider/hy-config-provider.vue +28 -50
- package/components/hy-config-provider/props.ts +26 -11
- package/components/hy-config-provider/typing.d.ts +20 -20
- package/components/hy-count-down/hy-count-down.vue +103 -131
- package/components/hy-count-down/props.ts +30 -8
- package/components/hy-count-down/typing.d.ts +25 -25
- package/components/hy-count-to/hy-count-to.vue +148 -213
- package/components/hy-count-to/props.ts +60 -15
- package/components/hy-count-to/typing.d.ts +46 -46
- package/components/hy-coupon/README.md +133 -0
- package/components/hy-coupon/hy-coupon.vue +180 -0
- package/components/hy-coupon/index.scss +553 -0
- package/components/hy-coupon/props.ts +129 -0
- package/components/hy-coupon/typing.d.ts +146 -0
- package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
- package/components/hy-datetime-picker/props.ts +142 -32
- package/components/hy-datetime-picker/typing.d.ts +132 -132
- package/components/hy-divider/hy-divider.vue +90 -169
- package/components/hy-divider/props.ts +78 -19
- package/components/hy-divider/typing.d.ts +60 -60
- package/components/hy-dropdown/hy-dropdown.vue +37 -71
- package/components/hy-dropdown/props.ts +38 -15
- package/components/hy-dropdown/typing.d.ts +44 -44
- package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
- package/components/hy-dropdown-item/props.ts +19 -8
- package/components/hy-empty/hy-empty.vue +75 -129
- package/components/hy-empty/props.ts +57 -15
- package/components/hy-empty/typing.d.ts +84 -84
- package/components/hy-flex/hy-flex.vue +33 -88
- package/components/hy-flex/props.ts +58 -0
- package/components/hy-flex/typing.d.ts +14 -16
- package/components/hy-float-button/hy-float-button.vue +289 -406
- package/components/hy-float-button/props.ts +109 -25
- package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
- package/components/hy-folding-panel/props.ts +40 -15
- package/components/hy-folding-panel/typing.d.ts +52 -63
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
- package/components/hy-folding-panel-item/index.scss +87 -0
- package/components/hy-folding-panel-item/props.ts +81 -0
- package/components/hy-folding-panel-item/typing.d.ts +23 -0
- package/components/hy-form/hy-form.vue +172 -212
- package/components/hy-form/props.ts +37 -0
- package/components/hy-form/typing.d.ts +68 -61
- package/components/hy-form-group/typing.d.ts +74 -74
- package/components/hy-form-item/hy-form-item.vue +100 -129
- package/components/hy-form-item/props.ts +25 -0
- package/components/hy-form-item/typing.d.ts +40 -37
- package/components/hy-grid/hy-grid.vue +76 -132
- package/components/hy-grid/props.ts +58 -16
- package/components/hy-grid/typing.d.ts +66 -66
- package/components/hy-icon/hy-icon.vue +84 -161
- package/components/hy-icon/props.ts +76 -22
- package/components/hy-icon/typing.d.ts +83 -82
- package/components/hy-image/hy-image.vue +142 -272
- package/components/hy-image/props.ts +105 -23
- package/components/hy-image/typing.d.ts +84 -87
- package/components/hy-input/hy-input.vue +230 -421
- package/components/hy-input/props.ts +183 -35
- package/components/hy-input/typing.d.ts +169 -169
- package/components/hy-line/hy-line.vue +34 -72
- package/components/hy-line/props.ts +41 -10
- package/components/hy-line/typing.d.ts +29 -29
- package/components/hy-line-progress/hy-line-progress.vue +66 -101
- package/components/hy-line-progress/props.ts +31 -10
- package/components/hy-line-progress/typing.d.ts +29 -29
- package/components/hy-list/hy-list.vue +151 -220
- package/components/hy-list/props.ts +67 -16
- package/components/hy-list/typing.d.ts +52 -52
- package/components/hy-loading/hy-loading.vue +63 -119
- package/components/hy-loading/props.ts +63 -15
- package/components/hy-loading/typing.d.ts +49 -49
- package/components/hy-menu/hy-menu.vue +124 -166
- package/components/hy-menu/props.ts +42 -10
- package/components/hy-menu/typing.d.ts +60 -60
- package/components/hy-modal/hy-modal.vue +127 -218
- package/components/hy-modal/props.ts +89 -24
- package/components/hy-navbar/hy-navbar.vue +104 -177
- package/components/hy-navbar/props.ts +76 -22
- package/components/hy-navbar/typing.d.ts +81 -81
- package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
- package/components/hy-notice-bar/props.ts +80 -19
- package/components/hy-notice-bar/typing.d.ts +62 -62
- package/components/hy-notify/hy-notify.vue +128 -177
- package/components/hy-notify/props.ts +49 -12
- package/components/hy-notify/typing.d.ts +45 -41
- package/components/hy-number-step/hy-number-step.vue +281 -394
- package/components/hy-number-step/props.ts +110 -27
- package/components/hy-number-step/typing.d.ts +120 -120
- package/components/hy-overlay/hy-overlay.vue +39 -66
- package/components/hy-overlay/props.ts +31 -8
- package/components/hy-pagination/hy-pagination.vue +100 -155
- package/components/hy-pagination/props.ts +53 -13
- package/components/hy-picker/hy-picker.vue +309 -430
- package/components/hy-picker/index.scss +8 -12
- package/components/hy-picker/props.ts +110 -26
- package/components/hy-popover/hy-popover.vue +190 -252
- package/components/hy-popover/props.ts +48 -10
- package/components/hy-popup/hy-popup.vue +162 -248
- package/components/hy-popup/props.ts +82 -18
- package/components/hy-price/hy-price.vue +45 -104
- package/components/hy-price/props.ts +52 -12
- package/components/hy-price/typing.d.ts +41 -36
- package/components/hy-qrcode/hy-qrcode.vue +115 -185
- package/components/hy-qrcode/props.ts +68 -18
- package/components/hy-qrcode/typing.d.ts +67 -66
- package/components/hy-radio/hy-radio.vue +161 -259
- package/components/hy-radio/props.ts +95 -25
- package/components/hy-radio/typing.d.ts +85 -84
- package/components/hy-rate/hy-rate.vue +185 -270
- package/components/hy-rate/props.ts +76 -18
- package/components/hy-rate/typing.d.ts +61 -60
- package/components/hy-read-more/hy-read-more.vue +93 -136
- package/components/hy-read-more/props.ts +43 -13
- package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
- package/components/hy-scroll-list/props.ts +22 -11
- package/components/hy-search/hy-search.vue +155 -284
- package/components/hy-search/props.ts +130 -25
- package/components/hy-signature/hy-signature.vue +491 -635
- package/components/hy-signature/props.ts +115 -26
- package/components/hy-signature/typing.d.ts +138 -138
- package/components/hy-slider/hy-slider.vue +388 -477
- package/components/hy-slider/props.ts +75 -19
- package/components/hy-steps/hy-steps.vue +212 -279
- package/components/hy-steps/props.ts +47 -13
- package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
- package/components/hy-submit-bar/props.ts +89 -20
- package/components/hy-submit-bar/typing.d.ts +86 -85
- package/components/hy-subsection/hy-subsection.vue +132 -185
- package/components/hy-subsection/props.ts +50 -17
- package/components/hy-subsection/typing.d.ts +52 -52
- package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
- package/components/hy-swipe-action/props.ts +43 -18
- package/components/hy-swipe-action/typing.d.ts +46 -46
- package/components/hy-swiper/hy-swiper.vue +159 -286
- package/components/hy-swiper/props.ts +126 -28
- package/components/hy-swiper/typing.d.ts +115 -115
- package/components/hy-switch/hy-switch.vue +112 -176
- package/components/hy-switch/props.ts +60 -15
- package/components/hy-switch/typing.d.ts +63 -63
- package/components/hy-tabBar/hy-tabBar.vue +64 -60
- package/components/hy-tabs/hy-tabs.vue +277 -380
- package/components/hy-tabs/props.ts +75 -18
- package/components/hy-tag/hy-tag.vue +111 -204
- package/components/hy-tag/props.ts +81 -19
- package/components/hy-text/hy-text.vue +200 -322
- package/components/hy-text/props.ts +107 -28
- package/components/hy-textarea/hy-textarea.vue +147 -256
- package/components/hy-textarea/props.ts +112 -25
- package/components/hy-textarea/typing.d.ts +42 -42
- package/components/hy-toast/hy-toast.vue +135 -143
- package/components/hy-tooltip/hy-tooltip.vue +220 -306
- package/components/hy-tooltip/props.ts +79 -15
- package/components/hy-transition/hy-transition.vue +111 -138
- package/components/hy-transition/props.ts +30 -8
- package/components/hy-upload/hy-upload.vue +320 -469
- package/components/hy-upload/props.ts +130 -27
- package/components/hy-warn/hy-warn.vue +80 -129
- package/components/hy-warn/props.ts +47 -12
- package/components/hy-waterfall/hy-waterfall.vue +139 -163
- package/components/hy-waterfall/props.ts +19 -7
- package/components/hy-watermark/hy-watermark.vue +762 -870
- package/components/hy-watermark/props.ts +103 -22
- package/global.d.ts +2 -0
- package/libs/css/theme.scss +3 -3
- package/package.json +2 -2
- package/web-types.json +1 -1
- package/components/hy-folding-panel/index.scss +0 -9
|
@@ -1,205 +1,152 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
</
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
} from
|
|
76
|
-
import type { PropType } from
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} from
|
|
84
|
-
import {
|
|
85
|
-
import
|
|
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
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
})
|
|
122
|
+
touching.value = true
|
|
123
|
+
changeState(props.modelValue)
|
|
124
|
+
touching.value = false
|
|
125
|
+
})
|
|
179
126
|
|
|
180
127
|
onBeforeUnmount(() => {
|
|
181
|
-
|
|
182
|
-
})
|
|
128
|
+
removeFromQueue(proxy)
|
|
129
|
+
})
|
|
183
130
|
|
|
184
131
|
function changeState(value?: SwipeActionStatus, old?: SwipeActionStatus) {
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
189
|
+
if (props.disabled || wrapperOffset.value === 0) {
|
|
190
|
+
return
|
|
191
|
+
}
|
|
247
192
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
201
|
+
if (props.disabled) return
|
|
257
202
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
212
|
+
if (props.disabled) return
|
|
268
213
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
222
|
+
touching.value = true
|
|
278
223
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
247
|
+
if (props.disabled) return
|
|
248
|
+
// 滑出"操作按钮"的阈值
|
|
249
|
+
const THRESHOLD = 0.3
|
|
250
|
+
touching.value = false
|
|
306
251
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
360
|
-
|
|
361
|
-
|
|
304
|
+
if (reason && position) {
|
|
305
|
+
props.beforeClose && props.beforeClose(reason, position)
|
|
306
|
+
}
|
|
362
307
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
371
|
-
|
|
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
|
|
322
|
+
@import './index.scss';
|
|
378
323
|
</style>
|