Files
auto-solution/modeler/src/views/decision/trees-card.vue

207 lines
5.5 KiB
Vue
Raw Normal View History

2026-02-08 15:59:14 +08:00
<template>
2026-02-08 21:36:39 +08:00
<a-collapse v-model:activeKey="activeKey" :accordion="false" class="ks-trees-collapse">
2026-02-08 22:28:52 +08:00
<a-collapse-panel key="1" style="position: relative">
2026-02-08 15:59:14 +08:00
<template #header>
2026-02-08 22:28:52 +08:00
<a-flex>
<span class="ks-model-builder-title-icon icon-model"></span>
<span style="color: #82c4e9;font-size: 16px;">我的行为树</span>
<!-- <span style="position: absolute; right: 15px;"><PlusOutlined @click="$emit('create-tree')"/></span>-->
</a-flex>
2026-02-08 15:59:14 +08:00
</template>
2026-02-08 21:36:39 +08:00
<div class="w-full" style="padding: 5px;">
2026-02-08 22:28:52 +08:00
<a-flex>
<a-input-search size="small" allowClear v-model:value="behaviorTreeQuery.name" placeholder="行为树名称" @search="loadTress" />
<a-button size="small" style="margin-left: 10px;"><PlusOutlined style="margin-top: 0px;display: block;" @click="$emit('create-tree')"/></a-button>
</a-flex>
2026-02-08 21:36:39 +08:00
</div>
2026-02-08 16:44:50 +08:00
<a-list size="small" :data-source="behaviorTrees || []" style="min-height: 25vh">
2026-02-08 15:59:14 +08:00
<template #renderItem="{ item }">
2026-02-08 21:50:56 +08:00
<a-list-item>
<a-flex>
<a-tooltip placement="right">
<template #title>
<p>名称: {{ item.name }}</p>
<p>说明: {{item.description}}</p>
</template>
<span>{{ substring(item.name, 15) }}</span>
</a-tooltip>
<a-flex class="ks-tree-actions">
<span style="margin-right: 10px" @click="()=> handleSelect(item)"><EditFilled /></span>
<a-popconfirm
title="确定删除?"
@confirm="()=> handleDelete(item)"
>
<span class="ks-tree-action ks-tree-action-delete"><DeleteOutlined /></span>
</a-popconfirm>
</a-flex>
</a-flex>
</a-list-item>
2026-02-08 15:59:14 +08:00
</template>
</a-list>
2026-02-08 21:36:39 +08:00
<a-pagination
size="small"
v-model:current="behaviorTreeQuery.pageNum"
:page-size="behaviorTreeQuery.pageSize"
simple :total="totalTress" @change="handleChange" />
2026-02-08 15:59:14 +08:00
</a-collapse-panel>
</a-collapse>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
2026-02-08 21:50:56 +08:00
import { CheckOutlined, DeleteOutlined, EditFilled, PlusOutlined } from '@ant-design/icons-vue';
2026-02-08 21:36:39 +08:00
import type { BehaviorTree, BehaviorTreeRequest } from './types';
2026-02-08 21:50:56 +08:00
import { deleteOneTreeById, findTreesByQuery } from './api';
2026-02-08 21:36:39 +08:00
import { substring } from '@/utils/strings';
2026-02-08 15:59:14 +08:00
export default defineComponent({
2026-02-08 22:28:52 +08:00
emits: ['select-tree','create-tree'],
2026-02-08 15:59:14 +08:00
components: {
2026-02-08 21:50:56 +08:00
CheckOutlined,
PlusOutlined,
DeleteOutlined,
EditFilled,
2026-02-08 15:59:14 +08:00
},
setup(_props, { emit }) {
2026-02-08 16:44:50 +08:00
const behaviorTrees = ref<BehaviorTree[]>([]);
2026-02-08 21:36:39 +08:00
const behaviorTreeQuery = ref<Partial<BehaviorTreeRequest>>({
name: null,
pageNum: 1,
pageSize: 8,
});
2026-02-08 16:01:21 +08:00
const activeKey = ref<number>(1)
2026-02-08 21:36:39 +08:00
const totalTress = ref<number>(0);
2026-02-08 21:50:56 +08:00
2026-02-08 15:59:14 +08:00
const loadTress = () => {
2026-02-08 16:44:50 +08:00
findTreesByQuery(behaviorTreeQuery.value).then(r => {
behaviorTrees.value = r.rows;
2026-02-08 21:36:39 +08:00
totalTress.value = r.total ?? 0;
2026-02-08 15:59:14 +08:00
});
};
2026-02-08 21:36:39 +08:00
const handleChange = (page: number, pageSize: number) => {
behaviorTreeQuery.value.pageNum = page;
behaviorTreeQuery.value.pageSize = pageSize;
loadTress();
};
2026-02-08 21:50:56 +08:00
const handleDelete = (item: BehaviorTree) => {
deleteOneTreeById(item.id).then(r => {
if (r.code === 200) {
loadTress();
}
});
};
2026-02-08 15:59:14 +08:00
const columns = [
{
title: '名称',
dataIndex: 'name',
},
];
2026-02-08 16:44:50 +08:00
const handleSelect = (record: BehaviorTree) => {
2026-02-08 15:59:14 +08:00
emit('select-tree', record);
2026-02-08 16:01:21 +08:00
}
2026-02-08 15:59:14 +08:00
2026-02-08 16:44:50 +08:00
const customRow = (record: BehaviorTree) => {
2026-02-08 15:59:14 +08:00
return {
onClick: (event: any) => {
emit('select-tree', record, event);
},
};
};
2026-02-08 22:16:22 +08:00
const refresh = ()=> loadTress();
2026-02-08 15:59:14 +08:00
onMounted(() => {
loadTress();
});
return {
2026-02-08 22:16:22 +08:00
refresh,
2026-02-08 21:36:39 +08:00
totalTress,
2026-02-08 18:05:48 +08:00
substring,
2026-02-08 15:59:14 +08:00
activeKey,
2026-02-08 16:44:50 +08:00
behaviorTrees,
behaviorTreeQuery,
2026-02-08 15:59:14 +08:00
loadTress,
columns,
customRow,
handleSelect,
2026-02-08 21:36:39 +08:00
handleChange,
2026-02-08 21:50:56 +08:00
handleDelete,
2026-02-08 15:59:14 +08:00
};
},
2026-02-08 16:01:21 +08:00
})
2026-02-08 15:59:14 +08:00
</script>
2026-02-08 21:36:39 +08:00
<style lang="less">
.ant-collapse {
.ant-list-sm {
.ant-list-item {
padding: 4px 15px;
cursor: pointer;
color: rgb(130 196 233);
2026-02-08 21:50:56 +08:00
position: relative;
.ks-tree-actions {
position: absolute;
right: 10px;
display: none;
}
2026-02-08 21:36:39 +08:00
&:hover {
background: #0d2d4e;
2026-02-08 21:50:56 +08:00
.ks-tree-actions {
display: block;
}
2026-02-08 21:36:39 +08:00
}
2026-02-08 21:50:56 +08:00
2026-02-08 21:36:39 +08:00
}
}
&.ks-trees-collapse {
2026-02-08 21:50:56 +08:00
2026-02-08 21:36:39 +08:00
.ant-collapse-content-box {
padding: 0;
height: 40vh;
position: relative;
}
.ant-pagination{
position: absolute;
bottom: 10px;
width: 100%;
.ant-pagination-disabled .ant-pagination-item-link,
.ant-pagination-disabled:hover .ant-pagination-item-link,
.ant-pagination-prev .ant-pagination-item-link,
.ant-pagination-next .ant-pagination-item-link,
&.ant-pagination-mini .ant-pagination-total-text,
&.ant-pagination-mini .ant-pagination-simple-pager{
color: rgb(255 255 255 / 95%);
}
&.ant-pagination-simple .ant-pagination-simple-pager input {
background-color: transparent;
border: 1px solid #0f4a7c;
color:#eee;
}
}
}
}
2026-02-08 16:01:21 +08:00
.create-tree-icon{
2026-02-08 15:59:14 +08:00
cursor: pointer;
}
.ant-list-item {
2026-02-08 21:36:39 +08:00
padding: 3px 5px;
2026-02-08 15:59:14 +08:00
cursor: pointer;
color: rgb(130 196 233);
&:hover {
background: #0d2d4e;
}
}
</style>