import { $t, Tools, MarkupTableUtil } from 'platform-core'; import { Processor } from '../Processor'; import { PlaceHolder } from '@/utils/PlaceHolder'; class ConditionRange extends Processor { public getToolbarAction(target: any): any { return { extend: 'add', name: 'conditionRange', label: $t('io.sc.engine.rule.core.enums.ProcessorType.CONDITION_RANGE'), icon: 'bi-card-checklist', enableIf: (args: any) => { return target.type !== 'RULE_RESULT' && target.type !== 'SINGLE_RULE_RESULT'; }, afterClick: (args: any) => { args.grid.getEditorForm().setFieldValue('type', 'CONDITION_RANGE'); }, }; } public format(row: any): any { const objs: any[] = Tools.json2Object(row.conditionRange); if (objs && objs.length > 0) { let str = ''; objs.forEach((obj) => { str += ''; str += ' ' + PlaceHolder.replace(obj.condition) + ''; str += ' ' + ('' + PlaceHolder.replace(obj.value)) + ''; str += ''; }); return MarkupTableUtil.markupTable('', str, { dense: false }); } return ''; } public getEditorFields(context?: any): any { return [ { colSpan: 5, name: 'conditionRange', label: $t('re.resources.designer.processor.grid.entity.conditionRange'), showIf: (args: any) => { return 'CONDITION_RANGE' === args.form.getFieldValue('type'); }, type: 'w-grid', height: 300, dbClickOperation: 'edit', autoFetchData: false, denseBody: true, draggable: 'local', pageable: false, configButton: false, toolbarConfigure: { noIcon: false }, toolbarActions: [ 'add', 'clone', 'edit', { extend: 'remove', click: (args: any) => { const grid = args.grid.getEditorForm().getFieldComponent('conditionRange'); grid.removeLocalData(args.selecteds); }, }, 'separator', { name: 'example', label: $t('example'), icon: 'bi-balloon', click: (args: any) => { const sampleData = [ { uuid: Tools.uuid(), condition: '${变量名}<=0', value: '0' }, { uuid: Tools.uuid(), condition: '${变量名}>0 && ${变量名}<=50', value: '50' }, { uuid: Tools.uuid(), condition: '${变量名}>50 && ${变量名}<=80', value: '80' }, { uuid: Tools.uuid(), condition: '${变量名}>80 && ${变量名}<=100', value: '100' }, { uuid: Tools.uuid(), condition: '${变量名}>100', value: '60' }, ]; args.grid.setLocalData(sampleData); }, }, ], primaryKey: 'uuid', columns: [ { name: 'uuid', label: 'uuid', hidden: true }, { name: 'condition', label: $t('condition'), align: 'left', sortable: false, format: (value: any) => { return PlaceHolder.replace(value); }, }, { name: 'value', label: $t('value'), sortable: false, format: (value: any) => { return PlaceHolder.replace(value); }, }, ], editor: { dialog: { width: '600px', }, form: { colsNum: 1, fields: [ { name: 'uuid', label: 'uuid', showIf: false }, { name: 'condition', label: $t('condition'), type: 'w-code-mirror', lang: 'java', rows: 4, placeholder: true, lineWrap: true, lineBreak: false, autoCompletion: this.autoCompletionManager.autoCompletion(), userDefinedFunctions: this.userDefinedFunctionsManager.userDefinedFunctions(), }, { name: 'value', label: $t('value'), type: 'w-code-mirror', lang: 'java', rows: 4, lineWrap: true, lineBreak: false, placeholder: true, autoCompletion: this.autoCompletionManager.autoCompletion(), userDefinedFunctions: this.userDefinedFunctionsManager.userDefinedFunctions(), }, ], }, }, onBeforeEditorDataSubmit: (args: any) => { const grid = args.grid.getEditorForm().getFieldComponent('conditionRange'); const form = grid.getEditorForm(); if ('add' == form.getStatus() || 'clone' == form.getStatus()) { args.data.uuid = Tools.uuid(); grid.addLocalData(args.data); args.callback(false); } else if ('edit' == form.getStatus()) { grid.updateLocalData(args.data); args.callback(false); } }, }, ]; } public getViewerFields(context?: any): any { return [{ name: 'conditionRange', label: $t('re.resources.designer.processor.grid.entity.conditionRange') }]; } public beforeEditorDataSubmit(args: any): void { const grid = args.grid.getEditorForm().getFieldComponent('conditionRange'); const localData: any[] = grid.getRows(); const ranges: any[] = []; localData.forEach((item) => { ranges.push({ uuid: item.uuid, condition: item.condition, value: item.value, }); }); args.data.conditionRange = Tools.object2Json(ranges); } public afterEditorOpen(args: any): void { this.initAutoCompletionManager(args); this.initUserDefinedFunctionsManager(args); const grid = args.grid.getEditorForm().getFieldComponent('conditionRange'); const data = Tools.json2Object(args.data.conditionRange); grid.setLocalData(data); } } export { ConditionRange };