动态组件升级

This commit is contained in:
zegezy 2024-03-05 20:42:12 +08:00
parent 70be66fd66
commit 53feaf3462
7 changed files with 109 additions and 296 deletions

View File

@ -5,7 +5,7 @@
"groupId" : "6f106ebdee21489db34b956f7770ff03", "groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "保存tree", "name" : "保存tree",
"createTime" : null, "createTime" : null,
"updateTime" : 1709468623502, "updateTime" : 1709539934808,
"lock" : null, "lock" : null,
"createBy" : null, "createBy" : null,
"updateBy" : null, "updateBy" : null,
@ -22,7 +22,16 @@
"responseBodyDefinition" : null "responseBodyDefinition" : null
} }
================================ ================================
return db.table("sys_dynamic_component").primary("id").saveOrUpdate({ let data
pid, if(id){
name data = {id, name}
}) if(db.selectInt("select count(1) from sys_dynamic_component where is_del = 0 and name = #{name} and id != #{id}") > 0){
exit 0, '名称不能重复'
}
}else{
data = {pid, name}
if(db.selectInt("select count(1) from sys_dynamic_component where is_del = 0 and name = #{name}") > 0){
exit 0, '名称不能重复'
}
}
return db.table("sys_dynamic_component").primary("id").saveOrUpdate(data)

View File

@ -0,0 +1,34 @@
{
"properties" : { },
"id" : "ac35656c8123461e8c01e5bfa604a0ee",
"script" : null,
"groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "保存代码",
"createTime" : null,
"updateTime" : 1709621424466,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/saveCode",
"method" : "POST",
"parameters" : [ ],
"options" : [ ],
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : null
}
================================
if(db.selectInt("select count(1) from sys_dynamic_component where id = #{id} and is_del = 0") == 0){
exit 0, '文件不存在'
}
return db.table("sys_dynamic_component").where().eq("id",id).update({
sourceCode,
compileJs,
compileCss
})

View File

