execute 增加参数messageProps 处理提交时 setMessage可禁用
This commit is contained in:
parent
9fc9f7e95c
commit
4bf8e981d2
|
|
@ -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<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 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 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;
|
||||
|
|
|
|||
|
|
@ -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*/];
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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, {
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
clean: (path?: string) => void;
|
||||
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;
|
||||
tryExecute: (path?: string) => boolean | Error;
|
||||
getOperations: (path?: string) => {
|
||||
|
|
|
|||
|
|
@ -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<ED>,
|
||||
FrontCxt extends SyncContext<ED>>(
|
||||
this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>,
|
||||
action?: ED[T]['Action'],
|
||||
path?: string) {
|
||||
FrontCxt extends SyncContext<ED>
|
||||
>(
|
||||
this: ComponentFullThisType<ED, T, any, Cxt, FrontCxt>,
|
||||
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<
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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<IsList, TProperty>) {
|
||||
super(props);
|
||||
const methodProps: Record<WebComponentCommonMethodNames, Function> = {
|
||||
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: <T2 extends keyof ED>(
|
||||
options: { url: string } & OakNavigateToParameters<ED, T2>,
|
||||
state?: Record<string, any>,
|
||||
disableNamespace?: boolean
|
||||
) => {
|
||||
return this.navigateTo(options, state, disableNamespace);
|
||||
},
|
||||
navigateBack: (delta?: number) => {
|
||||
return this.navigateBack(delta);
|
||||
},
|
||||
redirectTo: <T2 extends keyof ED>(
|
||||
options: Parameters<typeof wx.redirectTo>[0] &
|
||||
OakNavigateToParameters<ED, T2>,
|
||||
state?: Record<string, any>,
|
||||
disableNamespace?: boolean
|
||||
) => {
|
||||
return this.redirectTo(options, state, disableNamespace);
|
||||
},
|
||||
clean: (path?: string) => {
|
||||
return this.clean(path);
|
||||
}
|
||||
};
|
||||
const methodProps: Record<WebComponentCommonMethodNames, Function> =
|
||||
{
|
||||
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: <T2 extends keyof ED>(
|
||||
options: { url: string } & OakNavigateToParameters<
|
||||
ED,
|
||||
T2
|
||||
>,
|
||||
state?: Record<string, any>,
|
||||
disableNamespace?: boolean
|
||||
) => {
|
||||
return this.navigateTo(
|
||||
options,
|
||||
state,
|
||||
disableNamespace
|
||||
);
|
||||
},
|
||||
navigateBack: (delta?: number) => {
|
||||
return this.navigateBack(delta);
|
||||
},
|
||||
redirectTo: <T2 extends keyof ED>(
|
||||
options: Parameters<typeof wx.redirectTo>[0] &
|
||||
OakNavigateToParameters<ED, T2>,
|
||||
state?: Record<string, any>,
|
||||
disableNamespace?: boolean
|
||||
) => {
|
||||
return this.redirectTo(
|
||||
options,
|
||||
state,
|
||||
disableNamespace
|
||||
);
|
||||
},
|
||||
clean: (path?: string) => {
|
||||
return this.clean(path);
|
||||
},
|
||||
};
|
||||
if (option.isList) {
|
||||
Object.assign(methodProps, {
|
||||
addItem: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => {
|
||||
|
|
|
|||
|
|
@ -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<void>;
|
||||
execute: (action?: ED[T]['Action'], messageProps?: boolean | MessageProps) => Promise<void>;
|
||||
checkOperation: (
|
||||
ntity: T,
|
||||
action: ED[T]['Action'],
|
||||
|
|
|
|||
Loading…
Reference in New Issue