This commit is contained in:
asp_ly 2025-01-17 22:26:55 +08:00
parent 80aa81708b
commit f64b9a8d72

View File

@ -75,8 +75,8 @@ interface DeploymentConfigModalProps {
// 定义字段映射接口 // 定义字段映射接口
interface FieldMapping { interface FieldMapping {
label: string; // 显示字段 label?: string;
value: string; // 值字段 value?: string;
} }
const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
@ -88,19 +88,19 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
}) => { }) => {
// 通用的异步数据源加载方法 // 通用的异步数据源加载方法
const useAsyncDataSource = ( const useAsyncDataSource = (url: string | null, mapping: FieldMapping = {}) => (field: Field) => {
url: string, if (!url) {
options?: { field.dataSource = [];
mapping?: FieldMapping; return;
} }
) => (field: Field) => {
const {mapping = {label: 'name', value: 'id'}} = options || {}; const { label = 'name', value = 'id' } = mapping;
field.loading = true; field.loading = true;
request.get(url) request.get(url)
.then(action.bound?.((response) => { .then(action.bound?.((response) => {
field.dataSource = response.map((item: any) => ({ field.dataSource = response.map((item: any) => ({
label: item[mapping.label], label: item[label],
value: item[mapping.value] value: item[value]
})); }));
field.loading = false; field.loading = false;
})) }))
@ -160,7 +160,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
placeholder: '请选择三方系统', placeholder: '请选择三方系统',
allowClear: true allowClear: true
}, },
'x-reactions': ["{{useAsyncDataSource('/api/v1/external-system/list?type=JENKINS', { mapping: { label: 'name', value: 'id' } })}}"], 'x-reactions': ["{{useAsyncDataSource('/api/v1/external-system/list?type=JENKINS', { label: 'name' })}}"],
}, },
viewId: { viewId: {
type: 'string', type: 'string',
@ -189,7 +189,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
state: { state: {
value: undefined value: undefined
}, },
run: '{{$deps[0] ? useAsyncDataSource(`/api/v1/jenkins-view/list?externalSystemId=${$deps[0]}`, { mapping: { label: "viewName", value: "id" } })($self) : ($self.dataSource = [])}}' run: '{{useAsyncDataSource($deps[0] ? `/api/v1/jenkins-view/list?externalSystemId=${$deps[0]}` : null, { label: "viewName" })($self)}}'
} }
} }
}, },
@ -220,7 +220,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
state: { state: {
value: undefined value: undefined
}, },
run: '{{($deps[0] && $deps[1]) ? useAsyncDataSource(`/api/v1/jenkins-job/list?externalSystemId=${$deps[0]}&viewId=${$deps[1]}`, { mapping: { label: "jobName", value: "id" } })($self) : ($self.dataSource = [])}}' run: '{{useAsyncDataSource(($deps[0] && $deps[1]) ? `/api/v1/jenkins-job/list?externalSystemId=${$deps[0]}&viewId=${$deps[1]}` : null, { label: "jobName" })($self)}}'
} }
} }
}, },