diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetGroupVO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetGroupVO.java index 28222917..b7fa010a 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetGroupVO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetGroupVO.java @@ -7,6 +7,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +import java.util.List; /** * 命令片段分组 视图响应对象 @@ -30,4 +31,7 @@ public class CommandSnippetGroupVO implements Serializable { @Schema(description = "分组名称") private String name; + @Schema(description = "命令片段列表") + private List items; + } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetWrapperVO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetWrapperVO.java index fed88046..7b16c252 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetWrapperVO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetWrapperVO.java @@ -28,7 +28,7 @@ public class CommandSnippetWrapperVO implements Serializable { @Schema(description = "分组") private List groups; - @Schema(description = "命令片段") - private List items; + @Schema(description = "未分组的命令片段") + private List ungroupedItems; } \ No newline at end of file diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetServiceImpl.java index 0d412702..0a4ddc22 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetServiceImpl.java @@ -3,6 +3,7 @@ package com.orion.ops.module.asset.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.orion.lang.utils.collect.Lists; import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.framework.redis.core.utils.RedisMaps; @@ -25,7 +26,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -92,9 +96,22 @@ public class CommandSnippetServiceImpl implements CommandSnippetService { List groups = commandSnippetGroupService.getCommandSnippetGroupList(); // 查询命令片段 List items = this.getCommandSnippetList(); + // 设置组内数据 + Map groupMap = groups.stream() + .collect(Collectors.toMap(CommandSnippetGroupVO::getId, Function.identity())); + groupMap.forEach((groupId, group) -> { + List groupedItems = items.stream() + .filter(s -> groupId.equals(s.getGroupId())) + .collect(Collectors.toList()); + group.setItems(groupedItems); + }); + // 未分组数据 + List ungroupedItems = items.stream() + .filter(s -> s.getGroupId() == null) + .collect(Collectors.toList()); return CommandSnippetWrapperVO.builder() .groups(groups) - .items(items) + .ungroupedItems(ungroupedItems) .build(); } diff --git a/orion-ops-ui/src/api/asset/command-snippet-group.ts b/orion-ops-ui/src/api/asset/command-snippet-group.ts index 2391ff01..ca6eac17 100644 --- a/orion-ops-ui/src/api/asset/command-snippet-group.ts +++ b/orion-ops-ui/src/api/asset/command-snippet-group.ts @@ -1,3 +1,4 @@ +import type { CommandSnippetQueryResponse } from './command-snippet'; import axios from 'axios'; /** @@ -20,6 +21,7 @@ export interface CommandSnippetGroupUpdateRequest extends CommandSnippetGroupCre export interface CommandSnippetGroupQueryResponse { id: number; name: string; + items: Array; } /** diff --git a/orion-ops-ui/src/api/asset/command-snippet.ts b/orion-ops-ui/src/api/asset/command-snippet.ts index 71c93131..4325a90f 100644 --- a/orion-ops-ui/src/api/asset/command-snippet.ts +++ b/orion-ops-ui/src/api/asset/command-snippet.ts @@ -20,12 +20,16 @@ export interface CommandSnippetUpdateRequest extends CommandSnippetCreateRequest /** * 命令片段查询响应 */ -export interface CommandSnippetQueryResponse { +export interface CommandSnippetQueryResponse extends CommandSnippetQueryResponseExtra { id: number; groupId: number; name: string; command: string; - expand?: boolean; +} + +export interface CommandSnippetQueryResponseExtra { + visible: boolean; + expand: boolean; } /** @@ -33,7 +37,7 @@ export interface CommandSnippetQueryResponse { */ export interface CommandSnippetWrapperResponse { groups: Array; - items: Array; + ungroupedItems: Array; } /** @@ -54,7 +58,7 @@ export function updateCommandSnippet(request: CommandSnippetUpdateRequest) { * 查询全部命令片段 */ export function getCommandSnippetList() { - return axios.get>('/asset/command-snippet/list'); + return axios.get('/asset/command-snippet/list'); } /** diff --git a/orion-ops-ui/src/views/host/terminal/components/snippet/snippet-drawer.vue b/orion-ops-ui/src/views/host/terminal/components/snippet/snippet-drawer.vue index 4ca0852e..142c888e 100644 --- a/orion-ops-ui/src/views/host/terminal/components/snippet/snippet-drawer.vue +++ b/orion-ops-ui/src/views/host/terminal/components/snippet/snippet-drawer.vue @@ -10,7 +10,7 @@ -
+
@@ -19,19 +19,26 @@ + allow-clear + @search="filterSnippet" + @keyup.enter="filterSnippet" />
-
+
+ -
- + +
+
-
+ @@ -46,26 +53,59 @@ import { onMounted, ref } from 'vue'; import useVisible from '@/hooks/visible'; import useLoading from '@/hooks/loading'; + import { getCommandSnippetList } from '@/api/asset/command-snippet'; import SnippetItem from './snippet-item.vue'; import SnippetGroup from './snippet-group.vue'; - const { loading, toggle } = useLoading(); + const { loading, setLoading } = useLoading(); const { visible, setVisible } = useVisible(); - const snippet = ref({ - groups: [], - items: [] - }); + + const filterValue = ref(); + const snippet = ref(); // 打开 - const open = () => { + const open = async () => { setVisible(true); - - console.log('loading'); - // loading + // 加载数据 + await fetchData(); }; defineExpose({ open }); + // 加载数据 + const fetchData = async () => { + if (snippet.value) { + return; + } + setLoading(true); + try { + // 查询 + const { data } = await getCommandSnippetList(); + snippet.value = data; + // 设置状态 + filterSnippet(); + } catch (e) { + } finally { + setLoading(false); + } + }; + + // 过滤 + const filterSnippet = () => { + snippet.value?.groups.forEach(g => { + g.items?.forEach(s => { + s.visible = !filterValue.value + || s.name.toLowerCase().includes(filterValue.value.toLowerCase()) + || s.command.toLowerCase().includes(filterValue.value.toLowerCase()); + }); + }); + snippet.value?.ungroupedItems.forEach(s => { + s.visible = !filterValue.value + || s.name.toLowerCase().includes(filterValue.value.toLowerCase()) + || s.command.toLowerCase().includes(filterValue.value.toLowerCase()); + }); + }; + onMounted(() => { open(); }); @@ -82,6 +122,8 @@ position: relative; background: var(--color-bg-2); height: 100%; + width: 100%; + display: block; .snippet-header { padding: 12px; diff --git a/orion-ops-ui/src/views/host/terminal/components/snippet/snippet-group.vue b/orion-ops-ui/src/views/host/terminal/components/snippet/snippet-group.vue index d682f1e9..c6352198 100644 --- a/orion-ops-ui/src/views/host/terminal/components/snippet/snippet-group.vue +++ b/orion-ops-ui/src/views/host/terminal/components/snippet/snippet-group.vue @@ -1,16 +1,21 @@ @@ -21,6 +26,7 @@