feat: Support quick commands in the file terminal (#10405)

Refs #9541
This commit is contained in:
ssongliu 2025-09-18 15:06:37 +08:00 committed by GitHub
parent 98d01556c2
commit 58c994a3e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,7 +8,20 @@
:fullScreen="true"
>
<template #content>
<Terminal style="height: calc(100vh - 100px)" ref="terminalRef"></Terminal>
<Terminal style="height: calc(100vh - 120px)" ref="terminalRef"></Terminal>
<div>
<el-select v-model="quickCmd" clearable filterable @change="quickInput" class="w-full -mt-6">
<template #prefix>{{ $t('terminal.quickCommand') }}</template>
<el-option-group v-for="group in commandTree" :key="group.label" :label="group.label">
<el-option
v-for="(cmd, index) in group.children"
:key="index"
:label="cmd.name"
:value="cmd.command"
/>
</el-option-group>
</el-select>
</div>
</template>
</DrawerPro>
</template>
@ -16,16 +29,21 @@
<script lang="ts" setup>
import { ref, nextTick } from 'vue';
import Terminal from '@/components/terminal/index.vue';
import { getCommandTree } from '@/api/modules/command';
const terminalVisible = ref(false);
const terminalRef = ref<InstanceType<typeof Terminal> | null>(null);
let quickCmd = ref();
const commandTree = ref();
interface DialogProps {
cwd: string;
command: string;
}
const acceptParams = async (params: DialogProps): Promise<void> => {
terminalVisible.value = true;
loadCommandTree();
await initTerm(params.cwd);
};
@ -39,6 +57,16 @@ const initTerm = async (cwd: string) => {
});
};
const loadCommandTree = async () => {
const res = await getCommandTree('command');
commandTree.value = res.data || [];
};
function quickInput(val: any) {
terminalRef.value?.sendMsg(val + '\n');
quickCmd.value = '';
}
const onClose = () => {
terminalRef.value?.onClose();
};