基本还原了便签列表项;

添加了mock数据;
This commit is contained in:
User
2025-10-10 16:55:51 +08:00
parent d0a47b44d2
commit a03384f170
7 changed files with 246 additions and 315 deletions

View File

@@ -23,6 +23,9 @@ text {
box-sizing: border-box;
flex-shrink: 0;
}
button {
border: none;
}
#app {
width: 100vw;

View File

@@ -1,91 +1,186 @@
<template>
<div class="code-fun-flex-col code-fun-justify-start code-fun-relative list-item_7">
<div class="code-fun-flex-col section_17">
<div class="code-fun-flex-row code-fun-justify-between">
<!-- 便签编辑时间 -->
<span class="font_2 text_18">750天前2023/9/21下午4:52</span>
<div class="code-fun-flex-row group_3">
<!-- 是否置顶状态&置顶按钮 -->
<img class="image_11 image_29" src="/assets/icons/drawable-xxhdpi/icon_top_normal.png" />
<!-- 是否收藏状态&收藏按钮 -->
<img class="image_26 ml-15" src="/assets/icons/drawable-xxhdpi/icon_detail_star_unchecked.png" />
</div>
</div>
<div class="code-fun-flex-row code-fun-justify-between mt-17-5">
<!-- 便签正文第一行 -->
<span class="font_3 text_19">夜幕中启程</span>
<!-- 便签中是否存在图片 -->
<img class="image_28" src="/assets/icons/drawable-xxhdpi/list_item_image_icon.png" />
</div>
</div>
<img class="image_27 pos_18" src="/assets/icons/drawable-xxhdpi/note_item_clip_normal.png" />
</div>
</template>
<script setup></script>
<style lang="less" scoped>
.ml-15 {
margin-left: 0.94rem;
}
.mt-17-5 {
margin-top: 1.09rem;
}
.list-item_7 {
height: 3.16rem;
.section_17 {
margin-left: 0.25rem;
padding: 0.44rem 0.69rem 0.88rem 2.69rem;
background-color: #00000000;
.font_2 {
font-size: 0.71rem;
line-height: 0.71rem;
color: #c2bdb1;
}
.text_18 {
margin-top: 0.061rem;
color: #c3beb4;
}
.group_3 {
margin-right: 0.19rem;
margin-bottom: 0.063rem;
.image_11 {
width: 0.63rem;
height: 0.63rem;
}
.image_29 {
margin-top: 0.063rem;
}
.image_26 {
width: 0.69rem;
height: 0.69rem;
}
}
.font_3 {
font-size: 0.88rem;
line-height: 0.88rem;
font-weight: 700;
}
.text_19 {
margin-bottom: 0.065rem;
color: #816d61;
font-size: 0.9rem;
line-height: 0.9rem;
}
.image_28 {
width: 1.06rem;
height: 0.91rem;
}
}
.image_27 {
border-radius: 0.024rem 0.26rem 0.25rem 0.094rem;
width: 1.56rem;
height: 1.03rem;
}
.pos_18 {
position: absolute;
left: 0;
bottom: 0.5rem;
}
}
</style>
<template>
<div class="code-fun-flex-row code-fun-justify-center code-fun-relative list-item_7" @click="handlePress">
<div class="code-fun-flex-col code-fun-relative section_17">
<div class="code-fun-flex-row code-fun-justify-between">
<!-- 便签编辑时间 -->
<span class="font_2 text_18">{{ formattedDate }}</span>
<div class="code-fun-flex-row group_3">
<!-- 是否置顶状态&置顶按钮 -->
<img class="image_11 image_29" :src="isTop ? '/assets/icons/drawable-xxhdpi/icon_top_checked.png' : '/assets/icons/drawable-xxhdpi/icon_top_normal.png'" @click.stop="handleTopToggle" />
<!-- 是否收藏状态&收藏按钮 -->
<img class="image_26 ml-5" :src="isStarred ? '/assets/icons/drawable-xxhdpi/icon_detail_star_checked.png' : '/assets/icons/drawable-xxhdpi/icon_detail_star_unchecked.png'" @click.stop="handleStarToggle" />
</div>
</div>
<div class="code-fun-flex-row code-fun-justify-between mt-17-5">
<!-- 便签正文第一行 -->
<span class="font_3 text_19">{{ title }}</span>
<!-- 便签中是否存在图片 -->
<img v-if="hasImage" class="image_28" src="/assets/icons/drawable-xxhdpi/list_item_image_icon.png" />
</div>
</div>
<!-- 删除按钮 -->
<button class="btn_delete">
<span>删除</span>
</button>
<!-- 便签夹 -->
<img class="image_27 pos_18" src="/assets/icons/drawable-xxhdpi/note_item_clip_normal.png" />
</div>
</template>
<script setup>
import { computed } from 'vue'
const props = defineProps({
title: {
type: String,
required: true,
},
content: {
type: String,
required: true,
},
date: {
type: String,
required: true,
},
isStarred: {
type: Boolean,
default: false,
},
isTop: {
type: Boolean,
default: false,
},
hasImage: {
type: Boolean,
default: false,
},
onPress: {
type: Function,
default: () => {},
},
onStarToggle: {
type: Function,
default: () => {},
},
onTopToggle: {
type: Function,
default: () => {},
},
})
const formattedDate = computed(() => {
// 简单的日期格式化,实际项目中可能需要更复杂的处理
return props.date
})
const handlePress = () => {
if (props.onPress) {
props.onPress()
}
}
const handleStarToggle = () => {
if (props.onStarToggle) {
props.onStarToggle()
}
}
const handleTopToggle = () => {
if (props.onTopToggle) {
props.onTopToggle()
}
}
</script>
<style lang="less" scoped>
.ml-15 {
margin-left: 0.94rem;
}
.mt-17-5 {
margin-top: -1rem;
}
.btn_delete {
background: url(/assets/icons/drawable-xxhdpi/btn_slide_delete_normal.png);
background-size: cover;
width: 4rem;
height: 2rem;
position: absolute;
top: 50%;
left: 2rem;
z-index: 1;
transform: translate(0, -50%);
color: white;
text-align: right;
span {
margin-right: 0.2rem;
font-size: 0.6rem;
}
}
.list-item_7 {
width: 100%;
height: 3.16rem;
.section_17 {
box-sizing: border-box;
width: 95%;
height: 100%;
background: var(--background);
z-index: 2;
padding: 0.44rem 0.69rem 0.88rem 2.69rem;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.23);
.font_2 {
font-size: 0.71rem;
line-height: 0.71rem;
color: #c2bdb1;
}
.text_18 {
margin-top: 0.061rem;
color: #c3beb4;
}
.group_3 {
margin-right: 0.19rem;
margin-bottom: 0.063rem;
.image_11 {
width: 2.2rem;
height: 2.2rem;
object-fit: contain;
position: relative;
top: -0.15rem;
}
.image_29 {
margin-top: 0.063rem;
}
.image_26 {
width: 1.2rem;
height: 1.2rem;
}
}
.font_3 {
font-size: 0.88rem;
line-height: 0.88rem;
}
.text_19 {
margin-bottom: 0.065rem;
color: #816d61;
font-size: 0.9rem;
line-height: 0.9rem;
}
.image_28 {
width: 1.06rem;
height: 0.91rem;
}
}
.image_27 {
width: 1.7rem;
height: 1.7rem;
object-fit: cover;
}
.pos_18 {
position: absolute;
left: 0;
top: 50%;
transform: translate(0, -50%);
z-index: 3;
}
}
</style>

