feat:cms + gen code
This commit is contained in:
1 parent
7215f7c236
commit
d27583421b
14 files changed
+644
-60
No files matched your search
@@ -0,0 +1,82 @@
|
||||
package syscategory
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/tools"
|
||||
"go-admin/tools/app"
|
||||
"go-admin/tools/app/msg"
|
||||
)
|
||||
|
||||
func GetSysCategoryList(c *gin.Context) {
|
||||
var data models.SysCategory
|
||||
var err error
|
||||
var pageSize = 10
|
||||
var pageIndex = 1
|
||||
|
||||
if size := c.Request.FormValue("pageSize"); size != "" {
|
||||
pageSize = tools.StrToInt(err, size)
|
||||
}
|
||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||
pageIndex = tools.StrToInt(err, index)
|
||||
}
|
||||
|
||||
data.Name = c.Request.FormValue("name")
|
||||
data.Status = c.Request.FormValue("status")
|
||||
|
||||
data.DataScope = tools.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.PageOK(c, result, count, pageIndex, pageSize, "")
|
||||
}
|
||||
|
||||
func GetSysCategory(c *gin.Context) {
|
||||
var data models.SysCategory
|
||||
data.Id, _ = tools.StringToInt(c.Param("id"))
|
||||
result, err := data.Get()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 添加分类
|
||||
// @Description 获取JSON
|
||||
// @Tags 分类
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body models.SysCategory true "data"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/syscategory [post]
|
||||
func InsertSysCategory(c *gin.Context) {
|
||||
var data models.SysCategory
|
||||
err := c.ShouldBindJSON(&data)
|
||||
data.CreateBy = tools.GetUserIdStr(c)
|
||||
tools.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func UpdateSysCategory(c *gin.Context) {
|
||||
var data models.SysCategory
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
tools.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.Id)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func DeleteSysCategory(c *gin.Context) {
|
||||
var data models.SysCategory
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
|
||||
IDS := tools.IdsStrToIdsIntGroup("id", c)
|
||||
_, err := data.BatchDelete(IDS)
|
||||
tools.HasError(err, msg.DeletedFail, 500)
|
||||
app.OK(c, nil, msg.DeletedSuccess)
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package syscontent
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/tools"
|
||||
"go-admin/tools/app"
|
||||
"go-admin/tools/app/msg"
|
||||
)
|
||||
|
||||
func GetSysContentList(c *gin.Context) {
|
||||
var data models.SysContent
|
||||
var err error
|
||||
var pageSize = 10
|
||||
var pageIndex = 1
|
||||
|
||||
if size := c.Request.FormValue("pageSize"); size != "" {
|
||||
pageSize = tools.StrToInt(err, size)
|
||||
}
|
||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||
pageIndex = tools.StrToInt(err, index)
|
||||
}
|
||||
|
||||
data.CateId = c.Request.FormValue("cateId")
|
||||
data.Name = c.Request.FormValue("name")
|
||||
data.Status = c.Request.FormValue("status")
|
||||
|
||||
|
||||
data.DataScope = tools.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.PageOK(c, result, count, pageIndex, pageSize, "")
|
||||
}
|
||||
|
||||
func GetSysContent(c *gin.Context) {
|
||||
var data models.SysContent
|
||||
data.Id, _ = tools.StringToInt(c.Param("id"))
|
||||
result, err := data.Get()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 添加内容管理
|
||||
// @Description 获取JSON
|
||||
// @Tags 内容管理
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body models.SysContent true "data"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/syscontent [post]
|
||||
func InsertSysContent(c *gin.Context) {
|
||||
var data models.SysContent
|
||||
err := c.ShouldBindJSON(&data)
|
||||
data.CreateBy = tools.GetUserIdStr(c)
|
||||
tools.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func UpdateSysContent(c *gin.Context) {
|
||||
var data models.SysContent
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
tools.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.Id)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func DeleteSysContent(c *gin.Context) {
|
||||
var data models.SysContent
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
|
||||
IDS := tools.IdsStrToIdsIntGroup("id", c)
|
||||
_, err := data.BatchDelete(IDS)
|
||||
tools.HasError(err, msg.DeletedFail, 500)
|
||||
app.OK(c, nil, msg.DeletedSuccess)
|
||||
}
|
||||
+2
-2
@@ -139,7 +139,7 @@ func GenMenuAndApi(c *gin.Context) {
|
||||
table.TableId = id
|
||||
tab, _ := table.Get()
|
||||
Mmenu := models.Menu{}
|
||||
Mmenu.MenuName = tab.TBName + "管理"
|
||||
Mmenu.MenuName = tab.TBName + "Manage"
|
||||
Mmenu.Title = tab.TableComment
|
||||
Mmenu.Icon = "pass"
|
||||
Mmenu.Path = "/" + tab.TBName
|
||||
@@ -158,7 +158,7 @@ func GenMenuAndApi(c *gin.Context) {
|
||||
Mmenu.MenuId, err = Mmenu.Create()
|
||||
|
||||
Cmenu := models.Menu{}
|
||||
Cmenu.MenuName = tab.TBName + "管理"
|
||||
Cmenu.MenuName = tab.TBName
|
||||
Cmenu.Title = tab.TableComment
|
||||
Cmenu.Icon = "pass"
|
||||
Cmenu.Path = tab.TBName
|
||||
|
||||
@@ -70,6 +70,23 @@ func GetSysTables(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
func GetSysTablesInfo(c *gin.Context) {
|
||||
var data tools.SysTables
|
||||
if c.Request.FormValue("tableName")!="" {
|
||||
data.TBName = c.Request.FormValue("tableName")
|
||||
}
|
||||
result, err := data.Get()
|
||||
tools2.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
mp := make(map[string]interface{})
|
||||
mp["list"] = result.Columns
|
||||
mp["info"] = result
|
||||
res.Data = mp
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
func GetSysTablesTree(c *gin.Context) {
|
||||
var data tools.SysTables
|
||||
result, err := data.GetTree()
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
type SysCategory struct {
|
||||
|
||||
Id int `json:"id" gorm:"type:int(11);primary_key;AUTO_INCREMENT"` // 分类Id
|
||||
Name string `json:"name" gorm:"type:varchar(255);"` // 名称
|
||||
Img string `json:"img" gorm:"type:varchar(255);"` // 图片
|
||||
Sort string `json:"sort" gorm:"type:int(4);"` // 排序
|
||||
Status string `json:"status" gorm:"type:int(1);"` // 状态
|
||||
Remark string `json:"remark" gorm:"type:varchar(255);"` // 备注
|
||||
CreateBy string `json:"createBy" gorm:"type:varchar(64);"` // 创建者
|
||||
UpdateBy string `json:"updateBy" gorm:"type:varchar(64);"` // 更新者
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
func (SysCategory) TableName() string {
|
||||
return "sys_category"
|
||||
}
|
||||
|
||||
// 创建SysCategory
|
||||
func (e *SysCategory) Create() (SysCategory, error) {
|
||||
var doc SysCategory
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
|
||||
// 获取SysCategory
|
||||
func (e *SysCategory) Get() (SysCategory, error) {
|
||||
var doc SysCategory
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
|
||||
if e.Id != 0 {
|
||||
table = table.Where("id = ?", e.Id)
|
||||
}
|
||||
|
||||
if e.Name != "" {
|
||||
table = table.Where("name = ?", e.Name)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if e.Status != "" {
|
||||
table = table.Where("status = ?", e.Status)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取SysCategory带分页
|
||||
func (e *SysCategory) GetPage(pageSize int, pageIndex int) ([]SysCategory, int, error) {
|
||||
var doc []SysCategory
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
|
||||
if e.Name != "" {
|
||||
table = table.Where("name = ?", e.Name)
|
||||
}
|
||||
|
||||
if e.Status != "" {
|
||||
table = table.Where("status = ?", e.Status)
|
||||
}
|
||||
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
// 更新SysCategory
|
||||
func (e *SysCategory) Update(id int) (update SysCategory, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 删除SysCategory
|
||||
func (e *SysCategory) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).Delete(&SysCategory{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
}
|
||||
|
||||
//批量删除
|
||||
func (e *SysCategory) BatchDelete(id []int) (Result bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id in (?)", id).Delete(&SysCategory{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
type SysContent struct {
|
||||
Id int `json:"id" gorm:"type:int(11);primary_key;auto_increment"` // id
|
||||
CateId string `json:"cateId" gorm:"type:int(11);"` // 分类id
|
||||
Name string `json:"name" gorm:"type:varchar(255);"` // 名称
|
||||
Status string `json:"status" gorm:"type:int(1);"` // 状态
|
||||
Img string `json:"img" gorm:"type:varchar(255);"` // 图片
|
||||
Content string `json:"content" gorm:"type:text;"` // 内容
|
||||
Remark string `json:"remark" gorm:"type:varchar(255);"` // 备注
|
||||
Sort string `json:"sort" gorm:"type:int(4);"` // 排序
|
||||
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` // 创建者
|
||||
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"` // 更新者
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
func (SysContent) TableName() string {
|
||||
return "sys_content"
|
||||
}
|
||||
|
||||
// 创建SysContent
|
||||
func (e *SysContent) Create() (SysContent, error) {
|
||||
var doc SysContent
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取SysContent
|
||||
func (e *SysContent) Get() (SysContent, error) {
|
||||
var doc SysContent
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
if e.Id != 0 {
|
||||
table = table.Where("id = ?", e.Id)
|
||||
}
|
||||
|
||||
if e.CateId != "" {
|
||||
table = table.Where("cate_id = ?", e.CateId)
|
||||
}
|
||||
|
||||
if e.Name != "" {
|
||||
table = table.Where("name like ?", "%"+e.Name+"%")
|
||||
}
|
||||
|
||||
if e.Status != "" {
|
||||
table = table.Where("status = ?", e.Status)
|
||||
}
|
||||
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取SysContent带分页
|
||||
func (e *SysContent) GetPage(pageSize int, pageIndex int) ([]SysContent, int, error) {
|
||||
var doc []SysContent
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
|
||||
if e.CateId != "" {
|
||||
table = table.Where("cate_id = ?", e.CateId)
|
||||
}
|
||||
|
||||
if e.Name != "" {
|
||||
table = table.Where("name like ?", "%"+e.Name+"%")
|
||||
}
|
||||
|
||||
if e.Status != "" {
|
||||
table = table.Where("status = ?", e.Status)
|
||||
}
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table, err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
// 更新SysContent
|
||||
func (e *SysContent) Update(id int) (update SysContent, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 删除SysContent
|
||||
func (e *SysContent) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).Delete(&SysContent{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
}
|
||||
|
||||
//批量删除
|
||||
func (e *SysContent) BatchDelete(id []int) (Result bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id in (?)", id).Delete(&SysContent{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
return
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type SysFileInfo struct {
|
||||
Id int `json:"id" gorm:"type:int(11);primary_key"` // id
|
||||
Id int `json:"id" gorm:"type:int(11);primary_key;AUTO_INCREMENT"` // id
|
||||
Type string `json:"type" gorm:"type:varchar(255);"` // 文件类型
|
||||
Name string `json:"name" gorm:"type:varchar(255);"` // 文件名称
|
||||
Size string `json:"size" gorm:"type:int(11);"` // 文件大小
|
||||
|
||||
+37
-35
@@ -6,41 +6,43 @@ import (
|
||||
)
|
||||
|
||||
type SysColumns struct {
|
||||
ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"`
|
||||
TableId int `gorm:"" json:"tableId"`
|
||||
ColumnName string `gorm:"size:128;" json:"columnName"`
|
||||
ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
|
||||
ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
|
||||
GoType string `gorm:"column:go_type;size:128;" json:"goType"`
|
||||
GoField string `gorm:"column:go_field;size:128;" json:"goField"`
|
||||
JsonField string `gorm:"column:json_field;size:128;" json:"jsonField"`
|
||||
IsPk string `gorm:"column:is_pk;size:4;" json:"isPk"`
|
||||
IsIncrement string `gorm:"column:is_increment;size:4;" json:"isIncrement"`
|
||||
IsRequired string `gorm:"column:is_required;size:4;" json:"isRequired"`
|
||||
IsInsert string `gorm:"column:is_insert;size:4;" json:"isInsert"`
|
||||
IsEdit string `gorm:"column:is_edit;size:4;" json:"isEdit"`
|
||||
IsList string `gorm:"column:is_list;size:4;" json:"isList"`
|
||||
IsQuery string `gorm:"column:is_query;size:4;" json:"isQuery"`
|
||||
QueryType string `gorm:"column:query_type;size:128;" json:"queryType"`
|
||||
HtmlType string `gorm:"column:html_type;size:128;" json:"htmlType"`
|
||||
DictType string `gorm:"column:dict_type;size:128;" json:"dictType"`
|
||||
Sort int `gorm:"column:sort;" json:"sort"`
|
||||
List string `gorm:"column:list;size:1;" json:"list"`
|
||||
Pk bool `gorm:"column:pk;size:1;" json:"pk"`
|
||||
Required bool `gorm:"column:required;size:1;" json:"required"`
|
||||
SuperColumn bool `gorm:"column:super_column;size:1;" json:"superColumn"`
|
||||
UsableColumn bool `gorm:"column:usable_column;size:1;" json:"usableColumn"`
|
||||
Increment bool `gorm:"column:increment;size:1;" json:"increment"`
|
||||
Insert bool `gorm:"column:insert;size:1;" json:"insert"`
|
||||
Edit bool `gorm:"column:edit;size:1;" json:"edit"`
|
||||
Query bool `gorm:"column:query;size:1;" json:"query"`
|
||||
Remark string `gorm:"column:remark;size:255;" json:"remark"`
|
||||
FkTableName int `gorm:"" json:"fkTableName"`
|
||||
FkCol []SysColumns `gorm:"-" json:"fkCol"`
|
||||
FkLableId int `gorm:"" json:"fkLableId"`
|
||||
FkLableName string `gorm:"size:255;" json:"fkLableName"`
|
||||
CreateBy string `gorm:"column:create_by;size:128;" json:"createBy"`
|
||||
UpdateBy string `gorm:"column:update_By;size:128;" json:"updateBy"`
|
||||
ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"`
|
||||
TableId int `gorm:"" json:"tableId"`
|
||||
ColumnName string `gorm:"size:128;" json:"columnName"`
|
||||
ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
|
||||
ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
|
||||
GoType string `gorm:"column:go_type;size:128;" json:"goType"`
|
||||
GoField string `gorm:"column:go_field;size:128;" json:"goField"`
|
||||
JsonField string `gorm:"column:json_field;size:128;" json:"jsonField"`
|
||||
IsPk string `gorm:"column:is_pk;size:4;" json:"isPk"`
|
||||
IsIncrement string `gorm:"column:is_increment;size:4;" json:"isIncrement"`
|
||||
IsRequired string `gorm:"column:is_required;size:4;" json:"isRequired"`
|
||||
IsInsert string `gorm:"column:is_insert;size:4;" json:"isInsert"`
|
||||
IsEdit string `gorm:"column:is_edit;size:4;" json:"isEdit"`
|
||||
IsList string `gorm:"column:is_list;size:4;" json:"isList"`
|
||||
IsQuery string `gorm:"column:is_query;size:4;" json:"isQuery"`
|
||||
QueryType string `gorm:"column:query_type;size:128;" json:"queryType"`
|
||||
HtmlType string `gorm:"column:html_type;size:128;" json:"htmlType"`
|
||||
DictType string `gorm:"column:dict_type;size:128;" json:"dictType"`
|
||||
Sort int `gorm:"column:sort;" json:"sort"`
|
||||
List string `gorm:"column:list;size:1;" json:"list"`
|
||||
Pk bool `gorm:"column:pk;size:1;" json:"pk"`
|
||||
Required bool `gorm:"column:required;size:1;" json:"required"`
|
||||
SuperColumn bool `gorm:"column:super_column;size:1;" json:"superColumn"`
|
||||
UsableColumn bool `gorm:"column:usable_column;size:1;" json:"usableColumn"`
|
||||
Increment bool `gorm:"column:increment;size:1;" json:"increment"`
|
||||
Insert bool `gorm:"column:insert;size:1;" json:"insert"`
|
||||
Edit bool `gorm:"column:edit;size:1;" json:"edit"`
|
||||
Query bool `gorm:"column:query;size:1;" json:"query"`
|
||||
Remark string `gorm:"column:remark;size:255;" json:"remark"`
|
||||
FkTableName string `gorm:"" json:"fkTableName"`
|
||||
FkTableNameClass string `gorm:"" json:"fkTableNameClass"`
|
||||
FkTableNamePackage string `gorm:"" json:"fkTableNamePackage"`
|
||||
FkCol []SysColumns `gorm:"-" json:"fkCol"`
|
||||
FkLabelId string `gorm:"" json:"fkLabelId"`
|
||||
FkLabelName string `gorm:"size:255;" json:"fkLabelName"`
|
||||
CreateBy string `gorm:"column:create_by;size:128;" json:"createBy"`
|
||||
UpdateBy string `gorm:"column:update_By;size:128;" json:"updateBy"`
|
||||
|
||||
models.BaseModel
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package tools
|
||||
import (
|
||||
orm "go-admin/global"
|
||||
"go-admin/models"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SysTables struct {
|
||||
@@ -10,12 +11,12 @@ type SysTables struct {
|
||||
TBName string `gorm:"column:table_name;size:255;" json:"tableName"` //表名称
|
||||
TableComment string `gorm:"size:255;" json:"tableComment"` //表备注
|
||||
ClassName string `gorm:"size:255;" json:"className"` //类名
|
||||
TplCategory string `gorm:"size:255;" json:"tplCategory"`
|
||||
PackageName string `gorm:"size:255;" json:"packageName"` //包名
|
||||
ModuleName string `gorm:"size:255;" json:"moduleName"` //模块名
|
||||
BusinessName string `gorm:"size:255;" json:"businessName"`
|
||||
FunctionName string `gorm:"size:255;" json:"functionName"` //功能名称
|
||||
FunctionAuthor string `gorm:"size:255;" json:"functionAuthor"` //功能作者
|
||||
TplCategory string `gorm:"size:255;" json:"tplCategory"` //
|
||||
PackageName string `gorm:"size:255;" json:"packageName"` //包名
|
||||
ModuleName string `gorm:"size:255;" json:"moduleName"` //模块名
|
||||
BusinessName string `gorm:"size:255;" json:"businessName"` //
|
||||
FunctionName string `gorm:"size:255;" json:"functionName"` //功能名称
|
||||
FunctionAuthor string `gorm:"size:255;" json:"functionAuthor"` //功能作者
|
||||
PkColumn string `gorm:"size:255;" json:"pkColumn"`
|
||||
PkGoField string `gorm:"size:255;" json:"pkGoField"`
|
||||
PkJsonField string `gorm:"size:255;" json:"pkJsonField"`
|
||||
@@ -156,6 +157,17 @@ func (e *SysTables) Update() (update SysTables, err error) {
|
||||
}
|
||||
|
||||
for i := 0; i < len(e.Columns); i++ {
|
||||
if e.Columns[i].FkTableName != "" {
|
||||
tableNameList := strings.Split(e.Columns[i].FkTableName, "_")
|
||||
e.Columns[i].FkTableNameClass = ""
|
||||
e.Columns[i].FkTableNamePackage = ""
|
||||
for a := 0; a < len(tableNameList); a++ {
|
||||
strStart := string([]byte(tableNameList[a])[:1])
|
||||
strEnd := string([]byte(tableNameList[a])[1:])
|
||||
e.Columns[i].FkTableNameClass += strings.ToUpper(strStart) + strEnd
|
||||
e.Columns[i].FkTableNamePackage += strings.ToLower(strStart) + strings.ToLower(strEnd)
|
||||
}
|
||||
}
|
||||
_, _ = e.Columns[i].Update()
|
||||
}
|
||||
return
|
||||
|
||||
@@ -38,5 +38,7 @@ func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddle
|
||||
v1.GET("/checkrole", nil)
|
||||
|
||||
// {{认证路由自动补充在此处请勿删除}}
|
||||
registerSysContentRouter(v1,authMiddleware)
|
||||
registerSysCategoryRouter(v1,authMiddleware)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/middleware"
|
||||
"go-admin/apis/syscategory"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
// 需认证的路由代码
|
||||
func registerSysCategoryRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
|
||||
r := v1.Group("/syscategory").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
r.GET("/:id", syscategory.GetSysCategory)
|
||||
r.POST("", syscategory.InsertSysCategory)
|
||||
r.PUT("", syscategory.UpdateSysCategory)
|
||||
r.DELETE("/:id", syscategory.DeleteSysCategory)
|
||||
}
|
||||
|
||||
l := v1.Group("").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
l.GET("/syscategoryList",syscategory.GetSysCategoryList)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/middleware"
|
||||
"go-admin/apis/syscontent"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
// 需认证的路由代码
|
||||
func registerSysContentRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
|
||||
r := v1.Group("/syscontent").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
r.GET("/:id", syscontent.GetSysContent)
|
||||
r.POST("", syscontent.InsertSysContent)
|
||||
r.PUT("", syscontent.UpdateSysContent)
|
||||
r.DELETE("/:id", syscontent.DeleteSysContent)
|
||||
}
|
||||
|
||||
l := v1.Group("").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
l.GET("/syscontentList",syscontent.GetSysContentList)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -102,6 +102,7 @@ func registerSysTableRouter(v1 *gin.RouterGroup) {
|
||||
tablesinfo.PUT("", UpdateSysTable)
|
||||
tablesinfo.DELETE("/:tableId", DeleteSysTables)
|
||||
tablesinfo.GET("/:tableId", GetSysTables)
|
||||
tablesinfo.GET("",GetSysTablesInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+78
-16
@@ -8,6 +8,17 @@
|
||||
{{- $x := .IsQuery -}}
|
||||
{{- if ($x) -}}
|
||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
||||
{{- if ne .FkTableName "" -}}
|
||||
<el-select v-model="form.{{.JsonField}}"
|
||||
placeholder="请选择" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
||||
<el-option
|
||||
v-for="dict in {{.JsonField}}Options"
|
||||
:key="dict.key"
|
||||
:label="dict.value"
|
||||
:value="dict.key"
|
||||
/>
|
||||
</el-select>
|
||||
{{- else -}}
|
||||
{{if eq .DictType "" -}}
|
||||
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable
|
||||
size="small" @keyup.enter.native="handleQuery"/>
|
||||
@@ -22,6 +33,7 @@
|
||||
/>
|
||||
</el-select>
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
</el-form-item>
|
||||
{{end}}
|
||||
{{- end }}
|
||||
@@ -71,6 +83,14 @@
|
||||
{{- range .Columns -}}
|
||||
{{- $x := .IsList -}}
|
||||
{{- if ($x) }}
|
||||
{{- if ne .FkTableName "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :formatter="{{.JsonField}}Format" width="100">
|
||||
<template slot-scope="scope">
|
||||
{{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
{{- else -}}
|
||||
{{- if ne .DictType "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
|
||||
:formatter="{{.JsonField}}Format" width="100">
|
||||
@@ -78,12 +98,14 @@
|
||||
{{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
{{- end -}}
|
||||
{{- if eq .DictType "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
|
||||
:show-overflow-tooltip="true"/>
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
@@ -134,6 +156,17 @@
|
||||
<el-input v-model="form.{{.JsonField}}" placeholder="{{.ColumnComment}}"
|
||||
{{if eq .IsEdit "false" -}}:disabled="isEdit" {{- end}}/>
|
||||
{{- else if eq "select" .HtmlType -}}
|
||||
{{- if ne .FkTableName "" -}}
|
||||
<el-select v-model="form.{{.JsonField}}"
|
||||
placeholder="请选择" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
||||
<el-option
|
||||
v-for="dict in {{.JsonField}}Options"
|
||||
:key="dict.key"
|
||||
:label="dict.value"
|
||||
:value="dict.key"
|
||||
/>
|
||||
</el-select>
|
||||
{{- else -}}
|
||||
<el-select v-model="form.{{.JsonField}}"
|
||||
placeholder="请选择" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
||||
<el-option
|
||||
@@ -143,6 +176,7 @@
|
||||
:value="dict.dictValue"
|
||||
/>
|
||||
</el-select>
|
||||
{{- end -}}
|
||||
{{- else if eq "radio" .HtmlType -}}
|
||||
<el-radio-group v-model="form.{{.JsonField}}">
|
||||
<el-radio
|
||||
@@ -182,6 +216,12 @@
|
||||
|
||||
<script>
|
||||
import {add{{.ClassName}}, del{{.ClassName}}, get{{.ClassName}}, list{{.ClassName}}, update{{.ClassName}}} from '@/api/{{ .PackageName}}'
|
||||
{{range .Columns}}
|
||||
{{- if ne .FkTableName "" -}}
|
||||
import {list{{.FkTableNameClass}} } from '@/api/{{ .FkTableNamePackage}}'
|
||||
|
||||
{{ end -}}
|
||||
{{- end -}}
|
||||
|
||||
export default {
|
||||
name: 'Config',
|
||||
@@ -210,23 +250,27 @@
|
||||
{{.JsonField}}Options: [],
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
// 关系表类型
|
||||
{{range .Columns}}
|
||||
{{- if ne .FkTableName "" -}}
|
||||
{{.JsonField}}Options :[],
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageIndex: 1,
|
||||
pageSize: 10,
|
||||
{{ range .Columns }}
|
||||
{{- if (.IsQuery) -}}
|
||||
{{.JsonField}}:
|
||||
undefined,
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
},
|
||||
// 表单参数
|
||||
form: {
|
||||
}
|
||||
,
|
||||
// 表单校验
|
||||
rules: {
|
||||
{{ range .Columns }}
|
||||
{{- if (.IsQuery) -}}
|
||||
{{.JsonField}}:undefined,
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
},
|
||||
// 表单参数
|
||||
form: {
|
||||
},
|
||||
// 表单校验
|
||||
rules: {
|
||||
{{- range .Columns -}}
|
||||
{{- $x := .IsQuery -}}
|
||||
{{- if ($x) -}}
|
||||
@@ -248,6 +292,10 @@
|
||||
this.{{.JsonField}}Options = response.data
|
||||
})
|
||||
|
||||
{{ end -}}
|
||||
{{- if ne .FkTableName "" -}}
|
||||
this.get{{.FkTableNameClass}}Items()
|
||||
|
||||
{{ end -}}
|
||||
{{- end -}}
|
||||
},
|
||||
@@ -292,8 +340,22 @@
|
||||
return this.selectDictLabel(this.{{.JsonField}}Options, row.{{.JsonField}})
|
||||
},
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
|
||||
{{- if ne .FkTableName "" -}}
|
||||
{{.JsonField}}Format(row) {
|
||||
return this.selectItemsLabel(this.{{.JsonField}}Options, row.{{.JsonField}})
|
||||
},
|
||||
{{ end -}}
|
||||
{{- end -}}
|
||||
// 关系
|
||||
{{range .Columns}}
|
||||
{{- if ne .FkTableName "" -}}
|
||||
get{{.FkTableNameClass}}Items() {
|
||||
this.getItems(list{{.FkTableNameClass}}, undefined).then(res => {
|
||||
this.{{.JsonField}}Options = this.setItems(res, '{{.FkLabelId}}', '{{.FkLabelName}}')
|
||||
})
|
||||
},
|
||||
{{ end -}}
|
||||
{{- end -}}
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageIndex = 1
|
||||
|
||||
Reference in new issue
Block a user