优化日程界面

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>
+321
View File
@@ -0,0 +1,321 @@
<template>
<view class="page">
<view v-if="loading" class="state-box">
<text class="state-text">加载中...</text>
</view>
<template v-else-if="item">
<view class="detail-card">
<view class="content-block">
<view class="content-header">
<text class="info-label">日程内容</text>
<view class="status-tag" :class="item.completed ? 'done' : 'pending'">
<text>{{ item.completed ? '已完成' : '待办' }}</text>
</view>
</view>
<text class="content-text">{{ item.content || '无内容' }}</text>
</view>
<view class="info-row">
<text class="info-label">发生时间</text>
<text class="info-value">{{ formatDate(item.datetime, true) }}</text>
</view>
<view class="info-row channel-row">
<text class="info-label">提醒渠道</text>
<view class="channel-tags">
<text
v-for="channel in item.remindChannels"
:key="channel"
class="channel-tag"
>{{ getRemindChannelLabel(channel) }}</text>
<text v-if="!item.remindChannels?.length" class="info-value muted">未设置</text>
</view>
</view>
<view class="info-row">
<text class="info-label">提前提醒时间</text>
<text class="info-value">{{ remindText }}</text>
</view>
<view class="meta-row">
<text>创建于 {{ formatDate(item.createdAt, true) }}</text>
<text v-if="item.updatedAt !== item.createdAt">更新于 {{ formatDate(item.updatedAt, true) }}</text>
</view>
</view>
</template>
<view v-if="item" class="footer">
<view class="btn-complete" @tap="onToggleComplete">
<FaIcon :name="item.completed ? 'rotate-left' : 'check'" :color="item.completed ? '#606266' : '#3c9cff'" :size="16" />
<text>{{ item.completed ? '标为待办' : '标记完成' }}</text>
</view>
<view v-if="!item.completed" class="btn-edit" @tap="openEdit">
<FaIcon name="pen-to-square" color="#3c9cff" :size="16" />
<text>编辑</text>
</view>
<view class="btn-delete" @tap="onDelete">
<FaIcon name="trash-can" color="#f56c6c" :size="16" />
<text>删除</text>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import {
getSchedule,
deleteSchedule,
toggleScheduleComplete,
getRemindChannelLabel,
getRemindMinutesLabel
} from '@/api/schedule.js'
import { formatDate } from '@/utils/date.js'
const scheduleId = ref('')
const item = ref(null)
const loading = ref(false)
const remindText = computed(() => {
if (!item.value) return ''
return getRemindMinutesLabel(item.value.remindMinutes)
})
onLoad((query) => {
if (query?.id) {
scheduleId.value = query.id
loadDetail()
}
})
onShow(() => {
if (scheduleId.value) loadDetail()
})
async function loadDetail() {
loading.value = true
try {
const data = await getSchedule(scheduleId.value)
if (!data) {
uni.showToast({ title: '日程不存在', icon: 'none' })
setTimeout(() => uni.navigateBack(), 800)
return
}
item.value = data
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function openEdit() {
uni.navigateTo({ url: `/pages/tools/schedule/edit?id=${scheduleId.value}` })
}
async function onToggleComplete() {
if (!item.value) return
try {
const updated = await toggleScheduleComplete(item.value.id)
item.value = updated
uni.showToast({
title: updated.completed ? '已标记完成' : '已标为待办',
icon: 'none'
})
} catch (e) {
uni.showToast({ title: '操作失败', icon: 'none' })
}
}
function onDelete() {
const summary = (item.value?.content || '').split('\n')[0] || '该日程'
uni.showModal({
title: '删除日程',
content: `确定删除「${summary}」吗?`,
success: async (res) => {
if (!res.confirm) return
try {
await deleteSchedule(scheduleId.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));
overflow-x: hidden;
}
.detail-card {
@include card;
padding: 32rpx 28rpx;
}
.content-block {
padding-bottom: 24rpx;
margin-bottom: 8rpx;
.info-label {
display: block;
margin-bottom: 12rpx;
}
}
.content-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12rpx;
}
.status-tag {
padding: 4rpx 12rpx;
border-radius: $radius-sm;
font-size: 22rpx;
font-weight: 500;
&.pending {
background: $color-primary-bg;
color: $color-primary;
}
&.done {
background: #f0f9eb;
color: #67c23a;
}
}
.content-text {
display: block;
font-size: 30rpx;
color: $color-text;
line-height: 1.7;
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
}
.info-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24rpx;
padding: 20rpx 0;
border-top: 1rpx solid $color-divider;
}
.channel-row {
align-items: flex-start;
}
.info-label {
font-size: 26rpx;
color: $color-text-muted;
flex-shrink: 0;
}
.info-value {
font-size: 28rpx;
color: $color-text;
text-align: right;
&.muted {
color: $color-text-muted;
}
}
.channel-tags {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 10rpx;
flex: 1;
}
.channel-tag {
font-size: 24rpx;
color: $color-primary;
background: $color-primary-bg;
padding: 6rpx 16rpx;
border-radius: $radius-sm;
}
.meta-row {
display: flex;
flex-direction: column;
gap: 8rpx;
padding-top: 24rpx;
margin-top: 8rpx;
border-top: 1rpx solid $color-divider;
font-size: 24rpx;
color: $color-text-muted;
}
.footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
display: flex;
gap: 16rpx;
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-complete,
.btn-edit,
.btn-delete {
flex: 1;
height: 88rpx;
border-radius: $radius-md;
display: flex;
align-items: center;
justify-content: center;
gap: 8rpx;
font-size: 28rpx;
font-weight: 500;
}
.btn-complete {
background: $color-primary-bg;
color: $color-primary;
}
.btn-edit {
background: $color-bg-page;
color: $color-primary;
border: 1rpx solid $color-primary-bg;
}
.btn-delete {
background: $color-bg-page;
color: #f56c6c;
border: 1rpx solid #fde2e2;
}
.state-box {
display: flex;
justify-content: center;
padding: 160rpx 0;
}
.state-text {
font-size: 28rpx;
color: $color-text-muted;
}
</style>
+375
View File
@@ -0,0 +1,375 @@
<template>
<view class="page">
<view v-if="isCompleted" class="completed-notice">
<FaIcon name="circle-check" color="#67c23a" :size="40" />
<text>该日程已完成不可编辑</text>
</view>
<view class="form-card" :class="{ 'is-disabled': isCompleted }">
<view class="field">
<text class="field-label">日程内容 <text class="required">*</text></text>
<textarea
class="field-textarea content-textarea"
v-model="form.content"
placeholder="输入日程内容,支持多行"
placeholder-class="placeholder"
maxlength="1000"
:show-confirm-bar="false"
:disabled="isCompleted"
/>
<text class="char-count">{{ form.content.length }}/1000</text>
</view>
<view class="field">
<text class="field-label">发生日期 <text class="required">*</text></text>
<picker mode="date" :value="form.date" @change="onDateChange" :disabled="isCompleted">
<view class="picker-value">
<text>{{ form.date || '选择日期' }}</text>
<FaIcon name="calendar-days" color="#909399" :size="16" />
</view>
</picker>
</view>
<view class="field">
<text class="field-label">发生时间 <text class="required">*</text></text>
<picker mode="time" :value="form.time" @change="onTimeChange" :disabled="isCompleted">
<view class="picker-value">
<text>{{ form.time || '选择时间' }}</text>
<FaIcon name="clock" color="#909399" :size="16" />
</view>
</picker>
</view>
<view class="field">
<text class="field-label">提醒渠道</text>
<text class="field-hint">可多选接入接口后按渠道下发提醒</text>
<view class="channel-grid">
<view
v-for="channel in channelOptions"
:key="channel.value"
class="channel-chip"
:class="{ active: form.remindChannels.includes(channel.value) }"
@tap="!isCompleted && toggleChannel(channel.value)"
>
<text>{{ channel.label }}</text>
</view>
</view>
</view>
<view class="field picker-field">
<text class="field-label">提前提醒时间</text>
<picker :range="remindLabels" :value="remindIndex" @change="onRemindChange" :disabled="isCompleted">
<view class="picker-value">
<text>{{ remindLabels[remindIndex] }}</text>
<FaIcon name="bell" color="#909399" :size="16" />
</view>
</picker>
</view>
</view>
<view v-if="!isCompleted" class="footer">
<view class="btn-primary full" :class="{ disabled: saving }" @tap="onSave">
{{ saving ? '保存中...' : '保存' }}
</view>
</view>
</view>
</template>
<script setup>
import { ref, reactive, computed } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {
getSchedule,
createSchedule,
updateSchedule,
REMIND_CHANNEL_OPTIONS,
REMIND_MINUTES_OPTIONS
} from '@/api/schedule.js'
import { formatDate, pad } from '@/utils/date.js'
const scheduleId = ref('')
const saving = ref(false)
const isCompleted = ref(false)
const channelOptions = REMIND_CHANNEL_OPTIONS
const remindOptions = REMIND_MINUTES_OPTIONS
const remindLabels = remindOptions.map(item => item.label)
const form = reactive({
content: '',
date: '',
time: '',
remindChannels: ['app'],
remindMinutes: 15
})
const remindIndex = computed(() => {
const index = remindOptions.findIndex(item => item.value === form.remindMinutes)
return index >= 0 ? index : 3
})
onLoad(async (query) => {
const now = new Date()
form.date = formatDate(now)
form.time = `${pad(now.getHours())}:${pad(now.getMinutes())}`
if (query?.id) {
scheduleId.value = query.id
uni.setNavigationBarTitle({ title: '编辑日程' })
await loadSchedule(query.id)
} else {
uni.setNavigationBarTitle({ title: '新建日程' })
}
})
async function loadSchedule(id) {
try {
const item = await getSchedule(id)
if (!item) {
uni.showToast({ title: '日程不存在', icon: 'none' })
setTimeout(() => uni.navigateBack(), 800)
return
}
const d = new Date(item.datetime)
form.content = item.content || ''
form.date = formatDate(d)
form.time = `${pad(d.getHours())}:${pad(d.getMinutes())}`
form.remindChannels = [...(item.remindChannels || [])]
form.remindMinutes = item.remindMinutes ?? 15
isCompleted.value = !!item.completed
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
}
}
function toggleChannel(value) {
const index = form.remindChannels.indexOf(value)
if (index >= 0) {
form.remindChannels.splice(index, 1)
} else {
form.remindChannels.push(value)
}
}
function onDateChange(e) {
form.date = e.detail.value
}
function onTimeChange(e) {
form.time = e.detail.value
}
function onRemindChange(e) {
const index = Number(e.detail.value)
form.remindMinutes = remindOptions[index].value
}
function buildDatetime() {
const [year, month, day] = form.date.split('-').map(Number)
const [hour, minute] = form.time.split(':').map(Number)
return new Date(year, month - 1, day, hour, minute).getTime()
}
async function onSave() {
if (saving.value) return
if (!form.content.trim()) {
uni.showToast({ title: '请输入日程内容', icon: 'none' })
return
}
if (!form.date || !form.time) {
uni.showToast({ title: '请选择发生时间', icon: 'none' })
return
}
const datetime = buildDatetime()
if (datetime < Date.now() - 60000 && !scheduleId.value) {
uni.showModal({
title: '时间提示',
content: '发生时间已过去,仍要保存吗?',
success: async (res) => {
if (res.confirm) await saveData(datetime)
}
})
return
}
await saveData(datetime)
}
async function saveData(datetime) {
saving.value = true
const payload = {
content: form.content,
datetime,
remindChannels: [...form.remindChannels],
remindMinutes: form.remindMinutes
}
try {
if (scheduleId.value) {
await updateSchedule(scheduleId.value, payload)
} else {
await createSchedule(payload)
}
uni.showToast({ title: '保存成功', icon: 'success' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) {
uni.showToast({ title: '保存失败', icon: 'none' })
} finally {
saving.value = false
}
}
</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));
}
.completed-notice {
display: flex;
align-items: center;
justify-content: center;
gap: 12rpx;
padding: 20rpx 0;
margin-bottom: 16rpx;
font-size: 28rpx;
color: #67c23a;
background: #f0f9eb;
border-radius: $radius-md;
}
.is-disabled {
opacity: 0.7;
pointer-events: none;
}
.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-hint {
display: block;
font-size: 22rpx;
color: $color-text-muted;
margin-bottom: 16rpx;
}
.required {
color: #f56c6c;
}
.field-textarea {
width: 100%;
font-size: 30rpx;
color: $color-text;
line-height: 1.6;
}
.content-textarea {
height: 240rpx;
}
.placeholder {
color: $color-text-muted;
}
.char-count {
display: block;
text-align: right;
font-size: 22rpx;
color: $color-text-muted;
margin-top: 12rpx;
}
.picker-value {
display: flex;
align-items: center;
justify-content: space-between;
height: 72rpx;
padding: 0 20rpx;
background: $color-bg-page;
border-radius: $radius-md;
font-size: 28rpx;
color: $color-text;
}
.channel-grid {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.channel-chip {
padding: 14rpx 28rpx;
border-radius: $radius-full;
font-size: 26rpx;
color: $color-text-secondary;
background: $color-bg-page;
border: 1rpx solid transparent;
&.active {
color: $color-primary;
background: $color-primary-bg;
border-color: $color-primary;
font-weight: 500;
}
}
.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 {
flex: 1;
height: 88rpx;
border-radius: $radius-md;
display: flex;
align-items: center;
justify-content: center;
font-size: 30rpx;
font-weight: 600;
background: $color-primary;
color: #fff;
&:active {
background: $color-primary-dark;
}
&.disabled {
opacity: 0.6;
}
&.full {
flex: 1;
}
}
</style>
+428
View File
@@ -0,0 +1,428 @@
<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="loadSchedules"
/>
<view v-if="keyword" class="search-clear" @tap="clearSearch">
<FaIcon name="circle-xmark" color="#c0c4cc" :size="16" />
</view>
</view>
<view class="tabs">
<view
v-for="tab in tabs"
:key="tab.value"
class="tab"
:class="{ active: status === tab.value }"
@tap="changeStatus(tab.value)"
>{{ tab.label }}</view>
</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="groupedList.length === 0" class="state-box">
<FaIcon name="calendar-days" color="#c0c4cc" :size="40" />
<text class="state-text">{{ keyword ? '未找到相关日程' : '暂无日程,点击右下角新建' }}</text>
</view>
<view v-else class="schedule-list">
<view v-for="group in groupedList" :key="group.key" class="group">
<text class="group-title">{{ group.label }}</text>
<view
v-for="item in group.items"
:key="item.id"
class="schedule-card"
:class="{ done: item.completed }"
>
<view class="schedule-main" @tap="openDetail(item.id)">
<view class="schedule-head">
<view class="status-dot" :class="item.completed ? 'done' : 'pending'" />
<text class="schedule-title">{{ getScheduleSummary(item) }}</text>
</view>
<view class="schedule-meta">
<FaIcon name="clock" color="#909399" :size="12" />
<text>{{ formatDate(item.datetime, true) }}</text>
</view>
<view v-if="item.remindChannels?.length" class="channel-row">
<text
v-for="ch in item.remindChannels"
:key="ch"
class="channel-mini"
>{{ getRemindChannelLabel(ch) }}</text>
<text v-if="item.remindMinutes" class="remind-text">{{ getRemindMinutesLabel(item.remindMinutes) }}</text>
</view>
</view>
<view class="action-row">
<view
class="action-btn"
:class="{ disabled: item.completed }"
@tap="!item.completed && onToggleComplete(item)"
>
<FaIcon name="check" :color="item.completed ? '#c0c4cc' : '#3c9cff'" :size="14" />
<text>{{ item.completed ? '已完成' : '标记完成' }}</text>
</view>
<view v-if="!item.completed" class="action-btn" @tap="openEdit(item.id)">
<FaIcon name="pen-to-square" color="#3c9cff" :size="14" />
<text>编辑</text>
</view>
</view>
</view>
</view>
</view>
<view class="bottom-space" />
</scroll-view>
<view class="fab" @tap="createSchedule">
<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 { fetchSchedules, toggleScheduleComplete, getScheduleSummary, getRemindChannelLabel, getRemindMinutesLabel } from '@/api/schedule.js'
import { formatDate, dayLabel, isToday, startOfDay } from '@/utils/date.js'
import { isLoggedIn } from '@/utils/auth.js'
const keyword = ref('')
const status = ref('all')
const schedules = ref([])
const loading = ref(false)
const tabs = [
{ value: 'all', label: '全部' },
{ value: 'pending', label: '待办' },
{ value: 'done', label: '已完成' }
]
const groupedList = computed(() => {
const map = new Map()
schedules.value.forEach(item => {
const key = startOfDay(item.datetime).getTime()
if (!map.has(key)) {
map.set(key, {
key,
label: dayLabel(item.datetime),
isToday: isToday(item.datetime),
items: []
})
}
map.get(key).items.push(item)
})
return [...map.values()].sort((a, b) => a.key - b.key)
})
onMounted(() => {
if (!isLoggedIn()) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
loadSchedules()
})
onShow(() => {
if (isLoggedIn()) loadSchedules()
})
async function loadSchedules() {
loading.value = true
try {
const res = await fetchSchedules({
keyword: keyword.value,
status: status.value
})
schedules.value = res.list
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function clearSearch() {
keyword.value = ''
loadSchedules()
}
function changeStatus(value) {
status.value = value
loadSchedules()
}
function createSchedule() {
uni.navigateTo({ url: '/pages/tools/schedule/edit' })
}
function openDetail(id) {
uni.navigateTo({ url: `/pages/tools/schedule/detail?id=${id}` })
}
function openEdit(id) {
uni.navigateTo({ url: `/pages/tools/schedule/edit?id=${id}` })
}
async function onToggleComplete(item) {
try {
await toggleScheduleComplete(item.id)
await loadSchedules()
uni.showToast({
title: item.completed ? '已标为待办' : '已标记完成',
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;
}
.tabs {
display: flex;
gap: 16rpx;
padding: 20rpx 0 24rpx;
}
.tab {
padding: 10rpx 28rpx;
border-radius: $radius-full;
font-size: 26rpx;
color: $color-text-secondary;
background: $color-bg-page;
&.active {
color: $color-primary;
background: $color-primary-bg;
font-weight: 500;
}
}
.list-scroll {
flex: 1;
height: 0;
}
.schedule-list {
padding: 24rpx $page-padding-x 0;
}
.group {
margin-bottom: 28rpx;
}
.group-title {
display: block;
font-size: 26rpx;
font-weight: 600;
color: $color-text-secondary;
margin-bottom: 16rpx;
padding-left: 4rpx;
}
.schedule-card {
@include card;
margin-bottom: 16rpx;
overflow: hidden;
&.done .schedule-title {
text-decoration: line-through;
color: $color-text-muted;
}
}
.schedule-main {
padding: 24rpx 24rpx 16rpx;
&:active {
background: $color-bg-page;
}
}
.schedule-head {
display: flex;
align-items: center;
gap: 12rpx;
margin-bottom: 8rpx;
}
.status-dot {
width: 12rpx;
height: 12rpx;
border-radius: 50%;
flex-shrink: 0;
&.pending {
background: $color-primary;
}
&.done {
background: #67c23a;
}
}
.schedule-title {
flex: 1;
font-size: 30rpx;
font-weight: 600;
color: $color-text;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.schedule-meta {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8rpx;
font-size: 24rpx;
color: $color-text-muted;
padding-left: 24rpx;
margin-top: 8rpx;
}
.channel-row {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 10rpx;
padding-left: 24rpx;
margin-top: 12rpx;
}
.channel-mini {
font-size: 22rpx;
color: $color-primary;
background: $color-primary-bg;
padding: 4rpx 12rpx;
border-radius: $radius-sm;
}
.remind-text {
font-size: 22rpx;
color: $color-text-muted;
}
.action-row {
display: flex;
border-top: 1rpx solid $color-divider;
}
.action-btn {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
gap: 8rpx;
padding: 20rpx 0;
font-size: 24rpx;
color: $color-text-muted;
& + & {
border-left: 1rpx solid $color-divider;
}
&.danger {
color: #f56c6c;
}
&.disabled {
color: #c0c4cc;
}
&:active {
background: $color-bg-page;
}
}
.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>