Merge branch 'v1.3' of https://github.com/metersphere/metersphere into v1.3
This commit is contained in:
commit
95293a7377
|
@ -4,8 +4,10 @@ import io.metersphere.base.domain.ApiTestReport;
|
|||
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||
import io.metersphere.base.domain.SystemParameter;
|
||||
import io.metersphere.base.domain.TestCaseWithBLOBs;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
import io.metersphere.commons.constants.NoticeConstants;
|
||||
import io.metersphere.commons.constants.ParamConstants;
|
||||
import io.metersphere.commons.constants.PerformanceTestStatus;
|
||||
import io.metersphere.commons.utils.EncryptUtils;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
|
@ -46,12 +48,13 @@ public class MailService {
|
|||
context.put("title", "Performance" + Translator.get("timing_task_result_notification"));
|
||||
context.put("testName", loadTest.getName());
|
||||
context.put("id", loadTest.getId());
|
||||
context.put("type", "performance");
|
||||
context.put("url", baseSystemConfigDTO.getUrl());
|
||||
String performanceTemplate = "";
|
||||
try {
|
||||
if (status.equals("Completed")) {
|
||||
if (StringUtils.equals(status, PerformanceTestStatus.Completed.name())) {
|
||||
performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/successPerformance.html"), StandardCharsets.UTF_8);
|
||||
} else if (status.equals("Error")) {
|
||||
} else if (StringUtils.equals(status, PerformanceTestStatus.Error.name())) {
|
||||
performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/failPerformance.html"), StandardCharsets.UTF_8);
|
||||
}
|
||||
sendHtmlTimeTasks(noticeList, status, context, performanceTemplate);
|
||||
|
@ -65,14 +68,14 @@ public class MailService {
|
|||
Map<String, String> context = new HashMap<>();
|
||||
context.put("title", "api" + Translator.get("timing_task_result_notification"));
|
||||
context.put("testName", apiTestReport.getName());
|
||||
context.put("type", "Api");
|
||||
context.put("type", "api");
|
||||
context.put("url", baseSystemConfigDTO.getUrl());
|
||||
context.put("id", apiTestReport.getId());
|
||||
String apiTemplate = "";
|
||||
try {
|
||||
if (apiTestReport.getStatus().equals("Success")) {
|
||||
if (StringUtils.equals(APITestStatus.Success.name(), apiTestReport.getStatus())) {
|
||||
apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/success.html"), StandardCharsets.UTF_8);
|
||||
} else if (apiTestReport.getStatus().equals("Error")) {
|
||||
} else if (StringUtils.equals(APITestStatus.Error.name(), apiTestReport.getStatus())) {
|
||||
apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/fail.html"), StandardCharsets.UTF_8);
|
||||
}
|
||||
sendHtmlTimeTasks(noticeList, apiTestReport.getStatus(), context, apiTemplate);
|
||||
|
@ -183,17 +186,21 @@ public class MailService {
|
|||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
javaMailSender.setProtocol("smtps");
|
||||
for (SystemParameter p : paramList) {
|
||||
if (p.getParamKey().equals("smtp.host")) {
|
||||
javaMailSender.setHost(p.getParamValue());
|
||||
}
|
||||
if (p.getParamKey().equals("smtp.port")) {
|
||||
javaMailSender.setPort(Integer.parseInt(p.getParamValue()));
|
||||
}
|
||||
if (p.getParamKey().equals("smtp.account")) {
|
||||
javaMailSender.setUsername(p.getParamValue());
|
||||
}
|
||||
if (p.getParamKey().equals("smtp.password")) {
|
||||
javaMailSender.setPassword(EncryptUtils.aesDecrypt(p.getParamValue()).toString());
|
||||
switch (p.getParamKey()) {
|
||||
case "smtp.host":
|
||||
javaMailSender.setHost(p.getParamValue());
|
||||
break;
|
||||
case "smtp.port":
|
||||
javaMailSender.setPort(Integer.parseInt(p.getParamValue()));
|
||||
break;
|
||||
case "smtp.account":
|
||||
javaMailSender.setUsername(p.getParamValue());
|
||||
break;
|
||||
case "smtp.password":
|
||||
javaMailSender.setPassword(EncryptUtils.aesDecrypt(p.getParamValue()).toString());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Properties props = new Properties();
|
||||
|
@ -223,10 +230,10 @@ public class MailService {
|
|||
List<String> failEmailList = new ArrayList<>();
|
||||
if (noticeList.size() > 0) {
|
||||
for (NoticeDetail n : noticeList) {
|
||||
if (n.getEnable().equals("true") && n.getEvent().equals(NoticeConstants.EXECUTE_SUCCESSFUL)) {
|
||||
if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_SUCCESSFUL)) {
|
||||
successEmailList = userService.queryEmail(n.getNames());
|
||||
}
|
||||
if (n.getEnable().equals("true") && n.getEvent().equals(NoticeConstants.EXECUTE_FAILED)) {
|
||||
if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_FAILED)) {
|
||||
failEmailList = userService.queryEmail(n.getNames());
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +241,7 @@ public class MailService {
|
|||
LogUtil.error("Recipient information is empty");
|
||||
}
|
||||
|
||||
if (status.equals("Success") || status.equals("Completed")) {
|
||||
if (StringUtils.equalsAny(status, PerformanceTestStatus.Completed.name(), APITestStatus.Success.name())) {
|
||||
recipientEmails = successEmailList.toArray(new String[0]);
|
||||
} else {
|
||||
recipientEmails = failEmailList.toArray(new String[0]);
|
||||
|
|
|
@ -230,7 +230,7 @@ public class TestCaseNodeService {
|
|||
return list;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<TestCaseNodeDTO> getNodeDTO(String projectId, String planId) {
|
||||
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
|
||||
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(planId);
|
||||
|
@ -355,50 +355,45 @@ public class TestCaseNodeService {
|
|||
}
|
||||
|
||||
public Map<String, String> createNodeByTestCases(List<TestCaseWithBLOBs> testCases, String projectId) {
|
||||
|
||||
List<TestCaseNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId);
|
||||
|
||||
Map<String, String> pathMap = new HashMap<>();
|
||||
|
||||
List<String> nodePaths = testCases.stream()
|
||||
.map(TestCase::getNodePath)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
nodePaths.forEach(path -> {
|
||||
return this.createNodes(nodePaths, projectId);
|
||||
}
|
||||
|
||||
if (path == null) {
|
||||
public Map<String, String> createNodes(List<String> nodePaths, String projectId) {
|
||||
List<TestCaseNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId);
|
||||
Map<String, String> pathMap = new HashMap<>();
|
||||
for(String item : nodePaths){
|
||||
if (item == null) {
|
||||
throw new ExcelException(Translator.get("test_case_module_not_null"));
|
||||
}
|
||||
List<String> nodeNameList = new ArrayList<>(Arrays.asList(path.split("/")));
|
||||
Iterator<String> pathIterator = nodeNameList.iterator();
|
||||
|
||||
List<String> nodeNameList = new ArrayList<>(Arrays.asList(item.split("/")));
|
||||
Iterator<String> itemIterator = nodeNameList.iterator();
|
||||
Boolean hasNode = false;
|
||||
String rootNodeName = null;
|
||||
|
||||
if (nodeNameList.size() <= 1) {
|
||||
throw new ExcelException(Translator.get("test_case_create_module_fail") + ":" + path);
|
||||
throw new ExcelException(Translator.get("test_case_create_module_fail") + ":" + item);
|
||||
} else {
|
||||
pathIterator.next();
|
||||
pathIterator.remove();
|
||||
|
||||
rootNodeName = pathIterator.next().trim();
|
||||
itemIterator.next();
|
||||
itemIterator.remove();
|
||||
rootNodeName = itemIterator.next().trim();
|
||||
//原来没有,新建的树nodeTrees也不包含
|
||||
for (TestCaseNodeDTO nodeTree : nodeTrees) {
|
||||
if (StringUtils.equals(rootNodeName, nodeTree.getName())) {
|
||||
hasNode = true;
|
||||
createNodeByPathIterator(pathIterator, "/" + rootNodeName, nodeTree,
|
||||
createNodeByPathIterator(itemIterator, "/" + rootNodeName, nodeTree,
|
||||
pathMap, projectId, 2);
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!hasNode) {
|
||||
createNodeByPath(pathIterator, rootNodeName, null, projectId, 1, "", pathMap);
|
||||
createNodeByPath(itemIterator, rootNodeName, null, projectId, 1, "", pathMap);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
return pathMap;
|
||||
|
||||
}
|
||||
|
|
|
@ -284,6 +284,9 @@ public class TestCaseService {
|
|||
errList.add(excelErrData);
|
||||
excelResponse.setErrList(errList);
|
||||
} else {
|
||||
if (!xmindParser.getNodePaths().isEmpty()) {
|
||||
testCaseNodeService.createNodes(xmindParser.getNodePaths(), projectId);
|
||||
}
|
||||
if (!xmindParser.getTestCase().isEmpty()) {
|
||||
this.saveImportData(xmindParser.getTestCase(), projectId);
|
||||
xmindParser.clear();
|
||||
|
|
|
@ -40,6 +40,9 @@ public class XmindCaseParser {
|
|||
// 案例详情重写了hashCode方法去重用
|
||||
private List<TestCaseExcelData> compartDatas;
|
||||
|
||||
// 记录没有用例的目录
|
||||
private List<String> nodePaths;
|
||||
|
||||
public XmindCaseParser(TestCaseService testCaseService, String userId, String projectId, Set<String> testCaseNames) {
|
||||
this.testCaseService = testCaseService;
|
||||
this.maintainer = userId;
|
||||
|
@ -48,6 +51,7 @@ public class XmindCaseParser {
|
|||
testCases = new LinkedList<>();
|
||||
compartDatas = new ArrayList<>();
|
||||
process = new StringBuffer();
|
||||
nodePaths = new ArrayList<>();
|
||||
}
|
||||
|
||||
// 这里清理是为了 加快jvm 回收
|
||||
|
@ -55,26 +59,55 @@ public class XmindCaseParser {
|
|||
compartDatas.clear();
|
||||
testCases.clear();
|
||||
testCaseNames.clear();
|
||||
nodePaths.clear();
|
||||
}
|
||||
|
||||
public List<TestCaseWithBLOBs> getTestCase() {
|
||||
return this.testCases;
|
||||
}
|
||||
|
||||
public List<String> getNodePaths() {
|
||||
return this.nodePaths;
|
||||
}
|
||||
|
||||
private final Map<String, String> caseTypeMap = ImmutableMap.of("功能测试", "functional", "性能测试", "performance", "接口测试", "api");
|
||||
|
||||
public void validate() {
|
||||
nodePaths.forEach(nodePath -> {
|
||||
String[] nodes = nodePath.split("/");
|
||||
if (nodes.length > TestCaseConstants.MAX_NODE_DEPTH + 1) {
|
||||
process.append(Translator.get("test_case_node_level_tip") +
|
||||
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level") + "; ");
|
||||
}
|
||||
for (int i = 0; i < nodes.length; i++) {
|
||||
if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) {
|
||||
process.append(Translator.get("module_not_null") + "; ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 递归处理案例数据
|
||||
private void recursion(StringBuffer processBuffer, Attached parent, int level, String nodePath, List<Attached> attacheds) {
|
||||
private void recursion(StringBuffer processBuffer, Attached parent, int level, List<Attached> attacheds) {
|
||||
for (Attached item : attacheds) {
|
||||
if (isAvailable(item.getTitle(), "(?:tc:|tc:|tc)")) { // 用例
|
||||
item.setParent(parent);
|
||||
this.newTestCase(item.getTitle(), parent.getPath(), item.getChildren() != null ? item.getChildren().getAttached() : null);
|
||||
} else {
|
||||
nodePath = parent.getPath() + "/" + item.getTitle();
|
||||
String nodePath = parent.getPath() + "/" + item.getTitle();
|
||||
item.setPath(nodePath);
|
||||
item.setParent(parent);
|
||||
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
|
||||
item.setParent(parent);
|
||||
recursion(processBuffer, item, level + 1, nodePath, item.getChildren().getAttached());
|
||||
recursion(processBuffer, item, level + 1, item.getChildren().getAttached());
|
||||
} else {
|
||||
if (!nodePath.startsWith("/")) {
|
||||
nodePath = "/" + nodePath;
|
||||
}
|
||||
if (nodePath.endsWith("/")) {
|
||||
nodePath = nodePath.substring(0, nodePath.length() - 1);
|
||||
}
|
||||
nodePaths.add(nodePath); // 没有用例的路径
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -243,11 +276,12 @@ public class XmindCaseParser {
|
|||
item.setPath(item.getTitle());
|
||||
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
|
||||
item.setPath(item.getTitle());
|
||||
recursion(processBuffer, item, 1, item.getPath(), item.getChildren().getAttached());
|
||||
recursion(processBuffer, item, 1, item.getChildren().getAttached());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.validate();
|
||||
} catch (Exception ex) {
|
||||
processBuffer.append(Translator.get("incorrect_format"));
|
||||
LogUtil.error(ex.getMessage());
|
||||
|
|
|
@ -1,272 +1,283 @@
|
|||
<template>
|
||||
<el-dialog :close-on-click-modal="false" width="60%" class="schedule-edit" :visible.sync="dialogVisible"
|
||||
@close="close">
|
||||
<template>
|
||||
<div>
|
||||
<el-tabs v-model="activeName" @tab-click="handleClick">
|
||||
<el-dialog :close-on-click-modal="false" width="60%" class="schedule-edit" :visible.sync="dialogVisible"
|
||||
@close="close">
|
||||
<template>
|
||||
<div>
|
||||
<el-tabs v-model="activeName" @tab-click="handleClick">
|
||||
|
||||
<el-tab-pane :label="$t('schedule.edit_timer_task')" name="first">
|
||||
<el-form :model="form" :rules="rules" ref="from">
|
||||
<el-form-item
|
||||
prop="cronValue">
|
||||
<el-input :disabled="isReadOnly" v-model="form.cronValue" class="inp"
|
||||
:placeholder="$t('schedule.please_input_cron_expression')"/>
|
||||
<!-- <el-button type="primary" @click="showCronDialog">{{$t('schedule.generate_expression')}}</el-button>-->
|
||||
<el-button :disabled="isReadOnly" type="primary" @click="saveCron">{{ $t('commons.save') }}</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-link :disabled="isReadOnly" type="primary" @click="showCronDialog">
|
||||
{{ $t('schedule.generate_expression') }}
|
||||
</el-link>
|
||||
</el-form-item>
|
||||
<crontab-result :ex="form.cronValue" ref="crontabResult"/>
|
||||
</el-form>
|
||||
<el-dialog width="60%" :title="$t('schedule.generate_expression')" :visible.sync="showCron" :modal="false">
|
||||
<crontab @hide="showCron=false" @fill="crontabFill" :expression="schedule.value" ref="crontab"/>
|
||||
</el-dialog>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="$t('schedule.task_notification')" name="second">
|
||||
<template>
|
||||
<el-table
|
||||
:data="tableData"
|
||||
style="width: 100%">
|
||||
<el-table-column
|
||||
prop="event"
|
||||
:label="$t('schedule.event')">
|
||||
<template v-slot:default="{row}">
|
||||
<span v-if="row.event === 'EXECUTE_SUCCESSFUL'"> {{ $t('schedule.event_success') }}</span>
|
||||
<span v-else-if="row.event === 'EXECUTE_FAILED'"> {{ $t('schedule.event_failed') }}</span>
|
||||
<span v-else>{{ row.event }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="name"
|
||||
:label="$t('schedule.receiver')"
|
||||
width="200"
|
||||
>
|
||||
<template v-slot:default="{row}">
|
||||
<el-select v-model="row.names" filterable multiple :placeholder="$t('commons.please_select')"
|
||||
@click.native="userList()">
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.name">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="type"
|
||||
:label="$t('schedule.receiving_mode')"
|
||||
>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
:label="$t('test_resource_pool.enable_disable')"
|
||||
prop="enable"
|
||||
>
|
||||
<template v-slot:default="{row}">
|
||||
<el-switch
|
||||
v-model="row.enable"
|
||||
active-value="true"
|
||||
inactive-value="false"
|
||||
inactive-color="#DCDFE6"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div style="padding-top: 20px;">
|
||||
<el-button type="primary" @click="saveNotice">{{ $t('commons.save') }}</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
<el-tab-pane :label="$t('schedule.edit_timer_task')" name="first">
|
||||
<el-form :model="form" :rules="rules" ref="from">
|
||||
<el-form-item
|
||||
prop="cronValue">
|
||||
<el-input :disabled="isReadOnly" v-model="form.cronValue" class="inp"
|
||||
:placeholder="$t('schedule.please_input_cron_expression')"/>
|
||||
<!-- <el-button type="primary" @click="showCronDialog">{{$t('schedule.generate_expression')}}</el-button>-->
|
||||
<el-button :disabled="isReadOnly" type="primary" @click="saveCron">{{ $t('commons.save')
|
||||
}}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-link :disabled="isReadOnly" type="primary" @click="showCronDialog">
|
||||
{{ $t('schedule.generate_expression') }}
|
||||
</el-link>
|
||||
</el-form-item>
|
||||
<crontab-result :ex="form.cronValue" ref="crontabResult"/>
|
||||
</el-form>
|
||||
<el-dialog width="60%" :title="$t('schedule.generate_expression')" :visible.sync="showCron"
|
||||
:modal="false">
|
||||
<crontab @hide="showCron=false" @fill="crontabFill" :expression="schedule.value"
|
||||
ref="crontab"/>
|
||||
</el-dialog>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="$t('schedule.task_notification')" name="second">
|
||||
<template>
|
||||
<el-table
|
||||
:data="tableData"
|
||||
style="width: 100%">
|
||||
<el-table-column
|
||||
prop="event"
|
||||
:label="$t('schedule.event')">
|
||||
<template v-slot:default="{row}">
|
||||
<span v-if="row.event === 'EXECUTE_SUCCESSFUL'"> {{ $t('schedule.event_success') }}</span>
|
||||
<span v-else-if="row.event === 'EXECUTE_FAILED'"> {{ $t('schedule.event_failed') }}</span>
|
||||
<span v-else>{{ row.event }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="name"
|
||||
:label="$t('schedule.receiver')"
|
||||
width="240"
|
||||
>
|
||||
<template v-slot:default="{row}">
|
||||
<el-select v-model="row.names" filterable multiple
|
||||
:placeholder="$t('commons.please_select')"
|
||||
@click.native="userList()" style="width: 100%;">
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.name">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="type"
|
||||
:label="$t('schedule.receiving_mode')"
|
||||
>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
:label="$t('test_resource_pool.enable_disable')"
|
||||
prop="enable"
|
||||
>
|
||||
<template v-slot:default="{row}">
|
||||
<el-switch
|
||||
v-model="row.enable"
|
||||
active-value="true"
|
||||
inactive-value="false"
|
||||
inactive-color="#DCDFE6"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div style="padding-top: 20px;">
|
||||
<el-button type="primary" @click="saveNotice">{{ $t('commons.save') }}</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import Crontab from "../cron/Crontab";
|
||||
import CrontabResult from "../cron/CrontabResult";
|
||||
import {cronValidate} from "@/common/js/cron";
|
||||
import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
|
||||
import Crontab from "../cron/Crontab";
|
||||
import CrontabResult from "../cron/CrontabResult";
|
||||
import {cronValidate} from "@/common/js/cron";
|
||||
import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
|
||||
|
||||
function defaultCustomValidate() {
|
||||
return {pass: true};
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "MsScheduleEdit",
|
||||
components: {CrontabResult, Crontab},
|
||||
props: {
|
||||
testId: String,
|
||||
save: Function,
|
||||
schedule: {},
|
||||
customValidate: {
|
||||
type: Function,
|
||||
default: defaultCustomValidate
|
||||
},
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
watch: {
|
||||
'schedule.value'() {
|
||||
this.form.cronValue = this.schedule.value;
|
||||
function defaultCustomValidate() {
|
||||
return {pass: true};
|
||||
}
|
||||
},
|
||||
data() {
|
||||
const validateCron = (rule, cronValue, callback) => {
|
||||
let customValidate = this.customValidate(this.getIntervalTime());
|
||||
if (!cronValue) {
|
||||
callback(new Error(this.$t('commons.input_content')));
|
||||
} else if (!cronValidate(cronValue)) {
|
||||
callback(new Error(this.$t('schedule.cron_expression_format_error')));
|
||||
}
|
||||
// else if(!this.intervalShortValidate()) {
|
||||
// callback(new Error(this.$t('schedule.cron_expression_interval_short_error')));
|
||||
// }
|
||||
else if (!customValidate.pass) {
|
||||
callback(new Error(customValidate.info));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
return {
|
||||
operation: true,
|
||||
dialogVisible: false,
|
||||
showCron: false,
|
||||
form: {
|
||||
cronValue: ""
|
||||
},
|
||||
tableData: [
|
||||
{
|
||||
event: "EXECUTE_SUCCESSFUL",
|
||||
type: "EMAIL",
|
||||
names: [],
|
||||
enable: false
|
||||
|
||||
export default {
|
||||
name: "MsScheduleEdit",
|
||||
components: {CrontabResult, Crontab},
|
||||
props: {
|
||||
testId: String,
|
||||
save: Function,
|
||||
schedule: {},
|
||||
customValidate: {
|
||||
type: Function,
|
||||
default: defaultCustomValidate
|
||||
},
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
},
|
||||
{
|
||||
event: "EXECUTE_FAILED",
|
||||
type: "EMAIL",
|
||||
names: [],
|
||||
enable: false
|
||||
}
|
||||
],
|
||||
options: [{}],
|
||||
enable: true,
|
||||
type: "",
|
||||
activeName: 'first',
|
||||
rules: {
|
||||
cronValue: [{required: true, validator: validateCron, trigger: 'blur'}],
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
userList() {
|
||||
this.result = this.$get('user/list', response => {
|
||||
this.options = response.data
|
||||
})
|
||||
},
|
||||
handleClick() {
|
||||
if (this.activeName === "second") {
|
||||
this.result = this.$get('notice/query/' + this.testId, response => {
|
||||
if (response.data.length > 0) {
|
||||
this.tableData = response.data
|
||||
|
||||
this.tableData[0].event = "EXECUTE_SUCCESSFUL"
|
||||
this.tableData[0].type = "EMAIL"
|
||||
this.tableData[1].event = "EXECUTE_FAILED"
|
||||
this.tableData[1].type = "EMAIL"
|
||||
} else {
|
||||
this.tableData[0].names = []
|
||||
this.tableData[1].names = []
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
buildParam() {
|
||||
let param = {};
|
||||
param.notices = this.tableData
|
||||
param.testId = this.testId
|
||||
return param;
|
||||
},
|
||||
open() {
|
||||
this.dialogVisible = true;
|
||||
this.form.cronValue = this.schedule.value;
|
||||
listenGoBack(this.close);
|
||||
this.handleClick()
|
||||
this.activeName = 'first'
|
||||
},
|
||||
crontabFill(value, resultList) {
|
||||
//确定后回传的值
|
||||
this.form.cronValue = value;
|
||||
this.$refs.crontabResult.resultList = resultList;
|
||||
this.$refs['from'].validate();
|
||||
},
|
||||
showCronDialog() {
|
||||
this.showCron = true;
|
||||
},
|
||||
saveCron() {
|
||||
this.$refs['from'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.intervalShortValidate();
|
||||
this.save(this.form.cronValue);
|
||||
this.dialogVisible = false;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
watch: {
|
||||
'schedule.value'() {
|
||||
this.form.cronValue = this.schedule.value;
|
||||
}
|
||||
},
|
||||
data() {
|
||||
const validateCron = (rule, cronValue, callback) => {
|
||||
let customValidate = this.customValidate(this.getIntervalTime());
|
||||
if (!cronValue) {
|
||||
callback(new Error(this.$t('commons.input_content')));
|
||||
} else if (!cronValidate(cronValue)) {
|
||||
callback(new Error(this.$t('schedule.cron_expression_format_error')));
|
||||
}
|
||||
// else if(!this.intervalShortValidate()) {
|
||||
// callback(new Error(this.$t('schedule.cron_expression_interval_short_error')));
|
||||
// }
|
||||
else if (!customValidate.pass) {
|
||||
callback(new Error(customValidate.info));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
return {
|
||||
operation: true,
|
||||
dialogVisible: false,
|
||||
showCron: false,
|
||||
form: {
|
||||
cronValue: ""
|
||||
},
|
||||
tableData: [
|
||||
{
|
||||
event: "EXECUTE_SUCCESSFUL",
|
||||
type: "EMAIL",
|
||||
names: [],
|
||||
enable: false
|
||||
},
|
||||
{
|
||||
event: "EXECUTE_FAILED",
|
||||
type: "EMAIL",
|
||||
names: [],
|
||||
enable: false
|
||||
}
|
||||
],
|
||||
options: [{}],
|
||||
enable: true,
|
||||
type: "",
|
||||
activeName: 'first',
|
||||
rules: {
|
||||
cronValue: [{required: true, validator: validateCron, trigger: 'blur'}],
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
userList() {
|
||||
this.result = this.$get('user/list', response => {
|
||||
this.options = response.data
|
||||
})
|
||||
},
|
||||
handleClick() {
|
||||
if (this.activeName === "second") {
|
||||
this.result = this.$get('notice/query/' + this.testId, response => {
|
||||
if (response.data.length > 0) {
|
||||
this.tableData = response.data
|
||||
|
||||
this.tableData[0].event = "EXECUTE_SUCCESSFUL"
|
||||
this.tableData[0].type = "EMAIL"
|
||||
this.tableData[1].event = "EXECUTE_FAILED"
|
||||
this.tableData[1].type = "EMAIL"
|
||||
} else {
|
||||
this.tableData[0].names = []
|
||||
this.tableData[1].names = []
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
buildParam() {
|
||||
let param = {};
|
||||
param.notices = this.tableData
|
||||
param.testId = this.testId
|
||||
return param;
|
||||
},
|
||||
open() {
|
||||
this.dialogVisible = true;
|
||||
this.form.cronValue = this.schedule.value;
|
||||
listenGoBack(this.close);
|
||||
this.handleClick()
|
||||
this.activeName = 'first'
|
||||
},
|
||||
crontabFill(value, resultList) {
|
||||
//确定后回传的值
|
||||
this.form.cronValue = value;
|
||||
this.$refs.crontabResult.resultList = resultList;
|
||||
this.$refs['from'].validate();
|
||||
},
|
||||
showCronDialog() {
|
||||
this.showCron = true;
|
||||
},
|
||||
saveCron() {
|
||||
this.$refs['from'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.intervalShortValidate();
|
||||
this.save(this.form.cronValue);
|
||||
this.dialogVisible = false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
saveNotice() {
|
||||
let param = this.buildParam();
|
||||
this.result = this.$post("notice/save", param, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
})
|
||||
},
|
||||
close() {
|
||||
this.dialogVisible = false;
|
||||
this.form.cronValue = '';
|
||||
this.$refs['from'].resetFields();
|
||||
if (!this.schedule.value) {
|
||||
this.$refs.crontabResult.resultList = [];
|
||||
}
|
||||
removeGoBackListener(this.close);
|
||||
},
|
||||
intervalShortValidate() {
|
||||
if (this.getIntervalTime() < 3 * 60 * 1000) {
|
||||
// return false;
|
||||
this.$info(this.$t('schedule.cron_expression_interval_short_error'));
|
||||
}
|
||||
return true;
|
||||
},
|
||||
resultListChange() {
|
||||
this.$refs['from'].validate();
|
||||
},
|
||||
getIntervalTime() {
|
||||
let resultList = this.$refs.crontabResult.resultList;
|
||||
let time1 = new Date(resultList[0]);
|
||||
let time2 = new Date(resultList[1]);
|
||||
return time2 - time1;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
saveNotice() {
|
||||
let param = this.buildParam();
|
||||
this.result = this.$post("notice/save", param, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
})
|
||||
},
|
||||
close() {
|
||||
this.dialogVisible = false;
|
||||
this.form.cronValue = '';
|
||||
this.$refs['from'].resetFields();
|
||||
if (!this.schedule.value) {
|
||||
this.$refs.crontabResult.resultList = [];
|
||||
}
|
||||
removeGoBackListener(this.close);
|
||||
},
|
||||
intervalShortValidate() {
|
||||
if (this.getIntervalTime() < 3 * 60 * 1000) {
|
||||
// return false;
|
||||
this.$info(this.$t('schedule.cron_expression_interval_short_error'));
|
||||
}
|
||||
return true;
|
||||
},
|
||||
resultListChange() {
|
||||
this.$refs['from'].validate();
|
||||
},
|
||||
getIntervalTime() {
|
||||
let resultList = this.$refs.crontabResult.resultList;
|
||||
let time1 = new Date(resultList[0]);
|
||||
let time2 = new Date(resultList[1]);
|
||||
return time2 - time1;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
.inp {
|
||||
width: 50%;
|
||||
margin-right: 20px;
|
||||
}
|
||||
.inp {
|
||||
width: 50%;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.el-form-item {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
/deep/ .el-select__tags {
|
||||
flex-wrap: unset;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.el-form-item {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue