Merge pull request #68 from wenjianzhang/master_fixbug
Modify unauthorized code update api template update js template update model template update vue template
This commit is contained in:
5 files changed
+67
-74
No files matched your search
@@ -27,7 +27,7 @@ func AuthCheckRole() gin.HandlerFunc {
|
|||||||
c.Next()
|
c.Next()
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"code": 401,
|
"code": 403,
|
||||||
"msg": "对不起,您没有该接口访问权限,请联系管理员",
|
"msg": "对不起,您没有该接口访问权限,请联系管理员",
|
||||||
})
|
})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
|
|||||||
+24
-43
@@ -4,10 +4,9 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gin-gonic/gin/binding"
|
"github.com/gin-gonic/gin/binding"
|
||||||
"go-admin/models"
|
"go-admin/models"
|
||||||
|
"go-admin/tools"
|
||||||
"go-admin/tools/app"
|
"go-admin/tools/app"
|
||||||
"go-admin/pkg"
|
"go-admin/tools/app/msg"
|
||||||
"go-admin/utils"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Get{{.ClassName}}List(c *gin.Context) {
|
func Get{{.ClassName}}List(c *gin.Context) {
|
||||||
@@ -17,10 +16,10 @@ func Get{{.ClassName}}List(c *gin.Context) {
|
|||||||
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 = tools.StrToInt(err, size)
|
||||||
}
|
}
|
||||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||||
pageIndex = pkg.StrToInt(err, index)
|
pageIndex = tools.StrToInt(err, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
@@ -29,67 +28,49 @@ func Get{{.ClassName}}List(c *gin.Context) {
|
|||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
data.DataScope = utils.GetUserIdStr(c)
|
data.DataScope = tools.GetUserIdStr(c)
|
||||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||||
pkg.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
|
|
||||||
var mp = make(map[string]interface{}, 3)
|
app.PageOK(c, result, count, pageIndex, pageSize, "")
|
||||||
mp["list"] = result
|
|
||||||
mp["count"] = count
|
|
||||||
mp["pageIndex"] = pageIndex
|
|
||||||
mp["pageIndex"] = pageSize
|
|
||||||
|
|
||||||
var res models.Response
|
|
||||||
res.Data = mp
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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}}, _ = tools.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||||
result, err := data.Get()
|
result, err := data.Get()
|
||||||
pkg.HasError(err, "抱歉未找到相关信息", -1)
|
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||||
|
|
||||||
var res models.Response
|
app.OK(c, result, "")
|
||||||
res.Data = result
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.ShouldBindJSON(&data)
|
||||||
data.CreateBy = utils.GetUserIdStr(c)
|
data.CreateBy = tools.GetUserIdStr(c)
|
||||||
pkg.HasError(err, "", 500)
|
tools.HasError(err, "", 500)
|
||||||
result, err := data.Create()
|
result, err := data.Create()
|
||||||
pkg.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
var res models.Response
|
app.OK(c, result, "")
|
||||||
res.Data = result
|
|
||||||
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)
|
tools.HasError(err, "数据解析失败", -1)
|
||||||
data.UpdateBy = utils.GetUserIdStr(c)
|
data.UpdateBy = tools.GetUserIdStr(c)
|
||||||
result, err := data.Update(data.{{.PkGoField}})
|
result, err := data.Update(data.{{.PkGoField}})
|
||||||
pkg.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
|
|
||||||
var res models.Response
|
app.OK(c, result, "")
|
||||||
res.Data = result
|
|
||||||
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}}"))
|
data.UpdateBy = tools.GetUserIdStr(c)
|
||||||
data.UpdateBy = utils.GetUserIdStr(c)
|
|
||||||
_, err = data.Delete(id)
|
|
||||||
pkg.HasError(err, "修改失败", 500)
|
|
||||||
|
|
||||||
var res models.Response
|
IDS := tools.IdsStrToIdsIntGroup("{{.PkJsonField}}", c)
|
||||||
res.Msg = "删除成功"
|
_, err := data.BatchDelete(IDS)
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
tools.HasError(err, msg.DeletedFail, 500)
|
||||||
|
app.OK(c, nil, msg.DeletedSuccess)
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
// 查询参数列表
|
// 查询{{.ClassName}}列表
|
||||||
export function list{{.ClassName}}(query) {
|
export function list{{.ClassName}}(query) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}List',
|
url: '/api/v1/{{.ModuleName}}List',
|
||||||
@@ -9,7 +9,7 @@ params: query
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询参数详细
|
// 查询{{.ClassName}}详细
|
||||||
export function get{{.ClassName}} ({{.PkJsonField}}) {
|
export function get{{.ClassName}} ({{.PkJsonField}}) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}},
|
url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}},
|
||||||
@@ -18,7 +18,7 @@ method: 'get'
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 新增参数配置
|
// 新增{{.ClassName}}
|
||||||
export function add{{.ClassName}}(data) {
|
export function add{{.ClassName}}(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}',
|
url: '/api/v1/{{.ModuleName}}',
|
||||||
@@ -27,7 +27,7 @@ data: data
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改参数配置
|
// 修改{{.ClassName}}
|
||||||
export function update{{.ClassName}}(data) {
|
export function update{{.ClassName}}(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}',
|
url: '/api/v1/{{.ModuleName}}',
|
||||||
@@ -36,7 +36,7 @@ data: data
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除参数配置
|
// 删除{{.ClassName}}
|
||||||
export function del{{.ClassName}}({{.PkJsonField}}) {
|
export function del{{.ClassName}}({{.PkJsonField}}) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}},
|
url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}},
|
||||||
|
|||||||
+33
-17
@@ -2,8 +2,8 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
orm "go-admin/database"
|
orm "go-admin/database"
|
||||||
"go-admin/utils"
|
"go-admin/tools"
|
||||||
"time"
|
_ "time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type {{.ClassName}} struct {
|
type {{.ClassName}} struct {
|
||||||
@@ -11,12 +11,19 @@ type {{.ClassName}} struct {
|
|||||||
{{$x := .Pk}}
|
{{$x := .Pk}}
|
||||||
{{if ($x)}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"`{{else}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"`{{end}} // {{.ColumnComment}}
|
{{if ($x)}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"`{{else}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"`{{end}} // {{.ColumnComment}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
DataScope string `json:"dataScope" gorm:"-"`
|
||||||
|
Params string `json:"params" gorm:"-"`
|
||||||
|
BaseModel
|
||||||
|
}
|
||||||
|
|
||||||
|
func ({{.ClassName}}) TableName() string {
|
||||||
|
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("{{.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
|
||||||
@@ -25,11 +32,12 @@ func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
|
|||||||
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(e.TableName())
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$z := .IsQuery}}
|
{{$z := .IsQuery}}
|
||||||
{{- if ($z) -}}
|
{{- if ($z) -}}
|
||||||
@@ -46,10 +54,10 @@ func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取{{.ClassName}}带分页
|
// 获取{{.ClassName}}带分页
|
||||||
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int32, error) {
|
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int, error) {
|
||||||
var doc []{{.ClassName}}
|
var doc []{{.ClassName}}
|
||||||
|
|
||||||
table := orm.Eloquent.Select("*").Table("{{.TableName}}")
|
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$z := .IsQuery}}
|
{{$z := .IsQuery}}
|
||||||
{{- if ($z) -}}
|
{{- if ($z) -}}
|
||||||
@@ -59,14 +67,14 @@ func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}},
|
|||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
// 数据权限控制
|
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||||
dataPermission := new(DataPermission)
|
dataPermission := new(DataPermission)
|
||||||
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
|
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||||
table = dataPermission.GetDataScope("{{.TableName}}", table)
|
table = dataPermission.GetDataScope(e.TableName(), table)
|
||||||
|
|
||||||
var count int32
|
var count int
|
||||||
table = table.Offset((pageIndex - 1) * pageSize).Limit(pageSize)
|
|
||||||
if err := table.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.Count(&count)
|
table.Count(&count)
|
||||||
@@ -74,22 +82,22 @@ func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}},
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新{{.ClassName}}
|
// 更新{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Update(id int64) (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(e.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(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除{{.ClassName}}
|
// 删除{{.ClassName}}
|
||||||
func (e *{{.ClassName}}) Delete(id int64) (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(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||||
success = false
|
success = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -97,3 +105,11 @@ func (e *{{.ClassName}}) Delete(id int64) (success bool, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//批量删除
|
||||||
|
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 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Result = true
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
{{range .Columns}}
|
{{range .Columns}}
|
||||||
{{- $x := .IsQuery -}}
|
{{- $x := .IsQuery -}}
|
||||||
{{- if ($x) -}}
|
{{- if ($x) -}}
|
||||||
<el-form-item label="参数名称" prop="{{.JsonField}}">
|
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
||||||
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable size="small" @keyup.enter.native="handleQuery" />
|
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable size="small" @keyup.enter.native="handleQuery" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
{{end}}
|
{{end}}
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="configList" @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 -}}
|
||||||
@@ -86,9 +86,6 @@
|
|||||||
<!-- 添加或修改参数配置对话框 -->
|
<!-- 添加或修改参数配置对话框 -->
|
||||||
<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">
|
||||||
<el-form-item label="参数名称" prop="configName">
|
|
||||||
<el-input v-model="form.configName" placeholder="请输入参数名称" />
|
|
||||||
</el-form-item>
|
|
||||||
{{ range .Columns }}
|
{{ range .Columns }}
|
||||||
{{- $x := .IsInsert -}}
|
{{- $x := .IsInsert -}}
|
||||||
{{- if ($x) -}}
|
{{- if ($x) -}}
|
||||||
@@ -107,8 +104,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { list{{.ClassName}}, get{{.ClassName}}, del{{.ClassName}}, add{{.ClassName}}, update{{.ClassName}} } from '@/api/system/config'
|
import { list{{.ClassName}}, get{{.ClassName}}, del{{.ClassName}}, add{{.ClassName}}, update{{.ClassName}} } from '@/api/{{.PackageName}}'
|
||||||
import { formatJson } from '@/utils'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Config',
|
name: 'Config',
|
||||||
@@ -173,7 +169,7 @@
|
|||||||
this.loading = false
|
this.loading = false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
// 取消按钮
|
// 取消按钮
|
||||||
cancel() {
|
cancel() {
|
||||||
this.open = false
|
this.open = false
|
||||||
|
|||||||
Reference in new issue
Block a user