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