diff --git a/lib/page.common.d.ts b/lib/page.common.d.ts index bd552250..7880df2d 100644 --- a/lib/page.common.d.ts +++ b/lib/page.common.d.ts @@ -3,9 +3,10 @@ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { OakComponentOption, ComponentFullThisType } from './types/Page'; import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; +import { MessageProps } from './types/Message'; export declare function onPathSet, FrontCxt extends SyncContext>(this: ComponentFullThisType, option: OakComponentOption): void; export declare function reRender, FrontCxt extends SyncContext>(this: ComponentFullThisType, option: OakComponentOption, extra?: Record): void; export declare function refresh, FrontCxt extends SyncContext>(this: ComponentFullThisType): Promise; export declare function loadMore, FrontCxt extends SyncContext>(this: ComponentFullThisType): Promise; -export declare function execute, FrontCxt extends SyncContext>(this: ComponentFullThisType, action?: ED[T]['Action'], path?: string): Promise; +export declare function execute, FrontCxt extends SyncContext>(this: ComponentFullThisType, action?: ED[T]['Action'], path?: string, messageProps?: boolean | MessageProps): Promise; export declare function destroyNode, FrontCxt extends SyncContext>(this: ComponentFullThisType): void; diff --git a/lib/page.common.js b/lib/page.common.js index 5b6bb048..ac7dc431 100644 --- a/lib/page.common.js +++ b/lib/page.common.js @@ -259,23 +259,31 @@ function loadMore() { }); } exports.loadMore = loadMore; -function execute(action, path) { +function execute(action, path, messageProps) { return tslib_1.__awaiter(this, void 0, void 0, function () { - var fullpath; + var fullpath, messageData; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: if (this.state.oakExecuting) { 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)]; case 1: _a.sent(); - this.setMessage({ - type: 'success', - content: '操作成功', - }); + if (messageProps !== false) { + messageData = { + type: 'success', + content: '操作成功', + }; + if (typeof messageProps === 'object') { + Object.assign(messageData, messageProps); + } + this.setMessage(messageData); + } return [2 /*return*/]; } }); diff --git a/lib/page.mp.js b/lib/page.mp.js index e609c898..8a966686 100644 --- a/lib/page.mp.js +++ b/lib/page.mp.js @@ -224,8 +224,8 @@ var oakBehavior = Behavior({ : this.state.oakFullpath; return this.features.runningTree.clean(path2); }, - execute: function (action, path) { - return page_common_1.execute.call(this, action, path); + execute: function (action, messageProps) { + return page_common_1.execute.call(this, action, undefined, messageProps); }, getFreshValue: function (path) { var path2 = path diff --git a/lib/page.web.js b/lib/page.web.js index 2c96ab5c..a6ec24b4 100644 --- a/lib/page.web.js +++ b/lib/page.web.js @@ -157,8 +157,8 @@ var OakComponentBase = /** @class */ (function (_super) { OakComponentBase.prototype.t = function (key, params) { return this.props.t(key, params); }; - OakComponentBase.prototype.execute = function (action) { - return page_common_1.execute.call(this, action); + OakComponentBase.prototype.execute = function (action, messageProps) { + return page_common_1.execute.call(this, action, undefined, messageProps); }; OakComponentBase.prototype.getFreshValue = function (path) { var path2 = path @@ -353,10 +353,12 @@ function createComponent(option, features) { _this.checkReachBottom(); }; 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); }, - execute: function (action) { - return _this.execute(action); + execute: function (action, messageProps) { + return _this.execute(action, messageProps); }, refresh: function () { return _this.refresh(); @@ -378,7 +380,7 @@ function createComponent(option, features) { }, clean: function (path) { return _this.clean(path); - } + }, }; if (option.isList) { Object.assign(methodProps, { diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index e8e1dd0d..aebf7a59 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -145,7 +145,7 @@ export declare type OakCommonComponentMethods(options: Parameters[0] & OakNavigateToParameters, state?: Record, disableNamespace?: boolean) => Promise; clean: (path?: string) => void; t(key: string, params?: object): string; - execute: (action?: ED[T]['Action'], path?: string) => Promise; + execute: (action?: ED[T]['Action'], messageProps?: boolean | MessageProps) => Promise; checkOperation: (ntity: T, action: ED[T]['Action'], filter?: ED[T]['Update']['filter'], checkerTypes?: CheckerType[]) => boolean; tryExecute: (path?: string) => boolean | Error; getOperations: (path?: string) => { diff --git a/src/page.common.ts b/src/page.common.ts index ca7984f9..2e7b0d0f 100644 --- a/src/page.common.ts +++ b/src/page.common.ts @@ -14,6 +14,7 @@ import { import { unset } from 'oak-domain/lib/utils/lodash'; import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; +import { MessageProps } from './types/Message'; export function onPathSet< ED extends EntityDict & BaseEntityDict, @@ -256,10 +257,13 @@ export async function execute< ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext, - FrontCxt extends SyncContext>( - this: ComponentFullThisType, - action?: ED[T]['Action'], - path?: string) { + FrontCxt extends SyncContext +>( + this: ComponentFullThisType, + action?: ED[T]['Action'], + path?: string, + messageProps?: boolean | MessageProps, //默认true +) { if (this.state.oakExecuting) { throw new Error('请仔细设计按钮状态,不要允许重复点击!'); } @@ -267,12 +271,20 @@ export async function execute< 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); - this.setMessage({ - type: 'success', - content: '操作成功', - }); + if (messageProps !== false) { + const messageData: MessageProps = { + type: 'success', + content: '操作成功', + }; + if (typeof messageProps === 'object') { + Object.assign(messageData, messageProps); + } + this.setMessage(messageData); + } } export function destroyNode< diff --git a/src/page.mp.ts b/src/page.mp.ts index ad1e3fb0..1b874e5d 100644 --- a/src/page.mp.ts +++ b/src/page.mp.ts @@ -304,8 +304,8 @@ const oakBehavior = Behavior< return this.features.runningTree.clean(path2); }, - execute(action, path) { - return execute.call(this as any, action, path); + execute(action, messageProps?: boolean | MessageProps) { + return execute.call(this as any, action, undefined, messageProps); }, getFreshValue(path?: string) { @@ -564,8 +564,7 @@ const oakBehavior = Behavior< oakId(data) { if (this.state.oakFullpath) { this.features.runningTree.setId(this.state.oakFullpath, data); - } - else { + } else { this.props.oakId = data; } }, diff --git a/src/page.web.tsx b/src/page.web.tsx index 1d7f282d..93305cbc 100644 --- a/src/page.web.tsx +++ b/src/page.web.tsx @@ -301,8 +301,8 @@ abstract class OakComponentBase< return this.props.t(key, params); } - execute(action?: ED[T]['Action']) { - return execute.call(this as any, action); + execute(action?: ED[T]['Action'], messageProps?: boolean | MessageProps) { + return execute.call(this as any, action, undefined, messageProps); } getFreshValue(path?: string) { @@ -603,43 +603,59 @@ export function createComponent< constructor(props: ComponentProps) { super(props); - const methodProps: Record = { - setDisablePulldownRefresh: (able: boolean) => this.setDisablePulldownRefresh(able), - t: (key: string, params?: object) => this.t(key, params), - execute: (action?: ED[T]['Action']) => { - return this.execute(action); - }, - refresh: () => { - return this.refresh(); - }, - setNotification: (data: NotificationProps) => { - return this.setNotification(data); - }, - setMessage: (data: MessageProps) => { - return this.setMessage(data); - }, - navigateTo: ( - options: { url: string } & OakNavigateToParameters, - state?: Record, - disableNamespace?: boolean - ) => { - return this.navigateTo(options, state, disableNamespace); - }, - navigateBack: (delta?: number) => { - return this.navigateBack(delta); - }, - redirectTo: ( - options: Parameters[0] & - OakNavigateToParameters, - state?: Record, - disableNamespace?: boolean - ) => { - return this.redirectTo(options, state, disableNamespace); - }, - clean: (path?: string) => { - return this.clean(path); - } - }; + const methodProps: Record = + { + setDisablePulldownRefresh: (able: boolean) => + this.setDisablePulldownRefresh(able), + t: (key: string, params?: object) => this.t(key, params), + execute: ( + action?: ED[T]['Action'], + messageProps?: boolean | MessageProps + ) => { + return this.execute(action, messageProps); + }, + refresh: () => { + return this.refresh(); + }, + setNotification: (data: NotificationProps) => { + return this.setNotification(data); + }, + setMessage: (data: MessageProps) => { + return this.setMessage(data); + }, + navigateTo: ( + options: { url: string } & OakNavigateToParameters< + ED, + T2 + >, + state?: Record, + disableNamespace?: boolean + ) => { + return this.navigateTo( + options, + state, + disableNamespace + ); + }, + navigateBack: (delta?: number) => { + return this.navigateBack(delta); + }, + redirectTo: ( + options: Parameters[0] & + OakNavigateToParameters, + state?: Record, + disableNamespace?: boolean + ) => { + return this.redirectTo( + options, + state, + disableNamespace + ); + }, + clean: (path?: string) => { + return this.clean(path); + }, + }; if (option.isList) { Object.assign(methodProps, { addItem: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) => { diff --git a/src/types/Page.ts b/src/types/Page.ts index e65e1ceb..22749cba 100644 --- a/src/types/Page.ts +++ b/src/types/Page.ts @@ -250,7 +250,7 @@ export type OakCommonComponentMethods< clean: (path?: string) => void; t(key: string, params?: object): string; - execute: (action?: ED[T]['Action'], path?: string) => Promise; + execute: (action?: ED[T]['Action'], messageProps?: boolean | MessageProps) => Promise; checkOperation: ( ntity: T, action: ED[T]['Action'],