refactor: 自定义函数修改为自定义代码片段

This commit is contained in:
shiziyuan9527 2021-09-17 17:02:39 +08:00 committed by 刘瑞斌
parent 083bcfb077
commit 542be4d26d
11 changed files with 122 additions and 48 deletions

View File

@ -87,7 +87,7 @@ public class CustomFunctionService {
public void update(CustomFunctionRequest request) {
checkFuncExist(request);
request.setUpdateTime(System.currentTimeMillis());
customFunctionMapper.updateByPrimaryKeyWithBLOBs(request);
customFunctionMapper.updateByPrimaryKeySelective(request);
}
public CustomFunctionWithBLOBs copy(String id) {

View File

@ -38,20 +38,20 @@
jsr223ProcessorData: {},
codeTemplates: [
{
title: 'API测试',
title: this.$t('project.code_segment.api_test'),
children: [
{
title: '从API定义导入',
title: this.$t('project.code_segment.import_api_test'),
command: "api_definition",
},
{
title: '新API测试[JSON]',
title: this.$t('project.code_segment.new_api_test'),
command: "new_api_request",
}
]
},
{
title: '自定义变量',
title: this.$t('project.code_segment.custom_value'),
children: [
{
title: this.$t('api_test.request.processor.code_template_get_variable'),
@ -79,7 +79,7 @@
]
},
{
title: '项目环境',
title: this.$t('project.code_segment.project_env'),
children: [
{
title: this.$t('api_test.request.processor.param_environment_set_global_variable'),
@ -88,25 +88,25 @@
]
},
{
title: '自定义函数',
title: this.$t('project.code_segment.code_segment'),
children: [
{
title: "插入自定义函数",
title: this.$t('project.code_segment.insert_segment'),
command: "custom_function",
}
]
},
{
title: '异常处理',
title: this.$t('project.code_segment.exception_handle'),
children: [
{
title: "终止测试",
title: this.$t('project.code_segment.stop_test'),
value: 'ctx.getEngine().stopThreadNow(ctx.getThread().getThreadName())'
},
]
},
{
title: '报文处理',
title: this.$t('project.code_segment.report_handle'),
children: [
{
title: this.$t('api_test.request.processor.code_add_report_length'),

View File

@ -3,9 +3,9 @@
<el-card class="table-card">
<template v-slot:header>
<ms-table-header :show-create="false" :condition.sync="condition"
:title="'自定义函数'" @search="init" :tip="'根据 名称/标签 搜索'">
:title="$t('project.code_segment.code_segment')" @search="init" :tip="$t('project.code_segment.search')">
<template v-slot:button>
<ms-table-button icon="el-icon-circle-plus-outline" :content="'创建函数'" @click="handleCreate"/>
<ms-table-button icon="el-icon-circle-plus-outline" :content="$t('project.code_segment.create')" @click="handleCreate"/>
</template>
</ms-table-header>
</template>
@ -27,7 +27,7 @@
<span></span>
</template>
</el-table-column>
<el-table-column prop="type" :label="'脚本语言'" show-overflow-tooltip/>
<el-table-column prop="type" :label="$t('project.code_segment.language')" show-overflow-tooltip/>
<el-table-column prop="createTime"
:label="$t('commons.create_time')"
show-overflow-tooltip>
@ -52,7 +52,7 @@
</el-card>
<edit-function @refresh="init" ref="editFunction"/>
<ms-delete-confirm :title="'删除自定义函数'" @delete="_handleDel" ref="deleteConfirm"/>
<ms-delete-confirm :title="$t('project.code_segment.delete')" @delete="_handleDel" ref="deleteConfirm"/>
</div>

View File

@ -1,14 +1,14 @@
<template>
<el-dialog :close-on-click-modal="false" :title="'自定义函数'" :visible.sync="visible" :destroy-on-close="true"
<el-dialog :close-on-click-modal="false" :title="$t('project.code_segment.code_segment')" :visible.sync="visible" :destroy-on-close="true"
@close="close" width="60%" top="10vh" v-loading="result.loading" append-to-body class="customFunc">
<div>
<el-alert
title="在 系统设置->项目->自定义函数 菜单中创建函数"
:title="$t('project.code_segment.relate_tip')"
type="info"
style="width: 350px;float: left;"
:closable="false" show-icon>
</el-alert>
<ms-table-search-bar :condition.sync="condition" @change="init" class="search-bar" :tip="'根据 名称/标签 搜索'"/>
<ms-table-search-bar :condition.sync="condition" @change="init" class="search-bar" :tip="$t('project.code_segment.search')"/>
<el-table border class="adjust-table" :data="data" style="width: 100%" ref="table"
highlight-current-row @current-change="handleCurrentChange">
<el-table-column prop="name" :label="$t('commons.name')" show-overflow-tooltip/>
@ -25,7 +25,7 @@
<span></span>
</template>
</el-table-column>
<el-table-column prop="type" :label="'脚本语言'" show-overflow-tooltip/>
<el-table-column prop="type" :label="$t('project.code_segment.language')" show-overflow-tooltip/>
<el-table-column prop="createTime"
:label="$t('commons.create_time')"
show-overflow-tooltip>
@ -106,12 +106,12 @@ export default {
},
submit() {
if (!this.currentRow) {
this.$warning("请选择自定义函数!");
this.$warning(this.$t('project.code_segment.select_tip'));
return;
}
this.result = this.$get("/custom/func/get/" + this.currentRow.id, res => {
if (!res.data) {
this.$warning("函数为空!")
this.$warning(this.$t('project.code_segment.none_content'))
}
let {script} = res.data;
this.$emit("addCustomFuncScript", script);

View File

@ -35,7 +35,7 @@
<template v-slot>
<div style="position: relative;">
<el-tabs v-model="activeName">
<el-tab-pane :label="'函数编辑'" name="code">
<el-tab-pane :label="$t('project.code_segment.segment')" name="code">
<ms-code-edit
v-if="isCodeEditAlive"
:mode="codeEditModeMap[form.type]"
@ -45,7 +45,7 @@
:modes="modes"
ref="codeEdit"/>
</el-tab-pane>
<el-tab-pane :label="'执行结果'" name="result">
<el-tab-pane :label="$t('project.code_segment.result')" name="result">
<div v-loading="runResult.loading">
<ms-code-edit :mode="'text'" :data.sync="console" v-if="isResultAlive" height="330px"
ref="funcResult"/>
@ -53,7 +53,7 @@
</el-tab-pane>
</el-tabs>
<el-button type="primary" size="mini" style="width: 70px;position: absolute; right: 0;top:10px;" @click="handleTest"
:disabled="runResult.loading">测试
:disabled="runResult.loading">{{ $t('project.code_segment.test') }}
</el-button>
</div>
</template>
@ -123,8 +123,8 @@ export default {
reportId: "",
runData: [],
isStop: false,
dialogCreateTitle: "创建函数",
dialogUpdateTitle: "更新函数",
dialogCreateTitle: this.$t('project.code_segment.create'),
dialogUpdateTitle: this.$t('project.code_segment.update'),
activeName: 'code',
dialogTitle: "",
isCodeEditAlive: true,
@ -162,7 +162,7 @@ export default {
response: {},
request: {},
debug: true,
console: "无执行结果"
console: this.$t('project.code_segment.no_result')
}
},
methods: {
@ -198,7 +198,7 @@ export default {
type: "beanshell",
params: [{}]
};
this.console = "无执行结果";
this.console = this.$t('project.code_segment.no_result');
this.visible = false;
},
languageChange(language) {
@ -253,6 +253,7 @@ export default {
this.form.id = res.data.id;
}
this.$success(this.$t('commons.save_success'));
this.reload();
})
},
update(obj) {
@ -262,11 +263,12 @@ export default {
this.result = this.$post("/custom/func/update", obj, () => {
this.$emit("refresh");
this.$success(this.$t('commons.modify_success'));
this.reload();
})
},
handleTest() {
this.activeName = "result";
this.console = "无执行结果";
this.console = this.$t('project.code_segment.no_result');
this.reloadResult();
this.runResult.loading = true;
let jSR223Processor = new JSR223Processor({

View File

@ -1,9 +1,9 @@
export const FUNC_TEMPLATE = {
beanshell: "public void test() {\n\n\n}",
groovy: "def test() {\n\n\n}",
python: "def test():\n",
nashornScript: "function test() {\n\n\n}",
rhinoScript: "function test() {\n\n\n}"
beanshell: "",
groovy: "",
python: "",
nashornScript: "",
rhinoScript: ""
}
export function getCodeTemplate(language, requestObj) {

View File

@ -1,20 +1,20 @@
import i18n from "@/i18n/i18n";
export const SCRIPT_MENU = [
{
title: 'API测试',
title: i18n.t('project.code_segment.api_test'),
children: [
{
title: '从API定义导入',
title: i18n.t('project.code_segment.import_api_test'),
command: "api_definition",
},
{
title: '新API测试[JSON]',
title: i18n.t('project.code_segment.new_api_test'),
command: "new_api_request",
}
]
},
{
title: '自定义变量',
title: i18n.t('project.code_segment.custom_value'),
children: [
{
title: i18n.t('api_test.request.processor.code_template_get_variable'),
@ -39,7 +39,7 @@ export const SCRIPT_MENU = [
]
},
{
title: '项目环境',
title: i18n.t('project.code_segment.project_env'),
children: [
{
title: i18n.t('api_test.request.processor.param_environment_set_global_variable'),
@ -48,25 +48,25 @@ export const SCRIPT_MENU = [
]
},
{
title: '自定义函数',
title: i18n.t('project.code_segment.code_segment'),
children: [
{
title: "插入自定义函数",
title: i18n.t('project.code_segment.insert_segment'),
command: "custom_function",
}
]
},
{
title: '异常处理',
title: i18n.t('project.code_segment.exception_handle'),
children: [
{
title: "终止测试",
title: i18n.t('project.code_segment.stop_test'),
value: 'ctx.getEngine().stopThreadNow(ctx.getThread().getThreadName())'
},
]
},
{
title: '报文处理',
title: i18n.t('project.code_segment.report_handle'),
children: [
{
title: i18n.t('api_test.request.processor.code_add_report_length'),

View File

@ -161,7 +161,7 @@ export default {
{
path: 'function',
component: () => import('@/business/components/settings/project/function/CustomFunction'),
meta: {project: true, title: '自定义函数'}
meta: {project: true, title: 'project.code_segment.code_segment'}
}
]
};

View File

@ -507,7 +507,31 @@ export default {
no_data: 'No Data',
select: 'Select',
repeatable: 'Interface definition URL repeatable',
upload_file_again: 'Upload again'
upload_file_again: 'Upload again',
code_segment: {
code_segment: "Custom Code",
search: "Search by name/tag",
create: "Create Custom Code",
update: "Update Custom Code",
delete: "Delete Custom Code",
language: "language",
relate_tip: "Create in the System Settings -> Project -> Custom Code Snippet menu",
select_tip: "Please select a custom code!",
none_content: "The custom code snippet is empty",
segment: "code segment",
result: "Result",
test: "Run",
no_result: "No Result",
api_test: "API TEST",
import_api_test: "Import from API definition",
new_api_test: "New API test[JSON]",
custom_value: "Custom variable",
project_env: "Project environment",
insert_segment: "Insert custom code snippet",
exception_handle: "Exception handling",
stop_test: "Terminate the test",
report_handle: "Message processing"
}
},
member: {
create: 'Create',

View File

@ -511,7 +511,31 @@ export default {
no_data: '无数据',
select: '选择项目',
repeatable: '接口定义URL可重复',
upload_file_again: '重新上传'
upload_file_again: '重新上传',
code_segment: {
code_segment: "自定义代码片段",
search: "根据 名称/标签 搜索",
create: "创建代码片段",
update: "更新代码片段",
delete: "删除自定义代码片段",
language: "脚本语言",
relate_tip: "在 系统设置->项目->自定义代码片段 菜单中创建",
select_tip: "请选择自定义代码片段!",
none_content: "自定义代码片段为空!",
segment: "代码片段",
result: "执行结果",
test: "测试",
no_result: "无执行结果",
api_test: "API测试",
import_api_test: "从API定义导入",
new_api_test: "新API测试[JSON]",
custom_value: "自定义变量",
project_env: "项目环境",
insert_segment: "插入自定义代码片段",
exception_handle: "异常处理",
stop_test: "终止测试",
report_handle: "报文处理"
}
},
member: {
create: '添加成员',

View File

@ -511,7 +511,31 @@ export default {
no_data: '無數據',
select: '選擇項目',
repeatable: '接口定義URL可重復',
upload_file_again: '重新上傳'
upload_file_again: '重新上傳',
code_segment: {
code_segment: "自定義代碼片段",
search: "根據 名稱/標籤 搜索",
create: "創建代碼片段",
update: "更新代碼片段",
delete: "刪除自定義代碼片段",
language: "腳本語言",
relate_tip: "在 系統設置->項目->自定義代碼片段 菜單中創建",
select_tip: "請選擇自定義代碼片段!",
none_content: "自定義代碼片段為空!",
segment: "代碼片段",
result: "執行結果",
test: "測試",
no_result: "無執行結果",
api_test: "API測試",
import_api_test: "从API定义导入",
new_api_test: "新API測試[JSON]",
custom_value: "新API測試",
project_env: "項目環境",
insert_segment: "插入自定義代碼片段",
exception_handle: "異常處理",
stop_test: "終止測試",
report_handle: "報文處理"
}
},
member: {
create: '添加成員',