优化小程序报销模块

This commit is contained in:
hero920103 committed 2026-10-10 14:24:44 +08:00
1 parent 1e9666cefd
commit 48f3bd997c
21 files changed
+5738 -1750

No files matched your search

+242 -78
View File
@@ -5,46 +5,70 @@
</view>
<template v-else-if="item">
<view class="detail-card">
<view class="content-block">
<view class="content-header">
<text class="info-label">日程内容</text>
<u-tag
:text="item.completed ? '已完成' : '待办'"
:type="item.completed ? 'success' : 'primary'"
size="mini"
/>
<view class="head-block">
<view class="head-row">
<text class="head-text" :class="{ done: item.completed }">{{ headText }}</text>
<view class="head-tags">
<u-tag
v-if="priorityLabel !== '普通'"
:text="priorityLabel"
:type="Number(item.priority) === 2 ? 'error' : 'warning'"
size="mini"
plain
/>
<u-tag
:text="item.completed ? '已完成' : '待办'"
:type="item.completed ? 'success' : 'primary'"
size="mini"
/>
</view>
</view>
<text class="content-text">{{ item.content || '无内容' }}</text>
<text v-if="extraContent" class="head-extra">{{ extraContent }}</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">
<u-tag
v-for="channel in item.remindChannels"
:key="channel"
:text="getRemindChannelLabel(channel)"
type="primary"
size="mini"
plain
/>
<text v-if="!item.remindChannels?.length" class="info-value muted">未设置</text>
</view>
<text class="info-label">日期</text>
<text class="info-value">{{ dayLabel(item.timestamp) }}</text>
</view>
<view class="info-row">
<text class="info-label">提前提醒时间</text>
<text class="info-value">{{ remindText }}</text>
<text class="info-label">时间</text>
<text class="info-value">{{ timeRangeText }}</text>
</view>
<!-- <view class="info-row">
<text class="info-label">优先级</text>
<text class="info-value">{{ priorityLabel }}</text>
</view> -->
<view
v-if="item.images?.length || item.completed"
class="image-block"
>
<view class="image-head">
<text class="info-label">任务资料</text>
<text v-if="item.images?.length" class="image-hint">长按图片可删除</text>
</view>
<view class="image-grid">
<image
v-for="(img, index) in item.images"
:key="img.id || index"
class="image-item"
:src="img.url"
mode="aspectFill"
@click="previewImage(index)"
@longpress="onRemoveImage(index)"
/>
<view v-if="item.completed" class="image-add" @tap="onUploadMaterial">
<FaIcon name="plus" color="#94a3b8" :size="20" />
<text>{{ uploading ? '上传中...' : '上传' }}</text>
</view>
</view>
</view>
<view class="meta-row">
<text>创建于 {{ formatDate(item.createdAt, true) }}</text>
<text v-if="item.updatedAt !== item.createdAt">更新于 {{ formatDate(item.updatedAt, true) }}</text>
<text>创建于 {{ formatTime(item.create_time) }}</text>
<text v-if="item.update_time">更新于 {{ formatTime(item.update_time) }}</text>
</view>
</view>
</template>
@@ -54,17 +78,19 @@
<u-button
:type="item.completed ? 'info' : 'primary'"
:icon="item.completed ? 'reload' : 'checkmark'"
:text="item.completed ? '标为待办' : '标记完成'"
:text="item.completed ? '反审核' : '标记完成'"
:plain="item.completed"
@click="onToggleComplete"
/>
</view>
<view v-if="!item.completed" class="footer-btn">
<u-button type="primary" plain icon="edit-pen" text="编辑" @click="openEdit" />
</view>
<view class="footer-btn">
<u-button type="error" plain icon="trash" text="删除" @click="onDelete" />
</view>
<template v-if="!item.completed">
<view class="footer-btn">
<u-button type="primary" plain icon="edit-pen" text="编辑" @click="openEdit" />
</view>
<view class="footer-btn">
<u-button type="error" plain icon="trash" text="删除" @click="onDelete" />
</view>
</template>
</view>
</view>
</template>
@@ -73,21 +99,46 @@
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'
getOaSchedule,
deleteOaSchedule,
toggleOaScheduleComplete,
uploadOaScheduleImage,
setOaScheduleImages,
getOaPriorityLabel
} from '@/api/oaSchedule.js'
import { dayLabel, formatDate } from '@/utils/date.js'
const scheduleId = ref('')
const item = ref(null)
const loading = ref(false)
const uploading = ref(false)
const remindText = computed(() => {
const priorityLabel = computed(() => {
if (!item.value) return ''
return getRemindMinutesLabel(item.value.remindMinutes)
return getOaPriorityLabel(item.value.priority)
})
/** 标题即内容:标题作为正文主文本展示 */
const headText = computed(() => {
if (!item.value) return ''
return (item.value.title || '').trim() || '无标题'
})
/** content 与标题相同(或为空)时不重复展示,仅在有额外内容时补充显示 */
const extraContent = computed(() => {
if (!item.value) return ''
const c = (item.value.content || '').trim()
if (!c || c === (item.value.title || '').trim()) return ''
return c
})
const timeRangeText = computed(() => {
if (!item.value) return ''
if (item.value.allDay) return '全天'
const start = item.value.start_time || ''
const end = item.value.end_time || ''
if (!start) return '未设置'
return end ? `${start} - ${end}` : start
})
onLoad((query) => {
@@ -101,10 +152,16 @@ onShow(() => {
if (scheduleId.value) loadDetail()
})
/** 后端时间字段可能为 "YYYY-MM-DD HH:mm:ss" 格式,iOS 需转 T 分隔 */
function formatTime(value) {
if (!value) return ''
return formatDate(new Date(String(value).replace(' ', 'T')), true)
}
async function loadDetail() {
loading.value = true
try {
const data = await getSchedule(scheduleId.value)
const data = await getOaSchedule(scheduleId.value)
if (!data) {
uni.showToast({ title: '日程不存在', icon: 'none' })
setTimeout(() => uni.navigateBack(), 800)
@@ -118,6 +175,64 @@ async function loadDetail() {
}
}
function previewImage(index) {
const urls = (item.value?.images || []).map(img => img.url).filter(Boolean)
if (!urls.length) return
uni.previewImage({ urls, current: urls[index] || urls[0] })
}
/** 上传资料图片:选图 → 逐张上传 → 引用写回日程 */
function onUploadMaterial() {
if (uploading.value) return
uni.chooseImage({
count: 9,
success: async (res) => {
const paths = res.tempFilePaths || []
if (!paths.length) return
uploading.value = true
try {
const uploaded = []
for (const p of paths) {
uploaded.push(await uploadOaScheduleImage(p))
}
const saved = await setOaScheduleImages(
scheduleId.value,
[...(item.value.images || []), ...uploaded]
)
item.value.images = saved
uni.showToast({ title: '上传成功', icon: 'success' })
} catch (e) {
// 上传/请求封装已提示错误
} finally {
uploading.value = false
}
}
})
}
/** 长按删除资料图片(仅移除引用,不动文件管理里的文件) */
function onRemoveImage(index) {
const img = item.value?.images?.[index]
if (!img || uploading.value) return
uni.showModal({
title: '删除资料',
content: `确定删除「${img.name || '该图片'}」吗?`,
success: async (res) => {
if (!res.confirm) return
try {
const saved = await setOaScheduleImages(
scheduleId.value,
item.value.images.filter((_, i) => i !== index)
)
item.value.images = saved
uni.showToast({ title: '已删除', icon: 'none' })
} catch (e) {
// request 封装已提示错误
}
}
})
}
function openEdit() {
uni.navigateTo({ url: `/pages/tools/schedule/edit?id=${scheduleId.value}` })
}
@@ -126,31 +241,30 @@ async function onToggleComplete() {
if (!item.value) return
const wasCompleted = item.value.completed
try {
await toggleScheduleComplete(item.value.id)
// toggle 接口只返回 is_finished,需重新拉取完整详情
await loadDetail()
const res = await toggleOaScheduleComplete(item.value.id)
item.value = { ...item.value, completed: res.completed, status: res.status }
uni.showToast({
title: wasCompleted ? '已标为待办' : '已标记完成',
title: wasCompleted ? '已反审核' : '已标记完成',
icon: 'none'
})
} catch (e) {
uni.showToast({ title: '操作失败', icon: 'none' })
// request 封装已弹出服务端错误提示
}
}
function onDelete() {
const summary = (item.value?.content || '').split('\n')[0] || '该日程'
const summary = item.value?.title || '该日程'
uni.showModal({
title: '删除日程',
content: `确定删除「${summary}」吗?`,
success: async (res) => {
if (!res.confirm) return
try {
await deleteSchedule(scheduleId.value)
await deleteOaSchedule(scheduleId.value)
uni.showToast({ title: '已删除', icon: 'success' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) {
uni.showToast({ title: '删除失败', icon: 'none' })
// request 封装已弹出服务端错误提示
}
}
})
@@ -173,27 +287,45 @@ function onDelete() {
padding: 32rpx 28rpx;
}
.content-block {
.head-block {
padding-bottom: 24rpx;
margin-bottom: 8rpx;
}
.info-label {
display: block;
margin-bottom: 12rpx;
.head-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16rpx;
}
.head-text {
flex: 1;
min-width: 0;
font-size: 30rpx;
color: $color-text;
line-height: 1.6;
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
&.done {
color: $color-text-muted;
text-decoration: line-through;
}
}
.content-header {
.head-tags {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12rpx;
gap: 10rpx;
flex-shrink: 0;
}
.content-text {
.head-extra {
display: block;
font-size: 30rpx;
color: $color-text;
margin-top: 12rpx;
font-size: 28rpx;
color: $color-text-secondary;
line-height: 1.7;
white-space: pre-wrap;
word-wrap: break-word;
@@ -209,10 +341,6 @@ function onDelete() {
border-top: 1rpx solid $color-divider;
}
.channel-row {
align-items: flex-start;
}
.info-label {
font-size: 26rpx;
color: $color-text-muted;
@@ -223,18 +351,54 @@ function onDelete() {
font-size: 28rpx;
color: $color-text;
text-align: right;
&.muted {
color: $color-text-muted;
}
}
.channel-tags {
.image-block {
padding: 20rpx 0;
border-top: 1rpx solid $color-divider;
}
.image-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12rpx;
}
.image-hint {
font-size: 22rpx;
color: $color-text-muted;
}
.image-grid {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 10rpx;
flex: 1;
gap: 12rpx;
}
.image-item {
width: 160rpx;
height: 160rpx;
border-radius: $radius-md;
background: $color-bg-page;
}
.image-add {
width: 160rpx;
height: 160rpx;
border: 1rpx dashed $color-border;
border-radius: $radius-md;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 6rpx;
font-size: 22rpx;
color: $color-text-muted;
&:active {
opacity: 0.7;
}
}
.meta-row {
+117 -142
View File
@@ -7,20 +7,18 @@
<view class="form-card" :class="{ 'is-disabled': isCompleted }">
<view class="field">
<text class="field-label">日程内容 <text class="required">*</text></text>
<u-textarea
v-model="form.content"
placeholder="输入日程内容,支持多行"
:maxlength="1000"
count
height="120"
<text class="field-label">标题 <text class="required">*</text></text>
<u-input
v-model="form.title"
placeholder="输入日程标题"
:maxlength="80"
border="none"
:disabled="isCompleted"
/>
</view>
<view class="field">
<text class="field-label">发生日期 <text class="required">*</text></text>
<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>
@@ -29,65 +27,60 @@
</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="field switch-field">
<view class="switch-info">
<text class="field-label">全天</text>
<text class="form-tip">开启后无需填写起止时间</text>
</view>
<u-switch
v-model="form.allDay"
active-color="#2563eb"
size="22"
:disabled="isCompleted"
/>
</view>
<view v-if="!form.allDay" class="field">
<text class="field-label">开始时间 <text class="required">*</text></text>
<picker mode="time" :value="form.startTime" @change="onStartTimeChange" :disabled="isCompleted">
<view class="picker-value">
<text>{{ form.time || '选择时间' }}</text>
<text>{{ form.startTime || '选择开始时间' }}</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">
<u-tag
v-for="channel in channelOptions"
:key="channel.value"
:text="channel.label"
:name="channel.value"
:type="isChannelActive(channel.value) ? 'primary' : 'info'"
:plain="!isChannelActive(channel.value)"
size="medium"
@click="onChannelTap"
/>
</view>
<view v-if="!form.allDay" class="field">
<text class="field-label">结束时间</text>
<picker mode="time" :value="form.endTime" @change="onEndTimeChange" :disabled="isCompleted">
<view class="picker-value">
<text>{{ form.endTime || '选填,不填则只记开始时间' }}</text>
<FaIcon name="clock" color="#909399" :size="16" />
</view>
</picker>
</view>
<view class="field picker-field">
<text class="field-label">提前提醒时间</text>
<picker :range="remindLabels" :value="remindIndex" @change="onRemindChange" :disabled="isCompleted">
<text class="field-label">优先级</text>
<picker :range="priorityLabels" :value="priorityIndex" @change="onPriorityChange" :disabled="isCompleted">
<view class="picker-value">
<text>{{ remindLabels[remindIndex] }}</text>
<FaIcon name="bell" color="#909399" :size="16" />
<text>{{ priorityLabels[priorityIndex] }}</text>
<FaIcon name="flag" color="#909399" :size="16" />
</view>
</picker>
</view>
<view class="field">
<text class="field-label">重复提醒间隔(分钟)</text>
<u-number-box
v-model="form.repeatIntervalMinutes"
:min="0"
:max="1440"
integer
<text class="field-label">内容</text>
<u-textarea
v-model="form.content"
placeholder="补充日程详细内容(选填)"
:maxlength="1000"
count
height="120"
border="none"
:disabled="isCompleted"
/>
<text class="form-tip">0表示不重复,仅发送一次</text>
</view>
<view class="field">
<text class="field-label">最多提醒次数</text>
<u-number-box
v-model="form.maxSendCount"
:min="1"
:max="100"
integer
:disabled="isCompleted"
/>
<text class="form-tip">最多发送的提醒次数</text>
</view>
</view>
@@ -109,40 +102,36 @@
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'
getOaSchedule,
createOaSchedule,
updateOaSchedule,
OA_SCHEDULE_PRIORITY_OPTIONS
} from '@/api/oaSchedule.js'
import { formatDate } 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 priorityOptions = OA_SCHEDULE_PRIORITY_OPTIONS
const priorityLabels = priorityOptions.map(item => item.label)
const form = reactive({
title: '',
content: '',
date: '',
time: '',
remindChannels: ['app'],
remindMinutes: 0,
repeatIntervalMinutes: 0,
maxSendCount: 1
allDay: true,
startTime: '09:00',
endTime: '',
priority: 0
})
const remindIndex = computed(() => {
const index = remindOptions.findIndex(item => item.value === form.remindMinutes)
return index >= 0 ? index : 3
const priorityIndex = computed(() => {
const index = priorityOptions.findIndex(item => item.value === Number(form.priority))
return index >= 0 ? index : 0
})
onLoad(async (query) => {
const now = new Date()
form.date = formatDate(now)
form.time = `${pad(now.getHours())}:${pad(now.getMinutes())}`
form.date = formatDate(new Date())
if (query?.id) {
scheduleId.value = query.id
@@ -155,105 +144,86 @@ onLoad(async (query) => {
async function loadSchedule(id) {
try {
const item = await getSchedule(id)
const item = await getOaSchedule(id)
if (!item) {
uni.showToast({ title: '日程不存在', icon: 'none' })
setTimeout(() => uni.navigateBack(), 800)
return
}
const d = new Date(item.datetime)
form.title = item.title || ''
form.content = item.content || ''
form.date = formatDate(d)
form.time = `${pad(d.getHours())}:${pad(d.getMinutes())}`
form.remindChannels = [...(item.remindChannels || [])]
form.remindMinutes = item.remindMinutes ?? 0
form.repeatIntervalMinutes = item.repeatIntervalMinutes ?? 0
form.maxSendCount = item.maxSendCount ?? 1
form.date = item.schedule_date || formatDate(new Date())
form.allDay = !!item.allDay
form.startTime = item.start_time || '09:00'
form.endTime = item.end_time || ''
form.priority = Number(item.priority) || 0
isCompleted.value = !!item.completed
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
}
}
/** 渠道是否已选中 */
function isChannelActive(value) {
return form.remindChannels.includes(value)
}
function onChannelTap(name) {
if (isCompleted.value) return
const index = form.remindChannels.indexOf(name)
if (index >= 0) {
form.remindChannels.splice(index, 1)
} else {
form.remindChannels.push(name)
}
}
function onDateChange(e) {
form.date = e.detail.value
}
function onTimeChange(e) {
form.time = e.detail.value
function onStartTimeChange(e) {
form.startTime = e.detail.value
}
function onRemindChange(e) {
function onEndTimeChange(e) {
form.endTime = e.detail.value
}
function onPriorityChange(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()
form.priority = priorityOptions[index].value
}
async function onSave() {
if (saving.value) return
if (!form.content.trim()) {
uni.showToast({ title: '请输入日程内容', icon: 'none' })
if (!form.title.trim()) {
uni.showToast({ title: '请输入日程标题', icon: 'none' })
return
}
if (!form.date || !form.time) {
uni.showToast({ title: '请选择发生时间', icon: 'none' })
if (!form.date) {
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
if (!form.allDay) {
if (!form.startTime) {
uni.showToast({ title: '请选择开始时间', icon: 'none' })
return
}
if (form.endTime && form.endTime <= form.startTime) {
uni.showToast({ title: '结束时间需晚于开始时间', icon: 'none' })
return
}
}
await saveData(datetime)
await saveData()
}
async function saveData(datetime) {
async function saveData() {
saving.value = true
const payload = {
title: form.title.trim(),
content: form.content,
datetime,
remindChannels: [...form.remindChannels],
remindMinutes: form.remindMinutes,
repeatIntervalMinutes: form.repeatIntervalMinutes,
maxSendCount: form.maxSendCount
scheduleDate: form.date,
allDay: form.allDay,
startTime: form.startTime,
endTime: form.endTime,
priority: form.priority
}
try {
if (scheduleId.value) {
await updateSchedule(scheduleId.value, payload)
await updateOaSchedule(scheduleId.value, payload)
} else {
await createSchedule(payload)
await createOaSchedule(payload)
}
uni.showToast({ title: '保存成功', icon: 'success' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) {
uni.showToast({ title: '保存失败', icon: 'none' })
// request 封装已弹出服务端错误提示
} finally {
saving.value = false
}
@@ -308,17 +278,28 @@ async function saveData(datetime) {
margin-bottom: 12rpx;
}
.field-hint {
display: block;
font-size: 22rpx;
color: $color-text-muted;
margin-bottom: 16rpx;
}
.required {
color: #f56c6c;
}
.switch-field {
display: flex;
align-items: center;
justify-content: space-between;
.switch-info {
flex: 1;
}
.field-label {
margin-bottom: 4rpx;
}
.form-tip {
margin-top: 0;
}
}
.picker-value {
display: flex;
align-items: center;
@@ -331,12 +312,6 @@ async function saveData(datetime) {
color: $color-text;
}
.channel-grid {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.form-tip {
display: block;
font-size: 22rpx;
+69 -108
View File
@@ -91,42 +91,31 @@
>
<view class="sched-main" @tap="openDetail(item.id)">
<view class="sched-left">
<text class="sched-day">{{ dayLabel(item.datetime) }}</text>
<text class="sched-time">{{ timeText(item.datetime) }}</text>
</view>
<view class="sched-sep" />
<view class="sched-right">
<view class="sched-title-row">
<text class="sched-content">{{ item.content || item.title }}</text>
<view class="status-chip" :class="item.completed ? 'done' : 'pending'">
<text>{{ item.completed ? '已完成' : '待办' }}</text>
<text class="sched-day">{{ dayLabel(item.timestamp) }}</text>
<text class="sched-time">{{ timeRangeText(item) }}</text>
</view>
<view class="sched-sep" />
<view class="sched-right">
<view class="sched-title-row">
<text class="sched-content">{{ item.title }}</text>
<view class="status-chip" :class="item.completed ? 'done' : 'pending'">
<text>{{ item.completed ? '已完成' : '待办' }}</text>
</view>
</view>
<view v-if="item.priority > 0 || item.reminder_id > 0" class="sched-meta">
<text
v-if="item.priority > 0"
class="priority-tag"
:class="item.priority === 2 ? 'urgent' : 'important'"
>{{ item.priority === 2 ? '紧急' : '重要' }}</text>
<FaIcon v-if="item.reminder_id > 0" name="bell" color="#94a3b8" :size="11" />
<text v-if="item.reminder_id > 0">已设提醒</text>
</view>
</view>
<view v-if="item.remindChannels.length" class="sched-meta">
<FaIcon name="bell" color="#94a3b8" :size="11" />
<text>{{ getRemindMinutesLabel(item.remindMinutes) }}</text>
<text v-if="item.repeatIntervalMinutes > 0">· 每 {{ item.repeatIntervalMinutes }} 分钟</text>
</view>
</view>
</view>
<view class="action-row">
<view class="action-btn" @tap="onToggleComplete(item)">
<FaIcon :name="item.completed ? 'rotate-left' : 'check'" color="#8a94ad" :size="12" />
<text>{{ item.completed ? '标为待办' : '标记完成' }}</text>
</view>
<view class="action-btn" @tap="openEdit(item.id)">
<FaIcon name="pen" color="#8a94ad" :size="12" />
<text>编辑</text>
</view>
<view class="action-btn danger" @tap="onDelete(item)">
<FaIcon name="trash" color="#f56c6c" :size="12" />
<text>删除</text>
</view>
</view>
</view>
<view class="bottom-space" />
<view class="bottom-space" />
</view>
</scroll-view>
@@ -139,12 +128,7 @@
<script setup>
import { ref, computed, onMounted } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import {
fetchSchedules,
deleteSchedule,
toggleScheduleComplete,
getRemindMinutesLabel
} from '@/api/schedule.js'
import { fetchOaSchedules } from '@/api/oaSchedule.js'
import { pad, startOfDay, isToday, isTomorrow, dayLabel } from '@/utils/date.js'
import { isLoggedIn } from '@/utils/auth.js'
@@ -209,22 +193,25 @@ const monthCells = computed(() => {
const gridCells = computed(() => (expanded.value ? monthCells.value : weekCells.value))
/** 日程按日期聚合,key 为 YYYY-MM-DD */
/** 日程按日期聚合,key 为 YYYY-MM-DD(OA 日程的 schedule_date) */
const dayMap = computed(() => {
const map = {}
schedules.value.forEach((item) => {
if (!item.datetime) return
const key = dateKey(new Date(item.datetime))
if (!map[key]) map[key] = []
map[key].push(item)
if (!item.schedule_date) return
if (!map[item.schedule_date]) map[item.schedule_date] = []
map[item.schedule_date].push(item)
})
return map
})
/** 选中日期的日程,按时间升序 */
/** 选中日期的日程:全天在前,其余按开始时间升序 */
const dayItems = computed(() => {
const list = dayMap.value[selectedKey.value] || []
return list.slice().sort((a, b) => a.datetime - b.datetime)
return list.slice().sort((a, b) => {
if (a.allDay !== b.allDay) return a.allDay ? -1 : 1
const cmp = String(a.start_time || '').localeCompare(String(b.start_time || ''))
return cmp !== 0 ? cmp : Number(b.id) - Number(a.id)
})
})
/** 本周(周一~周日)范围与日程数 */
@@ -238,11 +225,11 @@ const weekRange = computed(() => {
const weekCount = computed(() => {
const { start, end } = weekRange.value
return schedules.value.filter((item) => {
if (!item.datetime) return false
const d = new Date(item.datetime)
return d >= start && d < end
}).length
const startKey = dateKey(start)
const endKey = dateKey(end)
return schedules.value.filter(
(item) => item.schedule_date >= startKey && item.schedule_date < endKey
).length
})
const heroRangeLabel = computed(() => {
@@ -263,27 +250,44 @@ function dotCount(key) {
return Math.min(3, (dayMap.value[key] || []).length)
}
function timeText(timestamp) {
const d = new Date(timestamp)
return `${pad(d.getHours())}:${pad(d.getMinutes())}`
/** 时间展示:全天显示「全天」,其余显示开始时间或起止区间 */
function timeRangeText(item) {
if (item.allDay) return '全天'
if (!item.start_time) return ''
return item.end_time ? `${item.start_time} - ${item.end_time}` : item.start_time
}
/** 数据加载区间:当前日历月前后各扩 7 天,覆盖周视图跨月格子 */
function currentRange() {
const year = monthCursor.value.getFullYear()
const month = monthCursor.value.getMonth()
const start = new Date(year, month, -6)
const end = new Date(year, month + 1, 7)
return { startDate: dateKey(start), endDate: dateKey(end) }
}
function shiftMonth(step) {
const cur = monthCursor.value
monthCursor.value = new Date(cur.getFullYear(), cur.getMonth() + step, 1)
loadSchedules()
}
function goToday() {
const now = new Date()
monthCursor.value = new Date(now.getFullYear(), now.getMonth(), 1)
selectedDate.value = startOfDay(now)
loadSchedules()
}
function pickDay(cell) {
const monthChanged =
cell.date.getFullYear() !== monthCursor.value.getFullYear() ||
cell.date.getMonth() !== monthCursor.value.getMonth()
selectedDate.value = startOfDay(cell.date)
monthCursor.value = new Date(cell.date.getFullYear(), cell.date.getMonth(), 1)
// 月历里选完日期后自动收回周栏
if (expanded.value) expanded.value = false
if (monthChanged) loadSchedules()
}
onMounted(() => {
@@ -301,8 +305,9 @@ onShow(() => {
async function loadSchedules() {
loading.value = true
try {
// 后端暂不支持按日期区间过滤,取最近一页在端上按月/按天聚合
const res = await fetchSchedules({ pageSize: 100 })
// OA 工作日程:按日历区间拉取(前后各扩 7 天),端上按天聚合
const { startDate, endDate } = currentRange()
const res = await fetchOaSchedules({ startDate, endDate, pageSize: 500 })
schedules.value = res.list
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
@@ -318,42 +323,6 @@ function createSchedule() {
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' })
}
}
function onDelete(item) {
uni.showModal({
title: '删除日程',
content: '删除后该日程及其提醒将一并移除,确定继续吗?',
confirmText: '删除',
cancelText: '取消',
success: async (res) => {
if (!res.confirm) return
try {
await deleteSchedule(item.id)
uni.showToast({ title: '已删除', icon: 'none' })
await loadSchedules()
} catch (e) {
uni.showToast({ title: '删除失败', icon: 'none' })
}
}
})
}
</script>
<style lang="scss" scoped>
@@ -688,27 +657,19 @@ function onDelete(item) {
color: $color-text-muted;
}
.action-row {
display: flex;
border-top: 1rpx solid $color-divider;
}
.priority-tag {
padding: 2rpx 12rpx;
border-radius: $radius-full;
font-size: 21rpx;
.action-btn {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
gap: 8rpx;
padding: 18rpx 0;
font-size: 24rpx;
color: $color-text-secondary;
&:active {
background: $color-bg-page;
&.important {
background: #fff7ed;
color: #ea580c;
}
&.danger {
color: #f56c6c;
&.urgent {
background: #fef2f2;
color: #dc2626;
}
}