mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-10-24 16:40:25 +08:00
去掉生成方式
This commit is contained in:
@@ -217,25 +217,7 @@
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="生成方式" prop="gen.genType">
|
||||
<el-radio-group v-model="formData.gen.genType">
|
||||
<el-radio :label="GenType.ZIP">压缩包下载</el-radio>
|
||||
<el-radio :label="GenType.CUSTOM_PATH">自定义路径</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="formData.gen.genType == GenType.CUSTOM_PATH"
|
||||
label="自定义路径"
|
||||
prop="gen.genPath"
|
||||
>
|
||||
<div class="w-80">
|
||||
<el-input
|
||||
v-model="formData.gen.genPath"
|
||||
placeholder="请输入自定义路径"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<template v-if="formData.gen.genTpl == GenTpl.TREE">
|
||||
<el-form-item label="树主键字段" prop="gen.treePrimary">
|
||||
<el-select
|
||||
@@ -295,11 +277,6 @@ enum GenTpl {
|
||||
TREE = 'tree'
|
||||
}
|
||||
|
||||
enum GenType {
|
||||
ZIP,
|
||||
CUSTOM_PATH
|
||||
}
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { removeTab } = useMultipleTabs()
|
||||
@@ -316,9 +293,8 @@ const formData = reactive({
|
||||
column: [] as any[],
|
||||
gen: {
|
||||
functionName: '',
|
||||
genPath: '',
|
||||
|
||||
genTpl: '',
|
||||
genType: 0,
|
||||
moduleName: '',
|
||||
subTableFk: '',
|
||||
subTableName: '',
|
||||
|
||||
@@ -206,23 +206,15 @@ const handlePreview = async (id: number) => {
|
||||
}
|
||||
|
||||
const handleGenerate = async (selectData: any[]) => {
|
||||
const downloadTables = getTables(selectData, 0)
|
||||
const genTables = getTables(selectData, 1)
|
||||
const downloadTables = getTables(selectData)
|
||||
if (downloadTables) {
|
||||
const file = await downloadCode({ tables: downloadTables })
|
||||
streamFileDownload(file, 'code_' + downloadTables + '.zip')
|
||||
}
|
||||
if (genTables) {
|
||||
await generateCode({ tables: genTables })
|
||||
feedback.msgSuccess('生成成功')
|
||||
}
|
||||
}
|
||||
|
||||
const getTables = (selectData: any[], type: 0 | 1) => {
|
||||
return selectData
|
||||
.filter(({ genType }) => genType == type)
|
||||
.map(({ tableName }) => tableName)
|
||||
.join()
|
||||
const getTables = (selectData: any[]) => {
|
||||
return selectData.map(({ tableName }) => tableName).join()
|
||||
}
|
||||
|
||||
const handleCommand = (command: any, row: any) => {
|
||||
|
||||
@@ -129,20 +129,20 @@ func (gh genHandler) previewCode(c *gin.Context) {
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// genCode 生成代码
|
||||
func (gh genHandler) genCode(c *gin.Context) {
|
||||
var genReq GenCodeReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &genReq)) {
|
||||
return
|
||||
}
|
||||
for _, table := range strings.Split(genReq.Tables, ",") {
|
||||
err := gh.Service.GenCode(table)
|
||||
if response.IsFailWithResp(c, err) {
|
||||
return
|
||||
}
|
||||
}
|
||||
response.Ok(c)
|
||||
}
|
||||
// // genCode 生成代码,生成到服务器自定义路径存在风险,禁止使用
|
||||
// func (gh genHandler) genCode(c *gin.Context) {
|
||||
// var genReq GenCodeReq
|
||||
// if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &genReq)) {
|
||||
// return
|
||||
// }
|
||||
// for _, table := range strings.Split(genReq.Tables, ",") {
|
||||
// err := gh.Service.GenCode(table)
|
||||
// if response.IsFailWithResp(c, err) {
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// response.Ok(c)
|
||||
// }
|
||||
|
||||
// downloadCode 下载代码
|
||||
func (gh genHandler) downloadCode(c *gin.Context) {
|
||||
|
||||
@@ -71,8 +71,7 @@ type EditTableReq struct {
|
||||
GenTpl string `form:"genTpl" binding:"oneof=crud tree"` // 生成模板方式: [crud=单表, tree=树表]
|
||||
ModuleName string `form:"moduleName" binding:"required,min=1,max=60"` // 生成模块名
|
||||
FunctionName string `form:"functionName" binding:"required,min=1,max=60"` // 生成功能名
|
||||
GenType int `form:"genType" binding:"oneof=0 1"` // 生成代码方式: [0=zip压缩包, 1=自定义路径]
|
||||
GenPath string `form:"genPath,default=/" binding:"required,max=60"` // 生成路径
|
||||
|
||||
TreePrimary string `form:"treePrimary"` // 树表主键
|
||||
TreeParent string `form:"treeParent"` // 树表父键
|
||||
TreeName string `form:"treeName"` // 树表名称
|
||||
@@ -112,7 +111,7 @@ type DbTableResp struct {
|
||||
// GenTableResp 生成表返回信息
|
||||
type GenTableResp struct {
|
||||
ID uint `json:"id" structs:"id"` // 主键
|
||||
GenType int `json:"genType" structs:"genType"` // 生成类型
|
||||
|
||||
TableName string `json:"tableName" structs:"tableName"` // 表名称
|
||||
TableComment string `json:"tableComment" structs:"tableComment"` // 表描述
|
||||
CreateTime core.TsTime `json:"createTime" structs:"createTime"` // 创建时间
|
||||
@@ -134,8 +133,7 @@ type GenTableBaseResp struct {
|
||||
// GenTableGenResp 生成表生成返回信息
|
||||
type GenTableGenResp struct {
|
||||
GenTpl string `json:"genTpl" structs:"genTpl"` // 生成模板方式: [crud=单表, tree=树表]
|
||||
GenType int `json:"genType" structs:"genType"` // 生成代码方式: [0=zip压缩包, 1=自定义路径]
|
||||
GenPath string `json:"genPath" structs:"genPath"` // 生成代码路径: [不填默认项目路径]
|
||||
|
||||
ModuleName string `json:"moduleName" structs:"moduleName"` // 生成模块名
|
||||
FunctionName string `json:"functionName" structs:"functionName"` // 生成功能名
|
||||
TreePrimary string `json:"treePrimary" structs:"treePrimary"` // 树主键字段
|
||||
|
||||
@@ -383,31 +383,6 @@ func (genSrv generateService) PreviewCode(id uint) (res map[string]string, e err
|
||||
return
|
||||
}
|
||||
|
||||
// GenCode 生成代码 (自定义路径)
|
||||
func (genSrv generateService) GenCode(tableName string) (e error) {
|
||||
var genTable gen_model.GenTable
|
||||
err := genSrv.db.Where("table_name = ?", tableName).Order("id desc").Limit(1).First(&genTable).Error
|
||||
if e = response.CheckErrDBNotRecord(err, "记录丢失!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "GenCode First err"); e != nil {
|
||||
return
|
||||
}
|
||||
//获取模板内容
|
||||
tplCodeMap, err := genSrv.renderCodeByTable(genTable)
|
||||
if e = response.CheckErr(err, "GenCode renderCodeByTable err"); e != nil {
|
||||
return
|
||||
}
|
||||
//获取生成根路径
|
||||
basePath := tpl_utils.TemplateUtil.GetGenPath(genTable)
|
||||
//生成代码文件
|
||||
err = tpl_utils.TemplateUtil.GenCodeFiles(tplCodeMap, genTable.TableName, basePath)
|
||||
if e = response.CheckErr(err, "GenCode GenCodeFiles err"); e != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// genZipCode 生成代码 (压缩包下载)
|
||||
func (genSrv generateService) genZipCode(zipWriter *zip.Writer, tableName string) (e error) {
|
||||
var genTable gen_model.GenTable
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
package {{{ .TableName }}}
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"x_admin/admin/schemas/req"
|
||||
"x_admin/admin/service/system"
|
||||
"x_admin/core"
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/middleware"
|
||||
"x_admin/util"
|
||||
)
|
||||
|
||||
|
||||
func {{{ title (toCamelCase .ModuleName) }}}Route(rg *gin.RouterGroup) {
|
||||
db := core.GetDB()
|
||||
|
||||
server := New{{{ title (toCamelCase .EntityName) }}}Service(db)
|
||||
|
||||
handle := productHandler{service: server}
|
||||
|
||||
rg = rg.Group("/", middleware.TokenAuth())
|
||||
rg.GET("/{{{ .ModuleName }}}/list", handle.List)
|
||||
rg.GET("/{{{ .ModuleName }}}/detail", handle.Detail)
|
||||
rg.POST("/{{{ .ModuleName }}}/add", handle.Add)
|
||||
rg.POST("/{{{ .ModuleName }}}/edit", handle.Edit)
|
||||
rg.POST("/{{{ .ModuleName }}}/del", handle.Del)
|
||||
}
|
||||
type {{{ toCamelCase .ModuleName }}}Handler struct {
|
||||
service I{{{ title (toCamelCase .EntityName) }}}Service
|
||||
}
|
||||
|
||||
//list {{{ .ModuleName }}}列表
|
||||
func (hd {{{ toCamelCase .ModuleName }}}Handler) List(c *gin.Context) {
|
||||
var page request.PageReq
|
||||
var listReq {{{ title (toCamelCase .EntityName) }}}ListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
|
||||
return
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := hd.service.List(page, listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
//detail {{{ .ModuleName }}}详情
|
||||
func (hd {{{ toCamelCase .ModuleName }}}Handler) Detail(c *gin.Context) {
|
||||
var detailReq {{{ title (toCamelCase .EntityName) }}}DetailReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
|
||||
return
|
||||
}
|
||||
res, err := hd.service.Detail(detailReq.{{{ title (toCamelCase .PrimaryKey) }}})
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
//add {{{ .ModuleName }}}新增
|
||||
func (hd {{{ toCamelCase .ModuleName }}}Handler) Add(c *gin.Context) {
|
||||
var addReq {{{ title (toCamelCase .EntityName) }}}AddReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &addReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, hd.service.Add(addReq))
|
||||
}
|
||||
|
||||
//edit {{{ .ModuleName }}}编辑
|
||||
func (hd {{{ toCamelCase .ModuleName }}}Handler) Edit(c *gin.Context) {
|
||||
var editReq {{{ title (toCamelCase .EntityName) }}}EditReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &editReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, hd.service.Edit(editReq))
|
||||
}
|
||||
|
||||
//del {{{ .ModuleName }}}删除
|
||||
func (hd {{{ toCamelCase .ModuleName }}}Handler) Del(c *gin.Context) {
|
||||
var delReq {{{ title (toCamelCase .EntityName) }}}DelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, hd.service.Del(delReq.{{{ title (toCamelCase .PrimaryKey) }}}))
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package {{{ .ModuleName }}}
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/util"
|
||||
)
|
||||
|
||||
|
||||
type {{{ title (toCamelCase .ModuleName) }}}Handler struct {
|
||||
Service I{{{ title (toCamelCase .EntityName) }}}Service
|
||||
}
|
||||
|
||||
//list {{{ .ModuleName }}}列表
|
||||
func (hd {{{ title (toCamelCase .ModuleName) }}}Handler) List(c *gin.Context) {
|
||||
var page request.PageReq
|
||||
var listReq {{{ title (toCamelCase .EntityName) }}}ListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
|
||||
return
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := hd.Service.List(page, listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
//detail {{{ .ModuleName }}}详情
|
||||
func (hd {{{ title (toCamelCase .ModuleName) }}}Handler) Detail(c *gin.Context) {
|
||||
var detailReq {{{ title (toCamelCase .EntityName) }}}DetailReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
|
||||
return
|
||||
}
|
||||
res, err := hd.Service.Detail(detailReq.{{{ title (toCamelCase .PrimaryKey) }}})
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
//add {{{ .ModuleName }}}新增
|
||||
func (hd {{{ title (toCamelCase .ModuleName) }}}Handler) Add(c *gin.Context) {
|
||||
var addReq {{{ title (toCamelCase .EntityName) }}}AddReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &addReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, hd.Service.Add(addReq))
|
||||
}
|
||||
|
||||
//edit {{{ .ModuleName }}}编辑
|
||||
func (hd {{{ title (toCamelCase .ModuleName) }}}Handler) Edit(c *gin.Context) {
|
||||
var editReq {{{ title (toCamelCase .EntityName) }}}EditReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &editReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, hd.Service.Edit(editReq))
|
||||
}
|
||||
|
||||
//del {{{ .ModuleName }}}删除
|
||||
func (hd {{{ title (toCamelCase .ModuleName) }}}Handler) Del(c *gin.Context) {
|
||||
var delReq {{{ title (toCamelCase .EntityName) }}}DelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, hd.Service.Del(delReq.{{{ title (toCamelCase .PrimaryKey) }}}))
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package model
|
||||
|
||||
//{{{ title (toCamelCase .EntityName) }}} {{{ .FunctionName }}}实体
|
||||
type {{{ title (toCamelCase .EntityName) }}} struct {
|
||||
{{{- range .Columns }}}
|
||||
{{{- if not (contains $.SubTableFields .ColumnName) }}}
|
||||
{{{ title (toCamelCase .GoField) }}} {{{ if eq .GoType "core.TsTime" }}} int64 {{{ else }}} {{{ .GoType }}} {{{ end }}} `gorm:"{{{ if .IsPk }}}primarykey;{{{ end }}}comment:'{{{ .ColumnComment }}}'"` // {{{ .ColumnComment }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"x_admin/core"
|
||||
"x_admin/middleware"
|
||||
"x_admin/admin/{{{ .ModuleName }}}"
|
||||
)
|
||||
|
||||
/**
|
||||
集成
|
||||
1. 导入
|
||||
- 请先提交git避免文件覆盖!!!
|
||||
- 下载并解压压缩包后,直接复制server、admin文件夹到项目根目录即可
|
||||
|
||||
2. 注册路由
|
||||
请在 admin/entry.go 文件引入{{{ title (toCamelCase .ModuleName) }}}Route注册路由
|
||||
|
||||
3. 后台手动添加菜单和按钮
|
||||
{{{ .ModuleName }}}:add
|
||||
{{{.ModuleName }}}:edit
|
||||
{{{.ModuleName }}}:del
|
||||
{{{.ModuleName }}}:list
|
||||
{{{.ModuleName }}}:detail
|
||||
*/
|
||||
|
||||
|
||||
// {{{ title (toCamelCase .ModuleName) }}}Route(rg)
|
||||
func {{{ title (toCamelCase .ModuleName) }}}Route(rg *gin.RouterGroup) {
|
||||
db := core.GetDB()
|
||||
|
||||
server := {{{ .ModuleName }}}.New{{{ title (toCamelCase .EntityName) }}}Service(db)
|
||||
|
||||
handle := {{{ .ModuleName}}}.{{{ title (toCamelCase .EntityName) }}}Handler{Service: server}
|
||||
|
||||
rg = rg.Group("/", middleware.TokenAuth())
|
||||
rg.GET("/{{{ .ModuleName }}}/list", handle.List)
|
||||
rg.GET("/{{{ .ModuleName }}}/detail", handle.Detail)
|
||||
rg.POST("/{{{ .ModuleName }}}/add", handle.Add)
|
||||
rg.POST("/{{{ .ModuleName }}}/edit", handle.Edit)
|
||||
rg.POST("/{{{ .ModuleName }}}/del", handle.Del)
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package {{{ .ModuleName }}}
|
||||
|
||||
import "x_admin/core"
|
||||
|
||||
//{{{ title (toCamelCase .EntityName) }}}ListReq {{{ .FunctionName }}}列表参数
|
||||
type {{{ title (toCamelCase .EntityName) }}}ListReq struct {
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsQuery }}}
|
||||
{{{ title (toCamelCase .GoField) }}} {{{ .GoType }}} `form:"{{{ toCamelCase .GoField }}}"` // {{{ .ColumnComment }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
}
|
||||
|
||||
//{{{ title (toCamelCase .EntityName) }}}DetailReq {{{ .FunctionName }}}详情参数
|
||||
type {{{ title (toCamelCase .EntityName) }}}DetailReq struct {
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsPk }}}
|
||||
{{{ title (toCamelCase .GoField) }}} {{{ .GoType }}} `form:"{{{ toCamelCase .GoField }}}"` // {{{ .ColumnComment }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
}
|
||||
|
||||
//{{{ title (toCamelCase .EntityName) }}}AddReq {{{ .FunctionName }}}新增参数
|
||||
type {{{ title (toCamelCase .EntityName) }}}AddReq struct {
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsInsert }}}
|
||||
{{{ title (toCamelCase .GoField) }}} {{{ .GoType }}} `form:"{{{ toCamelCase .GoField }}}"` // {{{ .ColumnComment }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
}
|
||||
|
||||
//{{{ title (toCamelCase .EntityName) }}}EditReq {{{ .FunctionName }}}新增参数
|
||||
type {{{ title (toCamelCase .EntityName) }}}EditReq struct {
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsEdit }}}
|
||||
{{{ title (toCamelCase .GoField) }}} {{{ .GoType }}} `form:"{{{ toCamelCase .GoField }}}"` // {{{ .ColumnComment }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
}
|
||||
|
||||
//{{{ title (toCamelCase .EntityName) }}}DelReq {{{ .FunctionName }}}新增参数
|
||||
type {{{ title (toCamelCase .EntityName) }}}DelReq struct {
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsPk }}}
|
||||
{{{ title (toCamelCase .GoField) }}} {{{ .GoType }}} `form:"{{{ toCamelCase .GoField }}}"` // {{{ .ColumnComment }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
}
|
||||
|
||||
//{{{ title (toCamelCase .EntityName) }}}Resp {{{ .FunctionName }}}返回信息
|
||||
type {{{ title (toCamelCase .EntityName) }}}Resp struct {
|
||||
{{{- range .Columns }}}
|
||||
{{{- if or .IsList .IsPk }}}
|
||||
{{{ title (toCamelCase .GoField) }}} {{{ .GoType }}} `json:"{{{ toCamelCase .GoField }}}" structs:"{{{ toCamelCase .GoField }}}"` // {{{ .ColumnComment }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package {{{ .ModuleName }}}
|
||||
|
||||
import (
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type I{{{ title (toCamelCase .EntityName) }}}Service interface {
|
||||
List(page request.PageReq, listReq {{{ title (toCamelCase .EntityName) }}}ListReq) (res response.PageResp, e error)
|
||||
Detail(id int) (res {{{ title (toCamelCase .EntityName) }}}Resp, e error)
|
||||
Add(addReq {{{ title (toCamelCase .EntityName) }}}AddReq) (e error)
|
||||
Edit(editReq {{{ title (toCamelCase .EntityName) }}}EditReq) (e error)
|
||||
Del(id int) (e error)
|
||||
}
|
||||
|
||||
//New{{{ title (toCamelCase .EntityName) }}}Service 初始化
|
||||
func New{{{ title (toCamelCase .EntityName) }}}Service(db *gorm.DB) I{{{ title (toCamelCase .EntityName) }}}Service {
|
||||
return &{{{ toCamelCase .EntityName }}}Service{db: db}
|
||||
}
|
||||
|
||||
//{{{ toCamelCase .EntityName }}}Service {{{ .FunctionName }}}服务实现类
|
||||
type {{{ toCamelCase .EntityName }}}Service struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
//List {{{ .FunctionName }}}列表
|
||||
func (Service {{{ toCamelCase .EntityName }}}Service) List(page request.PageReq, listReq {{{ title (toCamelCase .EntityName) }}}ListReq) (res response.PageResp, e error) {
|
||||
// 分页信息
|
||||
limit := page.PageSize
|
||||
offset := page.PageSize * (page.PageNo - 1)
|
||||
// 查询
|
||||
dbModel := Service.db.Model(&model.{{{ title (toCamelCase .EntityName) }}}{})
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsQuery }}}
|
||||
{{{- $queryOpr := index $.ModelOprMap .QueryType }}}
|
||||
{{{- if and (eq .GoType "string") (eq $queryOpr "like") }}}
|
||||
if listReq.{{{ title (toCamelCase .ColumnName) }}} != "" {
|
||||
dbModel = dbModel.Where("{{{ .ColumnName }}} like ?", "%"+listReq.{{{ title (toCamelCase .ColumnName) }}}+"%")
|
||||
}
|
||||
{{{- else }}}
|
||||
if listReq.{{{ title (toCamelCase .ColumnName) }}} {{{ if eq .GoType "string" }}}!= ""{{{ else }}}> 0{{{ end }}} {
|
||||
dbModel = dbModel.Where("{{{ .ColumnName }}} = ?", listReq.{{{ title (toCamelCase .ColumnName) }}})
|
||||
}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- if contains .AllFields "is_delete" }}}
|
||||
dbModel = dbModel.Where("is_delete = ?", 0)
|
||||
{{{- end }}}
|
||||
// 总数
|
||||
var count int64
|
||||
err := dbModel.Count(&count).Error
|
||||
if e = response.CheckErr(err, "List Count err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 数据
|
||||
var objs []model.{{{ title (toCamelCase .EntityName) }}}
|
||||
err = dbModel.Limit(limit).Offset(offset).Order("id desc").Find(&objs).Error
|
||||
if e = response.CheckErr(err, "List Find err"); e != nil {
|
||||
return
|
||||
}
|
||||
resps := []{{{ title (toCamelCase .EntityName) }}}Resp{}
|
||||
response.Copy(&resps, objs)
|
||||
return response.PageResp{
|
||||
PageNo: page.PageNo,
|
||||
PageSize: page.PageSize,
|
||||
Count: count,
|
||||
Lists: resps,
|
||||
}, nil
|
||||
}
|
||||
|
||||
//Detail {{{ .FunctionName }}}详情
|
||||
func (Service {{{ toCamelCase .EntityName }}}Service) Detail(id int) (res {{{ title (toCamelCase .EntityName) }}}Resp, e error) {
|
||||
var obj model.{{{ title (toCamelCase .EntityName) }}}
|
||||
err := Service.db.Where("{{{ $.PrimaryKey }}} = ?{{{ if contains .AllFields "is_delete" }}} AND is_delete = ?{{{ end }}}", id{{{ if contains .AllFields "is_delete" }}}, 0{{{ end }}}).Limit(1).First(&obj).Error
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Detail First err"); e != nil {
|
||||
return
|
||||
}
|
||||
response.Copy(&res, obj)
|
||||
{{{- range .Columns }}}
|
||||
{{{- if and .IsEdit (contains (slice "image" "avatar" "logo" "img") .GoField) }}}
|
||||
res.Avatar = util.UrlUtil.ToAbsoluteUrl(res.Avatar)
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
return
|
||||
}
|
||||
|
||||
//Add {{{ .FunctionName }}}新增
|
||||
func (Service {{{ toCamelCase .EntityName }}}Service) Add(addReq {{{ title (toCamelCase .EntityName) }}}AddReq) (e error) {
|
||||
var obj model.{{{ title (toCamelCase .EntityName) }}}
|
||||
response.Copy(&obj, addReq)
|
||||
err := Service.db.Create(&obj).Error
|
||||
e = response.CheckErr(err, "Add Create err")
|
||||
return
|
||||
}
|
||||
|
||||
//Edit {{{ .FunctionName }}}编辑
|
||||
func (Service {{{ toCamelCase .EntityName }}}Service) Edit(editReq {{{ title (toCamelCase .EntityName) }}}EditReq) (e error) {
|
||||
var obj model.{{{ title (toCamelCase .EntityName) }}}
|
||||
err := Service.db.Where("{{{ $.PrimaryKey }}} = ?{{{ if contains .AllFields "is_delete" }}} AND is_delete = ?{{{ end }}}", editReq.Id{{{ if contains .AllFields "is_delete" }}}, 0{{{ end }}}).Limit(1).First(&obj).Error
|
||||
// 校验
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Edit First err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 更新
|
||||
response.Copy(&obj, editReq)
|
||||
err = Service.db.Model(&obj).Updates(obj).Error
|
||||
e = response.CheckErr(err, "Edit Updates err")
|
||||
return
|
||||
}
|
||||
|
||||
//Del {{{ .FunctionName }}}删除
|
||||
func (Service {{{ toCamelCase .EntityName }}}Service) Del(id int) (e error) {
|
||||
var obj model.{{{ title (toCamelCase .EntityName) }}}
|
||||
err := Service.db.Where("{{{ $.PrimaryKey }}} = ?{{{ if contains .AllFields "is_delete" }}} AND is_delete = ?{{{ end }}}", id{{{ if contains .AllFields "is_delete" }}}, 0{{{ end }}}).Limit(1).First(&obj).Error
|
||||
// 校验
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Del First err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 删除
|
||||
{{{- if contains .AllFields "is_delete" }}}
|
||||
obj.IsDelete = 1
|
||||
err = Service.db.Save(&obj).Error
|
||||
e = response.CheckErr(err, "Del Save err")
|
||||
{{{- else }}}
|
||||
err = Service.db.Delete(&obj).Error
|
||||
e = response.CheckErr(err, "Del Delete err")
|
||||
{{{- end }}}
|
||||
return
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// {{{.FunctionName}}}列表
|
||||
export function {{{.ModuleName}}}_lists(params?: Record<string, any>) {
|
||||
return request.get({ url: '/{{{.ModuleName}}}/list', params })
|
||||
}
|
||||
|
||||
// {{{.FunctionName}}}详情
|
||||
export function {{{.ModuleName}}}_detail(params: Record<string, any>) {
|
||||
return request.get({ url: '/{{{.ModuleName}}}/detail', params })
|
||||
}
|
||||
|
||||
// {{{.FunctionName}}}新增
|
||||
export function {{{.ModuleName}}}_add(params: Record<string, any>) {
|
||||
return request.post({ url: '/{{{.ModuleName}}}/add', params })
|
||||
}
|
||||
|
||||
// {{{.FunctionName}}}编辑
|
||||
export function {{{.ModuleName}}}_edit(params: Record<string, any>) {
|
||||
return request.post({ url: '/{{{.ModuleName}}}/edit', params })
|
||||
}
|
||||
|
||||
// {{{.FunctionName}}}删除
|
||||
export function {{{.ModuleName}}}_delete(params: Record<string, any>) {
|
||||
return request.post({ url: '/{{{.ModuleName}}}/del', params })
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
<template>
|
||||
<div class="edit-popup">
|
||||
<popup
|
||||
ref="popupRef"
|
||||
:title="popupTitle"
|
||||
:async="true"
|
||||
width="550px"
|
||||
:clickModalClose="true"
|
||||
@confirm="handleSubmit"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" label-width="84px" :rules="formRules">
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsEdit }}}
|
||||
{{{- if ne (toCamelCase .GoField) "id" }}}
|
||||
{{{- if and (ne $.Table.TreeParent "") (eq (toCamelCase .GoField) $.Table.TreeParent) }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-tree-select
|
||||
class="flex-1"
|
||||
v-model="formData.{{{ (toCamelCase .GoField) }}}"
|
||||
:data="treeList"
|
||||
clearable
|
||||
node-key="{{{ .Table.TreePrimary }}}"
|
||||
:props="{ label: '{{{ .Table.TreeName }}}', value: '{{{ .Table.TreePrimary }}}', children: 'children' }"
|
||||
:default-expand-all="true"
|
||||
placeholder="请选择{{{ .ColumnComment }}}"
|
||||
check-strictly
|
||||
/>
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "input" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-input v-model="formData.{{{ (toCamelCase .GoField) }}}" placeholder="请输入{{{ .ColumnComment }}}" />
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "number" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-input-number v-model="formData.{{{ (toCamelCase .GoField) }}}" :max="9999" />
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "textarea" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-input
|
||||
v-model="formData.{{{ (toCamelCase .GoField) }}}"
|
||||
placeholder="请输入{{{ .ColumnComment }}}"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 4, maxRows: 6 }"
|
||||
/>
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "checkbox" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-checkbox-group v-model="formData.{{{ (toCamelCase .GoField) }}}" placeholder="请选择{{{ .ColumnComment }}}">
|
||||
{{{- if ne .DictType "" }}}
|
||||
<el-checkbox
|
||||
v-for="(item, index) in dictData.{{{ .DictType }}}"
|
||||
:key="index"
|
||||
:label="item.value"
|
||||
:disabled="!item.status"
|
||||
>
|
||||
{{ item.name }}
|
||||
</el-checkbox>
|
||||
{{{- else }}}
|
||||
<el-checkbox>请选择字典生成</el-checkbox>
|
||||
{{{- end }}}
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "select" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-select class="flex-1" v-model="formData.{{{ (toCamelCase .GoField) }}}" placeholder="请选择{{{ .ColumnComment }}}">
|
||||
{{{- if ne .DictType "" }}}
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.{{{ .DictType }}}"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
{{{- if eq .GoType "Integer" }}}
|
||||
:value="parseInt(item.value)"
|
||||
{{{- else }}}
|
||||
:value="item.value"
|
||||
{{{- end }}}
|
||||
clearable
|
||||
:disabled="!item.status"
|
||||
/>
|
||||
{{{- else }}}
|
||||
<el-option label="请选择字典生成" value="" />
|
||||
{{{- end }}}
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "radio" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-radio-group v-model="formData.{{{ (toCamelCase .GoField) }}}" placeholder="请选择{{{ .ColumnComment }}}">
|
||||
{{{- if ne .DictType "" }}}
|
||||
<el-radio
|
||||
v-for="(item, index) in dictData.{{{ .DictType }}}"
|
||||
:key="index"
|
||||
{{{- if eq .GoType "Integer" }}}
|
||||
:label="parseInt(item.value)"
|
||||
{{{- else }}}
|
||||
:label="item.value"
|
||||
{{{- end }}}
|
||||
:disabled="!item.status"
|
||||
>
|
||||
{{ item.name }}
|
||||
</el-radio>
|
||||
{{{- else }}}
|
||||
<el-radio label="0">请选择字典生成</el-radio>
|
||||
{{{- end }}}
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "datetime" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-date-picker
|
||||
class="flex-1 !flex"
|
||||
v-model="formData.{{{ (toCamelCase .GoField) }}}"
|
||||
type="datetime"
|
||||
clearable
|
||||
value-format="YYYY-MM-DD hh:mm:ss"
|
||||
placeholder="请选择{{{ .ColumnComment }}}"
|
||||
/>
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "editor" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<editor v-model="formData.{{{ (toCamelCase .GoField) }}}" :height="500" />
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "imageUpload" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<material-picker v-model="formData.{{{ (toCamelCase .GoField) }}}" />
|
||||
</el-form-item>
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
|
||||
</el-form>
|
||||
</popup>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import { {{{ if and .Table.TreePrimary .Table.TreeParent }}}{{{ .ModuleName }}}_lists,{{{ end }}} {{{ .ModuleName }}}_edit, {{{ .ModuleName }}}_add, {{{ .ModuleName }}}_detail } from '@/api/{{{ .ModuleName }}}'
|
||||
import Popup from '@/components/popup/index.vue'
|
||||
import feedback from '@/utils/feedback'
|
||||
import type { PropType } from 'vue'
|
||||
defineProps({
|
||||
dictData: {
|
||||
type: Object as PropType<Record<string, any[]>>,
|
||||
default: () => ({})
|
||||
}
|
||||
})
|
||||
const emit = defineEmits(['success', 'close'])
|
||||
const formRef = shallowRef<FormInstance>()
|
||||
const popupRef = shallowRef<InstanceType<typeof Popup>>()
|
||||
{{{- if and .Table.TreePrimary .Table.TreeParent }}}
|
||||
const treeList = ref<any[]>([])
|
||||
{{{- end }}}
|
||||
const mode = ref('add')
|
||||
const popupTitle = computed(() => {
|
||||
return mode.value == 'edit' ? '编辑{{{ .FunctionName }}}' : '新增{{{ .FunctionName }}}'
|
||||
})
|
||||
|
||||
const formData = reactive({
|
||||
{{{- range .Columns }}}
|
||||
{{{- if eq (toCamelCase .GoField) $.PrimaryKey }}}
|
||||
{{{ $.PrimaryKey }}}: '',
|
||||
{{{- else if .IsEdit }}}
|
||||
{{{- if eq .HtmlType "checkbox" }}}
|
||||
{{{ (toCamelCase .GoField) }}}: [],
|
||||
{{{- else if eq .HtmlType "number" }}}
|
||||
{{{ (toCamelCase .GoField) }}}: 0,
|
||||
{{{- else }}}
|
||||
{{{ (toCamelCase .GoField) }}}: '',
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
{{{- range .Columns }}}
|
||||
{{{- if and .IsEdit .IsRequired }}}
|
||||
{{{ (toCamelCase .GoField) }}}: [
|
||||
{
|
||||
required: true,
|
||||
{{{- if or (eq .HtmlType "checkbox") (eq .HtmlType "datetime") (eq .HtmlType "radio") (eq .HtmlType "select") (eq .HtmlType "imageUpload") }}}
|
||||
message: '请选择{{{ .ColumnComment }}}',
|
||||
{{{- else }}}
|
||||
message: '请输入{{{ .ColumnComment }}}',
|
||||
{{{- end }}}
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
await formRef.value?.validate()
|
||||
const data: any = { ...formData }
|
||||
{{{- range .Columns }}}
|
||||
{{{- if eq .HtmlType "checkbox" }}}
|
||||
data.{{{ (toCamelCase .GoField) }}} = data.{{{ (toCamelCase .GoField) }}}.join(',')
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
mode.value == 'edit' ? await {{{ .ModuleName }}}_edit(data) : await {{{ .ModuleName }}}_add(data)
|
||||
popupRef.value?.close()
|
||||
feedback.msgSuccess('操作成功')
|
||||
emit('success')
|
||||
}
|
||||
|
||||
const open = (type = 'add') => {
|
||||
mode.value = type
|
||||
popupRef.value?.open()
|
||||
}
|
||||
|
||||
const setFormData = async (data: Record<string, any>) => {
|
||||
for (const key in formData) {
|
||||
if (data[key] != null && data[key] != undefined) {
|
||||
//@ts-ignore
|
||||
formData[key] = data[key]
|
||||
{{{- range .Columns }}}
|
||||
{{{- if eq .HtmlType "checkbox" }}}
|
||||
//@ts-ignore
|
||||
formData.{{{ (toCamelCase .GoField) }}} = String(data.{{{ (toCamelCase .GoField) }}}).split(',')
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getDetail = async (row: Record<string, any>) => {
|
||||
const data = await {{{ .ModuleName }}}_detail({
|
||||
{{{ .PrimaryKey }}}: row.{{{ .PrimaryKey }}}
|
||||
})
|
||||
setFormData(data)
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
emit('close')
|
||||
}
|
||||
{{{- if and .Table.TreePrimary .Table.TreeParent }}}
|
||||
|
||||
const getLists = async () => {
|
||||
const data: any = await {{{ .ModuleName }}}_lists()
|
||||
const item = { {{{ .Table.TreePrimary }}}: 0, {{{ .Table.TreeName }}}: '顶级', children: [] }
|
||||
item.children = data
|
||||
treeList.value.push(item)
|
||||
}
|
||||
|
||||
getLists()
|
||||
{{{- end }}}
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
setFormData,
|
||||
getDetail
|
||||
})
|
||||
</script>
|
||||
@@ -1,222 +0,0 @@
|
||||
<template>
|
||||
<div class="index-tree">
|
||||
<el-card class="!border-none mb-4" shadow="never">
|
||||
<el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
|
||||
{{{- range .Columns }}}
|
||||
{{{- if eq .IsQuery 1 }}}
|
||||
{{{- if eq .HtmlType "datetime" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<daterange-picker
|
||||
v-model:startTime="queryParams.createTimeStart"
|
||||
v-model:endTime="queryParams.createTimeEnd"
|
||||
/>
|
||||
</el-form-item>
|
||||
{{{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-select
|
||||
v-model="queryParams.{{{ (toCamelCase .GoField) }}}"
|
||||
class="w-[280px]"
|
||||
clearable
|
||||
>
|
||||
{{{- if eq .DictType "" }}}
|
||||
<el-option label="请选择字典生成" value="" />
|
||||
{{{- else }}}
|
||||
<el-option label="全部" value="" />
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.{{{ .DictType }}}"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
{{{- end }}}
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "input" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-input class="w-[280px]" v-model="queryParams.{{{ (toCamelCase .GoField) }}}" />
|
||||
</el-form-item>
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="getLists">查询</el-button>
|
||||
<el-button @click="getLists">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
<el-card class="!border-none" shadow="never">
|
||||
<div>
|
||||
<el-button v-perms="['{{{ .ModuleName }}}:add']" type="primary" @click="handleAdd()">
|
||||
<template #icon>
|
||||
<icon name="el-icon-Plus" />
|
||||
</template>
|
||||
新增
|
||||
</el-button>
|
||||
<el-button @click="handleExpand"> 展开/折叠 </el-button>
|
||||
</div>
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
ref="tableRef"
|
||||
class="mt-4"
|
||||
size="large"
|
||||
:data="lists"
|
||||
row-key="{{{ .Table.TreePrimary }}}"
|
||||
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
|
||||
>
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsList }}}
|
||||
{{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
|
||||
<el-table-column label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}" min-width="100">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictData.{{{ .DictType }}}" :value="row.{{{ (toCamelCase .GoField) }}}" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
{{{- else if eq .HtmlType "imageUpload" }}}
|
||||
<el-table-column label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}" min-width="100">
|
||||
<template #default="{ row }">
|
||||
<image-contain
|
||||
:width="40"
|
||||
:height="40"
|
||||
:src="row.{{{ (toCamelCase .GoField) }}}"
|
||||
:preview-src-list="[row.{{{ (toCamelCase .GoField) }}}]"
|
||||
preview-teleported
|
||||
hide-on-click-modal
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
{{{- else }}}
|
||||
<el-table-column label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}" min-width="100" />
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
<el-table-column label="操作" width="160" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-perms="['{{{ .ModuleName }}}:add']"
|
||||
type="primary"
|
||||
link
|
||||
@click="handleAdd(row.{{{ .Table.TreePrimary }}})"
|
||||
>
|
||||
新增
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['{{{ .ModuleName }}}:edit']"
|
||||
type="primary"
|
||||
link
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['{{{ .ModuleName }}}:del']"
|
||||
type="danger"
|
||||
link
|
||||
@click="handleDelete(row.{{{ .PrimaryKey }}})"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
<edit-popup
|
||||
v-if="showEdit"
|
||||
ref="editRef"
|
||||
{{{- if ge (len .DictFields) 1 }}}
|
||||
:dict-data="dictData"
|
||||
{{{- end }}}
|
||||
@success="getLists"
|
||||
@close="showEdit = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="{{{ .ModuleName }}}">
|
||||
import { {{{ .ModuleName }}}_delete, {{{ .ModuleName }}}_lists } from '@/api/{{{ .ModuleName }}}'
|
||||
import EditPopup from './edit.vue'
|
||||
import feedback from '@/utils/feedback'
|
||||
{{{- if ge (len .DictFields) 1 }}}
|
||||
import { useDictData } from '@/hooks/useDictOptions'
|
||||
{{{- end }}}
|
||||
import type { ElTable } from 'element-plus'
|
||||
|
||||
const tableRef = shallowRef<InstanceType<typeof ElTable>>()
|
||||
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
||||
let isExpand = false
|
||||
const showEdit = ref(false)
|
||||
const loading = ref(false)
|
||||
const lists = ref<any[]>([])
|
||||
|
||||
const queryParams = reactive({
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsQuery }}}
|
||||
{{{- if eq .HtmlType "datetime" }}}
|
||||
{{{ (toCamelCase .GoField) }}}Start: '',
|
||||
{{{ (toCamelCase .GoField) }}}End: '',
|
||||
{{{- else }}}
|
||||
{{{ (toCamelCase .GoField) }}}: '',
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
})
|
||||
|
||||
const getLists = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await {{{ .ModuleName }}}_lists(queryParams)
|
||||
lists.value = data
|
||||
loading.value = false
|
||||
} catch (error) {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
{{{- if ge (len .DictFields) 1 }}}
|
||||
{{{- $dictSize := sub (len .DictFields) 1 }}}
|
||||
const { dictData } = useDictData<{
|
||||
{{{- range .DictFields }}}
|
||||
{{{ . }}}: any[]
|
||||
{{{- end }}}
|
||||
}>([{{{- range .DictFields }}}'{{{ . }}}'{{{- if ne (index $.DictFields $dictSize) . }}},{{{- end }}}{{{- end }}}])
|
||||
{{{- end }}}
|
||||
|
||||
const handleAdd = async ({{{ .Table.TreePrimary }}}?: number) => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
if ({{{ .Table.TreePrimary }}}) {
|
||||
editRef.value?.setFormData({
|
||||
{{{ .Table.TreeParent }}}: {{{ .Table.TreePrimary }}}
|
||||
})
|
||||
}
|
||||
editRef.value?.open('add')
|
||||
}
|
||||
|
||||
const handleEdit = async (data: any) => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
editRef.value?.open('edit')
|
||||
editRef.value?.getDetail(data)
|
||||
}
|
||||
|
||||
const handleDelete = async ({{{ .PrimaryKey }}}: number) => {
|
||||
await feedback.confirm('确定要删除?')
|
||||
await {{{ .ModuleName }}}_delete({ {{{ .PrimaryKey }}} })
|
||||
feedback.msgSuccess('删除成功')
|
||||
getLists()
|
||||
}
|
||||
|
||||
const handleExpand = () => {
|
||||
isExpand = !isExpand
|
||||
toggleExpand(lists.value, isExpand)
|
||||
}
|
||||
|
||||
const toggleExpand = (children: any[], unfold = true) => {
|
||||
for (const key in children) {
|
||||
tableRef.value?.toggleRowExpansion(children[key], unfold)
|
||||
if (children[key].children) {
|
||||
toggleExpand(children[key].children!, unfold)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getLists()
|
||||
</script>
|
||||
@@ -1,183 +0,0 @@
|
||||
<template>
|
||||
<div class="index-lists">
|
||||
<el-card class="!border-none" shadow="never">
|
||||
<el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
|
||||
{{{- range .Columns }}}
|
||||
{{{- if eq .IsQuery 1 }}}
|
||||
{{{- if eq .HtmlType "datetime" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<daterange-picker
|
||||
v-model:startTime="queryParams.createTimeStart"
|
||||
v-model:endTime="queryParams.createTimeEnd"
|
||||
/>
|
||||
</el-form-item>
|
||||
{{{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-select
|
||||
v-model="queryParams.{{{ (toCamelCase .GoField) }}}"
|
||||
class="w-[280px]"
|
||||
clearable
|
||||
>
|
||||
{{{- if eq .DictType "" }}}
|
||||
<el-option label="请选择字典生成" value="" />
|
||||
{{{- else }}}
|
||||
<el-option label="全部" value="" />
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.{{{ .DictType }}}"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
{{{- end }}}
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
{{{- else if eq .HtmlType "input" }}}
|
||||
<el-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}">
|
||||
<el-input class="w-[280px]" v-model="queryParams.{{{ (toCamelCase .GoField) }}}" />
|
||||
</el-form-item>
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="resetPage">查询</el-button>
|
||||
<el-button @click="resetParams">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
<el-card class="!border-none mt-4" shadow="never">
|
||||
<div>
|
||||
<el-button v-perms="['{{{ .ModuleName }}}:add']" type="primary" @click="handleAdd()">
|
||||
<template #icon>
|
||||
<icon name="el-icon-Plus" />
|
||||
</template>
|
||||
新增
|
||||
</el-button>
|
||||
</div>
|
||||
<el-table
|
||||
class="mt-4"
|
||||
size="large"
|
||||
v-loading="pager.loading"
|
||||
:data="pager.lists"
|
||||
>
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsList }}}
|
||||
{{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
|
||||
<el-table-column label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}" min-width="100">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictData.{{{ .DictType }}}" :value="row.{{{ (toCamelCase .GoField) }}}" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
{{{- else if eq .HtmlType "imageUpload" }}}
|
||||
<el-table-column label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}" min-width="100">
|
||||
<template #default="{ row }">
|
||||
<image-contain
|
||||
:width="40"
|
||||
:height="40"
|
||||
:src="row.{{{ (toCamelCase .GoField) }}}"
|
||||
:preview-src-list="[row.{{{ (toCamelCase .GoField) }}}]"
|
||||
preview-teleported
|
||||
hide-on-click-modal
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
{{{- else }}}
|
||||
<el-table-column label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}" min-width="100" />
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-perms="['{{{ .ModuleName }}}:edit']"
|
||||
type="primary"
|
||||
link
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['{{{ .ModuleName }}}:del']"
|
||||
type="danger"
|
||||
link
|
||||
@click="handleDelete(row.{{{ .PrimaryKey }}})"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<pagination v-model="pager" @change="getLists" />
|
||||
</div>
|
||||
</el-card>
|
||||
<edit-popup
|
||||
v-if="showEdit"
|
||||
ref="editRef"
|
||||
{{{- if ge (len .DictFields) 1 }}}
|
||||
:dict-data="dictData"
|
||||
{{{- end }}}
|
||||
@success="getLists"
|
||||
@close="showEdit = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="{{{ .ModuleName }}}">
|
||||
import { {{{ .ModuleName }}}_delete, {{{ .ModuleName }}}_lists } from '@/api/{{{ .ModuleName }}}'
|
||||
{{{- if ge (len .DictFields) 1 }}}
|
||||
import { useDictData } from '@/hooks/useDictOptions'
|
||||
{{{- end }}}
|
||||
import { usePaging } from '@/hooks/usePaging'
|
||||
import feedback from '@/utils/feedback'
|
||||
import EditPopup from './edit.vue'
|
||||
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
||||
const showEdit = ref(false)
|
||||
const queryParams = reactive({
|
||||
{{{- range .Columns }}}
|
||||
{{{- if .IsQuery }}}
|
||||
{{{- if eq .HtmlType "datetime" }}}
|
||||
{{{ (toCamelCase .GoField) }}}Start: '',
|
||||
{{{ (toCamelCase .GoField) }}}End: '',
|
||||
{{{- else }}}
|
||||
{{{ (toCamelCase .GoField) }}}: '',
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
{{{- end }}}
|
||||
})
|
||||
|
||||
const { pager, getLists, resetPage, resetParams } = usePaging({
|
||||
fetchFun: {{{ .ModuleName }}}_lists,
|
||||
params: queryParams
|
||||
})
|
||||
|
||||
{{{- if ge (len .DictFields) 1 }}}
|
||||
{{{- $dictSize := sub (len .DictFields) 1 }}}
|
||||
const { dictData } = useDictData<{
|
||||
{{{- range .DictFields }}}
|
||||
{{{ . }}}: any[]
|
||||
{{{- end }}}
|
||||
}>([{{{- range .DictFields }}}'{{{ . }}}'{{{- if ne (index $.DictFields $dictSize) . }}},{{{- end }}}{{{- end }}}])
|
||||
{{{- end }}}
|
||||
|
||||
|
||||
const handleAdd = async () => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
editRef.value?.open('add')
|
||||
}
|
||||
|
||||
const handleEdit = async (data: any) => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
editRef.value?.open('edit')
|
||||
editRef.value?.getDetail(data)
|
||||
}
|
||||
|
||||
const handleDelete = async ({{{ .PrimaryKey }}}: number) => {
|
||||
await feedback.confirm('确定要删除?')
|
||||
await {{{ .ModuleName }}}_delete({ {{{ .PrimaryKey }}} })
|
||||
feedback.msgSuccess('删除成功')
|
||||
getLists()
|
||||
}
|
||||
|
||||
getLists()
|
||||
</script>
|
||||
@@ -5,11 +5,9 @@ import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"text/template"
|
||||
"x_admin/config"
|
||||
"x_admin/core/response"
|
||||
"x_admin/model/gen_model"
|
||||
"x_admin/util"
|
||||
@@ -194,23 +192,14 @@ func (tu templateUtil) Render(tplPath string, tplVars TplVars) (res string, e er
|
||||
return "", e
|
||||
}
|
||||
buf := &bytes.Buffer{}
|
||||
basePath := path.Base(tplPath)
|
||||
err = tpl.ExecuteTemplate(buf, basePath, tplVars)
|
||||
fileName := path.Base(tplPath)
|
||||
err = tpl.ExecuteTemplate(buf, fileName, tplVars)
|
||||
if e = response.CheckErr(err, "TemplateUtil.Render Execute err"); e != nil {
|
||||
return "", e
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
// GetGenPath 获取生成路径
|
||||
func (tu templateUtil) GetGenPath(table gen_model.GenTable) string {
|
||||
if table.GenPath == "/" {
|
||||
//return path.Join(config.Config.RootPath, config.GenConfig.GenRootPath)
|
||||
return config.GenConfig.GenRootPath
|
||||
}
|
||||
return table.GenPath
|
||||
}
|
||||
|
||||
// GetFilePaths 获取生成文件相对路径
|
||||
func (tu templateUtil) GetFilePaths(tplCodeMap map[string]string, TableName string) map[string]string {
|
||||
//模板文件对应的输出文件
|
||||
@@ -235,26 +224,6 @@ func (tu templateUtil) GetFilePaths(tplCodeMap map[string]string, TableName stri
|
||||
return filePath
|
||||
}
|
||||
|
||||
// GenCodeFiles 生成代码文件
|
||||
func (tu templateUtil) GenCodeFiles(tplCodeMap map[string]string, TableName string, basePath string) error {
|
||||
filePaths := tu.GetFilePaths(tplCodeMap, TableName)
|
||||
for file, tplCode := range filePaths {
|
||||
filePath := path.Join(basePath, file)
|
||||
dir := path.Dir(filePath)
|
||||
if !util.ToolsUtil.IsFileExist(dir) {
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
return response.CheckErr(err, "TemplateUtil.GenCodeFiles MkdirAll err")
|
||||
}
|
||||
}
|
||||
err := os.WriteFile(filePath, []byte(tplCode), 0644)
|
||||
if err != nil {
|
||||
return response.CheckErr(err, "TemplateUtil.GenCodeFiles WriteFile err")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addFileToZip(zipWriter *zip.Writer, file zFile) error {
|
||||
header := &zip.FileHeader{
|
||||
Name: file.Name,
|
||||
|
||||
@@ -15,8 +15,7 @@ type GenTable struct {
|
||||
TreeParent string `gorm:"not null;default:'';comment:'树父级字段'"`
|
||||
TreeName string `gorm:"not null;default:'';comment:'树显示字段'"`
|
||||
GenTpl string `gorm:"not null;default:'crud';comment:'生成模板方式: [crud=单表, tree=树表]'"`
|
||||
GenType int `gorm:"not null;default:0;comment:'生成代码方式: [0=zip压缩包, 1=自定义路径]'"`
|
||||
GenPath string `gorm:"not null;default:'/';comment:'生成代码路径: [不填默认项目路径]'"`
|
||||
|
||||
Remarks string `gorm:"not null;default:'';comment:'备注信息'"`
|
||||
CreateTime int64 `gorm:"autoCreateTime;not null;comment:'创建时间'"`
|
||||
UpdateTime int64 `gorm:"autoUpdateTime;not null;comment:'更新时间'"`
|
||||
|
||||
Reference in New Issue
Block a user