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.

1341 lines
52 KiB

1 year ago
<template>
10 months ago
<div style="height: 100%">
<w-grid
ref="gridRef"
:title="$t('re.resources.designer.processor.grid.title')"
8 months ago
:draggable="true"
10 months ago
dense
hide-bottom
db-click-operation="edit"
:config-button="true"
selection="multiple"
:checkbox-selection="false"
:tree="false"
:fetch-data-url="Environment.apiContextPath('/api/re/indicator/processor?indicator=' + indicator.id)"
:data-url="Environment.apiContextPath('/api/re/indicator/processor')"
:pageable="false"
:toolbar-configure="{ noIcon: false }"
:toolbar-actions="[
'refresh',
'separator',
[
{
extend: 'add',
click: undefined,
enableIf: (arg) => {
return !readOnly;
},
10 months ago
},
10 months ago
{
extend: 'add',
name: 'objectProperties',
label: Formater.enum(Enums.ProcessorType)('OBJECT_PROPERTIES'),
icon: 'bi-card-list',
enableIf: (arg) => {
const valueType = indicator.valueType;
return (
valueType !== 'java.lang.Boolean' &&
valueType !== 'java.lang.Long' &&
valueType !== 'java.lang.Float' &&
valueType !== 'Float' &&
valueType !== 'java.math.BigDecimal' &&
valueType !== 'java.lang.String' &&
valueType !== 'java.util.Date' &&
valueType !== 'io.sc.engine.rule.core.classes.ResourceAbstract' &&
valueType !== 'io.sc.engine.rule.core.classes.RuleResult' &&
valueType !== 'io.sc.engine.rule.core.classes.SingleRuleResult' &&
!valueType.startsWith('List') &&
!valueType.startsWith('Map')
);
},
afterClick: (arg) => {
arg.grid.getEditorForm().setFieldValue('type', 'OBJECT_PROPERTIES');
},
1 year ago
},
10 months ago
{
extend: 'add',
name: 'mathFormula',
label: Formater.enum(Enums.ProcessorType)('MATH_FORMULA'),
icon: 'bi-calculator',
enableIf: (arg) => {
return indicator.type !== 'RULE_RESULT' && indicator.type !== 'SINGLE_RULE_RESULT';
},
afterClick: (arg) => {
arg.grid.getEditorForm().setFieldValue('type', 'MATH_FORMULA');
},
1 year ago
},
10 months ago
{
extend: 'add',
name: 'arithmetic',
label: Formater.enum(Enums.ProcessorType)('ARITHMETIC'),
icon: 'bi-calculator',
enableIf: (arg) => {
return indicator.type !== 'RULE_RESULT' && indicator.type !== 'SINGLE_RULE_RESULT';
},
afterClick: (arg) => {
arg.grid.getEditorForm().setFieldValue('type', 'ARITHMETIC');
},
1 year ago
},
10 months ago
{
extend: 'add',
name: 'ternary',
label: Formater.enum(Enums.ProcessorType)('TERNARY'),
icon: 'bi-question',
enableIf: (arg) => {
return indicator.type !== 'RULE_RESULT' && indicator.type !== 'SINGLE_RULE_RESULT';
},
afterClick: (arg) => {
arg.grid.getEditorForm().setFieldValue('type', 'TERNARY');
},
1 year ago
},
10 months ago
{
extend: 'add',
name: 'whenThen',
label: Formater.enum(Enums.ProcessorType)('WHEN_THEN'),
icon: 'bi-sliders',
enableIf: (arg) => {
return indicator.type !== 'RULE_RESULT' && indicator.type !== 'SINGLE_RULE_RESULT';
},
afterClick: (arg) => {
arg.grid.getEditorForm().setFieldValue('type', 'WHEN_THEN');
},
1 year ago
},
10 months ago
{
extend: 'add',
name: 'numberRange',
label: Formater.enum(Enums.ProcessorType)('NUMBER_RANGE'),
icon: 'bi-justify',
enableIf: (arg) => {
return indicator.type !== 'RULE_RESULT' && indicator.type !== 'SINGLE_RULE_RESULT';
},
afterClick: (arg) => {
arg.grid.getEditorForm().setFieldValue('type', 'NUMBER_RANGE');
},
1 year ago
},
10 months ago
{
extend: 'add',
name: 'conditionRange',
label: Formater.enum(Enums.ProcessorType)('CONDITION_RANGE'),
icon: 'bi-rainbow',
enableIf: (arg) => {
return indicator.type !== 'RULE_RESULT' && indicator.type !== 'SINGLE_RULE_RESULT';
},
afterClick: (arg) => {
arg.grid.getEditorForm().setFieldValue('type', 'CONDITION_RANGE');
},
},
{
extend: 'add',
name: 'groovyScript',
label: Formater.enum(Enums.ProcessorType)('GROOVY_SCRIPT'),
icon: 'bi-code',
enableIf: (arg) => {
return indicator.type !== 'RULE_RESULT' && indicator.type !== 'SINGLE_RULE_RESULT';
},
afterClick: (arg) => {
arg.grid.getEditorForm().setFieldValue('type', 'GROOVY_SCRIPT');
},
1 year ago
},
10 months ago
{
extend: 'add',
name: 'sql',
label: Formater.enum(Enums.ProcessorType)('SQL'),
icon: 'bi-filetype-sql',
enableIf: (arg) => {
return indicator.type !== 'RULE_RESULT' && indicator.type !== 'SINGLE_RULE_RESULT';
},
afterClick: (arg) => {
arg.grid.getEditorForm().setFieldValue('type', 'SQL');
},
1 year ago
},
10 months ago
],
1 year ago
{
10 months ago
extend: 'clone',
1 year ago
enableIf: (arg) => {
10 months ago
return !readOnly && arg.selected;
1 year ago
},
},
{
10 months ago
extend: 'edit',
1 year ago
enableIf: (arg) => {
10 months ago
return !readOnly && arg.selected;
1 year ago
},
},
{
10 months ago
extend: 'remove',
1 year ago
enableIf: (arg) => {
10 months ago
return !readOnly && arg.selected;
1 year ago
},
},
10 months ago
'separator',
'view',
'separator',
'export',
]"
:columns="[
{ width: 60, name: 'order', label: $t('order'), sortable: false, align: 'right' },
{ width: 120, name: 'type', label: $t('type'), sortable: false, format: Formater.enum(Enums.ProcessorType) },
{
width: '100%',
name: 'content',
label: $t('re.resources.designer.processor.grid.entity.content'),
sortable: false,
format: (value, row) => {
const type = row.type;
if ('OBJECT_PROPERTIES' === type) {
let str = '';
if (row.objectCondition) {
str += `<div class='py-2'>When ` + PlaceHolder.replace(row.objectCondition) + ' Then</div>';
}
const objs = Tools.json2Object(row.objectProperties);
if (objs) {
str += `<div class='border border-b-0 overflow-auto' style='max-height:100px'>`;
str += `<table width='100%' height='100%'>`;
8 months ago
objs.forEach((obj) => {
10 months ago
str += '<tr>';
str += ` <td width='30%'>` + obj.name + `</td>`;
str += ` <td width='70%'><span>` + ('' + PlaceHolder.replace(obj.expression)) + '</span></td>';
str += '</tr>';
8 months ago
});
10 months ago
str += '</table>';
str += `</div>`;
10 months ago
}
return str;
10 months ago
} else if ('ARITHMETIC' === type) {
return {
componentType: 'w-code-mirror',
attrs: {
lang: 'java',
rows: 2,
modelValue: row.arithmetic,
editable: false,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
},
};
//return PlaceHolder.replace(row.arithmetic);
} else if ('MATH_FORMULA' === type) {
return {
componentType: 'w-expression',
attrs: {
modelValue: row.mathFormula,
readOnly: true,
zoom: 2,
},
};
} else if ('TERNARY' === type) {
return row.ternaryCondition + ' <b><span>?</span></b> ' + row.ternaryTrue + ' <b><span>:</span></b> ' + row.ternaryFalse;
} else if ('WHEN_THEN' === type) {
let str = '';
if (row.isWhenThenShorted) {
str += '<span>' + $t('re.resources.designer.processor.grid.entity.isWhenThenShorted') + ', </span>';
}
if (row.when) {
str += '<span>When</span> ' + PlaceHolder.replace(row.when) + ' ';
}
if (row.then) {
str += '<span>Then</span> ' + PlaceHolder.replace(row.then);
10 months ago
}
return str;
10 months ago
} else if ('NUMBER_RANGE' === type) {
const objs = Tools.json2Object(row.numberRange);
if (objs) {
let str = `<div class='border border-b-0'>`;
str += `<table width='100%'>`;
8 months ago
objs.forEach((obj) => {
10 months ago
str += '<tr>';
if (i == 0) {
str += ' <td rowspan=' + objs.length + '>' + PlaceHolder.replace(row.numberRangeVar) + '</td>';
}
str += ' <td>' + Tools.generateIntervalRange(obj.minIncluded, obj.min, obj.max, obj.maxIncluded) + '</td>';
str += ' <td>' + ('' + PlaceHolder.replace('' + obj.value)) + '</td>';
str += '</tr>';
8 months ago
});
10 months ago
str += '</table>';
str += '</div>';
return str;
}
return '';
} else if ('CONDITION_RANGE' === type) {
const objs = Tools.json2Object(row.conditionRange);
if (objs) {
let str = `<div class='border border-b-0'>`;
str += `<table width='100%'>`;
8 months ago
objs.forEach((obj) => {
10 months ago
str += '<tr>';
str += ' <td>' + PlaceHolder.replace(obj.condition) + '</td>';
str += ' <td><span>' + ('' + PlaceHolder.replace(obj.value)) + '</span></td>';
str += '</tr>';
8 months ago
});
10 months ago
str += '</table>';
str += `</div>`;
return str;
}
return '';
} else if ('GROOVY_SCRIPT' === type) {
return transfromContent(row.groovyScript);
10 months ago
} else if ('SQL' === type) {
return {
componentType: 'w-code-mirror',
attrs: {
lang: 'sql',
rows: 4,
editable: false,
modelValue: row.sql,
placeholder: true,
},
};
10 months ago
}
10 months ago
},
1 year ago
},
10 months ago
]"
:editor="{
dialog: {
width: '80%',
},
form: {
colsNum: 5,
fields: [
8 months ago
{ colSpan: 5, name: 'indicator', label: 'indicator', type: 'w-text', defaultValue: indicator.id, showIf: false },
{ colSpan: 5, name: 'id', label: $t('id'), type: 'w-text', showIf: false },
{ colSpan: 5, name: 'order', label: $t('order'), type: 'w-number', showIf: false },
{ colSpan: 5, name: 'type', label: $t('type'), type: 'w-text', showIf: false },
10 months ago
{
colSpan: 5,
name: 'objectCondition',
label: $t('re.resources.designer.processor.grid.entity.objectCondition'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 3,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
showIf: (arg) => {
return 'OBJECT_PROPERTIES' === arg.form.getFieldValue('type');
},
1 year ago
},
10 months ago
{
colSpan: 5,
name: 'objectProperties',
label: $t('re.resources.designer.processor.grid.entity.objectProperties'),
showIf: (arg) => {
return 'OBJECT_PROPERTIES' === arg.form.getFieldValue('type');
},
type: 'w-grid',
title: $t('re.resources.designer.processor.grid.entity.objectProperties'),
height: 400,
autoFetchData: false,
dbClickOperation: 'edit',
dense: true,
draggable: true,
pageable: false,
configButton: false,
toolbarConfigure: { noIcon: false },
toolbarActions: [
'separator',
{
name: 'autoMatch',
label: $t('autoMatch'),
icon: 'bi-link-45deg',
click: () => {
const grid = gridRef.getEditorForm().getFieldComponent('objectProperties');
const localData = grid.getLocalData();
const objectProperties = [];
8 months ago
localData.forEach((item) => {
10 months ago
objectProperties.push({
code: item.code,
name: item.name,
expression: item.expression,
});
8 months ago
});
10 months ago
objectPropertiesMatcherDialogRef.open(objectProperties);
},
},
10 months ago
'separator',
10 months ago
'edit',
10 months ago
{
extend: 'remove',
click: (arg) => {
const grid = gridRef.getEditorForm().getFieldComponent('objectProperties');
const selecteds = arg.selecteds;
8 months ago
selecteds.forEach((selected) => {
10 months ago
selected.expression = '';
grid.replaceRow(selected);
8 months ago
});
10 months ago
},
},
'separator',
{
extend: 'remove',
name: 'removeAll',
label: $t('removeAll'),
icon: 'bi-trash3',
enableIf: () => {
return true;
},
click: (arg) => {
const grid = gridRef.getEditorForm().getFieldComponent('objectProperties');
const rows = grid.getLocalData();
8 months ago
rows.forEach((row) => {
10 months ago
row.expression = '';
8 months ago
});
10 months ago
grid.setLocalData(rows);
},
},
10 months ago
],
primaryKey: 'code',
columns: [
8 months ago
{ name: 'code', label: 'code', showIf: false },
10 months ago
{
width: 300,
name: 'name',
label: $t('propertyName'),
align: 'left',
sortable: false,
format: (value, row) => {
if (row.expression) {
const expression = row.expression.replace(/\$\{(.+?)\.(.+?)\}/g, '$2');
if (expression.trim() !== value.trim()) {
return `<span class='text-red-500'>` + value + '</span>';
}
}
return value;
},
},
{
width: '100%',
name: 'expression',
label: $t('expression'),
sortable: false,
format: (value) => {
return PlaceHolder.replace(value);
},
},
],
editor: {
dialog: {
width: '800px',
},
form: {
colsNum: 1,
fields: [
8 months ago
{ name: 'code', label: 'code', showIf: false },
10 months ago
{
name: 'expression',
label: $t('expression'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 3,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
},
],
},
},
onBeforeEditorDataSubmit: (data, callback) => {
const grid = gridRef.getEditorForm().getFieldComponent('objectProperties');
const form = grid.getEditorForm();
if ('edit' == form.getStatus()) {
grid.replaceRow(data);
callback(false);
}
},
1 year ago
},
10 months ago
{
colSpan: 5,
name: 'mathFormula',
label: $t('re.resources.designer.processor.grid.entity.mathFormula'),
8 months ago
type: 'w-math',
10 months ago
autoCompletion: autoCompletion,
10 months ago
showIf: (arg) => {
return 'MATH_FORMULA' === arg.form.getFieldValue('type');
},
1 year ago
},
10 months ago
{
colSpan: 5,
name: 'arithmetic',
label: $t('re.resources.designer.processor.grid.entity.arithmetic'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 5,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
showIf: (arg) => {
return 'ARITHMETIC' === arg.form.getFieldValue('type');
},
1 year ago
},
10 months ago
{
colSpan: 5,
name: 'ternaryCondition',
label: $t('re.resources.designer.processor.grid.entity.ternaryCondition'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 3,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
showIf: (arg) => {
return 'TERNARY' === arg.form.getFieldValue('type');
},
1 year ago
},
10 months ago
{
colSpan: 5,
name: 'ternaryTrue',
label: $t('re.resources.designer.processor.grid.entity.ternaryTrue'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 3,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
showIf: (arg) => {
return 'TERNARY' === arg.form.getFieldValue('type');
},
1 year ago
},
10 months ago
{
colSpan: 5,
name: 'ternaryFalse',
label: $t('re.resources.designer.processor.grid.entity.ternaryFalse'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 3,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
showIf: (arg) => {
return 'TERNARY' === arg.form.getFieldValue('type');
},
1 year ago
},
10 months ago
{
colSpan: 5,
name: 'when',
label: $t('re.resources.designer.processor.grid.entity.when'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 3,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
showIf: (arg) => {
return 'WHEN_THEN' === arg.form.getFieldValue('type');
10 months ago
},
10 months ago
},
{
colSpan: 5,
name: 'then',
label: $t('re.resources.designer.processor.grid.entity.then'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 3,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
showIf: (arg) => {
return 'WHEN_THEN' === arg.form.getFieldValue('type');
10 months ago
},
10 months ago
},
{
colSpan: 5,
name: 'isWhenThenShorted',
label: $t('re.resources.designer.processor.grid.entity.isWhenThenShorted'),
8 months ago
type: 'w-checkbox',
10 months ago
showIf: (arg) => {
return 'WHEN_THEN' === arg.form.getFieldValue('type');
},
},
{
colSpan: 5,
name: 'numberRangeVar',
label: $t('re.resources.designer.processor.grid.entity.numberRangeVar'),
showIf: (arg) => {
return 'NUMBER_RANGE' === arg.form.getFieldValue('type');
},
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 2,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
},
{
colSpan: 5,
name: 'numberRange',
label: $t('re.resources.designer.processor.grid.entity.numberRange'),
showIf: (arg) => {
return 'NUMBER_RANGE' === arg.form.getFieldValue('type');
},
type: 'w-grid',
10 months ago
dbClickOperation: 'edit',
10 months ago
height: 300,
denseBody: true,
draggable: true,
pageable: false,
configButton: false,
toolbarConfigure: { noIcon: false },
toolbarActions: [
'add',
'clone',
'edit',
{
extend: 'remove',
click: (arg) => {
const grid = gridRef.getEditorForm().getFieldComponent('numberRange');
grid.removeRows(arg.selecteds);
},
},
'separator',
{
name: 'example',
label: $t('example'),
icon: 'bi-balloon',
click: (arg) => {
const grid = gridRef.getEditorForm().getFieldComponent('numberRange');
const sampleData = [
{ uuid: Tools.uuid(), minIncluded: false, min: null, max: 0, maxIncluded: false, value: 1 },
{ uuid: Tools.uuid(), minIncluded: true, min: 0, max: 1, maxIncluded: false, value: 2 },
{ uuid: Tools.uuid(), minIncluded: true, min: 1, max: 2, maxIncluded: false, value: 3 },
{ uuid: Tools.uuid(), minIncluded: true, min: 2, max: 3, maxIncluded: false, value: 4 },
{ uuid: Tools.uuid(), minIncluded: true, min: 3, max: null, maxIncluded: false, value: 5 },
{ uuid: Tools.uuid(), minIncluded: false, min: null, max: null, maxIncluded: false, value: 0 },
];
grid.setLocalData(sampleData);
},
},
],
primaryKey: 'uuid',
columns: [
8 months ago
{ width: 200, name: 'uuid', label: 'uuid', showIf: false },
10 months ago
{
width: 60,
name: 'minIncluded',
label: $t('include'),
align: 'center',
sortable: false,
format: (value) => {
if (value) {
return '[';
} else {
return '(';
}
},
},
{ width: 100, name: 'min', label: $t('minValue'), align: 'right', sortable: false },
{ width: 100, name: 'max', label: $t('maxValue'), align: 'right', sortable: false },
{
width: 60,
name: 'maxIncluded',
label: $t('include'),
align: 'center',
sortable: false,
format: (value) => {
if (value) {
return '[';
} else {
return ')';
}
},
},
{ width: '100%', name: 'value', label: $t('value'), sortable: false },
],
editor: {
dialog: {
width: '600px',
},
form: {
colsNum: 4,
fields: [
8 months ago
{ name: 'uuid', label: 'uuid', showIf: false, colSpan: 4 },
8 months ago
{ name: 'min', label: $t('minValue'), type: 'w-text', colSpan: 3 },
{ name: 'minIncluded', label: $t('include'), type: 'w-checkbox' },
{ name: 'max', label: $t('maxValue'), type: 'w-text', colSpan: 3 },
{ name: 'maxIncluded', label: $t('include'), type: 'w-checkbox' },
{ name: 'value', label: $t('value'), type: 'w-number', colSpan: 3 },
10 months ago
],
10 months ago
},
},
10 months ago
onBeforeEditorDataSubmit: (data, callback) => {
const grid = gridRef.getEditorForm().getFieldComponent('numberRange');
const form = grid.getEditorForm();
if ('add' == form.getStatus() || 'clone' == form.getStatus()) {
data.uuid = Tools.uuid();
grid.addRow(data);
callback(false);
} else if ('edit' == form.getStatus()) {
grid.replaceRow(data);
callback(false);
}
},
},
{
colSpan: 5,
name: 'conditionRange',
label: $t('re.resources.designer.processor.grid.entity.conditionRange'),
showIf: (arg) => {
return 'CONDITION_RANGE' === arg.form.getFieldValue('type');
},
type: 'w-grid',
height: 300,
denseBody: true,
draggable: true,
pageable: false,
configButton: false,
toolbarConfigure: { noIcon: false },
toolbarActions: [
'add',
'clone',
'edit',
{
extend: 'remove',
click: (arg) => {
const grid = gridRef.getEditorForm().getFieldComponent('conditionRange');
grid.removeRows(arg.selecteds);
},
},
'separator',
{
name: 'example',
label: $t('example'),
icon: 'bi-balloon',
click: (arg) => {
const grid = 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: [
8 months ago
{ name: 'uuid', label: 'uuid', showIf: false },
10 months ago
{
name: 'condition',
label: $t('condition'),
align: 'left',
sortable: false,
format: (value) => {
return PlaceHolder.replace(value);
},
},
{
name: 'value',
label: $t('value'),
sortable: false,
format: (value) => {
return PlaceHolder.replace(value);
},
},
],
editor: {
dialog: {
width: '800px',
},
form: {
colsNum: 1,
fields: [
8 months ago
{ name: 'uuid', label: 'uuid', showIf: false },
10 months ago
{
name: 'condition',
label: $t('condition'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 3,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
},
{
name: 'value',
label: $t('value'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 3,
lineWrap: true,
lineBreak: false,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
},
],
10 months ago
},
},
10 months ago
onBeforeEditorDataSubmit: (data, callback) => {
const grid = gridRef.getEditorForm().getFieldComponent('conditionRange');
const form = grid.getEditorForm();
if ('add' == form.getStatus() || 'clone' == form.getStatus()) {
data.uuid = Tools.uuid();
grid.addRow(data);
callback(false);
} else if ('edit' == form.getStatus()) {
grid.replaceRow(data);
callback(false);
}
10 months ago
},
10 months ago
},
{
colSpan: 5,
name: 'groovyScript',
label: $t('re.resources.designer.processor.grid.entity.groovyScript'),
8 months ago
type: 'w-code-mirror',
10 months ago
rows: 20,
lang: 'java',
lineWrap: false,
lineBreak: true,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
showIf: (arg) => {
return 'GROOVY_SCRIPT' === arg.form.getFieldValue('type');
10 months ago
},
},
10 months ago
{
colSpan: 5,
name: 'sqlDatasourceName',
label: $t('re.resources.designer.processor.grid.entity.sqlDatasourceName'),
8 months ago
type: 'w-select',
10 months ago
clearable: true,
options: dsOptionsRef,
rows: 1,
showIf: (arg) => {
return 'SQL' === arg.form.getFieldValue('type');
},
10 months ago
},
10 months ago
{
colSpan: 3,
name: 'sql',
label: $t('re.resources.designer.processor.grid.entity.sql'),
8 months ago
type: 'w-code-mirror',
10 months ago
height: 180,
lang: 'sql',
toolbar: false,
placeholder: true,
autoCompletion: autoCompletion,
showIf: (arg) => {
return 'SQL' === arg.form.getFieldValue('type');
10 months ago
},
10 months ago
},
{
colSpan: 2,
name: 'sqlParameterValues',
label: $t('re.resources.designer.processor.grid.entity.sqlParameterValues'),
showIf: (arg) => {
return 'SQL' === arg.form.getFieldValue('type');
10 months ago
},
10 months ago
type: 'w-grid',
height: 150,
title: $t('re.resources.designer.processor.grid.entity.sqlParameterValues'),
autoFetchData: false,
dense: true,
dbClickOperation: 'edit',
draggable: true,
pageable: false,
configButton: false,
toolbarConfigure: { noIcon: false },
toolbarActions: [
{
name: 'analyze',
label: $t('analyze'),
icon: 'bi-tag',
click: (arg) => {
const sql = gridRef.getEditorForm().getFieldValue('sql');
const regex = /\$\{[\u0000-\uFFFF]+?\}/g;
const array = sql.match(regex);
const rows = [];
8 months ago
array.forEach((item) => {
10 months ago
rows.push({ uuid: Tools.uuid(), name: item, value: '' });
8 months ago
});
10 months ago
const grid = gridRef.getEditorForm().getFieldComponent('sqlParameterValues');
grid.setLocalData(rows);
},
10 months ago
},
10 months ago
'separator',
'add',
'edit',
[
{
extend: 'remove',
click: (arg) => {
const grid = gridRef.getEditorForm().getFieldComponent('sqlParameterValues');
grid.removeRows(arg.selecteds);
},
},
{
extend: 'remove',
name: 'removeAll',
label: $t('deleteAll'),
click: (arg) => {
const grid = gridRef.getEditorForm().getFieldComponent('sqlParameterValues');
grid.setLocalData([]);
},
},
],
],
primaryKey: 'uuid',
columns: [
8 months ago
{ name: 'uuid', label: 'uuid', showIf: false },
10 months ago
{
width: '50%',
name: 'name',
label: $t('name'),
align: 'left',
sortable: false,
format: (value) => {
return PlaceHolder.replace(value);
},
},
{
width: '100%',
name: 'value',
label: $t('value'),
sortable: false,
},
],
editor: {
dialog: {
width: '600px',
},
form: {
colsNum: 1,
fields: [
8 months ago
{ name: 'uuid', label: 'uuid', showIf: false },
10 months ago
{
name: 'name',
label: $t('name'),
8 months ago
type: 'w-code-mirror',
10 months ago
lang: 'java',
rows: 1,
placeholder: true,
autoCompletion: autoCompletion,
9 months ago
userDefinedFunctions: userDefinedFunctionsRef,
10 months ago
},
{
name: 'value',
label: $t('value'),
8 months ago
type: 'w-text',
10 months ago
},
],
10 months ago
},
},
10 months ago
onBeforeEditorDataSubmit: (data, callback) => {
const grid = gridRef.getEditorForm().getFieldComponent('sqlParameterValues');
const form = grid.getEditorForm();
if ('add' == form.getStatus() || 'clone' == form.getStatus()) {
data.uuid = Tools.uuid();
grid.addRow(data);
callback(false);
} else if ('edit' == form.getStatus()) {
grid.replaceRow(data);
callback(false);
}
10 months ago
},
10 months ago
},
{
colSpan: 3,
name: 'sqlQueryResult',
label: $t('re.resources.designer.processor.grid.entity.sqlQueryResult'),
showIf: (arg) => {
return 'SQL' === arg.form.getFieldValue('type');
},
type: 'w-grid',
height: 250,
autoFetchData: false,
title: $t('re.resources.designer.processor.grid.entity.sqlQueryResult'),
dense: true,
draggable: true,
pageable: false,
checkboxSelection: false,
configButton: false,
toolbarConfigure: { noIcon: false },
toolbarActions: [
{
name: 'execute',
label: $t('execute'),
icon: 'bi-caret-right',
click: (arg) => {
const sql = gridRef.getEditorForm().getFieldValue('sql');
10 months ago
const grid = gridRef.getEditorForm().getFieldComponent('sqlParameterValues');
const sqlParameterValues = grid?.getLocalData();
10 months ago
axios
10 months ago
.post(Environment.apiContextPath('/api/re/indicator/processor/executeSql'), {
10 months ago
sql: sql,
sqlParameterValues: sqlParameterValues,
})
.then((response) => {
const fieldMetaDatas = response.data.fieldMetaDatas;
8 months ago
fieldMetaDatas.forEach((field) => {
10 months ago
field.value = field.name;
8 months ago
});
10 months ago
const data = response.data.data;
const grid = gridRef.getEditorForm().getFieldComponent('sqlQueryResult');
sqlQueryResultFieldsRef = fieldMetaDatas;
grid.setLocalData(data);
});
},
},
],
columns: computed(() => {
return sqlQueryResultFieldsRef;
}),
},
{
colSpan: 2,
name: 'sqlFieldMapping',
label: $t('re.resources.designer.processor.grid.entity.sqlFieldMapping'),
showIf: (arg) => {
return 'SQL' === arg.form.getFieldValue('type');
},
type: 'w-grid',
height: 250,
width: '100%',
autoFetchData: false,
title: $t('re.resources.designer.processor.grid.entity.sqlFieldMapping'),
dense: true,
dbClickOperation: 'edit',
draggable: true,
pageable: false,
configButton: false,
toolbarConfigure: { noIcon: false },
toolbarActions: [
'add',
'edit',
[
10 months ago
{
10 months ago
extend: 'remove',
click: (arg) => {
const grid = gridRef.getEditorForm().getFieldComponent('sqlFieldMapping');
grid.removeRows(arg.selecteds);
},
10 months ago
},
{
10 months ago
extend: 'remove',
name: 'removeAll',
label: $t('deleteAll'),
click: (arg) => {
const grid = gridRef.getEditorForm().getFieldComponent('sqlFieldMapping');
grid.setLocalData([]);
},
10 months ago
},
],
10 months ago
],
primaryKey: 'uuid',
columns: [
8 months ago
{ name: 'uuid', label: 'uuid', showIf: false },
10 months ago
{
width: '50%',
name: 'field',
label: $t('fieldName'),
align: 'left',
sortable: false,
},
{
width: '50%',
name: 'parameter',
label: $t('parameterName'),
sortable: false,
format: (value) => {
return PlaceHolder.replace(value);
},
},
],
editor: {
dialog: {
width: '600px',
},
form: {
colsNum: 1,
fields: [
8 months ago
{ name: 'uuid', label: 'uuid', showIf: false },
10 months ago
{
name: 'field',
label: $t('fieldName'),
8 months ago
type: 'w-select',
10 months ago
options: sqlQueryResultFieldsRef,
},
{
name: 'parameter',
label: $t('parameterName'),
8 months ago
type: 'w-select',
10 months ago
options: indicatorOptionsRef,
10 months ago
},
],
},
},
onBeforeEditorDataSubmit: (data, callback) => {
const grid = gridRef.getEditorForm().getFieldComponent('sqlFieldMapping');
const form = grid.getEditorForm();
if ('add' == form.getStatus() || 'clone' == form.getStatus()) {
data.uuid = Tools.uuid();
grid.addRow(data);
callback(false);
} else if ('edit' == form.getStatus()) {
grid.replaceRow(data);
callback(false);
}
10 months ago
},
},
10 months ago
],
},
}"
:viewer="{
panel: {
columnNum: 1,
fields: [
{ name: 'order', label: $t('order') },
{ name: 'id', label: $t('id'), primaryKey: true },
{ name: 'indicator', label: $t('indicator') },
{ name: 'description', label: $t('description') },
{ name: 'enable', label: $t('enable') },
{ name: 'type', label: $t('type') },
{ name: 'optionCode', label: $t('re.resources.designer.processor.grid.entity.optionCode') },
{ name: 'arithmetic', label: $t('re.resources.designer.processor.grid.entity.arithmetic') },
{ name: 'ternaryCondition', label: $t('re.resources.designer.processor.grid.entity.ternaryCondition') },
{ name: 'ternaryTrue', label: $t('re.resources.designer.processor.grid.entity.ternaryTrue') },
{ name: 'ternaryFalse', label: $t('re.resources.designer.processor.grid.entity.ternaryFalse') },
{ name: 'when', label: $t('re.resources.designer.processor.grid.entity.when') },
{ name: 'then', label: $t('re.resources.designer.processor.grid.entity.then') },
{ name: 'isWhenThenShorted', label: $t('re.resources.designer.processor.grid.entity.isWhenThenShorted') },
{ name: 'rule', label: $t('re.resources.designer.processor.grid.entity.rule') },
{ name: 'singleRule', label: $t('re.resources.designer.processor.grid.entity.singleRule') },
{ name: 'numberRange', label: $t('re.resources.designer.processor.grid.entity.numberRange') },
{ name: 'conditionRange', label: $t('re.resources.designer.processor.grid.entity.conditionRange') },
{ name: 'decisionTable2C', label: $t('re.resources.designer.processor.grid.entity.decisionTable2C') },
{ name: 'decisionTable', label: $t('re.resources.designer.processor.grid.entity.decisionTable') },
{ name: 'groovyScript', label: $t('re.resources.designer.processor.grid.entity.groovyScript') },
1 year ago
10 months ago
{ name: 'sqlDatasourceName', label: $t('re.resources.designer.processor.grid.entity.sqlDatasourceName') },
{ name: 'sql', label: $t('re.resources.designer.processor.grid.entity.sql') },
{ name: 'sqlParameterValues', label: $t('re.resources.designer.processor.grid.entity.sqlParameterValues') },
{ name: 'sqlFieldMapping', label: $t('re.resources.designer.processor.grid.entity.sqlFieldMapping') },
1 year ago
10 months ago
{ name: 'dataComeFrom', label: $t('dataComeFrom') },
{ name: 'creator', label: $t('creator') },
{ name: 'createDate', label: $t('createDate') },
{ name: 'lastModifier', label: $t('lastModifier') },
{ name: 'lastModifyDate', label: $t('lastModifyDate'), format: Formater.none() },
],
},
}"
@before-editor-data-submit="
(data, callback) => {
const form = gridRef.getEditorForm();
if ('OBJECT_PROPERTIES' === data.type) {
const grid = form.getFieldComponent('objectProperties');
const localData = grid.getLocalData();
const objectProperties = [];
8 months ago
localData.forEach((item) => {
10 months ago
objectProperties.push({
code: item.code,
name: item.name,
expression: item.expression,
});
8 months ago
});
10 months ago
data.objectProperties = Tools.object2Json(objectProperties);
} else if ('NUMBER_RANGE' === data.type) {
const grid = form.getFieldComponent('numberRange');
const localData = grid.getLocalData();
const ranges = [];
8 months ago
localData.forEach((item) => {
10 months ago
ranges.push({
uuid: item.uuid,
minIncluded: item.minIncluded,
min: item.min,
max: item.max,
maxIncluded: item.maxIncluded,
value: item.value,
});
8 months ago
});
10 months ago
data.numberRange = Tools.object2Json(ranges);
} else if ('CONDITION_RANGE' === data.type) {
const grid = form.getFieldComponent('conditionRange');
const localData = grid.getLocalData();
const ranges = [];
8 months ago
localData.forEach((item) => {
10 months ago
ranges.push({
uuid: item.uuid,
condition: item.condition,
value: item.value,
});
8 months ago
});
10 months ago
data.conditionRange = Tools.object2Json(ranges);
} else if ('SQL' === data.type) {
const sqlParameterValuesGrid = form.getFieldComponent('sqlParameterValues');
const sqlParameterValuesLocalData = sqlParameterValuesGrid.getLocalData();
const sqlParameterValues = [];
8 months ago
sqlParameterValuesLocalData.forEach((item) => {
10 months ago
sqlParameterValues.push({
uuid: item.uuid,
name: item.name,
value: item.value,
});
8 months ago
});
10 months ago
data.sqlParameterValues = Tools.object2Json(sqlParameterValues);
const sqlFieldMappingGrid = form.getFieldComponent('sqlFieldMapping');
const sqlFieldMappingLocalData = sqlFieldMappingGrid.getLocalData();
const sqlFieldMapping = [];
8 months ago
sqlFieldMappingLocalData.forEach((item) => {
10 months ago
sqlFieldMapping.push({
uuid: item.uuid,
field: item.field,
parameter: item.parameter,
});
8 months ago
});
10 months ago
data.sqlFieldMapping = Tools.object2Json(sqlFieldMapping);
10 months ago
}
}
10 months ago
"
@after-editor-open="
8 months ago
(args) => {
const row = args.data;
10 months ago
// 获取代码提示列表
axios.get(Environment.apiContextPath('/api/re/common/listParameterAndValueTypeByIndicatorId/' + indicator.id)).then((response) => {
autoCompletionManager.setParameters(response.data.parameters);
autoCompletionManager.setValueTypes(response.data.valueTypes);
});
if ('add' == gridRef.getEditorForm().getStatus()) {
// 获取对象属性列表
axios.get(Environment.apiContextPath('/api/re/indicator/listObejctPropertiesByIndicatorId/' + indicator.id)).then((response) => {
const properties = response.data;
const grid = gridRef.getEditorForm().getFieldComponent('objectProperties');
grid?.setLocalData(properties);
});
} else if ('edit' == gridRef.getEditorForm().getStatus()) {
// 获取对象属性列表
axios.get(Environment.apiContextPath('/api/re/indicator/processor/listObejctPropertiesByProcessorId/' + row.id)).then((response) => {
const properties = response.data;
const grid = gridRef.getEditorForm().getFieldComponent('objectProperties');
grid?.setLocalData(properties);
});
10 months ago
}
10 months ago
//获取所有指标列表
axios.get(Environment.apiContextPath('api/re/indicator/findIndicatorsByIndicatorId?indicatorId=' + indicator.id)).then((response) => {
const options = [];
8 months ago
response.data.forEach((indicator) => {
10 months ago
options.push({ label: indicator.name, value: '${' + indicator.name + '}' });
8 months ago
});
10 months ago
indicatorOptionsRef = options;
});
10 months ago
const type = gridRef.getEditorForm().getFieldValue('type');
if ('NUMBER_RANGE' === type) {
const grid = gridRef.getEditorForm().getFieldComponent('numberRange');
const rows = Tools.json2Object(row.numberRange);
grid.setLocalData(rows);
} else if ('CONDITION_RANGE' === type) {
const grid = gridRef.getEditorForm().getFieldComponent('conditionRange');
const rows = Tools.json2Object(row.conditionRange);
grid.setLocalData(rows);
} else if ('SQL' === type) {
const sqlParameterValuesGrid = gridRef.getEditorForm().getFieldComponent('sqlParameterValues');
const sqlParameterValuesRows = Tools.json2Object(row.sqlParameterValues);
sqlParameterValuesGrid.setLocalData(sqlParameterValuesRows);
const sqlFieldMappingGrid = gridRef.getEditorForm().getFieldComponent('sqlFieldMapping');
const sqlFieldMappingRows = Tools.json2Object(row.sqlFieldMapping);
sqlFieldMappingGrid.setLocalData(sqlFieldMappingRows);
10 months ago
}
}
10 months ago
"
></w-grid>
<ObjectPropertiesMatcherDialog
ref="objectPropertiesMatcherDialogRef"
:indicator="indicator"
@after-matched="
(objectProperties) => {
const grid = gridRef.getEditorForm().getFieldComponent('objectProperties');
grid.setLocalData(objectProperties);
}
"
></ObjectPropertiesMatcherDialog>
</div>
1 year ago
</template>
<script setup lang="ts">
10 months ago
import { ref, computed, onMounted } from 'vue';
10 months ago
import { axios, Environment, Formater, EnumTools, Tools } from 'platform-core';
import { PlaceHolder } from '@/utils/PlaceHolder';
10 months ago
import ObjectPropertiesMatcherDialog from './ObjectPropertiesMatcherDialog.vue';
import { AutoCompletionManager } from '@/views/shared/AutoCompletionManager';
1 year ago
const props = defineProps({
indicator: { type: Object, default: undefined },
10 months ago
readOnly: { type: Boolean, default: false },
1 year ago
});
const gridRef = ref();
10 months ago
const objectPropertiesMatcherDialogRef = ref();
const dsOptionsRef = ref([]);
9 months ago
const userDefinedFunctionsRef = ref();
10 months ago
const sqlQueryResultFieldsRef = ref([]);
10 months ago
const indicatorOptionsRef = ref();
10 months ago
const autoCompletionManager = new AutoCompletionManager();
const autoCompletion = (context) => {
return autoCompletionManager.autoCompletion(context);
};
10 months ago
const transfromContent = (xml) => {
const div = document.createElement('div');
div.textContent = xml;
const result = div.outerHTML;
div.parentNode?.removeChild(div);
return result;
};
1 year ago
const refresh = () => {
1 year ago
gridRef?.value?.refresh();
1 year ago
};
onMounted(() => {
1 year ago
gridRef?.value?.refresh();
1 year ago
});
defineExpose({
refresh,
});
const Enums = await EnumTools.fetch(['io.sc.engine.rule.core.enums.ProcessorType']);
9 months ago
axios.get(Environment.apiContextPath('/api/re/function?pageable=false')).then((response) => {
const options = [];
const items = response.data?.content;
if (items && items.length > 0) {
8 months ago
items.forEach((item) => {
9 months ago
if (item.enable) {
options.push(item);
}
8 months ago
});
9 months ago
}
userDefinedFunctionsRef.value = options;
});
1 year ago
</script>