import { Util, LayoutTool, throttle } from '@ibizstudio/runtime'; import { SearchFormControlBase } from '../../../widgets'; import { IPSAppDEUIAction, IPSDEFormButton, IPSDEFormDetail, IPSDEFormDRUIPart, IPSDEFormFormPart, IPSDEFormGroupPanel, IPSDEFormIFrame, IPSDEFormPage, IPSDEFormRawItem, IPSDEFormTabPage, IPSDEFormTabPanel, IPSDESearchFormItem, IPSEditor, IPSFlexLayout, IPSFlexLayoutPos, IPSGridLayoutPos, IPSLayout, IPSLanguageRes, } from '@ibizstudio/runtime'; /** * 搜索表单部件基类 * * @export * @class AppSearchFormBase * @extends {SearchFormControlBase} */ export class AppSearchFormBase extends SearchFormControlBase { /** * 绘制子表单成员,布局控制 * * @param {*} modelJson * @returns * @memberof AppSearchFormBase */ renderDetails(modelJson: any) { let formDetails: IPSDEFormDetail[] = modelJson.getPSDEFormDetails(); let layout: IPSLayout = modelJson.getPSLayout(); // 没有子表单成员 if (!formDetails || formDetails.length == 0) { return null; } // 无布局 if (!layout) { return formDetails.map((item: any, index: number) => { return this.renderByDetailType(item, index); }); } // 栅格布局 if (layout.layout == 'TABLE_24COL' || layout.layout == 'TABLE_12COL') { return ( {formDetails.map((item: IPSDEFormDetail, index: number) => { if ((item as any).hidden) { return; } let attrs = LayoutTool.getGridOptions(item.getPSLayoutPos() as IPSGridLayoutPos); return ( {this.renderByDetailType(item, index)} ); })} ); } // FLEX布局 if (layout.layout == 'FLEX') { const flexStyle = LayoutTool.getFlexStyle(layout as IPSFlexLayout); return (
{formDetails.map((item: IPSDEFormDetail, index: number) => { if ((item as any).hidden) { return; } let detailStyle = LayoutTool.getFlexStyle2(item?.getPSLayoutPos() as IPSFlexLayoutPos); detailStyle += this.detailsModel[item.name].visible ? '' : 'display: none;'; return (
{this.renderByDetailType(item, index)}
); })}
); } } /** * 根据detailType绘制对应detail * * @param {*} modelJson * @param {number} index * @memberof AppSearchFormBase */ renderByDetailType(modelJson: IPSDEFormDetail, index: number) { if (modelJson.getPSSysPFPlugin()) { const pluginInstance: any = this.PluginFactory.getPluginInstance('CONTROLITEM', modelJson.getPSSysPFPlugin()?.pluginCode || ''); if (pluginInstance) { return pluginInstance.renderCtrlItem(this.$createElement, modelJson, this, null); } } else { switch (modelJson.detailType) { case 'FORMPAGE': return this.renderFormPage(modelJson as IPSDEFormPage, index); case 'GROUPPANEL': return this.renderGroupPanel(modelJson as IPSDEFormGroupPanel, index); case 'TABPAGE': return this.renderTabPage(modelJson as IPSDEFormTabPage, index); case 'TABPANEL': return this.renderTabPanel(modelJson as IPSDEFormTabPanel, index); case 'FORMITEM': return this.renderFormItem(modelJson as IPSDESearchFormItem, index); case 'BUTTON': return this.renderButton(modelJson as IPSDEFormButton, index); case 'DRUIPART': return this.renderDruipart(modelJson as IPSDEFormDRUIPart, index); case 'RAWITEM': return this.renderRawitem(modelJson as IPSDEFormRawItem, index); case 'IFRAME': return this.renderIframe(modelJson as IPSDEFormIFrame, index); case 'FORMPART': return this.renderFormPart(modelJson as IPSDEFormFormPart, index); } } } /** * 绘制表单部件 * * @returns * @memberof AppSearchFormBase */ renderFormPart(modelJson: IPSDEFormFormPart, index: number): any { let { formPartType, name, codeName } = modelJson; // 后续补 let systemCodeName = '', appCodeName = '', deCodeName = '', formCodeName = ''; if (formPartType && formPartType == 'DYNASYS') { return ( ); } } /** * 绘制iframe * * @returns * @memberof AppSearchFormBase */ renderIframe(modelJson: any, index: number): any { let { contentHeight, iFrameUrl } = modelJson; let iframeStyle = { height: contentHeight + 'px' }; return (
); } /** * 绘制直接内容 * * @returns * @memberof AppSearchFormBaseBase */ renderRawitem(modelJson: IPSDEFormRawItem, index: number): any { const data: any = this.data; let { rawItemHeight, rawItemWidth, contentType, htmlContent, rawContent } = modelJson; let sysCss = modelJson.getPSSysCss(); let sysImage = modelJson.getPSSysImage(); let sizeStyle = rawItemHeight > 0 && rawItemWidth > 0 ? { width: rawItemWidth + 'px', height: rawItemHeight + 'px' } : ''; if (rawContent) { const items = rawContent?.match(/\{{(.+?)\}}/g); if (items) { items.forEach((item: string) => { rawContent = rawContent?.replace(/\{{(.+?)\}}/, eval(item?.substring(2, item?.length - 2))); }); } } const tempNode = this.$createElement('div', { domProps: { innerHTML: rawContent, }, }); return ( {Object.is(contentType, 'RAW') ? tempNode : null} ); } /** * 关系界面保存事件 * * @param {*} e * @memberof AppSearchFormBase */ onDrDataSaved(e: any) { this.ctrlEvent({ controlname: this.controlInstance.name, action: 'drdatasaved', data: e, }); } /** * 绘制关系界面 * * @returns * @memberof AppSearchFormBase */ renderDruipart(modelJson: any, index: number): any { const { getPSSysCss, refreshItems, getLayoutPos, contentHeight, appView, parentdata, localContext, localParam, appDERSPaths } = modelJson; const { dynaModelFilePath } = appView; let tempContext: any = Object.assign(this.context, { viewpath: dynaModelFilePath }); // druipart样式 let druipartHeight: any; if (getLayoutPos?.layout == 'FlEX') { druipartHeight = '100%'; } else if (contentHeight === 0 && appView?.height > 0) { druipartHeight = appView.height; } else { druipartHeight = contentHeight; } let druipartStyle = { height: druipartHeight, overflow: 'auto' }; return ( this.drdatasaved($event)} style={druipartStyle} > ); } /** * 绘制按钮 * * @returns * @memberof AppSearchFormBase */ renderButton(modelJson: IPSDEFormButton, index: number): any { const { width, height, showCaption, caption } = modelJson; const uiAction = modelJson.getPSUIAction() as IPSAppDEUIAction; const sysImage = modelJson.getPSSysImage(); const sysCss = modelJson.getPSSysCss(); let btnClass = width > 0 && height > 0 ? { width: width + 'px', height: height + 'px' } : ''; let badge = null; // TODO计数器徽章 // if (uiAction) { // let { appCounter, counterId } = uiAction; // let { codeName } = appCounter; // let count = codeName + 'counterservice.counterData.' + counterId; // badge = ; // } // 自定义类名 const controlClassNames: any = { 'app-form-button': true }; if (sysCss?.cssName) { Object.assign(controlClassNames, { [sysCss.cssName]: true }); } let labelCaption: any = this.$tl((modelJson.getCapPSLanguageRes() as IPSLanguageRes)?.lanResTag, caption); return (
{badge} throttle(this.onFormItemActionClick, [{ formdetail: modelJson, event: $event }], this)} disabled={this.detailsModel[modelJson.name]?.disabled} > {sysImage ? : } {showCaption && {labelCaption}}
); } /** * 绘制表单项 * * @returns * @memberof AppSearchFormBase */ renderFormItem(modelJson: IPSDESearchFormItem, index: number): any { const editor = modelJson.getPSEditor() as IPSEditor; return ( { this.onFormItemValueChange(value); }} controlInstance={this.controlInstance} > {editor && ( { this.onFormItemValueChange(value); }} /> )} ); } /** * 绘制分页部件panel * * @returns * @memberof AppSearchFormBase */ renderTabPanel(modelJson: any, index: number): any { return ( {this.renderDetails(modelJson)} ); } /** * 绘制分页部件 * * @returns * @memberof AppSearchFormBase */ renderTabPage(modelJson: IPSDEFormTabPage, index: number): any { return ( {this.renderDetails(modelJson)} ); } /** * 绘制分组面板 * * @returns * @memberof AppSearchFormBase */ renderGroupPanel(modelJson: IPSDEFormGroupPanel, index: number): any { return ( throttle(this.handleActionClick, params, this)} data={this.data} > {this.renderDetails(modelJson)} ); } /** * 绘制表单分页 * * @returns * @memberof AppSearchFormBase */ renderFormPage(modelJson: IPSDEFormPage, index: number): any { const { noTabHeader } = this.controlInstance; if (noTabHeader) { return this.renderDetails(modelJson); } return ( {this.renderDetails(modelJson)} ); } /** * 绘制表单内容 * * @returns * @memberof AppSearchFormBase */ renderFormContent() { const { noTabHeader, codeName, name, controlType } = this.controlInstance; const formPages = this.controlInstance.getPSDEFormPages(); if (formPages && formPages.length > 0) { if (noTabHeader) { return formPages.map((item: any, index: number) => { return this.renderFormPage(item, index); }); } else { const tabsName = `${this.appDeCodeName.toLowerCase()}_${controlType?.toLowerCase()}_${codeName?.toLowerCase()}`; return ( { throttle(this.detailsModel[name]?.clickPage, [e], this); }} > {formPages.map((item: any, index: number) => { return this.renderFormPage(item, index); })} ); } } } /** * 绘制内容 * * @returns * @memberof AppSearchFormBase */ render(): any { const isShow = this.controlInstance.formStyle != 'SEARCHBAR' ? this.isExpandSearchForm : true; if (!(this.controlIsLoaded && isShow)) { return; } const { controlClassNames } = this.renderOptions; let formId = this.appDeCodeName.toLowerCase() + this.controlInstance.codeName?.toLowerCase(); if (!this.controlInstance.getPSDEFormItems() || this.controlInstance.getPSDEFormItems()?.length == 0) { return null; } return ( {this.renderFormContent()} {this.controlInstance.formStyle != 'SEARCHBAR' && ( {this.historyItems?.length > 0 ? ( {this.historyItems.map((item: any) => { return (
{ if (this.selectItem == item.value) { this.data = JSON.parse(JSON.stringify(item.data)); } }} > {item.name} throttle(this.removeHistoryItem, [e, item], this)} />
); })}
) : null} {Object.keys(this.data).length > 0 && ( throttle(this.onSearch, params, this)}> {this.$t('app.searchbutton.search')}
throttle(this.onReset, params, this)}>{this.$t('app.searchbutton.reset')}
{this.enableSaveFilter ? ( (this.saveItemName = '')}>
throttle(this.onCancel, params, this)}>{this.$t('app.commonwords.cancel')} throttle(this.onOk, params, this)}> {this.$t('app.commonwords.save')}
) : null}
)}
)}
); } }