hy-app 0.2.1 → 0.2.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/components/hy-button/index.scss +4 -0
- package/components/hy-code-input/hy-code-input.vue +223 -0
- package/components/hy-code-input/index.scss +108 -0
- package/components/hy-code-input/props.ts +21 -0
- package/components/hy-code-input/typing.d.ts +65 -0
- package/components/hy-config-provider/hy-config-provider.vue +0 -1
- package/components/hy-dropdown/props.ts +1 -1
- package/components/hy-dropdown-item/hy-dropdown-item.vue +2 -5
- package/components/hy-dropdown-item/index.scss +11 -13
- package/components/hy-grid/hy-grid.vue +5 -5
- package/components/hy-icon/index.scss +1 -0
- package/components/hy-modal/hy-modal.vue +5 -5
- package/components/hy-modal/index.scss +0 -6
- package/components/hy-notify/hy-notify.vue +169 -0
- package/components/hy-notify/index.scss +25 -0
- package/components/hy-notify/props.ts +14 -0
- package/components/hy-notify/typing.d.ts +44 -0
- package/components/hy-pagination/hy-pagination.vue +125 -0
- package/components/hy-pagination/index.scss +46 -0
- package/components/hy-pagination/props.ts +15 -0
- package/components/hy-pagination/typing.d.ts +44 -0
- package/components/hy-picker/index.scss +4 -0
- package/components/hy-scroll-list/index.scss +1 -1
- package/components/hy-search/index.scss +1 -2
- package/components/hy-signature/canvasHelper.ts +51 -0
- package/components/hy-signature/hy-signature.vue +656 -0
- package/components/hy-signature/index.scss +31 -0
- package/components/hy-signature/props.ts +28 -0
- package/components/hy-signature/typing.d.ts +177 -0
- package/components/hy-slider/index.scss +5 -1
- package/components/hy-swipe-action/hy-swipe-action.vue +288 -248
- package/components/hy-swipe-action/index.scss +34 -0
- package/components/hy-swipe-action/index.ts +34 -0
- package/components/hy-swipe-action/props.ts +15 -9
- package/components/hy-swipe-action/typing.d.ts +20 -22
- package/components/hy-swiper/index.scss +5 -0
- package/components/hy-tabs/index.scss +2 -2
- package/components/hy-tag/index.scss +1 -1
- package/components/hy-textarea/hy-textarea.vue +5 -5
- package/components/hy-textarea/index.scss +5 -6
- package/components/hy-tooltip/index.scss +2 -2
- package/components/hy-upload/index.scss +1 -1
- package/composables/index.ts +1 -0
- package/composables/useTouch.ts +48 -0
- package/libs/css/mixin.scss +52 -13
- package/libs/css/vars.css +7 -1
- package/package.json +2 -2
- package/theme.scss +23 -46
- package/components/hy-swipe-action/index.wxs +0 -235
- package/components/hy-swipe-action/wxs.js +0 -15
|
@@ -1,294 +1,334 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
<!--注意阻止横向滑动的穿透:横向移动时阻止冒泡-->
|
|
3
|
+
<view
|
|
4
|
+
class="hy-swipe-action"
|
|
5
|
+
:style="customStyle"
|
|
6
|
+
@click.stop="onClick()"
|
|
7
|
+
@touchstart="startDrag"
|
|
8
|
+
@touchmove="onDrag"
|
|
9
|
+
@touchend="endDrag"
|
|
10
|
+
@touchcancel="endDrag"
|
|
11
|
+
>
|
|
12
|
+
<!--容器-->
|
|
13
|
+
<view class="hy-swipe-action--wrapper" :style="wrapperStyle">
|
|
14
|
+
<!--左侧操作-->
|
|
15
|
+
<view
|
|
16
|
+
:class="['hy-swipe-action--left', leftClass]"
|
|
17
|
+
@click="onClick('left')"
|
|
18
|
+
>
|
|
19
|
+
<slot name="left" />
|
|
20
|
+
</view>
|
|
21
|
+
<!--左侧操作-->
|
|
22
|
+
|
|
23
|
+
<!--内容-->
|
|
24
|
+
<view
|
|
25
|
+
:class="[
|
|
26
|
+
'hy-swipe-action--center',
|
|
27
|
+
borderBottom && 'hy-border__bottom',
|
|
28
|
+
]"
|
|
29
|
+
>
|
|
30
|
+
<slot></slot>
|
|
31
|
+
</view>
|
|
32
|
+
<!--内容-->
|
|
33
|
+
|
|
34
|
+
<!--右侧操作-->
|
|
35
|
+
<view
|
|
36
|
+
:class="['hy-swipe-action--right', rightClass]"
|
|
37
|
+
@click="onClick('right')"
|
|
38
|
+
>
|
|
39
|
+
<slot name="right">
|
|
40
|
+
<view v-if="!slots.left" class="hy-swipe-action--right__action">
|
|
11
41
|
<view
|
|
12
|
-
|
|
13
|
-
:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
alignItems: item?.style?.borderRadius ? 'center' : 'stretch',
|
|
18
|
-
}"
|
|
19
|
-
@tap="buttonClickHandler(item, index, fatherI)"
|
|
42
|
+
class="hy-swipe-action--right__action-btn"
|
|
43
|
+
:style="item.style"
|
|
44
|
+
v-for="(item, i) in options"
|
|
45
|
+
@tap.stop="onActiveClick(item, i)"
|
|
46
|
+
>{{ item.text }}</view
|
|
20
47
|
>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
:style="operateItemStyle(item?.style)"
|
|
24
|
-
>
|
|
25
|
-
<u-icon
|
|
26
|
-
v-if="item.icon"
|
|
27
|
-
:name="item.icon"
|
|
28
|
-
:color="item?.style?.color || '#ffffff'"
|
|
29
|
-
:size="
|
|
30
|
-
item.iconSize
|
|
31
|
-
? addUnit(item.iconSize)
|
|
32
|
-
: item.style && item.style.fontSize
|
|
33
|
-
? getPx(item.style.fontSize) * 1.2
|
|
34
|
-
: 17
|
|
35
|
-
"
|
|
36
|
-
:customStyle="{
|
|
37
|
-
marginRight: item.text ? '2px' : 0,
|
|
38
|
-
}"
|
|
39
|
-
></u-icon>
|
|
40
|
-
<text
|
|
41
|
-
v-if="item.text"
|
|
42
|
-
class="u-swipe-action-item__right__button__wrapper__text u-line-1"
|
|
43
|
-
:style="operateTextStyle(item?.style)"
|
|
44
|
-
>{{ item.text }}</text
|
|
45
|
-
>
|
|
46
|
-
</view>
|
|
47
|
-
</view>
|
|
48
|
-
</slot>
|
|
49
|
-
</view>
|
|
50
|
-
<!-- 右侧操作按钮 -->
|
|
51
|
-
|
|
52
|
-
<!-- 左侧内容 -->
|
|
53
|
-
<!-- #ifdef APP-VUE || MP-WEIXIN || MP-QQ || H5 -->
|
|
54
|
-
<view
|
|
55
|
-
class="u-swipe-action-item__content"
|
|
56
|
-
@touchstart="wxs.touchstart"
|
|
57
|
-
@touchmove="wxs.touchmove"
|
|
58
|
-
@touchend="wxs.touchend"
|
|
59
|
-
:status="fatherItem.status"
|
|
60
|
-
:change:status="wxs.statusChange"
|
|
61
|
-
:size="size"
|
|
62
|
-
:change:size="wxs.sizeChange"
|
|
63
|
-
>
|
|
64
|
-
<slot :record="fatherItem"> </slot>
|
|
65
|
-
</view>
|
|
66
|
-
<!-- #endif -->
|
|
67
|
-
<!-- 左侧内容 -->
|
|
48
|
+
</view>
|
|
49
|
+
</slot>
|
|
68
50
|
</view>
|
|
69
|
-
|
|
51
|
+
<!--右侧操作-->
|
|
52
|
+
</view>
|
|
70
53
|
</view>
|
|
71
54
|
</template>
|
|
72
|
-
<!-- #ifdef APP-VUE || MP-WEIXIN || MP-QQ || H5 -->
|
|
73
|
-
<script src="./index.wxs" module="wxs" lang="wxs"></script>
|
|
74
|
-
<!-- #endif -->
|
|
75
55
|
|
|
76
|
-
<script
|
|
77
|
-
|
|
78
|
-
|
|
56
|
+
<script lang="ts">
|
|
57
|
+
export default {
|
|
58
|
+
name: "hy-swipe-action",
|
|
59
|
+
options: {
|
|
60
|
+
addGlobalClass: true,
|
|
61
|
+
virtualHost: true,
|
|
62
|
+
styleIsolation: "shared",
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
</script>
|
|
66
|
+
<script lang="ts" setup>
|
|
79
67
|
import {
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
getCurrentInstance,
|
|
69
|
+
onBeforeMount,
|
|
70
|
+
onBeforeUnmount,
|
|
82
71
|
onMounted,
|
|
83
72
|
ref,
|
|
84
73
|
toRefs,
|
|
85
74
|
watch,
|
|
75
|
+
useSlots,
|
|
86
76
|
} from "vue";
|
|
87
|
-
|
|
88
|
-
import {
|
|
89
|
-
|
|
77
|
+
import type IProps from "./typing";
|
|
78
|
+
import type {
|
|
79
|
+
SwipeActionStatus,
|
|
80
|
+
SwipeActionPosition,
|
|
81
|
+
SwipeActionReason,
|
|
82
|
+
} from "./typing";
|
|
83
|
+
import defaultProps from "./props";
|
|
84
|
+
import { useTouch } from "../../composables";
|
|
85
|
+
import { closeOther, pushToQueue, removeFromQueue } from "./index";
|
|
86
|
+
import { getRect, guid } from "../../utils";
|
|
90
87
|
|
|
91
88
|
const props = withDefaults(defineProps<IProps>(), defaultProps);
|
|
92
|
-
const {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
duration,
|
|
100
|
-
closeOnClick,
|
|
101
|
-
} = toRefs(props);
|
|
102
|
-
const emit = defineEmits(["update:show", "click"]);
|
|
89
|
+
const {} = toRefs(props);
|
|
90
|
+
const emit = defineEmits(["click", "clickAction", "update:modelValue"]);
|
|
91
|
+
const leftClass = `hy-swipe-action--left--${guid()}`;
|
|
92
|
+
const rightClass = `hy-swipe-action--right--${guid()}`;
|
|
93
|
+
|
|
94
|
+
const slots = useSlots();
|
|
95
|
+
const wrapperStyle = ref<string>("");
|
|
103
96
|
|
|
104
|
-
|
|
97
|
+
// 滑动开始时,wrapper的偏移量
|
|
98
|
+
const originOffset = ref<number>(0);
|
|
99
|
+
// wrapper现在的偏移量
|
|
100
|
+
const wrapperOffset = ref<number>(0);
|
|
101
|
+
// 是否处于滑动状态
|
|
102
|
+
const touching = ref<boolean>(false);
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
const swipeActionList = ref<AnyObject[]>([]);
|
|
104
|
+
const touch = useTouch();
|
|
105
|
+
|
|
106
|
+
const { proxy } = getCurrentInstance() as any;
|
|
110
107
|
|
|
111
108
|
watch(
|
|
112
|
-
() =>
|
|
113
|
-
(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
() => props.modelValue,
|
|
110
|
+
(value, old) => {
|
|
111
|
+
changeState(value, old);
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
deep: true,
|
|
118
115
|
},
|
|
119
|
-
{ immediate: true },
|
|
120
116
|
);
|
|
121
117
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const operateItemStyle = computed(() => {
|
|
133
|
-
return (temp?: CSSProperties): CSSProperties => {
|
|
134
|
-
return {
|
|
135
|
-
backgroundColor: temp?.backgroundColor || "#C7C6CD",
|
|
136
|
-
borderRadius: temp?.borderRadius || "0",
|
|
137
|
-
padding: temp?.borderRadius ? 0 : "0 15px",
|
|
138
|
-
...temp,
|
|
139
|
-
};
|
|
140
|
-
};
|
|
118
|
+
onBeforeMount(() => {
|
|
119
|
+
pushToQueue(proxy);
|
|
120
|
+
// 滑动开始时,wrapper的偏移量
|
|
121
|
+
originOffset.value = 0;
|
|
122
|
+
// wrapper现在的偏移量
|
|
123
|
+
wrapperOffset.value = 0;
|
|
124
|
+
// 是否处于滑动状态
|
|
125
|
+
touching.value = false;
|
|
141
126
|
});
|
|
142
127
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
threshold.value,
|
|
148
|
-
options.value,
|
|
149
|
-
duration.value,
|
|
150
|
-
];
|
|
128
|
+
onMounted(() => {
|
|
129
|
+
touching.value = true;
|
|
130
|
+
changeState(props.modelValue);
|
|
131
|
+
touching.value = false;
|
|
151
132
|
});
|
|
152
133
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
* */
|
|
156
|
-
const queryRect = () => {
|
|
157
|
-
getRect(".u-swipe-action-item__right__button", true).then((buttons) => {
|
|
158
|
-
size.value = {
|
|
159
|
-
buttons,
|
|
160
|
-
show: show.value,
|
|
161
|
-
disabled: disabled.value,
|
|
162
|
-
threshold: threshold.value,
|
|
163
|
-
duration: duration.value,
|
|
164
|
-
};
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
watch(
|
|
169
|
-
() => wxsInit.value,
|
|
170
|
-
() => queryRect(),
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
// watch(
|
|
174
|
-
// () => status.value,
|
|
175
|
-
// (newValue: OpenStatus) => {
|
|
176
|
-
// if (newValue === "open") {
|
|
177
|
-
// emit("update:show", true);
|
|
178
|
-
// } else {
|
|
179
|
-
// emit("update:show", false);
|
|
180
|
-
// }
|
|
181
|
-
// },
|
|
182
|
-
// );
|
|
183
|
-
//
|
|
184
|
-
// watch(
|
|
185
|
-
// () => show.value,
|
|
186
|
-
// (newValue: boolean) => {
|
|
187
|
-
// if (newValue) {
|
|
188
|
-
// status.value = "open";
|
|
189
|
-
// } else {
|
|
190
|
-
// status.value = "close";
|
|
191
|
-
// }
|
|
192
|
-
// },
|
|
193
|
-
// );
|
|
194
|
-
|
|
195
|
-
onMounted(() => {
|
|
196
|
-
init();
|
|
134
|
+
onBeforeUnmount(() => {
|
|
135
|
+
removeFromQueue(proxy);
|
|
197
136
|
});
|
|
198
137
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
138
|
+
function changeState(value: SwipeActionStatus, old?: SwipeActionStatus) {
|
|
139
|
+
if (props.disabled) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
getWidths().then(([leftWidth, rightWidth]) => {
|
|
143
|
+
switch (value) {
|
|
144
|
+
case "close":
|
|
145
|
+
// 调用此函数时,偏移量本就是0
|
|
146
|
+
if (wrapperOffset.value === 0) return;
|
|
147
|
+
close("value", old);
|
|
148
|
+
break;
|
|
149
|
+
case "left":
|
|
150
|
+
swipeMove(leftWidth);
|
|
151
|
+
break;
|
|
152
|
+
case "right":
|
|
153
|
+
swipeMove(-rightWidth);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
205
156
|
});
|
|
206
|
-
|
|
207
|
-
};
|
|
157
|
+
}
|
|
208
158
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
159
|
+
/**
|
|
160
|
+
* @description 获取左/右操作按钮的宽度
|
|
161
|
+
* @return {Promise<[Number, Number]>} 左宽度、右宽度
|
|
162
|
+
*/
|
|
163
|
+
const getWidths = (): Promise<number[]> => {
|
|
164
|
+
return Promise.all([
|
|
165
|
+
getRect("." + leftClass, false, proxy).then((rect) => {
|
|
166
|
+
return rect.width ? rect.width : 0;
|
|
167
|
+
}),
|
|
168
|
+
getRect("." + rightClass, false, proxy).then((rect) => {
|
|
169
|
+
return rect.width ? rect.width : 0;
|
|
170
|
+
}),
|
|
171
|
+
]);
|
|
212
172
|
};
|
|
213
|
-
|
|
214
173
|
/**
|
|
215
|
-
* @description
|
|
174
|
+
* @description wrapper滑动函数
|
|
175
|
+
* @param {Number} offset 滑动漂移量
|
|
216
176
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
"
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
177
|
+
function swipeMove(offset = 0) {
|
|
178
|
+
// this.offset = offset
|
|
179
|
+
const transform = `translate3d(${offset}px, 0, 0)`;
|
|
180
|
+
// 跟随手指滑动,不需要动画
|
|
181
|
+
const transition = touching.value
|
|
182
|
+
? "none"
|
|
183
|
+
: ".6s cubic-bezier(0.18, 0.89, 0.32, 1)";
|
|
184
|
+
wrapperStyle.value = `
|
|
185
|
+
-webkit-transform: ${transform};
|
|
186
|
+
-webkit-transition: ${transition};
|
|
187
|
+
transform: ${transform};
|
|
188
|
+
transition: ${transition};
|
|
189
|
+
`;
|
|
190
|
+
// 记录容器当前偏移的量
|
|
191
|
+
wrapperOffset.value = offset;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* @description click的handler
|
|
195
|
+
* @param event
|
|
196
|
+
*/
|
|
197
|
+
function onClick(position?: SwipeActionPosition) {
|
|
198
|
+
if (props.disabled || wrapperOffset.value === 0) {
|
|
199
|
+
return;
|
|
232
200
|
}
|
|
233
|
-
};
|
|
234
201
|
|
|
202
|
+
position = position || "inside";
|
|
203
|
+
close("click", position);
|
|
204
|
+
emit("click", {
|
|
205
|
+
value: position,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
235
208
|
/**
|
|
236
|
-
* @description
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
...item,
|
|
241
|
-
status: i === index ? "close" : "open",
|
|
242
|
-
}));
|
|
243
|
-
console.log(swipeActionList.value);
|
|
244
|
-
};
|
|
245
|
-
</script>
|
|
246
|
-
|
|
247
|
-
<style lang="scss" scoped>
|
|
248
|
-
@import "../../libs/css/mixin.scss";
|
|
209
|
+
* @description 开始滑动
|
|
210
|
+
*/
|
|
211
|
+
function startDrag(event: TouchEvent) {
|
|
212
|
+
if (props.disabled) return;
|
|
249
213
|
|
|
250
|
-
.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
214
|
+
originOffset.value = wrapperOffset.value;
|
|
215
|
+
touch.touchStart(event);
|
|
216
|
+
closeOther(proxy);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* @description 滑动时,逐渐展示按钮
|
|
220
|
+
* @param event
|
|
221
|
+
*/
|
|
222
|
+
function onDrag(event: TouchEvent) {
|
|
223
|
+
if (props.disabled) return;
|
|
256
224
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
225
|
+
touch.touchMove(event);
|
|
226
|
+
if (touch.direction.value === "vertical") {
|
|
227
|
+
return;
|
|
228
|
+
} else {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
event.stopPropagation();
|
|
261
231
|
}
|
|
262
232
|
|
|
263
|
-
|
|
264
|
-
position: absolute;
|
|
265
|
-
top: 0;
|
|
266
|
-
bottom: 0;
|
|
267
|
-
right: 0;
|
|
268
|
-
@include flex;
|
|
269
|
-
|
|
270
|
-
&__button {
|
|
271
|
-
@include flex;
|
|
272
|
-
justify-content: center;
|
|
273
|
-
overflow: hidden;
|
|
274
|
-
align-items: center;
|
|
233
|
+
touching.value = true;
|
|
275
234
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
235
|
+
// 本次滑动,wrapper应该设置的偏移量
|
|
236
|
+
const offset = originOffset.value + touch.deltaX.value;
|
|
237
|
+
getWidths().then(([leftWidth, rightWidth]) => {
|
|
238
|
+
// 如果需要想滑出来的按钮不存在,对应的按钮肯定滑不出来,容器处于初始状态。此时需要模拟一下位于此处的start事件。
|
|
239
|
+
if ((leftWidth === 0 && offset > 0) || (rightWidth === 0 && offset < 0)) {
|
|
240
|
+
swipeMove(0);
|
|
241
|
+
return startDrag(event);
|
|
242
|
+
}
|
|
243
|
+
// 按钮已经展示完了,再滑动没有任何意义,相当于滑动结束。此时需要模拟一下位于此处的start事件。
|
|
244
|
+
if (leftWidth !== 0 && offset >= leftWidth) {
|
|
245
|
+
swipeMove(leftWidth);
|
|
246
|
+
return startDrag(event);
|
|
247
|
+
} else if (rightWidth !== 0 && -offset >= rightWidth) {
|
|
248
|
+
swipeMove(-rightWidth);
|
|
249
|
+
return startDrag(event);
|
|
250
|
+
}
|
|
251
|
+
swipeMove(offset);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* @description 滑动结束,自动修正位置
|
|
256
|
+
*/
|
|
257
|
+
function endDrag() {
|
|
258
|
+
if (props.disabled) return;
|
|
259
|
+
// 滑出"操作按钮"的阈值
|
|
260
|
+
const THRESHOLD = 0.3;
|
|
261
|
+
touching.value = false;
|
|
281
262
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
263
|
+
getWidths().then(([leftWidth, rightWidth]) => {
|
|
264
|
+
if (
|
|
265
|
+
originOffset.value < 0 && // 之前展示的是右按钮
|
|
266
|
+
wrapperOffset.value < 0 && // 目前仍然是右按钮
|
|
267
|
+
wrapperOffset.value - originOffset.value < rightWidth * THRESHOLD // 并且滑动的范围不超过右边框阀值
|
|
268
|
+
) {
|
|
269
|
+
swipeMove(-rightWidth); // 回归右按钮
|
|
270
|
+
emit("update:modelValue", "right");
|
|
271
|
+
} else if (
|
|
272
|
+
originOffset.value > 0 && // 之前展示的是左按钮
|
|
273
|
+
wrapperOffset.value > 0 && // 现在仍然是左按钮
|
|
274
|
+
originOffset.value - wrapperOffset.value < leftWidth * THRESHOLD // 并且滑动的范围不超过左按钮阀值
|
|
275
|
+
) {
|
|
276
|
+
swipeMove(leftWidth); // 回归左按钮
|
|
277
|
+
emit("update:modelValue", "left");
|
|
278
|
+
} else if (
|
|
279
|
+
rightWidth > 0 &&
|
|
280
|
+
originOffset.value >= 0 && // 之前是初始状态或者展示左按钮显
|
|
281
|
+
wrapperOffset.value < 0 && // 现在展示右按钮
|
|
282
|
+
Math.abs(wrapperOffset.value) > rightWidth * THRESHOLD // 视图中已经展示的右按钮长度超过阀值
|
|
283
|
+
) {
|
|
284
|
+
swipeMove(-rightWidth);
|
|
285
|
+
emit("update:modelValue", "right");
|
|
286
|
+
} else if (
|
|
287
|
+
leftWidth > 0 &&
|
|
288
|
+
originOffset.value <= 0 && // 之前初始状态或者右按钮显示
|
|
289
|
+
wrapperOffset.value > 0 && // 现在左按钮
|
|
290
|
+
Math.abs(wrapperOffset.value) > leftWidth * THRESHOLD // 视图中已经展示的左按钮长度超过阀值
|
|
291
|
+
) {
|
|
292
|
+
swipeMove(leftWidth);
|
|
293
|
+
emit("update:modelValue", "left");
|
|
294
|
+
} else {
|
|
295
|
+
// 回归初始状态
|
|
296
|
+
close("swipe");
|
|
291
297
|
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* @description 关闭操过按钮,并在合适的时候调用 beforeClose
|
|
302
|
+
*/
|
|
303
|
+
function close(reason: SwipeActionReason, position?: SwipeActionPosition) {
|
|
304
|
+
if (reason === "swipe" && originOffset.value === 0) {
|
|
305
|
+
// offset:0 ——> offset:0
|
|
306
|
+
return swipeMove(0);
|
|
307
|
+
} else if (reason === "swipe" && originOffset.value > 0) {
|
|
308
|
+
// offset > 0 ——> offset:0
|
|
309
|
+
position = "left";
|
|
310
|
+
} else if (reason === "swipe" && originOffset.value < 0) {
|
|
311
|
+
// offset < 0 ——> offset:0
|
|
312
|
+
position = "right";
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (reason && position) {
|
|
316
|
+
props.beforeClose && props.beforeClose(reason, position);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
swipeMove(0);
|
|
320
|
+
if (props.modelValue !== "close") {
|
|
321
|
+
emit("update:modelValue", "close");
|
|
292
322
|
}
|
|
293
323
|
}
|
|
324
|
+
|
|
325
|
+
const onActiveClick = (item: any, index: number) => {
|
|
326
|
+
close("click", "right");
|
|
327
|
+
emit("clickAction", index, item);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
defineExpose({ close });
|
|
331
|
+
</script>
|
|
332
|
+
<style lang="scss" scoped>
|
|
333
|
+
@import "./index.scss";
|
|
294
334
|
</style>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
@use "../../theme.scss" as *;
|
|
2
|
+
@use "../../libs/css/mixin.scss" as *;
|
|
3
|
+
|
|
4
|
+
@include b(swipe-action) {
|
|
5
|
+
position: relative;
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
@include m(left) {
|
|
8
|
+
left: 0;
|
|
9
|
+
transform: translate3d(-100%, 0, 0);
|
|
10
|
+
position: absolute;
|
|
11
|
+
top: 0;
|
|
12
|
+
height: 100%;
|
|
13
|
+
}
|
|
14
|
+
@include m(right) {
|
|
15
|
+
right: 0;
|
|
16
|
+
transform: translate3d(100%, 0, 0);
|
|
17
|
+
position: absolute;
|
|
18
|
+
top: 0;
|
|
19
|
+
height: 100%;
|
|
20
|
+
&__action {
|
|
21
|
+
display: flex;
|
|
22
|
+
align-items: center;
|
|
23
|
+
height: 100%;
|
|
24
|
+
&-btn {
|
|
25
|
+
padding: 0 15px;
|
|
26
|
+
line-height: 46px;
|
|
27
|
+
display: flex;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
align-items: center;
|
|
30
|
+
color: #FFFFFF;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: weisheng
|
|
3
|
+
* @Date: 2023-07-02 22:51:06
|
|
4
|
+
* @LastEditTime: 2024-03-16 19:59:07
|
|
5
|
+
* @LastEditors: weisheng
|
|
6
|
+
* @Description:
|
|
7
|
+
* @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/components/common/clickoutside.ts
|
|
8
|
+
* 记得注释
|
|
9
|
+
*/
|
|
10
|
+
let queue: any[] = [];
|
|
11
|
+
|
|
12
|
+
export function pushToQueue(comp: any) {
|
|
13
|
+
queue.push(comp);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function removeFromQueue(comp: any) {
|
|
17
|
+
queue = queue.filter((item) => {
|
|
18
|
+
return item.$.uid !== comp.$.uid;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function closeOther(comp: any) {
|
|
23
|
+
queue.forEach((item) => {
|
|
24
|
+
if (item.$.uid !== comp.$.uid) {
|
|
25
|
+
item.$.exposed.close();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function closeOutside() {
|
|
31
|
+
queue.forEach((item) => {
|
|
32
|
+
item.$.exposed.close();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import type IProps from "./typing";
|
|
2
2
|
|
|
3
3
|
const defaultProps: IProps = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
borderBottom: false,
|
|
5
|
+
options: [
|
|
6
|
+
{
|
|
7
|
+
text: "收藏",
|
|
8
|
+
style: {
|
|
9
|
+
backgroundColor: "#3c9cff",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
text: "删除",
|
|
14
|
+
style: {
|
|
15
|
+
backgroundColor: "#f56c6c",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
],
|
|
12
19
|
duration: 300,
|
|
13
|
-
closeOnClick: true,
|
|
14
20
|
};
|
|
15
21
|
|
|
16
22
|
export default defaultProps;
|