clear:formatting code
This commit is contained in:
1 parent
426cec1b62
commit
8c554d7ee7
52 files changed
+486
-502
No files matched your search
@@ -7,3 +7,4 @@ temp/
|
|||||||
vendor
|
vendor
|
||||||
config/settings.dev.yml
|
config/settings.dev.yml
|
||||||
go-admin
|
go-admin
|
||||||
|
middleware/demo.go
|
||||||
@@ -47,7 +47,6 @@ func ServerInfo(c *gin.Context) {
|
|||||||
cpuDic := make(map[string]interface{}, 0)
|
cpuDic := make(map[string]interface{}, 0)
|
||||||
cpuDic["cpuNum"], _ = cpu.Counts(false)
|
cpuDic["cpuNum"], _ = cpu.Counts(false)
|
||||||
|
|
||||||
|
|
||||||
app.Custum(c, gin.H{
|
app.Custum(c, gin.H{
|
||||||
"code": 200,
|
"code": 200,
|
||||||
"os": osDic,
|
"os": osDic,
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ func GetConfigByConfigKey(c *gin.Context) {
|
|||||||
result, err := Config.Get()
|
result, err := Config.Get()
|
||||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||||
|
|
||||||
app.OK(c, result,result.ConfigValue)
|
app.OK(c, result, result.ConfigValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 添加配置
|
// @Summary 添加配置
|
||||||
@@ -107,7 +107,7 @@ func InsertConfig(c *gin.Context) {
|
|||||||
result, err := data.Create()
|
result, err := data.Create()
|
||||||
tools.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
|
|
||||||
app.OK(c, result,"")
|
app.OK(c, result, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 修改配置
|
// @Summary 修改配置
|
||||||
@@ -127,7 +127,7 @@ func UpdateConfig(c *gin.Context) {
|
|||||||
data.UpdateBy = tools.GetUserIdStr(c)
|
data.UpdateBy = tools.GetUserIdStr(c)
|
||||||
result, err := data.Update(data.ConfigId)
|
result, err := data.Update(data.ConfigId)
|
||||||
tools.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
app.OK(c, result,"")
|
app.OK(c, result, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 删除配置
|
// @Summary 删除配置
|
||||||
@@ -145,5 +145,3 @@ func DeleteConfig(c *gin.Context) {
|
|||||||
tools.HasError(err, "修改失败", 500)
|
tools.HasError(err, "修改失败", 500)
|
||||||
app.OK(c, result, msg.DeletedSuccess)
|
app.OK(c, result, msg.DeletedSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
+8
-8
@@ -26,17 +26,17 @@ func GetDeptList(c *gin.Context) {
|
|||||||
Dept.DataScope = tools.GetUserIdStr(c)
|
Dept.DataScope = tools.GetUserIdStr(c)
|
||||||
result, err := Dept.SetDept(true)
|
result, err := Dept.SetDept(true)
|
||||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||||
app.OK(c,result,"")
|
app.OK(c, result, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDeptTree(c *gin.Context) {
|
func GetDeptTree(c *gin.Context) {
|
||||||
var Dept models.SysDept
|
var Dept models.SysDept
|
||||||
Dept.DeptName = c.Request.FormValue("deptName")
|
Dept.DeptName = c.Request.FormValue("deptName")
|
||||||
Dept.Status= c.Request.FormValue("status")
|
Dept.Status = c.Request.FormValue("status")
|
||||||
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
|
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
|
||||||
result, err := Dept.SetDept(false)
|
result, err := Dept.SetDept(false)
|
||||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||||
app.OK(c,result,"")
|
app.OK(c, result, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 部门列表数据
|
// @Summary 部门列表数据
|
||||||
@@ -53,7 +53,7 @@ func GetDept(c *gin.Context) {
|
|||||||
Dept.DataScope = tools.GetUserIdStr(c)
|
Dept.DataScope = tools.GetUserIdStr(c)
|
||||||
result, err := Dept.Get()
|
result, err := Dept.Get()
|
||||||
tools.HasError(err, msg.NotFound, 404)
|
tools.HasError(err, msg.NotFound, 404)
|
||||||
app.OK(c,result, msg.GetSuccess)
|
app.OK(c, result, msg.GetSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 添加部门
|
// @Summary 添加部门
|
||||||
@@ -73,7 +73,7 @@ func InsertDept(c *gin.Context) {
|
|||||||
data.CreateBy = tools.GetUserIdStr(c)
|
data.CreateBy = tools.GetUserIdStr(c)
|
||||||
result, err := data.Create()
|
result, err := data.Create()
|
||||||
tools.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
app.OK(c,result, msg.CreatedSuccess)
|
app.OK(c, result, msg.CreatedSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 修改部门
|
// @Summary 修改部门
|
||||||
@@ -94,7 +94,7 @@ func UpdateDept(c *gin.Context) {
|
|||||||
data.UpdateBy = tools.GetUserIdStr(c)
|
data.UpdateBy = tools.GetUserIdStr(c)
|
||||||
result, err := data.Update(data.DeptId)
|
result, err := data.Update(data.DeptId)
|
||||||
tools.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
app.OK(c,result, msg.UpdatedSuccess)
|
app.OK(c, result, msg.UpdatedSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 删除部门
|
// @Summary 删除部门
|
||||||
@@ -109,7 +109,7 @@ func DeleteDept(c *gin.Context) {
|
|||||||
id, err := tools.StringToInt(c.Param("id"))
|
id, err := tools.StringToInt(c.Param("id"))
|
||||||
_, err = data.Delete(id)
|
_, err = data.Delete(id)
|
||||||
tools.HasError(err, "删除失败", 500)
|
tools.HasError(err, "删除失败", 500)
|
||||||
app.OK(c,"", msg.DeletedSuccess)
|
app.OK(c, "", msg.DeletedSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDeptTreeRoleselect(c *gin.Context) {
|
func GetDeptTreeRoleselect(c *gin.Context) {
|
||||||
@@ -124,7 +124,7 @@ func GetDeptTreeRoleselect(c *gin.Context) {
|
|||||||
menuIds, err = SysRole.GetRoleDeptId()
|
menuIds, err = SysRole.GetRoleDeptId()
|
||||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||||
}
|
}
|
||||||
app.Custum(c,gin.H{
|
app.Custum(c, gin.H{
|
||||||
"code": 200,
|
"code": 200,
|
||||||
"depts": result,
|
"depts": result,
|
||||||
"checkedKeys": menuIds,
|
"checkedKeys": menuIds,
|
||||||
|
|||||||
@@ -148,5 +148,5 @@ func DeleteDictData(c *gin.Context) {
|
|||||||
IDS := tools.IdsStrToIdsIntGroup("dictCode", c)
|
IDS := tools.IdsStrToIdsIntGroup("dictCode", c)
|
||||||
result, err := data.BatchDelete(IDS)
|
result, err := data.BatchDelete(IDS)
|
||||||
tools.HasError(err, "修改失败", 500)
|
tools.HasError(err, "修改失败", 500)
|
||||||
app.OK(c,result,"删除成功")
|
app.OK(c, result, "删除成功")
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
import(
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,8 +33,7 @@ $(function(){
|
|||||||
</html>
|
</html>
|
||||||
`
|
`
|
||||||
|
|
||||||
|
func HelloWorld(c *gin.Context) {
|
||||||
func HelloWorld(c *gin.Context){
|
|
||||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||||
c.String(200, INDEX)
|
c.String(200, INDEX)
|
||||||
}
|
}
|
||||||
+4
-4
@@ -54,7 +54,7 @@ func GetPost(c *gin.Context) {
|
|||||||
Post.PostId, _ = tools.StringToInt(c.Param("postId"))
|
Post.PostId, _ = tools.StringToInt(c.Param("postId"))
|
||||||
result, err := Post.Get()
|
result, err := Post.Get()
|
||||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||||
app.OK(c,result,"")
|
app.OK(c, result, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 添加岗位
|
// @Summary 添加岗位
|
||||||
@@ -74,7 +74,7 @@ func InsertPost(c *gin.Context) {
|
|||||||
tools.HasError(err, "", 500)
|
tools.HasError(err, "", 500)
|
||||||
result, err := data.Create()
|
result, err := data.Create()
|
||||||
tools.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
app.OK(c,result,"")
|
app.OK(c, result, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 修改岗位
|
// @Summary 修改岗位
|
||||||
@@ -95,7 +95,7 @@ func UpdatePost(c *gin.Context) {
|
|||||||
tools.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
result, err := data.Update(data.PostId)
|
result, err := data.Update(data.PostId)
|
||||||
tools.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
app.OK(c,result,"修改成功")
|
app.OK(c, result, "修改成功")
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 删除岗位
|
// @Summary 删除岗位
|
||||||
@@ -111,5 +111,5 @@ func DeletePost(c *gin.Context) {
|
|||||||
IDS := tools.IdsStrToIdsIntGroup("postId", c)
|
IDS := tools.IdsStrToIdsIntGroup("postId", c)
|
||||||
result, err := data.BatchDelete(IDS)
|
result, err := data.BatchDelete(IDS)
|
||||||
tools.HasError(err, "删除失败", 500)
|
tools.HasError(err, "删除失败", 500)
|
||||||
app.OK(c,result,"删除成功")
|
app.OK(c, result, "删除成功")
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ func GetDBColumnList(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.TableName = c.Request.FormValue("tableName")
|
data.TableName = c.Request.FormValue("tableName")
|
||||||
tools2.Assert(data.TableName=="","table name cannot be empty!",500)
|
tools2.Assert(data.TableName == "", "table name cannot be empty!", 500)
|
||||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -73,8 +73,8 @@ func GenCode(c *gin.Context) {
|
|||||||
_ = tools2.PathCreate("./apis/" + tab.ModuleName + "/")
|
_ = tools2.PathCreate("./apis/" + tab.ModuleName + "/")
|
||||||
_ = tools2.PathCreate("./models/")
|
_ = tools2.PathCreate("./models/")
|
||||||
_ = tools2.PathCreate("./router/")
|
_ = tools2.PathCreate("./router/")
|
||||||
_ = tools2.PathCreate(config.GenConfig.FrontPath+"/api/")
|
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
|
||||||
_ = tools2.PathCreate(config.GenConfig.FrontPath+"/views/"+tab.PackageName)
|
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName)
|
||||||
|
|
||||||
var b1 bytes.Buffer
|
var b1 bytes.Buffer
|
||||||
err = t1.Execute(&b1, tab)
|
err = t1.Execute(&b1, tab)
|
||||||
@@ -92,15 +92,15 @@ func GenCode(c *gin.Context) {
|
|||||||
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js")
|
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js")
|
||||||
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue")
|
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue")
|
||||||
|
|
||||||
oldTest:="// {{认证路由自动补充在此处请勿删除}}"
|
oldTest := "// {{认证路由自动补充在此处请勿删除}}"
|
||||||
newText:="// {{认证路由自动补充在此处请勿删除}} \r\n register"+tab.ClassName+"Router(v1,authMiddleware)"
|
newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)"
|
||||||
|
|
||||||
helper := tools2.ReplaceHelper{
|
helper := tools2.ReplaceHelper{
|
||||||
Root: "./router/router.go",
|
Root: "./router/router.go",
|
||||||
OldText:oldTest,
|
OldText: oldTest,
|
||||||
NewText: newText,
|
NewText: newText,
|
||||||
}
|
}
|
||||||
if helper.OldText == helper.NewText{
|
if helper.OldText == helper.NewText {
|
||||||
log.Println("error !! the NewText isEqual the OldText")
|
log.Println("error !! the NewText isEqual the OldText")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-35
@@ -18,46 +18,46 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
configYml string
|
configYml string
|
||||||
port string
|
port string
|
||||||
mode string
|
mode string
|
||||||
StartCmd = &cobra.Command{
|
StartCmd = &cobra.Command{
|
||||||
Use: "server",
|
Use: "server",
|
||||||
Short: "Start API server",
|
Short: "Start API server",
|
||||||
Example: "go-admin server config/settings.yml",
|
Example: "go-admin server config/settings.yml",
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
usage()
|
usage()
|
||||||
setup()
|
setup()
|
||||||
},
|
},
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return run()
|
return run()
|
||||||
},
|
},
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file")
|
|
||||||
StartCmd.PersistentFlags().StringVarP(&port, "port", "p", "8000", "Tcp port server listening on")
|
|
||||||
StartCmd.PersistentFlags().StringVarP(&mode, "mode", "m", "dev", "server mode ; eg:dev,test,prod")
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func usage() {
|
func init() {
|
||||||
usageStr := `starting api server`
|
StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file")
|
||||||
log.Printf("%s\n", usageStr)
|
StartCmd.PersistentFlags().StringVarP(&port, "port", "p", "8000", "Tcp port server listening on")
|
||||||
}
|
StartCmd.PersistentFlags().StringVarP(&mode, "mode", "m", "dev", "server mode ; eg:dev,test,prod")
|
||||||
|
}
|
||||||
|
|
||||||
func setup() {
|
func usage() {
|
||||||
//1. 读取配置
|
usageStr := `starting api server`
|
||||||
config.ConfigSetup(configYml)
|
log.Printf("%s\n", usageStr)
|
||||||
//2. 设置日志
|
}
|
||||||
tools.InitLogger()
|
|
||||||
//3. 初始化数据库链接
|
|
||||||
database.Setup(config.DatabaseConfig.Driver)
|
|
||||||
|
|
||||||
mycasbin.Setup()
|
func setup() {
|
||||||
|
//1. 读取配置
|
||||||
|
config.ConfigSetup(configYml)
|
||||||
|
//2. 设置日志
|
||||||
|
tools.InitLogger()
|
||||||
|
//3. 初始化数据库链接
|
||||||
|
database.Setup(config.DatabaseConfig.Driver)
|
||||||
|
|
||||||
|
mycasbin.Setup()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
|
|
||||||
func Setup(driver string) {
|
func Setup(driver string) {
|
||||||
dbType := driver
|
dbType := driver
|
||||||
if dbType == "mysql" {
|
if dbType == "mysql" {
|
||||||
|
|||||||
@@ -47,4 +47,4 @@ func (e *SqLite) GetConnect() string {
|
|||||||
|
|
||||||
func (e *SqLite) GetDriver() string {
|
func (e *SqLite) GetDriver() string {
|
||||||
return config.DatabaseConfig.Driver
|
return config.DatabaseConfig.Driver
|
||||||
}
|
}
|
||||||
+2
-2
@@ -19,6 +19,6 @@ var CasbinEnforcer *casbin.Enforcer
|
|||||||
// go-admin Version Info
|
// go-admin Version Info
|
||||||
var Version string
|
var Version string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Version = "1.0.10"
|
Version = "1.0.10"
|
||||||
}
|
}
|
||||||
+2
-4
@@ -6,9 +6,7 @@ import (
|
|||||||
|
|
||||||
var RequestLogger = &logrus.Entry{}
|
var RequestLogger = &logrus.Entry{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
func init() {
|
|
||||||
// TODO: requestLogger log format
|
// TODO: requestLogger log format
|
||||||
// RequestLogger = logrus.WithFields(logrus.Fields{"request_id": request_id, "user_ip": user_ip})
|
// RequestLogger = logrus.WithFields(logrus.Fields{"request_id": request_id, "user_ip": user_ip})
|
||||||
}
|
}
|
||||||
+1
-1
@@ -8,4 +8,4 @@ func Ping(c *gin.Context) {
|
|||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"message": "ok",
|
"message": "ok",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
+12
-13
@@ -75,12 +75,12 @@ func DiskCheck(c *gin.Context) {
|
|||||||
func OSCheck(c *gin.Context) {
|
func OSCheck(c *gin.Context) {
|
||||||
status := http.StatusOK
|
status := http.StatusOK
|
||||||
app.Custum(c, gin.H{
|
app.Custum(c, gin.H{
|
||||||
"code": 200,
|
"code": 200,
|
||||||
"status": status,
|
"status": status,
|
||||||
"goOs": runtime.GOOS,
|
"goOs": runtime.GOOS,
|
||||||
"compiler": runtime.Compiler,
|
"compiler": runtime.Compiler,
|
||||||
"numCpu": runtime.NumCPU(),
|
"numCpu": runtime.NumCPU(),
|
||||||
"version": runtime.Version(),
|
"version": runtime.Version(),
|
||||||
"numGoroutine": runtime.NumGoroutine(),
|
"numGoroutine": runtime.NumGoroutine(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -153,13 +153,12 @@ func RAMCheck(c *gin.Context) {
|
|||||||
text = "WARNING"
|
text = "WARNING"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
app.Custum(c, gin.H{
|
app.Custum(c, gin.H{
|
||||||
"code": 200,
|
"code": 200,
|
||||||
"msg": text,
|
"msg": text,
|
||||||
"status": status,
|
"status": status,
|
||||||
"used": usedMB,
|
"used": usedMB,
|
||||||
"total": totalMB,
|
"total": totalMB,
|
||||||
"usedPercent": usedPercent,
|
"usedPercent": usedPercent,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
+12
-12
@@ -8,18 +8,18 @@ import (
|
|||||||
|
|
||||||
type DictData struct {
|
type DictData struct {
|
||||||
DictCode int `gorm:"primary_key;AUTO_INCREMENT" json:"dictCode" example:"1"` //字典编码
|
DictCode int `gorm:"primary_key;AUTO_INCREMENT" json:"dictCode" example:"1"` //字典编码
|
||||||
DictSort int `gorm:"" json:"dictSort"` //显示顺序
|
DictSort int `gorm:"" json:"dictSort"` //显示顺序
|
||||||
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
|
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
|
||||||
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
|
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
|
||||||
DictType string `gorm:"size:64;" json:"dictType"` //字典类型
|
DictType string `gorm:"size:64;" json:"dictType"` //字典类型
|
||||||
CssClass string `gorm:"size:128;" json:"cssClass"` //
|
CssClass string `gorm:"size:128;" json:"cssClass"` //
|
||||||
ListClass string `gorm:"size:128;" json:"listClass"` //
|
ListClass string `gorm:"size:128;" json:"listClass"` //
|
||||||
IsDefault string `gorm:"size:8;" json:"isDefault"` //
|
IsDefault string `gorm:"size:8;" json:"isDefault"` //
|
||||||
Status string `gorm:"size:4;" json:"status"` //状态
|
Status string `gorm:"size:4;" json:"status"` //状态
|
||||||
Default string `gorm:"size:8;" json:"default"` //
|
Default string `gorm:"size:8;" json:"default"` //
|
||||||
CreateBy string `gorm:"size:64;" json:"createBy"` //
|
CreateBy string `gorm:"size:64;" json:"createBy"` //
|
||||||
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
|
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
|
||||||
Remark string `gorm:"size:255;" json:"remark"` //备注
|
Remark string `gorm:"size:255;" json:"remark"` //备注
|
||||||
Params string `gorm:"-" json:"params"`
|
Params string `gorm:"-" json:"params"`
|
||||||
DataScope string `gorm:"-" json:"dataScope"`
|
DataScope string `gorm:"-" json:"dataScope"`
|
||||||
BaseModel
|
BaseModel
|
||||||
|
|||||||
+3
-3
@@ -10,9 +10,9 @@ type DictType struct {
|
|||||||
DictId int `gorm:"primary_key;AUTO_INCREMENT" json:"dictId"`
|
DictId int `gorm:"primary_key;AUTO_INCREMENT" json:"dictId"`
|
||||||
DictName string `gorm:"size:128;" json:"dictName"` //字典名称
|
DictName string `gorm:"size:128;" json:"dictName"` //字典名称
|
||||||
DictType string `gorm:"size:128;" json:"dictType"` //字典类型
|
DictType string `gorm:"size:128;" json:"dictType"` //字典类型
|
||||||
Status string `gorm:"size:4;" json:"status"` //状态
|
Status string `gorm:"size:4;" json:"status"` //状态
|
||||||
DataScope string `gorm:"-" json:"dataScope"` //
|
DataScope string `gorm:"-" json:"dataScope"` //
|
||||||
Params string `gorm:"-" json:"params"` //
|
Params string `gorm:"-" json:"params"` //
|
||||||
CreateBy string `gorm:"size:11;" json:"createBy"` //创建者
|
CreateBy string `gorm:"size:11;" json:"createBy"` //创建者
|
||||||
UpdateBy string `gorm:"size:11;" json:"updateBy"` //更新者
|
UpdateBy string `gorm:"size:11;" json:"updateBy"` //更新者
|
||||||
Remark string `gorm:"size:255;" json:"remark"` //备注
|
Remark string `gorm:"size:255;" json:"remark"` //备注
|
||||||
|
|||||||
+10
-10
@@ -7,19 +7,19 @@ import (
|
|||||||
|
|
||||||
type LoginLog struct {
|
type LoginLog struct {
|
||||||
InfoId int `json:"infoId" gorm:"primary_key;AUTO_INCREMENT"` //主键
|
InfoId int `json:"infoId" gorm:"primary_key;AUTO_INCREMENT"` //主键
|
||||||
Username string `json:"username" gorm:"size:128;"` //用户名
|
Username string `json:"username" gorm:"size:128;"` //用户名
|
||||||
Status string `json:"status" gorm:"size:4;"` //状态
|
Status string `json:"status" gorm:"size:4;"` //状态
|
||||||
Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址
|
Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址
|
||||||
LoginLocation string `json:"loginLocation" gorm:"size:255;"` //归属地
|
LoginLocation string `json:"loginLocation" gorm:"size:255;"` //归属地
|
||||||
Browser string `json:"browser" gorm:"size:255;"` //浏览器
|
Browser string `json:"browser" gorm:"size:255;"` //浏览器
|
||||||
Os string `json:"os" gorm:"size:255;"` //系统
|
Os string `json:"os" gorm:"size:255;"` //系统
|
||||||
Platform string `json:"platform" gorm:"size:255;"` // 固件
|
Platform string `json:"platform" gorm:"size:255;"` // 固件
|
||||||
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;"` //登录时间
|
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;"` //登录时间
|
||||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
||||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
||||||
DataScope string `json:"dataScope" gorm:"-"` //数据
|
DataScope string `json:"dataScope" gorm:"-"` //数据
|
||||||
Params string `json:"params" gorm:"-"` //
|
Params string `json:"params" gorm:"-"` //
|
||||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||||
Msg string `json:"msg" gorm:"size:255;"`
|
Msg string `json:"msg" gorm:"size:255;"`
|
||||||
BaseModel
|
BaseModel
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BaseModel struct {
|
type BaseModel struct {
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
DeletedAt *time.Time `json:"deletedAt"`
|
DeletedAt *time.Time `json:"deletedAt"`
|
||||||
}
|
}
|
||||||
+21
-21
@@ -8,28 +8,28 @@ import (
|
|||||||
//sys_operlog
|
//sys_operlog
|
||||||
type SysOperLog struct {
|
type SysOperLog struct {
|
||||||
OperId int `json:"operId" gorm:"primary_key;AUTO_INCREMENT"` //日志编码
|
OperId int `json:"operId" gorm:"primary_key;AUTO_INCREMENT"` //日志编码
|
||||||
Title string `json:"title" gorm:"size:255;"` //操作模块
|
Title string `json:"title" gorm:"size:255;"` //操作模块
|
||||||
BusinessType string `json:"businessType" gorm:"size:128;"` //操作类型
|
BusinessType string `json:"businessType" gorm:"size:128;"` //操作类型
|
||||||
BusinessTypes string `json:"businessTypes" gorm:"size:128;"`
|
BusinessTypes string `json:"businessTypes" gorm:"size:128;"`
|
||||||
Method string `json:"method" gorm:"size:128;"` //函数
|
Method string `json:"method" gorm:"size:128;"` //函数
|
||||||
RequestMethod string `json:"requestMethod" gorm:"size:128;"` //请求方式
|
RequestMethod string `json:"requestMethod" gorm:"size:128;"` //请求方式
|
||||||
OperatorType string `json:"operatorType" gorm:"size:128;"` //操作类型
|
OperatorType string `json:"operatorType" gorm:"size:128;"` //操作类型
|
||||||
OperName string `json:"operName" gorm:"size:128;"` //操作者
|
OperName string `json:"operName" gorm:"size:128;"` //操作者
|
||||||
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
|
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
|
||||||
OperUrl string `json:"operUrl" gorm:"size:255;"` //访问地址
|
OperUrl string `json:"operUrl" gorm:"size:255;"` //访问地址
|
||||||
OperIp string `json:"operIp" gorm:"size:128;"` //客户端ip
|
OperIp string `json:"operIp" gorm:"size:128;"` //客户端ip
|
||||||
OperLocation string `json:"operLocation" gorm:"size:128;"` //访问位置
|
OperLocation string `json:"operLocation" gorm:"size:128;"` //访问位置
|
||||||
OperParam string `json:"operParam" gorm:"size:255;"` //请求参数
|
OperParam string `json:"operParam" gorm:"size:255;"` //请求参数
|
||||||
Status string `json:"status" gorm:"size:4;"` //操作状态
|
Status string `json:"status" gorm:"size:4;"` //操作状态
|
||||||
OperTime time.Time `json:"operTime" gorm:"type:timestamp;"` //操作时间
|
OperTime time.Time `json:"operTime" gorm:"type:timestamp;"` //操作时间
|
||||||
JsonResult string `json:"jsonResult" gorm:"size:255;"` //返回数据
|
JsonResult string `json:"jsonResult" gorm:"size:255;"` //返回数据
|
||||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
||||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
||||||
DataScope string `json:"dataScope" gorm:"-"` //数据
|
DataScope string `json:"dataScope" gorm:"-"` //数据
|
||||||
Params string `json:"params" gorm:"-"` //参数
|
Params string `json:"params" gorm:"-"` //参数
|
||||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||||
LatencyTime string `json:"latencyime" gorm:"size:128;"` //耗时
|
LatencyTime string `json:"latencyime" gorm:"size:128;"` //耗时
|
||||||
UserAgent string `json:"userAgent" gorm:"size:255;"` //ua
|
UserAgent string `json:"userAgent" gorm:"size:255;"` //ua
|
||||||
BaseModel
|
BaseModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -7,11 +7,11 @@ import (
|
|||||||
|
|
||||||
type Post struct {
|
type Post struct {
|
||||||
PostId int `gorm:"primary_key;AUTO_INCREMENT" json:"postId"` //岗位编号
|
PostId int `gorm:"primary_key;AUTO_INCREMENT" json:"postId"` //岗位编号
|
||||||
PostName string `gorm:"size:128;" json:"postName"` //岗位名称
|
PostName string `gorm:"size:128;" json:"postName"` //岗位名称
|
||||||
PostCode string `gorm:"size:128;" json:"postCode"` //岗位代码
|
PostCode string `gorm:"size:128;" json:"postCode"` //岗位代码
|
||||||
Sort int `gorm:"" json:"sort"` //岗位排序
|
Sort int `gorm:"" json:"sort"` //岗位排序
|
||||||
Status string `gorm:"size:4;" json:"status"` //状态
|
Status string `gorm:"size:4;" json:"status"` //状态
|
||||||
Remark string `gorm:"size:255;" json:"remark"` //描述
|
Remark string `gorm:"size:255;" json:"remark"` //描述
|
||||||
CreateBy string `gorm:"size:128;" json:"createBy"`
|
CreateBy string `gorm:"size:128;" json:"createBy"`
|
||||||
UpdateBy string `gorm:"size:128;" json:"updateBy"`
|
UpdateBy string `gorm:"size:128;" json:"updateBy"`
|
||||||
DataScope string `gorm:"-" json:"dataScope"`
|
DataScope string `gorm:"-" json:"dataScope"`
|
||||||
|
|||||||
+9
-9
@@ -8,14 +8,14 @@ import (
|
|||||||
|
|
||||||
type SysRole struct {
|
type SysRole struct {
|
||||||
RoleId int `json:"roleId" gorm:"primary_key;AUTO_INCREMENT"` // 角色编码
|
RoleId int `json:"roleId" gorm:"primary_key;AUTO_INCREMENT"` // 角色编码
|
||||||
RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称
|
RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称
|
||||||
Status string `json:"status" gorm:"size:4;"` //
|
Status string `json:"status" gorm:"size:4;"` //
|
||||||
RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码
|
RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码
|
||||||
RoleSort int `json:"roleSort" gorm:""` //角色排序
|
RoleSort int `json:"roleSort" gorm:""` //角色排序
|
||||||
Flag string `json:"flag" gorm:"size:128;"` //
|
Flag string `json:"flag" gorm:"size:128;"` //
|
||||||
CreateBy string `json:"createBy" gorm:"size:128;"` //
|
CreateBy string `json:"createBy" gorm:"size:128;"` //
|
||||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //
|
UpdateBy string `json:"updateBy" gorm:"size:128;"` //
|
||||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
Remark string `json:"remark" gorm:"size:255;"` //备注
|
||||||
Admin bool `json:"admin" gorm:"size:4;"`
|
Admin bool `json:"admin" gorm:"size:4;"`
|
||||||
DataScope string `json:"dataScope" gorm:"size:128;"`
|
DataScope string `json:"dataScope" gorm:"size:128;"`
|
||||||
Params string `json:"params" gorm:"-"`
|
Params string `json:"params" gorm:"-"`
|
||||||
@@ -52,7 +52,7 @@ func (role *SysRole) GetPage(pageSize int, pageIndex int) ([]SysRole, int, error
|
|||||||
// 数据权限控制
|
// 数据权限控制
|
||||||
dataPermission := new(DataPermission)
|
dataPermission := new(DataPermission)
|
||||||
dataPermission.UserId, _ = tools.StringToInt(role.DataScope)
|
dataPermission.UserId, _ = tools.StringToInt(role.DataScope)
|
||||||
table,err := dataPermission.GetDataScope("sys_role", table)
|
table, err := dataPermission.GetDataScope("sys_role", table)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -42,13 +42,13 @@ type SysUserId struct {
|
|||||||
type SysUserB struct {
|
type SysUserB struct {
|
||||||
NickName string `gorm:"size:128" json:"nickName"` // 昵称
|
NickName string `gorm:"size:128" json:"nickName"` // 昵称
|
||||||
Phone string `gorm:"size:11" json:"phone"` // 手机号
|
Phone string `gorm:"size:11" json:"phone"` // 手机号
|
||||||
RoleId int `gorm:"" json:"roleId"` // 角色编码
|
RoleId int `gorm:"" json:"roleId"` // 角色编码
|
||||||
Salt string `gorm:"size:255" json:"salt"` //盐
|
Salt string `gorm:"size:255" json:"salt"` //盐
|
||||||
Avatar string `gorm:"size:255" json:"avatar"` //头像
|
Avatar string `gorm:"size:255" json:"avatar"` //头像
|
||||||
Sex string `gorm:"size:255" json:"sex"` //性别
|
Sex string `gorm:"size:255" json:"sex"` //性别
|
||||||
Email string `gorm:"size:128" json:"email"` //邮箱
|
Email string `gorm:"size:128" json:"email"` //邮箱
|
||||||
DeptId int `gorm:"" json:"deptId"` //部门编码
|
DeptId int `gorm:"" json:"deptId"` //部门编码
|
||||||
PostId int `gorm:"" json:"postId"` //职位编码
|
PostId int `gorm:"" json:"postId"` //职位编码
|
||||||
CreateBy string `gorm:"size:128" json:"createBy"` //
|
CreateBy string `gorm:"size:128" json:"createBy"` //
|
||||||
UpdateBy string `gorm:"size:128" json:"updateBy"` //
|
UpdateBy string `gorm:"size:128" json:"updateBy"` //
|
||||||
Remark string `gorm:"size:255" json:"remark"` //备注
|
Remark string `gorm:"size:255" json:"remark"` //备注
|
||||||
@@ -59,7 +59,6 @@ type SysUserB struct {
|
|||||||
BaseModel
|
BaseModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type SysUser struct {
|
type SysUser struct {
|
||||||
SysUserId
|
SysUserId
|
||||||
SysUserB
|
SysUserB
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SysColumns struct {
|
type SysColumns struct {
|
||||||
ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"`
|
ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"`
|
||||||
TableId int `gorm:"" json:"tableId"`
|
TableId int `gorm:"" json:"tableId"`
|
||||||
ColumnName string `gorm:"size:128;" json:"columnName"`
|
ColumnName string `gorm:"size:128;" json:"columnName"`
|
||||||
ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
|
ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
|
||||||
ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
|
ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SysTables struct {
|
type SysTables struct {
|
||||||
TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码
|
TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码
|
||||||
TBName string `gorm:"column:table_name;size:255;" json:"tableName"` //表名称
|
TBName string `gorm:"column:table_name;size:255;" json:"tableName"` //表名称
|
||||||
TableComment string `gorm:"size:255;" json:"tableComment"` //表备注
|
TableComment string `gorm:"size:255;" json:"tableComment"` //表备注
|
||||||
ClassName string `gorm:"size:255;" json:"className"` //类名
|
ClassName string `gorm:"size:255;" json:"className"` //类名
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ e = some(where (p.eft == allow))
|
|||||||
m = r.sub == p.sub && (keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj)) && (r.act == p.act || p.act == "*")
|
m = r.sub == p.sub && (keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj)) && (r.act == p.act || p.act == "*")
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func Setup() {
|
func Setup() {
|
||||||
Apter, err := gormAdapter.NewAdapterByDB(global.Eloquent)
|
Apter, err := gormAdapter.NewAdapterByDB(global.Eloquent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Info *log.Logger
|
Info *log.Logger
|
||||||
Warning *log.Logger
|
Warning *log.Logger
|
||||||
Error * log.Logger
|
Error *log.Logger
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
+1
-6
@@ -7,8 +7,6 @@ import (
|
|||||||
jwt "go-admin/pkg/jwtauth"
|
jwt "go-admin/pkg/jwtauth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 路由示例
|
// 路由示例
|
||||||
func InitExamplesRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.Engine {
|
func InitExamplesRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.Engine {
|
||||||
|
|
||||||
@@ -32,10 +30,7 @@ func examplesNoCheckRoleRouter(r *gin.Engine) {
|
|||||||
// 需要认证的路由示例
|
// 需要认证的路由示例
|
||||||
func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) {
|
func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) {
|
||||||
v1 := r.Group("/api/v1")
|
v1 := r.Group("/api/v1")
|
||||||
v1.GET("/checkrole",nil)
|
v1.GET("/checkrole", nil)
|
||||||
|
|
||||||
// {{认证路由自动补充在此处请勿删除}}
|
// {{认证路由自动补充在此处请勿删除}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+68
-68
@@ -7,119 +7,119 @@ _ "time"
|
|||||||
)
|
)
|
||||||
|
|
||||||
type {{.ClassName}} struct {
|
type {{.ClassName}} struct {
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$x := .Pk}}
|
{{$x := .Pk}}
|
||||||
{{- if ($x) }}
|
{{- if ($x) }}
|
||||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"` // {{.ColumnComment}}
|
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"` // {{.ColumnComment}}
|
||||||
{{- else if eq .GoField "CreatedAt" -}}
|
{{- else if eq .GoField "CreatedAt" -}}
|
||||||
{{- else if eq .GoField "UpdatedAt" -}}
|
{{- else if eq .GoField "UpdatedAt" -}}
|
||||||
{{- else if eq .GoField "DeletedAt" -}}
|
{{- else if eq .GoField "DeletedAt" -}}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"` // {{.ColumnComment}}{{end -}}
|
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"` // {{.ColumnComment}}{{end -}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
DataScope string `json:"dataScope" gorm:"-"`
|
DataScope string `json:"dataScope" gorm:"-"`
|
||||||
Params string `json:"params" gorm:"-"`
|
Params string `json:"params" gorm:"-"`
|
||||||
BaseModel
|
BaseModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func ({{.ClassName}}) TableName() string {
|
func ({{.ClassName}}) TableName() string {
|
||||||
return "{{.TBName}}"
|
return "{{.TBName}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建{{.ClassName}}
|
// 创建{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
|
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
|
||||||
var doc {{.ClassName}}
|
var doc {{.ClassName}}
|
||||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
err := result.Error
|
err := result.Error
|
||||||
return doc, err
|
return doc, err
|
||||||
}
|
}
|
||||||
doc = *e
|
doc = *e
|
||||||
return doc, nil
|
return doc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 获取{{.ClassName}}
|
// 获取{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
||||||
var doc {{.ClassName}}
|
var doc {{.ClassName}}
|
||||||
table := orm.Eloquent.Table(e.TableName())
|
table := orm.Eloquent.Table(e.TableName())
|
||||||
{{ range .Columns }}
|
{{ range .Columns }}
|
||||||
{{$x := .Pk}}
|
{{$x := .Pk}}
|
||||||
{{- if ($x) }}
|
{{- if ($x) }}
|
||||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||||
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
|
||||||
}
|
|
||||||
{{- else if .IsQuery }}
|
|
||||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
|
||||||
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
||||||
}
|
}
|
||||||
|
{{- else if .IsQuery }}
|
||||||
|
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||||
|
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
||||||
|
}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
if err := table.First(&doc).Error; err != nil {
|
if err := table.First(&doc).Error; err != nil {
|
||||||
return doc, err
|
return doc, err
|
||||||
}
|
}
|
||||||
return doc, nil
|
return doc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取{{.ClassName}}带分页
|
// 获取{{.ClassName}}带分页
|
||||||
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int, error) {
|
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int, error) {
|
||||||
var doc []{{.ClassName}}
|
var doc []{{.ClassName}}
|
||||||
|
|
||||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||||
{{ range .Columns }}
|
{{ range .Columns }}
|
||||||
{{- if .IsQuery }}
|
{{- if .IsQuery }}
|
||||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||||
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
||||||
}
|
}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||||
dataPermission := new(DataPermission)
|
dataPermission := new(DataPermission)
|
||||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||||
table,err := dataPermission.GetDataScope(e.TableName(), table)
|
table,err := dataPermission.GetDataScope(e.TableName(), table)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
var count int
|
var count int
|
||||||
|
|
||||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||||
return doc, count, nil
|
return doc, count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新{{.ClassName}}
|
// 更新{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
|
func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
|
||||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//参数1:是要修改的数据
|
//参数1:是要修改的数据
|
||||||
//参数2:是修改的数据
|
//参数2:是修改的数据
|
||||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除{{.ClassName}}
|
// 删除{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
|
func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
|
||||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||||
success = false
|
success = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
success = true
|
success = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//批量删除
|
//批量删除
|
||||||
func (e *{{.ClassName}}) BatchDelete(id []int) (Result bool, err error) {
|
func (e *{{.ClassName}}) BatchDelete(id []int) (Result bool, err error) {
|
||||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Result = true
|
Result = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"go-admin/middleware"
|
"go-admin/middleware"
|
||||||
"go-admin/apis/{{.ModuleName}}"
|
"go-admin/apis/{{.ModuleName}}"
|
||||||
jwt "go-admin/pkg/jwtauth"
|
jwt "go-admin/pkg/jwtauth"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 需认证的路由代码
|
// 需认证的路由代码
|
||||||
|
|||||||
+109
-93
@@ -3,23 +3,25 @@
|
|||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
|
<el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
|
||||||
{{range .Columns}}
|
{{range .Columns}}
|
||||||
{{- $x := .IsQuery -}}
|
{{- $x := .IsQuery -}}
|
||||||
{{- if ($x) -}}
|
{{- if ($x) -}}
|
||||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
||||||
{{if eq .DictType "" -}}
|
{{if eq .DictType "" -}}
|
||||||
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable size="small" @keyup.enter.native="handleQuery" />
|
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable
|
||||||
{{- else -}}
|
size="small" @keyup.enter.native="handleQuery"/>
|
||||||
<el-select v-model="queryParams.{{.JsonField}}" placeholder="{{$tableComment}}{{.ColumnComment}}" clearable size="small">
|
{{- else -}}
|
||||||
<el-option
|
<el-select v-model="queryParams.{{.JsonField}}"
|
||||||
v-for="dict in {{.JsonField}}Options"
|
placeholder="{{$tableComment}}{{.ColumnComment}}" clearable size="small">
|
||||||
:key="dict.dictValue"
|
<el-option
|
||||||
:label="dict.dictLabel"
|
v-for="dict in {{.JsonField}}Options"
|
||||||
:value="dict.dictValue"
|
:key="dict.dictValue"
|
||||||
/>
|
:label="dict.dictLabel"
|
||||||
</el-select>
|
:value="dict.dictValue"
|
||||||
{{- end}}
|
/>
|
||||||
</el-form-item>
|
</el-select>
|
||||||
{{end}}
|
{{- end}}
|
||||||
|
</el-form-item>
|
||||||
|
{{end}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||||
@@ -35,7 +37,8 @@
|
|||||||
icon="el-icon-plus"
|
icon="el-icon-plus"
|
||||||
size="mini"
|
size="mini"
|
||||||
@click="handleAdd"
|
@click="handleAdd"
|
||||||
>新增</el-button>
|
>新增
|
||||||
|
</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button
|
<el-button
|
||||||
@@ -45,7 +48,8 @@
|
|||||||
size="mini"
|
size="mini"
|
||||||
:disabled="single"
|
:disabled="single"
|
||||||
@click="handleUpdate"
|
@click="handleUpdate"
|
||||||
>修改</el-button>
|
>修改
|
||||||
|
</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button
|
<el-button
|
||||||
@@ -55,27 +59,30 @@
|
|||||||
size="mini"
|
size="mini"
|
||||||
:disabled="multiple"
|
:disabled="multiple"
|
||||||
@click="handleDelete"
|
@click="handleDelete"
|
||||||
>删除</el-button>
|
>删除
|
||||||
|
</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="{{.ModuleName}}List" @selection-change="handleSelectionChange">
|
<el-table v-loading="loading" :data="{{.ModuleName}}List" @selection-change="handleSelectionChange">
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column type="selection" width="55" align="center"/>
|
||||||
{{- range .Columns -}}
|
{{- range .Columns -}}
|
||||||
{{- $x := .IsList -}}
|
{{- $x := .IsList -}}
|
||||||
{{- if ($x) }}
|
{{- if ($x) }}
|
||||||
{{- if ne .DictType "" -}}
|
{{- if ne .DictType "" -}}
|
||||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :formatter="{{.JsonField}}Format" width="100">
|
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
|
||||||
<template slot-scope="scope">
|
:formatter="{{.JsonField}}Format" width="100">
|
||||||
{{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
|
<template slot-scope="scope">
|
||||||
</template>
|
{{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
|
||||||
</el-table-column>
|
</template>
|
||||||
{{- end -}}
|
</el-table-column>
|
||||||
{{- if eq .DictType "" -}}
|
{{- end -}}
|
||||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :show-overflow-tooltip="true" />
|
{{- if eq .DictType "" -}}
|
||||||
{{- end -}}
|
<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">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
@@ -85,14 +92,16 @@
|
|||||||
type="text"
|
type="text"
|
||||||
icon="el-icon-edit"
|
icon="el-icon-edit"
|
||||||
@click="handleUpdate(scope.row)"
|
@click="handleUpdate(scope.row)"
|
||||||
>修改</el-button>
|
>修改
|
||||||
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-permisaction="['{{.PackageName}}:{{.ModuleName}}:remove']"
|
v-permisaction="['{{.PackageName}}:{{.ModuleName}}:remove']"
|
||||||
size="mini"
|
size="mini"
|
||||||
type="text"
|
type="text"
|
||||||
icon="el-icon-delete"
|
icon="el-icon-delete"
|
||||||
@click="handleDelete(scope.row)"
|
@click="handleDelete(scope.row)"
|
||||||
>删除</el-button>
|
>删除
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -109,36 +118,38 @@
|
|||||||
<el-dialog :title="title" :visible.sync="open" width="500px">
|
<el-dialog :title="title" :visible.sync="open" width="500px">
|
||||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||||
{{ range .Columns }}
|
{{ range .Columns }}
|
||||||
{{- $x := .IsInsert -}}
|
{{- $x := .IsInsert -}}
|
||||||
{{- if ($x) -}}
|
{{- if ($x) -}}
|
||||||
{{- if (.Pk) }}
|
{{- if (.Pk) }}
|
||||||
{{- else if eq .GoField "CreatedAt" -}}
|
{{- else if eq .GoField "CreatedAt" -}}
|
||||||
{{- else if eq .GoField "UpdatedAt" -}}
|
{{- else if eq .GoField "UpdatedAt" -}}
|
||||||
{{- else if eq .GoField "DeletedAt" -}}
|
{{- else if eq .GoField "DeletedAt" -}}
|
||||||
{{- else if eq .GoField "UpdateBy" -}}
|
{{- else if eq .GoField "UpdateBy" -}}
|
||||||
{{- else if eq .GoField "CreateBy" -}}
|
{{- else if eq .GoField "CreateBy" -}}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}" >
|
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
||||||
{{ if eq "input" .HtmlType -}}
|
{{ if eq "input" .HtmlType -}}
|
||||||
<el-input v-model="form.{{.JsonField}}" placeholder="{{.ColumnComment}}" {{if eq .IsEdit "false" -}}:disabled="isEdit" {{- end}}/>
|
<el-input v-model="form.{{.JsonField}}" placeholder="{{.ColumnComment}}"
|
||||||
{{- else if eq "select" .HtmlType -}}
|
{{if eq .IsEdit "false" -}}:disabled="isEdit" {{- end}}/>
|
||||||
<el-select v-model="form.{{.JsonField}}" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
{{- else if eq "select" .HtmlType -}}
|
||||||
<el-option label="demo1" value="demo1" />
|
<el-select
|
||||||
<el-option label="demo2" value="demo2" />
|
v-model="form.{{.JsonField}}" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
||||||
</el-select>
|
<el-option label="demo1" value="demo1"/>
|
||||||
{{- else if eq "radio" .HtmlType -}}
|
<el-option label="demo2" value="demo2"/>
|
||||||
<el-radio-group v-model="form.{{.JsonField}}">
|
</el-select>
|
||||||
<el-radio
|
{{- else if eq "radio" .HtmlType -}}
|
||||||
v-for="dict in {{.JsonField}}Options"
|
<el-radio-group v-model="form.{{.JsonField}}">
|
||||||
:key="dict.dictValue"
|
<el-radio
|
||||||
:label="dict.dictValue"
|
v-for="dict in {{.JsonField}}Options"
|
||||||
>{{"{{"}} dict.dictLabel {{"}}"}}</el-radio>
|
:key="dict.dictValue"
|
||||||
</el-radio-group>
|
:label="dict.dictValue"
|
||||||
{{- end }}
|
>{{"{{"}} dict.dictLabel {{"}}"}}</el-radio>
|
||||||
</el-form-item>
|
</el-radio-group>
|
||||||
|
{{- end }}
|
||||||
|
</el-form-item>
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
|
||||||
</el-form>
|
</el-form>
|
||||||
<div slot="footer" class="dialog-footer">
|
<div slot="footer" class="dialog-footer">
|
||||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||||
@@ -149,7 +160,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { list{{.ClassName}}, get{{.ClassName}}, del{{.ClassName}}, add{{.ClassName}}, update{{.ClassName}} } from '@/api/{{.PackageName}}'
|
import {add, del, get, list, update} from '@/api/'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Config',
|
name: 'Config',
|
||||||
@@ -172,7 +183,7 @@
|
|||||||
isEdit: false,
|
isEdit: false,
|
||||||
// 类型数据字典
|
// 类型数据字典
|
||||||
typeOptions: [],
|
typeOptions: [],
|
||||||
{{.ModuleName}}List:[],
|
{{.ModuleName}}List: [],
|
||||||
{{range .Columns}}
|
{{range .Columns}}
|
||||||
{{- if ne .DictType "" -}}
|
{{- if ne .DictType "" -}}
|
||||||
{{.JsonField}}Options: [],
|
{{.JsonField}}Options: [],
|
||||||
@@ -182,28 +193,30 @@
|
|||||||
queryParams: {
|
queryParams: {
|
||||||
pageIndex: 1,
|
pageIndex: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
{{ range .Columns }}
|
{{ range .Columns }}
|
||||||
{{- if (.IsQuery) -}}
|
{{- if (.IsQuery) -}}
|
||||||
{{.JsonField}}:undefined,
|
{{.JsonField}}:
|
||||||
{{ end -}}
|
undefined,
|
||||||
{{- end }}
|
{{ end -}}
|
||||||
},
|
{{- end }}
|
||||||
// 表单参数
|
},
|
||||||
form: {
|
// 表单参数
|
||||||
},
|
form: {
|
||||||
// 表单校验
|
|
||||||
rules: {
|
|
||||||
{{- range .Columns -}}
|
|
||||||
{{- $x := .IsQuery -}}
|
|
||||||
{{- if ($x) -}}
|
|
||||||
{{.JsonField}}:
|
|
||||||
[
|
|
||||||
{required: true, message: '{{.ColumnComment}}不能为空', trigger: 'blur'}
|
|
||||||
],
|
|
||||||
{{ end }}
|
|
||||||
{{- end -}}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
,
|
||||||
|
// 表单校验
|
||||||
|
rules: {
|
||||||
|
{{- range .Columns -}}
|
||||||
|
{{- $x := .IsQuery -}}
|
||||||
|
{{- if ($x) -}}
|
||||||
|
{{.JsonField}}:
|
||||||
|
[
|
||||||
|
{required: true, message: '{{.ColumnComment}}不能为空', trigger: 'blur'}
|
||||||
|
],
|
||||||
|
{{ end }}
|
||||||
|
{{- end -}}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getList()
|
this.getList()
|
||||||
@@ -243,11 +256,12 @@
|
|||||||
{{- else if eq .GoField "UpdateBy" -}}
|
{{- else if eq .GoField "UpdateBy" -}}
|
||||||
{{- else if eq .GoField "CreateBy" -}}
|
{{- else if eq .GoField "CreateBy" -}}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{.JsonField}}: undefined,
|
{{.JsonField}}:
|
||||||
|
undefined,
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
this.resetForm('form')
|
this.resetForm('form')
|
||||||
},
|
},
|
||||||
{{range .Columns}}
|
{{range .Columns}}
|
||||||
@@ -285,7 +299,8 @@
|
|||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
handleUpdate(row) {
|
handleUpdate(row) {
|
||||||
this.reset()
|
this.reset()
|
||||||
const {{.PkJsonField}} = row.{{.PkJsonField}} || this.ids
|
const {{.PkJsonField}} =
|
||||||
|
row.{{.PkJsonField}} || this.ids
|
||||||
get{{.ClassName}}({{.PkJsonField}}).then(response => {
|
get{{.ClassName}}({{.PkJsonField}}).then(response => {
|
||||||
this.form = response.data
|
this.form = response.data
|
||||||
this.open = true
|
this.open = true
|
||||||
@@ -294,7 +309,7 @@
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
submitForm: function() {
|
submitForm: function () {
|
||||||
this.$refs['form'].validate(valid => {
|
this.$refs['form'].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.{{.PkJsonField}} !== undefined) {
|
if (this.form.{{.PkJsonField}} !== undefined) {
|
||||||
@@ -328,12 +343,13 @@
|
|||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(function() {
|
}).then(function () {
|
||||||
return del{{.ClassName}}(Ids)
|
return del{{.ClassName}}(Ids)
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.getList()
|
this.getList()
|
||||||
this.msgSuccess('删除成功')
|
this.msgSuccess('删除成功')
|
||||||
}).catch(function() {})
|
}).catch(function () {
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+62
-62
@@ -21,40 +21,40 @@ import (
|
|||||||
// @Router /api/v1/configList [get]
|
// @Router /api/v1/configList [get]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func Get{{.ClassName}}List(c *gin.Context) {
|
func Get{{.ClassName}}List(c *gin.Context) {
|
||||||
var data models.{{.ClassName}}
|
var data models.{{.ClassName}}
|
||||||
var err error
|
var err error
|
||||||
var pageSize = 10
|
var pageSize = 10
|
||||||
var pageIndex = 1
|
var pageIndex = 1
|
||||||
|
|
||||||
if size := c.Request.FormValue("pageSize"); size != "" {
|
if size := c.Request.FormValue("pageSize"); size != "" {
|
||||||
pageSize = pkg.StrToInt(err, size)
|
pageSize = pkg.StrToInt(err, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||||
pageIndex = pkg.StrToInt(err, index)
|
pageIndex = pkg.StrToInt(err, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$z := .IsQuery}}
|
{{$z := .IsQuery}}
|
||||||
{{- if ($z) -}}
|
{{- if ($z) -}}
|
||||||
data.{{.GoField}} = c.Request.FormValue("{{.JsonField}}")
|
data.{{.GoField}} = c.Request.FormValue("{{.JsonField}}")
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
data.DataScope = utils.GetUserIdStr(c)
|
data.DataScope = utils.GetUserIdStr(c)
|
||||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||||
pkg.HasError(err, "", -1)
|
pkg.HasError(err, "", -1)
|
||||||
|
|
||||||
var mp = make(map[string]interface{}, 3)
|
var mp = make(map[string]interface{}, 3)
|
||||||
mp["list"] = result
|
mp["list"] = result
|
||||||
mp["count"] = count
|
mp["count"] = count
|
||||||
mp["pageIndex"] = pageIndex
|
mp["pageIndex"] = pageIndex
|
||||||
mp["pageIndex"] = pageSize
|
mp["pageIndex"] = pageSize
|
||||||
|
|
||||||
var res app.Response
|
var res app.Response
|
||||||
res.Data = mp
|
res.Data = mp
|
||||||
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
c.JSON(http.StatusOK, res.ReturnOK())
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 获取配置
|
// @Summary 获取配置
|
||||||
@@ -65,15 +65,15 @@ func Get{{.ClassName}}List(c *gin.Context) {
|
|||||||
// @Router /api/v1/config/{configId} [get]
|
// @Router /api/v1/config/{configId} [get]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func Get{{.ClassName}}(c *gin.Context) {
|
func Get{{.ClassName}}(c *gin.Context) {
|
||||||
var data models.{{.ClassName}}
|
var data models.{{.ClassName}}
|
||||||
data.{{.PkGoField}}, _ = utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
data.{{.PkGoField}}, _ = utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||||
result, err := data.Get()
|
result, err := data.Get()
|
||||||
pkg.HasError(err, "抱歉未找到相关信息", -1)
|
pkg.HasError(err, "抱歉未找到相关信息", -1)
|
||||||
|
|
||||||
var res app.Response
|
var res app.Response
|
||||||
res.Data = result
|
res.Data = result
|
||||||
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
c.JSON(http.StatusOK, res.ReturnOK())
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary 添加配置
|
// @Summary 添加配置
|
||||||
@@ -82,45 +82,45 @@ func Get{{.ClassName}}(c *gin.Context) {
|
|||||||
// @Accept application/json
|
// @Accept application/json
|
||||||
// @Product application/json
|
// @Product application/json
|
||||||
// @Param data body models.{{.ClassName}} true "data"
|
// @Param data body models.{{.ClassName}} true "data"
|
||||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||||
// @Router /api/v1/dict/data [post]
|
// @Router /api/v1/dict/data [post]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func Insert{{.ClassName}}(c *gin.Context) {
|
func Insert{{.ClassName}}(c *gin.Context) {
|
||||||
var data models.{{.ClassName}}
|
var data models.{{.ClassName}}
|
||||||
err := c.BindWith(&data, binding.JSON)
|
err := c.BindWith(&data, binding.JSON)
|
||||||
data.CreateBy = utils.GetUserIdStr(c)
|
data.CreateBy = utils.GetUserIdStr(c)
|
||||||
pkg.HasError(err, "", 500)
|
pkg.HasError(err, "", 500)
|
||||||
result, err := data.Create()
|
result, err := data.Create()
|
||||||
pkg.HasError(err, "", -1)
|
pkg.HasError(err, "", -1)
|
||||||
|
|
||||||
var res app.Response
|
var res app.Response
|
||||||
res.Data = result
|
res.Data = result
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
c.JSON(http.StatusOK, res.ReturnOK())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update{{.ClassName}}(c *gin.Context) {
|
func Update{{.ClassName}}(c *gin.Context) {
|
||||||
var data models.{{.ClassName}}
|
var data models.{{.ClassName}}
|
||||||
err := c.BindWith(&data, binding.JSON)
|
err := c.BindWith(&data, binding.JSON)
|
||||||
pkg.HasError(err, "数据解析失败", -1)
|
pkg.HasError(err, "数据解析失败", -1)
|
||||||
data.UpdateBy = utils.GetUserIdStr(c)
|
data.UpdateBy = utils.GetUserIdStr(c)
|
||||||
result, err := data.Update(data.{{.PkGoField}})
|
result, err := data.Update(data.{{.PkGoField}})
|
||||||
pkg.HasError(err, "", -1)
|
pkg.HasError(err, "", -1)
|
||||||
|
|
||||||
var res app.Response
|
var res app.Response
|
||||||
res.Data = result
|
res.Data = result
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
c.JSON(http.StatusOK, res.ReturnOK())
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete{{.ClassName}}(c *gin.Context) {
|
func Delete{{.ClassName}}(c *gin.Context) {
|
||||||
var data models.{{.ClassName}}
|
var data models.{{.ClassName}}
|
||||||
id, err := utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
id, err := utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||||
data.UpdateBy = utils.GetUserIdStr(c)
|
data.UpdateBy = utils.GetUserIdStr(c)
|
||||||
_, err = data.Delete(id)
|
_, err = data.Delete(id)
|
||||||
pkg.HasError(err, "修改失败", 500)
|
pkg.HasError(err, "修改失败", 500)
|
||||||
|
|
||||||
var res app.Response
|
var res app.Response
|
||||||
res.Msg = "删除成功"
|
res.Msg = "删除成功"
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
c.JSON(http.StatusOK, res.ReturnOK())
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestGoModelTemplate(t *testing.T) {
|
func TestGoModelTemplate(t *testing.T) {
|
||||||
t1, err := template.ParseFiles("model.go.template")
|
t1, err := template.ParseFiles("model.go.template")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+60
-60
@@ -1,104 +1,104 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
orm "go-admin/global"
|
orm "go-admin/global"
|
||||||
"go-admin/utils"
|
"go-admin/utils"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type {{.ClassName}} struct {
|
type {{.ClassName}} struct {
|
||||||
|
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$x := .Pk}}
|
{{$x := .Pk}}
|
||||||
// {{.ColumnComment}}
|
// {{.ColumnComment}}
|
||||||
{{if ($x)}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};primary_key"`{{else}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};"`{{end}}
|
{{if ($x)}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};primary_key"`{{else}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};"`{{end}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建{{.ClassName}}
|
// 创建{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
|
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
|
||||||
var doc {{.ClassName}}
|
var doc {{.ClassName}}
|
||||||
doc.IsDel = "0"
|
doc.IsDel = "0"
|
||||||
e.CreateTime = time.Now().String()
|
e.CreateTime = time.Now().String()
|
||||||
result := orm.Eloquent.Table("{{.TableName}}").Create(&e)
|
result := orm.Eloquent.Table("{{.TableName}}").Create(&e)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
err := result.Error
|
err := result.Error
|
||||||
return doc, err
|
return doc, err
|
||||||
}
|
}
|
||||||
doc = *e
|
doc = *e
|
||||||
return doc, nil
|
return doc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取{{.ClassName}}
|
// 获取{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
||||||
var doc {{.ClassName}}
|
var doc {{.ClassName}}
|
||||||
|
|
||||||
table := orm.Eloquent.Table("{{.TableName}}")
|
table := orm.Eloquent.Table("{{.TableName}}")
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$z := .IsQuery}}
|
{{$z := .IsQuery}}
|
||||||
{{- if ($z) -}}if e.{{.GoField}} != "" {
|
{{- if ($z) -}}if e.{{.GoField}} != "" {
|
||||||
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
if err := table.First(&doc).Error; err != nil {
|
if err := table.First(&doc).Error; err != nil {
|
||||||
return doc, err
|
return doc, err
|
||||||
}
|
}
|
||||||
return doc, nil
|
return doc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取{{.ClassName}}带分页
|
// 获取{{.ClassName}}带分页
|
||||||
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int32, error) {
|
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int32, error) {
|
||||||
var doc []{{.ClassName}}
|
var doc []{{.ClassName}}
|
||||||
|
|
||||||
table := orm.Eloquent.Select("*").Table("{{.TableName}}")
|
table := orm.Eloquent.Select("*").Table("{{.TableName}}")
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$z := .IsQuery}}
|
{{$z := .IsQuery}}
|
||||||
{{- if ($z) -}}if e.{{.GoField}} != "" {
|
{{- if ($z) -}}if e.{{.GoField}} != "" {
|
||||||
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
// 数据权限控制
|
// 数据权限控制
|
||||||
dataPermission := new(DataPermission)
|
dataPermission := new(DataPermission)
|
||||||
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
|
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
|
||||||
table,err := dataPermission.GetDataScope("{{.TableName}}", table)
|
table,err := dataPermission.GetDataScope("{{.TableName}}", table)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
var count int32
|
var count int32
|
||||||
table = table.Offset((pageIndex - 1) * pageSize).Limit(pageSize)
|
table = table.Offset((pageIndex - 1) * pageSize).Limit(pageSize)
|
||||||
if err := table.Find(&doc).Error; err != nil {
|
if err := table.Find(&doc).Error; err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
table.Count(&count)
|
table.Count(&count)
|
||||||
return doc, count, nil
|
return doc, count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新{{.ClassName}}
|
// 更新{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
|
func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
|
||||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//参数1:是要修改的数据
|
//参数1:是要修改的数据
|
||||||
//参数2:是修改的数据
|
//参数2:是修改的数据
|
||||||
if err = orm.Eloquent.Table("{{.TableName}}").Model(&update).Updates(&e).Error; err != nil {
|
if err = orm.Eloquent.Table("{{.TableName}}").Model(&update).Updates(&e).Error; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除{{.ClassName}}
|
// 删除{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
|
func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
|
||||||
|
|
||||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||||
success = false
|
success = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
success = true
|
success = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
+4
-9
@@ -10,10 +10,10 @@ type Response struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Page struct {
|
type Page struct {
|
||||||
List interface{} `json:"list"`
|
List interface{} `json:"list"`
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
PageIndex int `json:"pageIndex"`
|
PageIndex int `json:"pageIndex"`
|
||||||
PageSize int `json:"pageSize"`
|
PageSize int `json:"pageSize"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PageResponse struct {
|
type PageResponse struct {
|
||||||
@@ -25,7 +25,6 @@ type PageResponse struct {
|
|||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (res *Response) ReturnOK() *Response {
|
func (res *Response) ReturnOK() *Response {
|
||||||
res.Code = 200
|
res.Code = 200
|
||||||
return res
|
return res
|
||||||
@@ -36,11 +35,7 @@ func (res *Response) ReturnError(code int) *Response {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (res *PageResponse) ReturnOK() *PageResponse {
|
func (res *PageResponse) ReturnOK() *PageResponse {
|
||||||
res.Code = 200
|
res.Code = 200
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+2
-2
@@ -26,7 +26,7 @@ func OK(c *gin.Context, data interface{}, msg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分页数据处理
|
// 分页数据处理
|
||||||
func PageOK(c *gin.Context, result interface{},count int,pageIndex int,pageSize int, msg string) {
|
func PageOK(c *gin.Context, result interface{}, count int, pageIndex int, pageSize int, msg string) {
|
||||||
var res PageResponse
|
var res PageResponse
|
||||||
res.Data.List = result
|
res.Data.List = result
|
||||||
res.Data.Count = count
|
res.Data.Count = count
|
||||||
@@ -40,5 +40,5 @@ func PageOK(c *gin.Context, result interface{},count int,pageIndex int,pageSize
|
|||||||
|
|
||||||
// 兼容函数
|
// 兼容函数
|
||||||
func Custum(c *gin.Context, data gin.H) {
|
func Custum(c *gin.Context, data gin.H) {
|
||||||
c.JSON(http.StatusOK,data)
|
c.JSON(http.StatusOK, data)
|
||||||
}
|
}
|
||||||
@@ -20,9 +20,8 @@ type configJsonBody struct {
|
|||||||
DriverDigit *base64Captcha.DriverDigit
|
DriverDigit *base64Captcha.DriverDigit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DriverStringFunc() (id, b64s string, err error) {
|
||||||
func DriverStringFunc() (id, b64s string, err error) {
|
e := configJsonBody{}
|
||||||
e :=configJsonBody{}
|
|
||||||
e.Id = uuid.New().String()
|
e.Id = uuid.New().String()
|
||||||
e.DriverString = base64Captcha.NewDriverString(46, 140, 2, 2, 4, "234567890abcdefghjkmnpqrstuvwxyz", &color.RGBA{240, 240, 246, 246}, []string{"wqy-microhei.ttc"})
|
e.DriverString = base64Captcha.NewDriverString(46, 140, 2, 2, 4, "234567890abcdefghjkmnpqrstuvwxyz", &color.RGBA{240, 240, 246, 246}, []string{"wqy-microhei.ttc"})
|
||||||
driver := e.DriverString.ConvertFonts()
|
driver := e.DriverString.ConvertFonts()
|
||||||
@@ -30,7 +29,6 @@ func DriverStringFunc() (id, b64s string, err error) {
|
|||||||
return cap.Generate()
|
return cap.Generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func DriverDigitFunc() (id, b64s string, err error) {
|
func DriverDigitFunc() (id, b64s string, err error) {
|
||||||
e := configJsonBody{}
|
e := configJsonBody{}
|
||||||
e.Id = uuid.New().String()
|
e.Id = uuid.New().String()
|
||||||
@@ -38,4 +36,4 @@ func DriverDigitFunc() (id, b64s string, err error) {
|
|||||||
driver := e.DriverDigit
|
driver := e.DriverDigit
|
||||||
cap := base64Captcha.NewCaptcha(driver, store)
|
cap := base64Captcha.NewCaptcha(driver, store)
|
||||||
return cap.Generate()
|
return cap.Generate()
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ func portDefault(cfg *viper.Viper) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isHttpsDefault(cfg *viper.Viper) bool {
|
func isHttpsDefault(cfg *viper.Viper) bool {
|
||||||
if cfg.GetString("ishttps") == "" || cfg.GetBool("ishttps") == false{
|
if cfg.GetString("ishttps") == "" || cfg.GetBool("ishttps") == false {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ var cfgLog *viper.Viper
|
|||||||
var cfgSsl *viper.Viper
|
var cfgSsl *viper.Viper
|
||||||
var cfgGen *viper.Viper
|
var cfgGen *viper.Viper
|
||||||
|
|
||||||
|
|
||||||
//载入配置文件
|
//载入配置文件
|
||||||
func ConfigSetup(path string) {
|
func ConfigSetup(path string) {
|
||||||
viper.SetConfigFile(path)
|
viper.SetConfigFile(path)
|
||||||
@@ -25,7 +24,6 @@ func ConfigSetup(path string) {
|
|||||||
log.Fatal(fmt.Sprintf("Read config file fail: %s", err.Error()))
|
log.Fatal(fmt.Sprintf("Read config file fail: %s", err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Replace environment variables
|
//Replace environment variables
|
||||||
err = viper.ReadConfig(strings.NewReader(os.ExpandEnv(string(content))))
|
err = viper.ReadConfig(strings.NewReader(os.ExpandEnv(string(content))))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -69,7 +67,6 @@ func ConfigSetup(path string) {
|
|||||||
GenConfig = InitGen(cfgGen)
|
GenConfig = InitGen(cfgGen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func SetConfig(configPath string, key string, value interface{}) {
|
func SetConfig(configPath string, key string, value interface{}) {
|
||||||
viper.AddConfigPath(configPath)
|
viper.AddConfigPath(configPath)
|
||||||
viper.Set(key, value)
|
viper.Set(key, value)
|
||||||
|
|||||||
@@ -19,4 +19,3 @@ func InitDatabase(cfg *viper.Viper) *Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var DatabaseConfig = new(Database)
|
var DatabaseConfig = new(Database)
|
||||||
|
|
||||||
+4
-4
@@ -3,14 +3,14 @@ package config
|
|||||||
import "github.com/spf13/viper"
|
import "github.com/spf13/viper"
|
||||||
|
|
||||||
type Gen struct {
|
type Gen struct {
|
||||||
DBName string
|
DBName string
|
||||||
FrontPath string
|
FrontPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitGen(cfg *viper.Viper) *Gen {
|
func InitGen(cfg *viper.Viper) *Gen {
|
||||||
return &Gen{
|
return &Gen{
|
||||||
DBName: cfg.GetString("dbname"),
|
DBName: cfg.GetString("dbname"),
|
||||||
FrontPath: cfg.GetString("frontpath"),
|
FrontPath: cfg.GetString("frontpath"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -3,13 +3,13 @@ package config
|
|||||||
import "github.com/spf13/viper"
|
import "github.com/spf13/viper"
|
||||||
|
|
||||||
type Log struct {
|
type Log struct {
|
||||||
Dir string
|
Dir string
|
||||||
Operdb bool
|
Operdb bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitLog(cfg *viper.Viper) *Log {
|
func InitLog(cfg *viper.Viper) *Log {
|
||||||
return &Log{
|
return &Log{
|
||||||
Dir: cfg.GetString("dir"),
|
Dir: cfg.GetString("dir"),
|
||||||
Operdb: cfg.GetBool("operdb"),
|
Operdb: cfg.GetBool("operdb"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -5,9 +5,9 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ModeDev Mode = "dev" //开发模式
|
ModeDev Mode = "dev" //开发模式
|
||||||
ModeTest Mode = "test" //测试模式
|
ModeTest Mode = "test" //测试模式
|
||||||
ModeProd Mode = "prod" //生产模式
|
ModeProd Mode = "prod" //生产模式
|
||||||
Mysql = "mysql" //mysql数据库标识
|
Mysql = "mysql" //mysql数据库标识
|
||||||
Sqlite = "sqlite3" //sqlite
|
Sqlite = "sqlite3" //sqlite
|
||||||
)
|
)
|
||||||
+6
-5
@@ -55,7 +55,7 @@ func FileRemove(name string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FileZip(dst, src string,notContPath string) (err error) {
|
func FileZip(dst, src string, notContPath string) (err error) {
|
||||||
//创建准备写入的文件
|
//创建准备写入的文件
|
||||||
fw, err := os.Create(dst)
|
fw, err := os.Create(dst)
|
||||||
defer fw.Close()
|
defer fw.Close()
|
||||||
@@ -119,6 +119,7 @@ type ReplaceHelper struct {
|
|||||||
OldText string //需要替换的文本
|
OldText string //需要替换的文本
|
||||||
NewText string //新的文本
|
NewText string //新的文本
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ReplaceHelper) DoWrok() error {
|
func (h *ReplaceHelper) DoWrok() error {
|
||||||
|
|
||||||
return filepath.Walk(h.Root, h.walkCallback)
|
return filepath.Walk(h.Root, h.walkCallback)
|
||||||
@@ -134,7 +135,7 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
log.Println("DIR:",path)
|
log.Println("DIR:", path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,8 +147,8 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
content := string(buf)
|
content := string(buf)
|
||||||
log.Printf("h.OldText: %s \n",h.OldText)
|
log.Printf("h.OldText: %s \n", h.OldText)
|
||||||
log.Printf("h.NewText: %s \n",h.NewText)
|
log.Printf("h.NewText: %s \n", h.NewText)
|
||||||
|
|
||||||
//替换
|
//替换
|
||||||
newContent := strings.Replace(content, h.OldText, h.NewText, -1)
|
newContent := strings.Replace(content, h.OldText, h.NewText, -1)
|
||||||
@@ -156,4 +157,4 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
|
|||||||
ioutil.WriteFile(path, []byte(newContent), 0)
|
ioutil.WriteFile(path, []byte(newContent), 0)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
+1
-1
@@ -4,4 +4,4 @@ import "strconv"
|
|||||||
|
|
||||||
func Float64ToString(e float64) string {
|
func Float64ToString(e float64) string {
|
||||||
return strconv.FormatFloat(e, 'E', -1, 64)
|
return strconv.FormatFloat(e, 'E', -1, 64)
|
||||||
}
|
}
|
||||||
+1
-1
@@ -4,4 +4,4 @@ import "strconv"
|
|||||||
|
|
||||||
func IntToString(e int) string {
|
func IntToString(e int) string {
|
||||||
return strconv.Itoa(e)
|
return strconv.Itoa(e)
|
||||||
}
|
}
|
||||||
+1
-1
@@ -4,4 +4,4 @@ import "strconv"
|
|||||||
|
|
||||||
func Int64ToString(e int64) string {
|
func Int64ToString(e int64) string {
|
||||||
return strconv.FormatInt(e, 10)
|
return strconv.FormatInt(e, 10)
|
||||||
}
|
}
|
||||||
+1
-1
@@ -30,4 +30,4 @@ func GetLocation(ip string) string {
|
|||||||
return "未知位置"
|
return "未知位置"
|
||||||
}
|
}
|
||||||
return m["province"] + "-" + m["city"]
|
return m["province"] + "-" + m["city"]
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,6 @@ func InitLogger() {
|
|||||||
log.FieldKeyLevel: "@level",
|
log.FieldKeyLevel: "@level",
|
||||||
log.FieldKeyMsg: "@message"}})
|
log.FieldKeyMsg: "@message"}})
|
||||||
|
|
||||||
|
|
||||||
switch Mode(config2.ApplicationConfig.Mode) {
|
switch Mode(config2.ApplicationConfig.Mode) {
|
||||||
case ModeDev, ModeTest:
|
case ModeDev, ModeTest:
|
||||||
log.SetOutput(os.Stdout)
|
log.SetOutput(os.Stdout)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ func StringToInt(e string) (int, error) {
|
|||||||
return strconv.Atoi(e)
|
return strconv.Atoi(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func GetCurrentTimeStr() string {
|
func GetCurrentTimeStr() string {
|
||||||
return time.Now().Format("2006/01/02 15:04:05")
|
return time.Now().Format("2006/01/02 15:04:05")
|
||||||
}
|
}
|
||||||
@@ -26,7 +25,6 @@ func GetCurrentTime() time.Time {
|
|||||||
return time.Now()
|
return time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func StructToJsonStr(e interface{}) (string, error) {
|
func StructToJsonStr(e interface{}) (string, error) {
|
||||||
if b, err := json.Marshal(e); err == nil {
|
if b, err := json.Marshal(e); err == nil {
|
||||||
return string(b), err
|
return string(b), err
|
||||||
|
|||||||
+1
-2
@@ -10,7 +10,6 @@ func IdsStrToIdsIntGroup(key string, c *gin.Context) []int {
|
|||||||
return idsStrToIdsIntGroup(c.Param(key))
|
return idsStrToIdsIntGroup(c.Param(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func idsStrToIdsIntGroup(keys string) []int {
|
func idsStrToIdsIntGroup(keys string) []int {
|
||||||
IDS := make([]int, 0)
|
IDS := make([]int, 0)
|
||||||
ids := strings.Split(keys, ",")
|
ids := strings.Split(keys, ",")
|
||||||
@@ -19,4 +18,4 @@ func idsStrToIdsIntGroup(keys string) []int {
|
|||||||
IDS = append(IDS, ID)
|
IDS = append(IDS, ID)
|
||||||
}
|
}
|
||||||
return IDS
|
return IDS
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user