diff --git a/packages/amis-editor/src/renderer/TimelineItemControl.tsx b/packages/amis-editor/src/renderer/TimelineItemControl.tsx index bad977484..47727a9e3 100644 --- a/packages/amis-editor/src/renderer/TimelineItemControl.tsx +++ b/packages/amis-editor/src/renderer/TimelineItemControl.tsx @@ -79,6 +79,7 @@ export default class TimelineItemControl extends React.Component< data.items = items.map(item => ({...item})); } if (source === 'api' || source === 'variable') { + data.items = []; data.source = api; } onBulkChange && onBulkChange(data); diff --git a/packages/amis-ui/src/components/WithRemoteConfig.tsx b/packages/amis-ui/src/components/WithRemoteConfig.tsx index 109bb2171..454fe1148 100644 --- a/packages/amis-ui/src/components/WithRemoteConfig.tsx +++ b/packages/amis-ui/src/components/WithRemoteConfig.tsx @@ -243,20 +243,16 @@ export function withRemoteConfig

( this.props.env || (this.context as RendererEnv); const {store, data} = this.props; const source = (this.props as any)[config.sourceField || 'source']; + if (isPureVariable(source)) { - //监听上下文变量变化 this.toDispose.push( reaction( - () => { - const source = (this.props as any)[ - config.sourceField || 'source' - ]; - return resolveVariableAndFilter( + () => + resolveVariableAndFilter( source as string, store.data, '| raw' - ); - }, + ), () => this.syncConfig(), // 当nav配置source: "${amisStore.app.portalNavs}"时,切换页面就会触发source更新 // 因此这里增加这个配置 数据源完全不相等情况下再执行loadConfig @@ -266,47 +262,32 @@ export function withRemoteConfig

( ); } else if (env && isEffectiveApi(source, data)) { this.loadConfig(); + (source as ApiObject).autoRefresh !== false && + this.toDispose.push( + reaction( + () => { + const api = normalizeApi(source as string); + return api.trackExpression + ? tokenize(api.trackExpression, store.data) + : buildApi(api, store.data, { + ignoreData: true + }).url; + }, + () => this.loadConfig() + ) + ); } } componentDidUpdate(prevProps: any) { - //监听source变化 - const env: RendererEnv = - this.props.env || (this.context as RendererEnv); - const {store, data} = this.props; - let source = (this.props as any)[config.sourceField || 'source']; - const prevSource = prevProps.source; - const prevApi = normalizeApi(prevSource as string); - const api = normalizeApi(source as string); - //如果没对上下文变量进行监听,则进行监听 - if (isPureVariable(source) && !this.toDispose.length) { - //比较上下文变量是否变化 - resolveVariableAndFilter( - prevSource as string, - store.data, - '| raw' - ) !== - resolveVariableAndFilter( - source as string, - store.data, - '| raw' - ) && this.syncConfig(); - } else if (env && isEffectiveApi(source, data)) { - //比较api是否变化 - (source as ApiObject).autoRefresh !== false && - (api.trackExpression - ? tokenize(api.trackExpression, store.data) - : buildApi(api, store.data, { - ignoreData: true - }).url) !== - (prevApi.trackExpression - ? tokenize(prevApi.trackExpression, store.data) - : buildApi(prevApi, store.data, { - ignoreData: true - }).url) && - this.loadConfig(); + const {source, data, store} = this.props; + if (source !== prevProps.source) { + // 如果是变量,则同步配置。如果为api,则重新加载配置 + (isPureVariable(source) && this.syncConfig()) || + (isEffectiveApi(source, data) && + (source as ApiObject).autoRefresh !== false && + this.loadConfig()); } - if (data !== prevProps.data) { store.setData(data); } diff --git a/packages/amis/src/renderers/Timeline.tsx b/packages/amis/src/renderers/Timeline.tsx index 674c0063f..fcc712960 100644 --- a/packages/amis/src/renderers/Timeline.tsx +++ b/packages/amis/src/renderers/Timeline.tsx @@ -198,6 +198,23 @@ const TimelineWithRemoteConfig = withRemoteConfig({ class extends React.Component< RemoteOptionsProps & React.ComponentProps > { + componentDidMount() { + const {source, updateConfig, config} = this.props; + if (typeof source === 'object' && !source.url && config) { + updateConfig(undefined); + } + } + componentDidUpdate(prevProps: any) { + const {source, updateConfig, config} = this.props; + + if ( + (!source || (typeof source === 'object' && !source.url)) && + config && + source !== prevProps.source + ) { + updateConfig(undefined); + } + } render() { const {config, items, deferLoad, loading, updateConfig, source, ...rest} = this.props; @@ -211,10 +228,6 @@ const TimelineWithRemoteConfig = withRemoteConfig({ })) : items || []; - // 如果items有值或者source为空,则直接使用items - if (items?.length || !source) { - sourceItems = items || []; - } return ; } }