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

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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"properties" : { },
"id" : "20316fcfa94644d685fa1b464f135f9a",
"id" : "8d60ba6788ef4a75b93f3c77683c7f89",
"name" : "数据管理",
"type" : "api",
"parentId" : "0",
@@ -1,9 +1,9 @@
{
"properties" : { },
"id" : "152b9ad78aaf49a7a8945b5de088c1da",
"id" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "测试生成",
"type" : "api",
"parentId" : "20316fcfa94644d685fa1b464f135f9a",
"parentId" : "8d60ba6788ef4a75b93f3c77683c7f89",
"path" : "/test",
"paths" : [ ],
"options" : [ ]
@@ -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)
@@ -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
""")
@@ -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,
@@ -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,
@@ -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
@@ -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",
@@ -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
@@ -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})`
})
}
@@ -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}}")
@@ -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();
@@ -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){
@@ -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){
@@ -1,10 +1,10 @@
{
"properties" : { },
"id" : "9bf92d503f4242d39a0f271c577aa3ac",
"name" : "系统管理",
"id" : "55ff62aa20144b7bb5c6dfb5d76c8139",
"name" : "数据管理",
"type" : "component",
"parentId" : "0",
"path" : "sys",
"path" : "/data",
"paths" : [ ],
"options" : [ ]
}
@@ -0,0 +1,10 @@
{
"properties" : { },
"id" : "eb5dbed949de4f50ba4bf59f483252a5",
"name" : "测试生成",
"type" : "component",
"parentId" : "55ff62aa20144b7bb5c6dfb5d76c8139",
"path" : "/test",
"paths" : [ ],
"options" : [ ]
}
@@ -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>
@@ -1,10 +0,0 @@
{
"properties" : { },
"id" : "6bee7576eea04963a573b21bb657784d",
"name" : "字典管理",
"type" : "component",
"parentId" : "9bf92d503f4242d39a0f271c577aa3ac",
"path" : "dict",
"paths" : [ ],
"options" : [ ]
}
@@ -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>