diff --git a/data/magic-api/api/后台/代码生成/group.json b/data/magic-api/api/后台/代码生成/group.json new file mode 100644 index 0000000..1db5a3b --- /dev/null +++ b/data/magic-api/api/后台/代码生成/group.json @@ -0,0 +1,10 @@ +{ + "properties" : { }, + "id" : "f2538e0f370a4cabab0ae920f5e77ae7", + "name" : "代码生成", + "type" : "api", + "parentId" : "02df51e4d7184780a98b632f43dc5848", + "path" : "/code/gen", + "paths" : [ ], + "options" : [ ] +} \ No newline at end of file diff --git a/data/magic-api/api/后台/代码生成/查出所有表.ms b/data/magic-api/api/后台/代码生成/查出所有表.ms new file mode 100644 index 0000000..d247a68 --- /dev/null +++ b/data/magic-api/api/后台/代码生成/查出所有表.ms @@ -0,0 +1,99 @@ +{ + "properties" : { }, + "id" : "6db309d3d6d0461c97419641849a99b4", + "script" : null, + "groupId" : "f2538e0f370a4cabab0ae920f5e77ae7", + "name" : "查出所有表", + "createTime" : null, + "updateTime" : 1647561263994, + "lock" : null, + "createBy" : null, + "updateBy" : null, + "path" : "/tables", + "method" : "GET", + "parameters" : [ ], + "options" : [ ], + "requestBody" : null, + "headers" : [ ], + "paths" : [ ], + "responseBody" : "{\n \"code\": 402,\n \"message\": \"凭证已过期\",\n \"data\": null,\n \"timestamp\": 1647561224202,\n \"executeTime\": null\n}", + "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" : "1647561224202", + "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.select(""" + select table_name, table_comment from information_schema.tables where table_schema = database() +""") \ No newline at end of file diff --git a/data/magic-api/api/后台/代码生成/根据表名查出所有列.ms b/data/magic-api/api/后台/代码生成/根据表名查出所有列.ms new file mode 100644 index 0000000..93be3ef --- /dev/null +++ b/data/magic-api/api/后台/代码生成/根据表名查出所有列.ms @@ -0,0 +1,207 @@ +{ + "properties" : { }, + "id" : "98367deee5714ede88c1e134b16bebeb", + "script" : null, + "groupId" : "f2538e0f370a4cabab0ae920f5e77ae7", + "name" : "根据表名查出所有列", + "createTime" : null, + "updateTime" : 1647564370396, + "lock" : null, + "createBy" : null, + "updateBy" : null, + "path" : "/columns", + "method" : "GET", + "parameters" : [ { + "name" : "tableName", + "value" : "sys_user", + "description" : null, + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + } ], + "options" : [ ], + "requestBody" : "", + "headers" : [ ], + "paths" : [ ], + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": {\n \"columns\": [{\n \"columnName\": \"username\",\n \"columnComment\": \"登录名\",\n \"dataType\": \"varchar\"\n }, {\n \"columnName\": \"name\",\n \"columnComment\": \"姓名/昵称\",\n \"dataType\": \"varchar\"\n }, {\n \"columnName\": \"password\",\n \"columnComment\": \"密码\",\n \"dataType\": \"varchar\"\n }, {\n \"columnName\": \"status\",\n \"columnComment\": \"状态\",\n \"dataType\": \"char\"\n }, {\n \"columnName\": \"phone\",\n \"columnComment\": \"手机号\",\n \"dataType\": \"varchar\"\n }, {\n \"columnName\": \"head_portrait\",\n \"columnComment\": \"头像\",\n \"dataType\": \"varchar\"\n }, {\n \"columnName\": \"is_login\",\n \"columnComment\": \"禁止登录:0未禁用,1已禁用\",\n \"dataType\": \"int\"\n }, {\n \"columnName\": \"sort\",\n \"columnComment\": \"排序\",\n \"dataType\": \"int\"\n }, {\n \"columnName\": \"office_id\",\n \"columnComment\": \"组织机构id\",\n \"dataType\": \"varchar\"\n }],\n \"primary\": {\n \"columnName\": \"id\"\n }\n },\n \"timestamp\": 1647564344902,\n \"executeTime\": 34\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" : "columns", + "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" : "columnName", + "value" : "username", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "columnComment", + "value" : "登录名", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "dataType", + "value" : "varchar", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } ] + }, { + "name" : "primary", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "columnName", + "value" : "id", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } ] + }, { + "name" : "timestamp", + "value" : "1647564344902", + "description" : "", + "required" : false, + "dataType" : "Long", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "executeTime", + "value" : "34", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } +} +================================ +return { + columns: db.select(""" + SELECT + column_name, + column_comment, + data_type + FROM + information_schema.COLUMNS + WHERE + table_name = #{tableName} + AND column_name NOT IN ( 'id', 'is_del', 'create_by', 'create_date', 'update_by', 'update_date' ) + AND table_schema = DATABASE() + """), + primary: db.selectValue("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = #{tableName} and column_key = 'PRI' and table_schema = database()") +} \ No newline at end of file diff --git a/magic-boot-ui/src/views/examples/editor-table.vue b/magic-boot-ui/src/views/examples/editor-table.vue index c6d95ed..92f3a38 100644 --- a/magic-boot-ui/src/views/examples/editor-table.vue +++ b/magic-boot-ui/src/views/examples/editor-table.vue @@ -6,31 +6,145 @@ </div> </template> -<script> +<script setup> +import { reactive,getCurrentInstance } from 'vue' +import genCode from '@/scripts/gen/gen-mb-list.js' +const { proxy } = getCurrentInstance() +const tableDatas = reactive([]) -export default { - name: 'EditorTable', - data() { - return { - tableDatas: [], - cols: [{ - type: 'input', - field: 'name', - title: '名称' - }, { - type: 'select', - field: 'role', - title: '角色', - properties: { - type: 'dict_type' - } - }] - } - }, - methods: { - getData() { - console.log(this.tableDatas) - } +proxy.$get('/code/gen/columns', { tableName: 'sys_user' }).then(res => { + var columns = res.data.columns + var primary = res.data.primary + columns.forEach(it => { + tableDatas.push({ + columnName: it.columnName, + columnComment: it.columnComment, + dataType: it.dataType + }) + }) + console.log(tableDatas) +}) + +const cols = reactive([{ + field: 'columnName', + label: '列名' +}, { + field: 'columnComment', + label: '列说明', + component: 'input' +}, { + field: 'dataType', + label: '字段类型' +}, { + field: 'save', + label: '保存', + component: 'switch', + width: '80px' +}, { + field: 'list', + label: '列表', + component: 'switch', + width: '80px' +}, { + field: 'query', + label: '查询', + component: 'switch', + width: '80px' +}, { + field: 'where', + label: '匹配方式', + component: 'select', + props: { + options: [{ + label: '=', + value: '=' + },{ + label: '!=', + value: '!=' + },{ + label: '>', + value: '>' + },{ + label: '>=', + value: '>=' + },{ + label: '<', + value: '<' + },{ + label: '<=', + value: '<=' + },{ + label: 'Between', + value: 'Between' + },{ + label: 'Like', + value: 'Like' + },{ + label: '左Like', + value: '左Like' + },{ + label: '右Like', + value: '右Like' + }] } +}, { + field: 'required', + label: '必填', + component: 'switch', + width: '80px' +}, { + field: 'component', + label: '控件类型', + component: 'select', + props: { + options: [{ + label: '单行文本框', + value: 'input' + },{ + label: '多行文本框', + value: 'textarea' + },{ + label: '单选下拉框', + value: 'radioSelect' + },{ + label: '多选下拉框', + value: 'multipleSelect' + },{ + label: '单选按钮', + value: 'radio' + },{ + label: '复选框', + value: 'checkbox' + },{ + label: '日期选择', + value: 'date' + },{ + label: '日期时间', + value: 'datetime' + },{ + label: '图片上传', + value: 'uploadImage' + },{ + label: '文件上传', + value: 'uploadFile' + }] + } +}, { + component: 'select', + field: 'dictType', + label: '字典类型', + props: { + url: 'dict/all', + showValue: true + } +}]) + +function gen(){ + genCode('user', tableDatas) } + +function getData(){ + console.log(tableDatas) +} + </script> diff --git a/magic-boot-ui/src/views/lowcode/code-gen-form.vue b/magic-boot-ui/src/views/lowcode/code-gen-form.vue new file mode 100644 index 0000000..efd248b --- /dev/null +++ b/magic-boot-ui/src/views/lowcode/code-gen-form.vue @@ -0,0 +1,27 @@ +<template> + <el-tabs v-model="activeName" @tab-click="handleClick"> + <el-tab-pane label="基本信息" name="basic"> + <el-row :gutter="24"> + <el-col :span="24"> + <el-form-item label="分组名称"> + <el-input v-model="formData.groupName"></el-input> + </el-form-item> + </el-col> + </el-row> + </el-tab-pane> + <el-tab-pane label="字段信息" name="field"> + + </el-tab-pane> + <el-tab-pane label="生成信息" name="gen"> + + </el-tab-pane> + </el-tabs> +</template> + +<script setup> + import {reactive, ref} from 'vue' + const activeName = ref('basic') + const formData = reactive({ + groupName: '' + }) +</script> diff --git a/magic-boot-ui/src/views/lowcode/code-gen-list.vue b/magic-boot-ui/src/views/lowcode/code-gen-list.vue new file mode 100644 index 0000000..41c7514 --- /dev/null +++ b/magic-boot-ui/src/views/lowcode/code-gen-list.vue @@ -0,0 +1,66 @@ +<template> + <mb-list ref="magicList" v-bind="listOptions" /> + <mb-dialog ref="formDialog" title="配置" @confirm-click="magicForm.save($event)" width="50%"> + <template #content> + <code-gen-form /> + </template> + </mb-dialog> +</template> + +<script setup> + import codeGenForm from './code-gen-form.vue' + import { ref, reactive, getCurrentInstance } from 'vue' + const { proxy } = getCurrentInstance() + const formDialog = ref() + const magicList = ref() + const magicForm = ref() + const listOptions = reactive({ + tools: [{ + type: 'add', + permission: 'code:gen:save', + click: () => { + formDialog.value.show() + } + }], + table: { + url: 'code/gen/list', + cols: [ + { + field: 'tableName', + label: '表名' + },{ + field: 'tableComment', + label: '描述' + }, { + label: '操作', + type: 'btns', + width: 140, + fixed: 'right', + btns: [ + { + permission: 'code:gen:save', + label: '修改', + type: 'text', + icon: 'ElEdit', + click: (row) => { + formDialog.value.show() + } + }, { + permission: 'code:gen:delete', + label: '删除', + type: 'text', + icon: 'ElDelete', + click: (row) => { + // proxy.$common.handleDelete({ + // url: 'user/delete', + // id: row.id, + // done: () => magicList.value.reload() + // }) + } + } + ] + } + ] + } + }) +</script>