diff --git a/server/admin/generator/tpl_utils/templates/gocode/controller.go.tpl b/server/admin/generator/tpl_utils/templates/gocode/controller.go.tpl index b41a9b4..35afa1f 100644 --- a/server/admin/generator/tpl_utils/templates/gocode/controller.go.tpl +++ b/server/admin/generator/tpl_utils/templates/gocode/controller.go.tpl @@ -26,10 +26,10 @@ type {{{ toUpperCamelCase .ModuleName }}}Handler struct { {{{- range .Columns }}} {{{- if .IsQuery }}} {{{- if eq .HtmlType "datetime" }}} -// @Param {{{toUpperCamelCase .GoField }}}Start query {{{ .GoType }}} false "{{{ .ColumnComment }}}" -// @Param {{{toUpperCamelCase .GoField }}}End query {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}}Start query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}}End query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- else }}} -// @Param {{{toUpperCamelCase .GoField }}} query {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}} query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- end }}} {{{- end }}} {{{- end }}} @@ -54,10 +54,10 @@ func (hd *{{{ toUpperCamelCase .ModuleName }}}Handler) List(c *gin.Context) { {{{- range .Columns }}} {{{- if .IsQuery }}} {{{- if eq .HtmlType "datetime" }}} -// @Param {{{toUpperCamelCase .GoField }}}Start query {{{ .GoType }}} false "{{{ .ColumnComment }}}" -// @Param {{{toUpperCamelCase .GoField }}}End query {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}}Start query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}}End query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- else }}} -// @Param {{{toUpperCamelCase .GoField }}} query {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}} query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- end }}} {{{- end }}} {{{- end }}} @@ -78,7 +78,7 @@ func (hd *{{{ toUpperCamelCase .ModuleName }}}Handler) ListAll(c *gin.Context) // @Param Token header string true "token" {{{- range .Columns }}} {{{- if .IsPk }}} -// @Param {{{toUpperCamelCase .GoField }}} query {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}} query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- end }}} {{{- end }}} // @Success 200 {object} response.Response{ data={{{ toUpperCamelCase .EntityName }}}Resp} "成功" @@ -103,7 +103,7 @@ func (hd *{{{ toUpperCamelCase .ModuleName }}}Handler) Detail(c *gin.Context) { // @Param Token header string true "token" {{{- range .Columns }}} {{{- if .IsInsert }}} -// @Param {{{toUpperCamelCase .GoField }}} body {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}} body {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- end }}} {{{- end }}} // @Success 200 {object} response.Response "成功" @@ -122,7 +122,7 @@ func (hd *{{{ toUpperCamelCase .ModuleName }}}Handler) Add(c *gin.Context) { // @Param Token header string true "token" {{{- range .Columns }}} {{{- if .IsEdit }}} -// @Param {{{toUpperCamelCase .GoField }}} body {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}} body {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- end }}} {{{- end }}} // @Success 200 {object} response.Response "成功" @@ -140,7 +140,7 @@ func (hd *{{{ toUpperCamelCase .ModuleName }}}Handler) Edit(c *gin.Context) { // @Param Token header string true "token" {{{- range .Columns }}} {{{- if .IsPk }}} -// @Param {{{toUpperCamelCase .GoField }}} body {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}} body {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- end }}} {{{- end }}} // @Success 200 {object} response.Response "成功" @@ -164,10 +164,10 @@ func (hd *{{{ toUpperCamelCase .ModuleName }}}Handler) Del(c *gin.Context) { {{{- range .Columns }}} {{{- if .IsQuery }}} {{{- if eq .HtmlType "datetime" }}} -// @Param {{{toUpperCamelCase .GoField }}}Start query {{{ .GoType }}} false "{{{ .ColumnComment }}}" -// @Param {{{toUpperCamelCase .GoField }}}End query {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}}Start query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}}End query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- else }}} -// @Param {{{toUpperCamelCase .GoField }}} query {{{ .GoType }}} false "{{{ .ColumnComment }}}" +// @Param {{{toUpperCamelCase .GoField }}} query {{{goToTsType .GoType }}} false "{{{ .ColumnComment }}}" {{{- end }}} {{{- end }}} {{{- end }}} diff --git a/server/admin/generator/tpl_utils/templates/gocode/schema.go.tpl b/server/admin/generator/tpl_utils/templates/gocode/schema.go.tpl index c7c860f..1a409a1 100644 --- a/server/admin/generator/tpl_utils/templates/gocode/schema.go.tpl +++ b/server/admin/generator/tpl_utils/templates/gocode/schema.go.tpl @@ -9,10 +9,10 @@ type {{{ toUpperCamelCase .EntityName }}}ListReq struct { {{{- range .Columns }}} {{{- if .IsQuery }}} {{{- if eq .HtmlType "datetime" }}} - {{{ toUpperCamelCase .GoField }}}Start *string `form:"{{{ .GoField }}}Start"` // 开始{{{ .ColumnComment }}} - {{{ toUpperCamelCase .GoField }}}End *string `GoField }}}End" form:"{{{ .GoField }}}End"` // 结束{{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}}Start *string `` // 开始{{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}}End *string `` // 结束{{{ .ColumnComment }}} {{{- else }}} - {{{ toUpperCamelCase .GoField }}} *{{{.GoType }}} ` form:"{{{ .GoField }}}"` // {{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}} *{{{.GoType }}} `` // {{{ .ColumnComment }}} {{{- end }}} {{{- end }}} {{{- end }}} @@ -24,7 +24,7 @@ type {{{ toUpperCamelCase .EntityName }}}ListReq struct { type {{{ toUpperCamelCase .EntityName }}}AddReq struct { {{{- range .Columns }}} {{{- if .IsInsert }}} - {{{ toUpperCamelCase .GoField }}} interface{} `mapstructure:"{{{ .GoField }}}" json:"{{{ .GoField }}}" form:"{{{ .GoField }}}"` // {{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} `` // {{{ .ColumnComment }}} {{{- end }}} {{{- end }}} } @@ -34,9 +34,9 @@ type {{{ toUpperCamelCase .EntityName }}}EditReq struct { {{{- range .Columns }}} {{{- if .IsEdit }}} {{{- if .IsPk }}} - {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `mapstructure:"{{{ .GoField }}}" json:"{{{ .GoField }}}" form:"{{{ .GoField }}}"` // {{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `` // {{{ .ColumnComment }}} {{{- else }}} - {{{ toUpperCamelCase .GoField }}} interface{} `mapstructure:"{{{ .GoField }}}" json:"{{{ .GoField }}}" form:"{{{ .GoField }}}"` // {{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} `` // {{{ .ColumnComment }}} {{{- end }}} {{{- end }}} {{{- end }}} @@ -46,7 +46,7 @@ type {{{ toUpperCamelCase .EntityName }}}EditReq struct { type {{{ toUpperCamelCase .EntityName }}}DetailReq struct { {{{- range .Columns }}} {{{- if .IsPk }}} - {{{ toUpperCamelCase .GoField }}} {{{.GoType }}} `form:"{{{ .GoField }}}"` // {{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}} {{{.GoType }}} `` // {{{ .ColumnComment }}} {{{- end }}} {{{- end }}} } @@ -55,7 +55,7 @@ type {{{ toUpperCamelCase .EntityName }}}DetailReq struct { type {{{ toUpperCamelCase .EntityName }}}DelReq struct { {{{- range .Columns }}} {{{- if .IsPk }}} - {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `form:"{{{ .GoField }}}"` // {{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `` // {{{ .ColumnComment }}} {{{- end }}} {{{- end }}} } @@ -65,9 +65,9 @@ type {{{ toUpperCamelCase .EntityName }}}Resp struct { {{{- range .Columns }}} {{{- if or .IsList .IsPk }}} {{{- if .IsPk }}} - {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `mapstructure:"{{{ .GoField }}}" json:"{{{ .GoField }}}"` // {{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}} {{{.GoType }}} `` // {{{ .ColumnComment }}} {{{- else }}} - {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `mapstructure:"{{{ .GoField }}}" json:"{{{ .GoField }}}"` // {{{ .ColumnComment }}} + {{{ toUpperCamelCase .GoField }}} {{{goWithRespType .GoType }}} `` // {{{ .ColumnComment }}} {{{- end }}} {{{- end }}} {{{- end }}} diff --git a/server/admin/generator/tpl_utils/templates/gocode/service.go.tpl b/server/admin/generator/tpl_utils/templates/gocode/service.go.tpl index fa74edb..34e9d1f 100644 --- a/server/admin/generator/tpl_utils/templates/gocode/service.go.tpl +++ b/server/admin/generator/tpl_utils/templates/gocode/service.go.tpl @@ -133,7 +133,7 @@ func (service {{{ toCamelCase .EntityName }}}Service) Detail({{{ toUpperCamelCas // Add {{{ .FunctionName }}}新增 func (service {{{ toCamelCase .EntityName }}}Service) Add(addReq {{{ toUpperCamelCase .EntityName }}}AddReq) (createId int,e error) { var obj model.{{{ toUpperCamelCase .EntityName }}} - util.ConvertUtil.Copy(&obj, addReq) + util.ConvertUtil.StructToStruct(addReq,&obj) err := service.db.Create(&obj).Error e = response.CheckMysqlErr(err) if e != nil { @@ -141,7 +141,6 @@ func (service {{{ toCamelCase .EntityName }}}Service) Add(addReq {{{ toUpperCame } cacheUtil.SetCache(obj.{{{ toUpperCamelCase .PrimaryKey }}}, obj) createId = obj.{{{ toUpperCamelCase .PrimaryKey }}} - e = response.CheckErr(err, "添加失败") return } @@ -156,15 +155,9 @@ func (service {{{ toCamelCase .EntityName }}}Service) Edit(editReq {{{ toUpperCa if e = response.CheckErr(err, "查询失败"); e != nil { return } - // 更新 - // util.ConvertUtil.Copy(&obj, editReq) - // - editInfo, err := convertor.StructToMap(editReq) - if err != nil { - return err - } + util.ConvertUtil.Copy(&obj, editReq) - err = service.db.Model(&obj).Updates(editInfo).Error + err = service.db.Model(&obj).Select("*").Updates(obj).Error if e = response.CheckErr(err, "编辑失败"); e != nil { return } @@ -205,9 +198,12 @@ func (service {{{ toCamelCase .EntityName }}}Service) GetExcelCol() []excel2.Col var cols = []excel2.Col{ {{{- range .Columns }}} {{{- if eq .HtmlType "datetime" }}} - {Name: "{{{.ColumnComment}}}", Key: "{{{ toUpperCamelCase .GoField }}}", Width: 15, Decode: excel2.DecodeTime }, + {Name: "{{{.ColumnComment}}}", Key: "{{{ toUpperCamelCase .GoField }}}", Width: 15,Encode: util.NullTimeUtil.EncodeTime, Decode: util.NullTimeUtil.DecodeTime }, + {{{- else if eq .GoType "int" }}} + {Name: "{{{.ColumnComment}}}", Key: "{{{ toUpperCamelCase .GoField }}}", Width: 15,Encode: core.EncodeInt, Decode: core.DecodeInt}, {{{- else }}} {Name: "{{{.ColumnComment}}}", Key: "{{{ toUpperCamelCase .GoField }}}", Width: 15}, + {{{- end }}} {{{- end }}} } diff --git a/server/admin/generator/tpl_utils/templates/uniapp/api.ts.tpl b/server/admin/generator/tpl_utils/templates/uniapp/api.ts.tpl index 83b6cec..9908adb 100644 --- a/server/admin/generator/tpl_utils/templates/uniapp/api.ts.tpl +++ b/server/admin/generator/tpl_utils/templates/uniapp/api.ts.tpl @@ -4,7 +4,7 @@ import { clearObjEmpty } from "@/utils/utils"; export type type_{{{.ModuleName}}} = { {{{- range .Columns }}} - {{{ .GoField }}}?: {{{goToTsType .GoType}}}; + {{{toUpperCamelCase .GoField }}}?: {{{goToTsType .GoType}}}; {{{- end }}} } // 查询 @@ -12,10 +12,10 @@ export type type_{{{.ModuleName}}}_query = { {{{- range .Columns }}} {{{- if .IsQuery }}} {{{- if eq .HtmlType "datetime" }}} - {{{ .GoField }}}Start?: string; - {{{ .GoField }}}End?: string; + {{{toUpperCamelCase .GoField }}}Start?: string; + {{{toUpperCamelCase .GoField }}}End?: string; {{{- else }}} - {{{ .GoField }}}?: {{{goToTsType .GoType}}}; + {{{toUpperCamelCase .GoField }}}?: {{{goToTsType .GoType}}}; {{{- end }}} {{{- end }}} {{{- end }}} @@ -24,7 +24,7 @@ export type type_{{{.ModuleName}}}_query = { export type type_{{{.ModuleName}}}_edit = { {{{- range .Columns }}} {{{- if or .IsEdit .IsInsert }}} - {{{ .GoField }}}?: {{{goToTsType .GoType}}}; + {{{toUpperCamelCase .GoField }}}?: {{{goToTsType .GoType}}}; {{{- end }}} {{{- end }}} } @@ -48,11 +48,11 @@ export function {{{.ModuleName}}}_list_all(params?: type_{{{.ModuleName}}}_query } // {{{.FunctionName}}}详情 -export function {{{.ModuleName}}}_detail({{{ .PrimaryKey }}}: number | string) { +export function {{{.ModuleName}}}_detail({{{toUpperCamelCase .PrimaryKey }}}: number | string) { return request({ url: '/{{{.ModuleName}}}/detail', method: 'GET', - data: { {{{ .PrimaryKey }}} } + data: { {{{toUpperCamelCase .PrimaryKey }}} } }) } @@ -75,12 +75,12 @@ export function {{{.ModuleName}}}_edit(data: type_{{{.ModuleName}}}_edit) { } // {{{.FunctionName}}}删除 -export function {{{.ModuleName}}}_delete({{{ .PrimaryKey }}}: number | string) { +export function {{{.ModuleName}}}_delete({{{toUpperCamelCase .PrimaryKey }}}: number | string) { return request({ url: '/{{{.ModuleName}}}/del', method: "POST", data:{ - {{{ .PrimaryKey }}} + {{{toUpperCamelCase .PrimaryKey }}} }, }); } \ No newline at end of file diff --git a/server/admin/generator/tpl_utils/templates/uniapp/details.vue.tpl b/server/admin/generator/tpl_utils/templates/uniapp/details.vue.tpl index 1abf841..b5f54a1 100644 --- a/server/admin/generator/tpl_utils/templates/uniapp/details.vue.tpl +++ b/server/admin/generator/tpl_utils/templates/uniapp/details.vue.tpl @@ -3,15 +3,15 @@ {{{- range .Columns }}} {{{- if .IsList }}} - + {{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}} - + {{{- else if and (ne .ListAllApi "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}} - + {{{- else if eq .HtmlType "imageUpload" }}} - + {{{- else }}} - {{form.{{{(.GoField)}}}}} + {{form.{{{(toUpperCamelCase .GoField)}}}}} {{{- end }}} {{{- end }}} @@ -44,7 +44,7 @@ let form = ref({ {{{- range .Columns }}} {{{- if or .IsList .IsPk }}} - {{{ .GoField }}}: "", + {{{ toUpperCamelCase .GoField }}}: "", {{{- end }}} {{{- end }}} }); diff --git a/server/admin/generator/tpl_utils/templates/uniapp/edit.vue.tpl b/server/admin/generator/tpl_utils/templates/uniapp/edit.vue.tpl index c207716..d648088 100644 --- a/server/admin/generator/tpl_utils/templates/uniapp/edit.vue.tpl +++ b/server/admin/generator/tpl_utils/templates/uniapp/edit.vue.tpl @@ -3,20 +3,20 @@ {{{- range .Columns }}} {{{- if .IsEdit }}} - + {{{- if eq .HtmlType "input" }}} - + {{{- else if eq .HtmlType "number" }}} - + {{{- else if eq .HtmlType "textarea" }}} - + {{{- else if eq .HtmlType "datetime" }}} - + {{{- else if or (eq .HtmlType "checkbox") (eq .HtmlType "radio") (eq .HtmlType "select")}}} {{{- if ne .DictType "" }}} - + {{{- else if ne .ListAllApi "" }}} - + {{{- else }}} 请选择字典生成代码 {{{- end }}} @@ -55,15 +55,15 @@ let formRef = ref(); let form = ref({ {{{- range .Columns }}} - {{{- if eq (.GoField) $.PrimaryKey }}} + {{{- if eq (toUpperCamelCase .GoField) $.PrimaryKey }}} {{{ $.PrimaryKey }}}: '', {{{- else if .IsEdit }}} {{{- if eq .HtmlType "checkbox" }}} - {{{ (.GoField) }}}: [], + {{{ (toUpperCamelCase .GoField) }}}: [], {{{- else if eq .HtmlType "number" }}} - {{{ (.GoField) }}}: 0, + {{{ (toUpperCamelCase .GoField) }}}: 0, {{{- else }}} - {{{ (.GoField) }}}: '', + {{{ (toUpperCamelCase .GoField) }}}: '', {{{- end }}} {{{- end }}} {{{- end }}} @@ -71,7 +71,7 @@ const formRules = { {{{- range .Columns }}} {{{- if and .IsEdit .IsRequired }}} - {{{ (.GoField) }}}: [ + {{{ (toUpperCamelCase .GoField) }}}: [ { required: true, {{{- if or (eq .HtmlType "checkbox") (eq .HtmlType "datetime") (eq .HtmlType "radio") (eq .HtmlType "select") (eq .HtmlType "imageUpload") }}} @@ -87,8 +87,8 @@ } onLoad((e) => { console.log("onLoad", e); - if (e.id) { - getDetails(e.id); + if (e.{{{toUpperCamelCase .PrimaryKey}}}) { + getDetails(e.{{{toUpperCamelCase .PrimaryKey}}}); } }); @@ -115,8 +115,8 @@ const { listAllData } = useListAllData<{ }) {{{- end }}} - function getDetails(id) { - {{{ .ModuleName }}}_detail(id).then((res) => { + function getDetails({{{toUpperCamelCase .PrimaryKey}}}) { + {{{ .ModuleName }}}_detail({{{toUpperCamelCase .PrimaryKey}}}).then((res) => { if (res.code == 200) { if (res?.data) { form.value = res?.data @@ -133,11 +133,11 @@ const { listAllData } = useListAllData<{ function submit() { console.log("submit", form.value); formRef.value.validate().then(() => { - if (form.value.id) { + if (form.value.{{{toUpperCamelCase .PrimaryKey}}}) { {{{ .ModuleName }}}_edit(form.value).then((res) => { if (res.code == 200) { toast("编辑成功"); - getDetails(form.value?.id); + getDetails(form.value?.{{{toUpperCamelCase .PrimaryKey}}}); } else { toast(res.message); } diff --git a/server/admin/generator/tpl_utils/templates/uniapp/index.vue.tpl b/server/admin/generator/tpl_utils/templates/uniapp/index.vue.tpl index 9168984..07f1b99 100644 --- a/server/admin/generator/tpl_utils/templates/uniapp/index.vue.tpl +++ b/server/admin/generator/tpl_utils/templates/uniapp/index.vue.tpl @@ -20,11 +20,11 @@ @@ -72,10 +72,10 @@ const queryParams = reactive({ {{{- range .Columns }}} {{{- if .IsQuery }}} {{{- if eq .HtmlType "datetime" }}} - {{{ (.GoField) }}}Start: '', - {{{ (.GoField) }}}End: '', + {{{ (toUpperCamelCase .GoField) }}}Start: '', + {{{ (toUpperCamelCase .GoField) }}}End: '', {{{- else }}} - {{{ (.GoField) }}}: '', + {{{ (toUpperCamelCase .GoField) }}}: '', {{{- end }}} {{{- end }}} {{{- end }}} @@ -110,7 +110,7 @@ onReachBottom(() => { }); function toDetails(item) { - toPath("/pages/{{{nameToPath .ModuleName }}}/details", { id: item.id }); + toPath("/pages/{{{nameToPath .ModuleName }}}/details", { {{{toUpperCamelCase .PrimaryKey}}}: item.{{{toUpperCamelCase .PrimaryKey}}} }); } function moreSearch() { toPath("/pages/{{{nameToPath .ModuleName }}}/search"); diff --git a/server/admin/generator/tpl_utils/templates/uniapp/search.vue.tpl b/server/admin/generator/tpl_utils/templates/uniapp/search.vue.tpl index 8aa5438..ba42ee8 100644 --- a/server/admin/generator/tpl_utils/templates/uniapp/search.vue.tpl +++ b/server/admin/generator/tpl_utils/templates/uniapp/search.vue.tpl @@ -3,18 +3,18 @@ {{{- range .Columns }}} {{{- if eq .IsQuery 1 }}} - + {{{- if eq .HtmlType "datetime" }}} - + {{{- else if or (eq .HtmlType "checkbox") (eq .HtmlType "radio") (eq .HtmlType "select") }}} {{{- if ne .DictType "" }}} - + {{{- else if ne .ListAllApi "" }}} - + {{{- end }}} {{{- else if eq .HtmlType "input" }}} - + {{{- end }}} {{{- end }}} @@ -71,10 +71,10 @@ const { listAllData } = useListAllData<{ {{{- range .Columns }}} {{{- if .IsQuery }}} {{{- if eq .HtmlType "datetime" }}} - {{{ (.GoField) }}}Start: null, - {{{ (.GoField) }}}End: null, + {{{ (toUpperCamelCase .GoField) }}}Start: null, + {{{ (toUpperCamelCase .GoField) }}}End: null, {{{- else }}} - {{{ (.GoField) }}}: null, + {{{ (toUpperCamelCase .GoField) }}}: null, {{{- end }}} {{{- end }}} {{{- end }}} diff --git a/server/admin/generator/tpl_utils/templates/vue/api.ts.tpl b/server/admin/generator/tpl_utils/templates/vue/api.ts.tpl index 6f8f3f7..d5cd27c 100644 --- a/server/admin/generator/tpl_utils/templates/vue/api.ts.tpl +++ b/server/admin/generator/tpl_utils/templates/vue/api.ts.tpl @@ -43,8 +43,8 @@ export function {{{.ModuleName}}}_list_all(params?: type_{{{.ModuleName}}}_query } // {{{.FunctionName}}}详情 -export function {{{.ModuleName}}}_detail({{{ .PrimaryKey }}}: number | string) { - return request.get({ url: '/{{{.ModuleName}}}/detail', params: { {{{ .PrimaryKey }}} } }) +export function {{{.ModuleName}}}_detail({{{toUpperCamelCase .PrimaryKey }}}: number | string) { + return request.get({ url: '/{{{.ModuleName}}}/detail', params: { {{{toUpperCamelCase .PrimaryKey }}} } }) } // {{{.FunctionName}}}新增 @@ -58,8 +58,8 @@ export function {{{.ModuleName}}}_edit(data: type_{{{.ModuleName}}}_edit) { } // {{{.FunctionName}}}删除 -export function {{{.ModuleName}}}_delete({{{ .PrimaryKey }}}: number | string) { - return request.post({ url: '/{{{.ModuleName}}}/del', data: { {{{ .PrimaryKey }}} } }) +export function {{{.ModuleName}}}_delete({{{toUpperCamelCase .PrimaryKey }}}: number | string) { + return request.post({ url: '/{{{.ModuleName}}}/del', data: { {{{toUpperCamelCase .PrimaryKey }}} } }) } // {{{.FunctionName}}}导入 diff --git a/server/admin/generator/tpl_utils/templates/vue/edit.vue.tpl b/server/admin/generator/tpl_utils/templates/vue/edit.vue.tpl index f2a2fd2..589ed58 100644 --- a/server/admin/generator/tpl_utils/templates/vue/edit.vue.tpl +++ b/server/admin/generator/tpl_utils/templates/vue/edit.vue.tpl @@ -12,7 +12,7 @@ {{{- range .Columns }}} {{{- if .IsEdit }}} - {{{- if ne (toUpperCamelCase .GoField) "id" }}} + {{{- if ne (toUpperCamelCase .GoField) "Id" }}} {{{- if and (ne $.Table.TreeParent "") (eq (toUpperCamelCase .GoField) $.Table.TreeParent) }}} {{{- else }}} 请选择字典生成 @@ -87,11 +87,11 @@ @@ -121,12 +121,12 @@ :key="index" :label="item.name" {{{- if eq .GoType "int" }}} - :value="parseInt(item.id)" + :value="parseInt(item.{{{toUpperCamelCase .PrimaryKey }}})" {{{- else }}} - :value="item.id" + :value="item.{{{toUpperCamelCase .PrimaryKey }}}" {{{- end }}} > - {{ item.id }} + {{ item.{{{toUpperCamelCase .PrimaryKey }}} }} {{{- else }}} 请选择字典生成 @@ -260,7 +260,7 @@ const setFormData = async (data: Record) => { const getDetail = async (row: Record) => { try { - const data = await {{{ .ModuleName }}}_detail(row.{{{ .PrimaryKey }}}) + const data = await {{{ .ModuleName }}}_detail(row.{{{toUpperCamelCase .PrimaryKey }}}) setFormData(data) } catch (error) {} } diff --git a/server/admin/generator/tpl_utils/templates/vue/index-tree.vue.tpl b/server/admin/generator/tpl_utils/templates/vue/index-tree.vue.tpl index 8041f5f..c610345 100644 --- a/server/admin/generator/tpl_utils/templates/vue/index-tree.vue.tpl +++ b/server/admin/generator/tpl_utils/templates/vue/index-tree.vue.tpl @@ -31,8 +31,8 @@ {{{- else }}} @@ -82,7 +82,7 @@ {{{- else if and (ne .ListAllApi "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}} {{{- else if eq .HtmlType "imageUpload" }}} @@ -232,9 +232,9 @@ const handleEdit = async (data: any) => { editRef.value?.getDetail(data) } -const handleDelete = async ({{{ .PrimaryKey }}}: number) => { +const handleDelete = async ({{{toUpperCamelCase .PrimaryKey }}}: number) => { await feedback.confirm('确定要删除?') - await {{{ .ModuleName }}}_delete({ {{{ .PrimaryKey }}} }) + await {{{ .ModuleName }}}_delete({ {{{toUpperCamelCase .PrimaryKey }}} }) feedback.msgSuccess('删除成功') getLists() } diff --git a/server/admin/generator/tpl_utils/templates/vue/index.vue.tpl b/server/admin/generator/tpl_utils/templates/vue/index.vue.tpl index fc80bff..9e6c49a 100644 --- a/server/admin/generator/tpl_utils/templates/vue/index.vue.tpl +++ b/server/admin/generator/tpl_utils/templates/vue/index.vue.tpl @@ -32,8 +32,8 @@ {{{- else }}} @@ -100,7 +100,7 @@ {{{- else if and (ne .ListAllApi "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}} @@ -136,7 +136,7 @@ v-perms="['admin:{{{ .ModuleName }}}:del']" type="danger" link - @click="handleDelete(row.{{{ .PrimaryKey }}})" + @click="handleDelete(row.{{{toUpperCamelCase .PrimaryKey }}})" > 删除 @@ -231,10 +231,10 @@ const handleEdit = async (data: any) => { editRef.value?.getDetail(data) } -const handleDelete = async ({{{ .PrimaryKey }}}: number) => { +const handleDelete = async ({{{toUpperCamelCase .PrimaryKey }}}: number) => { try { await feedback.confirm('确定要删除?') - await {{{ .ModuleName }}}_delete( {{{ .PrimaryKey }}} ) + await {{{ .ModuleName }}}_delete( {{{toUpperCamelCase .PrimaryKey }}} ) feedback.msgSuccess('删除成功') getLists() } catch (error) {} diff --git a/server/admin/generator/tpl_utils/tpl.go b/server/admin/generator/tpl_utils/tpl.go index 19a9fe5..d8556b8 100644 --- a/server/admin/generator/tpl_utils/tpl.go +++ b/server/admin/generator/tpl_utils/tpl.go @@ -17,18 +17,20 @@ var TemplateUtil = templateUtil{ tpl: template.New("").Delims("{{{", "}}}").Funcs( template.FuncMap{ - "sub": sub, - "slice": slice, - "toSnakeCase": util.StringUtil.ToSnakeCase, - "toCamelCase": util.StringUtil.ToCamelCase, - "toUpperCamelCase": util.StringUtil.ToUpperCamelCase, - "contains": util.ToolsUtil.Contains, - "goToTsType": GenUtil.GoToTsType, - "goToNullType": GenUtil.GoToNullType, - "getPageResp": GenUtil.GetPageResp, - "nameToPath": GenUtil.NameToPath, - "pathToName": GenUtil.PathToName, - "deletePathPrefix": GenUtil.DeletePathPrefix, + "sub": sub, + "slice": slice, + "toSnakeCase": util.StringUtil.ToSnakeCase, + "toCamelCase": util.StringUtil.ToCamelCase, + "toUpperCamelCase": util.StringUtil.ToUpperCamelCase, + "contains": util.ToolsUtil.Contains, + "goToTsType": GenUtil.GoToTsType, + "goToParamType": GenUtil.GoToParamType, + "goWithAddEditType": GenUtil.GoWithAddEditType, + "goWithRespType": GenUtil.GoWithRespType, + "getPageResp": GenUtil.GetPageResp, + "nameToPath": GenUtil.NameToPath, + "pathToName": GenUtil.PathToName, + "deletePathPrefix": GenUtil.DeletePathPrefix, }), } diff --git a/server/admin/generator/tpl_utils/utils.go b/server/admin/generator/tpl_utils/utils.go index 6dae34d..34cdebe 100644 --- a/server/admin/generator/tpl_utils/utils.go +++ b/server/admin/generator/tpl_utils/utils.go @@ -240,25 +240,61 @@ func (gu genUtil) GoToTsType(s string) string { } /** - * @description: Go类型转可为null类型,转换后还能解决前端对int传了string类型错误问题 + * @description: Go类型转 添加编辑 类型 */ -func (gu genUtil) GoToNullType(s string) string { - // if s == "int64" { - // return "null.Int" - // } else if s == "int32" || s == "int" { - // return "null.Int32" - // } else if s == "int8" || s == "int16" { - // return "null.Int16" - // } else if s == "float" || s == "float32" || s == "float64" { - // return "null.Float" - // } else if s == "string" { - // return "null.String" - // } else if s == "bool" { - // return "null.Bool" - // } else if s == "time.Time" { - // return "null.Time" - // } - return "*" + s +func (gu genUtil) GoWithAddEditType(s string) string { + if s == "int" || s == "int8" || s == "int16" || s == "int32" || s == "int64" { + return "core.NullInt" + } else if s == "float" || s == "float32" || s == "float64" { + return "core.NullFloat" + } else if s == "string" { + return "*string" + } else if s == "bool" { + return "*int" + } else if s == "time.Time" { + return "core.NullTime" + } else if s == "core.NullTime" { + return "core.NullTime" + } + return "string" +} + +/** + * @description: Go类型转 添加编辑 类型 + */ +func (gu genUtil) GoWithRespType(s string) string { + if s == "int" || s == "int8" || s == "int16" || s == "int32" || s == "int64" { + return "core.NullInt" + } else if s == "float" || s == "float32" || s == "float64" { + return "core.NullFloat" + } else if s == "string" { + return "string" + } else if s == "bool" { + return "int" + } else if s == "time.Time" { + return "core.NullTime" + } else if s == "core.NullTime" { + return "core.NullTime" + } + return "string" +} + +/** + * @description: Go类型转可为Param类型 + */ +func (gu genUtil) GoToParamType(s string) string { + if s == "int" || s == "int8" || s == "int16" || s == "int32" || s == "int64" { + return "int" + } else if s == "float" || s == "float32" || s == "float64" { + return "float" + } else if s == "string" { + return "string" + } else if s == "bool" { + return "bool" + } else if s == "core.NullTime" { + return "string" + } + return "string" } // 拼接字符串 diff --git a/server/core/null_time.go b/server/core/null_time.go index ecd468f..d9cb162 100644 --- a/server/core/null_time.go +++ b/server/core/null_time.go @@ -10,8 +10,8 @@ import ( "gorm.io/gorm/schema" ) -// const DateFormat = "2006-01-02" -// const TimeFormat = "2006-01-02 15:04:05" +const DateFormat = "2006-01-02" +const TimeFormat = "2006-01-02 15:04:05" // NullTime 自定义时间格式 type NullTime struct { diff --git a/server/core/time.go1 b/server/core/time.go1 deleted file mode 100644 index c4be8c0..0000000 --- a/server/core/time.go1 +++ /dev/null @@ -1,86 +0,0 @@ -package core - -import ( - "database/sql/driver" - "encoding/json" - "fmt" - "time" - - "gorm.io/gorm" - "gorm.io/gorm/schema" -) - -const DateFormat = "2006-01-02" -const TimeFormat = "2006-01-02 15:04:05" - -// TsTime 自定义时间格式 -type TsTime time.Time - -// 通过时间字符串生成时间戳 -func ToUnix(date string) int64 { - if date == "" { - return 0 - } - tt, _ := time.ParseInLocation(TimeFormat, date, time.Local) - return tt.Unix() -} - -func NowTime() TsTime { - return TsTime(time.Now()) -} - -func (tst *TsTime) UnmarshalJSON(bs []byte) error { - var date string - err := json.Unmarshal(bs, &date) - if err != nil { - return err - } - tt, _ := time.ParseInLocation(TimeFormat, date, time.Local) - *tst = TsTime(tt) - return nil -} - -// MarshalJSON 将TsTime类型的时间转化为JSON字符串格式 -// 返回转化后的JSON字符串和错误信息 -func (tst TsTime) MarshalJSON() ([]byte, error) { - tt := time.Time(tst).Format(TimeFormat) - return json.Marshal(tt) -} - -// 写入数据库gorm调用 -func (t TsTime) Value() (driver.Value, error) { - timeStr := t.String() - if timeStr == "0001-01-01 00:00:00" { - return nil, nil - } - return timeStr, nil -} - -// 读取数据gorm调用 -func (t *TsTime) Scan(v any) error { - // pt, err := time.ParseInLocation("2006-01-02 15:04:05", v.(time.Time).String(), time.Local) - if pt, ok := v.(time.Time); ok { - *t = TsTime(pt) - return nil - } - return fmt.Errorf("cant convert %s to time", v) -} - -func (t TsTime) String() string { - return time.Time(t).Format(TimeFormat) -} - -func (TsTime) GormDBDataType(db *gorm.DB, field *schema.Field) string { - // 使用 field.Tag、field.TagSettings 获取字段的 tag - // 查看 https://github.com/go-gorm/gorm/blob/master/schema/field.go 获取全部的选项 - - // 根据不同的数据库驱动返回不同的数据类型 - // switch db.Dialector.Name() { - // case "mysql", "sqlite": - // return "JSON" - // case "postgres": - // return "JSONB" - // } - // return "" - return "DATETIME" -} diff --git a/server/core/time.go2 b/server/core/time.go2 deleted file mode 100644 index 7e96798..0000000 --- a/server/core/time.go2 +++ /dev/null @@ -1,102 +0,0 @@ -package core - -import ( - "database/sql/driver" - "encoding/json" - "time" - - "gorm.io/gorm" - "gorm.io/gorm/schema" -) - -const DateFormat = "2006-01-02" -const TimeFormat = "2006-01-02 15:04:05" - -// 注解:时间类型从time.Time改为string的原因是struct转interface{}时,丢弃了部分信息,导致导出excel时,时间格式不对 -// TsTime 自定义时间格式 -type TsTime string - -// 通过时间字符串生成时间戳 -// -// func ToUnix(date string) int64 { -// if date == "" { -// return 0 -// } -// tt, _ := time.ParseInLocation(TimeFormat, date, time.Local) -// return tt.Unix() -// } -func ParseTimeToTsTime(date time.Time) TsTime { - return TsTime(date.Format(TimeFormat)) -} - -func NowTime() TsTime { - return TsTime(time.Now().Format(TimeFormat)) -} - -func (tst *TsTime) UnmarshalJSON(bs []byte) error { - var date string - err := json.Unmarshal(bs, &date) - if err != nil { - return err - } - tt, _ := time.ParseInLocation(TimeFormat, date, time.Local) - *tst = TsTime( - tt.Format(TimeFormat), - ) - return nil -} - -// MarshalJSON 将TsTime类型的时间转化为JSON字符串格式 -// 返回转化后的JSON字符串和错误信息 -func (tst TsTime) MarshalJSON() ([]byte, error) { - // tt := time.Time(tst.Str).Format(TimeFormat) - tt, _ := time.Parse(TimeFormat, tst.String()) - str := tt.Format(TimeFormat) - - return json.Marshal(str) -} - -// 写入数据库gorm调用 -func (t TsTime) Value() (driver.Value, error) { - timeStr := t.String() - if timeStr == "" { - return nil, nil - } - - return timeStr, nil -} - -// 读取数据gorm调用 -func (t *TsTime) Scan(v any) error { - // pt, err := time.ParseInLocation("2006-01-02 15:04:05", v.(time.Time).String(), time.Local) - if _, ok := v.(time.Time); ok { - *t = TsTime(v.(time.Time).Format(TimeFormat)) - return nil - } else { - *t = "" - return nil - } -} - -func (t TsTime) String() string { - return string(t) -} - -func (TsTime) GormDBDataType(db *gorm.DB, field *schema.Field) string { - // 使用 field.Tag、field.TagSettings 获取字段的 tag - // 查看 https://github.com/go-gorm/gorm/blob/master/schema/field.go 获取全部的选项 - - // 根据不同的数据库驱动返回不同的数据类型 - // switch db.Dialector.Name() { - // case "mysql", "sqlite": - // return "JSON" - // case "postgres": - // return "JSONB" - // } - // return "" - return "DATETIME" -} - -func (TsTime) GormDataType() string { - return "time" -} diff --git a/server/core/ts_time.go b/server/core/ts_time.go deleted file mode 100644 index c168e6e..0000000 --- a/server/core/ts_time.go +++ /dev/null @@ -1,84 +0,0 @@ -package core - -import ( - "database/sql/driver" - "encoding/json" - "fmt" - "time" - - "gorm.io/gorm" - "gorm.io/gorm/schema" -) - -const DateFormat = "2006-01-02" -const TimeFormat = "2006-01-02 15:04:05" - -// TsTime 自定义时间格式 -type TsTime time.Time - -func (tst *TsTime) IsZero() bool { - return tst.String() == "0001-01-01 00:00:00" -} -func (tst *TsTime) UnmarshalJSON(bs []byte) error { - var date string - err := json.Unmarshal(bs, &date) - if err != nil { - return err - } - if date == "" { - *tst = TsTime(time.Time{}) - return nil - } - tt, _ := time.ParseInLocation(TimeFormat, date, time.Local) - *tst = TsTime(tt) - return nil -} - -// MarshalJSON 将TsTime类型的时间转化为JSON字符串格式 -// 返回转化后的JSON字符串和错误信息 -func (tst TsTime) MarshalJSON() ([]byte, error) { - tt := time.Time(tst).Format(TimeFormat) - if tt == "0001-01-01 00:00:00" { - return json.Marshal(nil) - } else { - return json.Marshal(tt) - } -} - -// 写入数据库gorm调用 -func (t TsTime) Value() (driver.Value, error) { - timeStr := t.String() - if timeStr == "0001-01-01 00:00:00" { - return nil, nil - } - return timeStr, nil -} - -// 读取数据gorm调用 -func (t *TsTime) Scan(v any) error { - // pt, err := time.ParseInLocation("2006-01-02 15:04:05", v.(time.Time).String(), time.Local) - if pt, ok := v.(time.Time); ok { - *t = TsTime(pt) - return nil - } - return fmt.Errorf("cant convert %s to time", v) -} - -func (t TsTime) String() string { - return time.Time(t).Format(TimeFormat) -} - -func (TsTime) GormDBDataType(db *gorm.DB, field *schema.Field) string { - // 使用 field.Tag、field.TagSettings 获取字段的 tag - // 查看 https://github.com/go-gorm/gorm/blob/master/schema/field.go 获取全部的选项 - - // 根据不同的数据库驱动返回不同的数据类型 - // switch db.Dialector.Name() { - // case "mysql", "sqlite": - // return "JSON" - // case "postgres": - // return "JSONB" - // } - // return "" - return "DATETIME" -} diff --git a/server/util/time.go b/server/util/time.go deleted file mode 100644 index 0f456e1..0000000 --- a/server/util/time.go +++ /dev/null @@ -1,76 +0,0 @@ -package util - -import ( - "errors" - "time" - "x_admin/core" -) - -var TimeUtil = timeUtil{ - DateFormat: "2006-01-02", - TimeFormat: "2006-01-02 15:04:05", -} - -// arrayUtil 数组工具类 -type timeUtil struct { - DateFormat string - TimeFormat string -} - -// ToUnix 时间戳转时间戳 -func (t timeUtil) ToUnix(date any) int64 { - switch v := date.(type) { - case string: - if v == "" { - return 0 - } - tt, e := time.Parse(t.TimeFormat, v) - if e != nil { - return 0 - } - return time.Time(tt).Unix() - case time.Time: - return v.Unix() - default: - return 0 - } -} - -// ParseTsTime 时间戳转时间 -func (t timeUtil) ParseTsTime(value any) (core.TsTime, error) { - switch v := value.(type) { - case string: - tt, e := t.ParseString(v) - return tt, e - case time.Time: - tt := t.ParseTime(v) - return tt, nil - default: - return t.NowTime(), errors.New("not support type") - } -} - -// ParseTime 时间转时间戳 -func (t timeUtil) ParseTime(date time.Time) core.TsTime { - return core.TsTime(date) -} - -// ParseString 时间字符串转时间戳 -func (t timeUtil) ParseString(date string) (core.TsTime, error) { - tt, e := time.Parse(t.TimeFormat, date) - if e != nil { - return t.NowTime(), e - } - return core.TsTime(tt), nil -} - -// NowTime 当前时间 -func (t timeUtil) NowTime() core.TsTime { - return core.TsTime(time.Now()) -} - -// DecodeTime 时间解码 -func (t timeUtil) DecodeTime(value any) (any, error) { - tt, e := t.ParseTsTime(value) - return tt, e -}