Skip to content

Commit 90549a0

Browse files
committed
feature:自动化增加前端可控显隐和自定义class。
1 parent 17d3639 commit 90549a0

File tree

4 files changed

+84
-88
lines changed

4 files changed

+84
-88
lines changed

server/model/system/sys_auto_code.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type AutoCodeStruct struct {
3434
HasRichText bool `json:"-"`
3535
HasFile bool `json:"-"`
3636
NeedJSON bool `json:"-"`
37+
FrontFields []*Field `json:"-"`
3738
}
3839

3940
func (a *AutoCodeStruct) Pretreatment() {
@@ -67,6 +68,8 @@ type Field struct {
6768
ColumnName string `json:"columnName"` // 数据库字段
6869
FieldSearchType string `json:"fieldSearchType"` // 搜索条件
6970
DictType string `json:"dictType"` // 字典
71+
Front bool `json:"front"` // 是否前端可见
72+
Class string `json:"class"` // 前端样式类
7073
Require bool `json:"require"` // 是否必填
7174
DefaultValue string `json:"defaultValue"` // 是否必填
7275
ErrorText string `json:"errorText"` // 校验失败文字

server/service/system/sys_auto_code.go

Lines changed: 54 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -133,50 +133,7 @@ var AutoCodeServiceApp = new(AutoCodeService)
133133
// @return: map[string]string, error
134134

135135
func (autoCodeService *AutoCodeService) PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) {
136-
makeDictTypes(&autoCode)
137-
for i := range autoCode.Fields {
138-
if autoCode.Fields[i].FieldType == "time.Time" {
139-
autoCode.HasTimer = true
140-
if autoCode.Fields[i].FieldSearchType != "" {
141-
autoCode.HasSearchTimer = true
142-
}
143-
}
144-
if autoCode.Fields[i].Sort {
145-
autoCode.NeedSort = true
146-
}
147-
if autoCode.Fields[i].FieldType == "picture" {
148-
autoCode.HasPic = true
149-
}
150-
if autoCode.Fields[i].FieldType == "video" {
151-
autoCode.HasPic = true
152-
}
153-
if autoCode.Fields[i].FieldType == "richtext" {
154-
autoCode.HasRichText = true
155-
}
156-
if autoCode.Fields[i].FieldType == "pictures" {
157-
autoCode.HasPic = true
158-
autoCode.NeedJSON = true
159-
}
160-
if autoCode.Fields[i].FieldType == "file" {
161-
autoCode.HasFile = true
162-
autoCode.NeedJSON = true
163-
}
164-
165-
if autoCode.GvaModel {
166-
autoCode.PrimaryField = &system.Field{
167-
FieldName: "ID",
168-
FieldType: "uint",
169-
FieldDesc: "ID",
170-
FieldJson: "ID",
171-
DataTypeLong: "20",
172-
Comment: "主键ID",
173-
ColumnName: "id",
174-
}
175-
}
176-
if !autoCode.GvaModel && autoCode.PrimaryField == nil && autoCode.Fields[i].PrimaryKey {
177-
autoCode.PrimaryField = autoCode.Fields[i]
178-
}
179-
}
136+
fmtField(&autoCode)
180137
dataList, _, needMkdir, err := autoCodeService.getNeedList(&autoCode)
181138
if err != nil {
182139
return nil, err
@@ -255,49 +212,7 @@ func makeDictTypes(autoCode *system.AutoCodeStruct) {
255212
// @return: err error
256213

257214
func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruct, menuID uint, ids ...uint) (err error) {
258-
makeDictTypes(&autoCode)
259-
for i := range autoCode.Fields {
260-
if autoCode.Fields[i].FieldType == "time.Time" {
261-
autoCode.HasTimer = true
262-
if autoCode.Fields[i].FieldSearchType != "" {
263-
autoCode.HasSearchTimer = true
264-
}
265-
}
266-
if autoCode.Fields[i].Sort {
267-
autoCode.NeedSort = true
268-
}
269-
if autoCode.Fields[i].FieldType == "picture" {
270-
autoCode.HasPic = true
271-
}
272-
if autoCode.Fields[i].FieldType == "video" {
273-
autoCode.HasPic = true
274-
}
275-
if autoCode.Fields[i].FieldType == "richtext" {
276-
autoCode.HasRichText = true
277-
}
278-
if autoCode.Fields[i].FieldType == "pictures" {
279-
autoCode.NeedJSON = true
280-
autoCode.HasPic = true
281-
}
282-
if autoCode.Fields[i].FieldType == "file" {
283-
autoCode.NeedJSON = true
284-
autoCode.HasFile = true
285-
}
286-
if autoCode.GvaModel {
287-
autoCode.PrimaryField = &system.Field{
288-
FieldName: "ID",
289-
FieldType: "uint",
290-
FieldDesc: "ID",
291-
FieldJson: "ID",
292-
DataTypeLong: "20",
293-
Comment: "主键ID",
294-
ColumnName: "id",
295-
}
296-
}
297-
if !autoCode.GvaModel && autoCode.PrimaryField == nil && autoCode.Fields[i].PrimaryKey {
298-
autoCode.PrimaryField = autoCode.Fields[i]
299-
}
300-
}
215+
fmtField(&autoCode)
301216
// 增加判断: 重复创建struct
302217
if autoCode.AutoMoveFile && AutoCodeHistoryServiceApp.Repeat(autoCode.BusinessDB, autoCode.StructName, autoCode.Package) {
303218
return RepeatErr
@@ -1030,3 +945,55 @@ func (autoCodeService *AutoCodeService) doZip(zipWriter *zip.Writer, serverPath,
1030945
})
1031946
return err
1032947
}
948+
949+
func fmtField(autoCode *system.AutoCodeStruct) {
950+
makeDictTypes(autoCode)
951+
for i := range autoCode.Fields {
952+
953+
if autoCode.Fields[i].Front {
954+
autoCode.FrontFields = append(autoCode.FrontFields, autoCode.Fields[i])
955+
}
956+
957+
if autoCode.Fields[i].FieldType == "time.Time" {
958+
autoCode.HasTimer = true
959+
if autoCode.Fields[i].FieldSearchType != "" {
960+
autoCode.HasSearchTimer = true
961+
}
962+
}
963+
if autoCode.Fields[i].Sort {
964+
autoCode.NeedSort = true
965+
}
966+
if autoCode.Fields[i].FieldType == "picture" {
967+
autoCode.HasPic = true
968+
}
969+
if autoCode.Fields[i].FieldType == "video" {
970+
autoCode.HasPic = true
971+
}
972+
if autoCode.Fields[i].FieldType == "richtext" {
973+
autoCode.HasRichText = true
974+
}
975+
if autoCode.Fields[i].FieldType == "pictures" {
976+
autoCode.HasPic = true
977+
autoCode.NeedJSON = true
978+
}
979+
if autoCode.Fields[i].FieldType == "file" {
980+
autoCode.HasFile = true
981+
autoCode.NeedJSON = true
982+
}
983+
984+
if autoCode.GvaModel {
985+
autoCode.PrimaryField = &system.Field{
986+
FieldName: "ID",
987+
FieldType: "uint",
988+
FieldDesc: "ID",
989+
FieldJson: "ID",
990+
DataTypeLong: "20",
991+
Comment: "主键ID",
992+
ColumnName: "id",
993+
}
994+
}
995+
if !autoCode.GvaModel && autoCode.PrimaryField == nil && autoCode.Fields[i].PrimaryKey {
996+
autoCode.PrimaryField = autoCode.Fields[i]
997+
}
998+
}
999+
}

web/src/view/systemTools/autoCode/component/fieldDialog.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,15 @@
135135
placeholder="请输入默认值"
136136
/>
137137
</el-form-item>
138+
<el-form-item label="前端class">
139+
<el-input v-model="middleDate.class" />
140+
</el-form-item>
138141
<el-form-item label="主键">
139142
<el-checkbox v-model="middleDate.primaryKey" />
140143
</el-form-item>
144+
<el-form-item label="前端可见">
145+
<el-switch v-model="middleDate.front" />
146+
</el-form-item>
141147
<el-form-item label="是否排序">
142148
<el-switch v-model="middleDate.sort" />
143149
</el-form-item>

web/src/view/systemTools/autoCode/index.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@
383383
>
384384
<template #default="{row}"> <el-checkbox v-model="row.sort" /> </template>
385385
</el-table-column>
386+
<el-table-column
387+
align="left"
388+
prop="front"
389+
label="前端可见"
390+
>
391+
<template #default="{row}"> <el-checkbox v-model="row.front" /> </template>
392+
</el-table-column>
386393
<el-table-column
387394
align="left"
388395
prop="fieldJson"
@@ -445,6 +452,16 @@
445452
<el-input v-model="row.comment" />
446453
</template>
447454
</el-table-column>
455+
<el-table-column
456+
align="left"
457+
prop="comment"
458+
label="前端class"
459+
width="160"
460+
>
461+
<template #default="{row}">
462+
<el-input v-model="row.class" />
463+
</template>
464+
</el-table-column>
448465
<el-table-column
449466
align="left"
450467
prop="fieldSearchType"
@@ -702,6 +719,8 @@ const fieldTemplate = {
702719
defaultValue: '',
703720
require: false,
704721
sort: false,
722+
front: true,
723+
class: '',
705724
errorText: '',
706725
primaryKey: false,
707726
clearable: true,
@@ -990,7 +1009,8 @@ const getColumnFunc = async() => {
9901009
errorText: '',
9911010
clearable: true,
9921011
fieldSearchType: '',
993-
dictType: ''
1012+
dictType: '',
1013+
front: true
9941014
})
9951015
}
9961016
})

0 commit comments

Comments
 (0)