优化日程界面

This commit is contained in:
2026-07-15 18:14:17 +08:00
parent 11e0763766
commit bca5170e22
19 changed files with 2805 additions and 1070 deletions
+290
View File
@@ -0,0 +1,290 @@
<template>
<view class="page">
<view class="form-card">
<view class="field">
<text class="field-label">标题</text>
<input
class="field-input title-input"
v-model="form.title"
type="text"
placeholder="输入标题"
placeholder-class="placeholder"
maxlength="80"
/>
</view>
<view class="field content-field">
<text class="field-label">内容</text>
<textarea
class="field-textarea"
v-model="form.content"
placeholder="记录你的想法..."
placeholder-class="placeholder"
:auto-height="false"
maxlength="5000"
:show-confirm-bar="false"
/>
<text class="char-count">{{ form.content.length }}/5000</text>
</view>
<view class="switch-row" @tap="form.pinned = !form.pinned">
<view class="switch-left">
<FaIcon name="thumbtack" :color="form.pinned ? '#3c9cff' : '#909399'" :size="16" />
<text class="switch-label">置顶笔记</text>
</view>
<view class="switch-dot" :class="{ on: form.pinned }" />
</view>
</view>
<view v-if="noteId && meta.updatedAt" class="meta">
<text>最近更新{{ formatDate(meta.updatedAt, true) }}</text>
</view>
<view class="footer">
<view v-if="noteId" class="btn-danger" @tap="onDelete">删除</view>
<view class="btn-primary" :class="{ disabled: saving }" @tap="onSave">
{{ saving ? '保存中...' : '保存' }}
</view>
</view>
</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getNote, createNote, updateNote, deleteNote } from '@/api/note.js'
import { formatDate } from '@/utils/date.js'
const noteId = ref('')
const saving = ref(false)
const form = reactive({
title: '',
content: '',
pinned: false
})
const meta = reactive({
updatedAt: 0
})
onLoad(async (query) => {
if (query?.id) {
noteId.value = query.id
uni.setNavigationBarTitle({ title: '编辑笔记' })
await loadNote(query.id)
} else {
uni.setNavigationBarTitle({ title: '新建笔记' })
}
})
async function loadNote(id) {
try {
const note = await getNote(id)
if (!note) {
uni.showToast({ title: '笔记不存在', icon: 'none' })
setTimeout(() => uni.navigateBack(), 800)
return
}
form.title = note.title
form.content = note.content
form.pinned = !!note.pinned
meta.updatedAt = note.updatedAt
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
}
}
async function onSave() {
if (saving.value) return
if (!form.title.trim() && !form.content.trim()) {
uni.showToast({ title: '请输入标题或内容', icon: 'none' })
return
}
saving.value = true
try {
if (noteId.value) {
await updateNote(noteId.value, {
title: form.title,
content: form.content,
pinned: form.pinned
})
} else {
await createNote({
title: form.title,
content: form.content,
pinned: form.pinned
})
}
uni.showToast({ title: '保存成功', icon: 'success' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) {
uni.showToast({ title: '保存失败', icon: 'none' })
} finally {
saving.value = false
}
}
function onDelete() {
uni.showModal({
title: '删除笔记',
content: '删除后无法恢复,确定继续吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteNote(noteId.value)
uni.showToast({ title: '已删除', icon: 'success' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) {
uni.showToast({ title: '删除失败', icon: 'none' })
}
}
})
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
padding: 24rpx $page-padding-x;
padding-bottom: calc(180rpx + env(safe-area-inset-bottom));
}
.form-card {
@include card;
padding: 8rpx 0;
}
.field {
padding: 24rpx 28rpx;
& + & {
border-top: 1rpx solid $color-divider;
}
}
.field-label {
display: block;
font-size: 24rpx;
color: $color-text-muted;
margin-bottom: 12rpx;
}
.field-input,
.field-textarea {
width: 100%;
font-size: 30rpx;
color: $color-text;
}
.title-input {
font-weight: 600;
}
.content-field {
position: relative;
}
.field-textarea {
height: 480rpx;
line-height: 1.7;
}
.placeholder {
color: $color-text-muted;
}
.char-count {
display: block;
text-align: right;
font-size: 22rpx;
color: $color-text-muted;
margin-top: 12rpx;
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 28rpx;
border-top: 1rpx solid $color-divider;
}
.switch-left {
display: flex;
align-items: center;
gap: 12rpx;
}
.switch-label {
font-size: 28rpx;
color: $color-text;
}
.switch-dot {
width: 44rpx;
height: 44rpx;
border-radius: 50%;
border: 1rpx solid $color-border;
background: $color-card;
&.on {
background: $color-primary;
border-color: $color-primary;
box-shadow: inset 0 0 0 6rpx #fff;
}
}
.meta {
margin-top: 20rpx;
padding: 0 8rpx;
font-size: 24rpx;
color: $color-text-muted;
}
.footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
display: flex;
gap: 20rpx;
padding: 20rpx $page-padding-x;
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
background: $color-card;
border-top: 1rpx solid $color-border;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.04);
}
.btn-primary,
.btn-danger {
flex: 1;
height: 88rpx;
border-radius: $radius-md;
display: flex;
align-items: center;
justify-content: center;
font-size: 30rpx;
font-weight: 600;
}
.btn-primary {
background: $color-primary;
color: #fff;
&:active {
background: $color-primary-dark;
}
&.disabled {
opacity: 0.6;
}
}
.btn-danger {
background: $color-bg-page;
color: #f56c6c;
border: 1rpx solid #fde2e2;
}
</style>
+332
View File
@@ -0,0 +1,332 @@
<template>
<view class="page">
<view class="toolbar">
<view class="search-bar">
<FaIcon name="magnifying-glass" color="#909399" :size="16" />
<input
class="search-input"
v-model="keyword"
type="text"
placeholder="搜索笔记标题或内容"
placeholder-class="search-placeholder"
confirm-type="search"
@confirm="loadNotes"
/>
<view v-if="keyword" class="search-clear" @tap="clearSearch">
<FaIcon name="circle-xmark" color="#c0c4cc" :size="16" />
</view>
</view>
<view class="stats-row">
<text class="stats-text"> {{ total }} </text>
<text v-if="pinnedCount" class="stats-text">置顶 {{ pinnedCount }} </text>
</view>
</view>
<scroll-view class="list-scroll" scroll-y :show-scrollbar="false">
<view v-if="loading" class="state-box">
<text class="state-text">加载中...</text>
</view>
<view v-else-if="notes.length === 0" class="state-box">
<FaIcon name="note-sticky" color="#c0c4cc" :size="40" />
<text class="state-text">{{ keyword ? '未找到相关笔记' : '暂无笔记,点击右下角新建' }}</text>
</view>
<view v-else class="note-list">
<view
v-for="item in notes"
:key="item.id"
class="note-card"
@tap="openEdit(item.id)"
>
<view class="note-head">
<view class="note-title-row">
<text v-if="item.pinned" class="pin-tag">置顶</text>
<text class="note-title">{{ item.title }}</text>
</view>
<text class="note-time">{{ formatRelativeTime(item.updatedAt) }}</text>
</view>
<text class="note-preview">{{ preview(item.content) }}</text>
<view class="note-actions" @tap.stop>
<view class="action-btn" @tap="onTogglePin(item)">
<FaIcon :name="item.pinned ? 'thumbtack' : 'thumbtack'" :color="item.pinned ? '#3c9cff' : '#909399'" :size="14" />
<text>{{ item.pinned ? '取消置顶' : '置顶' }}</text>
</view>
<view class="action-btn danger" @tap="onDelete(item)">
<FaIcon name="trash-can" color="#f56c6c" :size="14" />
<text>删除</text>
</view>
</view>
</view>
</view>
<view class="bottom-space" />
</scroll-view>
<view class="fab" @tap="createNote">
<FaIcon name="plus" color="#ffffff" :size="22" />
</view>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { fetchNotes, deleteNote, toggleNotePin } from '@/api/note.js'
import { formatRelativeTime } from '@/utils/date.js'
import { isLoggedIn } from '@/utils/auth.js'
const keyword = ref('')
const notes = ref([])
const total = ref(0)
const loading = ref(false)
const pinnedCount = computed(() => notes.value.filter(item => item.pinned).length)
onMounted(() => {
if (!isLoggedIn()) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
loadNotes()
})
onShow(() => {
if (isLoggedIn()) loadNotes()
})
async function loadNotes() {
loading.value = true
try {
const res = await fetchNotes({ keyword: keyword.value })
notes.value = res.list
total.value = res.total
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function clearSearch() {
keyword.value = ''
loadNotes()
}
function preview(content) {
const text = (content || '').replace(/\s+/g, ' ').trim()
if (!text) return '暂无内容'
return text.length > 60 ? `${text.slice(0, 60)}...` : text
}
function createNote() {
uni.navigateTo({ url: '/pages/tools/notepad/edit' })
}
function openEdit(id) {
uni.navigateTo({ url: `/pages/tools/notepad/edit?id=${id}` })
}
async function onTogglePin(item) {
try {
await toggleNotePin(item.id)
await loadNotes()
uni.showToast({ title: item.pinned ? '已取消置顶' : '已置顶', icon: 'none' })
} catch (e) {
uni.showToast({ title: '操作失败', icon: 'none' })
}
}
function onDelete(item) {
uni.showModal({
title: '删除笔记',
content: `确定删除「${item.title}」吗?`,
success: async (res) => {
if (!res.confirm) return
try {
await deleteNote(item.id)
await loadNotes()
uni.showToast({ title: '已删除', icon: 'none' })
} catch (e) {
uni.showToast({ title: '删除失败', icon: 'none' })
}
}
})
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
display: flex;
flex-direction: column;
}
.toolbar {
flex-shrink: 0;
padding: 20rpx $page-padding-x 0;
background: $color-card;
box-shadow: $shadow-header;
}
.search-bar {
display: flex;
align-items: center;
gap: 12rpx;
height: 72rpx;
padding: 0 24rpx;
background: $color-bg-page;
border-radius: $radius-full;
}
.search-input {
flex: 1;
height: 72rpx;
font-size: 28rpx;
color: $color-text;
}
.search-placeholder {
color: $color-text-muted;
font-size: 28rpx;
}
.search-clear {
display: flex;
padding: 8rpx;
}
.stats-row {
display: flex;
gap: 24rpx;
padding: 16rpx 4rpx 20rpx;
}
.stats-text {
font-size: 24rpx;
color: $color-text-muted;
}
.list-scroll {
flex: 1;
height: 0;
}
.note-list {
padding: 24rpx $page-padding-x 0;
}
.note-card {
@include card;
padding: 28rpx 24rpx;
margin-bottom: 20rpx;
&:active {
opacity: 0.92;
}
}
.note-head {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 16rpx;
margin-bottom: 12rpx;
}
.note-title-row {
flex: 1;
min-width: 0;
display: flex;
align-items: center;
gap: 10rpx;
}
.pin-tag {
flex-shrink: 0;
font-size: 20rpx;
color: $color-primary;
background: $color-primary-bg;
padding: 2rpx 10rpx;
border-radius: $radius-sm;
}
.note-title {
font-size: 30rpx;
font-weight: 600;
color: $color-text;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.note-time {
flex-shrink: 0;
font-size: 22rpx;
color: $color-text-muted;
}
.note-preview {
display: block;
font-size: 26rpx;
color: $color-text-secondary;
line-height: 1.6;
margin-bottom: 20rpx;
}
.note-actions {
display: flex;
gap: 24rpx;
padding-top: 16rpx;
border-top: 1rpx solid $color-divider;
}
.action-btn {
display: flex;
align-items: center;
gap: 8rpx;
font-size: 24rpx;
color: $color-text-muted;
&.danger {
color: #f56c6c;
}
}
.state-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 160rpx 48rpx;
gap: 20rpx;
}
.state-text {
font-size: 26rpx;
color: $color-text-muted;
text-align: center;
}
.fab {
position: fixed;
right: 40rpx;
bottom: calc(40rpx + env(safe-area-inset-bottom));
width: 104rpx;
height: 104rpx;
border-radius: 50%;
background: $color-primary;
box-shadow: 0 8rpx 24rpx rgba(60, 156, 255, 0.35);
display: flex;
align-items: center;
justify-content: center;
&:active {
background: $color-primary-dark;
}
}
.bottom-space {
height: 160rpx;
}
</style>