@ -5,7 +5,7 @@
"groupId" : "6f106ebdee21489db34b956f7770ff03", "groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "列表", "name" : "列表",
"createTime" : null, "createTime" : null,
"updateTime" : 1648611595092, "updateTime" : 1709626054292,
"lock" : "0", "lock" : "0",
"createBy" : null, "createBy" : null,
"updateBy" : null, "updateBy" : null,
@ -16,7 +16,7 @@
"requestBody" : "", "requestBody" : "",
"headers" : [ ], "headers" : [ ],
"paths" : [ ], "paths" : [ ],
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [{\n \"name\": \"data-test-list\",\n \"code\": \"\\n <template>\\n <mb-list ref=\\\"magicList\\\" v-bind=\\\"listOptions\\\" />\\n <mb-dialog ref=\\\"formDialog\\\" @confirm-click=\\\"magicForm.save($event)\\\" width=\\\"50%\\\">\\n <template #content>\\n <mb-form ref=\\\"magicForm\\\" @reload=\\\"magicList.reload\\\" v-bind=\\\"formOptions\\\" />\\n </template>\\n </mb-dialog>\\n </template>\\n <script setup>\\n import { ref, reactive, getCurrentInstance } from 'vue'\\n const { proxy } = getCurrentInstance()\\n const formDialog = ref()\\n const magicList = ref()\\n const magicForm = ref()\\n const listOptions = reactive({\\n tools: [{\\n type: 'add',\\n permission: ':data/test:save',\\n click: () => {\\n formOptions.detail.formData = null\\n formDialog.value.show()\\n }\\n }],\\n table: {\\n url: '/data/test/list',\\n where: {\\n name: {\\n label: '名字'\\n },\\n sex: {\\n label: '性别'\\n },\\n headPortrait: {\\n label: '头像'\\n },\\n remarks: {\\n label: '备注'\\n }\\n },\\n cols: [\\n {\\n \\n field: 'name',\\n label: '名字'\\n },\\n {\\n dictType: 'sex',\\n field: 'sex',\\n label: '性别'\\n },\\n {\\n \\n field: 'headPortrait',\\n label: '头像'\\n },\\n {\\n \\n field: 'remarks',\\n label: '备注'\\n },{\\n label: '操作',\\n type: 'btns',\\n width: 140,\\n fixed: 'right',\\n btns: [\\n {\\n permission: ':data/test:save',\\n label: '修改',\\n type: 'text',\\n icon: 'ElEdit',\\n click: (row) => {\\n magicForm.value.getDetail(row.id)\\n formDialog.value.show()\\n }\\n }, {\\n permission: ':data/test:delete',\\n label: '删除',\\n type: 'text',\\n icon: 'ElDelete',\\n click: (row) => {\\n proxy.$common.handleDelete({\\n url: '/data/test/delete',\\n id: row.id,\\n done: () => magicList.value.reload()\\n })\\n }\\n }\\n ]\\n }\\n ]\\n }\\n })\\n \\n const formOptions = reactive({\\n detail: {\\n request: {\\n url: '/data/test/get'\\n }\\n },\\n form: {\\n request: {\\n url: \\\"/data/test/save\\\",\\n method: \\\"post\\\"\\n },\\n rows: [{\\n gutter: 24,\\n cols: [{\\n span: 12,\\n name: 'name',\\n label: '名字',\\n component: 'input'\\n },{\\n span: 12,\\n name: 'sex',\\n label: '性别',\\n component: 'radio-group'\\n },{\\n span: 12,\\n name: 'headPortrait',\\n label: '头像',\\n component: 'upload-image'\\n },{\\n span: 12,\\n name: 'remarks',\\n label: '备注',\\n component: 'input',\\n props: {\\n type: 'textarea'\\n }\\n \\n }]\\n }]\\n }\\n })\\n \"\n }],\n \"timestamp\": 1648608988019,\n \"executeTime\": 24\n}", "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [\n {\n \"name\": \"test\",\n \"compileJs\": \"const __sfc__ = {}\\nconst _openBlock = ___magic__import__('vue', 'openBlock');\\r\\nconst _createElementBlock = ___magic__import__('vue', 'createElementBlock');\\r\\nconst _pushScopeId = ___magic__import__('vue', 'pushScopeId');\\r\\nconst _popScopeId = ___magic__import__('vue', 'popScopeId');\\n\\nconst _withScopeId = n => (_pushScopeId(\\\"data-v-bWItc2Zj\\\"),n=n(),_popScopeId(),n)\\nconst _hoisted_1 = { class: \\\"qwer\\\" }\\nfunction render(_ctx, _cache) {\\n return (_openBlock(), _createElementBlock(\\\"div\\\", _hoisted_1, \\\" 123 \\\"))\\n}\\n__sfc__.render = render\\n__sfc__.__scopeId = \\\"data-v-bWItc2Zj\\\"\\n__sfc__.__file = \\\"mb-sfc-compiler.vue\\\"\\nreturn __sfc__\",\n \"compileCss\": \".qwer[data-v-bWItc2Zj]{\\n font-size: 18px;\\n color: red;\\n}\"\n }\n ],\n \"timestamp\": 1709625945293,\n \"executeTime\": 30\n}",
"description" : null, "description" : null,
"requestBodyDefinition" : null, "requestBodyDefinition" : null,
"responseBodyDefinition" : { "responseBodyDefinition" : {
@ -130,9 +130,4 @@
} }
} }
================================ ================================
import org.ssssssss.magicapi.utils.PathUtils return db.select("select name, compile_js, compile_css from sys_dynamic_component where is_del = 0 and compile_js is not null")
import org.ssssssss.magicapi.core.service.MagicResourceService
return MagicResourceService.files('component').map(it => {
name: PathUtils.replaceSlash(String.format("%s/%s", MagicResourceService.getGroupPath(it.groupId), it.path)).replace(/^\//,'').replace(/\/\//, '/').replace('/', '-'),
code: it.script
})

View File

@ -0,0 +1,37 @@
{
"properties" : { },
"id" : "da1bbeb256cf417cb26aaf2426ed58c3",
"script" : null,
"groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "删除组件",
"createTime" : null,
"updateTime" : 1709540925818,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/delete",
"method" : "DELETE",
"parameters" : [ ],
"options" : [ ],
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : null
}
================================
let recursionDelete = (list) => {
list.forEach(it => {
db.table("sys_dynamic_component").logic().where().eq("id",it.id).delete()
let children = db.select("select id from sys_dynamic_component where is_del = 0 and pid = #{it.id}")
if(children && children.size() > 0){
recursionDelete(children)
}
})
}
recursionDelete(db.select("select id from sys_dynamic_component where is_del = 0 and pid = #{id}"))
return db.table("sys_dynamic_component").logic().where().eq("id",id).delete()

View File

@ -4,8 +4,8 @@
"script" : null, "script" : null,
"groupId" : "6f106ebdee21489db34b956f7770ff03", "groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "获取源码", "name" : "获取源码",
"createTime" : 1709459380012, "createTime" : null,
"updateTime" : null, "updateTime" : 1709533763038,
"lock" : null, "lock" : null,
"createBy" : null, "createBy" : null,
"updateBy" : null, "updateBy" : null,
@ -23,5 +23,5 @@
} }
================================ ================================
return db.selectValue(""" return db.selectValue("""
select source_code from sys_dynamic_component where is_del=0 and name = #{name} select source_code from sys_dynamic_component where is_del = 0 and id = #{id}
""") """)

