1
This commit is contained in:
parent
80aa81708b
commit
f64b9a8d72
@ -75,8 +75,8 @@ interface DeploymentConfigModalProps {
|
||||
|
||||
// 定义字段映射接口
|
||||
interface FieldMapping {
|
||||
label: string; // 显示字段
|
||||
value: string; // 值字段
|
||||
label?: string;
|
||||
value?: string;
|
||||
}
|
||||
|
||||
const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
|
||||
@ -88,19 +88,19 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
|
||||
}) => {
|
||||
|
||||
// 通用的异步数据源加载方法
|
||||
const useAsyncDataSource = (
|
||||
url: string,
|
||||
options?: {
|
||||
mapping?: FieldMapping;
|
||||
const useAsyncDataSource = (url: string | null, mapping: FieldMapping = {}) => (field: Field) => {
|
||||
if (!url) {
|
||||
field.dataSource = [];
|
||||
return;
|
||||
}
|
||||
) => (field: Field) => {
|
||||
const {mapping = {label: 'name', value: 'id'}} = options || {};
|
||||
|
||||
const { label = 'name', value = 'id' } = mapping;
|
||||
field.loading = true;
|
||||
request.get(url)
|
||||
.then(action.bound?.((response) => {
|
||||
field.dataSource = response.map((item: any) => ({
|
||||
label: item[mapping.label],
|
||||
value: item[mapping.value]
|
||||
label: item[label],
|
||||
value: item[value]
|
||||
}));
|
||||
field.loading = false;
|
||||
}))
|
||||
@ -160,7 +160,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
|
||||
placeholder: '请选择三方系统',
|
||||
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: {
|
||||
type: 'string',
|
||||
@ -189,7 +189,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
|
||||
state: {
|
||||
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: {
|
||||
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)}}'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user