优化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

@ -5,7 +5,7 @@
"groupId" : "1952f25c81084e24b55b11385767dc38",
"name" : "登录",
"createTime" : null,
"updateTime" : 1647561372842,
"updateTime" : 1647790320949,
"lock" : "0",
"createBy" : null,
"updateBy" : null,

View File

@ -4,8 +4,8 @@
"script" : null,
"groupId" : "376f26eb43a44a3daeafd27020a96f48",
"name" : "获取所有字典项",
"createTime" : 1646490239446,
"updateTime" : 1634735167647,
"createTime" : null,
"updateTime" : 1647790331786,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@ -16,9 +16,21 @@
"requestBody" : "{\r\n\t\r\n}",
"headers" : [ ],
"paths" : [ ],
"responseBody" : "{\n \"code\": 402,\n \"message\": \"凭证已过期\",\n \"data\": null,\n \"timestamp\": 1634093797926,\n \"executeTime\": null\n}",
"responseBody" : "{\n \"code\": 402,\n \"message\": \"凭证已过期\",\n \"data\": null,\n \"timestamp\": 1647790314936,\n \"executeTime\": null\n}",
"description" : null,
"requestBodyDefinition" : null,
"requestBodyDefinition" : {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
},
"responseBodyDefinition" : {
"name" : "",
"value" : "",
@ -68,7 +80,7 @@
"children" : [ ]
}, {
"name" : "timestamp",
"value" : "1634093797926",
"value" : "1647790314936",
"description" : "",
"required" : false,
"dataType" : "Long",

View File

@ -0,0 +1,135 @@
{
"properties" : { },
"id" : "e516cf1dd64742a2b8a652b4c1224dd1",
"script" : null,
"groupId" : "c7ce65f5b3cf4aaa913f6fec7d35d176",
"name" : "所有字典",
"createTime" : null,
"updateTime" : 1647790584427,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/all",
"method" : "GET",
"parameters" : [ ],
"options" : [ ],
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [{\n \"label\": \"测试1\",\n \"value\": \"测试1\"\n }, {\n \"label\": \"组织机构类型\",\n \"value\": \"office_type\"\n }, {\n \"label\": \"字典类型\",\n \"value\": \"dict_type\"\n }, {\n \"label\": \"是否登录\",\n \"value\": \"is_login\"\n }],\n \"timestamp\": 1647790533379,\n \"executeTime\": 13\n}",
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "code",
"value" : "200",
"description" : "",
"required" : false,
"dataType" : "Integer",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "message",
"value" : "success",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "data",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "label",
"value" : "测试1",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "value",
"value" : "测试1",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
} ]
}, {
"name" : "timestamp",
"value" : "1647790533379",
"description" : "",
"required" : false,
"dataType" : "Long",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "13",
"description" : "",
"required" : false,
"dataType" : "Integer",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
}
}
================================
return db.select("""
select desc_ribe label,type value from sys_dict where is_del = 0
""")

View File

@ -1,37 +0,0 @@
{
"properties" : { },
"id" : "7879aae4cb5f40969b7de3db0dc4307c",
"script" : null,
"groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "保存",
"createTime" : null,
"updateTime" : 1646552458651,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
"path" : "/save",
"method" : "POST",
"parameters" : [ ],
"options" : [ {
"name" : "wrap_request_parameter",
"value" : "data",
"description" : "包装请求参数到一个变量中",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
} ],
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : null
}
================================
return db.table("sys_component").primary("id").saveOrUpdate(data)

File diff suppressed because one or more lines are too long

View File

@ -1,25 +0,0 @@
{
"properties" : { },
"id" : "529cbe774ebe4565b091a30e806a5085",
"script" : null,
"groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "删除",
"createTime" : null,
"updateTime" : 1646553123792,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
"path" : "/delete",
"method" : "DELETE",
"parameters" : [ ],
"options" : [ ],
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : null
}
================================
return db.table("sys_component").logic().where().eq("id",id).delete()

View File

