优化component插件

This commit is contained in:
吕金泽
2022-03-23 20:57:43 +08:00
parent 35da78b14e
commit 7abec9974f
17 changed files with 421 additions and 416 deletions

View File

@@ -1,8 +1,10 @@
<template>
<div class="magic-component-info">
<form>
<label>{{ $i('component.form.componentName') }}</label>
<magic-input v-model:value="info.name" :placeholder="$i('component.form.placeholder.componentName')" width="250px"/>
<label>{{ $i('component.form.name') }}</label>
<magic-input v-model:value="info.name" :placeholder="$i('component.form.placeholder.name')" width="250px"/>
<label>{{ $i('component.form.path') }}</label>
<magic-input v-model:value="info.path" :placeholder="$i('component.form.placeholder.path')" width="auto" style="flex:1"/>
</form>
<div style="flex:1;padding-top:5px;">
<magic-textarea v-model:value="info.description" :placeholder="$i('component.form.placeholder.description')"/>

View File

@@ -3,10 +3,12 @@ export default {
title: 'Component Info',
name: 'Component',
form: {
componentName: 'Component Name',
name: 'Component Name',
path: 'Component Path',
description: 'Component Description',
placeholder: {
componentName: 'Please Enter Component Name',
name: 'Please Enter Component Name',
path: 'Please Enter Component Path',
description: 'Please Enter Component Description'
}
}

View File

@@ -3,10 +3,12 @@ export default {
title: '组件信息',
name: '组件',
form: {
componentName: '组件名称',
name: '组件名称',
path: '组件路径',
description: '组件描述',
placeholder: {
componentName: '请输入组件名称',
name: '请输入组件名称',
path: '请输入组件路径',
description: '请输入组件描述'
}
}

View File

@@ -19,7 +19,7 @@ export default function (bus, constants, $i, Message, request) {
// 是否允许执行测试
runnable: false,
// 是否需要填写路径
requirePath: false,
requirePath: true,
// 合并
merge: item => item
}

View File

@@ -1,17 +1,10 @@
package org.ssssssss.magicapi.component.service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.ssssssss.magicapi.component.model.ComponentInfo;
import org.ssssssss.magicapi.core.exception.InvalidArgumentException;
import org.ssssssss.magicapi.core.model.Group;
import org.ssssssss.magicapi.core.model.JsonCode;
import org.ssssssss.magicapi.core.model.MagicEntity;
import org.ssssssss.magicapi.core.model.TreeNode;
import org.ssssssss.magicapi.core.service.AbstractPathMagicResourceStorage;
import org.ssssssss.magicapi.core.service.MagicResourceService;
import java.util.List;
import java.util.UUID;
public class ComponentInfoMagicResourceStorage extends AbstractPathMagicResourceStorage<ComponentInfo> {
@@ -26,49 +19,8 @@ public class ComponentInfoMagicResourceStorage extends AbstractPathMagicResource
return ComponentInfo.class;
}
private boolean strIsEnglish(String word) {
boolean sign = true;
for (int i = 0; i < word.length(); i++) {
if (!(word.charAt(i) >= 'A' && word.charAt(i) <= 'Z')
&& !(word.charAt(i) >= 'a' && word.charAt(i) <= 'z')) {
return false;
}
}
return true;
}
public void isNameRepeat(List<TreeNode<Group>> groupChildren, String name, String id){
groupChildren.stream().forEach(it -> {
Group node = it.getNode();
List<TreeNode<Group>> chi = it.getChildren();
magicResourceService.listFiles(node.getId()).forEach(file -> {
if(null != id){
if(!file.getId().equals(id) && file.getName().equals(name)){
throw new InvalidArgumentException(new JsonCode(9004, "组件名称已存在"));
}
}else{
if(file.getName().equals(name)){
throw new InvalidArgumentException(new JsonCode(9004, "组件名称已存在"));
}
}
});
if(chi.size() > 0){
isNameRepeat(chi, name, id);
}
});
}
@Override
public void validate(ComponentInfo entity) {
if(null == entity.getPath() || entity.getPath().equals("")){
entity.setPath(UUID.randomUUID().toString().replace("-", ""));
}
isNameRepeat(magicResourceService.tree("component").getChildren(), entity.getName(), entity.getId());
notBlank(entity.getName(), new JsonCode(9001, "组件名称不能为空"));
if(!strIsEnglish(entity.getName())){
throw new InvalidArgumentException(new JsonCode(9002, "组件名称必须是英文"));
}
notBlank(entity.getDescription(), new JsonCode(9003, "组件描述不能为空"));
}
@Override