This commit is contained in:
asp_ly 2025-01-17 21:40:32 +08:00
parent a676ed89d1
commit 6fbd00106c

View File

@ -14,59 +14,52 @@ import Editor from '@/components/Editor';
const ScriptEditor: React.FC<any> = (props) => { const ScriptEditor: React.FC<any> = (props) => {
const [isFullscreen, setIsFullscreen] = useState(false); const [isFullscreen, setIsFullscreen] = useState(false);
const toggleFullscreen = () => {
setIsFullscreen(!isFullscreen);
};
// 添加 ESC 键监听
useEffect(() => { useEffect(() => {
const handleEsc = (event: KeyboardEvent) => { const handleEscKey = (event: KeyboardEvent) => {
if (event.key === 'Escape' && isFullscreen) { if (event.key === 'Escape' && isFullscreen) {
setIsFullscreen(false); setIsFullscreen(false);
} }
}; };
window.addEventListener('keydown', handleEsc);
document.addEventListener('keydown', handleEscKey);
return () => { return () => {
window.removeEventListener('keydown', handleEsc); document.removeEventListener('keydown', handleEscKey);
}; };
}, [isFullscreen]); }, [isFullscreen]);
return ( const toggleFullscreen = () => {
<div style={{ position: 'relative' }}> setIsFullscreen(!isFullscreen);
<Button };
icon={isFullscreen ? <FullscreenExitOutlined /> : <FullscreenOutlined />}
style={{ const editorStyle = isFullscreen ? {
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', position: 'fixed',
right: '20px', top: 0,
top: '20px', left: 0,
zIndex: 1001 right: 0,
}} bottom: 0,
onClick={() => setIsFullscreen(false)} zIndex: 1000,
> backgroundColor: '#1e1e1e'
退 } : {};
</Button>
)} return (
<div style={{ position: 'relative', height: isFullscreen ? '100vh' : '240px', ...editorStyle }}>
<Editor {...props} height={isFullscreen ? '100vh' : '240px'} /> <Editor {...props} height={isFullscreen ? '100vh' : '240px'} />
<div style={{
position: 'absolute',
top: '10px',
right: '10px',
zIndex: 1001,
display: 'flex',
gap: '8px'
}}>
<Button
type="text"
icon={isFullscreen ? <FullscreenExitOutlined /> : <FullscreenOutlined />}
onClick={toggleFullscreen}
style={{ color: '#fff' }}
>
{isFullscreen ? '退出全屏' : '全屏'}
</Button>
</div> </div>
</div> </div>
); );
@ -261,21 +254,10 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
minColumns: 1 minColumns: 1
}, },
properties: { properties: {
envvAR: { envs: {
type: 'array', type: 'array',
title: '环境变量',
'x-decorator': 'FormItem',
'x-decorator-props': {
labelCol: 24,
wrapperCol: 24,
layout: 'vertical',
colon: false,
labelAlign: 'left',
style: {
marginBottom: '16px'
}
},
'x-component': 'ArrayTable', 'x-component': 'ArrayTable',
'x-decorator': 'FormItem',
'x-component-props': { 'x-component-props': {
pagination: { pageSize: 10 }, pagination: { pageSize: 10 },
scroll: { x: '100%' }, scroll: { x: '100%' },
@ -288,70 +270,59 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
items: { items: {
type: 'object', type: 'object',
properties: { properties: {
key: { column1: {
type: 'void', type: 'void',
'x-component': 'ArrayTable.Column', 'x-component': 'ArrayTable.Column',
'x-component-props': { 'x-component-props': { title: '键', width: '40%' },
title: '键',
width: '40%'
},
properties: { properties: {
key: { key: {
type: 'string', type: 'string',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-validator': { 'x-component': 'Input',
pattern: '^[a-zA-Z][a-zA-Z0-9_]*$', 'x-validator': [
message: '键名只能包含字母、数字和下划线,且必须以字母开头'
},
'x-component': 'Select',
'x-component-props': {
placeholder: '请输入或选择键',
allowClear: true,
showSearch: true,
mode: 'tags',
style: { width: '100%' }
},
'x-reactions': '{{useAsyncDataSource(api.environment.getKeyOptions)}}'
}
}
},
value: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': {
title: '值',
width: '40%'
},
properties: {
value: {
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
placeholder: '请输入或选择值',
allowClear: true,
showSearch: true,
mode: 'tags',
style: { width: '100%' }
},
'x-reactions': [
{ {
dependencies: ['.key'], required: true,
fulfill: { message: '请输入环境变量名'
run: '{{useAsyncDataSource(api.environment.getValueOptions, {key: $deps[0]})}}' },
{
pattern: '^[a-zA-Z][a-zA-Z0-9_]*$',
message: '只能包含字母、数字和下划线,且必须以字母开头'
} }
],
'x-component-props': {
placeholder: '请输入环境变量名',
allowClear: true
} }
]
} }
} }
}, },
operations: { column2: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': { title: '值', width: '40%' },
properties: {
value: {
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-validator': {
required: true,
message: '请输入环境变量值'
},
'x-component-props': {
placeholder: '请输入环境变量值',
allowClear: true
}
}
}
},
column3: {
type: 'void', type: 'void',
'x-component': 'ArrayTable.Column', 'x-component': 'ArrayTable.Column',
'x-component-props': { 'x-component-props': {
title: '操作', title: '操作',
dataIndex: 'operations',
width: '20%', width: '20%',
align: 'center'
}, },
properties: { properties: {
remove: { remove: {
@ -373,10 +344,8 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
properties: { properties: {
add: { add: {
type: 'void', type: 'void',
'x-component': 'ArrayTable.Addition', title: '添加环境变量',
'x-component-props': { 'x-component': 'ArrayTable.Addition'
title: '添加环境变量'
}
} }
} }
}, },
@ -422,7 +391,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
try { try {
const values = await form.submit() const values = await form.submit()
console.log('表单提交的值:', values) console.log('表单提交的值:', values)
console.log('环境变量数组:', values.envvAR) console.log('环境变量数组:', values.envs)
onSuccess?.(values as DeploymentConfig) onSuccess?.(values as DeploymentConfig)
} catch (e) { } catch (e) {
console.error('表单提交出错:', e) console.error('表单提交出错:', e)