@ -1,97 +0,0 @@
{
"properties" : { },
"id" : "59ce5de20a8b46599cb72c164a9500d1",
"script" : null,
"groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "详情",
"createTime" : null,
"updateTime" : 1646552459844,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
"path" : "/get",
"method" : "GET",
"parameters" : [ ],
"options" : [ ],
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : "{\"code\":402,\"message\":\"凭证已过期\",\"data\":null,\"timestamp\":1646545664781,\"executeTime\":null}",
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "code",
"value" : "402",
"description" : "",
"required" : false,
"dataType" : "Integer",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "message",
"value" : "凭证已过期",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "data",
"value" : "null",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "timestamp",
"value" : "1646545664781",
"description" : "",
"required" : false,
"dataType" : "Long",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "null",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
}
}
================================
return db.table("sys_component").where().eq("id",id).selectOne()

View File

@ -4,8 +4,8 @@
"script" : null,
"groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "选择组件",
"createTime" : 1646490239487,
"updateTime" : 1646402724502,
"createTime" : null,
"updateTime" : 1648025271406,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@ -16,7 +16,7 @@
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : "{\n \"code\": 1,\n \"message\": \"success\",\n \"data\": null,\n \"timestamp\": 1646402708142,\n \"executeTime\": 2\n}",
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [{\n \"id\": \"9bf92d503f4242d39a0f271c577aa3ac\",\n \"label\": \"系统管理\",\n \"children\": [{\n \"id\": \"6bee7576eea04963a573b21bb657784d\",\n \"label\": \"字典管理\",\n \"children\": [{\n \"id\": \"sys-dict-list\",\n \"label\": \"列表(sys-dict-list)\"\n }]\n }]\n }],\n \"timestamp\": 1648025200208,\n \"executeTime\": 14\n}",
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : {
@ -32,7 +32,7 @@
"expression" : "",
"children" : [ {
"name" : "code",
"value" : "1",
"value" : "200",
"description" : "",
"required" : false,
"dataType" : "Integer",
@ -56,7 +56,7 @@
"children" : [ ]
}, {
"name" : "data",
"value" : "null",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
@ -65,10 +65,142 @@
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
"children" : [ {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "id",
"value" : "9bf92d503f4242d39a0f271c577aa3ac",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "label",
"value" : "系统管理",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "children",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Array",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "id",
"value" : "6bee7576eea04963a573b21bb657784d",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "label",
"value" : "字典管理",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "children",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Array",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "id",
"value" : "sys-dict-list",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "label",
"value" : "列表(sys-dict-list)",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
} ]
} ]
} ]
} ]
} ]
}, {
"name" : "timestamp",
"value" : "1646402708142",
"value" : "1648025200208",
"description" : "",
"required" : false,
"dataType" : "Long",
@ -80,7 +212,7 @@
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "2",
"value" : "14",
"description" : "",
"required" : false,
"dataType" : "Integer",
@ -94,6 +226,34 @@
}
}
================================
return db.select("""
select id value,name label from sys_component where is_del = 0
""")
import org.ssssssss.magicapi.utils.PathUtils
import org.ssssssss.magicapi.core.service.MagicResourceService
var getFiles = (groupId) => {
return MagicResourceService.listFiles(groupId).map(file => {
id: PathUtils.replaceSlash(String.format("%s-%s", MagicResourceService.getGroupPath(file.groupId), file.path)).replace('/', '-'),
label: `${file.name}(${file.path})`
})
}
var toTree = (children) => {
var treeData = []
children.forEach(it => {
var chi = {}
chi.id = it.node.id
chi.label = `${it.node.name}(${it.node.path})`
if(it.children.length > 0){
chi.children = toTree(it.children)
var files = getFiles(it.node.id)
if(files.length > 0){
chi.children.push(...files)
}
}else{
var files = getFiles(it.node.id)
if(files.length > 0){
chi.children = files
}
}
treeData.push(chi)
})
return treeData
}
return toTree(MagicResourceService.tree('component').children)

File diff suppressed because one or more lines are too long

View File

