rrj-astra-ui 1.1.1 → 1.1.3

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.
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="aui-list-item">
2
+ <view class="aui-list-item" ref="listItemRef">
3
3
  <view class="aui-list-item-content-wrapper" :style="{ transform: `translateX(${offsetX}px)` }" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd">
4
4
  <view class="aui-list-item_befor">
5
5
  <slot name="befor"></slot>
@@ -26,13 +26,7 @@
26
26
  </template>
27
27
 
28
28
  <script setup>
29
- import { defineProps, ref } from 'vue';
30
- const __name = 'AuiListItem';
31
-
32
- // defineOptions 可能不是 Vue 内置方法,这里注释掉
33
- defineOptions({
34
- name: __name
35
- })
29
+ import { defineProps, ref, onMounted, onUnmounted } from 'vue';
36
30
 
37
31
  const props = defineProps({
38
32
  text: {
@@ -56,8 +50,11 @@ const props = defineProps({
56
50
  const startX = ref(0);
57
51
  const offsetX = ref(0);
58
52
  const isSliding = ref(false);
59
- const SLIDE_THRESHOLD = -50; // 滑动阈值
53
+ const SLIDE_THRESHOLD = -50;
54
+ // 新增:获取组件 DOM 引用
55
+ const listItemRef = ref(null);
60
56
 
57
+ // 原有滑动逻辑(不变)
61
58
  const onTouchStart = (e) => {
62
59
  if (!props.allowSlide) return;
63
60
  startX.value = e.touches[0].clientX;
@@ -80,14 +77,60 @@ const onTouchMove = (e) => {
80
77
  const onTouchEnd = () => {
81
78
  if (!props.allowSlide) return;
82
79
  if (offsetX.value < SLIDE_THRESHOLD) {
83
- offsetX.value = -150; // 自定义内容宽度
80
+ offsetX.value = -150;
84
81
  } else {
85
82
  offsetX.value = 0;
86
83
  isSliding.value = false;
87
84
  }
88
85
  };
86
+
87
+ // 新增:收回滑动区域的核心方法
88
+ const resetSlide = () => {
89
+ if (!props.allowSlide || !isSliding.value) return;
90
+ offsetX.value = 0;
91
+ isSliding.value = false;
92
+ };
93
+
94
+ // 新增:监听页面点击事件,判断是否点击组件外部
95
+ const handlePageClick = (e) => {
96
+ if (!listItemRef.value || !isSliding.value) return;
97
+
98
+ // 获取组件 DOM 信息
99
+ const itemDom = listItemRef.value;
100
+ const itemRect = itemDom.getBoundingClientRect();
101
+
102
+ // 判断点击坐标是否在组件外部
103
+ const clickX = e.clientX || e.touches?.[0]?.clientX;
104
+ const clickY = e.clientY || e.touches?.[0]?.clientY;
105
+ if (
106
+ clickX < itemRect.left ||
107
+ clickX > itemRect.right ||
108
+ clickY < itemRect.top ||
109
+ clickY > itemRect.bottom
110
+ ) {
111
+ // 点击外部,触发收回
112
+ resetSlide();
113
+ }
114
+ };
115
+
116
+ // 新增:挂载时添加页面点击监听,卸载时移除(防止内存泄漏)
117
+ onMounted(() => {
118
+ // 监听 uni-app 页面点击(兼容移动端/PC端)
119
+ uni.onClickOutside(listItemRef, resetSlide); // 优先使用 uni-app 内置方法(更简洁)
120
+ // 备用:监听 window 点击(兼容更多场景)
121
+ window.addEventListener('click', handlePageClick);
122
+ window.addEventListener('touchstart', handlePageClick);
123
+ });
124
+
125
+ onUnmounted(() => {
126
+ // 移除监听,防止内存泄漏
127
+ uni.offClickOutside(listItemRef, resetSlide);
128
+ window.removeEventListener('click', handlePageClick);
129
+ window.removeEventListener('touchstart', handlePageClick);
130
+ });
89
131
  </script>
90
132
 
133
+ <!-- 样式部分不变,保留你的原有样式 -->
91
134
  <style scoped lang="scss">
92
135
  @import '../style.scss';
93
136
  .aui-list-item {
@@ -139,4 +182,4 @@ const onTouchEnd = () => {
139
182
  justify-content: center;
140
183
  z-index: 999;
141
184
  }
142
- </style>
185
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrj-astra-ui",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "AstraUI - A powerful UI framework for UniApp with global SCSS color variables",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -36,4 +36,4 @@
36
36
  "parse5": "^7.3.0",
37
37
  "uuid": "^11.1.0"
38
38
  }
39
- }
39
+ }