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