You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
198 lines
6.8 KiB
198 lines
6.8 KiB
7 months ago
|
import { $t, Environment, Tools } from 'platform-core';
|
||
|
import { PlaceHolder } from '@/utils/PlaceHolder';
|
||
|
import { AutoCompletionManager } from '@/views/shared/AutoCompletionManager';
|
||
|
import { UserDefinedFunctionsManager } from '@/views/shared/UserDefinedFunctionsManager';
|
||
|
|
||
|
const autoCompletionManager = new AutoCompletionManager();
|
||
|
const userDefinedFunctionsManager = new UserDefinedFunctionsManager();
|
||
|
|
||
|
class ConditionRange {
|
||
|
public static getToolbarAction(parameter: any) {
|
||
|
return {
|
||
|
extend: 'add',
|
||
|
name: 'conditionRange',
|
||
|
label: $t('io.sc.engine.rule.core.enums.ProcessorType.CONDITION_RANGE'),
|
||
|
icon: 'bi-rainbow',
|
||
|
enableIf: (args: any) => {
|
||
|
return parameter.type !== 'RULE_RESULT' && parameter.type !== 'SINGLE_RULE_RESULT';
|
||
|
},
|
||
|
afterClick: (args: any) => {
|
||
|
args.grid.getEditorForm().setFieldValue('type', 'CONDITION_RANGE');
|
||
|
},
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public static format(row: any) {
|
||
|
const objs = Tools.json2Object(row.conditionRange);
|
||
|
if (objs) {
|
||
|
let str = `<div class='border border-b-0 overflow-auto' style='max-height:100px'>`;
|
||
|
str += `<table width='100%' height='100%'>`;
|
||
|
objs.forEach((obj: any) => {
|
||
|
str += '<tr>';
|
||
|
str += ' <td>' + PlaceHolder.replace(obj.condition) + '</td>';
|
||
|
str += ' <td><span>' + ('' + PlaceHolder.replace(obj.value)) + '</span></td>';
|
||
|
str += '</tr>';
|
||
|
});
|
||
|
str += '</table>';
|
||
|
str += `</div>`;
|
||
|
return str;
|
||
|
}
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
public static getEditorFields(properties: 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 = properties.gridRef.getEditorForm().getFieldComponent('conditionRange');
|
||
|
grid.removeLocalData(args.selecteds);
|
||
|
},
|
||
|
},
|
||
|
'separator',
|
||
|
{
|
||
|
name: 'example',
|
||
|
label: $t('example'),
|
||
|
icon: 'bi-balloon',
|
||
|
click: (args) => {
|
||
|
const grid = properties.gridRef.getEditorForm().getFieldComponent('conditionRange');
|
||
|
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' },
|
||
|
];
|
||
|
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: autoCompletionManager.autoCompletion(),
|
||
|
userDefinedFunctions: userDefinedFunctionsManager.userDefinedFunctions(),
|
||
|
},
|
||
|
{
|
||
|
name: 'value',
|
||
|
label: $t('value'),
|
||
|
type: 'w-code-mirror',
|
||
|
lang: 'java',
|
||
|
rows: 4,
|
||
|
lineWrap: true,
|
||
|
lineBreak: false,
|
||
|
placeholder: true,
|
||
|
autoCompletion: autoCompletionManager.autoCompletion(),
|
||
|
userDefinedFunctions: userDefinedFunctionsManager.userDefinedFunctions(),
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
onBeforeEditorDataSubmit: (args: any) => {
|
||
|
const grid = properties.gridRef.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 static getViewerFields(properties: any) {
|
||
|
return [{ name: 'conditionRange', label: $t('re.resources.designer.processor.grid.entity.conditionRange') }];
|
||
|
}
|
||
|
|
||
|
public static beforeEditorDataSubmit(args) {
|
||
|
const form = args.grid.getEditorForm();
|
||
|
const grid = form.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 static afterEditorOpen(args: any) {
|
||
|
if (args.type === 'parameter') {
|
||
|
autoCompletionManager.load(Environment.apiContextPath('/api/re/common/listParameterAndValueTypeByParameterId/' + args.parameter.id));
|
||
|
} else if (args.type === 'indicator') {
|
||
|
autoCompletionManager.load(Environment.apiContextPath('/api/re/common/listParameterAndValueTypeByIndicatorId/' + args.indicator.id));
|
||
|
}
|
||
|
userDefinedFunctionsManager.load();
|
||
|
|
||
|
const form = args.grid.getEditorForm();
|
||
|
const row = args.data;
|
||
|
const grid = form.getFieldComponent('conditionRange');
|
||
|
const rows = Tools.json2Object(row.conditionRange);
|
||
|
grid.setLocalData(rows);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export { ConditionRange };
|