|
@ -1,5 +1,67 @@ |
|
|
import { axios, Tools } from '@/platform'; |
|
|
import { axios, Tools } from '@/platform'; |
|
|
|
|
|
|
|
|
|
|
|
class ParameterMapping { |
|
|
|
|
|
/** |
|
|
|
|
|
* 显示顺序映射 |
|
|
|
|
|
*/ |
|
|
|
|
|
static #Boost = { |
|
|
|
|
|
//指标类型
|
|
|
|
|
|
INTERFACE: 100, //接口
|
|
|
|
|
|
INDICATOR: 100 - 1, //指标
|
|
|
|
|
|
|
|
|
|
|
|
// 参数类型
|
|
|
|
|
|
CONSTANT: 100, //常量
|
|
|
|
|
|
IN: 100 - 1, //输入
|
|
|
|
|
|
IN_OPTION: 100 - 1, //输入(选项)
|
|
|
|
|
|
IN_SUB_OUT: 100 - 1, //输入(子模型输出)
|
|
|
|
|
|
INTERMEDIATE: 100 - 2, //中间值
|
|
|
|
|
|
OUT: 100 - 2, //输出
|
|
|
|
|
|
|
|
|
|
|
|
// 元数据类型
|
|
|
|
|
|
ENUM: 0, //枚举
|
|
|
|
|
|
UD_JAVA_CLASS: 200 - 1, //自定义Java类
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取变量替换符前缀 |
|
|
|
|
|
* @param type 类型 |
|
|
|
|
|
* @returns 变量替换符前缀 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static getPlaceholderPrefix(type: string) { |
|
|
|
|
|
if (type === 'ENUM') { |
|
|
|
|
|
return '#'; |
|
|
|
|
|
} else { |
|
|
|
|
|
return '$'; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取自动完成项的优先级, 数值越大越优先 |
|
|
|
|
|
* @param type 类型 |
|
|
|
|
|
* @returns 自动完成项的优先级 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static getBoost(type: string) { |
|
|
|
|
|
return ParameterMapping.#Boost[type]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取自动完成项的类型 |
|
|
|
|
|
* @param type 类型 |
|
|
|
|
|
* @returns 自动完成项的类型 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static getAutoCompletionType(type: string) { |
|
|
|
|
|
if (type === 'ENUM') { |
|
|
|
|
|
return 'enum'; |
|
|
|
|
|
} else if (type === 'CONSTANT') { |
|
|
|
|
|
return 'constant'; |
|
|
|
|
|
} else if (type === 'INDICATOR' || type === 'INTERMEDIATE' || type === 'OUT') { |
|
|
|
|
|
return 'variable'; |
|
|
|
|
|
} else { |
|
|
|
|
|
return 'interface'; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
class AutoCompletionManager { |
|
|
class AutoCompletionManager { |
|
|
parameters: any; |
|
|
parameters: any; |
|
|
valueTypes: any; |
|
|
valueTypes: any; |
|
@ -101,13 +163,20 @@ class AutoCompletionManager { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public getParameterOptions(): any { |
|
|
public getParameterOptions(): any { |
|
|
|
|
|
const cache = {}; |
|
|
const options: any[] = []; |
|
|
const options: any[] = []; |
|
|
Object.values(this.parameters).forEach((parameter: any) => { |
|
|
Object.values(this.parameters).forEach((parameter: any) => { |
|
|
const option = this.getOptionItem(parameter); |
|
|
const option = this.getOptionItem(parameter); |
|
|
if (option) { |
|
|
if (option) { |
|
|
options.push(option); |
|
|
if (!cache[option.label]) { |
|
|
|
|
|
cache[option.label] = option; |
|
|
|
|
|
options.push(option); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
for (const option of options) { |
|
|
|
|
|
option.boost = ParameterMapping.getBoost(option.category); |
|
|
|
|
|
} |
|
|
return options; |
|
|
return options; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -116,15 +185,13 @@ class AutoCompletionManager { |
|
|
if (!Tools.isNill(valueType)) { |
|
|
if (!Tools.isNill(valueType)) { |
|
|
const version = valueType.version ? valueType.name + '(V' + valueType.version + ')' : valueType.name; |
|
|
const version = valueType.version ? valueType.name + '(V' + valueType.version + ')' : valueType.name; |
|
|
const info = parameter.valueTypeIsList ? 'List<' + version + '>' : version; |
|
|
const info = parameter.valueTypeIsList ? 'List<' + version + '>' : version; |
|
|
if (parameter.type === 'parameter') { |
|
|
return { |
|
|
if (parameter.valueTypeIsList) { |
|
|
category: parameter.type, |
|
|
return { label: parameter.name, type: 'variable', apply: '${' + parameter.name + '}[0]', info: info }; |
|
|
type: ParameterMapping.getAutoCompletionType(parameter.type), |
|
|
} else { |
|
|
label: parameter.name, |
|
|
return { label: parameter.name, type: 'variable', apply: '${' + parameter.name + '}', info: info }; |
|
|
apply: ParameterMapping.getPlaceholderPrefix(parameter.type) + '{' + parameter.name + '}' + (parameter.valueTypeIsList ? '[0]' : ''), |
|
|
} |
|
|
info: info, |
|
|
} else if (parameter.type === 'enum') { |
|
|
}; |
|
|
return { label: parameter.name, type: 'enum', apply: '#{' + parameter.name + '}', info: info }; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
@ -137,7 +204,8 @@ class AutoCompletionManager { |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public autoCompletionProperties(to: any, matchedText?: any): any { |
|
|
public autoCompletionProperties(to: any, matchedText?: any, subText?: string): any { |
|
|
|
|
|
console.log(matchedText, subText); |
|
|
const matchedTextReverse = Tools.reverseString(matchedText); |
|
|
const matchedTextReverse = Tools.reverseString(matchedText); |
|
|
const regReverse = /(\.(\](.+?)\[)?\}(.+?)\{[$#])+/g; //匹配 '.]n[}xxx{$#' 模式
|
|
|
const regReverse = /(\.(\](.+?)\[)?\}(.+?)\{[$#])+/g; //匹配 '.]n[}xxx{$#' 模式
|
|
|
// -- -- --- -- -- --- ----
|
|
|
// -- -- --- -- -- --- ----
|
|
@ -151,72 +219,56 @@ class AutoCompletionManager { |
|
|
if (Tools.isUndefinedOrNull(parameterName)) { |
|
|
if (Tools.isUndefinedOrNull(parameterName)) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
const enumRegReverse = /(\.(\](.+?)\[)?\}(.+?)\{#)+/g; //匹配 '.]n[}xxx{#' 模式
|
|
|
|
|
|
// -- -- --- -- -- --- ----
|
|
|
|
|
|
// . ] n [ } xxx {#
|
|
|
|
|
|
let matcheds: any = matchedTextReverse.match(enumRegReverse); |
|
|
|
|
|
if (Tools.isUndefinedOrNull(matcheds) || matcheds.length <= 0) { |
|
|
|
|
|
const regReverse = /(\.(\](.+?)\[)?\}(.+?)\{\$)+/g; //匹配 '.]n[}xxx{$' 模式
|
|
|
|
|
|
// -- -- --- -- -- --- ----
|
|
|
|
|
|
// . ] n [ } xxx {$
|
|
|
|
|
|
matcheds = matchedTextReverse.match(regReverse); |
|
|
|
|
|
if (Tools.isUndefinedOrNull(matcheds) || matcheds.length <= 0) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
const matched = Tools.reverseString(matcheds[0]); |
|
|
|
|
|
let parameterName = matched.replace(/#\{(.+?)\}(\[(.+?)\])?/g, '$1'); |
|
|
|
|
|
// ---- --- -- -- --- --
|
|
|
|
|
|
// $ { xxx } [ n ]
|
|
|
|
|
|
if (Tools.isUndefinedOrNull(parameterName)) { |
|
|
|
|
|
parameterName = matched.replace(/\$\{(.+?)\}(\[(.+?)\])?/g, '$1'); |
|
|
|
|
|
if (Tools.isUndefinedOrNull(parameterName)) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
const options = this.getOptions(parameterName); |
|
|
const options = this.getOptions(parameterName); |
|
|
if (Tools.isUndefinedOrNull(options)) { |
|
|
if (Tools.isUndefinedOrNull(options)) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
let filteredOptions: any[] = []; |
|
|
|
|
|
if (!Tools.isUndefinedOrNull(subText)) { |
|
|
|
|
|
options.forEach((item: any) => { |
|
|
|
|
|
if (item.label.indexOf(subText) > -1) { |
|
|
|
|
|
filteredOptions.push(item); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
filteredOptions = options; |
|
|
|
|
|
} |
|
|
return { |
|
|
return { |
|
|
from: to, |
|
|
from: to, |
|
|
options: options, |
|
|
options: filteredOptions, |
|
|
validFor: /^(.*)?$/, |
|
|
validFor: /^(.*)?$/, |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public doAutoCompletion(context: any): any { |
|
|
public doAutoCompletion(context: any): any { |
|
|
console.log('>>>>'); |
|
|
|
|
|
const beforeMatched = context.matchBefore(/(.+?)/g); |
|
|
const beforeMatched = context.matchBefore(/(.+?)/g); |
|
|
console.log(beforeMatched); |
|
|
|
|
|
|
|
|
|
|
|
if (Tools.isUndefinedOrNull(beforeMatched)) { |
|
|
if (Tools.isUndefinedOrNull(beforeMatched)) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
const beforeText = beforeMatched.text || ''; |
|
|
const beforeText = beforeMatched.text || ''; |
|
|
if (beforeText.endsWith('.')) { |
|
|
if (beforeText.endsWith(' ')) { |
|
|
//匹配属性
|
|
|
|
|
|
return this.autoCompletionProperties(beforeMatched.to, beforeText); |
|
|
|
|
|
} else if (beforeText.endsWith(' ')) { |
|
|
|
|
|
//匹配参数
|
|
|
//匹配参数
|
|
|
return this.autoCompletionParameters(beforeMatched.to); |
|
|
return this.autoCompletionParameters(beforeMatched.to); |
|
|
|
|
|
} else if (beforeText.endsWith('.')) { |
|
|
|
|
|
//匹配所有属性
|
|
|
|
|
|
return this.autoCompletionProperties(beforeMatched.to, beforeText); |
|
|
} else { |
|
|
} else { |
|
|
return null; |
|
|
//匹配部分属性
|
|
|
|
|
|
const lastIndexOf = beforeText.lastIndexOf('.'); |
|
|
|
|
|
if (lastIndexOf > -1) { |
|
|
|
|
|
return this.autoCompletionProperties(beforeMatched.to, beforeText.substring(0, lastIndexOf + 1), beforeText.substring(lastIndexOf + 1)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public load(url: string) { |
|
|
public load(url: string) { |
|
|
axios.get(url).then((response) => { |
|
|
axios.get(url).then((response: any) => { |
|
|
this.setParameters(response.data?.parameters); |
|
|
this.setParameters(response.data?.parameters); |
|
|
this.setValueTypes(response.data?.valueTypes); |
|
|
this.setValueTypes(response.data?.valueTypes); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public autoCompletion(): any { |
|
|
public autoCompletion(): any { |
|
|
console.log('????'); |
|
|
|
|
|
return (context: any) => { |
|
|
return (context: any) => { |
|
|
return this.doAutoCompletion(context); |
|
|
return this.doAutoCompletion(context); |
|
|
}; |
|
|
}; |
|
|