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