|
@ -3,17 +3,19 @@ import { $t, Tools, MarkupTableUtil } from 'platform-core'; |
|
|
import { Processor } from '../Processor'; |
|
|
import { Processor } from '../Processor'; |
|
|
import { PlaceHolder } from '@/utils/PlaceHolder'; |
|
|
import { PlaceHolder } from '@/utils/PlaceHolder'; |
|
|
|
|
|
|
|
|
const columnsRef = ref(<any>[]); |
|
|
|
|
|
|
|
|
|
|
|
class DecisionTable extends Processor { |
|
|
class DecisionTable extends Processor { |
|
|
public getToolbarAction(target: any): any { |
|
|
#editorDialogWidth: number = 1024; |
|
|
|
|
|
protected columnsRef = ref(<any>[]); |
|
|
|
|
|
|
|
|
|
|
|
public getToolbarAction(): any { |
|
|
return { |
|
|
return { |
|
|
extend: 'add', |
|
|
extend: 'add', |
|
|
name: 'decisionTable', |
|
|
name: 'decisionTable', |
|
|
label: $t('io.sc.engine.rule.core.enums.ProcessorType.DECISION_TABLE'), |
|
|
label: $t('io.sc.engine.rule.core.enums.ProcessorType.DECISION_TABLE'), |
|
|
icon: 'bi-grid-3x3', |
|
|
icon: 'bi-grid-3x3', |
|
|
enableIf: (args: any) => { |
|
|
enableIf: (args: any) => { |
|
|
return target.type !== 'RULE_RESULT' && target.type !== 'SINGLE_RULE_RESULT'; |
|
|
const type = this.context.target.type; |
|
|
|
|
|
return type !== 'RULE_RESULT' && type !== 'SINGLE_RULE_RESULT'; |
|
|
}, |
|
|
}, |
|
|
afterClick: (args: any) => { |
|
|
afterClick: (args: any) => { |
|
|
args.grid.getEditorForm().setFieldValue('type', 'DECISION_TABLE'); |
|
|
args.grid.getEditorForm().setFieldValue('type', 'DECISION_TABLE'); |
|
@ -32,7 +34,7 @@ class DecisionTable extends Processor { |
|
|
if (obj[key] === 'condition') { |
|
|
if (obj[key] === 'condition') { |
|
|
str += ' <td>' + $t(obj[key]) + '</td>'; |
|
|
str += ' <td>' + $t(obj[key]) + '</td>'; |
|
|
} else { |
|
|
} else { |
|
|
str += ' <td class="text-blue-500">' + $t(obj[key]) + '</td>'; |
|
|
str += ' <td class="font-bold">' + $t(obj[key]) + '</td>'; |
|
|
} |
|
|
} |
|
|
} else if (key.startsWith('C')) { |
|
|
} else if (key.startsWith('C')) { |
|
|
str += ' <td>' + PlaceHolder.replace(obj[key]) + '</td>'; |
|
|
str += ' <td>' + PlaceHolder.replace(obj[key]) + '</td>'; |
|
@ -40,15 +42,15 @@ class DecisionTable extends Processor { |
|
|
}); |
|
|
}); |
|
|
str += '</tr>'; |
|
|
str += '</tr>'; |
|
|
}); |
|
|
}); |
|
|
return MarkupTableUtil.markupTable('', str); |
|
|
return MarkupTableUtil.markupTable('', str, Tools.mergeObject({}, Processor.FORMAT_TABLE_STYLE)); |
|
|
} |
|
|
} |
|
|
return ''; |
|
|
return ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public getEditorFields(context?: any): any { |
|
|
public getEditorFields(): any { |
|
|
return [ |
|
|
return [ |
|
|
{ |
|
|
{ |
|
|
colSpan: 5, |
|
|
colSpan: 7, |
|
|
name: 'decisionTable', |
|
|
name: 'decisionTable', |
|
|
label: $t('re.resources.designer.processor.grid.entity.decisionTable'), |
|
|
label: $t('re.resources.designer.processor.grid.entity.decisionTable'), |
|
|
showIf: (args: any) => { |
|
|
showIf: (args: any) => { |
|
@ -56,8 +58,9 @@ class DecisionTable extends Processor { |
|
|
}, |
|
|
}, |
|
|
type: 'w-grid', |
|
|
type: 'w-grid', |
|
|
height: 300, |
|
|
height: 300, |
|
|
dbClickOperation: 'edit', |
|
|
localMode: true, |
|
|
selectedMode: 'cell', |
|
|
selectMode: 'cell', |
|
|
|
|
|
dbClickOperation: 'cellEdit', |
|
|
autoFetchData: false, |
|
|
autoFetchData: false, |
|
|
denseBody: true, |
|
|
denseBody: true, |
|
|
dndMode: 'local', |
|
|
dndMode: 'local', |
|
@ -80,7 +83,7 @@ class DecisionTable extends Processor { |
|
|
return false; |
|
|
return false; |
|
|
}, |
|
|
}, |
|
|
click: (args: any) => { |
|
|
click: (args: any) => { |
|
|
addCol(args.grid, args.selectedColName, /C[\d]/, 'left'); |
|
|
this.addCol(args.grid, args.selectedColName, /C[\d]/, 'left'); |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
@ -93,7 +96,7 @@ class DecisionTable extends Processor { |
|
|
return false; |
|
|
return false; |
|
|
}, |
|
|
}, |
|
|
click: (args: any) => { |
|
|
click: (args: any) => { |
|
|
addCol(args.grid, args.selectedColName, /C[\d]/, 'right'); |
|
|
this.addCol(args.grid, args.selectedColName, /C[\d]/, 'right'); |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
'separator', |
|
|
'separator', |
|
@ -101,34 +104,24 @@ class DecisionTable extends Processor { |
|
|
name: 'addConditionRow', |
|
|
name: 'addConditionRow', |
|
|
label: $t('re.resources.designer.processor.decisionTable.toolbar.addConditionRow'), |
|
|
label: $t('re.resources.designer.processor.decisionTable.toolbar.addConditionRow'), |
|
|
click: (args: any) => { |
|
|
click: (args: any) => { |
|
|
|
|
|
let rowNum = 0; |
|
|
const rows = args.grid.getRows(); |
|
|
const rows = args.grid.getRows(); |
|
|
const propertyNames = Tools.extractAllPropertyNames(rows, /C[\d]/); |
|
|
if (rows && rows.length > 0) { |
|
|
propertyNames.sort(); |
|
|
for (let i = 0; i < rows.length; i++) { |
|
|
const row: any = { |
|
|
if (rows[i].type === 'result') { |
|
|
uuid: Tools.uuid(), |
|
|
rowNum = i; |
|
|
type: 'condition', |
|
|
break; |
|
|
}; |
|
|
} |
|
|
propertyNames.forEach((name) => { |
|
|
} |
|
|
row[name] = ''; |
|
|
} |
|
|
}); |
|
|
args.grid.addLocalData({ type: 'condition' }, rowNum); |
|
|
args.grid.addLocalData(row); |
|
|
|
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
name: 'addResultRow', |
|
|
name: 'addResultRow', |
|
|
label: $t('re.resources.designer.processor.decisionTable.toolbar.addResultRow'), |
|
|
label: $t('re.resources.designer.processor.decisionTable.toolbar.addResultRow'), |
|
|
click: (args: any) => { |
|
|
click: (args: any) => { |
|
|
const rows = args.grid.getRows(); |
|
|
args.grid.addLocalData({ type: 'result' }); |
|
|
const propertyNames = Tools.extractAllPropertyNames(rows, /C[\d]/); |
|
|
|
|
|
propertyNames.sort(); |
|
|
|
|
|
const row: any = { |
|
|
|
|
|
uuid: Tools.uuid(), |
|
|
|
|
|
type: 'result', |
|
|
|
|
|
}; |
|
|
|
|
|
propertyNames.forEach((name) => { |
|
|
|
|
|
row[name] = ''; |
|
|
|
|
|
}); |
|
|
|
|
|
args.grid.addLocalData(row); |
|
|
|
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
], |
|
|
], |
|
@ -147,7 +140,7 @@ class DecisionTable extends Processor { |
|
|
return false; |
|
|
return false; |
|
|
}, |
|
|
}, |
|
|
click: (args: any) => { |
|
|
click: (args: any) => { |
|
|
removeCol(args.grid, args.selectedColName, /C[\d]/); |
|
|
this.removeCol(args.grid, args.selectedColName, /C[\d]/); |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
@ -160,12 +153,12 @@ class DecisionTable extends Processor { |
|
|
return false; |
|
|
return false; |
|
|
}, |
|
|
}, |
|
|
click: (args: any) => { |
|
|
click: (args: any) => { |
|
|
args.grid.removeLocalData(args.selected); |
|
|
args.grid.removeLocalData(args.selecteds); |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
], |
|
|
], |
|
|
'separator', |
|
|
'separator', |
|
|
'edit', |
|
|
'cellEdit', |
|
|
'separator', |
|
|
'separator', |
|
|
{ |
|
|
{ |
|
|
name: 'example', |
|
|
name: 'example', |
|
@ -173,31 +166,33 @@ class DecisionTable extends Processor { |
|
|
icon: 'bi-balloon', |
|
|
icon: 'bi-balloon', |
|
|
click: (args: any) => { |
|
|
click: (args: any) => { |
|
|
const sampleData = [ |
|
|
const sampleData = [ |
|
|
{ uuid: Tools.uuid(), type: 'condition', C0: '${客户类型}="普通客户"', C1: 'Y', C2: 'Y', C3: null, C4: null }, |
|
|
{ type: 'condition', C0: '${客户类型}="普通客户"', C1: 'Y', C2: 'Y', C3: null, C4: null }, |
|
|
{ uuid: Tools.uuid(), type: 'condition', C0: '${评分结果}>=60', C1: 'Y', C2: null, C3: 'Y', C4: null }, |
|
|
{ type: 'condition', C0: '${评分结果}>=60', C1: 'Y', C2: null, C3: 'Y', C4: null }, |
|
|
{ uuid: Tools.uuid(), type: 'result', C0: '${风险等级}', C1: 'A', C2: 'B', C3: 'B', C4: 'C' }, |
|
|
{ type: 'result', C0: '${风险等级}', C1: 'A', C2: 'B', C3: 'B', C4: 'C' }, |
|
|
{ uuid: Tools.uuid(), type: 'result', C0: '${决策结果}', C1: '直接通过', C2: '人工审查', C3: '人工审查', C4: '直接拒绝' }, |
|
|
{ type: 'result', C0: '${决策结果}', C1: '直接通过', C2: '人工审查', C3: '人工审查', C4: '直接拒绝' }, |
|
|
]; |
|
|
]; |
|
|
|
|
|
const propertyNames: any[] = Tools.extractAllPropertyNames(sampleData, /C[\d]/); |
|
|
|
|
|
propertyNames.sort(); |
|
|
|
|
|
this.buildColumsRef(propertyNames); |
|
|
args.grid.setLocalData(sampleData); |
|
|
args.grid.setLocalData(sampleData); |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
], |
|
|
], |
|
|
primaryKey: 'uuid', |
|
|
columns: this.columnsRef, |
|
|
columns: columnsRef, |
|
|
|
|
|
editor: { |
|
|
editor: { |
|
|
dialog: { |
|
|
dialog: { |
|
|
width: '600px', |
|
|
width: '600px', |
|
|
}, |
|
|
}, |
|
|
form: { |
|
|
form: { |
|
|
colsNum: 1, |
|
|
colsNum: 1, |
|
|
fields: columnsRef, |
|
|
fields: this.columnsRef, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public getViewerFields(context?: any): any { |
|
|
public getViewerFields(): any { |
|
|
return [{ name: 'decisionTable', label: $t('re.resources.designer.processor.grid.entity.decisionTable') }]; |
|
|
return [{ name: 'decisionTable', label: $t('re.resources.designer.processor.grid.entity.decisionTable') }]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -206,7 +201,6 @@ class DecisionTable extends Processor { |
|
|
const grid = form.getFieldComponent('decisionTable'); |
|
|
const grid = form.getFieldComponent('decisionTable'); |
|
|
const localData: any[] = grid.getRows(); |
|
|
const localData: any[] = grid.getRows(); |
|
|
const fieldNames: any[] = []; |
|
|
const fieldNames: any[] = []; |
|
|
fieldNames.push('uuid'); |
|
|
|
|
|
fieldNames.push('type'); |
|
|
fieldNames.push('type'); |
|
|
const propertyNames: any[] = Tools.extractAllPropertyNames(localData, /C[\d]/); |
|
|
const propertyNames: any[] = Tools.extractAllPropertyNames(localData, /C[\d]/); |
|
|
propertyNames.sort(); |
|
|
propertyNames.sort(); |
|
@ -225,43 +219,36 @@ class DecisionTable extends Processor { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public afterEditorOpen(args: any): void { |
|
|
public afterEditorOpen(args: any): void { |
|
|
|
|
|
args.grid.getEditorDialog().setWidth(this.#editorDialogWidth); |
|
|
|
|
|
this.initAutoCompletionManager(); |
|
|
|
|
|
this.initUserDefinedFunctionsManager(); |
|
|
|
|
|
|
|
|
const form = args.grid.getEditorForm(); |
|
|
const form = args.grid.getEditorForm(); |
|
|
const row = args.data; |
|
|
const row = args.data || []; |
|
|
// 构建表格的头
|
|
|
|
|
|
const rows = Tools.json2Object(row.decisionTable); |
|
|
const rows = Tools.json2Object(row.decisionTable); |
|
|
const fieldNames = Tools.extractAllPropertyNames(rows, /C[\d]/); |
|
|
const fieldNames = Tools.extractAllPropertyNames(rows, /C[\d]/); |
|
|
fieldNames.sort(); |
|
|
fieldNames.sort(); |
|
|
const fields: any = []; |
|
|
this.buildColumsRef(fieldNames); |
|
|
addFixedFields(fields); |
|
|
|
|
|
fieldNames.forEach((name) => { |
|
|
|
|
|
fields.push({ |
|
|
|
|
|
name: name, |
|
|
|
|
|
label: $t(name), |
|
|
|
|
|
sortable: false, |
|
|
|
|
|
type: 'w-code-mirror', |
|
|
|
|
|
attrs: { |
|
|
|
|
|
toolbar: false, |
|
|
|
|
|
rows: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
format: (value: any) => { |
|
|
|
|
|
return PlaceHolder.replace(value); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
columnsRef.value = fields; |
|
|
|
|
|
// 设置表格数据
|
|
|
|
|
|
const grid = form.getFieldComponent('decisionTable'); |
|
|
const grid = form.getFieldComponent('decisionTable'); |
|
|
|
|
|
switch (form.getStatus()) { |
|
|
|
|
|
case 'add': |
|
|
|
|
|
grid.setLocalData([]); |
|
|
|
|
|
break; |
|
|
|
|
|
case 'edit': |
|
|
|
|
|
case 'clone': |
|
|
grid.setLocalData(rows); |
|
|
grid.setLocalData(rows); |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const addCol = (grid: any, currentSelectedColName: string, colNamePattern: any, mode: string) => { |
|
|
protected addCol(grid: any, currentSelectedColName: string, colNamePattern: any, mode: string) { |
|
|
//更新表数据
|
|
|
//更新表数据
|
|
|
const rows: any[] = grid.getRows(); |
|
|
const rows: any[] = grid.getRows(); |
|
|
const propertyNames: string[] = Tools.extractAllPropertyNames(rows, colNamePattern); |
|
|
const propertyNames: string[] = Tools.extractAllPropertyNames(rows, colNamePattern); |
|
|
propertyNames.sort(); |
|
|
propertyNames.sort(); |
|
|
const selectedColIndex = propertyNames.indexOf(currentSelectedColName) + (mode === 'left' ? 0 : 1); |
|
|
const selectedColIndex = propertyNames.indexOf(currentSelectedColName) + (mode === 'left' ? 0 : 1); |
|
|
|
|
|
|
|
|
rows.forEach((row) => { |
|
|
rows.forEach((row) => { |
|
|
let i = 0; |
|
|
let i = 0; |
|
|
for (i = propertyNames.length; i > selectedColIndex; i--) { |
|
|
for (i = propertyNames.length; i > selectedColIndex; i--) { |
|
@ -269,32 +256,15 @@ const addCol = (grid: any, currentSelectedColName: string, colNamePattern: any, |
|
|
} |
|
|
} |
|
|
row['C' + selectedColIndex] = ''; |
|
|
row['C' + selectedColIndex] = ''; |
|
|
}); |
|
|
}); |
|
|
|
|
|
this.buildColumsRef(Tools.extractAllPropertyNames(rows, colNamePattern)); |
|
|
// 更新表头
|
|
|
|
|
|
const fields: any[] = []; |
|
|
|
|
|
addFixedFields(fields); |
|
|
|
|
|
let i = 0; |
|
|
|
|
|
for (i = 0; i <= propertyNames.length; i++) { |
|
|
|
|
|
fields.push({ |
|
|
|
|
|
name: 'C' + i, |
|
|
|
|
|
label: $t('C' + i), |
|
|
|
|
|
sortable: false, |
|
|
|
|
|
format: (value: any) => { |
|
|
|
|
|
return PlaceHolder.replace(value); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
columnsRef.value = fields; |
|
|
|
|
|
grid.setLocalData(rows); |
|
|
grid.setLocalData(rows); |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
const removeCol = (grid: any, currentSelectedColName: string, colNamePattern: any) => { |
|
|
protected removeCol(grid: any, currentSelectedColName: string, colNamePattern: any) { |
|
|
//更新表数据
|
|
|
|
|
|
const rows: any[] = grid.getRows(); |
|
|
const rows: any[] = grid.getRows(); |
|
|
const propertyNames: string[] = Tools.extractAllPropertyNames(rows, colNamePattern); |
|
|
const propertyNames: string[] = Tools.extractAllPropertyNames(rows, colNamePattern); |
|
|
propertyNames.sort(); |
|
|
propertyNames.sort(); |
|
|
const selectedColIndex = propertyNames.indexOf(currentSelectedColName); |
|
|
const selectedColIndex = propertyNames.indexOf(currentSelectedColName); |
|
|
|
|
|
|
|
|
rows.forEach((row) => { |
|
|
rows.forEach((row) => { |
|
|
let i = 0; |
|
|
let i = 0; |
|
|
for (i = selectedColIndex; i < propertyNames.length; i++) { |
|
|
for (i = selectedColIndex; i < propertyNames.length; i++) { |
|
@ -302,37 +272,49 @@ const removeCol = (grid: any, currentSelectedColName: string, colNamePattern: an |
|
|
} |
|
|
} |
|
|
delete row['C' + (propertyNames.length - 1)]; |
|
|
delete row['C' + (propertyNames.length - 1)]; |
|
|
}); |
|
|
}); |
|
|
|
|
|
this.buildColumsRef(Tools.extractAllPropertyNames(rows, colNamePattern)); |
|
|
|
|
|
grid.setLocalData(rows); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 更新表头
|
|
|
protected buildColumsRef(propertyNames: string[]) { |
|
|
const fields: any[] = []; |
|
|
const columns: any[] = []; |
|
|
addFixedFields(fields); |
|
|
// 添加"类型"列
|
|
|
|
|
|
columns.push({ |
|
|
|
|
|
name: 'type', |
|
|
|
|
|
label: $t('type'), |
|
|
|
|
|
format: (value: any) => { |
|
|
|
|
|
if (value === 'result') { |
|
|
|
|
|
return '<span class="font-bold">' + $t(value) + '</span>'; |
|
|
|
|
|
} |
|
|
|
|
|
return $t(value); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 添加其他列
|
|
|
let i = 0; |
|
|
let i = 0; |
|
|
for (i = 0; i < propertyNames.length - 1; i++) { |
|
|
for (i = 0; i < propertyNames.length; i++) { |
|
|
fields.push({ |
|
|
columns.push({ |
|
|
name: 'C' + i, |
|
|
name: 'C' + i, |
|
|
label: $t('C' + i), |
|
|
label: $t('C' + i), |
|
|
sortable: false, |
|
|
sortable: false, |
|
|
format: (value: any) => { |
|
|
format: (value: any) => { |
|
|
return PlaceHolder.replace(value); |
|
|
return PlaceHolder.replace(value); |
|
|
}, |
|
|
}, |
|
|
|
|
|
type: 'w-code-mirror', |
|
|
|
|
|
attrs: { |
|
|
|
|
|
toolbar: false, |
|
|
|
|
|
lang: 'java', |
|
|
|
|
|
rows: 4, |
|
|
|
|
|
lineWrap: true, |
|
|
|
|
|
lineBreak: false, |
|
|
|
|
|
placeholder: true, |
|
|
|
|
|
autoCompletion: this.autoCompletionManager.autoCompletion(), |
|
|
|
|
|
userDefinedFunctions: this.userDefinedFunctionsManager.userDefinedFunctions(), |
|
|
|
|
|
}, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
columnsRef.value = fields; |
|
|
this.columnsRef.value = columns; |
|
|
grid.setLocalData(rows); |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const addFixedFields = (fields: any[]) => { |
|
|
|
|
|
fields.push({ name: 'uuid', label: 'uuid', hidden: true }); |
|
|
|
|
|
fields.push({ |
|
|
|
|
|
name: 'type', |
|
|
|
|
|
label: $t('type'), |
|
|
|
|
|
format: (value: any) => { |
|
|
|
|
|
if (value === 'result') { |
|
|
|
|
|
return '<span class="text-blue-500">' + $t(value) + '</span>'; |
|
|
|
|
|
} |
|
|
} |
|
|
return $t(value); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export { DecisionTable }; |
|
|
export { DecisionTable }; |
|
|