import { throttle } from '@ibizstudio/runtime'; import { ListControlBase } from '../../../widgets'; import { IPSDEListItem, IPSDEUIAction, IPSDEUIActionGroup, IPSUIActionGroupDetail } from '@ibizstudio/runtime'; /** * 实体列表部件基类 * * @export * @class AppListBase * @extends {ListControlBase} */ export class AppListBase extends ListControlBase { /** * 绘制列表 * * @returns {*} * @memberof AppListBase */ render() { if (!this.controlIsLoaded) { return null; } let listClassName = { 'app-list': true, 'app-list-empty': this.items.length <= 0, ...this.renderOptions.controlClassNames, }; return this.batchToolbarInstance ? (
{this.items.length > 0 ?
{this.renderHaveItems()}
: this.isControlLoaded ? this.renderEmptyDataTip() : this.renderLoadDataTip()} {this.viewStyle == 'DEFAULT' ? : null}
{this.batchToolbarInstance && (this.selections.length > 0 ? {this.renderBatchToolbar()} : null)}
) : (
{this.items.length > 0 ?
{this.renderHaveItems()}
: this.isControlLoaded ? this.renderEmptyDataTip() : this.renderLoadDataTip()} {this.viewStyle == 'DEFAULT' ? : null}
); } /** * 绘制列表项内容 * * @returns {*} * @memberof AppListBase */ renderListItemContent(item: any, index: number) { const listItem = this.controlInstance.getPSDEListItems?.()?.[0] || null; return [
{item.srfmajortext} {item.content && {item.content}}
,
{listItem ? this.renderListItemAction(item, listItem) : ''}
, ]; } /** * 绘制有items的情况 * * @returns {*} * @memberof AppListBase */ renderHaveItems() { if (this.isEnableGroup) { return this.renderHaveGroup(); } else if (this.enableRowEditOrder) { return this.renderDraggableItems(); } else { return this.items.map((item: any, index: number) => { return this.renderDefaultItem(item, index); }); } } /** * 渲染可拖拽item项 * * @author zhanghengfeng * @date 2023-07-06 21:07:57 * @return {*} */ renderDraggableItems() { return ( {this.items.map((item, index) => (
throttle(this.handleClick, [item], this)} on-dblclick={() => throttle(this.handleDblClick, [item], this)} > {this.controlInstance.getItemPSLayoutPanel() ? this.renderItemPSLayoutPanel(item) : this.renderListItemContent(item, index)}
))}
); } /** * 绘制面板部件 * * @returns {*} * @memberof AppListBase */ renderItemPSLayoutPanel(item: any) { let { targetCtrlName, targetCtrlParam, targetCtrlEvent }: { targetCtrlName: string; targetCtrlParam: any; targetCtrlEvent: any } = this.computeTargetCtrlData( this.controlInstance.getItemPSLayoutPanel(), item, ); return this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: this.controlInstance.getItemPSLayoutPanel()?.name, on: targetCtrlEvent }); } /** * 绘制默认列表项 * * @returns {*} * @memberof AppListBase */ renderDefaultItem(item: any, index: number) { return (
throttle(this.handleClick, [item], this)} on-dblclick={() => throttle(this.handleDblClick, [item], this)} > {this.controlInstance.getItemPSLayoutPanel() ? this.renderItemPSLayoutPanel(item) : this.renderListItemContent(item, index)}
); } /** * 绘制有分组的情况 * * @returns {*} * @memberof AppListBase */ renderHaveGroup() { return ( {this.groupData.map((item: any) => { return (
{item.group}
{item.children.length > 0 ? (
{item.children.map((item: any, index: number) => { return this.renderDefaultItem(item, index); })}
) : (
{this.$t('${langbase}.nodata')}
)}
); })}
); } /** * 绘制列表项行为 * @param item 列数据 * @param listItem * @memberof AppListBase */ renderListItemAction(item: any, listItem: IPSDEListItem) { const UIActionGroupDetails: IPSUIActionGroupDetail[] = (listItem.getPSDEUIActionGroup() as IPSDEUIActionGroup)?.getPSUIActionGroupDetails() || []; return UIActionGroupDetails.map((uiactionDetail: IPSUIActionGroupDetail, index: number) => { const uiaction: IPSDEUIAction = uiactionDetail.getPSUIAction() as IPSDEUIAction; if (uiaction && item[uiaction.uIActionTag].visabled) { return ( { throttle(this.handleActionClick, [item, $event, listItem, uiactionDetail], this); }} > {uiactionDetail.showIcon ? : ''} {uiactionDetail.showCaption ? this.$tl(uiaction.getCapPSLanguageRes()?.lanResTag, uiaction.caption) : ''} ); } }); } }