From 7ad265079743f09264949ded133a117a50ef65d5 Mon Sep 17 00:00:00 2001 From: ShineKOT <1917095344@qq.com> Date: Tue, 4 Mar 2025 20:28:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=20=E6=9B=B4=E6=96=B0=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=A0=8F=EF=BC=8C=E8=A1=A8=E5=8D=95=E6=8C=89=E9=92=AE=EF=BC=8C?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E6=8C=89=E9=92=AE=EF=BC=8C=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E7=BB=84=E6=A0=B7=E5=BC=8F=E5=8F=8A=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/action-toolbar/action-toolbar.tsx | 4 +- src/common/button-list/button-list.scss | 10 +- src/common/button-list/button-list.tsx | 155 ++++++++---------- .../form-button-list/form-button-list.tsx | 7 +- .../form-detail/form-button/form-button.scss | 11 +- .../form-detail/form-button/form-button.tsx | 10 +- src/control/toolbar/toolbar.tsx | 8 +- .../panel-button-list.controller.ts | 42 ++++- .../panel-button-list/panel-button-list.tsx | 7 +- .../panel-button/panel-button.scss | 25 ++- .../panel-button/panel-button.tsx | 43 ++--- src/util/button-util/button-util.ts | 12 ++ src/util/index.ts | 1 + 13 files changed, 175 insertions(+), 160 deletions(-) create mode 100644 src/util/button-util/button-util.ts diff --git a/src/common/action-toolbar/action-toolbar.tsx b/src/common/action-toolbar/action-toolbar.tsx index ab330137..d6c16e63 100644 --- a/src/common/action-toolbar/action-toolbar.tsx +++ b/src/common/action-toolbar/action-toolbar.tsx @@ -2,6 +2,7 @@ import { defineComponent, PropType } from 'vue'; import { useNamespace } from '@ibiz-template/vue3-util'; import { IButtonContainerState } from '@ibiz-template/runtime'; import { IAppDEUIActionGroupDetail } from '@ibiz/model-core'; +import { convertBtnType } from '../../util'; import './action-toolbar.scss'; export const IBizActionToolbar = defineComponent({ @@ -49,8 +50,9 @@ export const IBizActionToolbar = defineComponent({
), this.handleClick(detail, e)} disabled={this.actionsState[detail.id!].disabled} class={[this.ns.e('item'), this.ns.is('disabled', false)]} diff --git a/src/common/button-list/button-list.scss b/src/common/button-list/button-list.scss index 454896a0..733ed796 100644 --- a/src/common/button-list/button-list.scss +++ b/src/common/button-list/button-list.scss @@ -13,10 +13,6 @@ height: 100%; .van-button { - border: none; - height: 100%; - background-color: transparent; - .van-button__text { display: flex; align-items: center; @@ -25,6 +21,12 @@ } } + @include e(content) { + display: flex; + flex-wrap: wrap; + gap: getCssVar(spacing, extra, tight); + } + @include e(popover) { --ibiz-color-bg-0: #{var(--van-popover-light-text-color)}; diff --git a/src/common/button-list/button-list.tsx b/src/common/button-list/button-list.tsx index a0cad8a6..c284a1b3 100644 --- a/src/common/button-list/button-list.tsx +++ b/src/common/button-list/button-list.tsx @@ -1,32 +1,14 @@ -import { computed, defineComponent, PropType, ref, Ref, VNode } from 'vue'; +import { computed, defineComponent, PropType, ref, Ref } from 'vue'; import { useNamespace } from '@ibiz-template/vue3-util'; import { - IAppDEUIActionGroupDetail, - IDEFormButtonList, IPanelButtonList, - IUIActionGroupDetail, + IDEFormButtonList, + IAppDEUIActionGroupDetail, } from '@ibiz/model-core'; import { IButtonContainerState } from '@ibiz-template/runtime'; +import { convertBtnType } from '../../util'; import './button-list.scss'; -/** - * Popover项配置 - */ -type PopoverAction = { - /** - * 是否禁用 - * - * @type {boolean} - */ - disabled: boolean; - /** - * 项类名 - * - * @type {(string | string[] | IData)} - */ - className?: string | string[] | IData; -}; - /** * 面板按钮组和表单按钮组的基础组件 */ @@ -47,7 +29,7 @@ export const IBizButtonList = defineComponent({ }, }, emits: { - click: (_actionId: string, _e?: MouseEvent) => true, + click: (_id: string, _e?: MouseEvent) => true, }, setup(props, { emit }) { const ns = useNamespace('button-list'); @@ -60,12 +42,8 @@ export const IBizButtonList = defineComponent({ * @param {MouseEvent} e * @param {IAppDEUIActionGroupDetail} item */ - const handleClick = ( - item: IAppDEUIActionGroupDetail, - e?: MouseEvent, - ): void => { - e?.stopPropagation(); - emit('click', item.uiactionId!, e); + const handleClick = (item: IData, e?: MouseEvent): void => { + emit('click', item.id, e); }; /** @@ -77,22 +55,38 @@ export const IBizButtonList = defineComponent({ showPopover.value = !showPopover.value; }; + /** + * 按钮组成员 + * + */ const details = computed(() => { - let result: (IAppDEUIActionGroupDetail & PopoverAction)[] = []; - const visibleItems = - props.model.uiactionGroup?.uiactionGroupDetails?.filter( - item => props.buttonsState[item.id!].visible, - ) as IAppDEUIActionGroupDetail[]; - if (visibleItems && visibleItems.length > 0) { - result = visibleItems.map(item => { + const { buttonListType, uiactionGroup } = props.model; + if (buttonListType === 'UIACTIONGROUP') + return ( + (uiactionGroup?.uiactionGroupDetails as IAppDEUIActionGroupDetail[]) || + [] + ); + return ( + (props.model as IPanelButtonList).panelButtons || + (props.model as IDEFormButtonList).deformButtons || + [] + ); + }); + + /** + * Popover中的行为项 + * + */ + const actions = computed(() => { + return details.value + .filter(detail => props.buttonsState[detail.id!]?.visible !== false) + .map(detail => { return { - ...item, - disabled: props.buttonsState[item.id!].disabled, - className: item.sysCss?.cssName, + ...detail, + disabled: props.buttonsState[detail.id!]?.disabled, + className: detail.sysCss?.cssName, }; }); - } - return result; }); /** @@ -103,32 +97,34 @@ export const IBizButtonList = defineComponent({ const renderActions = (): JSX.Element => { return (
- {details.value.map( - (item: IAppDEUIActionGroupDetail & PopoverAction) => { - return ( - handleClick(item, event)} - > - {item.showIcon && ( - - )} - {item.showCaption && ( - {item.caption} - )} - - ); - }, - )} + {details.value.map(item => { + if (props.buttonsState[item.id!]?.visible === false) return; + return ( + handleClick(item, event)} + > + {(item as IData).showIcon !== false && ( + + )} + {item.showCaption && ( + {item.caption} + )} + + ); + })}
); }; @@ -142,42 +138,33 @@ export const IBizButtonList = defineComponent({ return ( { - handleClick(data); - }} + onSelect={(data: IData) => handleClick(data)} > {{ - action: ({ - action, - }: { - action: IAppDEUIActionGroupDetail; - }): VNode | null => { - if (!props.buttonsState[action.id!].visible) { - return null; - } + action: ({ action }: { action: IData }) => { return ( - {action.showIcon && action.sysImage && ( + {action.showIcon !== false && action.sysImage && ( )} {action.showCaption && action.caption} ); }, - reference: (): VNode => { + reference: () => { const { caption, sysImage, showCaption } = props.model; return ( - + {sysImage && ( )} - {showCaption && ( + {showCaption !== false && ( {caption} => { + const handleClick = async (id: string, e?: MouseEvent): Promise => { e?.stopPropagation(); - c.doUIAction(actionId, e); + c.handleClick(id, e); }; return { ns, handleClick }; diff --git a/src/control/form/form-detail/form-button/form-button.scss b/src/control/form/form-detail/form-button/form-button.scss index 2cc7aaa1..a87b3aad 100644 --- a/src/control/form/form-detail/form-button/form-button.scss +++ b/src/control/form/form-detail/form-button/form-button.scss @@ -1,4 +1,4 @@ -$form-button: (icon-margin: getCssVar(spacing, extra-tight), +$form-button: ( icon-max-width: getCssVar(width-icon, medium), icon-max-height: getCssVar(width-icon, medium), ); @@ -14,20 +14,15 @@ $form-button: (icon-margin: getCssVar(spacing, extra-tight), .van-button { width: 100%; - @include b(form-button-content) { + @include e(content) { @include flex(row, flex-start, center); - + gap: getCssVar(spacing, extra, tight); img, i { display: inline-block; max-width: getCssVar(form-button, icon-max-width); max-height: getCssVar(form-button, icon-max-height); } - - // 同时存在图标和文本时,给文本加左margin - .#{bem(icon)}+.#{bem(form-button-content, '', caption)} { - margin-left: getCssVar(form-button, icon-margin); - } } } diff --git a/src/control/form/form-detail/form-button/form-button.tsx b/src/control/form/form-detail/form-button/form-button.tsx index 5ea119d2..ac624d0f 100644 --- a/src/control/form/form-detail/form-button/form-button.tsx +++ b/src/control/form/form-detail/form-button/form-button.tsx @@ -2,6 +2,7 @@ import { FormButtonController } from '@ibiz-template/runtime'; import { useNamespace } from '@ibiz-template/vue3-util'; import { IDEFormButton } from '@ibiz/model-core'; import { defineComponent, PropType, computed } from 'vue'; +import { convertBtnType } from '../../../../util'; import './form-button.scss'; export const FormButton = defineComponent({ @@ -47,17 +48,18 @@ export const FormButton = defineComponent({ ]} > -
+
- + {this.modelData.showCaption ? this.captionText : null}
diff --git a/src/control/toolbar/toolbar.tsx b/src/control/toolbar/toolbar.tsx index 9f4f8b5c..94292883 100644 --- a/src/control/toolbar/toolbar.tsx +++ b/src/control/toolbar/toolbar.tsx @@ -13,6 +13,7 @@ import { ToolbarController, } from '@ibiz-template/runtime'; import { IBizPopperToolbar } from './popper-toolbar/popper-toolbar'; +import { convertBtnType } from '../../util'; import './toolbar.scss'; const btnContent = ( @@ -96,10 +97,9 @@ export const ToolbarControl = defineComponent({ return position === 'bottom' ? 'normal' : 'small'; }); - const btnType = (item: IDEToolbarItem) => { - return (item as IDETBUIActionItem).actionLevel! > 100 - ? 'primary ' - : 'default'; + const btnType = (item: IDETBUIActionItem) => { + if (item.actionLevel && item.actionLevel > 100) return 'primary'; + return convertBtnType(item.buttonStyle); }; const getChildrenActions = (item: IDETBGroupItem) => { diff --git a/src/panel-component/panel-button-list/panel-button-list.controller.ts b/src/panel-component/panel-button-list/panel-button-list.controller.ts index aca2d10f..a4ff8bbb 100644 --- a/src/panel-component/panel-button-list/panel-button-list.controller.ts +++ b/src/panel-component/panel-button-list/panel-button-list.controller.ts @@ -7,7 +7,11 @@ import { UIActionButtonState, UIActionUtil, } from '@ibiz-template/runtime'; -import { IPanelButtonList } from '@ibiz/model-core'; +import { + IPanelButton, + IPanelButtonList, + IUIActionGroupDetail, +} from '@ibiz/model-core'; import { PanelButtonListState } from './panel-button-list.state'; /** @@ -129,28 +133,50 @@ export class PanelButtonListController extends PanelItemController detail.id === id, + ); + return panelButtons?.find(button => button.id === id); + } + + /** + * 处理按钮点击 * - * @param {string} actionId - * @param {MouseEvent} event + * @param {string} id + * @param {MouseEvent} [event] * @return {*} {Promise} * @memberof PanelButtonListController */ - async doUIAction(actionId: string, event?: MouseEvent): Promise { + async handleClick(id: string, event?: MouseEvent): Promise { + const action = this.getModelById(id); + if (!action?.uiactionId) return; await UIActionUtil.execAndResolved( - actionId, + action.uiactionId, { context: this.panel.context, params: { panelDataParent: this.dataParent.model.id!, ...this.panel.params, }, + event, data: [this.data], view: this.panel.view, - event, + ctrl: this.panel, noWaitRoute: true, }, - this.model.appId, + action.appId || this.model.appId, ); } diff --git a/src/panel-component/panel-button-list/panel-button-list.tsx b/src/panel-component/panel-button-list/panel-button-list.tsx index e6b54b1b..7e0b926c 100644 --- a/src/panel-component/panel-button-list/panel-button-list.tsx +++ b/src/panel-component/panel-button-list/panel-button-list.tsx @@ -22,12 +22,9 @@ export const PanelButtonList = defineComponent({ const c = props.controller; - const handleClick = async ( - actionId: string, - e?: MouseEvent, - ): Promise => { + const handleClick = async (id: string, e?: MouseEvent): Promise => { e?.stopPropagation(); - c.doUIAction(actionId, e); + c.handleClick(id, e); }; return { diff --git a/src/panel-component/panel-button/panel-button.scss b/src/panel-component/panel-button/panel-button.scss index 1ddfbd23..27482156 100644 --- a/src/panel-component/panel-button/panel-button.scss +++ b/src/panel-component/panel-button/panel-button.scss @@ -1,9 +1,20 @@ @include b(panel-button) { - width: 100%; - height: 100%; - @include when('login-btn'){ - background-color: getCssVar(color,primary); - color: getCssVar(color,fill,1); - font-size: getCssVar(font-size,header,4); + width: 100%; + height: 100%; + @include when('login-btn') { + background-color: getCssVar(color, primary); + color: getCssVar(color, fill, 1); + font-size: getCssVar(font-size, header, 4); + } + + @include e(content) { + @include flex(row, flex-start, center); + gap: getCssVar(spacing, extra, tight); + img, + i { + display: inline-block; + max-width: getCssVar(width-icon, medium); + max-height: getCssVar(width-icon, medium); } -} \ No newline at end of file + } +} diff --git a/src/panel-component/panel-button/panel-button.tsx b/src/panel-component/panel-button/panel-button.tsx index 15f4ec7a..94b39150 100644 --- a/src/panel-component/panel-button/panel-button.tsx +++ b/src/panel-component/panel-button/panel-button.tsx @@ -2,6 +2,7 @@ import { useNamespace } from '@ibiz-template/vue3-util'; import { IPanelButton } from '@ibiz/model-core'; import { defineComponent, PropType, computed } from 'vue'; import { PanelButtonController } from './panel-button.controller'; +import { convertBtnType } from '../../util'; import './panel-button.scss'; export const PanelButton = defineComponent({ @@ -23,7 +24,7 @@ export const PanelButton = defineComponent({ caption, captionItemName, renderMode, - itemStyle, + buttonStyle, showCaption, sysImage, codeName, @@ -39,33 +40,14 @@ export const PanelButton = defineComponent({ }); const buttonType = computed(() => { - if (Object.is(renderMode, 'LINK')) { - return 'text'; - } - if (itemStyle) { - switch (itemStyle) { - case 'PRIMARY': - return 'primary'; - case 'SUCCESS': - return 'success'; - case 'INFO': - return 'default'; - case 'WARNING': - return 'warning'; - case 'DANGER': - return 'danger'; - case 'INVERSE': - return 'default'; - default: - return 'default'; - } - } - return 'default'; + if (Object.is(renderMode, 'LINK')) return 'text'; + return convertBtnType(buttonStyle); }); const handleButtonClick = (event: MouseEvent) => { props.controller.onActionClick(event); }; + // 类名控制 const classArr = computed(() => { let result: Array = [ns.b(), ns.m(id)]; @@ -83,13 +65,13 @@ export const PanelButton = defineComponent({ return { ns, - captionText, - buttonType, - showCaption, + state, sysImage, codeName, classArr, - state, + buttonType, + captionText, + showCaption, handleButtonClick, }; }, @@ -97,17 +79,18 @@ export const PanelButton = defineComponent({ if (this.state.visible) { return ( -
+
- + {this.showCaption ? this.captionText : null}
diff --git a/src/util/button-util/button-util.ts b/src/util/button-util/button-util.ts new file mode 100644 index 00000000..9a015777 --- /dev/null +++ b/src/util/button-util/button-util.ts @@ -0,0 +1,12 @@ +/** + * 转换按钮类型 + * + * @export + * @param {string} [buttonStyle] + * @return {*} {string} + */ +export function convertBtnType(buttonStyle?: string): string { + return !buttonStyle || ['INVERSE', 'INFO'].includes(buttonStyle) + ? 'default' + : buttonStyle.toLowerCase(); +} diff --git a/src/util/index.ts b/src/util/index.ts index 02bc696e..4fc48e9b 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -12,3 +12,4 @@ export { FullscreenUtil } from './fullscreen/fullscreen-util'; export * from './store'; export { usePopstateListener } from './use-popstate-util/use-popstate-util'; export { QrcodeUtil } from './qrcode-util/qrcode-util'; +export { convertBtnType } from './button-util/button-util'; -- Gitee