refactor(plan): 统一使用 MaaPlanConfig 作为默认计划类型
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { PlanCreateIn, PlanDeleteIn, PlanGetIn, PlanReorderIn, PlanUpdateIn } from '../api'
|
||||
import { Service } from '../api'
|
||||
import type { PlanCreateIn, PlanGetIn, PlanUpdateIn, PlanDeleteIn, PlanReorderIn } from '../api'
|
||||
|
||||
export function usePlanApi() {
|
||||
const loading = ref(false)
|
||||
@@ -26,10 +26,12 @@ export function usePlanApi() {
|
||||
const createPlan = async (type: string) => {
|
||||
loading.value = true
|
||||
try {
|
||||
if (type === 'MaaPlanConfig') {
|
||||
type = 'MaaPlan'
|
||||
}
|
||||
const params: PlanCreateIn = { type }
|
||||
const response = await Service.addPlanApiPlanAddPost(params)
|
||||
// message.success('创建计划成功')
|
||||
return response
|
||||
return await Service.addPlanApiPlanAddPost(params)
|
||||
} catch (error) {
|
||||
console.error('创建计划失败:', error)
|
||||
message.error('创建计划失败')
|
||||
@@ -44,9 +46,8 @@ export function usePlanApi() {
|
||||
loading.value = true
|
||||
try {
|
||||
const params: PlanUpdateIn = { planId, data }
|
||||
const response = await Service.updatePlanApiPlanUpdatePost(params)
|
||||
// message.success('更新计划成功')
|
||||
return response
|
||||
return await Service.updatePlanApiPlanUpdatePost(params)
|
||||
} catch (error) {
|
||||
console.error('更新计划失败:', error)
|
||||
message.error('更新计划失败')
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<a-dropdown>
|
||||
<template #overlay>
|
||||
<a-menu @click="handleMenuClick">
|
||||
<a-menu-item key="MaaPlan">
|
||||
<a-menu-item key="MaaPlanConfig">
|
||||
<PlusOutlined />
|
||||
新建 MAA 计划
|
||||
</a-menu-item>
|
||||
@@ -54,7 +54,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { DeleteOutlined, DownOutlined, PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { ref, computed } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
interface Plan {
|
||||
id: string
|
||||
@@ -69,6 +69,7 @@ interface Props {
|
||||
|
||||
interface Emits {
|
||||
(e: 'add-plan', planType: string): void
|
||||
|
||||
(e: 'remove-plan', planId: string): void
|
||||
}
|
||||
|
||||
@@ -76,12 +77,12 @@ defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
// 默认计划类型
|
||||
const selectedPlanType = ref('MaaPlan')
|
||||
const selectedPlanType = ref('MaaPlanConfig')
|
||||
|
||||
// 根据选择的计划类型获取按钮文本
|
||||
const getPlanButtonText = computed(() => {
|
||||
switch (selectedPlanType.value) {
|
||||
case 'MaaPlan':
|
||||
case 'MaaPlanConfig':
|
||||
return '新建 MAA 计划'
|
||||
case 'GeneralPlan':
|
||||
return '新建通用计划'
|
||||
|
||||
@@ -83,18 +83,11 @@ const shouldShowPlanTypeTag = (plan: Plan) => {
|
||||
const allSameType = props.planList.every(p => p.type === firstType)
|
||||
|
||||
// 如果所有计划类型相同,则不显示任何标签
|
||||
if (allSameType) {
|
||||
return false
|
||||
}
|
||||
|
||||
// 如果存在不同类型的计划,则只显示非默认类型(MaaPlanConfig)的标签
|
||||
const normalizedPlanType = plan.type === 'MaaPlan' ? 'MaaPlanConfig' : plan.type
|
||||
return normalizedPlanType !== 'MaaPlanConfig'
|
||||
return !allSameType
|
||||
}
|
||||
|
||||
const getPlanTypeLabel = (planType: string) => {
|
||||
// 统一使用 MaaPlanConfig 作为默认类型
|
||||
const normalizedPlanType = planType === 'MaaPlan' ? 'MaaPlanConfig' : planType
|
||||
const normalizedPlanType = planType
|
||||
const labelMap: Record<string, string> = {
|
||||
MaaPlanConfig: 'MAA',
|
||||
GeneralPlan: '通用',
|
||||
|
||||
@@ -107,8 +107,7 @@ const tableData = ref<Record<string, any>>({})
|
||||
const currentTableComponent = computed(() => {
|
||||
const currentPlan = planList.value.find(plan => plan.id === activePlanId.value)
|
||||
// 统一使用 MaaPlanConfig 作为默认类型
|
||||
const planType =
|
||||
currentPlan?.type === 'MaaPlan' ? 'MaaPlanConfig' : currentPlan?.type || 'MaaPlanConfig'
|
||||
const planType = currentPlan?.type
|
||||
switch (planType) {
|
||||
case 'MaaPlanConfig':
|
||||
return MaaPlanTable
|
||||
@@ -292,7 +291,7 @@ const initPlans = async () => {
|
||||
planList.value = response.index.map((item: any) => {
|
||||
const planId = item.uid
|
||||
const planData = response.data[planId]
|
||||
const planType = item.type === 'MaaPlan' ? 'MaaPlanConfig' : item.type || 'MaaPlanConfig'
|
||||
const planType = item.type
|
||||
const planName = planData?.Info?.Name || getDefaultPlanName(planType)
|
||||
return { id: planId, name: planName, type: planType }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user