From f64b9a8d72e04febf39941be577ab5460d42af19 Mon Sep 17 00:00:00 2001 From: asp_ly Date: Fri, 17 Jan 2025 22:26:55 +0800 Subject: [PATCH] 1 --- .../List/components/DeploymentConfigModal.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/frontend/src/pages/Deploy/Deployment/List/components/DeploymentConfigModal.tsx b/frontend/src/pages/Deploy/Deployment/List/components/DeploymentConfigModal.tsx index 7535f4d0..404c4639 100644 --- a/frontend/src/pages/Deploy/Deployment/List/components/DeploymentConfigModal.tsx +++ b/frontend/src/pages/Deploy/Deployment/List/components/DeploymentConfigModal.tsx @@ -75,8 +75,8 @@ interface DeploymentConfigModalProps { // 定义字段映射接口 interface FieldMapping { - label: string; // 显示字段 - value: string; // 值字段 + label?: string; + value?: string; } const DeploymentConfigModal: React.FC = ({ @@ -88,19 +88,19 @@ const DeploymentConfigModal: React.FC = ({ }) => { // 通用的异步数据源加载方法 - 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 = ({ 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 = ({ 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 = ({ 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)}}' } } },