public: 发布2.8.0版本 (#1998)
* feat:修改token获取优先级,优先从header获取 * feat: 增加业务ctx的传递 * fix文件选择问题, 有公共函数onDownloadFile,去掉downloadFile * 没问题 * feat: 增加context引入 * fix: 修复图片多选的情况下点击确定抽屉无法收起的bug * feat: 提高header的token优先级,优化导出表格逻辑,不再依赖于cookie鉴权 --------- Co-authored-by: piexlMax(奇淼 <qimiaojiangjizhao@gmail.com> Co-authored-by: task <121913992@qq.com>
This commit is contained in:
@@ -7,8 +7,10 @@
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/{{.Router}} [{{.Method}}]
|
||||
func (a *{{.Abbreviation}}) {{.FuncName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
// 请添加自己的业务逻辑
|
||||
err := service{{ .StructName }}.{{.FuncName}}()
|
||||
err := service{{ .StructName }}.{{.FuncName}}(ctx)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("失败!", zap.Error(err))
|
||||
response.FailWithMessage("失败", c)
|
||||
@@ -28,8 +30,10 @@ func (a *{{.Abbreviation}}) {{.FuncName}}(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "成功"
|
||||
// @Router /{{.Abbreviation}}/{{.Router}} [{{.Method}}]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api){{.FuncName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
// 请添加自己的业务逻辑
|
||||
err := {{.Abbreviation}}Service.{{.FuncName}}()
|
||||
err := {{.Abbreviation}}Service.{{.FuncName}}(ctx)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("失败!", zap.Error(err))
|
||||
response.FailWithMessage("失败", c)
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
// {{.FuncName}} {{.FuncDesc}}
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (s *{{.Abbreviation}}) {{.FuncName}}() (err error) {
|
||||
func (s *{{.Abbreviation}}) {{.FuncName}}(ctx context.Context) (err error) {
|
||||
db := {{$db}}.Model(&model.{{.StructName}}{})
|
||||
return db.Error
|
||||
}
|
||||
@@ -17,9 +17,9 @@ func (s *{{.Abbreviation}}) {{.FuncName}}() (err error) {
|
||||
|
||||
// {{.FuncName}} {{.FuncDesc}}
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service){{.FuncName}}() (err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service){{.FuncName}}(ctx context.Context) (err error) {
|
||||
// 请在这里实现自己的业务逻辑
|
||||
db := {{$db}}.Model(&{{.Package}}.{{.StructName}}{})
|
||||
return db.Error
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
@@ -33,6 +33,9 @@ type {{.StructName}}Api struct {}
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /{{.Abbreviation}}/create{{.StructName}} [post]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
var {{.Abbreviation}} {{.Package}}.{{.StructName}}
|
||||
err := c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
if err != nil {
|
||||
@@ -42,7 +45,7 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Con
|
||||
{{- if .AutoCreateResource }}
|
||||
{{.Abbreviation}}.CreatedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
err = {{.Abbreviation}}Service.Create{{.StructName}}(&{{.Abbreviation}})
|
||||
err = {{.Abbreviation}}Service.Create{{.StructName}}(ctx,&{{.Abbreviation}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败:" + err.Error(), c)
|
||||
@@ -61,11 +64,14 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Con
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
{{.PrimaryField.FieldJson}} := c.Query("{{.PrimaryField.FieldJson}}")
|
||||
{{- if .AutoCreateResource }}
|
||||
userID := utils.GetUserID(c)
|
||||
{{- end }}
|
||||
err := {{.Abbreviation}}Service.Delete{{.StructName}}({{.PrimaryField.FieldJson}} {{- if .AutoCreateResource -}},userID{{- end -}})
|
||||
err := {{.Abbreviation}}Service.Delete{{.StructName}}(ctx,{{.PrimaryField.FieldJson}} {{- if .AutoCreateResource -}},userID{{- end -}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败:" + err.Error(), c)
|
||||
@@ -83,11 +89,14 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Con
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
{{.PrimaryField.FieldJson}}s := c.QueryArray("{{.PrimaryField.FieldJson}}s[]")
|
||||
{{- if .AutoCreateResource }}
|
||||
userID := utils.GetUserID(c)
|
||||
{{- end }}
|
||||
err := {{.Abbreviation}}Service.Delete{{.StructName}}ByIds({{.PrimaryField.FieldJson}}s{{- if .AutoCreateResource }},userID{{- end }})
|
||||
err := {{.Abbreviation}}Service.Delete{{.StructName}}ByIds(ctx,{{.PrimaryField.FieldJson}}s{{- if .AutoCreateResource }},userID{{- end }})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败:" + err.Error(), c)
|
||||
@@ -106,6 +115,9 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gi
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /{{.Abbreviation}}/update{{.StructName}} [put]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Context) {
|
||||
// 从ctx获取标准context进行业务行为
|
||||
ctx := c.Request.Context()
|
||||
|
||||
var {{.Abbreviation}} {{.Package}}.{{.StructName}}
|
||||
err := c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
if err != nil {
|
||||
@@ -115,7 +127,7 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Con
|
||||
{{- if .AutoCreateResource }}
|
||||
{{.Abbreviation}}.UpdatedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
err = {{.Abbreviation}}Service.Update{{.StructName}}({{.Abbreviation}})
|
||||
err = {{.Abbreviation}}Service.Update{{.StructName}}(ctx,{{.Abbreviation}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败:" + err.Error(), c)
|
||||
@@ -134,8 +146,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Con
|
||||
// @Success 200 {object} response.Response{data={{.Package}}.{{.StructName}},msg=string} "查询成功"
|
||||
// @Router /{{.Abbreviation}}/find{{.StructName}} [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
{{.PrimaryField.FieldJson}} := c.Query("{{.PrimaryField.FieldJson}}")
|
||||
re{{.Abbreviation}}, err := {{.Abbreviation}}Service.Get{{.StructName}}({{.PrimaryField.FieldJson}})
|
||||
re{{.Abbreviation}}, err := {{.Abbreviation}}Service.Get{{.StructName}}(ctx,{{.PrimaryField.FieldJson}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败:" + err.Error(), c)
|
||||
@@ -154,7 +169,10 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Conte
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Context) {
|
||||
list, err := {{.Abbreviation}}Service.Get{{.StructName}}InfoList()
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
list, err := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(ctx)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败:" + err.Error(), c)
|
||||
@@ -173,13 +191,16 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Co
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
var pageInfo {{.Package}}Req.{{.StructName}}Search
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(pageInfo)
|
||||
list, total, err := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(ctx,pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败:" + err.Error(), c)
|
||||
@@ -203,8 +224,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Co
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}DataSource [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}DataSource(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
// 此接口为获取数据源定义的数据
|
||||
dataSource, err := {{.Abbreviation}}Service.Get{{.StructName}}DataSource()
|
||||
dataSource, err := {{.Abbreviation}}Service.Get{{.StructName}}DataSource(ctx)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败:" + err.Error(), c)
|
||||
@@ -224,9 +248,12 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}DataSource(c *
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}Public [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}Public(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
// 此接口不需要鉴权
|
||||
// 示例为返回了一个固定的消息接口,一般本接口用于C端服务,需要自己实现业务逻辑
|
||||
{{.Abbreviation}}Service.Get{{.StructName}}Public()
|
||||
{{.Abbreviation}}Service.Get{{.StructName}}Public(ctx)
|
||||
response.OkWithDetailed(gin.H{
|
||||
"info": "不需要鉴权的{{.Description}}接口信息",
|
||||
}, "获取成功", c)
|
||||
|
@@ -58,6 +58,7 @@ package {{.Package}}
|
||||
|
||||
import (
|
||||
{{- if not .OnlyTemplate }}
|
||||
"context"
|
||||
"{{.Module}}/global"
|
||||
"{{.Module}}/model/{{.Package}}"
|
||||
{{- if not .IsTree}}
|
||||
@@ -77,14 +78,14 @@ type {{.StructName}}Service struct {}
|
||||
{{- if not .OnlyTemplate }}
|
||||
// Create{{.StructName}} 创建{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service) Create{{.StructName}}({{.Abbreviation}} *{{.Package}}.{{.StructName}}) (err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service) Create{{.StructName}}(ctx context.Context, {{.Abbreviation}} *{{.Package}}.{{.StructName}}) (err error) {
|
||||
err = {{$db}}.Create({{.Abbreviation}}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete{{.StructName}} 删除{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}({{.PrimaryField.FieldJson}} string{{- if .AutoCreateResource -}},userID uint{{- end -}}) (err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}(ctx context.Context, {{.PrimaryField.FieldJson}} string{{- if .AutoCreateResource -}},userID uint{{- end -}}) (err error) {
|
||||
{{- if .IsTree }}
|
||||
var count int64
|
||||
err = {{$db}}.Find(&{{.Package}}.{{.StructName}}{},"parent_id = ?",{{.PrimaryField.FieldJson}}).Count(&count).Error
|
||||
@@ -114,7 +115,7 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}({{.
|
||||
|
||||
// Delete{{.StructName}}ByIds 批量删除{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}ByIds({{.PrimaryField.FieldJson}}s []string {{- if .AutoCreateResource }},deleted_by uint{{- end}}) (err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}ByIds(ctx context.Context, {{.PrimaryField.FieldJson}}s []string {{- if .AutoCreateResource }},deleted_by uint{{- end}}) (err error) {
|
||||
{{- if .AutoCreateResource }}
|
||||
err = {{$db}}.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Model(&{{.Package}}.{{.StructName}}{}).Where("{{.PrimaryField.ColumnName}} in ?", {{.PrimaryField.FieldJson}}s).Update("deleted_by", deleted_by).Error; err != nil {
|
||||
@@ -133,14 +134,14 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}ById
|
||||
|
||||
// Update{{.StructName}} 更新{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Update{{.StructName}}({{.Abbreviation}} {{.Package}}.{{.StructName}}) (err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Update{{.StructName}}(ctx context.Context, {{.Abbreviation}} {{.Package}}.{{.StructName}}) (err error) {
|
||||
err = {{$db}}.Model(&{{.Package}}.{{.StructName}}{}).Where("{{.PrimaryField.ColumnName}} = ?",{{.Abbreviation}}.{{.PrimaryField.FieldName}}).Updates(&{{.Abbreviation}}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// Get{{.StructName}} 根据{{.PrimaryField.FieldJson}}获取{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}({{.PrimaryField.FieldJson}} string) ({{.Abbreviation}} {{.Package}}.{{.StructName}}, err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}(ctx context.Context, {{.PrimaryField.FieldJson}} string) ({{.Abbreviation}} {{.Package}}.{{.StructName}}, err error) {
|
||||
err = {{$db}}.Where("{{.PrimaryField.ColumnName}} = ?", {{.PrimaryField.FieldJson}}).First(&{{.Abbreviation}}).Error
|
||||
return
|
||||
}
|
||||
@@ -149,7 +150,7 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}({{.Pri
|
||||
{{- if .IsTree }}
|
||||
// Get{{.StructName}}InfoList 分页获取{{.Description}}记录,Tree模式下不添加分页和搜索
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoList() (list []*{{.Package}}.{{.StructName}},err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoList(ctx context.Context) (list []*{{.Package}}.{{.StructName}},err error) {
|
||||
// 创建db
|
||||
db := {{$db}}.Model(&{{.Package}}.{{.StructName}}{})
|
||||
var {{.Abbreviation}}s []*{{.Package}}.{{.StructName}}
|
||||
@@ -161,7 +162,7 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoLis
|
||||
{{- else }}
|
||||
// Get{{.StructName}}InfoList 分页获取{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoList(info {{.Package}}Req.{{.StructName}}Search) (list []{{.Package}}.{{.StructName}}, total int64, err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoList(ctx context.Context, info {{.Package}}Req.{{.StructName}}Search) (list []{{.Package}}.{{.StructName}}, total int64, err error) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
@@ -226,7 +227,7 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoLis
|
||||
{{- end }}
|
||||
|
||||
{{- if .HasDataSource }}
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}DataSource() (res map[string][]map[string]any, err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}DataSource(ctx context.Context) (res map[string][]map[string]any, err error) {
|
||||
res = make(map[string][]map[string]any)
|
||||
{{range $key, $value := .DataSourceMap}}
|
||||
{{$key}} := make([]map[string]any, 0)
|
||||
@@ -243,7 +244,7 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}DataSou
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}Public() {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}Public(ctx context.Context) {
|
||||
// 此方法为获取数据源定义的数据
|
||||
// 请自行实现
|
||||
}
|
||||
|
@@ -131,7 +131,7 @@
|
||||
<el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="200">
|
||||
<template #default="scope">
|
||||
<div class="file-list">
|
||||
<el-tag v-for="file in scope.row.{{.FieldJson}}" :key="file.uid" @click="downloadFile(file.url)">{{"{{"}}file.name{{"}}"}}</el-tag>
|
||||
<el-tag v-for="file in scope.row.{{.FieldJson}}" :key="file.uid" @click="onDownloadFile(file.url)">{{"{{"}}file.name{{"}}"}}</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -607,7 +607,7 @@ getDataSourceFunc()
|
||||
<el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="200">
|
||||
<template #default="scope">
|
||||
<div class="file-list">
|
||||
<el-tag v-for="file in scope.row.{{.FieldJson}}" :key="file.uid" @click="downloadFile(file.url)">{{"{{"}}file.name{{"}}"}}</el-tag>
|
||||
<el-tag v-for="file in scope.row.{{.FieldJson}}" :key="file.uid" @click="onDownloadFile(file.url)">{{"{{"}}file.name{{"}}"}}</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -1297,11 +1297,6 @@ const enterDialog = async () => {
|
||||
}
|
||||
})
|
||||
}
|
||||
{{if .HasFile }}
|
||||
const downloadFile = (url) => {
|
||||
window.open(getUrl(url), '_blank')
|
||||
}
|
||||
{{end}}
|
||||
|
||||
const detailFrom = ref({})
|
||||
|
||||
|
@@ -33,6 +33,9 @@ type {{.Abbreviation}} struct {}
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /{{.Abbreviation}}/create{{.StructName}} [post]
|
||||
func (a *{{.Abbreviation}}) Create{{.StructName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
var info model.{{.StructName}}
|
||||
err := c.ShouldBindJSON(&info)
|
||||
if err != nil {
|
||||
@@ -42,7 +45,7 @@ func (a *{{.Abbreviation}}) Create{{.StructName}}(c *gin.Context) {
|
||||
{{- if .AutoCreateResource }}
|
||||
info.CreatedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
err = service{{ .StructName }}.Create{{.StructName}}(&info)
|
||||
err = service{{ .StructName }}.Create{{.StructName}}(ctx,&info)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败:" + err.Error(), c)
|
||||
@@ -61,11 +64,14 @@ func (a *{{.Abbreviation}}) Create{{.StructName}}(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
|
||||
func (a *{{.Abbreviation}}) Delete{{.StructName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
{{.PrimaryField.FieldJson}} := c.Query("{{.PrimaryField.FieldJson}}")
|
||||
{{- if .AutoCreateResource }}
|
||||
userID := utils.GetUserID(c)
|
||||
{{- end }}
|
||||
err := service{{ .StructName }}.Delete{{.StructName}}({{.PrimaryField.FieldJson}} {{- if .AutoCreateResource -}},userID{{- end -}})
|
||||
err := service{{ .StructName }}.Delete{{.StructName}}(ctx,{{.PrimaryField.FieldJson}} {{- if .AutoCreateResource -}},userID{{- end -}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败:" + err.Error(), c)
|
||||
@@ -83,11 +89,14 @@ func (a *{{.Abbreviation}}) Delete{{.StructName}}(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete]
|
||||
func (a *{{.Abbreviation}}) Delete{{.StructName}}ByIds(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
{{.PrimaryField.FieldJson}}s := c.QueryArray("{{.PrimaryField.FieldJson}}s[]")
|
||||
{{- if .AutoCreateResource }}
|
||||
userID := utils.GetUserID(c)
|
||||
{{- end }}
|
||||
err := service{{ .StructName }}.Delete{{.StructName}}ByIds({{.PrimaryField.FieldJson}}s{{- if .AutoCreateResource }},userID{{- end }})
|
||||
err := service{{ .StructName }}.Delete{{.StructName}}ByIds(ctx,{{.PrimaryField.FieldJson}}s{{- if .AutoCreateResource }},userID{{- end }})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败:" + err.Error(), c)
|
||||
@@ -106,6 +115,9 @@ func (a *{{.Abbreviation}}) Delete{{.StructName}}ByIds(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /{{.Abbreviation}}/update{{.StructName}} [put]
|
||||
func (a *{{.Abbreviation}}) Update{{.StructName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
var info model.{{.StructName}}
|
||||
err := c.ShouldBindJSON(&info)
|
||||
if err != nil {
|
||||
@@ -115,7 +127,7 @@ func (a *{{.Abbreviation}}) Update{{.StructName}}(c *gin.Context) {
|
||||
{{- if .AutoCreateResource }}
|
||||
info.UpdatedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
err = service{{ .StructName }}.Update{{.StructName}}(info)
|
||||
err = service{{ .StructName }}.Update{{.StructName}}(ctx,info)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败:" + err.Error(), c)
|
||||
@@ -134,8 +146,11 @@ func (a *{{.Abbreviation}}) Update{{.StructName}}(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{data=model.{{.StructName}},msg=string} "查询成功"
|
||||
// @Router /{{.Abbreviation}}/find{{.StructName}} [get]
|
||||
func (a *{{.Abbreviation}}) Find{{.StructName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
{{.PrimaryField.FieldJson}} := c.Query("{{.PrimaryField.FieldJson}}")
|
||||
re{{.Abbreviation}}, err := service{{ .StructName }}.Get{{.StructName}}({{.PrimaryField.FieldJson}})
|
||||
re{{.Abbreviation}}, err := service{{ .StructName }}.Get{{.StructName}}(ctx,{{.PrimaryField.FieldJson}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败:" + err.Error(), c)
|
||||
@@ -154,7 +169,10 @@ func (a *{{.Abbreviation}}) Find{{.StructName}}(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
|
||||
func (a *{{.Abbreviation}}) Get{{.StructName}}List(c *gin.Context) {
|
||||
list, err := service{{ .StructName }}.Get{{.StructName}}InfoList()
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
list, err := service{{ .StructName }}.Get{{.StructName}}InfoList(ctx)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败:" + err.Error(), c)
|
||||
@@ -173,13 +191,16 @@ func (a *{{.Abbreviation}}) Get{{.StructName}}List(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
|
||||
func (a *{{.Abbreviation}}) Get{{.StructName}}List(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
var pageInfo request.{{.StructName}}Search
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := service{{ .StructName }}.Get{{.StructName}}InfoList(pageInfo)
|
||||
list, total, err := service{{ .StructName }}.Get{{.StructName}}InfoList(ctx,pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败:" + err.Error(), c)
|
||||
@@ -203,8 +224,11 @@ func (a *{{.Abbreviation}}) Get{{.StructName}}List(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}DataSource [get]
|
||||
func (a *{{.Abbreviation}}) Get{{.StructName}}DataSource(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
// 此接口为获取数据源定义的数据
|
||||
dataSource, err := service{{ .StructName }}.Get{{.StructName}}DataSource()
|
||||
dataSource, err := service{{ .StructName }}.Get{{.StructName}}DataSource(ctx)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败:" + err.Error(), c)
|
||||
@@ -222,7 +246,10 @@ func (a *{{.Abbreviation}}) Get{{.StructName}}DataSource(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}Public [get]
|
||||
func (a *{{.Abbreviation}}) Get{{.StructName}}Public(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
|
||||
// 此接口不需要鉴权 示例为返回了一个固定的消息接口,一般本接口用于C端服务,需要自己实现业务逻辑
|
||||
service{{ .StructName }}.Get{{.StructName}}Public()
|
||||
service{{ .StructName }}.Get{{.StructName}}Public(ctx)
|
||||
response.OkWithDetailed(gin.H{"info": "不需要鉴权的{{.Description}}接口信息"}, "获取成功", c)
|
||||
}
|
||||
|
@@ -58,6 +58,7 @@ package service
|
||||
|
||||
import (
|
||||
{{- if not .OnlyTemplate }}
|
||||
"context"
|
||||
"{{.Module}}/global"
|
||||
"{{.Module}}/plugin/{{.Package}}/model"
|
||||
{{- if not .IsTree }}
|
||||
@@ -87,14 +88,14 @@ type {{.Abbreviation}} struct {}
|
||||
{{- if not .OnlyTemplate }}
|
||||
// Create{{.StructName}} 创建{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (s *{{.Abbreviation}}) Create{{.StructName}}({{.Abbreviation}} *model.{{.StructName}}) (err error) {
|
||||
func (s *{{.Abbreviation}}) Create{{.StructName}}(ctx context.Context, {{.Abbreviation}} *model.{{.StructName}}) (err error) {
|
||||
err = {{$db}}.Create({{.Abbreviation}}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete{{.StructName}} 删除{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (s *{{.Abbreviation}}) Delete{{.StructName}}({{.PrimaryField.FieldJson}} string{{- if .AutoCreateResource -}},userID uint{{- end -}}) (err error) {
|
||||
func (s *{{.Abbreviation}}) Delete{{.StructName}}(ctx context.Context, {{.PrimaryField.FieldJson}} string{{- if .AutoCreateResource -}},userID uint{{- end -}}) (err error) {
|
||||
|
||||
{{- if .IsTree }}
|
||||
var count int64
|
||||
@@ -125,7 +126,7 @@ func (s *{{.Abbreviation}}) Delete{{.StructName}}({{.PrimaryField.FieldJson}} st
|
||||
|
||||
// Delete{{.StructName}}ByIds 批量删除{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (s *{{.Abbreviation}}) Delete{{.StructName}}ByIds({{.PrimaryField.FieldJson}}s []string {{- if .AutoCreateResource }},deleted_by uint{{- end}}) (err error) {
|
||||
func (s *{{.Abbreviation}}) Delete{{.StructName}}ByIds(ctx context.Context, {{.PrimaryField.FieldJson}}s []string {{- if .AutoCreateResource }},deleted_by uint{{- end}}) (err error) {
|
||||
{{- if .AutoCreateResource }}
|
||||
err = {{$db}}.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Model(&model.{{.StructName}}{}).Where("{{.PrimaryField.ColumnName}} in ?", {{.PrimaryField.FieldJson}}s).Update("deleted_by", deleted_by).Error; err != nil {
|
||||
@@ -144,14 +145,14 @@ func (s *{{.Abbreviation}}) Delete{{.StructName}}ByIds({{.PrimaryField.FieldJson
|
||||
|
||||
// Update{{.StructName}} 更新{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (s *{{.Abbreviation}}) Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
|
||||
func (s *{{.Abbreviation}}) Update{{.StructName}}(ctx context.Context, {{.Abbreviation}} model.{{.StructName}}) (err error) {
|
||||
err = {{$db}}.Model(&model.{{.StructName}}{}).Where("{{.PrimaryField.ColumnName}} = ?",{{.Abbreviation}}.{{.PrimaryField.FieldName}}).Updates(&{{.Abbreviation}}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// Get{{.StructName}} 根据{{.PrimaryField.FieldJson}}获取{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (s *{{.Abbreviation}}) Get{{.StructName}}({{.PrimaryField.FieldJson}} string) ({{.Abbreviation}} model.{{.StructName}}, err error) {
|
||||
func (s *{{.Abbreviation}}) Get{{.StructName}}(ctx context.Context, {{.PrimaryField.FieldJson}} string) ({{.Abbreviation}} model.{{.StructName}}, err error) {
|
||||
err = {{$db}}.Where("{{.PrimaryField.ColumnName}} = ?", {{.PrimaryField.FieldJson}}).First(&{{.Abbreviation}}).Error
|
||||
return
|
||||
}
|
||||
@@ -160,7 +161,7 @@ func (s *{{.Abbreviation}}) Get{{.StructName}}({{.PrimaryField.FieldJson}} strin
|
||||
{{- if .IsTree }}
|
||||
// Get{{.StructName}}InfoList 分页获取{{.Description}}记录,Tree模式下不添加分页和搜索
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (s *{{.Abbreviation}}) Get{{.StructName}}InfoList() (list []*model.{{.StructName}},err error) {
|
||||
func (s *{{.Abbreviation}}) Get{{.StructName}}InfoList(ctx context.Context) (list []*model.{{.StructName}},err error) {
|
||||
// 创建db
|
||||
db := {{$db}}.Model(&model.{{.StructName}}{})
|
||||
var {{.Abbreviation}}s []*model.{{.StructName}}
|
||||
@@ -172,7 +173,7 @@ func (s *{{.Abbreviation}}) Get{{.StructName}}InfoList() (list []*model.{{.Struc
|
||||
{{- else }}
|
||||
// Get{{.StructName}}InfoList 分页获取{{.Description}}记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (s *{{.Abbreviation}}) Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (list []model.{{.StructName}}, total int64, err error) {
|
||||
func (s *{{.Abbreviation}}) Get{{.StructName}}InfoList(ctx context.Context, info request.{{.StructName}}Search) (list []model.{{.StructName}}, total int64, err error) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
@@ -234,7 +235,7 @@ func (s *{{.Abbreviation}}) Get{{.StructName}}InfoList(info request.{{.StructNam
|
||||
}
|
||||
{{- end }}
|
||||
{{- if .HasDataSource }}
|
||||
func (s *{{.Abbreviation}})Get{{.StructName}}DataSource() (res map[string][]map[string]any, err error) {
|
||||
func (s *{{.Abbreviation}})Get{{.StructName}}DataSource(ctx context.Context) (res map[string][]map[string]any, err error) {
|
||||
res = make(map[string][]map[string]any)
|
||||
{{range $key, $value := .DataSourceMap}}
|
||||
{{$key}} := make([]map[string]any, 0)
|
||||
@@ -252,7 +253,7 @@ func (s *{{.Abbreviation}})Get{{.StructName}}DataSource() (res map[string][]map[
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
func (s *{{.Abbreviation}})Get{{.StructName}}Public() {
|
||||
func (s *{{.Abbreviation}})Get{{.StructName}}Public(ctx context.Context) {
|
||||
|
||||
}
|
||||
{{- end }}
|
||||
|
@@ -131,7 +131,7 @@
|
||||
<el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="200">
|
||||
<template #default="scope">
|
||||
<div class="file-list">
|
||||
<el-tag v-for="file in scope.row.{{.FieldJson}}" :key="file.uid" @click="downloadFile(file.url)">{{"{{"}}file.name{{"}}"}}</el-tag>
|
||||
<el-tag v-for="file in scope.row.{{.FieldJson}}" :key="file.uid" @click="onDownloadFile(file.url)">{{"{{"}}file.name{{"}}"}}</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -607,7 +607,7 @@ getDataSourceFunc()
|
||||
<el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="200">
|
||||
<template #default="scope">
|
||||
<div class="file-list">
|
||||
<el-tag v-for="file in scope.row.{{.FieldJson}}" :key="file.uid" @click="downloadFile(file.url)">{{"{{"}}file.name{{"}}"}}</el-tag>
|
||||
<el-tag v-for="file in scope.row.{{.FieldJson}}" :key="file.uid" @click="onDownloadFile(file.url)">{{"{{"}}file.name{{"}}"}}</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -1295,11 +1295,6 @@ const enterDialog = async () => {
|
||||
}
|
||||
})
|
||||
}
|
||||
{{if .HasFile }}
|
||||
const downloadFile = (url) => {
|
||||
window.open(getUrl(url), '_blank')
|
||||
}
|
||||
{{end}}
|
||||
|
||||
const detailFrom = ref({})
|
||||
|
||||
|
Reference in New Issue
Block a user