This commit is contained in:
asp_ly 2025-01-17 22:12:50 +08:00
parent ee14a4653a
commit 8f4a3efd81

View File

@ -91,13 +91,12 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
const useAsyncDataSource = ( const useAsyncDataSource = (
url: string, url: string,
options?: { options?: {
params?: Record<string, any>;
mapping?: FieldMapping; mapping?: FieldMapping;
} }
) => (field: Field) => { ) => (field: Field) => {
const {params, mapping = {label: 'name', value: 'id'}} = options || {}; const {mapping = {label: 'name', value: 'id'}} = options || {};
field.loading = true; field.loading = true;
request.get(url, {params}) 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[mapping.label],
@ -180,7 +179,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
placeholder: '请选择三方系统', placeholder: '请选择三方系统',
allowClear: true allowClear: true
}, },
'x-reactions': ["{{useAsyncDataSource('/api/v1/external-system/list', { params: { type: 'JENKINS' }, mapping: { label: 'name', value: 'id' } })}}"], 'x-reactions': ["{{useAsyncDataSource('/api/v1/external-system/list?type=JENKINS', { mapping: { label: 'name', value: 'id' } })}}"],
}, },
viewId: { viewId: {
type: 'string', type: 'string',
@ -208,7 +207,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
state: { state: {
value: undefined value: undefined
}, },
run: '{{function runEffect(){if($deps[0]){useAsyncDataSource("/api/v1/jenkins-view/list", { params: { externalSystemId: $deps[0] }, mapping: { label: "viewName", value: "id" } })($self)}else{$self.dataSource=[];}};runEffect()}}' run: '{{function runEffect(){if($deps[0]){useAsyncDataSource(`/api/v1/jenkins-view/list?externalSystemId=${$deps[0]}`, { mapping: { label: "viewName", value: "id" } })($self)}else{$self.dataSource=[];}};runEffect()}}'
} }
}, },
"description": "{{$self.dataSource && $self.value ? ($self.dataSource.find(item => item.value === $self.value)?.extra?.description) : undefined}}" "description": "{{$self.dataSource && $self.value ? ($self.dataSource.find(item => item.value === $self.value)?.extra?.description) : undefined}}"
@ -239,7 +238,7 @@ const DeploymentConfigModal: React.FC<DeploymentConfigModalProps> = ({
state: { state: {
value: undefined value: undefined
}, },
run: '{{function runEffect(){if($deps[0] && $deps[1]){useAsyncDataSource("/api/v1/jenkins-job/list", { params: { externalSystemId: $deps[0], viewId: $deps[1] }, mapping: { label: "jobName", value: "id" } })($self)}else{$self.dataSource=[];}};runEffect()}}' run: '{{function runEffect(){if($deps[0] && $deps[1]){useAsyncDataSource(`/api/v1/jenkins-job/list?externalSystemId=${$deps[0]}&viewId=${$deps[1]}`, { mapping: { label: "jobName", value: "id" } })($self)}else{$self.dataSource=[];}};runEffect()}}'
} }
}, },
"description": "{{$self.dataSource && $self.value ? ($self.dataSource.find(item => item.value === $self.value)?.extra?.description) : undefined}}" "description": "{{$self.dataSource && $self.value ? ($self.dataSource.find(item => item.value === $self.value)?.extra?.description) : undefined}}"