View File

@@ -1,211 +0,0 @@
<template>
<div class="note-item-container">
<!-- 左滑删除操作区域 -->
<div v-if="onDelete" class="delete-area" :class="{ 'delete-area-visible': isSwiped }">
<span class="delete-text">删除</span>
</div>
<!-- 便签内容区域 -->
<div
class="note-content"
:class="{
'note-content-swiped': isSwiped,
'note-content-pressed': isPressed,
}"
@click="onPress"
@touchstart="handleTouchStart"
@touchmove="handleTouchMove"
@touchend="handleTouchEnd"
@mousedown="handleMouseDown"
@mouseup="handleMouseUp"
@mouseleave="handleMouseLeave">
<div class="note-header">
<span class="note-date">
{{ date }}
</span>
<ion-icon v-if="isStarred" :icon="star" class="star-icon"></ion-icon>
</div>
<div class="note-title-container">
<span class="note-title">
{{ firstLine || '无内容' }}
</span>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed } from 'vue'
import { star } from 'ionicons/icons'
const props = defineProps({
title: {
type: String,
required: true,
},
content: {
type: String,
required: true,
},
date: {
type: String,
required: true,
},
isStarred: {
type: Boolean,
default: false,
},
onPress: {
type: Function,
required: true,
},
onDelete: {
type: Function,
default: null,
},
})
const isSwiped = ref(false)
const isPressed = ref(false)
const touchStartX = ref(0)
const touchEndX = ref(0)
const firstLine = computed(() => {
if (!props.content) return ''
return props.content.split('\n')[0]
})
const handleTouchStart = (event) => {
touchStartX.value = event.touches[0].clientX
isPressed.value = true
}
const handleTouchMove = (event) => {
touchEndX.value = event.touches[0].clientX
// 如果有滑动,取消按下状态
if (Math.abs(touchStartX.value - touchEndX.value) > 5) {
isPressed.value = false
}
}
const handleTouchEnd = () => {
// 重置按下状态
isPressed.value = false
// 计算滑动距离
const swipeDistance = touchStartX.value - touchEndX.value
// 如果滑动距离超过阈值,则显示删除按钮
if (swipeDistance > 50) {
isSwiped.value = true
} else if (swipeDistance < -50) {
isSwiped.value = false
}
}
const handleMouseDown = () => {
isPressed.value = true
}
const handleMouseUp = () => {
isPressed.value = false
}
const handleMouseLeave = () => {
isPressed.value = false
}
</script>
<style scoped>
.note-item-container {
height: 78.33px;
width: 100%;
overflow: hidden;
margin-bottom: 1px;
position: relative;
background: var(--background-card);
}
.delete-area {
position: absolute;
right: -80px;
top: 0;
bottom: 0;
width: 80px;
height: 100%;
background: #ffe65c53;
display: flex;
justify-content: center;
align-items: center;
transition: right 0.3s ease;
}
.delete-area-visible {
right: 0px;
}
.delete-text {
font-size: 12px;
font-weight: bold;
color: white;
}
.note-content {
width: 100%;
cursor: pointer;
height: 100%;
background: var(--background-card);
box-sizing: border-box;
transition: transform 0.3s ease, background-color 0.2s ease;
position: relative;
border-bottom: 1px solid var(--border);
position: relative;
transition: background-color 0.2s ease;
}
.note-content-swiped {
transform: translateX(-80px);
}
.note-content-pressed {
background: var(--background-secondary);
transform: scale(0.99);
}
.note-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 5px 12px 0 52px;
position: relative;
height: 24px;
}
.note-date {
font-size: 10px;
color: var(--note-date);
line-height: 1.2;
}
.star-icon {
font-size: 16px;
color: var(--note-star);
}
.note-title-container {
position: absolute;
top: 38.5px;
left: 52px;
right: 12px;
height: 30px;
}
.note-title {
font-size: 16.5px;
color: var(--note-title);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
line-height: 30px;
}
</style>

