Merge branch 'master' of https://github.com/metersphere/metersphere
This commit is contained in:
commit
7093a8a921
|
@ -20,6 +20,7 @@ import io.metersphere.commons.utils.PageUtils;
|
|||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.request.QueryScheduleRequest;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.dto.ScheduleDao;
|
||||
import io.metersphere.performance.service.PerformanceTestService;
|
||||
import io.metersphere.service.CheckPermissionService;
|
||||
|
@ -104,7 +105,7 @@ public class APITestController {
|
|||
}
|
||||
|
||||
@PostMapping(value = "/schedule/create")
|
||||
public void createSchedule(@RequestBody Schedule request) {
|
||||
public void createSchedule(@RequestBody ScheduleRequest request) {
|
||||
apiTestService.createSchedule(request);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import io.metersphere.commons.constants.RoleConstants;
|
|||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
||||
import io.metersphere.track.request.testplan.FileOperationRequest;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
|
@ -149,7 +150,7 @@ public class ApiAutomationController {
|
|||
}
|
||||
|
||||
@PostMapping(value = "/schedule/create")
|
||||
public void createSchedule(@RequestBody Schedule request) {
|
||||
public void createSchedule(@RequestBody ScheduleRequest request) {
|
||||
apiAutomationService.createSchedule(request);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import io.metersphere.commons.utils.CronUtils;
|
|||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.service.CheckPermissionService;
|
||||
import io.metersphere.service.ScheduleService;
|
||||
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
||||
|
@ -156,7 +157,7 @@ public class ApiDefinitionController {
|
|||
|
||||
//定时任务创建
|
||||
@PostMapping(value = "/schedule/create")
|
||||
public void createSchedule(@RequestBody Schedule request) {
|
||||
public void createSchedule(@RequestBody ScheduleRequest request) {
|
||||
apiDefinitionService.createSchedule(request);
|
||||
}
|
||||
@PostMapping(value = "/schedule/update")
|
||||
|
|
|
@ -21,6 +21,7 @@ import io.metersphere.commons.constants.ScheduleType;
|
|||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.controller.request.QueryScheduleRequest;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.dto.ScheduleDao;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.job.sechedule.ApiTestJob;
|
||||
|
@ -328,12 +329,12 @@ public class APITestService {
|
|||
addOrUpdateApiTestCronJob(request);
|
||||
}
|
||||
|
||||
public void createSchedule(Schedule request) {
|
||||
public void createSchedule(ScheduleRequest request) {
|
||||
scheduleService.addSchedule(buildApiTestSchedule(request));
|
||||
addOrUpdateApiTestCronJob(request);
|
||||
}
|
||||
|
||||
private Schedule buildApiTestSchedule(Schedule request) {
|
||||
private Schedule buildApiTestSchedule(ScheduleRequest request) {
|
||||
Schedule schedule = scheduleService.buildApiTestSchedule(request);
|
||||
schedule.setJob(ApiTestJob.class.getName());
|
||||
schedule.setGroup(ScheduleGroup.API_TEST.name());
|
||||
|
|
|
@ -31,6 +31,7 @@ import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper;
|
|||
import io.metersphere.commons.constants.*;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.job.sechedule.ApiScenarioTestJob;
|
||||
import io.metersphere.job.sechedule.TestPlanTestJob;
|
||||
|
@ -717,7 +718,7 @@ public class ApiAutomationService {
|
|||
return apiScenarioMapper.selectByExampleWithBLOBs(example);
|
||||
}
|
||||
|
||||
public void createSchedule(Schedule request) {
|
||||
public void createSchedule(ScheduleRequest request) {
|
||||
Schedule schedule = scheduleService.buildApiTestSchedule(request);
|
||||
schedule.setJob(ApiScenarioTestJob.class.getName());
|
||||
schedule.setGroup(ScheduleGroup.API_SCENARIO_TEST.name());
|
||||
|
|
|
@ -28,6 +28,7 @@ import io.metersphere.base.mapper.ext.*;
|
|||
import io.metersphere.commons.constants.*;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.job.sechedule.SwaggerUrlImportJob;
|
||||
import io.metersphere.service.FileService;
|
||||
|
@ -702,7 +703,7 @@ public class ApiDefinitionService {
|
|||
}
|
||||
|
||||
/*swagger定时导入*/
|
||||
public void createSchedule(Schedule request) {
|
||||
public void createSchedule(ScheduleRequest request) {
|
||||
/*保存swaggerUrl*/
|
||||
SwaggerUrlProject swaggerUrlProject = new SwaggerUrlProject();
|
||||
swaggerUrlProject.setId(UUID.randomUUID().toString());
|
||||
|
|
|
@ -126,8 +126,14 @@ public class ApiTestCaseService {
|
|||
if (!CollectionUtils.isEmpty(userIds)) {
|
||||
Map<String, User> userMap = userService.queryNameByIds(userIds);
|
||||
apiTestCases.forEach(caseResult -> {
|
||||
caseResult.setCreateUser(userMap.get(caseResult.getCreateUserId()).getName());
|
||||
caseResult.setUpdateUser(userMap.get(caseResult.getUpdateUserId()).getName());
|
||||
User createUser = userMap.get(caseResult.getCreateUserId());
|
||||
if (createUser != null) {
|
||||
caseResult.setCreateUser(createUser.getName());
|
||||
}
|
||||
User updateUser = userMap.get(caseResult.getUpdateUserId());
|
||||
if (updateUser != null) {
|
||||
caseResult.setUpdateUser(updateUser.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,15 +33,4 @@ public class Schedule implements Serializable {
|
|||
private String customData;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//定时任务来源: 测试计划/测试场景
|
||||
private String scheduleFrom;
|
||||
|
||||
private String projectId;
|
||||
|
||||
private String moduleId;
|
||||
|
||||
private String modulePath;
|
||||
|
||||
private String modeId;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package io.metersphere.commons.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class RsaKey {
|
||||
|
||||
//公钥
|
||||
private String publicKey;
|
||||
|
||||
//私钥
|
||||
private String privateKey;
|
||||
|
||||
}
|
|
@ -0,0 +1,224 @@
|
|||
package io.metersphere.commons.utils;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.security.*;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
|
||||
public class RsaUtil {
|
||||
|
||||
public static final String CHARSET = "UTF-8";
|
||||
public static final String RSA_ALGORITHM = "RSA";
|
||||
|
||||
|
||||
/**
|
||||
* 创建RSA 公钥-私钥
|
||||
*/
|
||||
public static RsaKey createKeys() throws NoSuchAlgorithmException {
|
||||
return createKeys(1024);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建RSA 公钥-私钥
|
||||
*/
|
||||
public static RsaKey createKeys(int keySize) throws NoSuchAlgorithmException {
|
||||
//为RSA算法创建一个KeyPairGenerator对象
|
||||
KeyPairGenerator kpg = KeyPairGenerator.getInstance(RSA_ALGORITHM);
|
||||
|
||||
//初始化KeyPairGenerator对象,密钥长度
|
||||
kpg.initialize(keySize);
|
||||
//生成密匙对
|
||||
KeyPair keyPair = kpg.generateKeyPair();
|
||||
|
||||
//得到公钥
|
||||
Key publicKey = keyPair.getPublic();
|
||||
|
||||
String publicKeyStr = new String(Base64.encodeBase64(publicKey.getEncoded()));
|
||||
|
||||
//得到私钥
|
||||
Key privateKey = keyPair.getPrivate();
|
||||
String privateKeyStr = new String(Base64.encodeBase64(privateKey.getEncoded()));
|
||||
|
||||
RsaKey rsaKey = new RsaKey();
|
||||
rsaKey.setPublicKey(publicKeyStr);
|
||||
rsaKey.setPrivateKey(privateKeyStr);
|
||||
|
||||
return rsaKey;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 公钥加密
|
||||
*
|
||||
* @param originalText 原文
|
||||
* @param publicKey 公钥
|
||||
*/
|
||||
public static String publicEncrypt(String originalText, String publicKey) throws NoSuchAlgorithmException {
|
||||
RSAPublicKey rsaPublicKey = getPublicKey(publicKey);
|
||||
return publicEncrypt(originalText, rsaPublicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公钥解密
|
||||
*
|
||||
* @param cipherText 密文
|
||||
* @param publicKey 公钥
|
||||
*/
|
||||
public static String publicDecrypt(String cipherText, String publicKey) throws NoSuchAlgorithmException {
|
||||
RSAPublicKey rsaPublicKey = getPublicKey(publicKey);
|
||||
return publicDecrypt(cipherText, rsaPublicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私钥加密
|
||||
*
|
||||
* @param originalText 原文
|
||||
* @param privateKey 私钥
|
||||
*/
|
||||
public static String privateEncrypt(String originalText, String privateKey) throws NoSuchAlgorithmException {
|
||||
RSAPrivateKey rsaPrivateKey = getPrivateKey(privateKey);
|
||||
return privateEncrypt(originalText, rsaPrivateKey);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 私钥解密
|
||||
*
|
||||
* @param cipherText 密文
|
||||
* @param privateKey 私钥
|
||||
*/
|
||||
public static String privateDecrypt(String cipherText, String privateKey) throws NoSuchAlgorithmException {
|
||||
RSAPrivateKey rsaPrivateKey = getPrivateKey(privateKey);
|
||||
return privateDecrypt(cipherText, rsaPrivateKey);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 得到公钥
|
||||
*
|
||||
* @param publicKey 密钥字符串(经过base64编码)
|
||||
*/
|
||||
private static RSAPublicKey getPublicKey(String publicKey) throws NoSuchAlgorithmException {
|
||||
//通过X509编码的Key指令获得公钥对象
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
|
||||
|
||||
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(Base64.decodeBase64(publicKey));
|
||||
RSAPublicKey key = null;
|
||||
try {
|
||||
key = (RSAPublicKey) keyFactory.generatePublic(x509KeySpec);
|
||||
} catch (InvalidKeySpecException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 公钥加密
|
||||
*
|
||||
* @param originalText 原文
|
||||
* @param publicKey 公钥
|
||||
*/
|
||||
private static String publicEncrypt(String originalText, RSAPublicKey publicKey) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
return Base64.encodeBase64URLSafeString(rsaSplitCodec(cipher, Cipher.ENCRYPT_MODE, originalText.getBytes(CHARSET), publicKey.getModulus().bitLength()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("加密字符串[" + originalText + "]时遇到异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到私钥
|
||||
*
|
||||
* @param privateKey 密钥字符串(经过base64编码)
|
||||
*/
|
||||
private static RSAPrivateKey getPrivateKey(String privateKey) throws NoSuchAlgorithmException {
|
||||
//通过PKCS#8编码的Key指令获得私钥对象
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
|
||||
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey));
|
||||
RSAPrivateKey key = null;
|
||||
try {
|
||||
key = (RSAPrivateKey) keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
} catch (InvalidKeySpecException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 私钥解密
|
||||
*
|
||||
* @param cipherText 密文
|
||||
* @param privateKey 私钥
|
||||
*/
|
||||
|
||||
private static String privateDecrypt(String cipherText, RSAPrivateKey privateKey) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
return new String(rsaSplitCodec(cipher, Cipher.DECRYPT_MODE, Base64.decodeBase64(cipherText), privateKey.getModulus().bitLength()), CHARSET);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("解密字符串[" + cipherText + "]时遇到异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String privateEncrypt(String originalText, RSAPrivateKey privateKey) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
|
||||
return Base64.encodeBase64URLSafeString(rsaSplitCodec(cipher, Cipher.ENCRYPT_MODE, originalText.getBytes(CHARSET), privateKey.getModulus().bitLength()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("加密字符串[" + originalText + "]时遇到异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String publicDecrypt(String cipherText, RSAPublicKey publicKey) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
||||
cipher.init(Cipher.DECRYPT_MODE, publicKey);
|
||||
return new String(rsaSplitCodec(cipher, Cipher.DECRYPT_MODE, Base64.decodeBase64(cipherText), publicKey.getModulus().bitLength()), CHARSET);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("解密字符串[" + cipherText + "]时遇到异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] rsaSplitCodec(Cipher cipher, int opmode, byte[] datas, int keySize) {
|
||||
int maxBlock;
|
||||
if (opmode == Cipher.DECRYPT_MODE) {
|
||||
maxBlock = keySize / 8;
|
||||
} else {
|
||||
maxBlock = keySize / 8 - 11;
|
||||
}
|
||||
int offSet = 0;
|
||||
byte[] buff;
|
||||
int i = 0;
|
||||
try (
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream()
|
||||
) {
|
||||
while (datas.length > offSet) {
|
||||
if (datas.length - offSet > maxBlock) {
|
||||
buff = cipher.doFinal(datas, offSet, maxBlock);
|
||||
} else {
|
||||
buff = cipher.doFinal(datas, offSet, datas.length - offSet);
|
||||
}
|
||||
out.write(buff, 0, buff.length);
|
||||
i++;
|
||||
offSet = i * maxBlock;
|
||||
}
|
||||
return out.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("加解密阀值为[" + maxBlock + "]的数据时发生异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -46,6 +46,7 @@ public class ShiroUtils {
|
|||
|
||||
public static void ignoreCsrfFilter(Map<String, String> filterChainDefinitionMap) {
|
||||
filterChainDefinitionMap.put("/", "apikey, authc"); // 跳转到 / 不用校验 csrf
|
||||
filterChainDefinitionMap.put("/document", "apikey, authc"); // 跳转到 /document 不用校验 csrf
|
||||
}
|
||||
|
||||
public static Cookie getSessionIdCookie(){
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package io.metersphere.config;
|
||||
|
||||
import io.metersphere.commons.utils.RsaKey;
|
||||
import io.metersphere.commons.utils.RsaUtil;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@Configuration
|
||||
public class RsaConfig {
|
||||
@Bean
|
||||
public RsaKey rsaKey() throws NoSuchAlgorithmException {
|
||||
return RsaUtil.createKeys();
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@ package io.metersphere.controller;
|
|||
|
||||
import io.metersphere.commons.constants.UserSource;
|
||||
import io.metersphere.commons.user.SessionUser;
|
||||
import io.metersphere.commons.utils.RsaKey;
|
||||
import io.metersphere.commons.utils.RsaUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.request.LoginRequest;
|
||||
import io.metersphere.service.BaseDisplayService;
|
||||
|
@ -23,6 +25,8 @@ public class LoginController {
|
|||
private UserService userService;
|
||||
@Resource
|
||||
private BaseDisplayService baseDisplayService;
|
||||
@Resource
|
||||
private RsaKey rsaKey;
|
||||
|
||||
@GetMapping(value = "/isLogin")
|
||||
public ResultHolder isLogin() {
|
||||
|
@ -33,7 +37,7 @@ public class LoginController {
|
|||
}
|
||||
return ResultHolder.success(user);
|
||||
}
|
||||
return ResultHolder.error("");
|
||||
return ResultHolder.error(rsaKey.getPublicKey());
|
||||
}
|
||||
|
||||
@PostMapping(value = "/signin")
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
|
|||
import io.metersphere.api.service.ApiAutomationService;
|
||||
import io.metersphere.base.domain.Schedule;
|
||||
import io.metersphere.controller.request.QueryScheduleRequest;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.dto.ScheduleDao;
|
||||
import io.metersphere.service.ScheduleService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -38,7 +39,7 @@ public class ScheduleController {
|
|||
}
|
||||
|
||||
@PostMapping(value = "/create")
|
||||
public void createSchedule(@RequestBody Schedule request) {
|
||||
public void createSchedule(@RequestBody ScheduleRequest request) {
|
||||
scheduleService.createSchedule(request);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,36 @@
|
|||
package io.metersphere.controller.request;
|
||||
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.RsaKey;
|
||||
import io.metersphere.commons.utils.RsaUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class LoginRequest {
|
||||
private String username;
|
||||
private String password;
|
||||
private String authenticate;
|
||||
|
||||
|
||||
public String getUsername() {
|
||||
try {
|
||||
RsaKey rsaKey = CommonBeanFactory.getBean(RsaKey.class);
|
||||
return RsaUtil.privateDecrypt(username, rsaKey.getPrivateKey());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return username;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
try {
|
||||
RsaKey rsaKey = CommonBeanFactory.getBean(RsaKey.class);
|
||||
return RsaUtil.privateDecrypt(password, rsaKey.getPrivateKey());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package io.metersphere.controller.request;
|
||||
|
||||
import io.metersphere.base.domain.Schedule;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/12 12:57 下午
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ScheduleRequest extends Schedule {
|
||||
|
||||
//定时任务来源: 测试计划/测试场景
|
||||
private String scheduleFrom;
|
||||
|
||||
private String projectId;
|
||||
|
||||
private String moduleId;
|
||||
|
||||
private String modulePath;
|
||||
|
||||
private String modeId;
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ import io.metersphere.commons.utils.PageUtils;
|
|||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.request.QueryScheduleRequest;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.dto.DashboardTestDTO;
|
||||
import io.metersphere.dto.LoadTestDTO;
|
||||
import io.metersphere.dto.ScheduleDao;
|
||||
|
@ -175,7 +176,7 @@ public class PerformanceTestController {
|
|||
}
|
||||
|
||||
@PostMapping(value = "/schedule/create")
|
||||
public void createSchedule(@RequestBody Schedule request) {
|
||||
public void createSchedule(@RequestBody ScheduleRequest request) {
|
||||
performanceTestService.createSchedule(request);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,12 +103,18 @@ public class DockerTestEngine extends AbstractEngine {
|
|||
startTestRequest.setEnv(env);
|
||||
|
||||
String uri = String.format(BASE_URL + "/jmeter/container/start", nodeIp, port);
|
||||
ResultHolder result = restTemplate.postForObject(uri, startTestRequest, ResultHolder.class);
|
||||
if (result == null) {
|
||||
MSException.throwException(Translator.get("start_engine_fail"));
|
||||
}
|
||||
if (!result.isSuccess()) {
|
||||
MSException.throwException(result.getMessage());
|
||||
try {
|
||||
ResultHolder result = restTemplate.postForObject(uri, startTestRequest, ResultHolder.class);
|
||||
if (result == null) {
|
||||
MSException.throwException(Translator.get("start_engine_fail"));
|
||||
}
|
||||
if (!result.isSuccess()) {
|
||||
MSException.throwException(result.getMessage());
|
||||
}
|
||||
} catch (MSException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
MSException.throwException("Please check node-controller status.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import io.metersphere.commons.utils.SessionUtils;
|
|||
import io.metersphere.config.KafkaProperties;
|
||||
import io.metersphere.controller.request.OrderRequest;
|
||||
import io.metersphere.controller.request.QueryScheduleRequest;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.dto.DashboardTestDTO;
|
||||
import io.metersphere.dto.LoadTestDTO;
|
||||
import io.metersphere.dto.ScheduleDao;
|
||||
|
@ -465,12 +466,12 @@ public class PerformanceTestService {
|
|||
addOrUpdatePerformanceTestCronJob(request);
|
||||
}
|
||||
|
||||
public void createSchedule(Schedule request) {
|
||||
public void createSchedule(ScheduleRequest request) {
|
||||
scheduleService.addSchedule(buildPerformanceTestSchedule(request));
|
||||
addOrUpdatePerformanceTestCronJob(request);
|
||||
}
|
||||
|
||||
private Schedule buildPerformanceTestSchedule(Schedule request) {
|
||||
private Schedule buildPerformanceTestSchedule(ScheduleRequest request) {
|
||||
Schedule schedule = scheduleService.buildApiTestSchedule(request);
|
||||
schedule.setJob(PerformanceTestJob.class.getName());
|
||||
schedule.setGroup(ScheduleGroup.PERFORMANCE_TEST.name());
|
||||
|
|
|
@ -17,6 +17,7 @@ import io.metersphere.commons.utils.ServiceUtils;
|
|||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.request.OrderRequest;
|
||||
import io.metersphere.controller.request.QueryScheduleRequest;
|
||||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.dto.ScheduleDao;
|
||||
import io.metersphere.job.sechedule.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -143,7 +144,7 @@ public class ScheduleService {
|
|||
});
|
||||
}
|
||||
|
||||
public Schedule buildApiTestSchedule(Schedule request) {
|
||||
public Schedule buildApiTestSchedule(ScheduleRequest request) {
|
||||
Schedule schedule = new Schedule();
|
||||
schedule.setResourceId(request.getResourceId());
|
||||
schedule.setEnable(true);
|
||||
|
@ -218,7 +219,7 @@ public class ScheduleService {
|
|||
return runningTaskInfoList;
|
||||
}
|
||||
|
||||
public void createSchedule(Schedule request) {
|
||||
public void createSchedule(ScheduleRequest request) {
|
||||
Schedule schedule = this.buildApiTestSchedule(request);
|
||||
schedule.setJob(ApiScenarioTestJob.class.getName());
|
||||
|
||||
|
|
|
@ -78,14 +78,19 @@ alter table test_case
|
|||
|
||||
alter table test_case
|
||||
add demand_name varchar(999) null;
|
||||
alter table test_case
|
||||
add follow_people varchar(100) null;
|
||||
-- test_case_review add column
|
||||
ALTER TABLE test_case_review ADD tags VARCHAR(2000) NULL;
|
||||
ALTER TABLE test_case_review
|
||||
ADD tags VARCHAR(2000) NULL;
|
||||
|
||||
-- alter test_plan_api_scenario
|
||||
alter table test_plan_api_scenario change environment_id environment longtext null comment 'Relevance environment';
|
||||
alter table test_plan_api_scenario
|
||||
change environment_id environment longtext null comment 'Relevance environment';
|
||||
|
||||
-- file add sort column
|
||||
alter table file_metadata add sort int default 0;
|
||||
alter table file_metadata
|
||||
add sort int default 0;
|
||||
|
||||
-- add Original state
|
||||
alter table api_definition add original_state varchar(64);
|
||||
|
|
|
@ -49,7 +49,8 @@
|
|||
"xml-js": "^1.6.11",
|
||||
"yan-progress": "^1.0.3",
|
||||
"jsonpath": "^1.1.0",
|
||||
"vue-minder-editor-plus": "^1.0.14"
|
||||
"vue-minder-editor-plus": "^1.0.16",
|
||||
"jsencrypt": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "^4.1.0",
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<template>
|
||||
<ms-module-minder
|
||||
:tree-nodes="treeNodes"/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MsModuleMinder from "@/business/components/common/components/MsModuleMinder";
|
||||
export default {
|
||||
name: "TestCaseMinder",
|
||||
components: {MsModuleMinder},
|
||||
data() {
|
||||
return{
|
||||
testCase: [],
|
||||
dataMap: new Map()
|
||||
}
|
||||
},
|
||||
props: {
|
||||
treeNodes: {
|
||||
type: Array,
|
||||
default() {
|
||||
return []
|
||||
}
|
||||
},
|
||||
condition: Object,
|
||||
projectId: String
|
||||
},
|
||||
mounted() {
|
||||
// this.getTestCases();
|
||||
},
|
||||
methods: {
|
||||
getTestCases() {
|
||||
if (this.projectId) {
|
||||
this.result = this.$get('/test/case/list/detail/' + this.projectId,response => {
|
||||
this.testCase = response.data;
|
||||
console.log(this.testCase)
|
||||
this.parse();
|
||||
});
|
||||
}
|
||||
},
|
||||
parse() {
|
||||
this.testCase.forEach(item => {
|
||||
let mapItem = this.dataMap.get(item.moduleId);
|
||||
let nodeItem = {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
|
||||
}
|
||||
if (mapItem) {
|
||||
mapItem.push(item);
|
||||
} else {
|
||||
mapItem = [];
|
||||
mapItem.push(item);
|
||||
}
|
||||
if (item.tags && item.tags.length > 0) {
|
||||
item.tags = JSON.parse(item.tags);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
|
@ -1,25 +0,0 @@
|
|||
<template>
|
||||
<ms-module-minder
|
||||
:tree-nodes="treeNodes"/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MsModuleMinder from "@/business/components/common/components/MsModuleMinder";
|
||||
export default {
|
||||
name: "TestcaseMinder",
|
||||
components: {MsModuleMinder},
|
||||
props: {
|
||||
treeNodes: {
|
||||
type: Array,
|
||||
default() {
|
||||
return []
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
|
@ -1,366 +1,378 @@
|
|||
import {
|
||||
COUNT_NUMBER, COUNT_NUMBER_SHALLOW,
|
||||
LicenseKey, ORIGIN_COLOR, ORIGIN_COLOR_SHALLOW,
|
||||
PROJECT_ID,
|
||||
REFRESH_SESSION_USER_URL,
|
||||
ROLE_ADMIN,
|
||||
ROLE_ORG_ADMIN,
|
||||
ROLE_TEST_MANAGER,
|
||||
ROLE_TEST_USER,
|
||||
ROLE_TEST_VIEWER,
|
||||
TokenKey
|
||||
COUNT_NUMBER,
|
||||
COUNT_NUMBER_SHALLOW,
|
||||
LicenseKey,
|
||||
ORIGIN_COLOR,
|
||||
ORIGIN_COLOR_SHALLOW,
|
||||
PROJECT_ID,
|
||||
REFRESH_SESSION_USER_URL,
|
||||
ROLE_ADMIN,
|
||||
ROLE_ORG_ADMIN,
|
||||
ROLE_TEST_MANAGER,
|
||||
ROLE_TEST_USER,
|
||||
ROLE_TEST_VIEWER,
|
||||
TokenKey
|
||||
} from "./constants";
|
||||
import axios from "axios";
|
||||
import {jsPDF} from "jspdf";
|
||||
import JSEncrypt from 'jsencrypt';
|
||||
|
||||
export function hasRole(role) {
|
||||
let user = getCurrentUser();
|
||||
let roles = user.roles.map(r => r.id);
|
||||
return roles.indexOf(role) > -1;
|
||||
let user = getCurrentUser();
|
||||
let roles = user.roles.map(r => r.id);
|
||||
return roles.indexOf(role) > -1;
|
||||
}
|
||||
|
||||
// 是否含有某个角色
|
||||
export function hasRoles(...roles) {
|
||||
let user = getCurrentUser();
|
||||
let rs = user.roles.map(r => r.id);
|
||||
for (let item of roles) {
|
||||
if (rs.indexOf(item) > -1) {
|
||||
return true;
|
||||
let user = getCurrentUser();
|
||||
let rs = user.roles.map(r => r.id);
|
||||
for (let item of roles) {
|
||||
if (rs.indexOf(item) > -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function hasRolePermission(role) {
|
||||
let user = getCurrentUser();
|
||||
for (let ur of user.userRoles) {
|
||||
if (role === ur.roleId) {
|
||||
if (ur.roleId === ROLE_ADMIN) {
|
||||
return true;
|
||||
} else if (ur.roleId === ROLE_ORG_ADMIN && user.lastOrganizationId === ur.sourceId) {
|
||||
return true;
|
||||
} else if (user.lastWorkspaceId === ur.sourceId) {
|
||||
return true;
|
||||
}
|
||||
let user = getCurrentUser();
|
||||
for (let ur of user.userRoles) {
|
||||
if (role === ur.roleId) {
|
||||
if (ur.roleId === ROLE_ADMIN) {
|
||||
return true;
|
||||
} else if (ur.roleId === ROLE_ORG_ADMIN && user.lastOrganizationId === ur.sourceId) {
|
||||
return true;
|
||||
} else if (user.lastWorkspaceId === ur.sourceId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return false
|
||||
}
|
||||
|
||||
export function hasLicense() {
|
||||
let v = localStorage.getItem(LicenseKey);
|
||||
return v === 'valid';
|
||||
let v = localStorage.getItem(LicenseKey);
|
||||
return v === 'valid';
|
||||
}
|
||||
|
||||
//是否含有对应组织或工作空间的角色
|
||||
export function hasRolePermissions(...roles) {
|
||||
for (let role of roles) {
|
||||
if (hasRolePermission(role)) {
|
||||
return true;
|
||||
for (let role of roles) {
|
||||
if (hasRolePermission(role)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function checkoutCurrentOrganization() {
|
||||
// 查看当前用户是否是 lastOrganizationId 的组织管理员
|
||||
return hasRolePermissions(ROLE_ORG_ADMIN);
|
||||
// 查看当前用户是否是 lastOrganizationId 的组织管理员
|
||||
return hasRolePermissions(ROLE_ORG_ADMIN);
|
||||
}
|
||||
|
||||
export function checkoutCurrentWorkspace() {
|
||||
// 查看当前用户是否是 lastWorkspaceId 的工作空间用户
|
||||
return hasRolePermissions(ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER);
|
||||
// 查看当前用户是否是 lastWorkspaceId 的工作空间用户
|
||||
return hasRolePermissions(ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER);
|
||||
}
|
||||
|
||||
export function checkoutTestManagerOrTestUser() {
|
||||
return hasRolePermissions(ROLE_TEST_MANAGER, ROLE_TEST_USER);
|
||||
return hasRolePermissions(ROLE_TEST_MANAGER, ROLE_TEST_USER);
|
||||
}
|
||||
|
||||
export function getCurrentOrganizationId() {
|
||||
let user = getCurrentUser();
|
||||
return user.lastOrganizationId;
|
||||
let user = getCurrentUser();
|
||||
return user.lastOrganizationId;
|
||||
}
|
||||
|
||||
export function getCurrentWorkspaceId() {
|
||||
let user = getCurrentUser();
|
||||
return user.lastWorkspaceId;
|
||||
let user = getCurrentUser();
|
||||
return user.lastWorkspaceId;
|
||||
}
|
||||
|
||||
export function getCurrentUser() {
|
||||
return JSON.parse(localStorage.getItem(TokenKey));
|
||||
return JSON.parse(localStorage.getItem(TokenKey));
|
||||
}
|
||||
|
||||
export function getCurrentProjectID() {
|
||||
return localStorage.getItem(PROJECT_ID);
|
||||
return localStorage.getItem(PROJECT_ID);
|
||||
}
|
||||
|
||||
export function saveLocalStorage(response) {
|
||||
// 登录信息保存 cookie
|
||||
localStorage.setItem(TokenKey, JSON.stringify(response.data));
|
||||
let rolesArray = response.data.roles;
|
||||
let roles = rolesArray.map(r => r.id);
|
||||
// 保存角色
|
||||
localStorage.setItem("roles", roles);
|
||||
// 登录信息保存 cookie
|
||||
localStorage.setItem(TokenKey, JSON.stringify(response.data));
|
||||
let rolesArray = response.data.roles;
|
||||
let roles = rolesArray.map(r => r.id);
|
||||
// 保存角色
|
||||
localStorage.setItem("roles", roles);
|
||||
}
|
||||
|
||||
export function saveLicense(data) {
|
||||
// 保存License
|
||||
localStorage.setItem(LicenseKey, data);
|
||||
// 保存License
|
||||
localStorage.setItem(LicenseKey, data);
|
||||
}
|
||||
|
||||
|
||||
export function refreshSessionAndCookies(sign, sourceId) {
|
||||
axios.post(REFRESH_SESSION_USER_URL + "/" + sign + "/" + sourceId).then(r => {
|
||||
saveLocalStorage(r.data);
|
||||
window.location.reload();
|
||||
})
|
||||
axios.post(REFRESH_SESSION_USER_URL + "/" + sign + "/" + sourceId).then(r => {
|
||||
saveLocalStorage(r.data);
|
||||
window.location.reload();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export function jsonToMap(jsonStr) {
|
||||
let obj = JSON.parse(jsonStr);
|
||||
let strMap = new Map();
|
||||
for (let k of Object.keys(obj)) {
|
||||
strMap.set(k, obj[k]);
|
||||
}
|
||||
return strMap;
|
||||
let obj = JSON.parse(jsonStr);
|
||||
let strMap = new Map();
|
||||
for (let k of Object.keys(obj)) {
|
||||
strMap.set(k, obj[k]);
|
||||
}
|
||||
return strMap;
|
||||
}
|
||||
|
||||
export function mapToJson(strMap) {
|
||||
let obj = Object.create(null);
|
||||
for (let [k, v] of strMap) {
|
||||
obj[k] = v;
|
||||
}
|
||||
return JSON.stringify(obj);
|
||||
let obj = Object.create(null);
|
||||
for (let [k, v] of strMap) {
|
||||
obj[k] = v;
|
||||
}
|
||||
return JSON.stringify(obj);
|
||||
}
|
||||
|
||||
// 驼峰转换下划线
|
||||
export function humpToLine(name) {
|
||||
return name.replace(/([A-Z])/g, "_$1").toLowerCase();
|
||||
return name.replace(/([A-Z])/g, "_$1").toLowerCase();
|
||||
}
|
||||
|
||||
export function downloadFile(name, content) {
|
||||
const blob = new Blob([content]);
|
||||
if ("download" in document.createElement("a")) {
|
||||
// 非IE下载
|
||||
// chrome/firefox
|
||||
let aTag = document.createElement('a');
|
||||
aTag.download = name;
|
||||
aTag.href = URL.createObjectURL(blob);
|
||||
aTag.click();
|
||||
URL.revokeObjectURL(aTag.href)
|
||||
} else {
|
||||
// IE10+下载
|
||||
navigator.msSaveBlob(blob, name)
|
||||
}
|
||||
const blob = new Blob([content]);
|
||||
if ("download" in document.createElement("a")) {
|
||||
// 非IE下载
|
||||
// chrome/firefox
|
||||
let aTag = document.createElement('a');
|
||||
aTag.download = name;
|
||||
aTag.href = URL.createObjectURL(blob);
|
||||
aTag.click();
|
||||
URL.revokeObjectURL(aTag.href)
|
||||
} else {
|
||||
// IE10+下载
|
||||
navigator.msSaveBlob(blob, name)
|
||||
}
|
||||
}
|
||||
|
||||
export function listenGoBack(callback) {
|
||||
//监听浏览器返回操作,关闭该对话框
|
||||
if (window.history && window.history.pushState) {
|
||||
history.pushState(null, null, document.URL);
|
||||
window.addEventListener('popstate', callback);
|
||||
}
|
||||
//监听浏览器返回操作,关闭该对话框
|
||||
if (window.history && window.history.pushState) {
|
||||
history.pushState(null, null, document.URL);
|
||||
window.addEventListener('popstate', callback);
|
||||
}
|
||||
}
|
||||
|
||||
export function removeGoBackListener(callback) {
|
||||
window.removeEventListener('popstate', callback);
|
||||
window.removeEventListener('popstate', callback);
|
||||
}
|
||||
|
||||
export const uuid = function () {
|
||||
let d = new Date().getTime();
|
||||
let d2 = (performance && performance.now && (performance.now() * 1000)) || 0;
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
let r = Math.random() * 16;
|
||||
if (d > 0) {
|
||||
r = (d + r) % 16 | 0;
|
||||
d = Math.floor(d / 16);
|
||||
} else {
|
||||
r = (d2 + r) % 16 | 0;
|
||||
d2 = Math.floor(d2 / 16);
|
||||
}
|
||||
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
||||
});
|
||||
let d = new Date().getTime();
|
||||
let d2 = (performance && performance.now && (performance.now() * 1000)) || 0;
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
let r = Math.random() * 16;
|
||||
if (d > 0) {
|
||||
r = (d + r) % 16 | 0;
|
||||
d = Math.floor(d / 16);
|
||||
} else {
|
||||
r = (d2 + r) % 16 | 0;
|
||||
d2 = Math.floor(d2 / 16);
|
||||
}
|
||||
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
||||
});
|
||||
};
|
||||
|
||||
export function getUUID() {
|
||||
function S4() {
|
||||
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
||||
}
|
||||
function S4() {
|
||||
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
||||
}
|
||||
|
||||
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
|
||||
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
|
||||
}
|
||||
|
||||
|
||||
export function exportPdf(name, canvasList) {
|
||||
|
||||
let pdf = new jsPDF('', 'pt', 'a4');
|
||||
let pdf = new jsPDF('', 'pt', 'a4');
|
||||
|
||||
// 当前页面的当前高度
|
||||
let currentHeight = 0;
|
||||
for (let canvas of canvasList) {
|
||||
if (canvas) {
|
||||
// 当前页面的当前高度
|
||||
let currentHeight = 0;
|
||||
for (let canvas of canvasList) {
|
||||
if (canvas) {
|
||||
|
||||
let contentWidth = canvas.width;
|
||||
let contentHeight = canvas.height;
|
||||
let contentWidth = canvas.width;
|
||||
let contentHeight = canvas.height;
|
||||
|
||||
//a4纸的尺寸[595.28,841.89]
|
||||
let a4Width = 592.28;
|
||||
let a4Height = 841.89;
|
||||
//a4纸的尺寸[595.28,841.89]
|
||||
let a4Width = 592.28;
|
||||
let a4Height = 841.89;
|
||||
|
||||
// html页面生成的canvas在pdf中图片的宽高
|
||||
let imgWidth = a4Width;
|
||||
let imgHeight = a4Width / contentWidth * contentHeight;
|
||||
// html页面生成的canvas在pdf中图片的宽高
|
||||
let imgWidth = a4Width;
|
||||
let imgHeight = a4Width / contentWidth * contentHeight;
|
||||
|
||||
let pageData = canvas.toDataURL('image/jpeg', 1.0);
|
||||
let pageData = canvas.toDataURL('image/jpeg', 1.0);
|
||||
|
||||
// 当前图片的剩余高度
|
||||
let leftHeight = imgHeight;
|
||||
// 当前图片的剩余高度
|
||||
let leftHeight = imgHeight;
|
||||
|
||||
// 当前页面的剩余高度
|
||||
let blankHeight = a4Height - currentHeight;
|
||||
// 当前页面的剩余高度
|
||||
let blankHeight = a4Height - currentHeight;
|
||||
|
||||
if (leftHeight > blankHeight) {
|
||||
//页面偏移
|
||||
let position = 0;
|
||||
while (leftHeight > 0) {
|
||||
// 本次添加占用的高度
|
||||
let occupation = a4Height - currentHeight;
|
||||
pdf.addImage(pageData, 'JPEG', 0, position + currentHeight, imgWidth, imgHeight);
|
||||
currentHeight = leftHeight;
|
||||
leftHeight -= occupation;
|
||||
position -= occupation;
|
||||
//避免添加空白页
|
||||
if (leftHeight > 0) {
|
||||
pdf.addPage();
|
||||
currentHeight = 0;
|
||||
}
|
||||
if (leftHeight > blankHeight) {
|
||||
//页面偏移
|
||||
let position = 0;
|
||||
while (leftHeight > 0) {
|
||||
// 本次添加占用的高度
|
||||
let occupation = a4Height - currentHeight;
|
||||
pdf.addImage(pageData, 'JPEG', 0, position + currentHeight, imgWidth, imgHeight);
|
||||
currentHeight = leftHeight;
|
||||
leftHeight -= occupation;
|
||||
position -= occupation;
|
||||
//避免添加空白页
|
||||
if (leftHeight > 0) {
|
||||
pdf.addPage();
|
||||
currentHeight = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pdf.addImage(pageData, 'JPEG', 0, currentHeight, imgWidth, imgHeight);
|
||||
currentHeight += imgHeight;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pdf.addImage(pageData, 'JPEG', 0, currentHeight, imgWidth, imgHeight);
|
||||
currentHeight += imgHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pdf.save(name.replace(" ", "_") + '.pdf');
|
||||
pdf.save(name.replace(" ", "_") + '.pdf');
|
||||
|
||||
}
|
||||
|
||||
export function windowPrint(id, zoom) {
|
||||
//根据div标签ID拿到div中的局部内容
|
||||
let bdhtml = window.document.body.innerHTML;
|
||||
let el = document.getElementById(id);
|
||||
var jubuData = el.innerHTML;
|
||||
document.getElementsByTagName('body')[0].style.zoom = zoom;
|
||||
//把获取的 局部div内容赋给body标签, 相当于重置了 body里的内容
|
||||
window.document.body.innerHTML = jubuData;
|
||||
//调用打印功能
|
||||
window.print();
|
||||
window.document.body.innerHTML = bdhtml;//重新给页面内容赋值;
|
||||
return false;
|
||||
//根据div标签ID拿到div中的局部内容
|
||||
let bdhtml = window.document.body.innerHTML;
|
||||
let el = document.getElementById(id);
|
||||
var jubuData = el.innerHTML;
|
||||
document.getElementsByTagName('body')[0].style.zoom = zoom;
|
||||
//把获取的 局部div内容赋给body标签, 相当于重置了 body里的内容
|
||||
window.document.body.innerHTML = jubuData;
|
||||
//调用打印功能
|
||||
window.print();
|
||||
window.document.body.innerHTML = bdhtml;//重新给页面内容赋值;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getBodyUploadFiles(obj, runData) {
|
||||
let bodyUploadFiles = [];
|
||||
obj.bodyUploadIds = [];
|
||||
if (runData) {
|
||||
if (runData instanceof Array) {
|
||||
runData.forEach(request => {
|
||||
_getBodyUploadFiles(request, bodyUploadFiles, obj);
|
||||
});
|
||||
} else {
|
||||
_getBodyUploadFiles(runData, bodyUploadFiles, obj);
|
||||
let bodyUploadFiles = [];
|
||||
obj.bodyUploadIds = [];
|
||||
if (runData) {
|
||||
if (runData instanceof Array) {
|
||||
runData.forEach(request => {
|
||||
_getBodyUploadFiles(request, bodyUploadFiles, obj);
|
||||
});
|
||||
} else {
|
||||
_getBodyUploadFiles(runData, bodyUploadFiles, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return bodyUploadFiles;
|
||||
return bodyUploadFiles;
|
||||
}
|
||||
|
||||
export function _getBodyUploadFiles(request, bodyUploadFiles, obj) {
|
||||
let body = null;
|
||||
if (request.hashTree && request.hashTree.length > 0 && request.hashTree[0].body) {
|
||||
body = request.hashTree[0].body;
|
||||
} else if (request.body) {
|
||||
body = request.body;
|
||||
}
|
||||
if (body) {
|
||||
if (body.kvs) {
|
||||
body.kvs.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
if (!item.id) {
|
||||
let fileId = getUUID().substring(0, 12);
|
||||
item.name = item.file.name;
|
||||
item.id = fileId;
|
||||
}
|
||||
obj.bodyUploadIds.push(item.id);
|
||||
bodyUploadFiles.push(item.file);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
let body = null;
|
||||
if (request.hashTree && request.hashTree.length > 0 && request.hashTree[0].body) {
|
||||
body = request.hashTree[0].body;
|
||||
} else if (request.body) {
|
||||
body = request.body;
|
||||
}
|
||||
if (body.binary) {
|
||||
body.binary.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
if (!item.id) {
|
||||
let fileId = getUUID().substring(0, 12);
|
||||
item.name = item.file.name;
|
||||
item.id = fileId;
|
||||
}
|
||||
obj.bodyUploadIds.push(item.id);
|
||||
bodyUploadFiles.push(item.file);
|
||||
}
|
||||
});
|
||||
if (body) {
|
||||
if (body.kvs) {
|
||||
body.kvs.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
if (!item.id) {
|
||||
let fileId = getUUID().substring(0, 12);
|
||||
item.name = item.file.name;
|
||||
item.id = fileId;
|
||||
}
|
||||
obj.bodyUploadIds.push(item.id);
|
||||
bodyUploadFiles.push(item.file);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (body.binary) {
|
||||
body.binary.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
if (!item.id) {
|
||||
let fileId = getUUID().substring(0, 12);
|
||||
item.name = item.file.name;
|
||||
item.id = fileId;
|
||||
}
|
||||
obj.bodyUploadIds.push(item.id);
|
||||
bodyUploadFiles.push(item.file);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function handleCtrlSEvent(event, func) {
|
||||
if (event.keyCode === 83 && event.ctrlKey) {
|
||||
// console.log('拦截到 ctrl + s');//ctrl+s
|
||||
func();
|
||||
event.preventDefault();
|
||||
event.returnValue = false;
|
||||
return false;
|
||||
}
|
||||
if (event.keyCode === 83 && event.ctrlKey) {
|
||||
// console.log('拦截到 ctrl + s');//ctrl+s
|
||||
func();
|
||||
event.preventDefault();
|
||||
event.returnValue = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function strMapToObj(strMap) {
|
||||
if (strMap) {
|
||||
let obj = Object.create(null);
|
||||
for (let [k, v] of strMap) {
|
||||
obj[k] = v;
|
||||
if (strMap) {
|
||||
let obj = Object.create(null);
|
||||
for (let [k, v] of strMap) {
|
||||
obj[k] = v;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
export function objToStrMap(obj) {
|
||||
let strMap = new Map();
|
||||
for (let k of Object.keys(obj)) {
|
||||
strMap.set(k, obj[k]);
|
||||
}
|
||||
return strMap;
|
||||
let strMap = new Map();
|
||||
for (let k of Object.keys(obj)) {
|
||||
strMap.set(k, obj[k]);
|
||||
}
|
||||
return strMap;
|
||||
}
|
||||
|
||||
export function getColor() {
|
||||
return localStorage.getItem('color');
|
||||
return localStorage.getItem('color');
|
||||
}
|
||||
|
||||
export function setColor(a, b, c, d) {
|
||||
document.body.style.setProperty('--color', a);
|
||||
document.body.style.setProperty('--color_shallow', b);
|
||||
document.body.style.setProperty('--count_number', c);
|
||||
document.body.style.setProperty('--count_number_shallow', d);
|
||||
document.body.style.setProperty('--color', a);
|
||||
document.body.style.setProperty('--color_shallow', b);
|
||||
document.body.style.setProperty('--count_number', c);
|
||||
document.body.style.setProperty('--count_number_shallow', d);
|
||||
}
|
||||
|
||||
export function setOriginColor() {
|
||||
setColor(ORIGIN_COLOR, ORIGIN_COLOR_SHALLOW, COUNT_NUMBER, COUNT_NUMBER_SHALLOW);
|
||||
setColor(ORIGIN_COLOR, ORIGIN_COLOR_SHALLOW, COUNT_NUMBER, COUNT_NUMBER_SHALLOW);
|
||||
}
|
||||
|
||||
export function publicKeyEncrypt(input, publicKey) {
|
||||
|
||||
let jsencrypt = new JSEncrypt({default_key_size: 1024});
|
||||
jsencrypt.setPublicKey(publicKey);
|
||||
|
||||
return jsencrypt.encrypt(input);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import {saveLocalStorage} from '@/common/js/utils';
|
||||
import {publicKeyEncrypt, saveLocalStorage} from '@/common/js/utils';
|
||||
import {DEFAULT_LANGUAGE} from "@/common/js/constants";
|
||||
|
||||
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
|
||||
|
@ -103,6 +103,8 @@ export default {
|
|||
|
||||
if (!response.data.success) {
|
||||
this.ready = true;
|
||||
// 保存公钥
|
||||
localStorage.setItem("publicKey", response.data.message);
|
||||
} else {
|
||||
let user = response.data.data;
|
||||
saveLocalStorage(response.data);
|
||||
|
@ -159,7 +161,15 @@ export default {
|
|||
});
|
||||
},
|
||||
doLogin() {
|
||||
this.result = this.$post(this.loginUrl, this.form, response => {
|
||||
let publicKey = localStorage.getItem("publicKey");
|
||||
|
||||
let form = {
|
||||
username: publicKeyEncrypt(this.form.username, publicKey),
|
||||
password: publicKeyEncrypt(this.form.password, publicKey),
|
||||
authenticate: this.form.authenticate
|
||||
};
|
||||
|
||||
this.result = this.$post(this.loginUrl, form, response => {
|
||||
saveLocalStorage(response);
|
||||
sessionStorage.setItem('loginSuccess', 'true');
|
||||
this.getLanguage(response.data.language);
|
||||
|
|
Loading…
Reference in New Issue