1
This commit is contained in:
parent
7c2d7ef1bc
commit
a676ed89d1
@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import {Modal, Button} from 'antd';
|
import {Modal, Button} from 'antd';
|
||||||
|
import { FullscreenOutlined, FullscreenExitOutlined } from '@ant-design/icons';
|
||||||
import type {DeploymentConfig} from '../types';
|
import type {DeploymentConfig} from '../types';
|
||||||
import './styles.less';
|
import './styles.less';
|
||||||
import {FormButtonGroup, FormItem, Select, Submit, FormGrid, Input, ArrayTable} from '@formily/antd-v5'
|
import {FormButtonGroup, FormItem, Select, Submit, FormGrid, Input, ArrayTable} from '@formily/antd-v5'
|
||||||
@ -9,6 +10,68 @@ import {action} from '@formily/reactive'
|
|||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
import Editor from '@/components/Editor';
|
import Editor from '@/components/Editor';
|
||||||
|
|
||||||
|
// 定义 ScriptEditor 组件
|
||||||
|
const ScriptEditor: React.FC<any> = (props) => {
|
||||||
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||||
|
|
||||||
|
const toggleFullscreen = () => {
|
||||||
|
setIsFullscreen(!isFullscreen);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 添加 ESC 键监听
|
||||||
|
useEffect(() => {
|
||||||
|
const handleEsc = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === 'Escape' && isFullscreen) {
|
||||||
|
setIsFullscreen(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener('keydown', handleEsc);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('keydown', handleEsc);
|
||||||
|
};
|
||||||
|
}, [isFullscreen]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ position: 'relative' }}>
|
||||||
|
<Button
|
||||||
|
icon={isFullscreen ? <FullscreenExitOutlined /> : <FullscreenOutlined />}
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
right: '10px',
|
||||||
|
top: '-40px',
|
||||||
|
zIndex: 1
|
||||||
|
}}
|
||||||
|
onClick={toggleFullscreen}
|
||||||
|
/>
|
||||||
|
<div style={{
|
||||||
|
position: isFullscreen ? 'fixed' : 'relative',
|
||||||
|
top: isFullscreen ? '0' : 'auto',
|
||||||
|
left: isFullscreen ? '0' : 'auto',
|
||||||
|
right: isFullscreen ? '0' : 'auto',
|
||||||
|
bottom: isFullscreen ? '0' : 'auto',
|
||||||
|
zIndex: isFullscreen ? 1000 : 1,
|
||||||
|
background: '#1e1e1e'
|
||||||
|
}}>
|
||||||
|
{isFullscreen && (
|
||||||
|
<Button
|
||||||
|
icon={<FullscreenExitOutlined />}
|
||||||
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
right: '20px',
|
||||||
|
top: '20px',
|
||||||
|
zIndex: 1001
|
||||||
|
}}
|
||||||
|
onClick={() => setIsFullscreen(false)}
|
||||||
|
>
|
||||||
|
退出全屏
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Editor {...props} height={isFullscreen ? '100vh' : '240px'} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
interface DeploymentConfigModalProps {
|
interface DeploymentConfigModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
@ -63,7 +126,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
|
|||||||
FormGrid,
|
FormGrid,
|
||||||
Input,
|
Input,
|
||||||
ArrayTable,
|
ArrayTable,
|
||||||
Editor
|
ScriptEditor
|
||||||
},
|
},
|
||||||
scope: {
|
scope: {
|
||||||
useAsyncDataSource
|
useAsyncDataSource
|
||||||
@ -331,13 +394,17 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
|
|||||||
marginBottom: '16px'
|
marginBottom: '16px'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'x-component': 'Editor',
|
'x-component': 'ScriptEditor',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
height: '240px',
|
|
||||||
language: 'shell',
|
language: 'shell',
|
||||||
theme: 'vs-dark',
|
theme: 'vs-dark',
|
||||||
options: {
|
options: {
|
||||||
minimap: { enabled: false },
|
minimap: {
|
||||||
|
enabled: true,
|
||||||
|
scale: 2,
|
||||||
|
showSlider: "mouseover",
|
||||||
|
renderCharacters: false
|
||||||
|
},
|
||||||
scrollBeyondLastLine: false,
|
scrollBeyondLastLine: false,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
lineNumbers: 'on',
|
lineNumbers: 'on',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user