@ -4,8 +4,8 @@
"script" : null,
"groupId" : "67b2ce258e24491194b74992958c74aa",
"name" : "获取菜单tree",
"createTime" : 1646490239523,
"updateTime" : 1646402874965,
"createTime" : null,
"updateTime" : 1648014003694,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@ -30,7 +30,19 @@
"paths" : [ ],
"responseBody" : "{\n \"code\": 402,\n \"message\": \"凭证已过期\",\n \"data\": null,\n \"timestamp\": 1634309660370,\n \"executeTime\": null\n}",
"description" : null,
"requestBodyDefinition" : null,
"requestBodyDefinition" : {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
},
"responseBodyDefinition" : {
"name" : "",
"value" : "",
@ -107,7 +119,7 @@
}
================================
var toTree = (list,pid) => select t.*,toTree(list,t.id) children from list t where t.pid = pid
var list = toTree(db.select('select id,name,pid,is_show,url,sort,permission,desc_ribe,icon,keep_alive,component_id from sys_menu where is_del = 0 order by sort'),'0')
var list = toTree(db.select('select id,name,pid,is_show,url,sort,permission,desc_ribe,icon,keep_alive,component_name from sys_menu where is_del = 0 order by sort'),'0')
return {
list: list,

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

View File

@ -28,7 +28,7 @@ function appComponent(app, item){
const install = (app) => {
app.config.globalProperties.$post('/component/list', { size: 999999 }).then((res) => {
res.data.list.forEach(it => {
res.data.forEach(it => {
appComponent(app, it)
})
})

View File

@ -1,161 +0,0 @@
<template>
<div class="app-container">
<mb-search :where="tableOptions.where" @search="reloadTable" />
<el-row class="toolbar-container">
<el-button v-permission="'component:save'" class="filter-item" type="primary" icon="ElPlus" @click="handleCreate">
添加
</el-button>
</el-row>
<mb-table ref="table" v-bind="tableOptions" />
<mb-dialog ref="formDialog" :fullscreen="true" :title="dialogTitle" width="900px" @confirm-click="save($event)">
<template #content>
<el-form ref="dataForm" :rules="rules" :model="temp" label-position="right" label-width="80px">
<el-form-item label="组件名称" prop="name">
<el-input v-model="temp.name" />
</el-form-item>
<el-form-item label="组件描述" prop="descRibe">
<el-input v-model="temp.descRibe" />
</el-form-item>
<el-form-item label="组件代码" prop="code">
<el-input v-model="temp.code" :rows="30" type="textarea" />
</el-form-item>
</el-form>
</template>
</mb-dialog>
</div>
</template>
<script setup>
import { ref, reactive,getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance()
const table = ref()
const formDialog = ref()
const dataForm = ref()
const tableOptions = reactive({
url: 'component/list',
where: {
name: {
type: 'input',
label: '组件名称',
value: ''
},
descRibe: {
type: 'input',
label: '组件描述',
value: ''
}
},
cols: [
{
field: 'name',
label: '组件名称'
},
{
field: 'descRibe',
label: '组件描述'
},
{
label: '操作',
type: 'btns',
width: 270,
fixed: 'right',
btns: [
{
permission: 'component:save',
label: '修改',
type: 'text',
icon: 'ElEdit',
click: (row) => {
handleUpdate(row)
}
},
{
permission: 'component:delete',
label: '删除',
type: 'text',
icon: 'ElDelete',
click: (row) => {
proxy.$common.handleDelete({
url: 'component/delete',
id: row.id,
done: () => reloadTable()
})
}
}
]
}
]
})
const dialogTitle = ref('')
const temp = ref(getTemp())
const rules = reactive({
name: [{ required: true, message: '请输入组件名称', trigger: 'change' }],
descRibe: [{ required: true, message: '请输入组件描述', trigger: 'change' }],
code: [{ required: true, message: '请输入组件代码', trigger: 'change' }]
})
const downloadLoading = ref(false)
function reloadTable() {
table.value.reloadList()
}
function getTemp(){
return {
id: '',
name: '',
code: '',
descRibe: ''
}
}
function resetTemp() {
temp.value = getTemp()
}
function handleCreate() {
resetTemp()
dialogTitle.value = '添加'
formDialog.value.show()
nextTick(() => {
dataForm.value.clearValidate()
})
}
function save(d) {
dataForm.value.validate((valid) => {
if (valid) {
d.loading()
proxy.$post('component/save', temp.value).then(() => {
d.hideLoading()
reloadTable()
formDialog.value.hide()
proxy.$notify({
title: '成功',
message: dialogTitle.value + '成功',
type: 'success',
duration: 2000
})
}).catch(() => d.hideLoading())
}
})
}
function handleUpdate(row) {
for (var t in temp.value) {
temp.value[t] = row[t]
}
dialogTitle.value = '修改'
formDialog.value.show()
nextTick(() => {
dataForm.value.clearValidate()
})
}
</script>