修改枚举

This commit is contained in:
2025-11-06 20:55:04 +08:00
parent d898d1eb48
commit 3c8044efa2
11 changed files with 38 additions and 92 deletions

View File

@@ -65,9 +65,9 @@
placement="top"
>
<el-card>
<h5>{{ task.name }} ({{ task.type === 'waiting' ? '延时任务' : '未知任务' }})</h5>
<h5>{{ task.name }} ({{ task.type === TaskType.WAITING ? '延时任务' : '未知任务' }})</h5>
<p>{{ task.description }}</p>
<p v-if="task.type === 'waiting' && task.parameters?.delay_duration">
<p v-if="task.type === TaskType.WAITING && task.parameters?.delay_duration">
延时: {{ task.parameters.delay_duration }}
</p>
<el-button-group v-if="isEditingContent">
@@ -155,7 +155,7 @@
<el-select v-model="currentTaskForm.type" placeholder="请选择任务类型" style="width: 100%;"
:disabled="isEditingTask || plan.plan_type === '系统任务'">
<!-- Only Delay Task for now -->
<el-option label="延时任务" value="delay_task"></el-option>
<el-option label="延时任务" :value="TaskType.WAITING"></el-option>
</el-select>
</el-form-item>
<el-form-item label="任务名称" prop="name">
@@ -167,7 +167,7 @@
:disabled="plan.plan_type === '系统任务'"></el-input>
</el-form-item>
<!-- Dynamic task component for specific parameters -->
<template v-if="currentTaskForm.type === 'delay_task'">
<template v-if="currentTaskForm.type === TaskType.WAITING">
<DelayTaskEditor
:parameters="currentTaskForm.parameters"
@update:parameters="val => currentTaskForm.parameters = val"
@@ -193,6 +193,7 @@ import apiClient from '../api/index.js';
import {ElMessage, ElMessageBox} from 'element-plus';
import {ArrowDown} from '@element-plus/icons-vue';
import DelayTaskEditor from './tasks/DelayTask.vue';
import { PlanTypeFilter, TaskType } from '../enums.js';
export default {
name: 'PlanDetail',
@@ -239,7 +240,7 @@ export default {
isEditingTask: false,
editingTaskOriginalId: null,
currentTaskForm: {
type: 'delay_task',
type: TaskType.WAITING,
name: '',
description: '',
parameters: {},
@@ -249,6 +250,7 @@ export default {
name: [{required: true, message: '请输入任务名称', trigger: 'blur'}],
// Rule for delay_duration will be added/removed dynamically
},
TaskType,
};
},
computed: {
@@ -267,7 +269,7 @@ export default {
},
'currentTaskForm.type'(newType) {
console.log("PlanDetail: currentTaskForm.type changed to", newType);
if (newType === 'delay_task') {
if (newType === TaskType.WAITING) {
this.taskFormRules['parameters.delay_duration'] = this.delayDurationRules;
} else {
if (this.taskFormRules['parameters.delay_duration']) {
@@ -376,7 +378,7 @@ export default {
},
async fetchAvailablePlans() {
try {
const response = await apiClient.plans.getPlans({plan_type: '自定义任务', page: 1, page_size: 1000});
const response = await apiClient.plans.getPlans({plan_type: PlanTypeFilter.CUSTOM, page: 1, page_size: 1000});
this.availablePlans = response.data.plans.filter(p =>
p.id !== this.planId
);
@@ -447,7 +449,7 @@ export default {
},
prepareTaskForm(task = null) {
// Reset properties of the existing reactive object
this.currentTaskForm.type = 'delay_task';
this.currentTaskForm.type = TaskType.WAITING;
this.currentTaskForm.name = '';
this.currentTaskForm.description = '';
@@ -455,7 +457,7 @@ export default {
this.isEditingTask = true;
this.editingTaskOriginalId = task.id;
// Update properties of the existing reactive object
this.currentTaskForm.type = task.type === 'waiting' ? 'delay_task' : task.type; // Convert backend type to UI type
this.currentTaskForm.type = task.type === TaskType.WAITING ? TaskType.WAITING : task.type; // Convert backend type to UI type
this.currentTaskForm.name = task.name;
this.currentTaskForm.description = task.description;
// Deep copy parameters to ensure reactivity for nested changes
@@ -477,7 +479,7 @@ export default {
delete this.taskFormRules['parameters.delay_duration'];
}
// Apply rules based on current type
if (this.currentTaskForm.type === 'delay_task') {
if (this.currentTaskForm.type === TaskType.WAITING) {
this.taskFormRules['parameters.delay_duration'] = this.delayDurationRules;
}
console.log("PlanDetail: Updated taskFormRules:", JSON.parse(JSON.stringify(this.taskFormRules)));
@@ -496,7 +498,7 @@ export default {
...this.plan.tasks[index], // Keep existing properties
name: this.currentTaskForm.name,
description: this.currentTaskForm.description,
type: this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type,
type: this.currentTaskForm.type,
parameters: {...this.currentTaskForm.parameters}, // Deep copy parameters to ensure new reference
};
this.plan.tasks.splice(index, 1, updatedTask); // Replace the old task with the new one
@@ -509,7 +511,7 @@ export default {
const newTask = {
id: Date.now(),
execution_order: this.plan.tasks.length + 1,
type: this.currentTaskForm.type === 'delay_task' ? 'waiting' : this.currentTaskForm.type,
type: this.currentTaskForm.type,
name: this.currentTaskForm.name,
description: this.currentTaskForm.description,
parameters: {...this.currentTaskForm.parameters}, // Deep copy parameters to ensure new reference
@@ -529,7 +531,7 @@ export default {
this.isEditingTask = false;
this.editingTaskOriginalId = null;
// Manually reset properties to ensure clean state for next use
this.currentTaskForm.type = 'delay_task';
this.currentTaskForm.type = TaskType.WAITING;
this.currentTaskForm.name = '';
this.currentTaskForm.description = '';
this.currentTaskForm.parameters = {};

View File

@@ -11,6 +11,7 @@
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getMedicationLogs } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { MedicationReasonType } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchMedicationLogs = async (params) => {
@@ -50,11 +51,7 @@ const medicationLogColumns = [
dataIndex: 'reason',
key: 'reason',
filterType: 'select',
filterOptions: [
{ text: '预防', value: '预防' },
{ text: '治疗', value: '治疗' },
{ text: '保健', value: '保健' },
],
filterOptions: Object.values(MedicationReasonType).map(value => ({ text: value, value: value })),
minWidth: 120,
},
{

View File

@@ -9,8 +9,9 @@
<script setup>
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getNotifications, ZapcoreLevel } from '../../api/monitor.js';
import { getNotifications } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { NotifierType, NotificationStatus, ZapcoreLevel } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchNotifications = async (params) => {
@@ -32,12 +33,7 @@ const notificationLogColumns = [
dataIndex: 'notifier_type',
key: 'notifier_type',
filterType: 'select',
filterOptions: [
{ value: '邮件', text: '邮件' },
{ value: '企业微信', text: '企业微信' },
{ value: '飞书', text: '飞书' },
{ value: '日志', text: '日志' },
],
filterOptions: Object.values(NotifierType).map(value => ({ text: value, value: value })),
minWidth: 120,
},
{
@@ -80,11 +76,7 @@ const notificationLogColumns = [
dataIndex: 'status',
key: 'status',
filterType: 'select',
filterOptions: [
{ value: '发送成功', text: '发送成功' },
{ value: '发送失败', text: '发送失败' },
{ value: '已跳过', text: '已跳过' },
],
filterOptions: Object.values(NotificationStatus).map(value => ({ text: value, value: value })),
minWidth: 120,
},
{

View File

@@ -11,6 +11,7 @@
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getPendingCollections } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { PendingCollectionStatus } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchPendingCollections = async (params) => {
@@ -38,11 +39,7 @@ const pendingCollectionColumns = [
dataIndex: 'status',
key: 'status',
filterType: 'select',
filterOptions: [
{ text: '等待中', value: '等待中' },
{ text: '已完成', value: '已完成' },
{ text: '已超时', value: '已超时' },
],
filterOptions: Object.values(PendingCollectionStatus).map(value => ({ text: value, value: value })),
minWidth: 120,
},
{

View File

@@ -11,6 +11,7 @@
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getPigBatchLogs } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { LogChangeType } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchPigBatchLogs = async (params) => {
@@ -39,15 +40,7 @@ const pigBatchLogColumns = [
dataIndex: 'change_type',
key: 'change_type',
filterType: 'select',
filterOptions: [
{ text: '死亡', value: '死亡' },
{ text: '淘汰', value: '淘汰' },
{ text: '销售', value: '销售' },
{ text: '购买', value: '购买' },
{ text: '转入', value: '转入' },
{ text: '转出', value: '转出' },
{ text: '盘点校正', value: '盘点校正' },
],
filterOptions: Object.values(LogChangeType).map(value => ({ text: value, value: value })),
minWidth: 120,
},
{

View File

@@ -11,6 +11,7 @@
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getPigSickLogs } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { PigBatchSickPigReasonType, PigBatchSickPigTreatmentLocation } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchPigSickLogs = async (params) => {
@@ -47,15 +48,7 @@ const pigSickLogColumns = [
dataIndex: 'reason',
key: 'reason',
filterType: 'select',
filterOptions: [
{ text: '患病', value: '患病' },
{ text: '康复', value: '康复' },
{ text: '死亡', value: '死亡' },
{ text: '淘汰', value: '淘汰' },
{ text: '转入', value: '转入' },
{ text: '转出', value: '转出' },
{ text: '其他', value: '其他' },
],
filterOptions: Object.values(PigBatchSickPigReasonType).map(value => ({ text: value, value: value })),
minWidth: 120,
},
{
@@ -63,10 +56,7 @@ const pigSickLogColumns = [
dataIndex: 'treatment_location',
key: 'treatment_location',
filterType: 'select',
filterOptions: [
{ text: '原地治疗', value: '原地治疗' },
{ text: '病猪栏治疗', value: '病猪栏治疗' },
],
filterOptions: Object.values(PigBatchSickPigTreatmentLocation).map(value => ({ text: value, value: value })),
minWidth: 130,
},
{

View File

@@ -11,6 +11,7 @@
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getPigTransferLogs } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { PigTransferType } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchPigTransferLogs = async (params) => {
@@ -47,15 +48,7 @@ const pigTransferLogColumns = [
dataIndex: 'type',
key: 'type',
filterType: 'select',
filterOptions: [
{ text: '群内调栏', value: '群内调栏' },
{ text: '跨群调栏', value: '跨群调栏' },
{ text: '销售', value: '销售' },
{ text: '死亡', value: '死亡' },
{ text: '淘汰', value: '淘汰' },
{ text: '新购入', value: '新购入' },
{ text: '产房转入', value: '产房转入' },
],
filterOptions: Object.values(PigTransferType).map(value => ({ text: value, value: value })),
minWidth: 130,
},
{

View File

@@ -11,6 +11,7 @@
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getPlanExecutionLogs } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { ExecutionStatus } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchPlanExecutionLogs = async (params) => {
@@ -45,13 +46,7 @@ const planExecutionLogColumns = [
dataIndex: 'status',
key: 'status',
filterType: 'select',
filterOptions: [
{ text: '已开始', value: '已开始' },
{ text: '已完成', value: '已完成' },
{ text: '失败', value: '失败' },
{ text: '已取消', value: '已取消' },
{ text: '等待中', value: '等待中' },
],
filterOptions: Object.values(ExecutionStatus).map(value => ({ text: value, value: value })),
minWidth: 120,
},
{

View File

@@ -11,6 +11,7 @@
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getRawMaterialStockLogs } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { StockLogSourceType } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchRawMaterialStockLogs = async (params) => {
@@ -39,14 +40,7 @@ const rawMaterialStockLogColumns = [
dataIndex: 'source_type',
key: 'source_type',
filterType: 'select',
filterOptions: [
{ text: '采购入库', value: '采购入库' },
{ text: '饲喂出库', value: '饲喂出库' },
{ text: '变质出库', value: '变质出库' },
{ text: '售卖出库', value: '售卖出库' },
{ text: '杂用领取', value: '杂用领取' },
{ text: '手动盘点', value: '手动盘点' },
],
filterOptions: Object.values(StockLogSourceType).map(value => ({ text: value, value: value })),
minWidth: 130,
},
{

View File

@@ -11,6 +11,7 @@
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getTaskExecutionLogs } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { ExecutionStatus } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchTaskExecutionLogs = async (params) => {
@@ -53,13 +54,7 @@ const taskExecutionLogColumns = [
dataIndex: 'status',
key: 'status',
filterType: 'select',
filterOptions: [
{ text: '已开始', value: '已开始' },
{ text: '已完成', value: '已完成' },
{ text: '失败', value: '失败' },
{ text: '已取消', value: '已取消' },
{ text: '等待中', value: '等待中' },
],
filterOptions: Object.values(ExecutionStatus).map(value => ({ text: value, value: value })),
minWidth: 120,
},
{

View File

@@ -11,6 +11,7 @@
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getUserActionLogs } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
import { AuditStatus } from '../../enums.js';
// 适配通用组件的 fetchData prop
const fetchUserActionLogs = async (params) => {
@@ -53,10 +54,7 @@ const userActionLogColumns = [
dataIndex: 'status',
key: 'status',
filterType: 'select',
filterOptions: [
{ text: '成功', value: '成功' },
{ text: '失败', value: '失败' },
],
filterOptions: Object.values(AuditStatus).map(value => ({ text: value, value: value })),
minWidth: 100,
},
{