完善阵位分配命令的变量数据加载

This commit is contained in:
2026-04-15 17:22:22 +08:00
parent a08e061979
commit dbbc8a27c3
3 changed files with 25 additions and 31 deletions

View File

@@ -11,6 +11,7 @@ import { HttpRequestClient } from '@/utils/request';
import type { NodeTemplatesResponse } from './template'; import type { NodeTemplatesResponse } from './template';
import type { BehaviorTree, BehaviorTreeDetailsResponse, BehaviorTreePageResponse, BehaviorTreeRequest } from './tree'; import type { BehaviorTree, BehaviorTreeDetailsResponse, BehaviorTreePageResponse, BehaviorTreeRequest } from './tree';
import type { BasicResponse } from '@/types'; import type { BasicResponse } from '@/types';
import type { PlatformListableResponse } from '../types';
const req = HttpRequestClient.create<BasicResponse>({ const req = HttpRequestClient.create<BasicResponse>({
baseURL: '/api', baseURL: '/api',
@@ -28,8 +29,8 @@ export const findOneTreeByPlatformId = (platformId: number): Promise<BehaviorTre
return req.get(`/system/behaviortree/platform/${platformId}`); return req.get(`/system/behaviortree/platform/${platformId}`);
}; };
export const findSubPlatforms = (treeId: number): Promise<BehaviorTreeDetailsResponse> => { export const findSubPlatforms = (platformId: number): Promise<PlatformListableResponse> => {
return req.get(`/system/behaviortree/underling/${treeId}`); return req.get(`/system/behaviortree/underling/${platformId}`);
}; };
export const findOneTreeById = (id: number): Promise<BehaviorTreeDetailsResponse> => { export const findOneTreeById = (id: number): Promise<BehaviorTreeDetailsResponse> => {

View File

@@ -156,20 +156,14 @@ export default defineComponent({
} }
// 加载下属平台 // 加载下属平台
const loadSubPlatforms = (treeId: number) => { const loadSubPlatforms = (platformId: number | null) => {
console.log(treeId); if (!platformId || platformId <= 0) {
if (!treeId || treeId <= 0) {
subPlatforms.value = []; subPlatforms.value = [];
return; return;
} }
findSubPlatforms(treeId).then(r => { findSubPlatforms(platformId).then(r => {
if (r.data && Array.isArray(r.data)) { subPlatforms.value = r.data ?? [];
subPlatforms.value = r.data as Platform[];
} else {
subPlatforms.value = [];
}
}).catch(err => { }).catch(err => {
console.error('加载下属平台失败:', err); console.error('加载下属平台失败:', err);
subPlatforms.value = []; subPlatforms.value = [];
@@ -292,7 +286,7 @@ export default defineComponent({
currentTreeEditing.value = true; currentTreeEditing.value = true;
// 加载下属平台 // 加载下属平台
loadSubPlatforms(r.data.id); loadSubPlatforms(r.data.platformId);
nextTick(() => { nextTick(() => {
initGraph(); initGraph();
@@ -508,6 +502,7 @@ export default defineComponent({
loadDatasource(); loadDatasource();
}); });
// 清理 // 清理
onBeforeUnmount(() => destroy()); onBeforeUnmount(() => destroy());

View File

@@ -135,7 +135,7 @@
<a-select :placeholder="`请选择${setting.description}`" <a-select :placeholder="`请选择${setting.description}`"
allow-clear allow-clear
v-else-if="setting.paramKey === 'platforms'" v-model:value="setting.defaultValue"> v-else-if="setting.paramKey === 'platforms'" v-model:value="setting.defaultValue">
<a-select-option v-for="pl in platforms" :value="pl.name">{{ pl.description }}</a-select-option> <a-select-option v-for="pl in getAvailablePlatforms()" :value="pl.name">{{ pl.description }}</a-select-option>
</a-select> </a-select>
<a-select :placeholder="`请选择${setting.description}`" <a-select :placeholder="`请选择${setting.description}`"
allow-clear allow-clear
@@ -231,7 +231,16 @@ export default defineComponent({
const addParameterTab = () => { const addParameterTab = () => {
let newParameters = dumpParameters(); let newParameters = dumpParameters();
// 新增一个空的参数分组 // 如果有下属平台,预填对应索引的平台名称
const nextIndex = groupedParameters.value.length;
const subPlatform = subPlatforms.value[nextIndex];
if (subPlatform) {
const platformParam = newParameters.find(p => p.paramKey === 'platforms');
if (platformParam) {
platformParam.defaultValue = subPlatform.name;
}
}
// 新增一个参数分组
groupedParameters.value.push(newParameters); groupedParameters.value.push(newParameters);
// 自动切换到新增的分组 // 自动切换到新增的分组
groupedParametersActiveTab.value = groupedParameters.value.length - 1; groupedParametersActiveTab.value = groupedParameters.value.length - 1;
@@ -301,24 +310,13 @@ export default defineComponent({
multiableParameters.value = multiable === true && groupedParameters.value.length > 0; multiableParameters.value = multiable === true && groupedParameters.value.length > 0;
}; };
// 获取平台Tab显示名称 // 获取平台Tab显示名称(优先使用下属平台名称)
const getPlatformTabName = (index: number): string => { const getPlatformTabName = (index: number): string => {
if (!currentTree.value?.platformId) { const sub = subPlatforms.value[index];
return `平台 ${index + 1}`; if (sub) {
return sub.name || sub.description || `平台 ${index + 1}`;
} }
return `平台 ${index + 1}`;
// 查找当前行为树绑定的平台
const currentPlatform = platforms.value.find(p => p.id === currentTree.value?.platformId);
if (!currentPlatform) {
return `平台 ${index + 1}`;
}
// 如果有多个分组,显示平台名称和索引
if (groupedParameters.value.length > 1) {
return `${currentPlatform.name || '未知平台'}-${index + 1}`;
}
return currentPlatform.name || '平台';
}; };
// 获取可用的平台列表(包括当前平台和其下属平台) // 获取可用的平台列表(包括当前平台和其下属平台)