mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: 修复timeline组件自测已知问题
This commit is contained in:
parent
7ace846fa7
commit
37cc524dcd
@ -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);
|
||||
|
@ -243,20 +243,16 @@ export function withRemoteConfig<P = any>(
|
||||
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<P = any>(
|
||||
);
|
||||
} 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);
|
||||
}
|
||||
|
@ -198,6 +198,23 @@ const TimelineWithRemoteConfig = withRemoteConfig({
|
||||
class extends React.Component<
|
||||
RemoteOptionsProps & React.ComponentProps<typeof TimelineCmpt>
|
||||
> {
|
||||
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 <TimelineCmpt items={sourceItems} {...rest} />;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user