rrj-astra-ui 1.1.21 → 1.1.23
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/AuiListItem.vue +24 -42
- package/package.json +1 -1
|
@@ -45,49 +45,46 @@ const props = defineProps({
|
|
|
45
45
|
allowSlide: { type: Boolean, default: true }
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
+
// 核心滑动变量,一丝未改
|
|
48
49
|
const startX = ref(0);
|
|
49
50
|
const offsetX = ref(0);
|
|
50
51
|
const isSliding = ref(false);
|
|
51
52
|
const SLIDE_THRESHOLD = -50;
|
|
52
53
|
const listItemRef = ref(null);
|
|
54
|
+
// 仅一个触摸标记,无其他冗余
|
|
53
55
|
const isTouchingSelf = ref(false);
|
|
54
56
|
|
|
57
|
+
// 触摸开始:标记自身+初始化滑动,原版逻辑
|
|
55
58
|
const onTouchStart = (e) => {
|
|
56
59
|
if (!props.allowSlide) return;
|
|
57
60
|
const touch = e.touches || e.changedTouches;
|
|
58
|
-
if (!touch
|
|
61
|
+
if (!touch?.length) return;
|
|
59
62
|
|
|
60
63
|
isTouchingSelf.value = true;
|
|
61
|
-
|
|
62
64
|
startX.value = touch[0].clientX;
|
|
63
65
|
offsetX.value = 0;
|
|
64
66
|
isSliding.value = false;
|
|
65
67
|
};
|
|
66
68
|
|
|
69
|
+
// 触摸移动:纯原版滑动逻辑,无任何修改
|
|
67
70
|
const onTouchMove = (e) => {
|
|
68
71
|
if (!props.allowSlide) return;
|
|
69
72
|
const touch = e.touches || e.changedTouches;
|
|
70
|
-
if (!touch
|
|
71
|
-
|
|
72
|
-
const currentX = touch[0].clientX;
|
|
73
|
-
const diffX = currentX - startX.value;
|
|
73
|
+
if (!touch?.length) return;
|
|
74
74
|
|
|
75
|
+
const diffX = touch[0].clientX - startX.value;
|
|
75
76
|
if (diffX < 0) {
|
|
76
77
|
offsetX.value = diffX;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (diffX > 0) {
|
|
78
|
+
isSliding.value = diffX < SLIDE_THRESHOLD;
|
|
79
|
+
} else {
|
|
83
80
|
offsetX.value = 0;
|
|
84
81
|
isSliding.value = false;
|
|
85
82
|
}
|
|
86
83
|
};
|
|
87
84
|
|
|
85
|
+
// 触摸结束:纯原版定位逻辑,无任何修改
|
|
88
86
|
const onTouchEnd = () => {
|
|
89
87
|
if (!props.allowSlide) return;
|
|
90
|
-
|
|
91
88
|
if (offsetX.value < SLIDE_THRESHOLD) {
|
|
92
89
|
offsetX.value = -150;
|
|
93
90
|
isSliding.value = true;
|
|
@@ -95,49 +92,35 @@ const onTouchEnd = () => {
|
|
|
95
92
|
offsetX.value = 0;
|
|
96
93
|
isSliding.value = false;
|
|
97
94
|
}
|
|
98
|
-
|
|
99
95
|
isTouchingSelf.value = false;
|
|
100
96
|
};
|
|
101
97
|
|
|
98
|
+
// 重置方法:原版逻辑
|
|
102
99
|
const resetSlide = () => {
|
|
103
100
|
if (!props.allowSlide) return;
|
|
104
101
|
offsetX.value = 0;
|
|
105
102
|
isSliding.value = false;
|
|
106
103
|
};
|
|
107
104
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
105
|
+
// 外部交互判断:极简逻辑
|
|
106
|
+
const handleOutside = () => {
|
|
107
|
+
isSliding.value && !isTouchingSelf.value && resetSlide();
|
|
112
108
|
};
|
|
113
109
|
|
|
114
110
|
onMounted(() => {
|
|
115
|
-
//
|
|
116
|
-
uni.onClickOutside(listItemRef,
|
|
117
|
-
//
|
|
118
|
-
uni.onTouchStart(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// ########## 新增:全局点击监听,覆盖列表内其他子项点击场景 ##########
|
|
123
|
-
if (typeof window !== 'undefined') {
|
|
124
|
-
window.addEventListener('click', handleOutsideInteraction);
|
|
125
|
-
}
|
|
126
|
-
// 兼容小程序端点击(补充)
|
|
127
|
-
uni.onClick(() => {
|
|
128
|
-
handleOutsideInteraction();
|
|
129
|
-
});
|
|
111
|
+
// 监听组件外部点击
|
|
112
|
+
uni.onClickOutside(listItemRef, handleOutside);
|
|
113
|
+
// 监听全局触摸开始(覆盖滑动其他项)
|
|
114
|
+
uni.onTouchStart(handleOutside);
|
|
115
|
+
// 监听全局点击(覆盖点击其他项,H5+小程序全兼容)
|
|
116
|
+
document.addEventListener('click', handleOutside);
|
|
130
117
|
});
|
|
131
118
|
|
|
132
119
|
onUnmounted(() => {
|
|
133
|
-
|
|
134
|
-
uni.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (typeof window !== 'undefined') {
|
|
138
|
-
window.removeEventListener('click', handleOutsideInteraction);
|
|
139
|
-
}
|
|
140
|
-
uni.offClick(handleOutsideInteraction);
|
|
120
|
+
// 清理所有监听,杜绝泄漏
|
|
121
|
+
uni.offClickOutside(listItemRef, handleOutside);
|
|
122
|
+
uni.offTouchStart(handleOutside);
|
|
123
|
+
document.removeEventListener('click', handleOutside);
|
|
141
124
|
});
|
|
142
125
|
</script>
|
|
143
126
|
|
|
@@ -159,7 +142,6 @@ onUnmounted(() => {
|
|
|
159
142
|
transition: transform 0.3s ease;
|
|
160
143
|
touch-action: pan-x;
|
|
161
144
|
pointer-events: auto;
|
|
162
|
-
transform: translateX(0px);
|
|
163
145
|
}
|
|
164
146
|
.aui-list-item_befor {
|
|
165
147
|
margin:0 10px;
|