Skip to content

Commit 8ef4f40

Browse files
pixelmaxQmSliverHorn
and
SliverHorn
authored
feat: 优化自动化代码结构,增加顶栏侧边栏组合式结构 (#1793)
* feature:增加顶栏组合模式。 * Update: 1. request.go.tpl and model.go.tpl indent problem 2. api.go.tpl, request.go.tpl, service.go.tpl struct {} * Update: 1. model.go.tpl import blank line * feature:增加顶栏组合模式。 * feature:增加左侧检测逻辑保证存在左侧菜单。 --------- Co-authored-by: SliverHorn <[email protected]>
1 parent 01139a2 commit 8ef4f40

File tree

13 files changed

+300
-89
lines changed

13 files changed

+300
-89
lines changed

server/resource/autocode_template/server/api.go.tpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import (
1313
{{- end }}
1414
)
1515

16-
type {{.StructName}}Api struct {
17-
}
16+
type {{.StructName}}Api struct {}
1817

1918
var {{.Abbreviation}}Service = service.ServiceGroupApp.{{.PackageT}}ServiceGroup.{{.StructName}}Service
2019

server/resource/autocode_template/server/model.go.tpl

+41-32
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,55 @@
22
package {{.Package}}
33

44
import (
5-
{{ if .GvaModel }}"github.com/flipped-aurora/gin-vue-admin/server/global"{{ end }}
6-
{{ if or .HasTimer }}"time"{{ end }}
7-
{{ if .NeedJSON }}"gorm.io/datatypes"{{ end }}
5+
{{- if .GvaModel }}
6+
"github.com/flipped-aurora/gin-vue-admin/server/global"
7+
{{- end }}
8+
{{- if or .HasTimer }}
9+
"time"
10+
{{- end }}
11+
{{- if .NeedJSON }}
12+
"gorm.io/datatypes"
13+
{{- end }}
814
)
915

1016
// {{.Description}} 结构体 {{.StructName}}
1117
type {{.StructName}} struct {
12-
{{ if .GvaModel }} global.GVA_MODEL {{ end }}
13-
{{- range .Fields}}
14-
{{- if eq .FieldType "enum" }}
15-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};type:enum({{.DataTypeLong}});comment:{{.Comment}};" {{- if .Require }} binding:"required"{{- end -}}`
16-
{{- else if eq .FieldType "picture" }}
17-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
18-
{{- else if eq .FieldType "video" }}
19-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
20-
{{- else if eq .FieldType "file" }}
21-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}} swaggertype:"array,object"`
22-
{{- else if eq .FieldType "pictures" }}
23-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}} swaggertype:"array,object"`
24-
{{- else if eq .FieldType "richtext" }}
25-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}}`
26-
{{- else if eq .FieldType "json" }}
27-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}} swaggertype:"object"`
28-
{{- else if eq .FieldType "array" }}
29-
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}} swaggertype:"array,object"`
30-
{{- else if ne .FieldType "string" }}
31-
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
32-
{{- else }}
33-
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
34-
{{- end }} {{ if .FieldDesc }}//{{.FieldDesc}} {{ end }} {{- end }}
35-
{{- if .AutoCreateResource }}
36-
CreatedBy uint `gorm:"column:created_by;comment:创建者"`
37-
UpdatedBy uint `gorm:"column:updated_by;comment:更新者"`
38-
DeletedBy uint `gorm:"column:deleted_by;comment:删除者"`
39-
{{- end}}
18+
{{- if .GvaModel }}
19+
global.GVA_MODEL
20+
{{- end }}
21+
{{- range .Fields}}
22+
{{- if eq .FieldType "enum" }}
23+
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};type:enum({{.DataTypeLong}});comment:{{.Comment}};" {{- if .Require }} binding:"required"{{- end -}}`
24+
{{- else if eq .FieldType "picture" }}
25+
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
26+
{{- else if eq .FieldType "video" }}
27+
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
28+
{{- else if eq .FieldType "file" }}
29+
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}} swaggertype:"array,object"`
30+
{{- else if eq .FieldType "pictures" }}
31+
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}} swaggertype:"array,object"`
32+
{{- else if eq .FieldType "richtext" }}
33+
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}}`
34+
{{- else if eq .FieldType "json" }}
35+
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}} swaggertype:"object"`
36+
{{- else if eq .FieldType "array" }}
37+
{{.FieldName}} datatypes.JSON `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}type:text;" {{- if .Require }} binding:"required"{{- end -}} swaggertype:"array,object"`
38+
{{- else if ne .FieldType "string" }}
39+
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
40+
{{- else }}
41+
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"{{- if ne .FieldIndexType "" -}}{{ .FieldIndexType }};{{- end -}}{{- if .PrimaryKey -}}primarykey;{{- end -}}{{- if .DefaultValue -}}default:{{ .DefaultValue }};{{- end -}}column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}" {{- if .Require }} binding:"required"{{- end -}}`
42+
{{- end }} {{ if .FieldDesc }}//{{.FieldDesc}} {{ end }}
43+
{{- end }}
44+
{{- if .AutoCreateResource }}
45+
CreatedBy uint `gorm:"column:created_by;comment:创建者"`
46+
UpdatedBy uint `gorm:"column:updated_by;comment:更新者"`
47+
DeletedBy uint `gorm:"column:deleted_by;comment:删除者"`
48+
{{- end }}
4049
}
4150

4251
{{ if .TableName }}
4352
// TableName {{.Description}} {{.StructName}}自定义表名 {{.TableName}}
4453
func ({{.StructName}}) TableName() string {
45-
return "{{.TableName}}"
54+
return "{{.TableName}}"
4655
}
4756
{{ end }}

server/resource/autocode_template/server/request.go.tpl

+25-25
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@ import (
66
)
77

88
type {{.StructName}}Search struct{
9-
{{ if .GvaModel }}
10-
StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"`
11-
EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
12-
{{ end }}
13-
{{- range .Fields}}
14-
{{- if ne .FieldSearchType ""}}
15-
{{- if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
16-
Start{{.FieldName}} *{{.FieldType}} `json:"start{{.FieldName}}" form:"start{{.FieldName}}"`
17-
End{{.FieldName}} *{{.FieldType}} `json:"end{{.FieldName}}" form:"end{{.FieldName}}"`
18-
{{- else }}
19-
{{- if eq .FieldType "enum" }}
20-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}"`
21-
{{- else if eq .FieldType "picture" }}
22-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
23-
{{- else if eq .FieldType "video" }}
24-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
25-
{{- else if eq .FieldType "richtext" }}
26-
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
27-
{{- else if ne .FieldType "string" }}
28-
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
29-
{{- else }}
30-
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
31-
{{- end }}
9+
{{- if .GvaModel }}
10+
StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"`
11+
EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
12+
{{- end }}
13+
{{- range .Fields}}
14+
{{- if ne .FieldSearchType ""}}
15+
{{- if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
16+
Start{{.FieldName}} *{{.FieldType}} `json:"start{{.FieldName}}" form:"start{{.FieldName}}"`
17+
End{{.FieldName}} *{{.FieldType}} `json:"end{{.FieldName}}" form:"end{{.FieldName}}"`
18+
{{- else }}
19+
{{- if eq .FieldType "enum" }}
20+
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}"`
21+
{{- else if eq .FieldType "picture" }}
22+
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
23+
{{- else if eq .FieldType "video" }}
24+
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
25+
{{- else if eq .FieldType "richtext" }}
26+
{{.FieldName}} string `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
27+
{{- else if ne .FieldType "string" }}
28+
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
29+
{{- else }}
30+
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" `
3231
{{- end }}
33-
{{- end}}
34-
{{- end }}
32+
{{- end }}
33+
{{- end}}
34+
{{- end }}
3535
request.PageInfo
3636
{{- if .NeedSort}}
3737
Sort string `json:"sort" form:"sort"`

server/resource/autocode_template/server/router.go.tpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"github.com/gin-gonic/gin"
77
)
88

9-
type {{.StructName}}Router struct {
10-
}
9+
type {{.StructName}}Router struct {}
1110

1211
// Init{{.StructName}}Router 初始化 {{.Description}} 路由信息
1312
func (s *{{.StructName}}Router) Init{{.StructName}}Router(Router *gin.RouterGroup,PublicRouter *gin.RouterGroup) {

server/resource/autocode_template/server/service.go.tpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
{{- end}}
1010
)
1111

12-
type {{.StructName}}Service struct {
13-
}
12+
type {{.StructName}}Service struct {}
1413

1514
{{- $db := "" }}
1615
{{- if eq .BusinessDB "" }}

web/src/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"grey":false,
33
"primaryColor":"#3b82f6",
44
"showTabs":true,
5-
"darkMode":"auto",
5+
"darkMode":"dark",
66
"layout_side_width":200,
77
"layout_side_collapsed_width":60,
88
"layout_side_item_height":44,

web/src/pinia/modules/router.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { asyncRouterHandle } from '@/utils/asyncRouter'
22
import { emitter } from '@/utils/bus.js'
33
import { asyncMenu } from '@/api/menu'
44
import { defineStore } from 'pinia'
5-
import { ref } from 'vue'
5+
import { ref,watchEffect,onMounted } from 'vue'
66

77
const notLayoutRouterArr = []
88
const keepAliveRoutersArr = []
@@ -56,6 +56,46 @@ export const useRouterStore = defineStore('router', () => {
5656
emitter.on('setKeepAlive', setKeepAliveRouters)
5757

5858
const asyncRouters = ref([])
59+
60+
const topMenu = ref([])
61+
62+
const leftMenu = ref([])
63+
64+
const menuMap = {}
65+
66+
const topActive = ref("")
67+
68+
69+
70+
71+
72+
const setLeftMenu = (name) => {
73+
sessionStorage.setItem('topActive', name)
74+
topActive.value = name
75+
if(menuMap[name]?.children){
76+
leftMenu.value = menuMap[name].children
77+
}
78+
return menuMap[name]?.children
79+
}
80+
81+
watchEffect(()=>{
82+
let topActive = sessionStorage.getItem("topActive")
83+
let firstHasChildren = ''
84+
asyncRouters.value[0]?.children.forEach((item) => {
85+
if (item.hidden) return;
86+
menuMap[item.name] = item;
87+
if (!firstHasChildren && item.children && item.children.length > 0) {
88+
firstHasChildren = item.name
89+
}
90+
topMenu.value.push({...item, children: []})
91+
});
92+
93+
if(!menuMap[topActive]?.children && firstHasChildren){
94+
topActive = firstHasChildren
95+
}
96+
setLeftMenu(topActive)
97+
})
98+
5999
const routeMap = ({})
60100
// 从后台获取动态路由
61101
const SetAsyncRouter = async() => {
@@ -93,6 +133,10 @@ export const useRouterStore = defineStore('router', () => {
93133
}
94134

95135
return {
136+
topActive,
137+
setLeftMenu,
138+
topMenu,
139+
leftMenu,
96140
asyncRouters,
97141
keepAliveRouters,
98142
asyncRouterFlag,

web/src/style/element_visiable.scss

+13-5
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,22 @@
9393
@apply my-1;
9494
}
9595
}
96-
.el-menu-item{
97-
border-radius: 2px;
98-
&.is-active{
99-
background-color: var(--el-color-primary) !important;
100-
color: #fff !important;
96+
.el-menu--vertical{
97+
.el-menu-item{
98+
border-radius: 2px;
99+
&.is-active{
100+
background-color: var(--el-color-primary) !important;
101+
color: #fff !important;
102+
}
101103
}
102104
}
103105

106+
107+
.el-sub-menu.el-sub-menu__hide-arrow{
108+
height: 44px;
109+
}
110+
111+
104112
.el-tabs__header{
105113
margin: 0 0 1px !important;
106114
}

0 commit comments

Comments
 (0)