优化功能,通知功能,任务功能

This commit is contained in:
PandaGoAdmin
2021-12-31 17:35:43 +08:00
parent ddc9d8b108
commit 1a1f137725
23 changed files with 2212 additions and 6 deletions

View File

@@ -0,0 +1,188 @@
// ==========================================================================
// GFast自动生成控制器相关代码只生成一次按需修改,再次生成不会覆盖.
// 生成日期:{{.table.CreateTime}}
// 生成路径: {{.table.PackageName}}/api/{{.table.BusinessName}}.go
// 生成人:{{.table.FunctionAuthor}}
// ==========================================================================
////
{{$structName := .table.BusinessName | CaseCamelLower}}
package api
{{$hasGStr:=false}}
{{$gjsonTag:=false}}
{{$libTag:=false}}
{{range $index,$column:=.table.Columns}}
{{if eq $column.HtmlType "checkbox"}}
{{$hasGStr = true}}
{{else if eq $column.HtmlType "images" "file" "files"}}
{{$gjsonTag = true}}
{{$libTag = true}}
{{end}}
{{end}}
import (
{{if ne $.table.ModuleName "system"}}
sysApi "gfast/app/system/api"
{{end}}
{{if $libTag}}
"gfast/library"
{{end}}
"{{.table.PackageName}}/dao"
"{{.table.PackageName}}/service"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/util/gvalid"
{{if $hasGStr}}
"github.com/gogf/gf/text/gstr"
{{end}}
{{if $gjsonTag}}
"github.com/gogf/gf/encoding/gjson"
{{end}}
)
type {{$structName}} struct {
{{if ne $.table.ModuleName "system"}}
sysApi.SystemBase
{{else}}
SystemBase
{{end}}
}
var {{.table.ClassName}} = new({{$structName}})
// List 列表
func (c *{{$structName}}) List(r *ghttp.Request) {
var req *dao.{{.table.ClassName}}SearchReq
//获取参数
if err := r.Parse(&req); err != nil {
c.FailJsonExit(r, err.(gvalid.Error).FirstString())
}
req.Ctx = r.GetCtx()
total, page, list, err := service.{{.table.ClassName}}.GetList(req)
if err != nil {
c.FailJsonExit(r, err.Error())
}
result := g.Map{
"currentPage": page,
"total": total,
"list": list,
}
c.SusJsonExit(r, result)
}
// Add 添加
func (c *{{$structName}}) Add(r *ghttp.Request) {
var req *dao.{{.table.ClassName}}AddReq
//获取参数
if err := r.Parse(&req); err != nil {
c.FailJsonExit(r, err.(gvalid.Error).FirstString())
}
{{range $index,$column:= .table.Columns}}
{{if eq $column.ColumnName "created_by"}}
req.CreatedBy = c.GetCurrentUser(r.GetCtx()).GetUserId()
{{end}}
{{if eq $column.HtmlType "checkbox"}}
{{$column.HtmlField}} := r.GetStrings("{{$column.HtmlField}}")
if len({{$column.HtmlField}})>0{
req.{{$column.GoField}} = gstr.Join({{$column.HtmlField}},",")
}else{
req.{{$column.GoField}} = ""
}
{{else if eq $column.HtmlType "images" "file" "files"}}
up{{$column.GoField}}:=gjson.New(req.{{$column.GoField}})
for _,obj:=range up{{$column.GoField}}.Array(){
mp := obj.(g.MapStrAny)
var err error
mp["url"],err = library.GetFilesPath(mp["url"].(string))
if err!=nil{
c.FailJsonExit(r, err.Error())
}
}
req.{{$column.GoField}} = up{{$column.GoField}}.MustToJsonString()
{{end}}
{{end}}
err := service.{{.table.ClassName}}.Add(r.GetCtx(),req)
if err != nil {
c.FailJsonExit(r, err.Error())
}
c.SusJsonExit(r, "添加成功")
}
// Get 获取
func (c *{{$structName}}) Get(r *ghttp.Request) {
id := r.Get{{$.table.PkColumn.GoType | CaseCamel}}("id")
info, err := service.{{.table.ClassName}}.GetInfoById(r.GetCtx(),id)
if err != nil {
c.FailJsonExit(r, err.Error())
}
c.SusJsonExit(r, info)
}
// Edit 修改
func (c *{{$structName}}) Edit(r *ghttp.Request) {
var req *dao.{{.table.ClassName}}EditReq
//获取参数
if err := r.Parse(&req); err != nil {
c.FailJsonExit(r, err.(gvalid.Error).FirstString())
}
{{range $index,$column:= .table.Columns}}
{{if eq $column.ColumnName "updated_by"}}
req.UpdatedBy = c.GetCurrentUser(r.GetCtx()).GetUserId() //获取登陆用户id
{{end}}
{{if eq $column.HtmlType "checkbox"}}
{{$column.HtmlField}} := r.GetStrings("{{$column.HtmlField}}")
if len({{$column.HtmlField}})>0{
req.{{$column.GoField}} = gstr.Join({{$column.HtmlField}},",")
}else{
req.{{$column.GoField}} = ""
}
{{else if eq $column.HtmlType "images" "file" "files"}}
up{{$column.GoField}}:=gjson.New(req.{{$column.GoField}})
for _,obj:=range up{{$column.GoField}}.Array(){
mp := obj.(g.MapStrAny)
var err error
mp["url"],err = library.GetFilesPath(mp["url"].(string))
if err!=nil{
c.FailJsonExit(r, err.Error())
}
}
req.{{$column.GoField}} = up{{$column.GoField}}.MustToJsonString()
{{end}}
{{end}}
err := service.{{.table.ClassName}}.Edit(r.GetCtx(),req)
if err != nil {
c.FailJsonExit(r, err.Error())
}
c.SusJsonExit(r, "修改成功")
}
// Delete 删除
func (c *{{$structName}}) Delete(r *ghttp.Request) {
ids := r.GetInts("ids")
err := service.{{.table.ClassName}}.DeleteByIds(r.GetCtx(),ids)
if err != nil {
c.FailJsonExit(r, err.Error())
}
c.SusJsonExit(r, "删除成功")
}
{{range $index,$column:= .table.Columns}}
{{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
// Change{{$column.GoField}} 修改状态
func (c *{{$structName}}) Change{{$column.GoField}}(r *ghttp.Request){
var req *dao.{{$.table.ClassName}}{{$column.GoField}}Req
//获取参数
if err := r.Parse(&req); err != nil {
c.FailJsonExit(r, err.(gvalid.Error).FirstString())
}
if err := service.{{$.table.ClassName}}.Change{{$column.GoField}}(r.GetCtx(),req); err != nil {
c.FailJsonExit(r, err.Error())
} else {
c.SusJsonExit(r, "状态设置成功")
}
}
{{end}}
{{end}}

View File

@@ -0,0 +1,67 @@
// ==========================================================================
// GFast自动生成dao internal操作代码无需手动修改重新生成会自动覆盖.
// 生成日期:{{.table.CreateTime}}
// 生成路径: {{.table.PackageName}}/dao/internal/{{.table.TableName}}.go
// 生成人:{{.table.FunctionAuthor}}
// ==========================================================================
////
package internal
import (
"context"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
)
// {{.table.ClassName}}Dao is the manager for logic model data accessing and custom defined data operations functions management.
type {{.table.ClassName}}Dao struct {
Table string // Table is the underlying table name of the DAO.
Group string // Group is the database configuration group name of current DAO.
Columns {{.table.ClassName}}Columns // Columns is the short type for Columns, which contains all the column names of Table for convenient usage.
}
// {{.table.ClassName}}Columns defines and stores column names for table {{.table.TableName}}.
type {{.table.ClassName}}Columns struct {
{{range $index, $column := .table.Columns}}
{{$column.GoField}} string // {{$column.ColumnComment}}
{{end}}
}
var {{.table.BusinessName | CaseCamelLower}}Columns = {{.table.ClassName}}Columns{
{{range $index, $column := .table.Columns}}
{{$column.GoField}}: "{{$column.ColumnName}}",
{{end}}
}
// New{{.table.ClassName}}Dao creates and returns a new DAO object for table data access.
func New{{.table.ClassName}}Dao() *{{.table.ClassName}}Dao {
return &{{.table.ClassName}}Dao{
Group: "default",
Table: "{{.table.TableName}}",
Columns:{{.table.BusinessName | CaseCamelLower}}Columns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *{{.table.ClassName}}Dao) DB() gdb.DB {
return g.DB(dao.Group)
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *{{.table.ClassName}}Dao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.Table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *{{.table.ClassName}}Dao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,86 @@
// ==========================================================================
// GFast自动生成dao操作代码无需手动修改重新生成不会自动覆盖.
// 生成日期:{{.table.CreateTime}}
// 生成路径: {{.table.PackageName}}/dao/{{.table.TableName}}.go
// 生成人:{{.table.FunctionAuthor}}
// ==========================================================================
////
package dao
{{$hasGTime:=false}}
{{range $index, $column := .table.Columns}}
{{if eq $column.GoType "Time"}}
{{$hasGTime = true}}
{{end}}
{{end}}
import (
comModel "gfast/app/common/model"
"{{.table.PackageName}}/dao/internal"
{{if $hasGTime}}
"github.com/gogf/gf/os/gtime"
{{end}}
)
// {{.table.BusinessName | CaseCamelLower}}Dao is the manager for logic model data accessing and custom defined data operations functions management.
// You can define custom methods on it to extend its functionality as you wish.
type {{.table.BusinessName | CaseCamelLower}}Dao struct {
*internal.{{.table.BusinessName | CaseCamel}}Dao
}
var (
// {{.table.ClassName}} is globally public accessible object for table tools_gen_table operations.
{{.table.ClassName}} = {{.table.BusinessName | CaseCamelLower}}Dao{
internal.New{{.table.ClassName}}Dao(),
}
)
////
// Fill with you ideas below.
////
// {{.table.ClassName}}SearchReq 分页请求参数
type {{.table.ClassName}}SearchReq struct {
{{range $index, $column := .table.Columns}}
{{if eq $column.IsQuery "1"}}
{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if or (eq $column.GoType "int") (eq $column.GoType "int64") (eq $column.GoType "uint") (eq $column.GoType "uint64")}}string{{else}}{{$column.GoType}}{{end}} `p:"{{$column.HtmlField}}"` //{{$column.ColumnComment}}
{{end}}
{{end}}
comModel.PageReq
}
// {{.table.ClassName}}AddReq 添加操作请求参数
type {{.table.ClassName}}AddReq struct {
{{range $index, $column := .table.Columns}}
{{if and (eq $column.IsInsert "1") (ne $column.IsPk "1")}}
{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `p:"{{$column.HtmlField}}" {{if eq $column.IsRequired "1"}}v:"required#{{$column.ColumnComment}}不能为空"{{end}}`
{{end}}
{{if eq $column.ColumnName "created_by"}}CreatedBy uint64 {{end}}
{{end}}
}
// {{.table.ClassName}}EditReq 修改操作请求参数
type {{.table.ClassName}}EditReq struct {
{{.table.PkColumn.GoField}} {{.table.PkColumn.GoType}} `p:"{{.table.PkColumn.HtmlField}}" v:"required#主键ID不能为空"`
{{range $index, $column := .table.Columns}}
{{if eq $column.IsEdit "1"}}
{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `p:"{{$column.HtmlField}}" {{if eq $column.IsRequired "1"}}v:"required#{{$column.ColumnComment}}不能为空"{{end}}`{{end}}
{{if eq $column.ColumnName "updated_by"}}UpdatedBy uint64 {{end}}
{{end}}
}
{{range $index,$column:= .table.Columns}}
{{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
// {{$.table.ClassName}}{{$column.GoField}}Req 设置用户状态参数
type {{$.table.ClassName}}{{$column.GoField}}Req struct {
{{$.table.PkColumn.GoField}} {{$.table.PkColumn.GoType}} `p:"{{$.table.PkColumn.HtmlField}}" v:"required#主键ID不能为空"`
{{$column.GoField}} {{$column.GoType}} `p:"{{$column.HtmlField}}" v:"required#{{$column.ColumnComment}}不能为空"`
}
{{end}}
{{end}}

View File

@@ -0,0 +1,27 @@
// ==========================================================================
// GFast自动生成model代码无需手动修改重新生成会自动覆盖.
// 生成日期:{{.table.CreateTime}}
// 生成路径: {{.table.PackageName}}/model/{{.table.TableName}}.go
// 生成人:{{.table.FunctionAuthor}}
// ==========================================================================
////
package model
{{$hasGTime:=false}}
{{range $index, $column := .table.Columns}}
{{if eq $column.GoType "Time"}}
{{$hasGTime = true}}
{{end}}
{{end}}
{{if $hasGTime}}
import "github.com/gogf/gf/os/gtime"
{{end}}
// {{.table.ClassName}} is the golang structure for table {{.table.TableName}}.
type {{.table.ClassName}} struct {
{{range $index, $column := .table.Columns}}
{{if eq $column.IsPk "1"}} {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}},primary" json:"{{$column.HtmlField}}"` // {{$column.ColumnComment}} {{else}} {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}}" json:"{{$column.HtmlField}}"` // {{$column.ColumnComment}} {{end}}
{{end}}
}

View File

@@ -0,0 +1,57 @@
// ==========================================================================
// GFast自动生成路由代码只生成一次按需修改,再次生成不会覆盖.
// 生成日期:{{.table.CreateTime}}
// 生成路径: {{.table.PackageName}}/router/{{.table.BusinessName}}.go
// 生成人:{{.table.FunctionAuthor}}
// ==========================================================================
////
package router
import (
"{{.table.PackageName}}/api"
"gfast/middleware"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
{{if ne $.table.ModuleName "system"}}
sysApi "gfast/app/system/api"
{{end}}
)
{{$plugin:=""}}
{{if ContainsI $.table.PackageName "plugins"}}
{{$plugin = "plugins/"}}
{{end}}
//加载路由
func init() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Group("/{{$plugin}}{{.table.ModuleName}}", func(group *ghttp.RouterGroup) {
group.Group("/{{.table.BusinessName | CaseCamelLower}}", func(group *ghttp.RouterGroup) {
//gToken拦截器
{{if ne $.table.ModuleName "system"}}
sysApi.GfToken.AuthMiddleware(group)
{{else}}
api.GfToken.AuthMiddleware(group)
{{end}}
//context拦截器
group.Middleware(middleware.Ctx, middleware.Auth)
{{if ne $.table.ModuleName "system"}}
//后台操作日志记录
group.Hook("/*", ghttp.HookAfterOutput, sysApi.SysOperLog.OperationLog)
{{end}}
group.GET("list", api.{{.table.ClassName}}.List)
group.GET("get", api.{{.table.ClassName}}.Get)
group.POST("add", api.{{.table.ClassName}}.Add)
group.PUT("edit", api.{{.table.ClassName}}.Edit)
group.DELETE("delete", api.{{.table.ClassName}}.Delete)
{{range $index,$column:= .table.Columns}}
{{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
group.PUT("change{{$column.GoField}}",api.{{$.table.ClassName}}.Change{{$column.GoField}})
{{end}}
{{end}}
})
})
})
}

View File

@@ -0,0 +1,198 @@
// ==========================================================================
// Panda自动生成业务逻辑层相关代码只生成一次按需修改,再次生成不会覆盖.
// 生成日期:{{.table.CreateTime}}
// 生成路径: {{.table.PackageName}}/service/{{.table.BusinessName}}.go
// 生成人:{{.table.FunctionAuthor}}
// ==========================================================================
////
{{$structName := .table.BusinessName | CaseCamelLower}}
package service
import (
"context"
comModel "gfast/app/common/model"
"pandax/apps/{{.table.PackageName}}/entity"
"pandax/base/biz"
"pandax/base/global"
)
type {{$structName}} struct {
}
var {{.table.ClassName}} = new({{$structName}})
{{$pk:=""}}
{{$pkGoField:=""}}
{{$createdAt:=""}}
{{$createdAtGoField:=""}}
{{range $index, $column := .table.Columns}}
{{if eq $column.IsPk "1"}}
{{$pk = $column.ColumnName}}
{{$pkGoField = $column.GoField}}
{{end}}
{{if eq $column.ColumnName "created_at"}}
{{$createdAt = $column.ColumnName}}
{{$createdAtGoField = $column.GoField}}
{{end}}
{{end}}
// GetList 获取任务列表
func (s *{{$structName}}) GetList(req *dao.{{.table.ClassName}}SearchReq) (total, page int, list []*model.{{.table.ClassName}}, err error) {
m := dao.{{.table.ClassName}}.Ctx(req.Ctx)
{{range $index, $column := .table.Columns}} {{if eq $column.IsQuery "1"}}
{{if eq $column.QueryType "LIKE"}}
if req.{{$column.GoField}} != "" {
m = m.Where(dao.{{$.table.ClassName}}.Columns.{{$column.GoField}}+" like ?", "%"+req.{{$column.GoField}}+"%")
} {{end}}
{{if eq $column.QueryType "EQ"}} {{if eq $column.GoType "string"}}
if req.{{$column.GoField}} != "" {
m = m.Where(dao.{{$.table.ClassName}}.Columns.{{$column.GoField}}+" = ?", req.{{$column.GoField}})
}
{{else if and (eq $column.GoType "Time") (eq $column.ColumnName "created_at")}}
if req.BeginTime != "" {
m = m.Where(dao.{{$.table.ClassName}}.Columns.{{$column.GoField}}+" >=", req.BeginTime)
}
if req.EndTime != "" {
m = m.Where(dao.{{$.table.ClassName}}.Columns.{{$column.GoField}}+" <", req.EndTime)
}
{{else if or (eq $column.GoType "int") (eq $column.GoType "int64") (eq $column.GoType "uint") (eq $column.GoType "uint64") }}
if req.{{$column.GoField}} != "" {
m = m.Where(dao.{{$.table.ClassName}}.Columns.{{$column.GoField}}+" = ?", req.{{$column.GoField}})
}
{{end}} {{end}}
{{if and (eq $column.QueryType "BETWEEN") (eq $column.ColumnType "datetime") }}
if req.{{$column.GoField}} != nil {
m = m.Where(dao.{{$.table.ClassName}}.Columns.{{$column.GoField}}+" >= ? AND "+dao.{{$.table.ClassName}}.Columns.{{$column.GoField}}+" < ?", req.{{$column.GoField}}, req.{{$column.GoField}}.Add(gtime.D))
}
{{end}}
{{end}}
{{end}}
total, err = m.Count()
if err != nil {
g.Log().Error(err)
err = gerror.New("获取总行数失败")
return
}
{{if ne .table.TplCategory "tree"}}
if req.PageNum == 0 {
req.PageNum = 1
}
page = req.PageNum
if req.PageSize == 0 {
req.PageSize = comModel.PageSize
}
order:= "{{$pk}} asc"
if req.OrderBy!=""{
order = req.OrderBy
}
err = m.Page(page, req.PageSize).Order(order).Scan(&list)
{{else}}
order:= "{{$pk}} asc"
if req.OrderBy!=""{
order = req.OrderBy
}
err = m.Order(order).Scan(&list)
{{end}}
if err != nil {
g.Log().Error(err)
err = gerror.New("获取数据失败")
}
return
}
// GetInfoById 通过id获取
func (s *{{$structName}}) GetInfoById(ctx context.Context,id {{$.table.PkColumn.GoType}}) (info *model.{{.table.ClassName}}, err error) {
if id == 0 {
err = gerror.New("参数错误")
return
}
err = dao.{{.table.ClassName}}.Ctx(ctx).Where(dao.{{.table.ClassName}}.Columns.{{$pkGoField}}, id).Scan(&info)
if err != nil {
g.Log().Error(err)
}
if info == nil || err != nil {
err = gerror.New("获取信息失败")
}
return
}
// Add 添加
func (s *{{$structName}}) Add(ctx context.Context,req *dao.{{.table.ClassName}}AddReq) (err error) {
_, err = dao.{{.table.ClassName}}.Ctx(ctx).Insert(req)
return
}
// Edit 修改
func (s *{{$structName}}) Edit(ctx context.Context,req *dao.{{.table.ClassName}}EditReq) error {
{{ $fieldsEx:= concat "dao." $.table.ClassName ".Columns." $pkGoField }}
{{if ne $createdAt ""}}
{{$fieldsEx = concat "dao." $.table.ClassName ".Columns." $pkGoField "," "dao." $.table.ClassName ".Columns." $createdAtGoField}}
{{end}}
_, err := dao.{{.table.ClassName}}.Ctx(ctx).FieldsEx({{$fieldsEx}}).Where(dao.{{.table.ClassName}}.Columns.{{$pkGoField}}, req.{{$pkGoField}}).
Update(req)
return err
}
// DeleteByIds 删除
func (s *{{$structName}}) DeleteByIds(ctx context.Context,ids []int) (err error) {
if len(ids) == 0 {
err = gerror.New("参数错误")
return
}
{{if eq .table.TplCategory "tree"}}
ids, err = s.GetChildrenIds(ctx,ids)
if err != nil {
return
}
{{end}}
_, err = dao.{{.table.ClassName}}.Ctx(ctx).Delete(dao.{{.table.ClassName}}.Columns.{{$pkGoField}}+" in (?)", ids)
if err != nil {
g.Log().Error(err)
err = gerror.New("删除失败")
}
return
}
{{range $index,$column:= .table.Columns}}
{{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
// Change{{$column.GoField}} 修改状态
func (s *{{$structName}}) Change{{$column.GoField}}(ctx context.Context,req *dao.{{$.table.ClassName}}{{$column.GoField}}Req) error {
_, err := dao.{{$.table.ClassName}}.Ctx(ctx).WherePri(req.{{$pkGoField}}).Update(g.Map{
dao.{{$.table.ClassName}}.Columns.{{$column.GoField}}: req.{{$column.GoField}},
})
return err
}
{{end}}
{{end}}
{{if eq .table.TplCategory "tree"}}
// GetChildrenIds 通过ID获取子级ID
func (s *{{$structName}})GetChildrenIds(ctx context.Context,ids []int) ([]int, error) {
//获取所有
_,_,all, err := s.GetList(&dao.{{.table.ClassName}}SearchReq{PageReq:comModel.PageReq{Ctx: ctx}})
if err != nil {
return nil, err
}
list := make(g.List, len(all))
for k, info := range all {
list[k] = gconv.Map(info)
}
for _, id := range ids {
children := library.FindSonByParentId(list, id, "{{.table.TreeParentCode}}", "{{.table.TreeCode}}")
for _, cid := range children {
ids = append(ids, gconv.Int(cid["{{.table.TreeCode}}"]))
}
}
return ids, nil
}
{{end}}

View File

@@ -0,0 +1,102 @@
import request from '@/utils/request'
{{$businessName := .table.BusinessName | CaseCamelLower}}
{{$plugin:=""}}
{{if ContainsI $.table.PackageName "plugins"}}
{{$plugin = "plugins/"}}
{{end}}
// 查询{{.table.FunctionName}}列表
export function list{{.table.ClassName}}(query) {
return request({
url: '/{{$plugin}}{{.table.ModuleName}}/{{$businessName}}/list',
method: 'get',
params: query
})
}
// 查询{{.table.FunctionName}}详细
export function get{{.table.ClassName}}({{.table.PkColumn.HtmlField}}) {
return request({
url: '/{{$plugin}}{{.table.ModuleName}}/{{$businessName}}/get',
method: 'get',
params: {
id: {{.table.PkColumn.HtmlField}}.toString()
}
})
}
// 新增{{.table.FunctionName}}
export function add{{.table.ClassName}}(data) {
return request({
url: '/{{$plugin}}{{.table.ModuleName}}/{{$businessName}}/add',
method: 'post',
data: data
})
}
// 修改{{.table.FunctionName}}
export function update{{.table.ClassName}}(data) {
return request({
url: '/{{$plugin}}{{.table.ModuleName}}/{{$businessName}}/edit',
method: 'put',
data: data
})
}
// 删除{{.table.FunctionName}}
export function del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}s) {
return request({
url: '/{{$plugin}}{{.table.ModuleName}}/{{$businessName}}/delete',
method: 'delete',
data:{
ids:{{.table.PkColumn.HtmlField}}s
}
})
}
{{$getUserList:=false}}
{{range $index,$column:= .table.Columns}}
{{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
// {{$.table.FunctionName}}{{$column.ColumnComment}}修改
export function change{{$.table.ClassName}}{{$column.GoField}}({{$.table.PkColumn.HtmlField}},{{$column.HtmlField}}) {
const data = {
{{$.table.PkColumn.HtmlField}},
{{$column.HtmlField}}
}
return request({
url: '/{{$plugin}}{{$.table.ModuleName}}/{{$businessName}}/change{{$column.GoField}}',
method: 'put',
data:data
})
}
{{end}}
{{if ne $column.LinkTableName ""}}
// 关联{{$column.LinkTableName}}表选项
export function list{{$column.LinkTableClass}}(query){
return request({
url: '/{{$plugin}}{{$.table.ModuleName}}/{{$column.LinkTableName | CaseCamelLower}}/list',
method: 'get',
params: query
})
}
{{end}}
{{if eq $column.HtmlField "createdBy" "updatedBy"}}
{{$getUserList = true}}
{{end}}
{{end}}
{{if $getUserList}}
//获取用户信息列表
export function getUserList(uIds){
return request({
url: '/system/auth/usersGet',
method: 'get',
params: {ids:uIds}
})
}
{{end}}

View File

@@ -0,0 +1,50 @@
/*
==========================================================================
GFast自动生成菜单SQL,只生成一次,按需修改.
生成日期:{{.table.CreateTime}}
生成路径: data/gen_sql/{{.table.ModuleName}}/{{.table.BusinessName}}_menu.sql
生成人:{{.table.FunctionAuthor}}
==========================================================================
*/
{{$plugin:=""}}
{{if ContainsI $.table.PackageName "plugins"}}
{{$plugin = "plugins/"}}
{{end}}
-- 当前日期
select @now := now();
-- 目录 SQL
INSERT INTO `sys_auth_rule` (`pid`,`name`,`title`,`icon`,`condition`,`remark`,`menu_type`,`weigh`,`status`,`always_show`,`path`,`jump_path`,`component`,`is_frame`,`module_type`,`model_id`,`created_at`,`updated_at`,`deleted_at` )
VALUES(0,'{{$plugin}}{{.table.ModuleName}}/{{.table.BusinessName | CaseCamelLower}}','{{.table.FunctionName}}管理','form','','{{.table.FunctionName}}管理',0,0,1,1,'{{$plugin}}{{.table.BusinessName | CaseCamelLower}}','','',0,'sys_admin',0,@now,@now,NULL );
-- 菜单父目录ID
SELECT @parentId := LAST_INSERT_ID();
-- 菜单 SQL
INSERT INTO `sys_auth_rule` (`pid`,`name`,`title`,`icon`,`condition`,`remark`,`menu_type`,`weigh`,`status`,`always_show`,`path`,`jump_path`,`component`,`is_frame`,`module_type`,`model_id`,`created_at`,`updated_at`,`deleted_at` )
VALUES(@parentId,'{{$plugin}}{{.table.ModuleName}}/{{.table.BusinessName | CaseCamelLower}}/list','{{.table.FunctionName}}列表','list','','{{.table.FunctionName}}列表',1,0,1,1,'{{.table.BusinessName | CaseCamelLower}}List','','{{$plugin}}{{.table.ModuleName}}/{{.table.BusinessName | CaseCamelLower}}/list',0,'sys_admin',0,@now,@now,NULL );
-- 按钮父目录ID
SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
INSERT INTO `sys_auth_rule` (`pid`,`name`,`title`,`icon`,`condition`,`remark`,`menu_type`,`weigh`,`status`,`always_show`,`path`,`jump_path`,`component`,`is_frame`,`module_type`,`model_id`,`created_at`,`updated_at`,`deleted_at` )
VALUES(@parentId,'{{$plugin}}{{.table.ModuleName}}/{{.table.BusinessName | CaseCamelLower}}/get','{{.table.FunctionName}}查询','','','{{.table.FunctionName}}查询',2,0,1,1,'','','',0,'sys_admin',0,@now,@now,NULL );
INSERT INTO `sys_auth_rule` (`pid`,`name`,`title`,`icon`,`condition`,`remark`,`menu_type`,`weigh`,`status`,`always_show`,`path`,`jump_path`,`component`,`is_frame`,`module_type`,`model_id`,`created_at`,`updated_at`,`deleted_at` )
VALUES(@parentId,'{{$plugin}}{{.table.ModuleName}}/{{.table.BusinessName | CaseCamelLower}}/add','{{.table.FunctionName}}添加','','','{{.table.FunctionName}}添加',2,0,1,1,'','','',0,'sys_admin',0,@now,@now,NULL );
INSERT INTO `sys_auth_rule` (`pid`,`name`,`title`,`icon`,`condition`,`remark`,`menu_type`,`weigh`,`status`,`always_show`,`path`,`jump_path`,`component`,`is_frame`,`module_type`,`model_id`,`created_at`,`updated_at`,`deleted_at` )
VALUES(@parentId,'{{$plugin}}{{.table.ModuleName}}/{{.table.BusinessName | CaseCamelLower}}/edit','{{.table.FunctionName}}修改','','','{{.table.FunctionName}}修改',2,0,1,1,'','','',0,'sys_admin',0,@now,@now,NULL );
INSERT INTO `sys_auth_rule` (`pid`,`name`,`title`,`icon`,`condition`,`remark`,`menu_type`,`weigh`,`status`,`always_show`,`path`,`jump_path`,`component`,`is_frame`,`module_type`,`model_id`,`created_at`,`updated_at`,`deleted_at` )
VALUES(@parentId,'{{$plugin}}{{.table.ModuleName}}/{{.table.BusinessName | CaseCamelLower}}/delete','{{.table.FunctionName}}删除','','','{{.table.FunctionName}}删除',2,0,1,1,'','','',0,'sys_admin',0,@now,@now,NULL );
{{range $index,$column:= .table.Columns}}
{{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
INSERT INTO `sys_auth_rule` (`pid`,`name`,`title`,`icon`,`condition`,`remark`,`menu_type`,`weigh`,`status`,`always_show`,`path`,`jump_path`,`component`,`is_frame`,`module_type`,`model_id`,`created_at`,`updated_at`,`deleted_at` )
VALUES(@parentId,'{{$plugin}}{{$.table.ModuleName}}/{{$.table.BusinessName | CaseCamelLower}}/change{{$column.GoField}}','{{$.table.FunctionName}}{{$column.ColumnComment}}修改','','','{{$.table.FunctionName}}{{$column.ColumnComment}}修改',2,0,1,1,'','','',0,'sys_admin',0,@now,@now,NULL );
{{end}}
{{end}}

View File

@@ -0,0 +1,513 @@
<template>
{{$lens := .table.Columns|len}}
{{$businessName := .table.BusinessName | CaseCamelLower}}
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
{{range $index, $column := .table.Columns}}
{{if and (eq $column.IsQuery "1") (ne $column.ColumnName "created_by") (ne $column.ColumnName "updated_by") (ne $column.ColumnName "created_at") (ne $column.ColumnName "updated_at") (ne $column.ColumnName "deleted_at")}}
{{if eq $column.HtmlType "input" "textarea"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-input
v-model="queryParams.{{$column.HtmlField}}"
placeholder="请输入{{$column.ColumnComment}}"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
{{else if and (eq $column.HtmlType "select" "radio" "checkbox") (ne $column.DictType "") }}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="queryParams.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" clearable size="small">
<el-option
v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key"
:label="dict.value"
:value="dict.key"
/>
</el-select>
</el-form-item>
{{else if eq $column.HtmlType "datetime"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-date-picker
clearable size="small" style="width: 200px"
v-model="queryParams.{{$column.HtmlField}}"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择{{$column.ColumnComment}}">
</el-date-picker>
</el-form-item>
{{else if and (eq $column.HtmlType "select" "radio" "checkbox") (ne $column.LinkTableName "")}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="queryParams.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" clearable size="small">
<el-option
v-for="item in {{$column.HtmlField}}Options"
:key="item.key"
:label="item.value"
:value="item.key"
/>
</el-select>
</el-form-item>
{{else}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="queryParams.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" clearable size="small">
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>
{{end}}
{{end}}
{{end}}
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/delete']"
>删除</el-button>
</el-col>
</el-row>
<el-table v-loading="loading" :data="{{$businessName}}List" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
{{range $index, $column := .table.Columns}}
{{if eq $column.IsPk "1"}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" />
{{else if and (eq $column.IsList "1") (eq $column.HtmlType "datetime")}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" width="180">
<template slot-scope="scope">
<span>{{VueTag "{{"}} parseTime(scope.row.{{$column.HtmlField}}, '{y}-{m}-{d}') {{VueTag "}}"}}</span>
</template>
</el-table-column>
{{else if and (eq $column.IsList "1") (HasSuffix $column.ColumnName "status")}}
<el-table-column label="{{$column.ColumnComment}}" align="center">
<template slot-scope="scope">
<el-switch
v-model="scope.row.{{$column.HtmlField}}"
:active-value="1"
:inactive-value="0"
@change="{{$column.HtmlField}}Change(scope.row)"
></el-switch>
</template>
</el-table-column>
{{else if ne $column.LinkTableName ""}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" :formatter="{{$column.HtmlField}}Format" width="100">
<template slot-scope="scope">
{{VueTag "{{" }} {{$column.HtmlField}}Format(scope.row) {{VueTag "}}" }}
</template>
</el-table-column>
{{else if and (eq $column.IsList "1") (ne $column.DictType "")}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" :formatter="{{$column.HtmlField}}Format" />
{{else if and (eq $column.IsList "1") (ne $column.HtmlField "")}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" />
{{end}}{{end}}
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/delete']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改{{.table.FunctionName}}对话框 -->
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
{{range $index, $column := .table.Columns}}
{{if and (eq $column.IsInsert "1") (ne $column.IsPk "1")}}
{{if eq $column.HtmlType "input"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-input v-model="form.{{$column.HtmlField}}" placeholder="请输入{{$column.ColumnComment}}" />
</el-form-item>
{{else if eq $column.HtmlType "select" }}
{{if ne $column.LinkTableName ""}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="form.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}">
<el-option
v-for="item in {{$column.HtmlField}}Options"
:key="item.key"
:label="item.value"
:value="item.key"
></el-option>
</el-select>
</el-form-item>
{{else if ne $column.DictType ""}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="form.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}">
<el-option
v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key"
:label="dict.value"
{{if eq $column.GoType "Integer"}}
:value="parseInt(dict.key)"
{{else}}
:value="dict.key"
{{end}}
></el-option>
</el-select>
</el-form-item>
{{else}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="form.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}">
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>
{{end}}
{{else if eq $column.HtmlType "radio" }}
{{if ne $column.DictType ""}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-radio-group v-model="form.{{$column.HtmlField}}">
<el-radio
v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key"
:label="dict.key"
>{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-radio>
</el-radio-group>
</el-form-item>
{{else}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-radio-group v-model="form.{{$column.HtmlField}}">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
{{end}}
{{else if eq $column.HtmlType "datetime"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-date-picker clearable size="small" style="width: 200px"
v-model="form.{{$column.HtmlField}}"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择{{$column.ColumnComment}}">
</el-date-picker>
</el-form-item>
{{else if eq $column.HtmlType "textarea"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-input v-model="form.{{$column.HtmlField}}" type="textarea" placeholder="请输入{{$column.ColumnComment}}" />
</el-form-item>
{{else if eq $column.HtmlType "checkbox" }}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-checkbox-group v-model="form.{{$column.HtmlField}}">
<el-checkbox
v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key"
:label="dict.key"
>{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
{{else if eq $column.HtmlType "richtext"}}
<el-form-item label="{{$column.ColumnComment}}">
<Editor ref="cke" v-model="form.{{$column.HtmlField}}" @setEditContent="set{{$column.GoField}}EditContent"/>
</el-form-item>
{{end}}
{{end}}
{{end}}
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
{{$plugin:=""}}
{{if ContainsI $.table.PackageName "plugins"}}
{{$plugin = "plugins/"}}
{{end}}
import {
list{{.table.ClassName}},
get{{.table.ClassName}},
del{{.table.ClassName}},
add{{.table.ClassName}},
update{{.table.ClassName}},
{{range $index,$column:= .table.Columns}}
{{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
change{{$.table.ClassName}}{{$column.GoField}},
{{end}}
{{if ne $column.LinkTableName ""}}
list{{$column.LinkTableClass}},
{{end}}
{{end}}
} from "@/api/{{$plugin}}{{.table.ModuleName}}/{{$businessName}}";
export default {
components:{},
name: "{{.table.ClassName}}",
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 总条数
total: 0,
// {{.table.FunctionName}}表格数据
{{$businessName}}List: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
// {{$column.HtmlField}}Options字典数据
{{$column.HtmlField}}Options: [],
{{else if ne $column.LinkTableName ""}}
// {{$column.HtmlField}}Options关联表数据
{{$column.HtmlField}}Options: [],
{{end}}
{{end}}
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,{{range $index, $column := .table.Columns}}{{if eq $column.IsQuery "1"}}
{{$column.HtmlField}}: undefined{{if ne $lens $index}},{{end}}{{end}}{{end}}
},
// 表单参数
form: {},
// 表单校验
rules: { {{range $index, $column := .table.Columns}}{{if eq $column.IsRequired "1"}}
{{$column.HtmlField}} : [
{ required: true, message: "{{$column.ColumnComment}}不能为空", trigger: "blur" }
]{{if ne $lens $index}},{{end}}{{end}}{{end}}
}
};
},
created() {
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
this.getDicts("{{$column.DictType}}").then(response => {
this.{{$column.HtmlField}}Options = response.data.values||[];
});
{{else if ne $column.LinkTableName ""}}
this.get{{$column.LinkTableClass}}Items()
{{end}}
{{end}}
this.getList();
},
methods: {
{{$setUpData:=true}}
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
get{{$column.LinkTableClass}}Items() {
this.getItems(list{{$column.LinkTableClass}}, {pageSize:10000}).then(res => {
this.{{$column.HtmlField}}Options = this.setItems(res, '{{$column.LinkLabelId}}', '{{$column.LinkLabelName}}')
})
},
{{else if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1")}}
// {{$column.ColumnComment}}修改
{{$column.HtmlField}}Change(row) {
let text = row.{{$column.HtmlField}} === 1 ? "启用" : "停用";
this.$confirm('确认要"' + text + '":吗?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return change{{$.table.ClassName}}{{$column.GoField}}(row.{{$.table.PkColumn.HtmlField}}, row.{{$column.HtmlField}});
}).then(() => {
this.msgSuccess(text + "成功");
}).catch(function() {
row.userStatus =row.userStatus === 0 ?1 : 0;
});
},
{{end}}
{{end}}
/** 查询{{.table.FunctionName}}列表 */
getList() {
this.loading = true;
list{{.table.ClassName}}(this.queryParams).then(response => {
this.{{$businessName}}List = response.data.list;
this.total = response.data.total;
this.loading = false;
});
},
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox"}}
// {{$column.ColumnComment}}字典翻译
{{$column.HtmlField}}Format(row, column) {
let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
let data = [];
{{$column.HtmlField}}.map(item=>{
data.push(this.selectDictLabel(this.{{$column.HtmlField}}Options, item))
})
return data.join(",")
},
{{else}}
// {{$column.ColumnComment}}字典翻译
{{$column.HtmlField}}Format(row, column) {
return this.selectDictLabel(this.{{$column.HtmlField}}Options, row.{{$column.HtmlField}});
},
{{end}}
{{else if ne $column.LinkTableName ""}}
// {{$column.ColumnComment}}关联表翻译
{{$column.HtmlField}}Format(row, column) {
return this.selectItemsLabel(this.{{$column.HtmlField}}Options, row.{{$column.HtmlField}});
},
{{end}}
{{end}}
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "radio"}}
{{$column.HtmlField}}: "0" ,
{{else if eq $column.HtmlType "checkbox"}}
{{$column.HtmlField}}: [] ,
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}
{{end}}
};
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "imagefile"}}
this.imageUrl{{$column.GoField}} = ''
{{end}}
{{end}}
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.{{.table.PkColumn.HtmlField}})
this.single = selection.length!=1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加{{.table.FunctionName}}";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const {{.table.PkColumn.HtmlField}} = row.{{.table.PkColumn.HtmlField}} || this.ids
get{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(response => {
let data = response.data;
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "checkbox"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
{{else if eq $column.HtmlType "radio" "select"}}
data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
{{end}}
{{end}}
this.form = data;
this.open = true;
this.title = "修改{{.table.FunctionName}}";
});
},
/** 提交按钮 */
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.{{.table.PkColumn.HtmlField}} != undefined) {
update{{.table.ClassName}}(this.form).then(response => {
if (response.code === 0) {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
} else {
this.msgError(response.msg);
}
});
} else {
add{{.table.ClassName}}(this.form).then(response => {
if (response.code === 0) {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
} else {
this.msgError(response.msg);
}
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const {{.table.PkColumn.HtmlField}}s = row.{{.table.PkColumn.HtmlField}} || this.ids;
this.$confirm('是否确认删除{{.table.FunctionName}}编号为"' + {{.table.PkColumn.HtmlField}}s + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}s);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(function() {});
}
}
};
</script>

View File

@@ -0,0 +1,536 @@
<template>
{{$lens := .table.Columns|len}}
{{$businessName := .table.BusinessName | CaseCamelLower}}
{{$treeParentCode := .table.TreeParentCode}}
{{$treeCode := .table.TreeCode}}
{{$treeName := .table.TreeName}}
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
{{range $index, $column := .table.Columns}}
{{if and (eq $column.IsQuery "1") (ne $column.ColumnName "created_by") (ne $column.ColumnName "updated_by") (ne $column.ColumnName "created_at") (ne $column.ColumnName "updated_at") (ne $column.ColumnName "deleted_at")}}
{{if eq $column.HtmlType "input" "textarea"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-input
v-model="queryParams.{{$column.HtmlField}}"
placeholder="请输入{{$column.ColumnComment}}"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
{{else if and (eq $column.HtmlType "select" "radio" "checkbox") (ne $column.DictType "") }}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="queryParams.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" clearable size="small">
<el-option
v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key"
:label="dict.value"
:value="dict.key"
/>
</el-select>
</el-form-item>
{{else if eq $column.HtmlType "datetime"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-date-picker
clearable size="small" style="width: 200px"
v-model="queryParams.{{$column.HtmlField}}"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择{{$column.ColumnComment}}">
</el-date-picker>
</el-form-item>
{{else if and (eq $column.HtmlType "select" "radio" "checkbox") (ne $column.LinkTableName "")}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="queryParams.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" clearable size="small">
<el-option
v-for="item in {{$column.HtmlField}}Options"
:key="item.key"
:label="item.value"
:value="item.key"
/>
</el-select>
</el-form-item>
{{else}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="queryParams.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" clearable size="small">
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>
{{end}}
{{end}}
{{end}}
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/delete']"
>删除</el-button>
</el-col>
</el-row>
<el-table v-loading="loading" :data="{{$businessName}}List"
@selection-change="handleSelectionChange"
row-key="{{$treeCode}}"
default-expand-all
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>
<el-table-column type="selection" width="55" align="center" />
{{range $index, $column := .table.Columns}}
{{if eq $column.IsPk "1"}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" />
{{else if and (eq $column.IsList "1") (eq $column.HtmlType "datetime")}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" width="180">
<template slot-scope="scope">
<span>{{VueTag "{{"}} parseTime(scope.row.{{$column.HtmlField}}, '{y}-{m}-{d}') {{VueTag "}}"}}</span>
</template>
</el-table-column>
{{else if and (eq $column.IsList "1") (HasSuffix $column.ColumnName "status")}}
<el-table-column label="{{$column.ColumnComment}}" align="center">
<template slot-scope="scope">
<el-switch
v-model="scope.row.{{$column.HtmlField}}"
:active-value="1"
:inactive-value="0"
@change="{{$column.HtmlField}}Change(scope.row)"
></el-switch>
</template>
</el-table-column>
{{else if ne $column.LinkTableName ""}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" :formatter="{{$column.HtmlField}}Format" width="100">
<template slot-scope="scope">
{{VueTag "{{" }} {{$column.HtmlField}}Format(scope.row) {{VueTag "}}" }}
</template>
</el-table-column>
{{else if and (eq $column.IsList "1") (ne $column.DictType "")}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" :formatter="{{$column.HtmlField}}Format" />
{{else if and (eq $column.IsList "1") (ne $column.HtmlField "")}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" />
{{end}}{{end}}
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/delete']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加或修改{{.table.FunctionName}}对话框 -->
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
{{range $index, $column := .table.Columns}}
{{if and (eq $column.IsInsert "1") (ne $column.IsPk "1")}}
{{if and (ne $treeParentCode "") (eq $column.HtmlField $treeParentCode)}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$treeParentCode}}">
<treeselect v-model="form.{{$treeParentCode}}" :options="{{$businessName}}Options" :normalizer="normalizer" placeholder="请选择{{$column.ColumnComment}}" />
</el-form-item>
{{else if eq $column.HtmlType "input"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-input v-model="form.{{$column.HtmlField}}" placeholder="请输入{{$column.ColumnComment}}" />
</el-form-item>
{{else if eq $column.HtmlType "select" }}
{{if ne $column.LinkTableName ""}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="form.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}">
<el-option
v-for="item in {{$column.HtmlField}}Options"
:key="item.key"
:label="item.value"
:value="item.key"
></el-option>
</el-select>
</el-form-item>
{{else if ne $column.DictType ""}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="form.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}">
<el-option
v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key"
:label="dict.value"
{{if eq $column.GoType "Integer"}}
:value="parseInt(dict.key)"
{{else}}
:value="dict.key"
{{end}}
></el-option>
</el-select>
</el-form-item>
{{else}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-select v-model="form.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}">
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>
{{end}}
{{else if eq $column.HtmlType "radio" }}
{{if ne $column.DictType ""}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-radio-group v-model="form.{{$column.HtmlField}}">
<el-radio
v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key"
:label="dict.key"
>{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-radio>
</el-radio-group>
</el-form-item>
{{else}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-radio-group v-model="form.{{$column.HtmlField}}">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
{{end}}
{{else if eq $column.HtmlType "datetime"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-date-picker clearable size="small" style="width: 200px"
v-model="form.{{$column.HtmlField}}"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择{{$column.ColumnComment}}">
</el-date-picker>
</el-form-item>
{{else if eq $column.HtmlType "textarea"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-input v-model="form.{{$column.HtmlField}}" type="textarea" placeholder="请输入{{$column.ColumnComment}}" />
</el-form-item>
{{else if eq $column.HtmlType "checkbox" }}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-checkbox-group v-model="form.{{$column.HtmlField}}">
<el-checkbox
v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key"
:label="dict.key"
>{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
{{end}}
{{end}}
{{end}}
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
{{$plugin:=""}}
{{if ContainsI $.table.PackageName "plugins"}}
{{$plugin = "plugins/"}}
{{end}}
import {
list{{.table.ClassName}},
get{{.table.ClassName}},
del{{.table.ClassName}},
add{{.table.ClassName}},
update{{.table.ClassName}},
{{range $index,$column:= .table.Columns}}
{{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
change{{$.table.ClassName}}{{$column.GoField}},
{{end}}
{{if ne $column.LinkTableName ""}}
list{{$column.LinkTableClass}},
{{end}}
{{end}}
} from "@/api/{{$plugin}}{{.table.ModuleName}}/{{$businessName}}";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
name: "{{.table.ClassName}}",
components: {Treeselect},
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 总条数
total: 0,
// {{.table.FunctionName}}表格数据
{{$businessName}}List: [],
// {{.table.FunctionName}}树选项
{{$businessName}}Options: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
// {{$column.HtmlField}}Options字典数据
{{$column.HtmlField}}Options: [],
{{else if ne $column.LinkTableName ""}}
// {{$column.HtmlField}}Options关联表数据
{{$column.HtmlField}}Options: [],
{{end}}
{{end}}
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,{{range $index, $column := .table.Columns}}{{if eq $column.IsQuery "1"}}
{{$column.HtmlField}}: undefined{{if ne $lens $index}},{{end}}{{end}}{{end}}
},
// 表单参数
form: {},
// 表单校验
rules: { {{range $index, $column := .table.Columns}}{{if eq $column.IsRequired "1"}}
{{$column.HtmlField}} : [
{ required: true, message: "{{$column.ColumnComment}}不能为空", trigger: "blur" }
]{{if ne $lens $index}},{{end}}{{end}}{{end}}
}
};
},
created() {
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
this.getDicts("{{$column.DictType}}").then(response => {
this.{{$column.HtmlField}}Options = response.data.values||[];
});
{{else if ne $column.LinkTableName ""}}
this.get{{$column.LinkTableClass}}Items()
{{end}}
{{end}}
this.getList();
},
methods: {
{{$setUpData:=true}}
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
get{{$column.LinkTableClass}}Items() {
this.getItems(list{{$column.LinkTableClass}}, {pageSize:10000}).then(res => {
this.{{$column.HtmlField}}Options = this.setItems(res, '{{$column.LinkLabelId}}', '{{$column.LinkLabelName}}')
})
},
{{else if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1")}}
// {{$column.ColumnComment}}修改
{{$column.HtmlField}}Change(row) {
let text = row.{{$column.HtmlField}} === 1 ? "启用" : "停用";
this.$confirm('确认要"' + text + '":吗?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return change{{$.table.ClassName}}{{$column.GoField}}(row.{{$.table.PkColumn.HtmlField}}, row.{{$column.HtmlField}});
}).then(() => {
this.msgSuccess(text + "成功");
}).catch(function() {
row.userStatus =row.userStatus === 0 ?1 : 0;
});
},
{{end}}
{{end}}
/** 查询{{.table.FunctionName}}列表 */
getList() {
this.loading = true;
list{{.table.ClassName}}(this.queryParams).then(response => {
this.{{$businessName}}List = this.handleTree(response.data.list||[], "{{$treeCode}}", "{{$treeParentCode}}");
this.loading = false;
});
},
/** 转换{{.table.FunctionName}}数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
return {
id: node.{{$treeCode}},
label: node.{{$treeName}},
children: node.children
};
},
/** 查询{{.table.FunctionName}}下拉树结构 */
getTreeselect() {
list{{.table.ClassName}}(this.queryParams).then(response => {
this.{{$businessName}}Options = [];
const data = { {{$treeCode}}: 0, {{$treeName}}: '顶级节点', children: [] };
data.children = this.handleTree(response.data.list||[], "{{$treeCode}}", "{{$treeParentCode}}");
this.{{$businessName}}Options.push(data);
});
},
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox"}}
// {{$column.ColumnComment}}字典翻译
{{$column.HtmlField}}Format(row, column) {
let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
let data = [];
{{$column.HtmlField}}.map(item=>{
data.push(this.selectDictLabel(this.{{$column.HtmlField}}Options, item))
})
return data.join(",")
},
{{else}}
// {{$column.ColumnComment}}字典翻译
{{$column.HtmlField}}Format(row, column) {
return this.selectDictLabel(this.{{$column.HtmlField}}Options, row.{{$column.HtmlField}});
},
{{end}}
{{else if ne $column.LinkTableName ""}}
// {{$column.ColumnComment}}关联表翻译
{{$column.HtmlField}}Format(row, column) {
return this.selectItemsLabel(this.{{$column.HtmlField}}Options, row.{{$column.HtmlField}});
},
{{end}}
{{end}}
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "radio"}}
{{$column.HtmlField}}: "0" {{if ne $lens $index}},{{end}}
{{else if eq $column.HtmlType "checkbox"}}
{{$column.HtmlField}}: [] {{if ne $lens $index}},{{end}}
{{else}}
{{$column.HtmlField}}: undefined{{if ne $lens $index}},{{end}}{{end}}{{end}}
};
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "imagefile"}}
this.imageUrl{{$column.GoField}} = ''
{{end}}
{{end}}
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.{{.table.PkColumn.HtmlField}})
this.single = selection.length!=1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.getTreeselect()
this.open = true;
this.title = "添加{{.table.FunctionName}}";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.getTreeselect()
const {{.table.PkColumn.HtmlField}} = row.{{.table.PkColumn.HtmlField}} || this.ids
get{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(response => {
let data = response.data;
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "checkbox"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
{{else if eq $column.HtmlType "radio" "select"}}
data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
{{end}}
{{end}}
this.form = data;
this.open = true;
this.title = "修改{{.table.FunctionName}}";
});
},
/** 提交按钮 */
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.{{.table.PkColumn.HtmlField}} != undefined) {
update{{.table.ClassName}}(this.form).then(response => {
if (response.code === 0) {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
} else {
this.msgError(response.msg);
}
});
} else {
add{{.table.ClassName}}(this.form).then(response => {
if (response.code === 0) {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
} else {
this.msgError(response.msg);
}
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const {{.table.PkColumn.HtmlField}}s = row.{{.table.PkColumn.HtmlField}} || this.ids;
this.$confirm('是否确认删除{{.table.FunctionName}}编号为"' + {{.table.PkColumn.HtmlField}}s + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}s);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(function() {});
}
}
};
</script>