优化小程序报销模块

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 {