优化一波生成,加载组件等

This commit is contained in:
吕金泽 2022-03-30 23:54:24 +08:00
parent 2e19ca3493
commit b91328dcc7
35 changed files with 460 additions and 547 deletions

View File

@ -1,6 +1,6 @@
{
"properties" : { },
"id" : "20316fcfa94644d685fa1b464f135f9a",
"id" : "8d60ba6788ef4a75b93f3c77683c7f89",
"name" : "数据管理",
"type" : "api",
"parentId" : "0",

View File

@ -1,9 +1,9 @@
{
"properties" : { },
"id" : "152b9ad78aaf49a7a8945b5de088c1da",
"id" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "测试生成",
"type" : "api",
"parentId" : "20316fcfa94644d685fa1b464f135f9a",
"parentId" : "8d60ba6788ef4a75b93f3c77683c7f89",
"path" : "/test",
"paths" : [ ],
"options" : [ ]

View File

@ -1,77 +1,17 @@
{
"properties" : { },
"id" : "d6c54f1563964523b601bd03d32e1bf0",
"id" : "46a5f8f41666462987ae042469b99ff4",
"script" : null,
"groupId" : "152b9ad78aaf49a7a8945b5de088c1da",
"groupId" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "保存",
"createTime" : null,
"updateTime" : 1648486126527,
"createTime" : 1648655132918,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/save",
"method" : "POST",
"parameters" : [ {
"name" : "name",
"value" : "111111",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "sex",
"value" : "222222",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "head_portrait",
"value" : "333333",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "remarks",
"value" : "444444",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "id",
"value" : "09c850212e1740e99485a850b90825a5",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
} ],
"parameters" : [ ],
"options" : [ {
"name" : "wrap_request_parameter",
"value" : "data",
@ -85,85 +25,13 @@
"expression" : null,
"children" : null
} ],
"requestBody" : "",
"requestBody" : null,
"headers" : [ ],
"paths" : [ ],
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": \"09c850212e1740e99485a850b90825a5\",\n \"timestamp\": 1648486104458,\n \"executeTime\": 12\n}",
"responseBody" : null,
"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" : "09c850212e1740e99485a850b90825a5",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "timestamp",
"value" : "1648486104458",
"description" : "",
"required" : false,
"dataType" : "Long",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "12",
"description" : "",
"required" : false,
"dataType" : "Integer",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
}
"responseBodyDefinition" : null
}
================================
return db.table('t_data_test').primary('id').saveOrUpdate(data)

View File

@ -1,10 +1,10 @@
{
"properties" : { },
"id" : "90986654bb2d4560ada10c309195f500",
"id" : "d94a4788e17a4e0f9b67ca86b171e231",
"script" : null,
"groupId" : "152b9ad78aaf49a7a8945b5de088c1da",
"groupId" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "列表",
"createTime" : 1648486052761,
"createTime" : 1648655132912,
"updateTime" : null,
"lock" : null,
"createBy" : null,
@ -28,4 +28,5 @@ return db.page("""
?{sex, and sex = #{sex} }
?{headPortrait, and head_portrait in(#{headPortrait.split(',')}) }
?{remarks, and remarks <= #{remarks} }
and is_del = 0
""")

View File

@ -1,10 +1,10 @@
{
"properties" : { },
"id" : "7443f294349446289c25d4ef6fe2b499",
"id" : "e1df886fe7604810b495d555abaa6200",
"script" : null,
"groupId" : "152b9ad78aaf49a7a8945b5de088c1da",
"groupId" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "删除",
"createTime" : 1648486052772,
"createTime" : 1648655132924,
"updateTime" : null,
"lock" : null,
"createBy" : null,

View File

@ -1,10 +1,10 @@
{
"properties" : { },
"id" : "f0e1cfcf4f254e17b75d7647f4f09f25",
"id" : "c999de118aa04594bc14c0e3f5ade568",
"script" : null,
"groupId" : "152b9ad78aaf49a7a8945b5de088c1da",
"groupId" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "详情",
"createTime" : 1648486052778,
"createTime" : 1648655132931,
"updateTime" : null,
"lock" : null,
"createBy" : null,

View File

@ -5,7 +5,7 @@
"groupId" : "f2538e0f370a4cabab0ae920f5e77ae7",
"name" : "执行生成",
"createTime" : null,
"updateTime" : 1648486047810,
"updateTime" : 1648651494341,
"lock" : null,
"createBy" : null,
"updateBy" : null,
@ -214,43 +214,66 @@
}
}
================================
import org.ssssssss.magicapi.core.model.Option
import org.ssssssss.magicapi.component.model.ComponentInfo
import org.ssssssss.magicapi.core.model.ApiInfo
import org.ssssssss.magicapi.core.model.Group
import org.ssssssss.magicapi.core.service.MagicResourceService
import log
info = info::json
var moduleGroup = MagicResourceService.tree('api').children.filter(it => {
return it.node.path == info.modulePath || it.node.path == info.modulePath.substring(1, info.modulePath.length())
})
if(moduleGroup.length == 0){
Group group = new Group();
group.setId(UUID.randomUUID().toString().replace('-', ''));
group.setName(info.moduleName);
group.setPath(info.modulePath);
group.setParentId("0");
group.setType('api')
MagicResourceService.saveGroup(group);
moduleGroup = group;
}else{
moduleGroup = moduleGroup[0].node
var getGroup = (type) => {
var moduleGroup = MagicResourceService.tree(type).children.filter(it => {
return it.node.path == info.modulePath || it.node.path == info.modulePath.substring(1, info.modulePath.length())
})
if(moduleGroup.length == 0){
Group group = new Group();
group.setId(UUID.randomUUID().toString().replace('-', ''));
group.setName(info.moduleName);
group.setPath(info.modulePath);
group.setParentId("0");
group.setType(type)
MagicResourceService.saveGroup(group);
moduleGroup = group;
}else{
moduleGroup = moduleGroup[0].node
}
var businessGroup = MagicResourceService.tree(type).children.filter(it => it.node.id == moduleGroup.id)[0].children.filter(it => {
return it.node.path == info.businessPath || it.node.path == info.businessPath.substring(1, info.businessPath.length())
})
if(businessGroup.length == 0){
Group group = new Group();
group.setId(UUID.randomUUID().toString().replace('-', ''));
group.setName(info.businessName);
group.setPath(info.businessPath);
group.setParentId(moduleGroup.getId());
group.setType(type)
MagicResourceService.saveGroup(group);
businessGroup = group;
}else{
businessGroup = businessGroup[0].node
}
return {
moduleGroup,
businessGroup
}
}
var businessGroup = MagicResourceService.tree('api').children.filter(it => it.node.id == moduleGroup.id)[0].children.filter(it => {
return it.node.path == info.businessPath || it.node.path == info.businessPath.substring(1, info.businessPath.length())
})
if(businessGroup.length == 0){
Group group = new Group();
group.setId(UUID.randomUUID().toString().replace('-', ''));
group.setName(info.businessName);
group.setPath(info.businessPath);
group.setParentId(moduleGroup.getId());
group.setType('api')
MagicResourceService.saveGroup(group);
businessGroup = group;
}else{
businessGroup = businessGroup[0].node
var deleteFiles = (groupId, paths) => {
var listFiles = MagicResourceService.listFiles(groupId)
listFiles.forEach(it => {
if(paths.indexOf(it.path) != -1){
MagicResourceService.delete(it.id)
}
})
}
var businessGroup = getGroup('api').businessGroup
deleteFiles(businessGroup.getId(),['/list', '/save', '/get', '/delete'])
columns = columns::json
var listFields = columns.filter(it => it.list).map(it => it.columnName.replace(/([A-Z])/g,"_$1").toLowerCase()).join(',')
var wheres = '';
@ -266,7 +289,6 @@ columns.forEach(it => {
}
}
})
wheres = wheres.substring(0,wheres.length() - 1)
var commonField = db.select("""
SELECT
@ -280,6 +302,13 @@ commonField = commonField.map(it => it.columnName)
var primary = db.selectValue("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = #{tableName} and column_key = 'PRI' and table_schema = database() limit 1")
var primaryLowerCamelCase = primary.replace(/([A-Z])/g,"_$1").toLowerCase()
var logic = ''
if(commonField.contains('is_del')){
logic = '.logic()'
wheres += ` and is_del = 0\n`
}
wheres = wheres.substring(0,wheres.length() - 1)
ApiInfo listApi = new ApiInfo()
listApi.setName("列表")
listApi.setPath("/list")
@ -302,14 +331,9 @@ saveApi.setPath("/save")
saveApi.setMethod("POST")
saveApi.setGroupId(businessGroup.getId())
saveApi.setScript(`return db.table('${tableName}').primary('${primary}').${saveMethod}`)
saveApi.setOption([{ name: 'wrap_request_parameter', value: 'data' }])
saveApi.setOption([new Option('wrap_request_parameter', 'data')])
MagicResourceService.saveFile(saveApi)
var logic = ''
if(commonField.contains('is_del')){
logic = '.logic()'
}
ApiInfo deleteApi = new ApiInfo()
deleteApi.setName("删除")
deleteApi.setPath("/delete")
@ -330,4 +354,16 @@ getApi.setScript(`return db.selectOne("""
""")`)
MagicResourceService.saveFile(getApi)
return commonField
var componentBusinessGroup = getGroup('component').businessGroup
deleteFiles(componentBusinessGroup.getId(),['/list'])
ComponentInfo componentInfo = new ComponentInfo()
componentInfo.setGroupId(componentBusinessGroup.getId())
componentInfo.setName("列表")
componentInfo.setPath("/list")
componentInfo.setScript(componentScript)
MagicResourceService.saveFile(componentInfo)
return 1

View File

@ -5,7 +5,7 @@
"groupId" : "1952f25c81084e24b55b11385767dc38",
"name" : "登录",
"createTime" : null,
"updateTime" : 1648478302933,
"updateTime" : 1648567495848,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@ -64,7 +64,7 @@
"requestBody" : "{\r\n \"username\": \"admin\",\r\n \"password\": \"123456\"\r\n}",
"headers" : [ ],
"paths" : [ ],
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": \"cb63a01c-63d7-4722-a2c4-48fffa4b3502\",\n \"timestamp\": 1647395770056,\n \"executeTime\": 20\n}",
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": \"319e2efb-9e42-4b86-9658-a60d3585a7fe\",\n \"timestamp\": 1648565675784,\n \"executeTime\": 12\n}",
"description" : null,
"requestBodyDefinition" : {
"name" : "",
@ -140,7 +140,7 @@
"children" : [ ]
}, {
"name" : "data",
"value" : "cb63a01c-63d7-4722-a2c4-48fffa4b3502",
"value" : "319e2efb-9e42-4b86-9658-a60d3585a7fe",
"description" : "",
"required" : false,
"dataType" : "Object",
@ -152,7 +152,7 @@
"children" : [ ]
}, {
"name" : "timestamp",
"value" : "1647395770056",
"value" : "1648565675784",
"description" : "",
"required" : false,
"dataType" : "Long",
@ -164,7 +164,7 @@
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "20",
"value" : "12",
"description" : "",
"required" : false,
"dataType" : "Integer",

View File

@ -5,7 +5,7 @@
"groupId" : "42d241c0bb18476f8dabf92c2e4e2324",
"name" : "列表",
"createTime" : null,
"updateTime" : 1646552460608,
"updateTime" : 1648647148457,
"lock" : "0",
"createBy" : null,
"updateBy" : null,

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
"groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "选择组件",
"createTime" : null,
"updateTime" : 1648025271406,
"updateTime" : 1648647253717,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@ -230,7 +230,7 @@ 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('/', '-'),
id: PathUtils.replaceSlash(String.format("%s/%s", MagicResourceService.getGroupPath(file.groupId), file.path)).replace(/^\//,'').replace(/\/\//, '/').replace('/', '-'),
label: `${file.name}(${file.path})`
})
}

View File

@ -5,7 +5,7 @@
"groupId" : "67b2ce258e24491194b74992958c74aa",
"name" : "保存",
"createTime" : null,
"updateTime" : 1646576146705,
"updateTime" : 1648647102120,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@ -59,7 +59,7 @@
}
================================
import org.ssssssss.magicapi.modules.db.cache.SqlCache;
import '@get:/menu/cache/delete' as cacheDelete;
import '@get:/system/menu/cache/delete' as cacheDelete;
if(data.url){
var urlCount = db.selectInt("select count(1) from sys_menu where is_del = 0 and url = #{data.url} ?{data.id, and id != #{data.id}}")

View File

@ -5,7 +5,7 @@
"groupId" : "67b2ce258e24491194b74992958c74aa",
"name" : "删除",
"createTime" : null,
"updateTime" : 1646553101301,
"updateTime" : 1648647114911,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@ -130,7 +130,7 @@
}
}
================================
import '@get:/menu/cache/delete' as cacheDelete;
import '@get:/system/menu/cache/delete' as cacheDelete;
var menuId = id
cacheDelete();

View File

@ -4,8 +4,8 @@
"script" : null,
"groupId" : "89130d496f6f467c88b22ae4a7f688eb",
"name" : "保存",
"createTime" : 1646490239526,
"updateTime" : 1644121680268,
"createTime" : null,
"updateTime" : 1648647133039,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@ -30,11 +30,23 @@
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"requestBodyDefinition" : {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
},
"responseBodyDefinition" : null
}
================================
import '@get:/role/cache/delete' as cacheDelete
import '@get:/system/role/cache/delete' as cacheDelete
var codeCount = db.selectInt("select count(1) from sys_role where is_del = 0 and code = #{code} ?{id, and id != #{id}}")
if(codeCount > 0){

View File

@ -5,7 +5,7 @@
"groupId" : "89130d496f6f467c88b22ae4a7f688eb",
"name" : "删除",
"createTime" : null,
"updateTime" : 1647615829916,
"updateTime" : 1648647124177,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@ -46,7 +46,7 @@
"responseBodyDefinition" : null
}
================================
import '@get:/role/cache/delete' as cacheDelete
import '@get:/system/role/cache/delete' as cacheDelete
var userCount = db.selectInt("select count(1) from sys_user_role where role_id = #{id}")
if(userCount > 0){

View File

@ -1,10 +1,10 @@
{
"properties" : { },
"id" : "9bf92d503f4242d39a0f271c577aa3ac",
"name" : "系统管理",
"id" : "55ff62aa20144b7bb5c6dfb5d76c8139",
"name" : "数据管理",
"type" : "component",
"parentId" : "0",
"path" : "sys",
"path" : "/data",
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,10 @@
{
"properties" : { },
"id" : "eb5dbed949de4f50ba4bf59f483252a5",
"name" : "测试生成",
"type" : "component",
"parentId" : "55ff62aa20144b7bb5c6dfb5d76c8139",
"path" : "/test",
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,156 @@
{
"properties" : { },
"id" : "f4ebe91beaef452498879a98556481eb",
"script" : null,
"groupId" : "eb5dbed949de4f50ba4bf59f483252a5",
"name" : "列表",
"createTime" : 1648655132940,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/list",
"description" : null
}
================================
<template>
<mb-list ref="magicList" v-bind="listOptions" />
<mb-dialog ref="formDialog" :title="magicFormTitle" @confirm-click="magicForm.save($event)" width="50%">
<template #content>
<mb-form ref="magicForm" @reload="magicList.reload" v-bind="formOptions" />
</template>
</mb-dialog>
</template>
<script setup>
import { ref, reactive, getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance()
const formDialog = ref()
const magicList = ref()
const magicForm = ref()
const magicFormTitle = ref()
const listOptions = reactive({
tools: [{
type: 'add',
permission: 'data:test:save',
click: () => {
magicFormTitle.value = '添加'
formDialog.value.show()
}
}],
table: {
url: '/data/test/list',
where: {
name: {
label: '名字'
},
sex: {
label: '性别'
},
headPortrait: {
label: '头像'
},
remarks: {
label: '备注'
}
},
cols: [
{
field: 'name',
label: '名字'
},
{
dictType: 'sex',
field: 'sex',
label: '性别'
},
{
field: 'headPortrait',
label: '头像'
},
{
field: 'remarks',
label: '备注'
},{
label: '操作',
type: 'btns',
width: 140,
fixed: 'right',
btns: [
{
permission: 'data:test:save',
label: '修改',
type: 'text',
icon: 'ElEdit',
click: (row) => {
magicFormTitle.value = '修改'
formDialog.value.show(() => magicForm.value.getDetail(row.id))
}
}, {
permission: 'data:test:delete',
label: '删除',
type: 'text',
icon: 'ElDelete',
click: (row) => {
proxy.$common.handleDelete({
url: '/data/test/delete',
id: row.id,
done: () => magicList.value.reload()
})
}
}
]
}
]
}
})
const formOptions = reactive({
detail: {
request: {
url: '/data/test/get'
}
},
form: {
request: {
url: "/data/test/save"
},
rows: [{
gutter: 24,
cols: [{
span: 12,
name: 'name',
label: '名字',
component: 'input',
},{
span: 12,
name: 'sex',
label: '性别',
component: 'radio-group',
props: {
type: 'sex'
}
},{
span: 12,
name: 'headPortrait',
label: '头像',
component: 'upload-image',
},{
span: 12,
name: 'remarks',
label: '备注',
component: 'input',
props: {
type: 'textarea'
}
,
}]
}]
}
})
</script>

View File

@ -1,10 +0,0 @@
{
"properties" : { },
"id" : "6bee7576eea04963a573b21bb657784d",
"name" : "字典管理",
"type" : "component",
"parentId" : "9bf92d503f4242d39a0f271c577aa3ac",
"path" : "dict",
"paths" : [ ],
"options" : [ ]
}

View File

@ -1,230 +0,0 @@
{
"properties" : { },
"id" : "995e2ee59d574429b8e3da3513c05a43",
"script" : null,
"groupId" : "6bee7576eea04963a573b21bb657784d",
"name" : "列表",
"createTime" : 1648017481335,
"updateTime" : 1648026074180,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "list",
"description" : null
}
================================
<template>
<div class="app-container">
<mb-search :where="tableOptions.where" @search="reloadTable" />
<el-row class="toolbar-container">
<el-button v-permission="'dict:save'" class="filter-item" type="primary" icon="ElPlus" @click="handleCreate">
添加13asdf
</el-button>
</el-row>
<mb-table ref="table" v-bind="tableOptions" />
<mb-dialog ref="dictDialog" :title="dialogTitle" width="640px" @confirm-click="save($event)">
<template #content>
<el-form ref="dataForm" :inline="true" :rules="rules" :model="temp" label-position="right" label-width="80px">
<el-row :gutter="24">
<el-col :span="12">
<el-form-item label="字典类型" prop="dictType">
<mb-select v-model="temp.dictType" type="dict_type" width="185px" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="类型" prop="type">
<el-input v-model="temp.type" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="24">
<el-col :span="12">
<el-form-item label="排序" prop="sort">
<el-input v-model="temp.sort" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="描述" prop="descRibe">
<el-input v-model="temp.descRibe" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="24">
<el-col :span="12">
<el-form-item label="备注" prop="remarks">
<el-input v-model="temp.remarks" />
</el-form-item>
</el-col>
</el-row>
</el-form>
</template>
</mb-dialog>
</div>
</template>
<script setup>
import { ref, reactive, getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance()
const tableOptions = reactive({
url: 'dict/list',
page: true,
where: {
type: {
type: 'input',
label: '类型',
value: ''
},
dictType: {
type: 'select',
label: '字典类型',
value: '',
properties: {
'all-option': true,
type: 'dict_type'
}
}
},
cols: [
{
field: 'type',
label: '类型'
},
{
field: 'descRibe',
label: '描述'
},
{
field: 'dictType',
label: '字典类型',
width: 200,
dictType: 'dict_type'
},
{
field: 'remarks',
label: '备注',
width: 200
},
{
field: 'sort',
label: '排序',
width: 100
},
{
label: '操作',
type: 'btns',
width: 220,
fixed: 'right',
btns: [
{
permission: 'dict:save',
label: '修改',
type: 'text',
icon: 'ElEdit',
click: (row) => {
handleUpdate(row)
}
},
{
permission: 'dict:delete',
label: '删除',
type: 'text',
icon: 'ElDelete',
click: (row) => {
proxy.$common.handleDelete({
url: 'dict/delete',
id: row.id,
done: () => {
reloadTable()
proxy.$common.getDictData()
}
})
}
}
]
}
]
})
const dictId = ref('')
const temp = ref(getTemp())
const dialogTitle = ref('')
const rules = reactive({
dictType: [{ required: true, message: '请输入标签', trigger: 'change' }],
type: [{ required: true, message: '请输入类型', trigger: 'change' }],
sort: [{ required: true, message: '请输入排序', trigger: 'change' }],
descRibe: [{ required: true, message: '请输入描述', trigger: 'change' }]
})
const table = ref()
const dictDialog = ref()
const dataForm = ref()
function getTemp() {
return {
id: '',
dictType: '',
type: '',
sort: 0,
descRibe: '',
remarks: ''
}
}
function reloadTable() {
table.value.reload()
}
function getSort() {
proxy.$get('/system/dict/sort').then(res => {
temp.value.sort = res.data
})
}
function handleCreate() {
temp.value = getTemp()
getSort()
dialogTitle.value = '添加'
dictDialog.value.show()
nextTick(() => {
dataForm.value.clearValidate()
})
}
function save(d) {
dataForm.value.validate((valid) => {
if (valid) {
d.loading()
proxy.$post('/system/dict/save', temp.value).then((response) => {
d.hideLoading()
temp.value.id = response.data
dictDialog.value.hide()
proxy.$notify({
title: '成功',
message: dialogTitle.value + '成功',
type: 'success',
duration: 2000
})
reloadTable()
proxy.$common.getDictData()
}).catch(() => d.hideLoading())
}
})
}
function handleUpdate(row) {
proxy.$common.objAssign(temp.value, row)
dialogTitle.value = '修改'
dictDialog.value.show()
nextTick(() => {
dataForm.value.clearValidate()
})
}
</script>

View File

@ -1,7 +1,7 @@
export default function (bus, constants, $i, Message, request) {
return {
// svg text
getIcon: item => ['COMPONENT', '#9012FE'],
getIcon: item => ['Vue', '#41B883'],
// 任务名称
name: $i('component.name'),
// 脚本语言

View File

@ -34,6 +34,10 @@
detail: {
type: Object,
default: () => {}
},
primaryField: {
type: String,
default: 'id'
}
})
const emit = defineEmits(['reload'])
@ -87,7 +91,7 @@
d.hideLoading()
proxy.$notify({
title: '成功',
message: (!formData.value.id ? '创建' : '修改') + '成功',
message: (!formData.value[props.primaryField] ? '创建' : '修改') + '成功',
type: 'success',
duration: 2000
})
@ -102,8 +106,8 @@
}
function getDetail(id) {
formData.value.id = id
proxy.$get(props.detail.request.url, { id: id }).then(res => {
formData.value[props.primaryField] = id
proxy.$get(props.detail.request.url, { [props.primaryField]: id }).then(res => {
const { data } = res
for (var t in formData.value) {
if (data[t] && (!props.detail.excludeAssign || props.detail.excludeAssign.indexOf(t) === -1)) {

View File

@ -10,6 +10,7 @@
:append-to-body="true"
draggable
@open="$emit('open')"
@opened="opened"
@close="$emit('close')"
>
<slot name="content" />
@ -30,7 +31,7 @@
<script>
export default {
emits: ['confirm-click', 'open', 'close'],
emits: ['confirm-click', 'open', 'opened', 'close'],
props: {
title: {
type: String,
@ -53,7 +54,8 @@ export default {
return {
dialogVisible: false,
confirmLoading: false,
customClass: 'mbDialog' + this.$common.uuid()
customClass: 'mbDialog' + this.$common.uuid(),
isOpen: false
}
},
watch: {
@ -69,6 +71,10 @@ export default {
this.addStyle()
},
methods: {
opened(){
this.$emit('opened')
this.isOpen = true
},
confirmClick() {
this.$emit('confirm-click', this)
},
@ -78,8 +84,17 @@ export default {
hideLoading(){
this.confirmLoading = false
},
show() {
show(callback) {
this.dialogVisible = true
if(callback){
var callbackInterval = setInterval(() => {
if(this.isOpen){
this.isOpen = false
clearInterval(callbackInterval)
callback()
}
},1)
}
},
hide() {
this.dialogVisible = false

View File

@ -70,7 +70,7 @@ export default {
video: 'avi,flv,mp4,mpeg,mov'
},
imageUrl: '',
action: import.meta.env.VITE_APP_BASE_API + 'file/upload',
action: import.meta.env.VITE_APP_BASE_API + '/system/file/upload',
headers: {
token: getToken()
},
@ -137,7 +137,7 @@ export default {
this.$emit('update:modelValue', '')
this.$emit('change', '')
}
this.$delete('file/delete', { url: encodeURI(url) })
this.$delete('/system/file/delete', { url: encodeURI(url) })
},
handlePreview(file) {
window.open(this.$global.baseApi + file.response.data.url)

View File

@ -127,7 +127,7 @@ export default {
},
data() {
return {
action: import.meta.env.VITE_APP_BASE_API + 'file/upload',
action: import.meta.env.VITE_APP_BASE_API + '/system/file/upload',
headers: {
token: getToken()
},
@ -179,7 +179,7 @@ export default {
this.fileList.splice(i, 1)
}
})
this.$delete('file/delete', { url: encodeURI(url) })
this.$delete('/system/file/delete', { url: encodeURI(url) })
if (this.multiple) {
this.$emit('update:modelValue', this.urls)
this.$emit('change', this.urls)

View File

@ -54,10 +54,6 @@ import { ArrowDown } from '@element-plus/icons-vue'
import Tabs from './tabs.vue'
import Sidebar from './sidebar/sidebar.vue'
import { logout } from '@/scripts/auth'
import dynamicComponent from '@/scripts/dynamicComponent'
import { getCurrentInstance } from 'vue'
const { proxy } = getCurrentInstance()
dynamicComponent(getCurrentInstance().appContext.app)
</script>
<style scoped>

View File

@ -1,10 +1,5 @@
import * as vue from 'vue'
const libs = { vue }
window.___magic__import__ = function(lib, name){
return (libs[lib] || {})[name]
}
import { createApp } from 'vue'
import {createApp} from 'vue'
const app = createApp(App)
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
@ -16,13 +11,37 @@ import router from './scripts/router'
import components from '@/components/index'
import globalProperties from './scripts/globalProperties'
import hasPermission from './scripts/hasPermission'
import { appComponent } from './scripts/dynamicComponent'
import '@/permission'
import global from '@/scripts/global.js'
const libs = {
vue,
'element-plus': ElementPlus
}
window.___magic__import__ = function(lib, name){
return (libs[lib] || {})[name]
}
app.use(globalProperties)
var loadDynamicComponent = false
import { ElLoading } from 'element-plus'
document.title = global.title
router.beforeEach((to, from) => {
router.beforeEach(async (to, from) => {
global.tabValue.value = to.path
if((to.name && global.visitedViews.length === 0 || global.visitedViews.every(it => it.path !== to.path)) && !to.path.startsWith('/redirect') && !to.path.startsWith('/login')){
if(!loadDynamicComponent){
loadDynamicComponent = true
const loading = ElLoading.service({
lock: true,
background: 'rgba(255, 255, 255, 0)',
})
await app.config.globalProperties.$post('/system/component/list').then((res) => {
res.data.forEach(it => {
appComponent(app, it)
})
loading.close()
})
}
global.visitedViews.push(to)
}
global.visitedViews.forEach((it, i) => {
@ -32,7 +51,6 @@ router.beforeEach((to, from) => {
})
return true
})
app.use(globalProperties)
app.use(hasPermission)
app.use(components)
app.use(ElementPlus, {

View File

@ -1,42 +1,55 @@
import { babelParse } from '@vue/compiler-sfc'
import { compileFile } from '@/compiler/sfc-compiler.js'
import { ElLoading } from 'element-plus'
import { ElLoading, ElMessage } from 'element-plus'
function appComponent(app, item){
export function appComponent(app, item){
var compiled = {}
compileFile('TestCode.vue', item.code, compiled)
var code = compiled.js
var ast = babelParse(code, {
sourceType: 'module'
})
var replaceCode = (node, subCode) => code.substring(0, node.start) + subCode + code.substring(node.end);
for(var i = ast.program.body.length - 1; i>=0; i--){
var node = ast.program.body[i]
if(node.type === 'ImportDeclaration'){
code = replaceCode(node, node.specifiers.map(it => `const ${it.local?.name || it.imported?.name || '*'} = ___magic__import__('${node.source.value}', '${it.imported?.name || '*'}');`).join('\r\n'));
} else if (node.type === 'ExportDefaultDeclaration'){
code = replaceCode(node, `return ${node.declaration.name}`)
}
}
code = `(function(){
${code}
})()`
var componentStyle = document.createElement("style");
componentStyle.innerHTML = compiled.css
document.head.appendChild(componentStyle);
app.component(item.name, eval(code))
}
const install = (app) => {
const loading = ElLoading.service({
lock: true,
background: 'rgba(255, 255, 255, 0)',
})
app.config.globalProperties.$post('/system/component/list').then((res) => {
res.data.forEach(it => {
appComponent(app, it)
if(compiled.errors.length > 0){
ElMessage({
type: 'error',
duration: 0,
showClose: true,
message: `
组件${item.name}发生错误
${compiled.errors[0]}
`
})
loading.close()
})
throw compiled.errors[0]
}else{
var code = compiled.js
var ast = babelParse(code, {
sourceType: 'module'
})
var replaceCode = (node, subCode) => code.substring(0, node.start) + subCode + code.substring(node.end);
for(var i = ast.program.body.length - 1; i>=0; i--){
var node = ast.program.body[i]
if(node.type === 'ImportDeclaration'){
code = replaceCode(node, node.specifiers.map(it => `const ${it.local?.name || it.imported?.name || '*'} = ___magic__import__('${node.source.value}', '${it.imported?.name || '*'}');`).join('\r\n'));
} else if (node.type === 'ExportDefaultDeclaration'){
code = replaceCode(node, `return ${node.declaration.name}`)
}
}
code = `(function(){
${code}
})()`
var componentStyle = document.createElement("style");
componentStyle.innerHTML = compiled.css
document.head.appendChild(componentStyle);
app.component(item.name, eval(code))
}
}
export default install
//
// const install = (app) => {
// const loading = ElLoading.service({
// lock: true,
// background: 'rgba(255, 255, 255, 0)',
// })
// app.config.globalProperties.$post('/system/component/list').then((res) => {
// res.data.forEach(it => {
// appComponent(app, it)
// })
// loading.close()
// })
// }
// export default install

View File

@ -1,26 +1,26 @@
function gen(groupPath, data){
var permissionPrefix = groupPath.replace('/', ':')
var html = `
<template>
<mb-list ref="magicList" v-bind="listOptions" />
<mb-dialog ref="formDialog" @confirm-click="magicForm.save($event)" width="50%">
var permissionPrefix = groupPath.replace(/^\//,'').replace(/\/\//, '/').replace('/', ':')
var html = `<template>
<mb-list ref="magicList" v-bind="listOptions" />
<mb-dialog ref="formDialog" :title="magicFormTitle" @confirm-click="magicForm.save($event)" width="50%">
<template #content>
<mb-form ref="magicForm" @reload="magicList.reload" v-bind="formOptions" />
<mb-form ref="magicForm" @reload="magicList.reload" v-bind="formOptions" />
</template>
</mb-dialog>
</template>
<script setup>
import { ref, reactive, getCurrentInstance } from 'vue'
</mb-dialog>
</template>
<script setup>
import { ref, reactive, getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance()
const formDialog = ref()
const magicList = ref()
const magicForm = ref()
const magicFormTitle = ref()
const listOptions = reactive({
tools: [{
type: 'add',
permission: '${permissionPrefix}:save',
click: () => {
formOptions.detail.formData = null
magicFormTitle.value = '添加'
formDialog.value.show()
}
}],
@ -70,8 +70,8 @@ function gen(groupPath, data){
type: 'text',
icon: 'ElEdit',
click: (row) => {
magicForm.value.getDetail(row.id)
formDialog.value.show()
magicFormTitle.value = '修改'
formDialog.value.show(() => magicForm.value.getDetail(row.id))
}
}, {
permission: '${permissionPrefix}:delete',
@ -101,8 +101,7 @@ function gen(groupPath, data){
},
form: {
request: {
url: "${groupPath}/save",
method: "post"
url: "${groupPath}/save"
},
rows: [{
gutter: 24,
@ -110,11 +109,18 @@ function gen(groupPath, data){
for(var i in data){
var d = data[i]
if(d.save){
var props = ''
if(d.dictType){
props = `props: {
type: '${d.dictType}'
}`
}
html += `{
span: 12,
name: '${d.columnName}',
label: '${d.columnComment}',
${d.component}
${d.component},
${props}
},`
}
}
@ -123,8 +129,7 @@ function gen(groupPath, data){
}]
}
})
`
console.log(html)
</script>`
return html
}
export default gen

View File

@ -29,7 +29,7 @@
import { reactive, ref, getCurrentInstance } from 'vue'
import { login } from '@/scripts/auth'
const { proxy } = getCurrentInstance()
const codeImg = ref(import.meta.env.VITE_APP_BASE_API + '/security/verification/code')
const codeImg = ref()
const loginForm = reactive({
username: '',
password: '',

View File

@ -77,7 +77,7 @@
<el-icon><ElQuestionFilled /></el-icon>
</el-tooltip>
</template>
<el-button type="primary" @click="gen" style="margin-bottom: 10px">代码生成</el-button>
<el-button type="primary" @click="executeGen()" style="margin-bottom: 10px">代码生成</el-button>
</el-form-item>
</el-col>
</el-row>
@ -291,8 +291,27 @@
}
}])
function gen(){
genCode('test', genInfo.value.columns)
function executeGen(){
dataForm.value.validate((valid) => {
if (valid) {
var formData = {...genInfo.value}
formData.info = JSON.stringify(genInfo.value.info)
formData.columns = JSON.stringify(genInfo.value.columns)
formData.componentScript = genCode(genInfo.value.info.modulePath+genInfo.value.info.businessPath, genInfo.value.columns)
proxy.$post('/system/code/gen/execute', formData).then((res) => {
if(res.data == 1){
proxy.$notify({
title: '成功',
message: '生成成功',
type: 'success',
duration: 2000
})
}
})
}else{
proxy.$message.error('表单校验未通过,请重新检查提交内容')
}
})
}
function save(d){

View File

@ -1,5 +1,5 @@
<template>
<mb-tree ref="tree" :el="{ 'show-checkbox': true }" url="menu/tree" :search="true" search-width="230px" v-model:select-values="menus" />
<mb-tree ref="tree" :el="{ 'show-checkbox': true }" url="/system/menu/tree" :search="true" search-width="230px" v-model:select-values="menus" />
</template>
<script setup>

View File

@ -41,13 +41,13 @@
<el-row :gutter="24">
<el-col :span="12">
<el-form-item label="菜单权限" prop="menus">
<mb-tree ref="tree" :el="{ 'show-checkbox': true }" max-height="270px" url="menu/tree" :search="true" v-model:select-values="temp.menus" />
<mb-tree ref="tree" :el="{ 'show-checkbox': true }" max-height="270px" url="/system/menu/tree" :search="true" v-model:select-values="temp.menus" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="数据权限" prop="permission">
<mb-select v-model="temp.permission" :options="permissionData" />
<mb-tree v-if="temp.permission == 1" max-height="270px" :el="{ 'check-strictly': true, 'show-checkbox': true }" ref="office" url="office/tree" v-model:select-values="temp.offices" />
<mb-tree v-if="temp.permission == 1" max-height="270px" :el="{ 'check-strictly': true, 'show-checkbox': true }" ref="office" url="/system/office/tree" v-model:select-values="temp.offices" />
</el-form-item>
</el-col>
</el-row>

View File

@ -32,7 +32,7 @@
</el-col>
<el-col :span="12">
<el-form-item label="选择角色" prop="roles">
<mb-select v-model="temp.roles" url="role/all" placeholder="请选择角色" multiple />
<mb-select v-model="temp.roles" url="/system/role/all" placeholder="请选择角色" multiple />
</el-form-item>
</el-col>
</el-row>

View File

@ -14,7 +14,7 @@
<div class="app-container">
<div class="left">
<mb-tree
url="office/tree"
url="/system/office/tree"
:el="{ 'expand-on-click-node': false,'show-checkbox': true }"
:checked-ids="[tableOptions.where.officeId]"
:expand="false"
@ -38,7 +38,7 @@
<el-button v-permission="'user:save'" class="filter-item" type="primary" icon="ElEdit" @click="handleCreate">
添加
</el-button>
<mb-button v-permission="'user:delete'" :el="{ plain: true }" :request-url="'user/delete'" :btn-type="'delete'" :request-data="{ id: ids }" :after-handler="reloadTable" />
<mb-button v-permission="'user:delete'" :el="{ plain: true }" :request-url="'/system/user/delete'" :btn-type="'delete'" :request-data="{ id: ids }" :after-handler="reloadTable" />
</el-row>
<mb-table ref="table" v-bind="tableOptions" @selection-change="selectionChange" />