onLoad新增参数callback, 解决react didmount中 ready取到oakfullpath

This commit is contained in:
Wang Kejun 2022-07-05 18:52:20 +08:00
parent 5ce89336a1
commit 454b48f0a2
3 changed files with 14 additions and 12 deletions

View File

@ -617,7 +617,7 @@ export function makePageMethods<
} }
}, },
async onLoad(pageOption) { async onLoad(pageOption, callback) {
const { const {
oakId, oakId,
oakEntity, oakEntity,
@ -704,7 +704,7 @@ export function makePageMethods<
id: oakId, id: oakId,
}); });
// const oakFullpath = oakParent ? `${oakParent}.${oakPath || options.path}` : oakPath || options.path; // const oakFullpath = oakParent ? `${oakParent}.${oakPath || options.path}` : oakPath || options.path;
this.setState( await this.setState(
{ {
oakEntity: node.getEntity(), oakEntity: node.getEntity(),
oakFullpath: path2, oakFullpath: path2,
@ -716,6 +716,7 @@ export function makePageMethods<
}, },
() => { () => {
this.refresh(); this.refresh();
callback && callback.call(this);
} }
); );
options.methods?.onLoad && options.methods.onLoad.call(this, pageOption); options.methods?.onLoad && options.methods.onLoad.call(this, pageOption);

View File

@ -77,7 +77,7 @@ function makeCommonComponentMethods<
const { delta } = option || {}; const { delta } = option || {};
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
this.props.navigateBack(delta || -1); this.props.navigate(delta || -1);
resolve(undefined); resolve(undefined);
} catch (err) { } catch (err) {
reject(err); reject(err);
@ -156,9 +156,6 @@ function makePageMethods<
return { return {
async onPullDownRefresh() { async onPullDownRefresh() {
await onPullDownRefresh.call(this); await onPullDownRefresh.call(this);
if (!this.state.oakLoading) {
await wx.stopPullDownRefresh();
}
}, },
...rest, ...rest,
}; };
@ -317,11 +314,12 @@ export function createPage<
} }
async componentDidMount() { async componentDidMount() {
await onLoad.call(this, this.props); await onLoad.call(this, this.props, () => {
methods?.onLoad && await methods.onLoad.call(this, this.props); methods?.onLoad && methods.onLoad.call(this, this.props);
methods?.onReady && await methods.onReady.call(this); methods?.onReady && methods.onReady.call(this);
lifetimes?.ready && await lifetimes.ready.call(this); lifetimes?.ready && lifetimes.ready.call(this);
pageLifetimes?.show && await pageLifetimes.show.call(this); pageLifetimes?.show && pageLifetimes.show.call(this);
});
} }
async componentWillUnmount() { async componentWillUnmount() {

View File

@ -256,7 +256,10 @@ export type OakPageMethods = {
refresh: (extra?: any) => Promise<void>; refresh: (extra?: any) => Promise<void>;
onPullDownRefresh: () => Promise<void>; onPullDownRefresh: () => Promise<void>;
onReachBottom: () => Promise<void>; onReachBottom: () => Promise<void>;
onLoad: (options: Record<string, string | undefined>) => Promise<void>; onLoad: (
options: Record<string, string | undefined>,
callback?: () => void
) => Promise<void>;
}; };
export type OakComponentInstanceProperties< export type OakComponentInstanceProperties<