feat: ESB的3点优化

1.用户登陆接口定义页面,会自动选择这个角色上一次选择的接口类型;2.ESB接口编辑-请求参数表格,取消每一行后的确认按钮,改为在table最下方增加一个整体的确认按钮。按钮包含校验功能;3.接口导入时所属模块默认选择第一个
This commit is contained in:
song-tianyang 2021-05-11 16:13:38 +08:00 committed by BugKing
parent b7f9228546
commit 446697379b
4 changed files with 76 additions and 5 deletions

View File

@ -5,6 +5,8 @@ import io.metersphere.api.dto.definition.DragModuleRequest;
import io.metersphere.api.service.ApiModuleService; import io.metersphere.api.service.ApiModuleService;
import io.metersphere.base.domain.ApiModule; import io.metersphere.base.domain.ApiModule;
import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.ApiDefinitionDefaultApiTypeUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.service.CheckPermissionService; import io.metersphere.service.CheckPermissionService;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresRoles;
@ -26,13 +28,27 @@ public class ApiModuleController {
@GetMapping("/list/{projectId}/{protocol}") @GetMapping("/list/{projectId}/{protocol}")
public List<ApiModuleDTO> getNodeByProjectId(@PathVariable String projectId,@PathVariable String protocol) { public List<ApiModuleDTO> getNodeByProjectId(@PathVariable String projectId,@PathVariable String protocol) {
checkPermissionService.checkProjectOwner(projectId); checkPermissionService.checkProjectOwner(projectId);
return apiModuleService.getNodeTreeByProjectId(projectId,protocol); String userId = SessionUtils.getUserId();
ApiDefinitionDefaultApiTypeUtil.addUserSelectApiType(userId, protocol);
return apiModuleService.getNodeTreeByProjectId(projectId, protocol);
} }
@GetMapping("/getModuleByName/{projectId}/{protocol}") @GetMapping("/getModuleByName/{projectId}/{protocol}")
public ApiModule getModuleByName(@PathVariable String projectId,@PathVariable String protocol) { public ApiModule getModuleByName(@PathVariable String projectId, @PathVariable String protocol) {
checkPermissionService.checkProjectOwner(projectId); checkPermissionService.checkProjectOwner(projectId);
return apiModuleService.getModuleByName(projectId,protocol); return apiModuleService.getModuleByName(projectId, protocol);
}
@GetMapping("/getUserDefaultApiType")
public String getUserDefaultApiType() {
String returnStr = ApiDefinitionDefaultApiTypeUtil.HTTP;
try {
String userId = SessionUtils.getUserId();
returnStr = ApiDefinitionDefaultApiTypeUtil.getUserSelectedApiType(userId);
} catch (Exception e) {
}
return returnStr;
} }
@GetMapping("/list/plan/{planId}/{protocol}") @GetMapping("/list/plan/{planId}/{protocol}")

View File

@ -0,0 +1,43 @@
package io.metersphere.commons.utils;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
/**
* 获取用户进入接口定义页面 默认展示的接口类型
*
* @author song.tianyang
* @Date 2021/5/11 10:52 上午
* @Description
*/
public class ApiDefinitionDefaultApiTypeUtil {
public static final String HTTP = "HTTP";
public static final String SQL = "SQL";
public static final String DUBBO = "DUBBO";
public static final String TCP = "TCP";
private static HashMap<String, String> apiTypePerferenceMap;
public synchronized static void addUserSelectApiType(String userId, String apiType) {
if (StringUtils.isNotEmpty(userId) && StringUtils.isNotEmpty(apiType)) {
if (apiTypePerferenceMap == null) {
apiTypePerferenceMap = new HashMap<>();
}
apiTypePerferenceMap.put(userId, apiType);
}
}
public synchronized static String getUserSelectedApiType(String userId) {
if (StringUtils.isEmpty(userId)) {
return HTTP;
} else {
String selectedApiType = apiTypePerferenceMap.get(userId);
if (StringUtils.equalsAny(selectedApiType, HTTP, SQL, DUBBO, TCP)) {
return selectedApiType;
} else {
return HTTP;
}
}
}
}

View File

@ -201,6 +201,11 @@
this.selectedPlatform = this.platforms[0]; this.selectedPlatform = this.platforms[0];
}, },
watch: { watch: {
moduleOptions() {
if (this.moduleOptions.length > 0) {
this.formData.moduleId = this.moduleOptions[0].id;
}
},
selectedPlatformValue() { selectedPlatformValue() {
for (let i in this.platforms) { for (let i in this.platforms) {
if (this.platforms[i].value === this.selectedPlatformValue) { if (this.platforms[i].value === this.selectedPlatformValue) {

View File

@ -93,9 +93,9 @@
}, },
}, },
mounted() { mounted() {
this.$emit('protocolChange', this.condition.protocol); this.initProtocol();
this.list();
}, },
watch: { watch: {
'condition.filterText'(val) { 'condition.filterText'(val) {
this.$refs.nodeTree.filter(val); this.$refs.nodeTree.filter(val);
@ -118,6 +118,13 @@
} }
}, },
methods: { methods: {
initProtocol() {
this.$get('/api/module//getUserDefaultApiType/', response => {
this.condition.protocol = response.data;
this.$emit('protocolChange', this.condition.protocol);
this.list();
});
},
list(projectId) { list(projectId) {
let url = undefined; let url = undefined;
if (this.isPlanModel) { if (this.isPlanModel) {