This commit is contained in:
asp_ly 2024-12-26 22:29:01 +08:00
parent a30b5101ec
commit b7d77c8033

View File

@ -125,58 +125,60 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
if (!selectedTemplate?.buildVariablesSchema) return null;
const { properties } = selectedTemplate.buildVariablesSchema;
const scriptProperty = properties.script;
return (
<>
{/* 脚本编辑器 */}
{scriptProperty?.format === 'monaco-editor' && (
<Form.Item
label={scriptProperty.title || 'Pipeline script'}
required={selectedTemplate.buildVariablesSchema.required?.includes('script')}
tooltip={scriptProperty.description}
>
<Editor
height="300px"
defaultLanguage={scriptProperty.editorConfig?.language || 'shell'}
theme={scriptProperty.editorConfig?.theme || 'vs-dark'}
value={buildVariables.script || scriptProperty.default || '#!/bin/bash\n'}
onChange={(value) => setBuildVariables({
...buildVariables,
script: value || ''
})}
options={{
minimap: { enabled: scriptProperty.editorConfig?.minimap ?? false },
fontSize: scriptProperty.editorConfig?.fontSize || 14,
lineNumbers: scriptProperty.editorConfig?.lineNumbers ? 'on' : 'off',
wordWrap: scriptProperty.editorConfig?.wordWrap ? 'on' : 'off',
tabSize: scriptProperty.editorConfig?.tabSize || 2,
scrollBeyondLastLine: false,
automaticLayout: true,
folding: scriptProperty.editorConfig?.folding ?? true,
autoClosingBrackets: 'always',
autoClosingQuotes: 'always',
formatOnPaste: true,
formatOnType: true,
suggestOnTriggerCharacters: scriptProperty.editorConfig?.autoComplete ?? true,
renderWhitespace: 'boundary',
}}
loading={
<div style={{
padding: '8px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '300px',
background: '#1e1e1e',
color: '#fff'
}}>
...
</div>
}
/>
</Form.Item>
)}
{/* 遍历所有字段,对有 editorConfig 的字段使用富文本编辑器 */}
{Object.entries(properties).map(([key, property]) => (
property.editorConfig ? (
<Form.Item
key={key}
label={property.title || key}
required={selectedTemplate.buildVariablesSchema.required?.includes(key)}
tooltip={property.description}
>
<Editor
height="300px"
defaultLanguage={property.editorConfig.language || 'shell'}
theme={property.editorConfig.theme || 'vs-dark'}
value={buildVariables[key] || property.default || ''}
onChange={(value) => setBuildVariables({
...buildVariables,
[key]: value || ''
})}
options={{
minimap: { enabled: property.editorConfig.minimap ?? false },
fontSize: property.editorConfig.fontSize || 14,
lineNumbers: property.editorConfig.lineNumbers ? 'on' : 'off',
wordWrap: property.editorConfig.wordWrap ? 'on' : 'off',
tabSize: property.editorConfig.tabSize || 2,
scrollBeyondLastLine: false,
automaticLayout: true,
folding: property.editorConfig.folding ?? true,
autoClosingBrackets: 'always',
autoClosingQuotes: 'always',
formatOnPaste: true,
formatOnType: true,
suggestOnTriggerCharacters: property.editorConfig.autoComplete ?? true,
renderWhitespace: 'boundary',
}}
loading={
<div style={{
padding: '8px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '300px',
background: '#1e1e1e',
color: '#fff'
}}>
...
</div>
}
/>
</Form.Item>
) : null
))}
{/* 其他配置项 */}
<BetaSchemaForm
@ -184,7 +186,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
columns={convertJsonSchemaToColumns({
type: 'object',
properties: Object.fromEntries(
Object.entries(properties).filter(([key]) => key !== 'script')
Object.entries(properties).filter(([_, prop]) => !prop.editorConfig)
),
required: selectedTemplate.buildVariablesSchema.required || []
})}