diff --git a/packages/client/src/components/admin-layout/SiteTitle.tsx b/packages/client/src/components/admin-layout/SiteTitle.tsx index 0667d4a4c..2847155ff 100644 --- a/packages/client/src/components/admin-layout/SiteTitle.tsx +++ b/packages/client/src/components/admin-layout/SiteTitle.tsx @@ -38,7 +38,7 @@ export const SiteTitle = () => { {!loading && data?.logo?.url && ( )} - {!loading && !data.showLogoOnly && data.title && ( + {!loading && !data?.showLogoOnly && data?.title && (
{data.title}
)} diff --git a/packages/client/src/components/admin-layout/style.less b/packages/client/src/components/admin-layout/style.less index 6dd5c7b3d..3c65efa13 100644 --- a/packages/client/src/components/admin-layout/style.less +++ b/packages/client/src/components/admin-layout/style.less @@ -62,6 +62,7 @@ color: #fff; } } + .site-info { display: flex; align-items: center; @@ -72,5 +73,6 @@ .site-title { color: #fff; font-size: 20px; + padding-right: 8px; } -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/cascader/demos/demo2.tsx b/packages/client/src/schemas/cascader/demos/demo2.tsx index 2cd1ec8c1..1e4ca9c81 100644 --- a/packages/client/src/schemas/cascader/demos/demo2.tsx +++ b/packages/client/src/schemas/cascader/demos/demo2.tsx @@ -34,8 +34,7 @@ const schema = { 'x-component': 'Cascader', 'x-component-props': { changeOnSelect: true, - loadData: '{{ loadData }}', - useDataSource: '{{ useDataSource }}', + loadData: '{{ loadChinaRegionData }}', labelInValue: true, maxLevel: 3, fieldNames: { @@ -46,7 +45,7 @@ const schema = { // changeOnSelect: true, }, 'x-reactions': [ - // '{{useAsyncDataSource(loadOptions)}}', + '{{useAsyncDataSource(loadChinaRegions)}}', { target: 'read', fulfill: { @@ -67,8 +66,7 @@ const schema = { 'x-component': 'Cascader', 'x-component-props': { changeOnSelect: true, - loadData: '{{ loadData }}', - useDataSource: '{{ useDataSource }}', + loadData: '{{ loadChinaRegionData }}', labelInValue: true, fieldNames: { label: 'name', @@ -80,32 +78,30 @@ const schema = { }, }; -const useDataSource = ({ onSuccess }) => { - const field = useField(); +// disableAsyncDataSource +const loadChinaRegions = async (field) => { const maxLevel = field.componentProps.maxLevel || 3; const resource = Resource.make('china_regions'); - useRequest( - () => - resource.list({ - perPage: -1, - filter: { - level: 1, - }, - }), - { - formatResult: (data) => - data?.data?.map((item) => { - if (maxLevel !== 1) { - item.isLeaf = false; - } - return item; - }), - onSuccess, + const { data } = await resource.list({ + perPage: -1, + filter: { + level: 1, }, + }); + return ( + data?.map((item) => { + if (maxLevel !== 1) { + item.isLeaf = false; + } + return item; + }) || [] ); }; -const loadData = (selectedOptions: CascaderOptionType[], field: ArrayField) => { +const loadChinaRegionData = ( + selectedOptions: CascaderOptionType[], + field: ArrayField, +) => { const maxLevel = field.componentProps.maxLevel || 3; const targetOption = selectedOptions[selectedOptions.length - 1]; targetOption.loading = true; @@ -132,6 +128,6 @@ const loadData = (selectedOptions: CascaderOptionType[], field: ArrayField) => { export default () => { return ( - + ); }; diff --git a/packages/client/src/schemas/cascader/index.tsx b/packages/client/src/schemas/cascader/index.tsx index c75fe3d4e..362389d86 100644 --- a/packages/client/src/schemas/cascader/index.tsx +++ b/packages/client/src/schemas/cascader/index.tsx @@ -28,11 +28,10 @@ export const Cascader = connect( onChange, loadData, labelInValue, - useDataSource, fieldNames = defaultFieldNames, ...others } = props; - console.log('Cascader', props) + console.log('Cascader', props); // 兼容值为 object[] 的情况 const toValue = () => { return toArr(value).map((item) => { @@ -46,6 +45,7 @@ export const Cascader = connect( const values = toArr(value); if (values.length !== labels.length) { labels = toValue(); + selectedOptions = values; } if (selectedOptions.length === 0) { selectedOptions = values; @@ -73,14 +73,6 @@ export const Cascader = connect( ); }); }; - // 这里没有用 x-reactions 是因为 readyPretty=true 时不需要 - if (typeof useDataSource === 'function') { - useDataSource({ - onSuccess: (data) => { - field.dataSource = data; - }, - }); - } if (loadData) { Object.assign(others, { loadData: (selectedOptions: CascaderOptionType[]) => { diff --git a/packages/client/src/schemas/database-field/interfaces/chinaRegion.ts b/packages/client/src/schemas/database-field/interfaces/chinaRegion.ts index 5568b5cdc..4b9c58500 100644 --- a/packages/client/src/schemas/database-field/interfaces/chinaRegion.ts +++ b/packages/client/src/schemas/database-field/interfaces/chinaRegion.ts @@ -28,6 +28,7 @@ export const chinaRegion: FieldOptions = { children: 'children', }, }, + 'x-reactions': ['{{useAsyncDataSource(loadChinaRegions)}}'], 'x-decorator': 'FormItem', 'x-designable-bar': 'Cascader.DesignableBar', },