🔨 执行命令.
This commit is contained in:
@@ -121,7 +121,7 @@
|
||||
});
|
||||
|
||||
// 打开
|
||||
const open = async (hostIdList: Array<number>) => {
|
||||
const open = async (hostIdList: Array<number> = []) => {
|
||||
setVisible(true);
|
||||
// 加载主机列表
|
||||
await fetchHosts();
|
||||
|
||||
56
orion-ops-ui/src/components/view/exec-editor/const.ts
Normal file
56
orion-ops-ui/src/components/view/exec-editor/const.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
// 模板参数
|
||||
export interface TemplateParam {
|
||||
name?: string;
|
||||
default?: string;
|
||||
desc?: string;
|
||||
}
|
||||
|
||||
// 内置参数
|
||||
export const builtinsParams: Array<TemplateParam> = [
|
||||
{
|
||||
name: 'hostId',
|
||||
desc: '执行主机id'
|
||||
}, {
|
||||
name: 'hostName',
|
||||
desc: '执行主机名称'
|
||||
}, {
|
||||
name: 'hostCode',
|
||||
desc: '执行主机编码'
|
||||
}, {
|
||||
name: 'hostAddress',
|
||||
desc: '执行主机地址'
|
||||
}, {
|
||||
name: 'userId',
|
||||
desc: '执行用户id'
|
||||
}, {
|
||||
name: 'username',
|
||||
desc: '执行用户名'
|
||||
}, {
|
||||
name: 'execId',
|
||||
desc: '执行记录id'
|
||||
}, {
|
||||
name: 'uuid',
|
||||
desc: '生成任务维度 uuid'
|
||||
}, {
|
||||
name: 'uuidShort',
|
||||
desc: '生成任务维度 uuid 无 \'-\''
|
||||
}, {
|
||||
name: 'hostUuid',
|
||||
desc: '生成机器维度 uuid'
|
||||
}, {
|
||||
name: 'hostUuidShort',
|
||||
desc: '生成机器维度 uuid 无 \'-\''
|
||||
}, {
|
||||
name: 'timestampMillis',
|
||||
desc: '时间戳毫秒'
|
||||
}, {
|
||||
name: 'timestamp',
|
||||
desc: '时间戳'
|
||||
}, {
|
||||
name: 'date',
|
||||
desc: '执行时间 yyyy-MM-dd'
|
||||
}, {
|
||||
name: 'datetime',
|
||||
desc: '执行时间 yyyy-MM-dd HH:mm:ss'
|
||||
},
|
||||
];
|
||||
86
orion-ops-ui/src/components/view/exec-editor/index.vue
Normal file
86
orion-ops-ui/src/components/view/exec-editor/index.vue
Normal file
@@ -0,0 +1,86 @@
|
||||
<template>
|
||||
<editor language="shell"
|
||||
:suggestions="false" />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'execEditor'
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { TemplateParam } from './const';
|
||||
import { onMounted, onUnmounted, ref } from 'vue';
|
||||
import { builtinsParams } from './const';
|
||||
import * as monaco from 'monaco-editor';
|
||||
import { language } from 'monaco-editor/esm/vs/basic-languages/shell/shell.js';
|
||||
|
||||
const props = defineProps<{
|
||||
parameter?: Array<TemplateParam>
|
||||
}>();
|
||||
|
||||
const suggestionsDispose = ref();
|
||||
|
||||
// 加载代码提示
|
||||
onMounted(() => {
|
||||
if (suggestionsDispose.value) {
|
||||
return;
|
||||
}
|
||||
// 代码提示
|
||||
suggestionsDispose.value = monaco.languages.registerCompletionItemProvider('shell', {
|
||||
provideCompletionItems() {
|
||||
const suggestions: any = [];
|
||||
language.keywords?.forEach((item: any) => {
|
||||
suggestions.push({
|
||||
label: item,
|
||||
kind: monaco.languages.CompletionItemKind.Keyword,
|
||||
insertText: item
|
||||
});
|
||||
});
|
||||
language.builtins?.forEach((item: any) => {
|
||||
suggestions.push({
|
||||
label: item,
|
||||
kind: monaco.languages.CompletionItemKind.Function,
|
||||
insertText: item,
|
||||
});
|
||||
});
|
||||
// 内置参数提示
|
||||
builtinsParams.forEach(s => {
|
||||
suggestions.push({
|
||||
label: s.name,
|
||||
kind: monaco.languages.CompletionItemKind.Function,
|
||||
insertText: `@{{ ${s.name} }}`,
|
||||
detail: s.desc || '',
|
||||
});
|
||||
});
|
||||
// 命令参数提示
|
||||
props.parameter?.forEach(s => {
|
||||
if (!s.name) {
|
||||
return;
|
||||
}
|
||||
suggestions.push({
|
||||
label: s.name,
|
||||
kind: monaco.languages.CompletionItemKind.Function,
|
||||
insertText: `@{{ ${s.name} }}`,
|
||||
detail: s.desc || '',
|
||||
});
|
||||
});
|
||||
return {
|
||||
suggestions: [...new Set(suggestions)],
|
||||
};
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// 卸载代码提示
|
||||
onUnmounted(() => {
|
||||
suggestionsDispose.value?.dispose();
|
||||
suggestionsDispose.value = undefined;
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user