|
@@ -9,7 +9,7 @@
|
|
|
<el-select v-model="form.IsMainIndex" placeholder="请选择指标显示的位置" size="small" class="inner_element_lr" style="width: 200px">
|
|
|
<el-option v-for="(i, index) in position" :key="`pos-${index}`" :label="i.label" :value="i.value"></el-option>
|
|
|
</el-select>
|
|
|
- <el-button type="primary" size="small">执行</el-button>
|
|
|
+ <el-button type="primary" size="small" @click="toTestCode">执行</el-button>
|
|
|
<el-button size="small" v-if="form.Script && form.Script.length > 0" @click="cleanScript">清空脚本</el-button>
|
|
|
<el-button type="success" size="small" @click="toSaveCommon">保存</el-button>
|
|
|
<el-link type="primary" @click="toHelp" class="inner_element_lr">函数帮助</el-link>
|
|
@@ -68,10 +68,10 @@ export default {
|
|
|
{ label: 'py脚本', value: '2' },
|
|
|
],
|
|
|
pararmsColumn: [
|
|
|
- { label: '参数名', model: 'label' },
|
|
|
- { label: '最小值', model: 'min' },
|
|
|
- { label: '最大值', model: 'max' },
|
|
|
- { label: '缺省值', model: 'def' },
|
|
|
+ { label: '参数名', model: 'Name' },
|
|
|
+ { label: '最小值', model: 'Min' },
|
|
|
+ { label: '最大值', model: 'Max' },
|
|
|
+ { label: '缺省值', model: 'Value' },
|
|
|
],
|
|
|
commonTrees: [],
|
|
|
form: {
|
|
@@ -85,18 +85,82 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
...common(['commonTree', 'create', 'update', 'delete']),
|
|
|
+ // 测试指标
|
|
|
+ toTestCode() {
|
|
|
+ const dup = _.cloneDeep(this.form);
|
|
|
+ let { Script, Args } = dup;
|
|
|
+ Args = Args.filter((f) => f.Name);
|
|
|
+ if (!Script) {
|
|
|
+ this.$message.error('请输入要执行的脚本');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let grammarRes = this.checkGrammar(Script);
|
|
|
+ if (!grammarRes) return;
|
|
|
+ let argsRes = this.checkUseArgs(Script, Args);
|
|
|
+ if (!argsRes) return;
|
|
|
+ let result = true;
|
|
|
+ JSComplier.Execute(Script, { Arguments: Args }, (e) => {
|
|
|
+ result = false;
|
|
|
+ const { Description, Column, Index, LineNumber } = e;
|
|
|
+ this.$message.error(`${Description}:位于 第${LineNumber}行,第${Column}个字符处需要修改`);
|
|
|
+ });
|
|
|
+ if (result) this.$message.success('执行成功');
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 检查语法
|
|
|
+ * @param {String} Script 脚本
|
|
|
+ * @return {Boolean} true:继续/false:中断
|
|
|
+ */
|
|
|
+ checkGrammar(Script) {
|
|
|
+ let res = true;
|
|
|
+ /**
|
|
|
+ * 转换成语法树,检验是否有写的错误.不过这个错误只能检测语法.
|
|
|
+ * 像是少个括号啥的,符号不对,能测出来.要是丢个乘号啊,少个参数啊,这都检查不出来,可能不符合要求,大概率要改
|
|
|
+ */
|
|
|
+ try {
|
|
|
+ const eRes = JSComplier.Parse(Script);
|
|
|
+ } catch (error) {
|
|
|
+ res = false;
|
|
|
+ const { LineNumber, Column } = error;
|
|
|
+ this.$message.error(`语法错误:位于 第${LineNumber}行,第${Column}个字符处需要修改`);
|
|
|
+ } finally {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 检查参数是否使用
|
|
|
+ * @param {String} Script 脚本
|
|
|
+ * @param {Array} args 参数数组
|
|
|
+ * @return {Boolean} true:继续/false:中断
|
|
|
+ */
|
|
|
+ checkUseArgs(Script, Args) {
|
|
|
+ let res = true;
|
|
|
+ /**
|
|
|
+ * 这个是把脚本拆开,符号,变量都统统拆开组合成一个数组
|
|
|
+ * 目前看来可以检测变量是否写错,参数是否错误或者有没用的
|
|
|
+ */
|
|
|
+ const wRes = JSComplier.Tokenize(Script);
|
|
|
+ const arr = [];
|
|
|
+ for (const arg of Args) {
|
|
|
+ const { Name } = arg;
|
|
|
+ const r = wRes.find((f) => f.Value === Name);
|
|
|
+ console.warn(r);
|
|
|
+ if (!r) arr.push(Name);
|
|
|
+ }
|
|
|
+ if (arr.length > 0) {
|
|
|
+ res = false;
|
|
|
+ const word = `参数: ${arr.join(',')} 未使用!`;
|
|
|
+ this.$message.error(word);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ // 选择指标
|
|
|
selectItem(item) {
|
|
|
- console.warn(item);
|
|
|
let dup = _.cloneDeep(item);
|
|
|
- dup.Args = dup.Args.map((i) => {
|
|
|
- const obj = {};
|
|
|
- obj.label = i.Name;
|
|
|
- obj.def = i.Value;
|
|
|
- return obj;
|
|
|
- });
|
|
|
dup.IsMainIndex = dup.IsMainIndex ? '1' : '0';
|
|
|
this.$set(this, 'form', dup);
|
|
|
},
|
|
|
+ //保存前的数据处理,校验
|
|
|
toSaveCommon() {
|
|
|
let dup = _.cloneDeep(this.form);
|
|
|
const checkDataRes = this.checkData(dup);
|
|
@@ -105,10 +169,10 @@ export default {
|
|
|
const obj = {};
|
|
|
const Args = _.get(dup, 'Args', []);
|
|
|
for (let i = 0; i < Args.length; i++) {
|
|
|
- const { label, min, max, def } = Args[i];
|
|
|
- if (!label || !def) continue;
|
|
|
- obj[`ArgsName${i + 1}`] = label;
|
|
|
- obj[`ArgsValue${i + 1}`] = def;
|
|
|
+ const { Name, Min, Max, Value } = Args[i];
|
|
|
+ if (!Name || !Value) continue;
|
|
|
+ obj[`ArgsName${i + 1}`] = Name;
|
|
|
+ obj[`ArgsValue${i + 1}`] = Value;
|
|
|
// TODO:min和max没处理
|
|
|
}
|
|
|
dup = { ...dup, ...obj };
|