gin-vue-admin 2.0代码重构
This commit is contained in:
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.4 KiB |
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang="zh"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=0,maximum-scale=0,user-scalable=yes,shrink-to-fit=no"><link rel="icon" href="/form-generator/favicon.ico"><title>form-generator</title><style>.pre-loader{position:absolute;top:calc(50% - 32px);left:calc(50% - 32px);width:64px;height:64px;border-radius:50%;perspective:800px}.pre-loader .inner{position:absolute;box-sizing:border-box;width:100%;height:100%;border-radius:50%}.pre-loader .inner.one{left:0;top:0;-webkit-animation:rotate-one 1s linear infinite;animation:rotate-one 1s linear infinite;border-bottom:3px solid #bc9048}.pre-loader .inner.two{right:0;top:0;-webkit-animation:rotate-two 1s linear infinite;animation:rotate-two 1s linear infinite;border-right:3px solid #74aeff}.pre-loader .inner.three{right:0;bottom:0;-webkit-animation:rotate-three 1s linear infinite;animation:rotate-three 1s linear infinite;border-top:3px solid #caef74}@keyframes rotate-one{0%{-webkit-transform:rotateX(35deg) rotateY(-45deg) rotateZ(0);transform:rotateX(35deg) rotateY(-45deg) rotateZ(0)}100%{-webkit-transform:rotateX(35deg) rotateY(-45deg) rotateZ(360deg);transform:rotateX(35deg) rotateY(-45deg) rotateZ(360deg)}}@keyframes rotate-two{0%{-webkit-transform:rotateX(50deg) rotateY(10deg) rotateZ(0);transform:rotateX(50deg) rotateY(10deg) rotateZ(0)}100%{-webkit-transform:rotateX(50deg) rotateY(10deg) rotateZ(360deg);transform:rotateX(50deg) rotateY(10deg) rotateZ(360deg)}}@keyframes rotate-three{0%{-webkit-transform:rotateX(35deg) rotateY(55deg) rotateZ(0);transform:rotateX(35deg) rotateY(55deg) rotateZ(0)}100%{-webkit-transform:rotateX(35deg) rotateY(55deg) rotateZ(360deg);transform:rotateX(35deg) rotateY(55deg) rotateZ(360deg)}}</style><link href="https://cdn.bootcss.com/element-ui/2.12.0/theme-chalk/index.css" rel="stylesheet"><link href="https://cdn.bootcss.com/monaco-editor/0.18.0/min/vs/editor/editor.main.css" rel="stylesheet"><script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script><script src="https://cdn.bootcss.com/vue-router/3.1.3/vue-router.min.js"></script><script src="https://cdn.bootcss.com/element-ui/2.12.0/index.js"></script><link href="/form-generator/css/index.d8b172cd.css" rel="preload" as="style"><link href="/form-generator/js/chunk-vendors.788511b0.js" rel="preload" as="script"><link href="/form-generator/js/index.b3720c41.js" rel="preload" as="script"><link href="/form-generator/css/index.d8b172cd.css" rel="stylesheet"></head><body><noscript><strong>抱歉,javascript被禁用,请开启后重试。</strong></noscript><div id="app"></div><div class="pre-loader" id="pre-loader"><div class="inner one"></div><div class="inner two"></div><div class="inner three"></div></div><script>var require={paths:{vs:"https://cdn.bootcss.com/monaco-editor/0.18.0/min/vs"}}</script><script src="https://cdn.bootcss.com/js-beautify/1.10.2/beautifier.min.js"></script><script src="https://cdn.bootcss.com/monaco-editor/0.18.0/min/vs/loader.js"></script><script src="https://cdn.bootcss.com/monaco-editor/0.18.0/min/vs/editor/editor.main.nls.js"></script><script src="https://cdn.bootcss.com/monaco-editor/0.18.0/min/vs/editor/editor.main.js"></script><script src="/form-generator/js/chunk-vendors.788511b0.js"></script><script src="/form-generator/js/index.b3720c41.js"></script></body></html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang="zh"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/form-generator/favicon.ico"><title>form-generator-preview</title><link href="https://cdn.bootcss.com/element-ui/2.12.0/theme-chalk/index.css" rel="stylesheet"><script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script><script src="https://cdn.bootcss.com/vue-router/3.1.3/vue-router.min.js"></script><script src="https://cdn.bootcss.com/element-ui/2.12.0/index.js"></script><style>body{margin:0;padding:0;overflow-x:hidden;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility;height:calc(100vh - 33px);padding:12px;box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji}input,textarea{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji}</style><link href="/form-generator/js/chunk-vendors.788511b0.js" rel="preload" as="script"><link href="/form-generator/js/preview.7fecf17e.js" rel="preload" as="script"></head><body><noscript><strong>抱歉,javascript被禁用,请开启后重试。</strong></noscript><div id="previewApp"></div><script src="/form-generator/js/chunk-vendors.788511b0.js"></script><script src="/form-generator/js/preview.7fecf17e.js"></script></body></html>
|
||||
@@ -0,0 +1,14 @@
|
||||
[request_definition]
|
||||
r = sub, obj, act
|
||||
|
||||
[policy_definition]
|
||||
p = sub, obj, act
|
||||
|
||||
[role_definition]
|
||||
g = _, _
|
||||
|
||||
[policy_effect]
|
||||
e = some(where (p.eft == allow))
|
||||
|
||||
[matchers]
|
||||
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
|
||||
@@ -0,0 +1,84 @@
|
||||
import service from '@/utils/request'
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 创建{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "创建{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/create{{.StructName}} [post]
|
||||
export const create{{.StructName}} = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/create{{.StructName}}",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 删除{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "删除{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}} [post]
|
||||
export const delete{{.StructName}} = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/delete{{.StructName}}",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 更新{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "更新{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /{{.Abbreviation}}/update{{.StructName}} [post]
|
||||
export const update{{.StructName}} = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/update{{.StructName}}",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 用id查询{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "用id查询{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /{{.Abbreviation}}/find{{.StructName}} [post]
|
||||
export const find{{.StructName}} = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/find{{.StructName}}",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 分页获取{{.StructName}}列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.PageInfo true "分页获取{{.StructName}}列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [post]
|
||||
export const get{{.StructName}}List = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/get{{.StructName}}List",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
代码解压后把fe的api文件内容粘贴进前端api文件夹下并修改为自己想要的名字即可
|
||||
|
||||
后端代码解压后同理,放到自己想要的 mvc对应路径 并且到 initRouter中注册自动生成的路由 到registerTable中注册自动生成的model
|
||||
|
||||
项目github:"https://github.com/piexlmax/gin-vue-admin"
|
||||
|
||||
希望大家给个star多多鼓励
|
||||
|
||||
暂时不保存大家生成的结构体 只为方便一次性使用
|
||||
@@ -0,0 +1,116 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
// 请自行引入model路径
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 创建{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "创建{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/create{{.StructName}} [post]
|
||||
func Create{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
err := {{.Abbreviation}}.Create{{.StructName}}()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "创建成功", gin.H{})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 删除{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "删除{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}} [post]
|
||||
func Delete{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
err := {{.Abbreviation}}.Delete{{.StructName}}()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "创建成功", gin.H{})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 更新{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "更新{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /{{.Abbreviation}}/update{{.StructName}} [post]
|
||||
func Update{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
err,re{{.Abbreviation}} := {{.Abbreviation}}.Update{{.StructName}}()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("更新失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "更新成功", gin.H{
|
||||
"re{{.Abbreviation}}":re{{.Abbreviation}},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 用id查询{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "用id查询{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /{{.Abbreviation}}/find{{.StructName}} [post]
|
||||
func Find{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
err,re{{.Abbreviation}} := {{.Abbreviation}}.FindById()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("查询失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "查询成功", gin.H{
|
||||
"re{{.Abbreviation}}":re{{.Abbreviation}},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 分页获取{{.StructName}}列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.PageInfo true "分页获取{{.StructName}}列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [post]
|
||||
func Get{{.StructName}}List(c *gin.Context) {
|
||||
var pageInfo model.PageInfo
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
err, list, total := new({{.PackageName}}.{{.StructName}}).GetInfoList(pageInfo)
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "获取数据成功", gin.H{
|
||||
"{{.PackageName}}List": list,
|
||||
"total": total,
|
||||
"page": pageInfo.Page,
|
||||
"pageSize": pageInfo.PageSize,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// 自动生成模板{{.StructName}}
|
||||
package {{.PackageName}}
|
||||
|
||||
import (
|
||||
"gin-vue-admin/init/qmsql"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
type {{.StructName}} struct {
|
||||
gorm.Model {{range .Fields}}
|
||||
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}"{{if .ColumnName}} gorm:"column:{{.ColumnName}}"{{end}}`{{ end }}
|
||||
}
|
||||
|
||||
// 创建{{.StructName}}
|
||||
func ({{.Abbreviation}} *{{.StructName}})Create{{.StructName}}()(err error){
|
||||
err = qmsql.DEFAULTDB.Create({{.Abbreviation}}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// 删除{{.StructName}}
|
||||
func ({{.Abbreviation}} *{{.StructName}})Delete{{.StructName}}()(err error){
|
||||
err = qmsql.DEFAULTDB.Delete({{.Abbreviation}}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新{{.StructName}}
|
||||
func ({{.Abbreviation}} *{{.StructName}})Update{{.StructName}}()(err error, re{{.Abbreviation}} {{.StructName}}){
|
||||
err = qmsql.DEFAULTDB.Save({{.Abbreviation}}).Error
|
||||
return err, *{{.Abbreviation}}
|
||||
}
|
||||
|
||||
// 根据ID查看单条{{.StructName}}
|
||||
func ({{.Abbreviation}} *{{.StructName}})FindById()(err error,re{{.Abbreviation}} {{.StructName}}){
|
||||
err = qmsql.DEFAULTDB.Where("id = ?",{{.Abbreviation}}.ID).First(&re{{.Abbreviation}}).Error
|
||||
return err,re{{.Abbreviation}}
|
||||
}
|
||||
|
||||
// 分页获取{{.StructName}}
|
||||
func ({{.Abbreviation}} *{{.StructName}})GetInfoList(info PageInfo)(err error, list interface{}, total int){
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db:=qmsql.DEFAULTDB
|
||||
if err != nil {
|
||||
return
|
||||
} else {
|
||||
var re{{.StructName}}List []{{.StructName}}
|
||||
err = db.Limit(limit).Offset(offset).Find(&re{{.StructName}}List).Error
|
||||
return err, re{{.StructName}}List, total
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"gin-vue-admin/controller/api"
|
||||
"gin-vue-admin/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Init{{.StructName}}Router(Router *gin.RouterGroup) {
|
||||
{{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
|
||||
{
|
||||
{{.StructName}}Router.POST("create{{.StructName}}", api.Create{{.StructName}}) // 新建{{.StructName}}
|
||||
{{.StructName}}Router.POST("delete{{.StructName}}", api.Delete{{.StructName}}) //删除{{.StructName}}
|
||||
{{.StructName}}Router.POST("update{{.StructName}}", api.Update{{.StructName}}) //更新{{.StructName}}
|
||||
{{.StructName}}Router.POST("find{{.StructName}} ", api.Find{{.StructName}}) // 根据ID获取{{.StructName}}
|
||||
{{.StructName}}Router.POST("get{{.StructName}}List", api.Get{{.StructName}}List) //获取{{.StructName}}列表
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user