View File

@@ -32,21 +32,27 @@
}
" />
</div>
<!-- 点击外部区域收起文件夹列表的覆盖层 -->
<div v-if="isFolderExpanded" @click="() => setIsFolderExpanded(false)" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: transparent; z-index: 99"></div>
<div style="padding: 0.8rem 0.5rem; margin-top: -2.8rem">
<SearchBar v-model="searchQuery" @search="handleSearch" @clear="handleClearSearch" @focus="handleSearchFocus" @blur="handleSearchBlur" />
</div>
<div style="flex: 1">
<div style="margin-inline: 0.5rem">
<div v-for="note in filteredAndSortedNotes" :key="note.id" style="border-radius: 6px; overflow: hidden; box-shadow: 0 1px 2px var(--shadow); background-color: var(--background-card); margin-block: .5rem">
<NoteItem :title="note.title" :content="note.content" :date="formatDate(note.updatedAt)" :isStarred="note.isStarred" :onPress="() => handleNotePress(note.id)" :onDelete="() => handleDeleteNote(note.id)" />
</div>
<div v-for="note in filteredAndSortedNotes" :key="note.id" style="margin: 0.4rem 0">
<NoteItem
:title="note.title"
:content="note.content"
:date="formatDate(note.updatedAt)"
:isStarred="note.isStarred"
:isTop="note.isTop || false"
:hasImage="note.hasImage || false"
:onPress="() => handleNotePress(note.id)"
:onStarToggle="() => handleStarToggle(note.id)"
:onTopToggle="() => handleTopToggle(note.id)" />
</div>
</div>
<!-- 点击外部区域收起文件夹列表的覆盖层 -->
<div v-if="isFolderExpanded" @click="() => setIsFolderExpanded(false)" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: transparent; z-index: 99"></div>
</div>
<ion-alert
:is-open="showAlert"
@@ -100,6 +106,11 @@ const starredNotesCount = computed(() => {
return store.notes.filter(note => note.isStarred).length
})
// 计算置顶便签数量
const topNotesCount = computed(() => {
return filteredAndSortedNotes.value.filter(note => note.isTop).length
})
// 根据当前文件夹过滤便签
const filteredNotes = computed(() => {
return store.notes.filter(note => {
@@ -122,6 +133,10 @@ const filteredAndSortedNotes = computed(() => {
return filteredNotes.value
.filter(note => note.title.toLowerCase().includes(searchQuery.value.toLowerCase()) || note.content.toLowerCase().includes(searchQuery.value.toLowerCase()))
.sort((a, b) => {
// 置顶的便签排在前面
if (a.isTop && !b.isTop) return -1
if (!a.isTop && b.isTop) return 1
if (sortBy.value === 'title') {
return a.title.localeCompare(b.title)
} else if (sortBy.value === 'starred') {
@@ -161,6 +176,20 @@ const handleDeleteNote = noteId => {
showAlert.value = true
}
const handleStarToggle = async noteId => {
const note = store.notes.find(n => n.id === noteId)
if (note) {
await store.updateNote(noteId, { isStarred: !note.isStarred })
}
}
const handleTopToggle = async noteId => {
const note = store.notes.find(n => n.id === noteId)
if (note) {
await store.updateNote(noteId, { isTop: !note.isTop })
}
}
const confirmDeleteNote = () => {
if (noteToDelete.value) {
store.deleteNote(noteToDelete.value)

View File

@@ -50,7 +50,9 @@ export const useAppStore = defineStore('app', {
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
folderId: null,
isStarred: true
isStarred: true,
isTop: true,
hasImage: false
},
{
id: '2',
@@ -59,7 +61,9 @@ export const useAppStore = defineStore('app', {
createdAt: new Date(Date.now() - 86400000).toISOString(), // 昨天
updatedAt: new Date(Date.now() - 86400000).toISOString(),
folderId: null,
isStarred: true
isStarred: true,
isTop: false,
hasImage: true
},
{
id: '3',
@@ -68,7 +72,9 @@ export const useAppStore = defineStore('app', {
createdAt: new Date(Date.now() - 172800000).toISOString(), // 前天
updatedAt: new Date(Date.now() - 172800000).toISOString(),
folderId: null,
isStarred: false
isStarred: false,
isTop: false,
hasImage: false
},
{
id: '4',
@@ -77,7 +83,9 @@ export const useAppStore = defineStore('app', {
createdAt: new Date(Date.now() - 259200000).toISOString(), // 3天前
updatedAt: new Date(Date.now() - 259200000).toISOString(),
folderId: null,
isStarred: false
isStarred: false,
isTop: false,
hasImage: false
},
{
id: '5',
@@ -86,7 +94,9 @@ export const useAppStore = defineStore('app', {
createdAt: new Date(Date.now() - 345600000).toISOString(), // 4天前
updatedAt: new Date(Date.now() - 345600000).toISOString(),
folderId: null,
isStarred: false
isStarred: false,
isTop: false,
hasImage: false
}
];

View File

@@ -28,6 +28,9 @@ export const addNote = async (note) => {
id: Date.now().toString(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
isStarred: note.isStarred || false,
isTop: note.isTop || false,
hasImage: note.hasImage || false
};
const notes = await getNotes();

View File

@@ -6,7 +6,9 @@ export const Note = {
createdAt: Date,
updatedAt: Date,
folderId: String,
isStarred: Boolean
isStarred: Boolean,
isTop: Boolean,
hasImage: Boolean
};
export const Folder = {