Browse Source

fix:#800

修复了自动化代码公用字典出现多次创建字典相关代码的bug
main
蒋吉兆 3 years ago
parent
commit
5b8691b4f4
  1. 1
      server/model/system/sys_auto_code.go
  2. 12
      server/resource/template/web/form.vue.tpl
  3. 12
      server/resource/template/web/table.vue.tpl
  4. 15
      server/service/system/sys_auto_code.go

1
server/model/system/sys_auto_code.go

@ -13,6 +13,7 @@ type AutoCodeStruct struct {
AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api
AutoMoveFile bool `json:"autoMoveFile"` // 是否自动移动文件 AutoMoveFile bool `json:"autoMoveFile"` // 是否自动移动文件
Fields []*Field `json:"fields"` Fields []*Field `json:"fields"`
DictTypes []string `json:"-"`
} }
type Field struct { type Field struct {

12
server/resource/template/web/form.vue.tpl

@ -49,10 +49,8 @@ export default {
data() { data() {
return { return {
type: '', type: '',
{{- range .Fields}}
{{- if .DictType }}
{{ .DictType }}Options: [],
{{- end }}
{{- range $index, $element := .DictTypes}}
{{ $element }}Options: [],
{{- end }} {{- end }}
formData: { formData: {
{{- range .Fields}} {{- range .Fields}}
@ -86,10 +84,8 @@ export default {
} else { } else {
this.type = 'create' this.type = 'create'
} }
{{- range .Fields }}
{{- if .DictType }}
await this.getDict('{{.DictType}}')
{{- end }}
{{- range $index, $element := .DictTypes }}
await this.getDict('{{$element}}')
{{- end }} {{- end }}
}, },
methods: { methods: {

12
server/resource/template/web/table.vue.tpl

@ -144,10 +144,8 @@ export default {
type: '', type: '',
deleteVisible: false, deleteVisible: false,
multipleSelection: [], multipleSelection: [],
{{- range .Fields}}
{{- if .DictType }}
{{ .DictType }}Options: [],
{{- end }}
{{- range $index, $element := .DictTypes }}
{{ $element }}Options: [],
{{- end }} {{- end }}
formData: { formData: {
{{- range .Fields}} {{- range .Fields}}
@ -172,10 +170,8 @@ export default {
}, },
async created() { async created() {
await this.getTableData() await this.getTableData()
{{- range .Fields }}
{{- if .DictType }}
await this.getDict('{{.DictType}}')
{{- end }}
{{- range $index, $element := .DictTypes }}
await this.getDict('{{$element}}')
{{- end }} {{- end }}
}, },
methods: { methods: {

15
server/service/system/sys_auto_code.go

@ -89,6 +89,7 @@ var AutoCodeServiceApp = new(AutoCodeService)
//@return: map[string]string, error //@return: map[string]string, error
func (autoCodeService *AutoCodeService) PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) { func (autoCodeService *AutoCodeService) PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) {
makeDictTypes(&autoCode)
dataList, _, needMkdir, err := autoCodeService.getNeedList(&autoCode) dataList, _, needMkdir, err := autoCodeService.getNeedList(&autoCode)
if err != nil { if err != nil {
return nil, err return nil, err
@ -147,6 +148,19 @@ func (autoCodeService *AutoCodeService) PreviewTemp(autoCode system.AutoCodeStru
return ret, nil return ret, nil
} }
func makeDictTypes(autoCode *system.AutoCodeStruct) {
DictTypeM := make(map[string]string)
for _, v := range autoCode.Fields {
if v.DictType != "" {
DictTypeM[v.DictType] = ""
}
}
for k, _ := range DictTypeM {
autoCode.DictTypes = append(autoCode.DictTypes, k)
}
}
//@author: [piexlmax](https://github.com/piexlmax) //@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateTemp //@function: CreateTemp
//@description: 创建代码 //@description: 创建代码
@ -154,6 +168,7 @@ func (autoCodeService *AutoCodeService) PreviewTemp(autoCode system.AutoCodeStru
//@return: err error //@return: err error
func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) { func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
makeDictTypes(&autoCode)
// 增加判断: 重复创建struct // 增加判断: 重复创建struct
if autoCode.AutoMoveFile && AutoCodeHistoryServiceApp.Repeat(autoCode.StructName) { if autoCode.AutoMoveFile && AutoCodeHistoryServiceApp.Repeat(autoCode.StructName) {
return RepeatErr return RepeatErr

Loading…
Cancel
Save