\"优化 便签列表页面交互体验,添加便签滑动状态管理,防止在滑动状态下误触编辑页面\"

This commit is contained in:
yuantao
2025-10-17 14:38:57 +08:00
parent f27c3e1da6
commit 508db9e9ae
4 changed files with 46 additions and 30 deletions

View File

@@ -31,6 +31,8 @@
<script setup>
import { computed, ref } from 'vue'
const emit = defineEmits(['update:modelValue'])
const props = defineProps({
content: {
type: String,
@@ -139,6 +141,9 @@ const handlePress = () => {
// 只有在未滑动状态下才触发点击事件
if (slideOffset.value === 0 && props.onPress) {
props.onPress()
} else if (slideOffset.value !== 0) {
// 如果当前处于滑动状态,重置滑动状态(收回便签条)
resetSlideState()
}
}
@@ -169,6 +174,21 @@ const handleDelete = () => {
isSlided.value = false
}
// 重置滑动状态
const resetSlideState = () => {
slideOffset.value = 0
isSliding.value = false
isSlided.value = false
}
// 获取滑动状态
const getSlideState = () => {
return isSlided.value
}
// 暴露方法给父组件
defineExpose({ resetSlideState, getSlideState })
// 触摸开始事件处理函数
// 记录触摸开始时的X坐标用于计算滑动距离
const handleTouchStart = e => {
@@ -216,7 +236,7 @@ const handleTouchMove = e => {
e.stopPropagation()
// 阻止父级滚动容器的滚动行为
e.stopImmediatePropagation()
// 只有当滑动达到一定距离时才阻止页面滚动
if (diffX > 5) {
e.preventDefault() // 防止页面滚动

View File

@@ -12,7 +12,7 @@
:isFolderExpanded="isFolderExpanded"
:onTitlePress="handleFolderToggle"
slot="fixed" />
<!-- 悬浮文件夹列表 - 使用绝对定位实现 -->
<div v-if="isFolderExpanded" class="folder-list" slot="fixed">
<FolderManage
@@ -35,7 +35,11 @@
<transition-group name="note-list" tag="div" class="notes-list">
<div v-for="note in filteredAndSortedNotes" :key="note.id" class="note-item">
<NoteItem
:title="note.title"
:ref="
el => {
if (el) noteItemRefs[note.id] = el
}
"
:content="note.content"
:date="formatDate(note.updatedAt)"
:isStarred="note.isStarred"
@@ -66,6 +70,7 @@ import { IonContent, IonPage } from '@ionic/vue'
const store = useAppStore()
const router = useRouter()
const noteItemRefs = ref({})
// 页面挂载时加载初始数据
onMounted(() => {
@@ -103,9 +108,8 @@ const filteredNotes = computed(() => {
return store.notes.filter(note => {
// 先检查搜索条件
const matchesSearch = !lowerCaseQuery ||
(note.title && typeof note.title === 'string' && note.title.toLowerCase().includes(lowerCaseQuery)) ||
(note.content && typeof note.content === 'string' && note.content.toLowerCase().includes(lowerCaseQuery))
const matchesSearch =
!lowerCaseQuery || (note.title && typeof note.title === 'string' && note.title.toLowerCase().includes(lowerCaseQuery)) || (note.content && typeof note.content === 'string' && note.content.toLowerCase().includes(lowerCaseQuery))
if (!matchesSearch) return false
@@ -172,6 +176,21 @@ const allNotesCount = computed(() => {
})
const handleNotePress = noteId => {
// 检查是否有便签条处于展开状态
let hasSlidedNote = false
Object.values(noteItemRefs.value).forEach(noteItem => {
// 注意isSlided是ref值需要通过.value访问
if (noteItem && noteItem.getSlideState()) {
hasSlidedNote = true
noteItem.resetSlideState()
}
})
// 如果有便签条处于展开状态,不跳转到编辑页面
if (hasSlidedNote) {
return
}
// 使用vue-router导航到编辑页面
router.push(`/editor/${noteId}`)
}