execute 增加参数messageProps 处理提交时 setMessage可禁用

This commit is contained in:
Wang Kejun 2022-12-14 12:00:17 +08:00
parent 9fc9f7e95c
commit 4bf8e981d2
9 changed files with 108 additions and 70 deletions

View File

@ -3,9 +3,10 @@ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { OakComponentOption, ComponentFullThisType } from './types/Page'; import { OakComponentOption, ComponentFullThisType } from './types/Page';
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
import { MessageProps } from './types/Message';
export declare function onPathSet<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>, option: OakComponentOption<ED, T, Cxt, FrontCxt, any, any, any, any, {}, {}, {}>): void; export declare function onPathSet<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>, option: OakComponentOption<ED, T, Cxt, FrontCxt, any, any, any, any, {}, {}, {}>): void;
export declare function reRender<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>, option: OakComponentOption<ED, T, Cxt, FrontCxt, any, any, any, any, {}, {}, {}>, extra?: Record<string, any>): void; export declare function reRender<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>, option: OakComponentOption<ED, T, Cxt, FrontCxt, any, any, any, any, {}, {}, {}>, extra?: Record<string, any>): void;
export declare function refresh<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>): Promise<void>; export declare function refresh<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>): Promise<void>;
export declare function loadMore<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>): Promise<void>; export declare function loadMore<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>): Promise<void>;
export declare function execute<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>, action?: ED[T]['Action'], path?: string): Promise<void>; export declare function execute<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>, action?: ED[T]['Action'], path?: string, messageProps?: boolean | MessageProps): Promise<void>;
export declare function destroyNode<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>): void; export declare function destroyNode<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>>(this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>): void;

View File

@ -259,23 +259,31 @@ function loadMore() {
}); });
} }
exports.loadMore = loadMore; exports.loadMore = loadMore;
function execute(action, path) { function execute(action, path, messageProps) {
return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__awaiter(this, void 0, void 0, function () {
var fullpath; var fullpath, messageData;
return tslib_1.__generator(this, function (_a) { return tslib_1.__generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
if (this.state.oakExecuting) { if (this.state.oakExecuting) {
throw new Error('请仔细设计按钮状态,不要允许重复点击!'); throw new Error('请仔细设计按钮状态,不要允许重复点击!');
} }
fullpath = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; fullpath = path
? "".concat(this.state.oakFullpath, ".").concat(path)
: this.state.oakFullpath;
return [4 /*yield*/, this.features.runningTree.execute(fullpath, action)]; return [4 /*yield*/, this.features.runningTree.execute(fullpath, action)];
case 1: case 1:
_a.sent(); _a.sent();
this.setMessage({ if (messageProps !== false) {
messageData = {
type: 'success', type: 'success',
content: '操作成功', content: '操作成功',
}); };
if (typeof messageProps === 'object') {
Object.assign(messageData, messageProps);
}
this.setMessage(messageData);
}
return [2 /*return*/]; return [2 /*return*/];
} }
}); });

View File

