diff --git a/typescript/component/basicbuttonwrapper/basic.button.wrapper.ts b/typescript/component/basicbuttonwrapper/basic.button.wrapper.ts new file mode 100644 index 000000000..4b5f70b57 --- /dev/null +++ b/typescript/component/basicbuttonwrapper/basic.button.wrapper.ts @@ -0,0 +1,19 @@ +import { shortcut } from "../../core/decorator/decorator"; + +@shortcut() +export class BasicButtonWrapper extends BI.BasicButton { + public static xtype = 'bi.component.basic_button_wrapper'; + + public props: { + render(): any; + doClick(): void; + } + + public render() { + return this.options.render(); + } + + public doClick() { + this.options.doClick(); + } +} diff --git a/typescript/core/decorator/decorator.ts b/typescript/core/decorator/decorator.ts index 29ca97c55..9b10d7a70 100644 --- a/typescript/core/decorator/decorator.ts +++ b/typescript/core/decorator/decorator.ts @@ -1,3 +1,5 @@ +import { BasicButtonWrapper } from "../../component/basicbuttonwrapper/basic.button.wrapper"; + export type Constructor = new(...args: any[]) => T; /** @@ -27,6 +29,28 @@ export function model() { }; } +/** + * 给控件render外包装basicButton + */ +export function click() { + return function (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) { + const render = descriptor.value; + + descriptor.value = function(this:any, ...args: any[]) { + return { + type: BasicButtonWrapper.xtype, + cls: 'cursor-default', + render: () => render.apply(this, args), + doClick: () => { + this.fireEvent('click'); + }, + }; + }; + + return descriptor; + }; +} + /** * 类注册_store属性 * @param Model model类 diff --git a/typescript/index.ts b/typescript/index.ts index b35966288..208880538 100644 --- a/typescript/index.ts +++ b/typescript/index.ts @@ -152,6 +152,7 @@ import { Tree, Node } from "./core/utils/tree"; import { TextNode } from "./base/single/button/node/textnode"; import { TextValueCheckComboPopup } from "./case/combo/textvaluecheckcombo/popup.textvaluecheck"; import { ImageButton } from './base/single/button/buttons/button.image'; +import { BasicButtonWrapper } from "./component/basicbuttonwrapper/basic.button.wrapper"; export interface BI extends _func, _i18n, _base, _inject, _var, _web, _utils { @@ -309,10 +310,12 @@ export interface BI extends _func, _i18n, _base, _inject, _var, _web, _utils { TextNode: typeof TextNode; TextValueCheckComboPopup: typeof TextValueCheckComboPopup; ImageButton: typeof ImageButton; + BasicButtonWrapper: typeof BasicButtonWrapper; } export default { Decorators: decorator, + BasicButtonWrapper, }; export { OB, @@ -468,4 +471,5 @@ export { TextNode, TextValueCheckComboPopup, ImageButton, + BasicButtonWrapper, };