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

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

View File

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

View File

@@ -135,7 +135,7 @@
<a-select :placeholder="`请选择${setting.description}`"
allow-clear
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 :placeholder="`请选择${setting.description}`"
allow-clear
@@ -231,7 +231,16 @@ export default defineComponent({
const addParameterTab = () => {
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);
// 自动切换到新增的分组
groupedParametersActiveTab.value = groupedParameters.value.length - 1;
@@ -301,24 +310,13 @@ export default defineComponent({
multiableParameters.value = multiable === true && groupedParameters.value.length > 0;
};
// 获取平台Tab显示名称
// 获取平台Tab显示名称(优先使用下属平台名称)
const getPlatformTabName = (index: number): string => {
if (!currentTree.value?.platformId) {
return `平台 ${index + 1}`;
const sub = subPlatforms.value[index];
if (sub) {
return sub.name || sub.description || `平台 ${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 || '平台';
return `平台 ${index + 1}`;
};
// 获取可用的平台列表(包括当前平台和其下属平台)