修改枚举

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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