feat: Implement scheduled tasks management and budget archiving functionality
Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 6s
Docker Build & Deploy / Deploy to Production (push) Has been skipped
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 2s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s
Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 6s
Docker Build & Deploy / Deploy to Production (push) Has been skipped
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 2s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s
- Added BudgetArchiveJob for monthly budget archiving. - Created BudgetArchive entity and BudgetArchiveRepository for managing archived budgets. - Introduced JobController for handling job execution, pausing, and resuming. - Developed ScheduledTasksView for displaying and managing scheduled tasks in the frontend. - Updated PeriodicBillJob to improve scope handling. - Enhanced OpenAiService with increased HTTP timeout. - Added archiveBudgets API endpoint for archiving budgets by year and month. - Refactored BudgetController to utilize new repository patterns and improved error handling. - Introduced rich-content styles for better rendering of HTML content in Vue components. - Updated various Vue components to support rich HTML content display.
This commit is contained in:
@@ -72,3 +72,15 @@ export function toggleStopBudget(id) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 归档预算
|
||||
* @param {number} year 年份
|
||||
* @param {number} month 月份
|
||||
*/
|
||||
export function archiveBudgets(year, month) {
|
||||
return request({
|
||||
url: `/Budget/ArchiveBudgetsAsync/${year}/${month}`,
|
||||
method: 'post'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
32
Web/src/api/job.js
Normal file
32
Web/src/api/job.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import request from '@/api/request'
|
||||
|
||||
export function getJobs() {
|
||||
return request({
|
||||
url: '/Job/GetJobs',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
export function executeJob(jobName) {
|
||||
return request({
|
||||
url: '/Job/Execute',
|
||||
method: 'post',
|
||||
data: { jobName }
|
||||
})
|
||||
}
|
||||
|
||||
export function pauseJob(jobName) {
|
||||
return request({
|
||||
url: '/Job/Pause',
|
||||
method: 'post',
|
||||
data: { jobName }
|
||||
})
|
||||
}
|
||||
|
||||
export function resumeJob(jobName) {
|
||||
return request({
|
||||
url: '/Job/Resume',
|
||||
method: 'post',
|
||||
data: { jobName }
|
||||
})
|
||||
}
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
<van-collapse-transition>
|
||||
<div v-if="budget.description && showDescription" class="budget-description">
|
||||
<div class="description-content" v-html="budget.description"></div>
|
||||
<div class="description-content rich-html-content" v-html="budget.description"></div>
|
||||
</div>
|
||||
</van-collapse-transition>
|
||||
</div>
|
||||
@@ -312,78 +312,6 @@ const timePercentage = computed(() => {
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.description-content :deep(h3) {
|
||||
margin: 12px 0 6px;
|
||||
font-size: 13px;
|
||||
color: #323233;
|
||||
border-left: 3px solid #1989fa;
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
.description-content :deep(table) {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 8px 0;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.description-content :deep(th),
|
||||
.description-content :deep(td) {
|
||||
text-align: left;
|
||||
padding: 6px 4px;
|
||||
border-bottom: 1px solid #f2f3f5;
|
||||
}
|
||||
|
||||
.description-content :deep(th) {
|
||||
background-color: #f7f8fa;
|
||||
color: #969799;
|
||||
font-weight: normal;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.description-content :deep(p) {
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.description-content :deep(.income-value) {
|
||||
color: #07c160;
|
||||
}
|
||||
|
||||
.description-content :deep(.expense-value) {
|
||||
color: #ee0a24;
|
||||
}
|
||||
|
||||
.description-content :deep(.highlight) {
|
||||
background-color: #fffbe6;
|
||||
color: #ed6a0c;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-weight: bold;
|
||||
border: 1px solid #ffe58f;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.description-content :deep(h3) {
|
||||
color: #f5f5f5;
|
||||
}
|
||||
.description-content :deep(table) {
|
||||
background: #1a1a1a;
|
||||
}
|
||||
.description-content :deep(th) {
|
||||
background-color: #242424;
|
||||
}
|
||||
.description-content :deep(td) {
|
||||
border-bottom-color: #2c2c2c;
|
||||
}
|
||||
.description-content :deep(.highlight) {
|
||||
background-color: #3e371a;
|
||||
color: #ff976a;
|
||||
border-color: #594a1a;
|
||||
}
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import './assets/main.css'
|
||||
import './styles/common.css'
|
||||
import './styles/rich-content.css'
|
||||
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
@@ -93,6 +93,12 @@ const router = createRouter({
|
||||
name: 'budget',
|
||||
component: () => import('../views/BudgetView.vue'),
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/scheduled-tasks',
|
||||
name: 'scheduled-tasks',
|
||||
component: () => import('../views/ScheduledTasksView.vue'),
|
||||
meta: { requiresAuth: true },
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
141
Web/src/styles/rich-content.css
Normal file
141
Web/src/styles/rich-content.css
Normal file
@@ -0,0 +1,141 @@
|
||||
/* 后端返回的 HTML 富文本内容样式 */
|
||||
.rich-html-content {
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
color: var(--van-text-color);
|
||||
white-space: normal; /* 重置可能存在的 pre-wrap */
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.rich-html-content h1,
|
||||
.rich-html-content h2,
|
||||
.rich-html-content h3 {
|
||||
margin: 16px 0 8px;
|
||||
color: var(--van-text-color);
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.rich-html-content h1 {
|
||||
font-size: 1.5em;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid var(--van-border-color);
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.rich-html-content h2 {
|
||||
font-size: 1.25em;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.rich-html-content h3 {
|
||||
font-size: 1.1em;
|
||||
border-left: 4px solid #1989fa;
|
||||
padding-left: 10px;
|
||||
margin-top: 15px;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
|
||||
.rich-html-content p {
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
.rich-html-content ul,
|
||||
.rich-html-content ol {
|
||||
padding-left: 20px;
|
||||
margin: 14px 0;
|
||||
}
|
||||
|
||||
.rich-html-content li {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.rich-html-content strong {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* 表格样式优化 - 移动端适配滑动 */
|
||||
.rich-html-content table {
|
||||
display: block;
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
border-collapse: collapse;
|
||||
margin: 16px 0;
|
||||
background: var(--van-background-2);
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--van-border-color);
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
.rich-html-content th,
|
||||
.rich-html-content td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
border: 1px solid var(--van-border-color);
|
||||
min-width: 80px; /* 防止内容过于拥挤 */
|
||||
}
|
||||
|
||||
/* 针对第一列预算项增加最小宽度 */
|
||||
.rich-html-content td:first-child,
|
||||
.rich-html-content th:first-child {
|
||||
min-width: 100px;
|
||||
position: sticky;
|
||||
left: 0;
|
||||
background: inherit;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.rich-html-content th {
|
||||
background: var(--van-gray-1);
|
||||
color: var(--van-text-color);
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* 业务特定样式:收入、支出、高亮 */
|
||||
.rich-html-content .income-value {
|
||||
color: #07c160 !important;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.rich-html-content .expense-value {
|
||||
color: #ee0a24 !important;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.rich-html-content .highlight {
|
||||
background-color: #fffbe6;
|
||||
color: #ed6a0c;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-weight: bold;
|
||||
border: 1px solid #ffe58f;
|
||||
margin: 0 2px;
|
||||
}
|
||||
|
||||
/* 暗色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.rich-html-content .highlight {
|
||||
background-color: rgba(255, 243, 205, 0.2);
|
||||
color: #ffc107;
|
||||
border-color: rgba(255, 229, 143, 0.3);
|
||||
}
|
||||
|
||||
.rich-html-content table {
|
||||
background: #1a1a1a;
|
||||
}
|
||||
|
||||
.rich-html-content th {
|
||||
background-color: #242424;
|
||||
color: #f5f5f5;
|
||||
}
|
||||
|
||||
.rich-html-content td:first-child,
|
||||
.rich-html-content th:first-child {
|
||||
background-color: #1a1a1a;
|
||||
}
|
||||
|
||||
.rich-html-content th:first-child {
|
||||
background-color: #242424;
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div ref="resultContainer" class="result-content">
|
||||
<div ref="resultContainer" class="result-content rich-html-content">
|
||||
<div v-html="resultHtml"></div>
|
||||
<van-loading v-if="analyzing" class="result-loading">
|
||||
AI正在分析中...
|
||||
@@ -351,103 +351,12 @@ const startAnalysis = async () => {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
/* 结果HTML样式 */
|
||||
.result-content :deep(h1),
|
||||
.result-content :deep(h2),
|
||||
.result-content :deep(h3) {
|
||||
color: var(--van-text-color);
|
||||
margin: 16px 0 12px 0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.result-content :deep(h1) {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.result-content :deep(h2) {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.result-content :deep(h3) {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.result-content :deep(p) {
|
||||
margin: 8px 0;
|
||||
color: var(--van-text-color);
|
||||
}
|
||||
|
||||
.result-content :deep(ul),
|
||||
.result-content :deep(ol) {
|
||||
padding-left: 24px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
.result-content :deep(li) {
|
||||
margin: 6px 0;
|
||||
color: var(--van-text-color);
|
||||
}
|
||||
|
||||
.result-content :deep(table) {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 16px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.result-content :deep(th),
|
||||
.result-content :deep(td) {
|
||||
padding: 10px;
|
||||
text-align: left;
|
||||
border: 1px solid var(--van-border-color);
|
||||
}
|
||||
|
||||
.result-content :deep(th) {
|
||||
background: var(--van-background-2);
|
||||
font-weight: 600;
|
||||
color: var(--van-text-color);
|
||||
}
|
||||
|
||||
.result-content :deep(td) {
|
||||
color: var(--van-text-color);
|
||||
}
|
||||
|
||||
.result-content :deep(strong) {
|
||||
color: var(--van-text-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.result-content :deep(.highlight) {
|
||||
background: #fff3cd;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
color: #856404;
|
||||
}
|
||||
|
||||
.result-content :deep(.expense-value) {
|
||||
color: #ff6b6b;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.result-content :deep(.income-value) {
|
||||
color: #51cf66;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #ff6b6b;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
/* 暗色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.result-content :deep(.highlight) {
|
||||
background: rgba(255, 243, 205, 0.2);
|
||||
color: #ffc107;
|
||||
}
|
||||
}
|
||||
|
||||
/* 设置页面容器背景色 */
|
||||
:deep(.van-nav-bar) {
|
||||
background: transparent !important;
|
||||
|
||||
@@ -41,12 +41,12 @@
|
||||
v-model="detailVisible"
|
||||
:title="currentMessage.title"
|
||||
:subtitle="currentMessage.createTime"
|
||||
height="50%"
|
||||
height="80%"
|
||||
:closeable="true"
|
||||
>
|
||||
<div
|
||||
v-if="currentMessage.messageType === 2"
|
||||
class="detail-content"
|
||||
class="detail-content rich-html-content"
|
||||
v-html="currentMessage.content"
|
||||
>
|
||||
</div>
|
||||
@@ -275,10 +275,13 @@ defineExpose({
|
||||
}
|
||||
|
||||
.detail-content {
|
||||
padding: 20px;
|
||||
font-size: 16px;
|
||||
padding: 16px;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
color: var(--van-text-color);
|
||||
}
|
||||
|
||||
.detail-content:not(.rich-html-content) {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
|
||||
182
Web/src/views/ScheduledTasksView.vue
Normal file
182
Web/src/views/ScheduledTasksView.vue
Normal file
@@ -0,0 +1,182 @@
|
||||
<template>
|
||||
<div class="page-container-flex">
|
||||
<van-nav-bar title="定时任务" left-arrow placeholder @click-left="onClickLeft" />
|
||||
<div class="scroll-content">
|
||||
<van-pull-refresh v-model="loading" @refresh="fetchTasks">
|
||||
<div v-for="task in tasks" :key="task.name" class="task-card">
|
||||
<van-cell-group inset>
|
||||
<van-cell :title="task.jobDescription" :label="task.triggerDescription || task.name">
|
||||
<template #value>
|
||||
<van-tag :type="task.status === 'Paused' ? 'warning' : 'success'">
|
||||
{{ task.status === 'Paused' ? '已暂停' : '已启动' }}
|
||||
</van-tag>
|
||||
</template>
|
||||
</van-cell>
|
||||
<van-cell title="任务标识" :value="task.name" />
|
||||
<van-cell title="下次执行" :value="task.nextRunTime || '无'" />
|
||||
<div class="card-footer">
|
||||
<van-row gutter="10">
|
||||
<van-col span="12">
|
||||
<van-button
|
||||
type="primary"
|
||||
size="small"
|
||||
block
|
||||
icon="play"
|
||||
@click="handleExecute(task)"
|
||||
>
|
||||
立即执行
|
||||
</van-button>
|
||||
</van-col>
|
||||
<van-col span="12">
|
||||
<van-button
|
||||
v-if="task.status !== 'Paused'"
|
||||
type="warning"
|
||||
size="small"
|
||||
block
|
||||
icon="pause"
|
||||
@click="handlePause(task)"
|
||||
>
|
||||
暂停任务
|
||||
</van-button>
|
||||
<van-button
|
||||
v-else
|
||||
type="success"
|
||||
size="small"
|
||||
block
|
||||
icon="play-circle-o"
|
||||
@click="handleResume(task)"
|
||||
>
|
||||
恢复任务
|
||||
</van-button>
|
||||
</van-col>
|
||||
</van-row>
|
||||
</div>
|
||||
</van-cell-group>
|
||||
</div>
|
||||
</van-pull-refresh>
|
||||
|
||||
<van-empty v-if="tasks.length === 0 && !loading" description="无定时任务" />
|
||||
|
||||
<!-- 底部安全距离 -->
|
||||
<div style="height: calc(20px + env(safe-area-inset-bottom, 0px))"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { showConfirmDialog, showSuccessToast, showToast, showLoadingToast, closeToast } from 'vant'
|
||||
import { getJobs, executeJob, pauseJob, resumeJob } from '@/api/job'
|
||||
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const tasks = ref([])
|
||||
|
||||
const fetchTasks = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const { success, data, message } = await getJobs()
|
||||
if (success) {
|
||||
tasks.value = data
|
||||
} else {
|
||||
showToast(message || '获取任务列表失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取任务列表失败:', error)
|
||||
showToast('获取任务列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchTasks()
|
||||
})
|
||||
|
||||
const onClickLeft = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
const handleExecute = async (task) => {
|
||||
try {
|
||||
await showConfirmDialog({
|
||||
title: '确认执行',
|
||||
message: `确定要立即执行"${task.jobDescription}"吗?`,
|
||||
})
|
||||
|
||||
showLoadingToast({
|
||||
message: '执行中...',
|
||||
forbidClick: true,
|
||||
duration: 0
|
||||
})
|
||||
|
||||
const { success, message } = await executeJob(task.name)
|
||||
if (success) {
|
||||
showSuccessToast('执行指令已发送')
|
||||
setTimeout(fetchTasks, 1000)
|
||||
} else {
|
||||
showToast(message || '执行失败')
|
||||
}
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('执行失败:', error)
|
||||
showToast('执行失败')
|
||||
}
|
||||
} finally {
|
||||
closeToast()
|
||||
}
|
||||
}
|
||||
|
||||
const handlePause = async (task) => {
|
||||
try {
|
||||
await showConfirmDialog({
|
||||
title: '确认暂停',
|
||||
message: `确定要暂停"${task.jobDescription}"吗?`,
|
||||
})
|
||||
|
||||
const { success, message } = await pauseJob(task.name)
|
||||
if (success) {
|
||||
showSuccessToast('已暂停')
|
||||
fetchTasks()
|
||||
} else {
|
||||
showToast(message || '暂停失败')
|
||||
}
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('暂停失败:', error)
|
||||
showToast('暂停失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleResume = async (task) => {
|
||||
try {
|
||||
const { success, message } = await resumeJob(task.name)
|
||||
if (success) {
|
||||
showSuccessToast('已恢复')
|
||||
fetchTasks()
|
||||
} else {
|
||||
showToast(message || '恢复失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('恢复失败:', error)
|
||||
showToast('恢复失败')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.task-card {
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
padding: 10px 16px;
|
||||
background-color: var(--van-background-2);
|
||||
}
|
||||
|
||||
.scroll-content {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -42,6 +42,7 @@
|
||||
<van-cell-group inset>
|
||||
<van-cell title="查看日志" is-link @click="handleLogView" />
|
||||
<van-cell title="清除缓存" is-link @click="handleReloadFromNetwork" />
|
||||
<van-cell title="定时任务" is-link @click="handleScheduledTasks" />
|
||||
</van-cell-group>
|
||||
|
||||
<div class="detail-header" style="padding-bottom: 5px;">
|
||||
@@ -291,6 +292,10 @@ const handleReloadFromNetwork = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleScheduledTasks = () => {
|
||||
router.push({ name: 'scheduled-tasks' })
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user