新增redirectTo
This commit is contained in:
parent
03678862d5
commit
5ce89336a1
|
|
@ -117,7 +117,7 @@ export function makeCommonComponentMethods<
|
|||
>['formData']
|
||||
): Omit<
|
||||
OakCommonComponentMethods<ED, T>,
|
||||
'navigateTo' | 'navigateBack' | 'resolveInput'
|
||||
'navigateTo' | 'navigateBack' | 'resolveInput' | 'redirectTo'
|
||||
> &
|
||||
ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod> {
|
||||
return {
|
||||
|
|
@ -260,8 +260,14 @@ export function makeCommonComponentMethods<
|
|||
}
|
||||
},
|
||||
|
||||
toggleNode(nodeData: Record<string, any>, checked: boolean, path?: string) {
|
||||
const fullpath = path ? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
|
||||
toggleNode(
|
||||
nodeData: Record<string, any>,
|
||||
checked: boolean,
|
||||
path?: string
|
||||
) {
|
||||
const fullpath = path
|
||||
? `${this.state.oakFullpath}.${path}`
|
||||
: this.state.oakFullpath;
|
||||
features.runningTree.toggleNode(fullpath, nodeData, checked);
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ function makeCommonComponentMethods<
|
|||
): OakCommonComponentMethods<ED, T> &
|
||||
ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod> {
|
||||
return {
|
||||
resolveInput: (input: WechatMiniprogram.CustomEvent, keys) => {
|
||||
resolveInput(input: WechatMiniprogram.CustomEvent, keys) {
|
||||
const { currentTarget, detail } = input;
|
||||
const { dataset } = currentTarget;
|
||||
const { value } = detail;
|
||||
|
|
@ -66,19 +66,19 @@ function makeCommonComponentMethods<
|
|||
}
|
||||
return result;
|
||||
},
|
||||
navigateBack: (option) => {
|
||||
return new Promise(
|
||||
(resolve, reject) => {
|
||||
wx.navigateBack(assign({}, option, {
|
||||
navigateBack(option) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.navigateBack(
|
||||
assign({}, option, {
|
||||
success() {
|
||||
resolve(undefined);
|
||||
},
|
||||
fail(err: any) {
|
||||
reject(err);
|
||||
}
|
||||
}));
|
||||
}
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
},
|
||||
navigateTo(options) {
|
||||
const { url, events, fail, complete, success, ...rest } = options;
|
||||
|
|
@ -97,9 +97,9 @@ function makeCommonComponentMethods<
|
|||
assign(options, {
|
||||
url: url2,
|
||||
});
|
||||
return new Promise(
|
||||
(resolve, reject) => {
|
||||
wx.navigateTo(assign({}, options, {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.navigateTo(
|
||||
assign({}, options, {
|
||||
success(res: any) {
|
||||
success && success(res);
|
||||
resolve(undefined);
|
||||
|
|
@ -107,10 +107,42 @@ function makeCommonComponentMethods<
|
|||
fail(err: any) {
|
||||
fail && fail(err);
|
||||
reject(err);
|
||||
}
|
||||
}))
|
||||
}
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
},
|
||||
redirectTo(options) {
|
||||
const { url, events, fail, complete, success, ...rest } = options;
|
||||
let url2 = url.includes('?')
|
||||
? url.concat(`&oakFrom=${this.state.oakFullpath}`)
|
||||
: url.concat(`?oakFrom=${this.state.oakFullpath}`);
|
||||
|
||||
for (const param in rest) {
|
||||
const param2 = param as unknown as keyof typeof rest;
|
||||
url2 += `&${param}=${
|
||||
typeof rest[param2] === 'string'
|
||||
? rest[param2]
|
||||
: JSON.stringify(rest[param2])
|
||||
}`;
|
||||
}
|
||||
assign(options, {
|
||||
url: url2,
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.redirectTo(
|
||||
assign({}, options, {
|
||||
success(res: any) {
|
||||
success && success(res);
|
||||
resolve(undefined);
|
||||
},
|
||||
fail(err: any) {
|
||||
fail && fail(err);
|
||||
reject(err);
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
...makeCommon(features, exceptionRouterDict, formData),
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ function makeCommonComponentMethods<
|
|||
): OakCommonComponentMethods<ED, T> &
|
||||
ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod> {
|
||||
return {
|
||||
resolveInput: (input: React.BaseSyntheticEvent, keys) => {
|
||||
resolveInput(input: React.BaseSyntheticEvent, keys) {
|
||||
const { currentTarget, target } = input;
|
||||
const { value, dataset } = target;
|
||||
const result = {
|
||||
|
|
@ -73,9 +73,20 @@ function makeCommonComponentMethods<
|
|||
}
|
||||
return result;
|
||||
},
|
||||
navigateBack: (option) => wx.navigateBack(option),
|
||||
navigateBack(option) {
|
||||
const { delta } = option || {};
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
this.props.navigateBack(delta || -1);
|
||||
resolve(undefined);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
navigateTo(options) {
|
||||
const { url, events, fail, complete, success, ...rest } = options;
|
||||
const { url, events, fail, complete, success, state, ...rest } =
|
||||
options;
|
||||
let url2 = url.includes('?')
|
||||
? url.concat(`&oakFrom=${this.state.oakFullpath}`)
|
||||
: url.concat(`?oakFrom=${this.state.oakFullpath}`);
|
||||
|
|
@ -88,10 +99,24 @@ function makeCommonComponentMethods<
|
|||
: JSON.stringify(rest[param2])
|
||||
}`;
|
||||
}
|
||||
assign(options, {
|
||||
url: url2,
|
||||
});
|
||||
return wx.navigateTo(options);
|
||||
return this.props.navigate(url2, { replace: false, state });
|
||||
},
|
||||
redirectTo(options) {
|
||||
const { url, events, fail, complete, success, state, ...rest } =
|
||||
options;
|
||||
let url2 = url.includes('?')
|
||||
? url.concat(`&oakFrom=${this.state.oakFullpath}`)
|
||||
: url.concat(`?oakFrom=${this.state.oakFullpath}`);
|
||||
|
||||
for (const param in rest) {
|
||||
const param2 = param as unknown as keyof typeof rest;
|
||||
url2 += `&${param}=${
|
||||
typeof rest[param2] === 'string'
|
||||
? rest[param2]
|
||||
: JSON.stringify(rest[param2])
|
||||
}`;
|
||||
}
|
||||
return this.props.navigate(url2, { replace: true, state });
|
||||
},
|
||||
|
||||
...makeCommon(features, exceptionRouterDict, formData),
|
||||
|
|
@ -241,11 +266,8 @@ export function createPage<
|
|||
});
|
||||
}
|
||||
if (methods) {
|
||||
const {
|
||||
onPullDownRefresh,
|
||||
onReachBottom,
|
||||
...restMethods
|
||||
} = methods;
|
||||
const { onPullDownRefresh, onReachBottom, ...restMethods } =
|
||||
methods;
|
||||
for (const m in restMethods) {
|
||||
assign(this, {
|
||||
[m]: restMethods[m as keyof typeof restMethods]!.bind(
|
||||
|
|
@ -294,14 +316,15 @@ export function createPage<
|
|||
this.isReachBottom = isCurrentReachBottom;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
methods?.onLoad && methods.onLoad.call(this, this.props);
|
||||
methods?.onReady && methods.onReady.call(this);
|
||||
lifetimes?.ready && lifetimes.ready.call(this);
|
||||
pageLifetimes?.show && pageLifetimes.show.call(this);
|
||||
async componentDidMount() {
|
||||
await onLoad.call(this, this.props);
|
||||
methods?.onLoad && await methods.onLoad.call(this, this.props);
|
||||
methods?.onReady && await methods.onReady.call(this);
|
||||
lifetimes?.ready && await lifetimes.ready.call(this);
|
||||
pageLifetimes?.show && await pageLifetimes.show.call(this);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
async componentWillUnmount() {
|
||||
hiddenMethods.unsubscribe.call(this);
|
||||
methods?.onUnload && methods.onUnload.call(this);
|
||||
lifetimes?.detached && lifetimes.detached.call(this);
|
||||
|
|
@ -446,12 +469,26 @@ export function createComponent<
|
|||
features = features;
|
||||
isReachBottom = false;
|
||||
|
||||
componentDidMount() {
|
||||
async componentDidMount() {
|
||||
const { oakPath, oakParent } = this.props;
|
||||
if (oakParent && oakPath) {
|
||||
const oakFullpath = `${oakParent}.${oakPath}`;
|
||||
this.setState(
|
||||
{
|
||||
oakFullpath,
|
||||
oakEntity: entity as any,
|
||||
},
|
||||
() => {
|
||||
commonMethods.reRender.call(this);
|
||||
}
|
||||
);
|
||||
}
|
||||
hiddenMethods.subscribe.call(this);
|
||||
lifetimes?.ready && lifetimes.ready.call(this);
|
||||
pageLifetimes?.show && pageLifetimes.show.call(this);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
async componentWillUnmount() {
|
||||
hiddenMethods.unsubscribe.call(this);
|
||||
lifetimes?.detached && lifetimes.detached.call(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ export type OakCommonComponentMethods<ED extends EntityDict, T extends keyof ED>
|
|||
[k in K]?: any;
|
||||
};
|
||||
reRender: (extra?: Record<string, any>) => Promise<void>;
|
||||
redirectTo: <T2 extends keyof ED>(options: Parameters<typeof wx.redirectTo>[0] & OakNavigateToParameters<ED, T2>) => Promise<void>
|
||||
navigateTo: <T2 extends keyof ED>(options: Parameters<typeof wx.navigateTo>[0] & OakNavigateToParameters<ED, T2>) => Promise<void>;
|
||||
navigateBack: (option?: { delta: number }) => Promise<void>;
|
||||
resetUpdateData: () => void;
|
||||
|
|
@ -287,6 +288,7 @@ export type OakPageData<ED extends EntityDict, T extends keyof ED> = {
|
|||
oakLegalActions: ED[T]['Action'][];
|
||||
oakLoading: boolean;
|
||||
oakLoadingMore: boolean;
|
||||
oakEntity: string;
|
||||
};
|
||||
|
||||
export type OakComponentData<ED extends EntityDict, T extends keyof ED> = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue