From 6246d152b0526faf17d0b00198f92f5debbdef3c Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sat, 7 Jan 2023 09:30:19 +0800 Subject: [PATCH] feat(Select): should compile title and label (#1332) --- .../antd/remote-select/RemoteSelect.tsx | 15 +++++++++++++-- .../src/schema-component/hooks/useFieldTitle.ts | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx b/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx index b309c1744..9d027c924 100644 --- a/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx +++ b/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx @@ -2,8 +2,9 @@ import { LoadingOutlined } from '@ant-design/icons'; import { connect, mapProps, mapReadPretty } from '@formily/react'; import { SelectProps } from 'antd'; import _ from 'lodash'; -import React from 'react'; +import React, { useMemo } from 'react'; import { ResourceActionOptions, useRequest } from '../../../api-client'; +import { useCompile } from '../../hooks'; import { defaultFieldNames, Select } from '../select'; import { ReadPretty } from './ReadPretty'; @@ -18,6 +19,7 @@ export type RemoteSelectProps

= SelectProps & { const InternalRemoteSelect = connect( (props: RemoteSelectProps) => { const { fieldNames = {}, service = {}, wait = 300, ...others } = props; + const compile = useCompile(); const { data, run } = useRequest( { @@ -54,6 +56,15 @@ const InternalRemoteSelect = connect( }); }; + const options = useMemo(() => { + return ( + data?.data?.map((item) => ({ + ...item, + [fieldNames.label]: compile(item[fieldNames.label]), + })) || [] + ); + }, [data, fieldNames.label]); + return (