Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
98f12a4a
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
9 个月 前同步成功
通知
324
Star
18154
Fork
5505
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
98f12a4a
编写于
3月 25, 2020
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
代码生成器模板
上级
5661281e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
126 addition
and
3 deletion
+126
-3
QMPlusServer/model/autoCodeModel/autoCode.go
QMPlusServer/model/autoCodeModel/autoCode.go
+75
-2
QMPlusServer/model/autoCodeModel/autoCode_test.go
QMPlusServer/model/autoCodeModel/autoCode_test.go
+7
-0
QMPlusServer/tpl/te/struct.go.tpl
QMPlusServer/tpl/te/struct.go.tpl
+36
-0
QMPlusVuePage/src/view/superAdmin/autoCode/component/componentDialog.vue
...rc/view/superAdmin/autoCode/component/componentDialog.vue
+3
-0
QMPlusVuePage/src/view/superAdmin/autoCode/index.vue
QMPlusVuePage/src/view/superAdmin/autoCode/index.vue
+5
-1
未找到文件。
QMPlusServer/model/autoCodeModel/autoCode.go
浏览文件 @
98f12a4a
package
autoCodeModel
import
(
"fmt"
log
"gin-vue-admin/init/initlog"
"html/template"
"os"
)
//开发中功能,若您发现这块代码可以研究,可以无视
type
AutoCodeStruct
struct
{
StructName
string
`json:"structName"`
Components
[]
Component
`json:"components"`
StructName
string
`json:"structName"`
PackageName
string
`json:"packageName"`
Abbreviation
string
`json:"abbreviation"`
Components
[]
Component
`json:"components"`
}
type
Component
struct
{
ComponentName
string
`json:"componentName"`
ComponentType
string
`json:"componentType"`
ComponentJson
string
`json:"componentJson"`
Ismultiple
bool
`json:"isMultiple"`
ComponentShowType
string
`json:"componentShowType"`
NideDictionary
bool
`json:"nideDictionary"`
...
...
@@ -20,3 +30,66 @@ type Dictionary struct {
Label
string
`json:"label"`
Value
string
`json:"value"`
}
func
Temp
()
{
tmpl
,
err
:=
template
.
ParseFiles
(
"../../tpl/te/struct.go.tpl"
)
fmt
.
Println
(
tmpl
,
err
)
a1
:=
Component
{
ComponentName
:
"TestComponent"
,
ComponentType
:
"string"
,
ComponentJson
:
"testComponent"
,
Ismultiple
:
false
,
ComponentShowType
:
""
,
NideDictionary
:
false
,
DictionaryName
:
""
,
ComponentDictionary
:
nil
,
}
a2
:=
Component
{
ComponentName
:
"TestBigComponent"
,
ComponentType
:
"int"
,
ComponentJson
:
"testBigComponent"
,
Ismultiple
:
false
,
ComponentShowType
:
""
,
NideDictionary
:
false
,
DictionaryName
:
""
,
ComponentDictionary
:
nil
,
}
a
:=
AutoCodeStruct
{
StructName
:
"Test"
,
PackageName
:
"autocode"
,
Components
:
[]
Component
{
a1
,
a2
},
}
_dir
:=
"../"
+
a
.
PackageName
exist
,
err
:=
pathExists
(
_dir
)
if
err
!=
nil
{
log
.
L
.
Info
(
"get dir error![%v]
\n
"
,
err
)
return
}
if
exist
{
log
.
L
.
Info
(
"has dir![%v]
\n
"
,
_dir
)
}
else
{
log
.
L
.
Info
(
"no dir![%v]
\n
"
,
_dir
)
// 创建文件夹
err
:=
os
.
Mkdir
(
_dir
,
os
.
ModePerm
)
if
err
!=
nil
{
log
.
L
.
Error
(
"mkdir failed![%v]
\n
"
,
err
)
}
else
{
log
.
L
.
Info
(
"mkdir success!
\n
"
)
}
}
file
,
err
:=
os
.
OpenFile
(
"../"
+
a
.
PackageName
+
"/struct.go"
,
os
.
O_CREATE
|
os
.
O_WRONLY
,
0755
)
err
=
tmpl
.
Execute
(
file
,
a
)
}
// 判断文件夹是否存在
func
pathExists
(
path
string
)
(
bool
,
error
)
{
_
,
err
:=
os
.
Stat
(
path
)
if
err
==
nil
{
return
true
,
nil
}
if
os
.
IsNotExist
(
err
)
{
return
false
,
nil
}
return
false
,
err
}
QMPlusServer/model/autoCodeModel/autoCode_test.go
0 → 100644
浏览文件 @
98f12a4a
package
autoCodeModel
import
"testing"
func
TestTemp
(
t
*
testing
.
T
)
{
Temp
()
}
QMPlusServer/tpl/te/struct.go.tpl
0 → 100644
浏览文件 @
98f12a4a
// 自动生成模板{{.StructName}}
package {{.PackageName}}
import (
"gin-vue-admin/controller/servers"
"gin-vue-admin/init/qmsql"
"gin-vue-admin/model/modelInterface"
"github.com/jinzhu/gorm"
"github.com/pkg/errors"
)
type {{.StructName}} struct {
gorm.Model {
{
range
.
Components
}
}
{{.ComponentName}} {{.ComponentType}} `json:"{{.ComponentJson}}"` {{ end }}
}
// 创建{{.StructName}}
func ({{.Abbreviation}} *{
{
StructName
}
})Create{{.StructName}}()(err error){
err = qmsql.DEFAULTDB.Create({{.Abbreviation}}).Error
return err
}
// 删除{{.StructName}}
func ({{.Abbreviation}} *{
{
StructName
}
})Delete{{.StructName}}()(err error){
err = qmsql.DEFAULTDB.Delete({{.Abbreviation}}).Error
return err
}
// 更新{{.StructName}}
func ({{.Abbreviation}} *{
{
StructName
}
})Update{{.StructName}}()(err error, re{{.Abbreviation}} {{.StructName}}){
}
func ({{.Abbreviation}} *{
{
StructName
}
})Create(){
}
\ No newline at end of file
QMPlusVuePage/src/view/superAdmin/autoCode/component/componentDialog.vue
浏览文件 @
98f12a4a
...
...
@@ -4,6 +4,9 @@
<el-form-item
label=
"组件名称"
label-width=
"80"
:span=
"8"
>
<el-input
v-model=
"dialogMiddle.componentName"
autocomplete=
"off"
></el-input>
</el-form-item>
<el-form-item
label=
"组件JSON"
label-width=
"80"
:span=
"8"
>
<el-input
v-model=
"dialogMiddle.componentJson"
autocomplete=
"off"
></el-input>
</el-form-item>
<el-form-item
label=
"数据类型"
label-width=
"80"
:span=
"8"
>
<el-select
v-model=
"dialogMiddle.componentType"
placeholder=
"请选择活动区域"
>
<el-option
...
...
QMPlusVuePage/src/view/superAdmin/autoCode/index.vue
浏览文件 @
98f12a4a
...
...
@@ -7,6 +7,9 @@
<el-form-item
label=
"Struct名称"
:span=
"8"
>
<el-input
v-model=
"form.structName"
></el-input>
</el-form-item>
<el-form-item
label=
"Package名称"
:span=
"8"
>
<el-input
v-model=
"form.packageName"
></el-input>
</el-form-item>
<!--
<el-form-item
label=
"结构类型"
:span=
"8"
>
<el-select
v-model=
"form.structType"
multiple
placeholder=
"请选择结构类型(多选)"
>
<el-option
...
...
@@ -101,7 +104,8 @@ export default {
addFlag
:
""
,
form
:{
structName
:
""
,
structType
:[],
packageName
:
""
,
components
:[]
},
options
:[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录