模板生成优化

This commit is contained in:
xiangheng
2024-08-16 02:51:43 +08:00
parent edd6d9df0e
commit 64e676572b
19 changed files with 174 additions and 488 deletions

View File

@@ -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 }}}

View File

@@ -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 }}}

View File

@@ -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 }}}
}

View File

@@ -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<type_{{{.ModuleName}}}>({
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<null>({
url: '/{{{.ModuleName}}}/del',
method: "POST",
data:{
{{{ .PrimaryKey }}}
{{{toUpperCamelCase .PrimaryKey }}}
},
});
}

View File

@@ -3,15 +3,15 @@
<uv-form labelPosition="left" :model="form">
{{{- range .Columns }}}
{{{- if .IsList }}}
<uv-form-item label="{{{.ColumnComment}}}" prop="{{{(.GoField)}}}" borderBottom>
<uv-form-item label="{{{.ColumnComment}}}" prop="{{{(toUpperCamelCase .GoField)}}}" borderBottom>
{{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
<dict-value :options="dictData.{{{ .DictType }}}" :value="row.{{{ (.GoField) }}}" />
<dict-value :options="dictData.{{{ .DictType }}}" :value="row.{{{ (toUpperCamelCase .GoField) }}}" />
{{{- else if and (ne .ListAllApi "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
<dict-value :options="listAllData.{{{pathToName .ListAllApi }}}" :value="row.{{{ (.GoField) }}}" labelKey='id' valueKey='id' />
<dict-value :options="listAllData.{{{pathToName .ListAllApi }}}" :value="row.{{{ (toUpperCamelCase .GoField) }}}" labelKey='id' valueKey='id' />
{{{- else if eq .HtmlType "imageUpload" }}}
<uv-image :src="$filePath(form.{{{(.GoField)}}})" width="100%"></uv-image>
<uv-image :src="$filePath(form.{{{(toUpperCamelCase .GoField)}}})" width="100%"></uv-image>
{{{- else }}}
{{form.{{{(.GoField)}}}}}
{{form.{{{(toUpperCamelCase .GoField)}}}}}
{{{- end }}}
</uv-form-item>
{{{- end }}}
@@ -44,7 +44,7 @@
let form = ref({
{{{- range .Columns }}}
{{{- if or .IsList .IsPk }}}
{{{ .GoField }}}: "",
{{{ toUpperCamelCase .GoField }}}: "",
{{{- end }}}
{{{- end }}}
});

View File

@@ -3,20 +3,20 @@
<uv-form labelPosition="left" :model="form" :rules="formRules" ref="formRef">
{{{- range .Columns }}}
{{{- if .IsEdit }}}
<uv-form-item label="{{{ .ColumnComment }}}" prop="{{{ (.GoField) }}}" borderBottom>
<uv-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toUpperCamelCase .GoField) }}}" borderBottom>
{{{- if eq .HtmlType "input" }}}
<uv-input v-model="form.{{{ (.GoField) }}}" border="surround"></uv-input>
<uv-input v-model="form.{{{ (toUpperCamelCase .GoField) }}}" border="surround"></uv-input>
{{{- else if eq .HtmlType "number" }}}
<uv-number-box v-model="form.{{{ (.GoField) }}}" :min="-99999999" :max="99999999" :integer="true"></uv-number-box>
<uv-number-box v-model="form.{{{ (toUpperCamelCase .GoField) }}}" :min="-99999999" :max="99999999" :integer="true"></uv-number-box>
{{{- else if eq .HtmlType "textarea" }}}
<uv-textarea v-model="form.{{{ (.GoField) }}}" border="surround"></uv-textarea>
<uv-textarea v-model="form.{{{ (toUpperCamelCase .GoField) }}}" border="surround"></uv-textarea>
{{{- else if eq .HtmlType "datetime" }}}
<x-date v-model:time="form.{{{ (.GoField) }}}"></x-date>
<x-date v-model:time="form.{{{ (toUpperCamelCase .GoField) }}}"></x-date>
{{{- else if or (eq .HtmlType "checkbox") (eq .HtmlType "radio") (eq .HtmlType "select")}}}
{{{- if ne .DictType "" }}}
<x-picker v-model="form.{{{ (.GoField) }}}" valueKey="value" labelKey="name" :columns="dictData.{{{ .DictType }}}"></x-picker>
<x-picker v-model="form.{{{ (toUpperCamelCase .GoField) }}}" valueKey="value" labelKey="name" :columns="dictData.{{{ .DictType }}}"></x-picker>
{{{- else if ne .ListAllApi "" }}}
<x-picker v-model="form.{{{ (.GoField) }}}" valueKey="id" labelKey="id" :columns="listAllData.{{{pathToName .ListAllApi}}}"></x-picker>
<x-picker v-model="form.{{{ (toUpperCamelCase .GoField) }}}" valueKey="{{{toUpperCamelCase .PrimaryKey}}}" labelKey="{{{toUpperCamelCase .PrimaryKey}}}" :columns="listAllData.{{{pathToName .ListAllApi}}}"></x-picker>
{{{- else }}}
请选择字典生成代码
{{{- end }}}
@@ -55,15 +55,15 @@
let formRef = ref();
let form = ref<type_{{{ .ModuleName }}}_edit>({
{{{- 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);
}

View File

@@ -20,11 +20,11 @@
<uv-list>
<uv-list-item
v-for="item of pager.lists"
:key="item.id"
:key="item.{{{toUpperCamelCase .PrimaryKey}}}"
clickable
show-arrow
:title="item.id"
:right-text="item.id"
:title="item.{{{toUpperCamelCase .PrimaryKey}}}"
:right-text="item.{{{toUpperCamelCase .PrimaryKey}}}"
@click="toDetails(item)"
></uv-list-item>
</uv-list>
@@ -72,10 +72,10 @@ const queryParams = reactive<type_{{{.ModuleName}}}_query>({
{{{- 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");

View File

@@ -3,18 +3,18 @@
<uv-form labelPosition="left" labelWidth="80" :model="form">
{{{- range .Columns }}}
{{{- if eq .IsQuery 1 }}}
<uv-form-item label="{{{ .ColumnComment }}}" prop="{{{ (.GoField) }}}" borderBottom>
<uv-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toUpperCamelCase .GoField) }}}" borderBottom>
{{{- if eq .HtmlType "datetime" }}}
<x-date-range v-model:startTime="form.{{{ (.GoField) }}}Start"
v-model:endTime="form.{{{ (.GoField) }}}End"></x-date-range>
<x-date-range v-model:startTime="form.{{{ (toUpperCamelCase .GoField) }}}Start"
v-model:endTime="form.{{{ (toUpperCamelCase .GoField) }}}End"></x-date-range>
{{{- else if or (eq .HtmlType "checkbox") (eq .HtmlType "radio") (eq .HtmlType "select") }}}
{{{- if ne .DictType "" }}}
<x-picker v-model="form.{{{ (.GoField) }}}" valueKey="value" labelKey="name" :columns="dictData.{{{ .DictType }}}"></x-picker>
<x-picker v-model="form.{{{ (toUpperCamelCase .GoField) }}}" valueKey="value" labelKey="name" :columns="dictData.{{{ .DictType }}}"></x-picker>
{{{- else if ne .ListAllApi "" }}}
<x-picker v-model="form.{{{ (.GoField) }}}" valueKey="id" labelKey="id" :columns="listAllData.{{{pathToName .ListAllApi}}}"></x-picker>
<x-picker v-model="form.{{{ (toUpperCamelCase .GoField) }}}" valueKey="{{{toUpperCamelCase .PrimaryKey}}}" labelKey="{{{toUpperCamelCase .PrimaryKey}}}" :columns="listAllData.{{{pathToName .ListAllApi}}}"></x-picker>
{{{- end }}}
{{{- else if eq .HtmlType "input" }}}
<uv-input v-model="form.{{{ (.GoField) }}}"> </uv-input>
<uv-input v-model="form.{{{ (toUpperCamelCase .GoField) }}}"> </uv-input>
{{{- end }}}
</uv-form-item>
{{{- 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 }}}

View File

@@ -43,8 +43,8 @@ export function {{{.ModuleName}}}_list_all(params?: type_{{{.ModuleName}}}_query
}
// {{{.FunctionName}}}详情
export function {{{.ModuleName}}}_detail({{{ .PrimaryKey }}}: number | string) {
return request.get<type_{{{.ModuleName}}}>({ url: '/{{{.ModuleName}}}/detail', params: { {{{ .PrimaryKey }}} } })
export function {{{.ModuleName}}}_detail({{{toUpperCamelCase .PrimaryKey }}}: number | string) {
return request.get<type_{{{.ModuleName}}}>({ 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<null>({ url: '/{{{.ModuleName}}}/del', data: { {{{ .PrimaryKey }}} } })
export function {{{.ModuleName}}}_delete({{{toUpperCamelCase .PrimaryKey }}}: number | string) {
return request.post<null>({ url: '/{{{.ModuleName}}}/del', data: { {{{toUpperCamelCase .PrimaryKey }}} } })
}
// {{{.FunctionName}}}导入

View File

@@ -12,7 +12,7 @@
<el-form ref="formRef" :model="formData" label-width="84px" :rules="formRules">
{{{- range .Columns }}}
{{{- if .IsEdit }}}
{{{- if ne (toUpperCamelCase .GoField) "id" }}}
{{{- if ne (toUpperCamelCase .GoField) "Id" }}}
{{{- if and (ne $.Table.TreeParent "") (eq (toUpperCamelCase .GoField) $.Table.TreeParent) }}}
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toUpperCamelCase .GoField) }}}">
<el-tree-select
@@ -59,8 +59,8 @@
<el-checkbox
v-for="(item, index) in listAllData.{{{pathToName .ListAllApi }}}"
:key="index"
:label="item.id"
:value="item.id"
:label="item.{{{toUpperCamelCase .PrimaryKey }}}"
:value="item.{{{toUpperCamelCase .PrimaryKey }}}"
></el-checkbox>
{{{- else }}}
<el-checkbox>请选择字典生成</el-checkbox>
@@ -87,11 +87,11 @@
<el-option
v-for="(item, index) in listAllData.{{{pathToName .ListAllApi }}}"
:key="index"
:label="item.id"
:label="item.{{{toUpperCamelCase .PrimaryKey }}}"
{{{- if eq .GoType "int" }}}
:value="parseInt(item.id)"
:value="parseInt(item.{{{toUpperCamelCase .PrimaryKey }}})"
{{{- else }}}
:value="String(item.id)"
:value="String(item.{{{toUpperCamelCase .PrimaryKey }}})"
{{{- end }}}
clearable
/>
@@ -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 }}} }}
</el-radio>
{{{- else }}}
<el-radio label="0">请选择字典生成</el-radio>
@@ -260,7 +260,7 @@ const setFormData = async (data: Record<string, any>) => {
const getDetail = async (row: Record<string, any>) => {
try {
const data = await {{{ .ModuleName }}}_detail(row.{{{ .PrimaryKey }}})
const data = await {{{ .ModuleName }}}_detail(row.{{{toUpperCamelCase .PrimaryKey }}})
setFormData(data)
} catch (error) {}
}

View File

@@ -31,8 +31,8 @@
<el-option
v-for="(item, index) in listAllData.{{{pathToName .ListAllApi}}}"
:key="index"
:label="item.id"
:value="item.id"
:label="item.{{{toUpperCamelCase .PrimaryKey }}}"
:value="item.{{{toUpperCamelCase .PrimaryKey }}}"
/>
{{{- else }}}
<el-option label="请选择字典生成" value="" />
@@ -82,7 +82,7 @@
{{{- else if and (ne .ListAllApi "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
<el-table-column label="{{{ .ColumnComment }}}" prop="{{{ (.GoField) }}}" min-width="100">
<template #default="{ row }">
<dict-value :options="listAllData.{{{pathToName .ListAllApi }}}" :value="row.{{{ (.GoField) }}}" labelKey='id' valueKey='id' />
<dict-value :options="listAllData.{{{pathToName .ListAllApi }}}" :value="row.{{{ (.GoField) }}}" labelKey='{{{toUpperCamelCase .PrimaryKey }}}' valueKey='{{{toUpperCamelCase .PrimaryKey }}}' />
</template>
</el-table-column>
{{{- 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()
}

View File

@@ -32,8 +32,8 @@
<el-option
v-for="(item, index) in listAllData.{{{pathToName .ListAllApi}}}"
:key="index"
:label="item.id"
:value="item.id"
:label="item.{{{toUpperCamelCase .PrimaryKey }}}"
:value="item.{{{toUpperCamelCase .PrimaryKey }}}"
/>
{{{- else }}}
<el-option label="请选择字典生成" value="" />
@@ -100,7 +100,7 @@
{{{- else if and (ne .ListAllApi "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
<el-table-column label="{{{ .ColumnComment }}}" prop="{{{ (toUpperCamelCase .GoField) }}}" min-width="100">
<template #default="{ row }">
<dict-value :options="listAllData.{{{pathToName .ListAllApi }}}" :value="row.{{{ (toUpperCamelCase .GoField) }}}" labelKey='id' valueKey='id' />
<dict-value :options="listAllData.{{{pathToName .ListAllApi }}}" :value="row.{{{ (toUpperCamelCase .GoField) }}}" labelKey='{{{toUpperCamelCase .PrimaryKey }}}' valueKey='{{{toUpperCamelCase .PrimaryKey }}}' />
</template>
</el-table-column>
@@ -136,7 +136,7 @@
v-perms="['admin:{{{ .ModuleName }}}:del']"
type="danger"
link
@click="handleDelete(row.{{{ .PrimaryKey }}})"
@click="handleDelete(row.{{{toUpperCamelCase .PrimaryKey }}})"
>
删除
</el-button>
@@ -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) {}

View File

@@ -24,7 +24,9 @@ var TemplateUtil = templateUtil{
"toUpperCamelCase": util.StringUtil.ToUpperCamelCase,
"contains": util.ToolsUtil.Contains,
"goToTsType": GenUtil.GoToTsType,
"goToNullType": GenUtil.GoToNullType,
"goToParamType": GenUtil.GoToParamType,
"goWithAddEditType": GenUtil.GoWithAddEditType,
"goWithRespType": GenUtil.GoWithRespType,
"getPageResp": GenUtil.GetPageResp,
"nameToPath": GenUtil.NameToPath,
"pathToName": GenUtil.PathToName,

View File

@@ -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"
}
// 拼接字符串

View File

@@ -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 {

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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
}