View File

@ -1,263 +0,0 @@
{
"properties" : { },
"id" : "eb2b08bc7fe74036867e8dc5f2c0e8f8",
"script" : null,
"groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "选择组件",
"createTime" : null,
"updateTime" : 1680361687356,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
"path" : "/select",
"method" : "GET",
"parameters" : [ ],
"options" : [ ],
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [{\n \"value\": \"55ff62aa20144b7bb5c6dfb5d76c8139\",\n \"label\": \"数据管理(/data)\",\n \"children\": [{\n \"value\": \"eb5dbed949de4f50ba4bf59f483252a5\",\n \"label\": \"测试生成(/test)\",\n \"children\": [{\n \"value\": \"data-test-list\",\n \"label\": \"列表(/list)\"\n }]\n }]\n }],\n \"timestamp\": 1680361660407,\n \"executeTime\": 17\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" : "value",
"value" : "55ff62aa20144b7bb5c6dfb5d76c8139",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "label",
"value" : "数据管理(/data)",
"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" : "value",
"value" : "eb5dbed949de4f50ba4bf59f483252a5",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "label",
"value" : "测试生成(/test)",
"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" : "value",
"value" : "data-test-list",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "label",
"value" : "列表(/list)",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
} ]
} ]
} ]
} ]
} ]
}, {
"name" : "timestamp",
"value" : "1680361660407",
"description" : "",
"required" : false,
"dataType" : "Long",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "17",
"description" : "",
"required" : false,
"dataType" : "Integer",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
}
}
================================
import org.ssssssss.magicapi.utils.PathUtils
import org.ssssssss.magicapi.core.service.MagicResourceService
var getFiles = (groupId) => {
return MagicResourceService.listFiles(groupId).map(file => {
key: PathUtils.replaceSlash(String.format("%s/%s", MagicResourceService.getGroupPath(file.groupId), file.path)).replace(/^\//,'').replace(/\/\//, '/').replace('/', '-'),
label: `${file.name}(${file.path})`
})
}
var toTree = (children) => {
var treeData = []
children.forEach(it => {
var chi = {}
chi.key = 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.addAll(files)
}
}else{
var files = getFiles(it.node.id)
if(files.length > 0){
chi.children = files
}
}
if(chi instanceof List){
treeData.addAll(chi)
}else{
treeData.add(chi)
}
})
return treeData
}
return toTree(MagicResourceService.tree('component').children)

File diff suppressed because one or more lines are too long