@ -224,8 +224,8 @@ var oakBehavior = Behavior({
: this.state.oakFullpath; : this.state.oakFullpath;
return this.features.runningTree.clean(path2); return this.features.runningTree.clean(path2);
}, },
execute: function (action, path) { execute: function (action, messageProps) {
return page_common_1.execute.call(this, action, path); return page_common_1.execute.call(this, action, undefined, messageProps);
}, },
getFreshValue: function (path) { getFreshValue: function (path) {
var path2 = path var path2 = path

View File

@ -157,8 +157,8 @@ var OakComponentBase = /** @class */ (function (_super) {
OakComponentBase.prototype.t = function (key, params) { OakComponentBase.prototype.t = function (key, params) {
return this.props.t(key, params); return this.props.t(key, params);
}; };
OakComponentBase.prototype.execute = function (action) { OakComponentBase.prototype.execute = function (action, messageProps) {
return page_common_1.execute.call(this, action); return page_common_1.execute.call(this, action, undefined, messageProps);
}; };
OakComponentBase.prototype.getFreshValue = function (path) { OakComponentBase.prototype.getFreshValue = function (path) {
var path2 = path var path2 = path
@ -353,10 +353,12 @@ function createComponent(option, features) {
_this.checkReachBottom(); _this.checkReachBottom();
}; };
var methodProps = { var methodProps = {
setDisablePulldownRefresh: function (able) { return _this.setDisablePulldownRefresh(able); }, setDisablePulldownRefresh: function (able) {
return _this.setDisablePulldownRefresh(able);
},
t: function (key, params) { return _this.t(key, params); }, t: function (key, params) { return _this.t(key, params); },
execute: function (action) { execute: function (action, messageProps) {
return _this.execute(action); return _this.execute(action, messageProps);
}, },
refresh: function () { refresh: function () {
return _this.refresh(); return _this.refresh();
@ -378,7 +380,7 @@ function createComponent(option, features) {
}, },
clean: function (path) { clean: function (path) {
return _this.clean(path); return _this.clean(path);
} },
}; };
if (option.isList) { if (option.isList) {
Object.assign(methodProps, { Object.assign(methodProps, {

2
lib/types/Page.d.ts vendored
View File

@ -145,7 +145,7 @@ export declare type OakCommonComponentMethods<ED extends EntityDict & BaseEntity
redirectTo: <T2 extends keyof ED>(options: Parameters<typeof wx.redirectTo>[0] & OakNavigateToParameters<ED, T2>, state?: Record<string, any>, disableNamespace?: boolean) => Promise<void>; redirectTo: <T2 extends keyof ED>(options: Parameters<typeof wx.redirectTo>[0] & OakNavigateToParameters<ED, T2>, state?: Record<string, any>, disableNamespace?: boolean) => Promise<void>;
clean: (path?: string) => void; clean: (path?: string) => void;
t(key: string, params?: object): string; t(key: string, params?: object): string;
execute: (action?: ED[T]['Action'], path?: string) => Promise<void>; execute: (action?: ED[T]['Action'], messageProps?: boolean | MessageProps) => Promise<void>;
checkOperation: (ntity: T, action: ED[T]['Action'], filter?: ED[T]['Update']['filter'], checkerTypes?: CheckerType[]) => boolean; checkOperation: (ntity: T, action: ED[T]['Action'], filter?: ED[T]['Update']['filter'], checkerTypes?: CheckerType[]) => boolean;
tryExecute: (path?: string) => boolean | Error; tryExecute: (path?: string) => boolean | Error;
getOperations: (path?: string) => { getOperations: (path?: string) => {

View File

@ -14,6 +14,7 @@ import {
import { unset } from 'oak-domain/lib/utils/lodash'; import { unset } from 'oak-domain/lib/utils/lodash';
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
import { MessageProps } from './types/Message';
export function onPathSet< export function onPathSet<
ED extends EntityDict & BaseEntityDict, ED extends EntityDict & BaseEntityDict,
@ -256,10 +257,13 @@ export async function execute<
ED extends EntityDict & BaseEntityDict, ED extends EntityDict & BaseEntityDict,
T extends keyof ED, T extends keyof ED,
Cxt extends AsyncContext<ED>, Cxt extends AsyncContext<ED>,
FrontCxt extends SyncContext<ED>>( FrontCxt extends SyncContext<ED>
>(
this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>, this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>,
action?: ED[T]['Action'], action?: ED[T]['Action'],
path?: string) { path?: string,
messageProps?: boolean | MessageProps, //默认true
) {
if (this.state.oakExecuting) { if (this.state.oakExecuting) {
throw new Error('请仔细设计按钮状态,不要允许重复点击!'); throw new Error('请仔细设计按钮状态,不要允许重复点击!');
} }
@ -267,12 +271,20 @@ export async function execute<
oakFocused: undefined, oakFocused: undefined,
}); */ }); */
const fullpath = path ? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; const fullpath = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
await this.features.runningTree.execute(fullpath, action); await this.features.runningTree.execute(fullpath, action);
this.setMessage({ if (messageProps !== false) {
const messageData: MessageProps = {
type: 'success', type: 'success',
content: '操作成功', content: '操作成功',
}); };
if (typeof messageProps === 'object') {
Object.assign(messageData, messageProps);
}
this.setMessage(messageData);
}
} }
export function destroyNode< export function destroyNode<

View File

@ -304,8 +304,8 @@ const oakBehavior = Behavior<
return this.features.runningTree.clean(path2); return this.features.runningTree.clean(path2);
}, },
execute(action, path) { execute(action, messageProps?: boolean | MessageProps) {
return execute.call(this as any, action, path); return execute.call(this as any, action, undefined, messageProps);
}, },
getFreshValue(path?: string) { getFreshValue(path?: string) {
@ -564,8 +564,7 @@ const oakBehavior = Behavior<
oakId(data) { oakId(data) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
this.features.runningTree.setId(this.state.oakFullpath, data); this.features.runningTree.setId(this.state.oakFullpath, data);
} } else {
else {
this.props.oakId = data; this.props.oakId = data;
} }
}, },

View File

@ -301,8 +301,8 @@ abstract class OakComponentBase<
return this.props.t(key, params); return this.props.t(key, params);
} }
execute(action?: ED[T]['Action']) { execute(action?: ED[T]['Action'], messageProps?: boolean | MessageProps) {
return execute.call(this as any, action); return execute.call(this as any, action, undefined, messageProps);
} }
getFreshValue(path?: string) { getFreshValue(path?: string) {
@ -603,11 +603,16 @@ export function createComponent<
constructor(props: ComponentProps<IsList, TProperty>) { constructor(props: ComponentProps<IsList, TProperty>) {
super(props); super(props);
const methodProps: Record<WebComponentCommonMethodNames, Function> = { const methodProps: Record<WebComponentCommonMethodNames, Function> =
setDisablePulldownRefresh: (able: boolean) => this.setDisablePulldownRefresh(able), {
setDisablePulldownRefresh: (able: boolean) =>
this.setDisablePulldownRefresh(able),
t: (key: string, params?: object) => this.t(key, params), t: (key: string, params?: object) => this.t(key, params),
execute: (action?: ED[T]['Action']) => { execute: (
return this.execute(action); action?: ED[T]['Action'],
messageProps?: boolean | MessageProps
) => {
return this.execute(action, messageProps);
}, },
refresh: () => { refresh: () => {
return this.refresh(); return this.refresh();
@ -619,11 +624,18 @@ export function createComponent<
return this.setMessage(data); return this.setMessage(data);
}, },
navigateTo: <T2 extends keyof ED>( navigateTo: <T2 extends keyof ED>(
options: { url: string } & OakNavigateToParameters<ED, T2>, options: { url: string } & OakNavigateToParameters<
ED,
T2
>,
state?: Record<string, any>, state?: Record<string, any>,
disableNamespace?: boolean disableNamespace?: boolean
) => { ) => {
return this.navigateTo(options, state, disableNamespace); return this.navigateTo(
options,
state,
disableNamespace
);
}, },
navigateBack: (delta?: number) => { navigateBack: (delta?: number) => {
return this.navigateBack(delta); return this.navigateBack(delta);
@ -634,11 +646,15 @@ export function createComponent<
state?: Record<string, any>, state?: Record<string, any>,
disableNamespace?: boolean disableNamespace?: boolean
) => { ) => {
return this.redirectTo(options, state, disableNamespace); return this.redirectTo(
options,
state,
disableNamespace
);
}, },
clean: (path?: string) => { clean: (path?: string) => {
return this.clean(path); return this.clean(path);
} },
}; };
if (option.isList) { if (option.isList) {
Object.assign(methodProps, { Object.assign(methodProps, {

View File

@ -250,7 +250,7 @@ export type OakCommonComponentMethods<
clean: (path?: string) => void; clean: (path?: string) => void;
t(key: string, params?: object): string; t(key: string, params?: object): string;
execute: (action?: ED[T]['Action'], path?: string) => Promise<void>; execute: (action?: ED[T]['Action'], messageProps?: boolean | MessageProps) => Promise<void>;
checkOperation: ( checkOperation: (
ntity: T, ntity: T,
action: ED[T]['Action'], action: ED[T]['Action'],