feat(plan):重构计划管理页面并新增 MAA 计划表组件

将原 Plans.vue 页面重构为 plan/index.vue
This commit is contained in:
MoeSnowyFox
2025-09-21 23:12:18 +08:00
parent d5331b728d
commit db0ac79e44
7 changed files with 1559 additions and 2120 deletions

View File

@@ -68,7 +68,7 @@ const routes: RouteRecordRaw[] = [
{
path: '/plans',
name: 'Plans',
component: () => import('../views/Plans.vue'),
component: () => import('../views/plan/index.vue'),
meta: { title: '计划管理' },
},
{

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,171 @@
<template>
<a-card class="plan-config-card" :bordered="false">
<template #title>
<div class="plan-title-container">
<div v-if="!isEditingPlanName" class="plan-title-display">
<span class="plan-title-text">{{ currentPlanName || '计划配置' }}</span>
<a-button
type="text"
size="small"
@click="$emit('start-edit-plan-name')"
class="plan-edit-btn"
>
<template #icon>
<EditOutlined />
</template>
</a-button>
</div>
<div v-else class="plan-title-edit">
<a-input
:value="currentPlanName"
@update:value="$emit('update:current-plan-name', $event)"
placeholder="请输入计划名称"
class="plan-title-input"
@blur="$emit('finish-edit-plan-name')"
@pressEnter="$emit('finish-edit-plan-name')"
:maxlength="50"
ref="planNameInputRef"
/>
</div>
</div>
</template>
<template #extra>
<a-space>
<span class="mode-label">执行模式</span>
<a-segmented
:value="currentMode"
@change="handleModeChange"
:options="[
{ label: '全局模式', value: 'ALL' },
{ label: '周计划模式', value: 'Weekly' },
]"
/>
<span class="view-label">视图</span>
<a-segmented
:value="viewMode"
@change="$emit('update:view-mode', $event)"
:options="[
{ label: '配置视图', value: 'config' },
{ label: '简化视图', value: 'simple' },
]"
/>
</a-space>
</template>
<!-- 配置表格容器 -->
<div class="config-table-container">
<slot />
</div>
</a-card>
</template>
<script setup lang="ts">
import { EditOutlined } from '@ant-design/icons-vue'
interface Props {
currentPlanName: string
currentMode: 'ALL' | 'Weekly'
viewMode: 'config' | 'simple'
isEditingPlanName: boolean
}
interface Emits {
(e: 'update:current-plan-name', value: string): void
(e: 'update:current-mode', value: 'ALL' | 'Weekly'): void
(e: 'update:view-mode', value: 'config' | 'simple'): void
(e: 'start-edit-plan-name'): void
(e: 'finish-edit-plan-name'): void
(e: 'mode-change'): void
}
defineProps<Props>()
const emit = defineEmits<Emits>()
const handleModeChange = (value: 'ALL' | 'Weekly') => {
emit('update:current-mode', value)
emit('mode-change')
}
</script>
<style scoped>
.plan-config-card {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
border-radius: 12px;
border: 1px solid var(--ant-color-border-secondary);
}
.mode-label,
.view-label {
color: var(--ant-color-text-secondary);
font-size: 14px;
font-weight: 500;
}
.plan-title-container {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
}
.plan-title-display {
display: flex;
align-items: center;
gap: 8px;
}
.plan-title-text {
font-size: 18px;
font-weight: 600;
color: var(--ant-color-text);
}
.plan-edit-btn {
color: var(--ant-color-primary);
padding: 0;
}
.plan-title-input {
flex: 1;
max-width: 400px;
border-radius: 8px;
transition: all 0.2s ease;
}
.config-table-container {
border-radius: 8px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
}
/* 深度样式 */
.plan-config-card :deep(.ant-card-head) {
border-bottom: 1px solid var(--ant-color-border-secondary);
padding: 16px 24px;
}
.plan-config-card :deep(.ant-card-head-title) {
font-size: 18px;
font-weight: 600;
}
.plan-title-input :deep(.ant-input) {
font-size: 16px;
font-weight: 500;
}
.plan-title-input :deep(.ant-input:focus) {
box-shadow: 0 0 0 2px var(--ant-color-primary);
}
@media (max-width: 768px) {
.plan-title-input {
max-width: 100%;
}
}
</style>

View File

@@ -0,0 +1,134 @@
<template>
<div class="plans-header">
<div class="header-left">
<h1 class="page-title">计划管理</h1>
</div>
<div class="header-actions">
<a-space size="middle">
<!-- 新建计划下拉菜单 -->
<a-dropdown>
<template #overlay>
<a-menu @click="handleMenuClick">
<a-menu-item key="MaaPlan">
<PlusOutlined />
新建 MAA 计划
</a-menu-item>
<!-- 预留其他计划类型 -->
<!-- <a-menu-item key="GeneralPlan">
<PlusOutlined />
新建通用计划
</a-menu-item>
<a-menu-item key="CustomPlan">
<PlusOutlined />
新建自定义计划
</a-menu-item> -->
</a-menu>
</template>
<a-button type="primary" size="large">
<template #icon>
<PlusOutlined />
</template>
新建计划
<DownOutlined />
</a-button>
</a-dropdown>
<a-popconfirm
v-if="planList.length > 0"
title="确定要删除这个计划吗?"
ok-text="确定"
cancel-text="取消"
@confirm="$emit('remove-plan', activePlanId)"
>
<a-button danger size="large" :disabled="!activePlanId">
<template #icon>
<DeleteOutlined />
</template>
删除当前计划
</a-button>
</a-popconfirm>
</a-space>
</div>
</div>
</template>
<script setup lang="ts">
import { DeleteOutlined, DownOutlined, PlusOutlined } from '@ant-design/icons-vue'
interface Plan {
id: string
name: string
type: string
}
interface Props {
planList: Plan[]
activePlanId: string
}
interface Emits {
(e: 'add-plan', planType: string): void
(e: 'remove-plan', planId: string): void
}
defineProps<Props>()
const emit = defineEmits<Emits>()
const handleMenuClick = ({ key }: { key: string }) => {
emit('add-plan', key)
}
</script>
<style scoped>
.plans-header {
display: flex;
justify-content: space-between;
align-items: flex-end;
margin-bottom: 24px;
padding: 0 4px;
}
.header-left {
flex: 1;
}
.page-title {
margin: 0 0 8px 0;
font-size: 32px;
font-weight: 700;
color: var(--ant-color-text);
background: linear-gradient(135deg, var(--ant-color-primary), var(--ant-color-primary-hover));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.header-actions {
flex-shrink: 0;
}
@media (max-width: 1200px) {
.plans-header {
flex-direction: column;
align-items: flex-start;
gap: 16px;
}
.page-title {
font-size: 28px;
}
}
@media (max-width: 768px) {
.page-title {
font-size: 24px;
}
.header-actions {
width: 100%;
display: flex;
justify-content: center;
}
}
</style>

View File

@@ -0,0 +1,112 @@
<template>
<a-card class="plan-selector-card" :bordered="false">
<template #title>
<div class="card-title">
<span>计划选择</span>
<a-tag :color="planList.length > 0 ? 'success' : 'default'">
{{ planList.length }} 个计划
</a-tag>
</div>
</template>
<div class="plan-selection-container">
<!-- 计划按钮组 -->
<div class="plan-buttons-container">
<a-space wrap size="middle">
<a-button
v-for="plan in planList"
:key="plan.id"
:type="activePlanId === plan.id ? 'primary' : 'default'"
size="large"
@click="$emit('plan-change', plan.id)"
class="plan-button"
>
<span class="plan-name">{{ plan.name }}</span>
<a-tag v-if="plan.type !== 'MaaPlan'" size="small" color="blue" class="plan-type-tag">
{{ getPlanTypeLabel(plan.type) }}
</a-tag>
</a-button>
</a-space>
</div>
</div>
</a-card>
</template>
<script setup lang="ts">
interface Plan {
id: string
name: string
type: string
}
interface Props {
planList: Plan[]
activePlanId: string
}
interface Emits {
(e: 'plan-change', planId: string): void
}
defineProps<Props>()
defineEmits<Emits>()
const getPlanTypeLabel = (planType: string) => {
const labelMap: Record<string, string> = {
MaaPlan: 'MAA',
GeneralPlan: '通用',
CustomPlan: '自定义',
}
return labelMap[planType] || planType
}
</script>
<style scoped>
.plan-selector-card {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
border-radius: 12px;
border: 1px solid var(--ant-color-border-secondary);
}
.card-title {
display: flex;
align-items: center;
gap: 12px;
font-size: 18px;
font-weight: 600;
}
.plan-selection-container {
padding: 16px;
}
.plan-buttons-container {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
.plan-button {
flex: 1 1 120px;
border-radius: 8px;
transition: all 0.2s ease;
display: flex;
align-items: center;
gap: 8px;
}
.plan-name {
flex: 1;
}
.plan-type-tag {
margin: 0;
}
/* 深度样式 */
.plan-selector-card :deep(.ant-card-head) {
border-bottom: 1px solid var(--ant-color-border-secondary);
padding: 16px 24px;
}
</style>

View File

@@ -0,0 +1,420 @@
<template>
<!-- 加载状态 -->
<div v-if="loading" class="loading-container">
<a-spin size="large" tip="加载中,请稍候..." />
</div>
<!-- 主要内容 -->
<div v-else class="plans-main">
<!-- 页面头部 -->
<PlanHeader
:plan-list="planList"
:active-plan-id="activePlanId"
@add-plan="handleAddPlan"
@remove-plan="handleRemovePlan"
/>
<!-- 空状态 -->
<div v-if="!planList.length || !currentPlanData" class="empty-state">
<div class="empty-content">
<div class="empty-image-container">
<img src="@/assets/NoData.png" alt="暂无数据" class="empty-image" />
</div>
<div class="empty-text-content">
<h3 class="empty-title">暂无计划</h3>
<p class="empty-description">您还没有创建任何计划</p>
</div>
</div>
</div>
<!-- 计划内容 -->
<div v-else class="plans-content">
<!-- 计划选择器 -->
<PlanSelector
:plan-list="planList"
:active-plan-id="activePlanId"
@plan-change="onPlanChange"
/>
<!-- 计划配置 -->
<PlanConfig
:current-plan-name="currentPlanName"
:current-mode="currentMode"
:view-mode="viewMode"
:is-editing-plan-name="isEditingPlanName"
@update:current-plan-name="currentPlanName = $event"
@update:current-mode="currentMode = $event"
@update:view-mode="viewMode = $event"
@start-edit-plan-name="startEditPlanName"
@finish-edit-plan-name="finishEditPlanName"
@mode-change="onModeChange"
>
<!-- 动态渲染不同类型的表格 -->
<component
:is="currentTableComponent"
:table-data="tableData"
:current-mode="currentMode"
:view-mode="viewMode"
@update-table-data="handleTableDataUpdate"
/>
</PlanConfig>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, nextTick, onMounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { message } from 'ant-design-vue'
import { usePlanApi } from '@/composables/usePlanApi'
import PlanHeader from './components/PlanHeader.vue'
import PlanSelector from './components/PlanSelector.vue'
import PlanConfig from './components/PlanConfig.vue'
import MaaPlanTable from './tables/MaaPlanTable.vue'
// import GeneralPlanTable from './tables/GeneralPlanTable.vue'
// import CustomPlanTable from './tables/CustomPlanTable.vue'
interface PlanData {
[key: string]: any
Info?: {
Mode: 'ALL' | 'Weekly'
Name: string
Type?: string
}
}
const { getPlans, createPlan, updatePlan, deletePlan } = usePlanApi()
const route = useRoute()
const planList = ref<Array<{ id: string; name: string; type: string }>>([])
const activePlanId = ref<string>('')
const currentPlanData = ref<PlanData | null>(null)
const currentPlanName = ref<string>('')
const currentMode = ref<'ALL' | 'Weekly'>('ALL')
const viewMode = ref<'config' | 'simple'>('config')
const isEditingPlanName = ref<boolean>(false)
const loading = ref(true)
// Use a record to match child component expectations
const tableData = ref<Record<string, any>>({})
const currentTableComponent = computed(() => {
const currentPlan = planList.value.find(plan => plan.id === activePlanId.value)
const planType = currentPlan?.type || 'MaaPlan'
switch (planType) {
case 'MaaPlan':
return MaaPlanTable
default:
return MaaPlanTable
}
})
const handleAddPlan = async (planType: string = 'MaaPlan') => {
try {
const response = await createPlan(planType)
const defaultName = getDefaultPlanName(planType)
const newPlan = { id: response.planId, name: defaultName, type: planType }
planList.value.push(newPlan)
activePlanId.value = newPlan.id
currentPlanName.value = defaultName
await loadPlanData(newPlan.id)
message.info(`已创建新的${getPlanTypeLabel(planType)},建议您修改为更有意义的名称`, 3)
} catch (error) {
console.error('添加计划失败:', error)
}
}
const handleRemovePlan = async (planId: string) => {
try {
await deletePlan(planId)
const index = planList.value.findIndex(plan => plan.id === planId)
if (index > -1) {
planList.value.splice(index, 1)
if (activePlanId.value === planId) {
activePlanId.value = planList.value[0]?.id || ''
if (activePlanId.value) {
await loadPlanData(activePlanId.value)
} else {
currentPlanData.value = null
}
}
}
} catch (error) {
console.error('删除计划失败:', error)
}
}
const onPlanChange = async (planId: string) => {
activePlanId.value = planId
await loadPlanData(planId)
}
const startEditPlanName = () => {
isEditingPlanName.value = true
setTimeout(() => {
const input = document.querySelector('.plan-title-input input') as HTMLInputElement
if (input) {
input.focus()
input.select()
}
}, 100)
}
const finishEditPlanName = () => {
isEditingPlanName.value = false
if (activePlanId.value) {
const currentPlan = planList.value.find(plan => plan.id === activePlanId.value)
if (currentPlan) {
currentPlan.name = currentPlanName.value || getDefaultPlanName(currentPlan.type)
}
}
}
const onModeChange = () => {
handleSave()
}
const handleTableDataUpdate = async (newData: Record<string, any>) => {
tableData.value = newData
await nextTick()
handleSave()
}
const loadPlanData = async (planId: string) => {
try {
const response = await getPlans(planId)
currentPlanData.value = response.data
if (response.data && response.data[planId]) {
const planData = response.data[planId] as PlanData
if (planData.Info) {
const apiName = planData.Info.Name || ''
if (!apiName && !currentPlanName.value) {
const currentPlan = planList.value.find(plan => plan.id === planId)
if (currentPlan) currentPlanName.value = currentPlan.name
} else if (apiName) {
currentPlanName.value = apiName
}
currentMode.value = planData.Info.Mode || 'ALL'
}
tableData.value = planData
}
} catch (error) {
console.error('加载计划数据失败:', error)
}
}
const initPlans = async () => {
try {
const response = await getPlans()
if (response.index && response.index.length > 0) {
planList.value = response.index.map((item: any, index: number) => {
const planId = item.uid
const planData = response.data[planId]
const planType = planData?.Info?.Type || 'MaaPlan'
const planName = planData?.Info?.Name || getDefaultPlanName(planType)
return { id: planId, name: planName, type: planType }
})
const queryPlanId = (route.query.planId as string) || ''
const target = queryPlanId ? planList.value.find(p => p.id === queryPlanId) : null
activePlanId.value = target ? target.id : planList.value[0].id
await loadPlanData(activePlanId.value)
} else {
currentPlanData.value = null
}
} catch (error) {
console.error('初始化计划失败:', error)
currentPlanData.value = null
} finally {
loading.value = false
}
}
const savePlanData = async () => {
if (!activePlanId.value) return
try {
const currentPlan = planList.value.find(plan => plan.id === activePlanId.value)
const planType = currentPlan?.type || 'MaaPlan'
// Start from existing tableData, then overwrite Info explicitly
const planData: Record<string, any> = { ...(tableData.value || {}) }
planData.Info = { Mode: currentMode.value, Name: currentPlanName.value, Type: planType }
await updatePlan(activePlanId.value, planData)
} catch (error) {
console.error('保存计划数据失败:', error)
throw error
}
}
const handleSave = async () => {
if (!activePlanId.value) {
message.warning('请先选择一个计划')
return
}
try {
await savePlanData()
} catch (error) {
message.error('保存失败')
}
}
const getDefaultPlanName = (planType: string) =>
(
({
MaaPlan: '新 MAA 计划表',
GeneralPlan: '新通用计划表',
CustomPlan: '新自定义计划表',
}) as Record<string, string>
)[planType] || '新计划表'
const getPlanTypeLabel = (planType: string) =>
(
({
MaaPlan: 'MAA计划表',
GeneralPlan: '通用计划表',
CustomPlan: '自定义计划表',
}) as Record<string, string>
)[planType] || '计划表'
watch(
() => [currentPlanName.value, currentMode.value],
async () => {
await nextTick()
handleSave()
}
)
watch(
() => route.query.planId,
async newPlanId => {
if (!newPlanId) return
const target = planList.value.find(p => p.id === newPlanId)
if (target && target.id !== activePlanId.value) {
activePlanId.value = target.id
await loadPlanData(activePlanId.value)
}
}
)
onMounted(() => {
initPlans()
})
</script>
<style scoped>
.loading-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 400px;
}
.plans-main {
margin: 0 auto;
}
/* 空状态样式 */
.empty-state {
display: flex;
justify-content: center;
align-items: center;
min-height: 500px;
padding: 60px 20px;
background: linear-gradient(135deg, rgba(24, 144, 255, 0.02), rgba(24, 144, 255, 0.01));
border-radius: 16px;
margin: 20px 0;
}
.empty-content {
text-align: center;
max-width: 480px;
animation: fadeInUp 0.8s ease-out;
}
.empty-image-container {
position: relative;
margin-bottom: 32px;
display: inline-block;
}
.empty-image-container::before {
content: '';
position: absolute;
top: -20px;
left: -20px;
right: -20px;
bottom: -20px;
background: radial-gradient(circle, rgba(24, 144, 255, 0.1) 0%, transparent 70%);
border-radius: 50%;
animation: pulse 3s ease-in-out infinite;
}
.empty-image {
max-width: 200px;
height: auto;
opacity: 0.9;
filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.1));
transition: all 0.3s ease;
position: relative;
z-index: 1;
}
.empty-image:hover {
transform: translateY(-4px);
filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.15));
}
.empty-text-content {
margin-top: 16px;
}
.empty-title {
font-size: 24px;
font-weight: 600;
color: var(--ant-color-text);
margin: 0 0 12px 0;
background: linear-gradient(135deg, var(--ant-color-text), var(--ant-color-text-secondary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.empty-description {
font-size: 16px;
color: var(--ant-color-text-secondary);
line-height: 1.6;
margin: 0;
opacity: 0.8;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes pulse {
0%,
100% {
opacity: 0.6;
transform: scale(1);
}
50% {
opacity: 0.8;
transform: scale(1.05);
}
}
.plans-content {
display: flex;
flex-direction: column;
gap: 24px;
}
</style>

View File

@@ -0,0 +1,721 @@
<template>
<div>
<div v-if="viewMode === 'config'" class="config-table-wrapper">
<a-table
:columns="dynamicTableColumns"
:data-source="rows"
:pagination="false"
:class="['config-table', `mode-${currentMode}`]"
size="middle"
:bordered="true"
:scroll="{ x: 'max-content' }"
:row-class-name="(record: TableRow) => `task-row-${record.key}`"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'taskName'">
{{ record.taskName }}
</template>
<template v-else-if="record.taskName === '吃理智药'">
<a-input-number
v-model:value="(record as any)[column.key]"
size="small"
:min="0"
:max="999"
:placeholder="getPlaceholder(record.taskName)"
class="config-input-number"
:controls="false"
:disabled="isColumnDisabled(column.key as string)"
/>
</template>
<template
v-else-if="
['关卡选择', '备选关卡-1', '备选关卡-2', '备选关卡-3', '剩余理智关卡'].includes(
record.taskName
)
"
>
<a-select
v-model:value="(record as any)[column.key]"
size="small"
:placeholder="getPlaceholder(record.taskName)"
:class="[
'config-select',
{
'custom-stage-selected': isCustomStage(
(record as any)[column.key] as string,
column.key as string
),
},
]"
allow-clear
:disabled="isColumnDisabled(column.key as string)"
>
<template #dropdownRender="{ menuNode: menu }">
<v-nodes :vnodes="menu" />
<a-divider style="margin: 4px 0" />
<a-space style="padding: 4px 8px" size="small">
<a-input
v-model:value="customStageNames[`${record.key}_${String(column.key)}`]"
placeholder="自定义"
style="flex: 1"
size="small"
@keyup.enter="addCustomStage(record.key, column.key as string)"
/>
<a-button
type="text"
size="small"
@click="addCustomStage(record.key, column.key as string)"
>
<template #icon>
<PlusOutlined />
</template>
</a-button>
</a-space>
</template>
<a-select-option
v-for="option in getSelectOptions(
column.key as string,
record.taskName,
(record as any)[column.key] as string
)"
:key="option.value"
:value="option.value"
>
<template v-if="option.label && String(option.label).includes('|')">
<span>{{ String(option.label).split('|')[0] }}</span>
<a-tag color="green" size="small" style="margin-left: 8px">
{{ String(option.label).split('|')[1] }}
</a-tag>
</template>
<template v-else>
<span
:style="
isCustomStage(option.value, column.key as string)
? { color: 'var(--ant-color-primary)', fontWeight: '500' }
: {}
"
>
{{ option.label }}
</span>
</template>
</a-select-option>
</a-select>
</template>
<template v-else>
<a-select
v-model:value="(record as any)[column.key]"
size="small"
:options="
getSelectOptions(
column.key as string,
record.taskName,
(record as any)[column.key] as string
)
"
:placeholder="getPlaceholder(record.taskName)"
class="config-select"
allow-clear
:disabled="isColumnDisabled(column.key as string)"
/>
</template>
</template>
</a-table>
</div>
<div v-else class="simple-table-wrapper">
<a-table
:columns="dynamicSimpleViewColumns"
:data-source="simpleViewData"
:pagination="false"
class="simple-table"
size="small"
:bordered="true"
:scroll="{ x: 'max-content' }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'globalControl'">
<a-space>
<a-tooltip title="/关所有可用关卡" placement="left">
<a-button ghost size="small" type="primary" @click="enableAllStages(record.key)"
>开</a-button
>
</a-tooltip>
<a-button size="small" danger @click="disableAllStages(record.key)">关</a-button>
</a-space>
</template>
<template v-else-if="column.key === 'taskName'">
<div class="task-name-cell">
<a-tag :color="getSimpleTaskTagColor(record.taskName)" class="task-tag">{{
record.taskName
}}</a-tag>
</div>
</template>
<template v-else>
<div v-if="isStageAvailable(record.key, column.key as string)">
<a-switch
:checked="isStageEnabled(record.key, column.key as string)"
@change="
(checked: boolean) => toggleStage(record.key, column.key as string, checked)
"
/>
</div>
</template>
</template>
</a-table>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, defineComponent, onMounted, ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { PlusOutlined } from '@ant-design/icons-vue'
interface TableRow {
key: string
taskName: string
ALL: string | number
Monday: string | number
Tuesday: string | number
Wednesday: string | number
Thursday: string | number
Friday: string | number
Saturday: string | number
Sunday: string | number
[key: string]: string | number
}
interface Props {
tableData: Record<string, any> | null
currentMode: 'ALL' | 'Weekly'
viewMode: 'config' | 'simple'
}
interface Emits {
(e: 'update-table-data', value: Record<string, any>): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
// 渲染VNode的辅助组件
const VNodes = defineComponent({
props: { vnodes: { type: Object, required: true } },
setup(p) {
return () => p.vnodes as any
},
})
const rows = ref<TableRow[]>([
{
key: 'MedicineNumb',
taskName: '吃理智药',
ALL: 0,
Monday: 0,
Tuesday: 0,
Wednesday: 0,
Thursday: 0,
Friday: 0,
Saturday: 0,
Sunday: 0,
},
{
key: 'SeriesNumb',
taskName: '连战次数',
ALL: '0',
Monday: '0',
Tuesday: '0',
Wednesday: '0',
Thursday: '0',
Friday: '0',
Saturday: '0',
Sunday: '0',
},
{
key: 'Stage',
taskName: '关卡选择',
ALL: '-',
Monday: '-',
Tuesday: '-',
Wednesday: '-',
Thursday: '-',
Friday: '-',
Saturday: '-',
Sunday: '-',
},
{
key: 'Stage_1',
taskName: '备选关卡-1',
ALL: '-',
Monday: '-',
Tuesday: '-',
Wednesday: '-',
Thursday: '-',
Friday: '-',
Saturday: '-',
Sunday: '-',
},
{
key: 'Stage_2',
taskName: '备选关卡-2',
ALL: '-',
Monday: '-',
Tuesday: '-',
Wednesday: '-',
Thursday: '-',
Friday: '-',
Saturday: '-',
Sunday: '-',
},
{
key: 'Stage_3',
taskName: '备选关卡-3',
ALL: '-',
Monday: '-',
Tuesday: '-',
Wednesday: '-',
Thursday: '-',
Friday: '-',
Saturday: '-',
Sunday: '-',
},
{
key: 'Stage_Remain',
taskName: '剩余理智关卡',
ALL: '-',
Monday: '-',
Tuesday: '-',
Wednesday: '-',
Thursday: '-',
Friday: '-',
Saturday: '-',
Sunday: '-',
},
])
// 列配置
const tableColumns = ref([
{
title: '配置项',
dataIndex: 'taskName',
key: 'taskName',
width: 120,
fixed: 'left',
align: 'center',
className: 'task-name-td',
},
{ title: '全局', dataIndex: 'ALL', key: 'ALL', width: 120, align: 'center' },
{ title: '周一', dataIndex: 'Monday', key: 'Monday', width: 120, align: 'center' },
{ title: '周二', dataIndex: 'Tuesday', key: 'Tuesday', width: 120, align: 'center' },
{ title: '周三', dataIndex: 'Wednesday', key: 'Wednesday', width: 120, align: 'center' },
{ title: '周四', dataIndex: 'Thursday', key: 'Thursday', width: 120, align: 'center' },
{ title: '周五', dataIndex: 'Friday', key: 'Friday', width: 120, align: 'center' },
{ title: '周六', dataIndex: 'Saturday', key: 'Saturday', width: 120, align: 'center' },
{ title: '周日', dataIndex: 'Sunday', key: 'Sunday', width: 120, align: 'center' },
])
const dynamicTableColumns = computed(() => tableColumns.value)
// 简化视图列
const dynamicSimpleViewColumns = computed(() => [
{ title: '全局控制', key: 'globalControl', width: 75, fixed: 'left', align: 'center' },
{
title: '关卡',
dataIndex: 'taskName',
key: 'taskName',
width: 120,
fixed: 'left',
align: 'center',
},
...tableColumns.value.filter(col => col.key !== 'taskName' && col.key !== 'globalControl'),
])
// 关卡日历
const STAGE_DAILY_INFO = [
{ value: '-', text: '当前/上次', days: [1, 2, 3, 4, 5, 6, 7] },
{ value: '1-7', text: '1-7', days: [1, 2, 3, 4, 5, 6, 7] },
{ value: 'R8-11', text: 'R8-11', days: [1, 2, 3, 4, 5, 6, 7] },
{ value: '12-17-HARD', text: '12-17-HARD', days: [1, 2, 3, 4, 5, 6, 7] },
{ value: 'LS-6', text: '经验-6/5', days: [1, 2, 3, 4, 5, 6, 7] },
{ value: 'CE-6', text: '龙门币-6/5', days: [2, 4, 6, 7] },
{ value: 'AP-5', text: '红票-5', days: [1, 4, 6, 7] },
{ value: 'CA-5', text: '技能-5', days: [2, 3, 5, 7] },
{ value: 'SK-5', text: '碳-5', days: [1, 3, 5, 6] },
{ value: 'PR-A-1', text: '奶/盾芯片', days: [1, 4, 5, 7] },
{ value: 'PR-A-2', text: '奶/盾芯片组', days: [1, 4, 5, 7] },
{ value: 'PR-B-1', text: '术/狙芯片', days: [1, 2, 5, 6] },
{ value: 'PR-B-2', text: '术/狙芯片组', days: [1, 2, 5, 6] },
{ value: 'PR-C-1', text: '先/辅芯片', days: [3, 4, 6, 7] },
{ value: 'PR-C-2', text: '先/辅芯片组', days: [3, 4, 6, 7] },
{ value: 'PR-D-1', text: '近/特芯片', days: [2, 3, 6, 7] },
{ value: 'PR-D-2', text: '近/特芯片组', days: [2, 3, 6, 7] },
]
const getDayNumber = (columnKey: string) =>
(
({
ALL: 0,
Monday: 1,
Tuesday: 2,
Wednesday: 3,
Thursday: 4,
Friday: 5,
Saturday: 6,
Sunday: 7,
}) as Record<string, number>
)[columnKey] || 0
// 自定义关卡
const customStageNames = ref<Record<string, string>>({})
const addCustomStage = (rowKey: string, columnKey: string) => {
const inputName = `${rowKey}_${columnKey}`
const customName = customStageNames.value[inputName]
if (!customName || !customName.trim()) {
message.warning('请输入关卡名称')
return
}
const stagePattern = /^[A-Za-z0-9\-_]+$/
if (!stagePattern.test(customName.trim())) {
message.warning('关卡名称只能包含字母、数字、短横线和下划线')
return
}
const exists = stageOptions.value.find(option => option.value === customName.trim())
if (exists) {
message.warning('该关卡已存在')
return
}
customStageNames.value[customName.trim()] = customName.trim()
const targetRow = rows.value.find(row => row.key === rowKey)
if (targetRow) {
;(targetRow as any)[columnKey] = customName.trim()
}
customStageNames.value[inputName] = ''
message.success('关卡添加成功')
}
const stageOptions = computed(() => {
const baseOptions = STAGE_DAILY_INFO.map(stage => ({
label: stage.text,
value: stage.value,
isCustom: false,
}))
const customOptions = Object.keys(customStageNames.value).map(key => ({
label: customStageNames.value[key],
value: key,
isCustom: true,
}))
return [...baseOptions, ...customOptions]
})
const isCustomStage = (value: string, columnKey: string) => {
if (!value || value === '-') return false
const dayNumber = getDayNumber(columnKey)
let availableStages: string[] = []
if (dayNumber === 0) {
availableStages = STAGE_DAILY_INFO.map(stage => stage.value)
} else {
availableStages = STAGE_DAILY_INFO.filter(stage => stage.days.includes(dayNumber)).map(
stage => stage.value
)
}
return !availableStages.includes(value)
}
const getSelectOptions = (columnKey: string, taskName: string, currentValue?: string) => {
switch (taskName) {
case '连战次数':
return [
{ label: 'AUTO', value: '0' },
{ label: '1', value: '1' },
{ label: '2', value: '2' },
{ label: '3', value: '3' },
{ label: '4', value: '4' },
{ label: '5', value: '5' },
{ label: '6', value: '6' },
{ label: '不切换', value: '-1' },
]
case '关卡选择':
case '备选关卡-1':
case '备选关卡-2':
case '备选关卡-3':
case '剩余理智关卡': {
const dayNumber = getDayNumber(columnKey)
let baseOptions: any[] = []
if (dayNumber === 0) {
baseOptions = STAGE_DAILY_INFO.map(stage => ({
label: taskName === '剩余理智关卡' && stage.value === '-' ? '不选择' : stage.text,
value: stage.value,
isCustom: false,
}))
} else {
baseOptions = STAGE_DAILY_INFO.filter(stage => stage.days.includes(dayNumber)).map(
stage => ({
label: taskName === '剩余理智关卡' && stage.value === '-' ? '不选择' : stage.text,
value: stage.value,
isCustom: false,
})
)
}
if (currentValue && isCustomStage(currentValue, columnKey)) {
const exists = baseOptions.some(option => option.value === currentValue)
if (!exists) baseOptions.push({ label: currentValue, value: currentValue, isCustom: true })
}
const customOptions = Object.keys(customStageNames.value)
.filter(key => customStageNames.value[key] && customStageNames.value[key].trim())
.filter(key => !baseOptions.some(option => option.value === customStageNames.value[key]))
.map(key => ({
label: customStageNames.value[key],
value: customStageNames.value[key],
isCustom: true,
}))
return [...baseOptions, ...customOptions]
}
default:
return []
}
}
const getPlaceholder = (taskName: string) => {
switch (taskName) {
case '吃理智药':
return '输入数量'
case '连战次数':
return '选择次数'
case '关卡选择':
case '备选关卡-1':
case '备选关卡-2':
case '备选关卡-3':
return '1-7'
case '剩余理智关卡':
return '不选择'
default:
return '请选择'
}
}
const isColumnDisabled = (columnKey: string): boolean => {
if (props.currentMode === 'ALL') return columnKey !== 'ALL'
if (props.currentMode === 'Weekly') return columnKey === 'ALL'
return false
}
// 简化视图数据
const SIMPLE_VIEW_DATA = STAGE_DAILY_INFO.filter(stage => stage.value !== '-').map(stage => ({
key: stage.value,
taskName: stage.text,
ALL: '-',
Monday: '-',
Tuesday: '-',
Wednesday: '-',
Thursday: '-',
Friday: '-',
Saturday: '-',
Sunday: '-',
}))
const simpleViewData = ref(SIMPLE_VIEW_DATA)
const isStageAvailable = (stageValue: string, columnKey: string) => {
if (columnKey === 'ALL') return true
const dayNumber = getDayNumber(columnKey)
const stage = STAGE_DAILY_INFO.find(s => s.value === stageValue)
return stage ? stage.days.includes(dayNumber) : false
}
const isStageEnabled = (stageValue: string, columnKey: string) => {
const stageSlots = ['Stage', 'Stage_1', 'Stage_2', 'Stage_3']
return stageSlots.some(slot => {
const row = rows.value.find(r => r.key === slot) as TableRow | undefined
return row && (row as any)[columnKey] === stageValue
})
}
const toggleStage = (stageValue: string, columnKey: string, checked: boolean) => {
const stageSlots = ['Stage', 'Stage_1', 'Stage_2', 'Stage_3']
if (checked) {
for (const slot of stageSlots) {
const row = rows.value.find(r => r.key === slot) as TableRow | undefined
if (row && ((row as any)[columnKey] === '-' || (row as any)[columnKey] === '')) {
;(row as any)[columnKey] = stageValue
break
}
}
} else {
for (const slot of stageSlots) {
const row = rows.value.find(r => r.key === slot) as TableRow | undefined
if (row && (row as any)[columnKey] === stageValue) {
;(row as any)[columnKey] = '-'
}
}
}
}
const getSimpleTaskTagColor = (taskName: string) => {
const colorMap: Record<string, string> = {
'当前/上次': 'blue',
'1-7': 'default',
'R8-11': 'default',
'12-17-HARD': 'default',
'龙门币-6/5': 'blue',
'红票-5': 'volcano',
'技能-5': 'cyan',
'经验-6/5': 'gold',
'碳-5': 'default',
'奶/盾芯片': 'green',
'奶/盾芯片组': 'green',
'术/狙芯片': 'purple',
'术/狙芯片组': 'purple',
'先/辅芯片': 'volcano',
'先/辅芯片组': 'volcano',
'近/特芯片': 'red',
'近/特芯片组': 'red',
}
return colorMap[taskName] || 'default'
}
const enableAllStages = (stageValue: string) => {
const timeKeys = [
'ALL',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday',
]
timeKeys.forEach(timeKey => {
if (isStageAvailable(stageValue, timeKey)) {
if (!isStageEnabled(stageValue, timeKey)) toggleStage(stageValue, timeKey, true)
}
})
}
const disableAllStages = (stageValue: string) => {
const timeKeys = [
'ALL',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday',
]
timeKeys.forEach(timeKey => {
if (isStageAvailable(stageValue, timeKey)) {
if (isStageEnabled(stageValue, timeKey)) toggleStage(stageValue, timeKey, false)
}
})
}
// 将 props.tableData 映射到 rows
const applyPlanDataToRows = (plan: Record<string, any> | null | undefined) => {
if (!plan) return
const timeKeys = [
'ALL',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday',
]
rows.value.forEach(row => {
const fieldKey = row.key
timeKeys.forEach(timeKey => {
if (plan[timeKey] && plan[timeKey][fieldKey] !== undefined) {
;(row as any)[timeKey] = plan[timeKey][fieldKey]
}
})
})
}
// 从 rows 组装为 API 所需结构
const buildPlanDataFromRows = (): Record<string, any> => {
const planData: Record<string, any> = {}
const timeKeys = [
'ALL',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday',
]
timeKeys.forEach(timeKey => {
planData[timeKey] = {}
rows.value.forEach(row => {
;(planData[timeKey] as Record<string, any>)[row.key] = (row as any)[timeKey]
})
})
return planData
}
watch(
() => props.tableData,
newVal => {
applyPlanDataToRows(newVal || {})
},
{ immediate: true, deep: true }
)
watch(
() =>
rows.value.map(r => ({
key: r.key,
ALL: r.ALL,
Monday: r.Monday,
Tuesday: r.Tuesday,
Wednesday: r.Wednesday,
Thursday: r.Thursday,
Friday: r.Friday,
Saturday: r.Saturday,
Sunday: r.Sunday,
})),
() => {
emit('update-table-data', buildPlanDataFromRows())
},
{ deep: true }
)
onMounted(() => {
applyPlanDataToRows(props.tableData || {})
})
</script>
<style scoped>
.config-table-wrapper {
}
.simple-table-wrapper {
}
.config-select {
width: 100%;
min-width: 100px;
}
.config-input-number {
width: 100%;
min-width: 100px;
}
.task-name-cell {
display: flex;
justify-content: center;
}
</style>