mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-21 20:35:16 +00:00
自动化代码增加 批量删除功能
This commit is contained in:
@@ -33,6 +33,22 @@ export const create{{.StructName}} = (data) => {
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 删除{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
|
||||
export const delete{{.StructName}}ByIds = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/delete{{.StructName}}ByIds",
|
||||
method: 'delete',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 更新{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
|
||||
@@ -27,10 +27,21 @@
|
||||
<el-form-item>
|
||||
<el-button @click="openDialog" type="primary">新增{{.Description}}</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-popover placement="top" v-model="deleteVisible" width="160">
|
||||
<p>确定要删除吗?</p>
|
||||
<div style="text-align: right; margin: 0">
|
||||
<el-button @click="deleteVisible = false" size="mini" type="text">取消</el-button>
|
||||
<el-button @click="onDelete" size="mini" type="primary">确定</el-button>
|
||||
</div>
|
||||
<el-button icon="el-icon-delete" size="mini" slot="reference" type="danger">批量删除</el-button>
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<el-table
|
||||
:data="tableData"
|
||||
@selection-change="handleSelectionChange"
|
||||
border
|
||||
ref="multipleTable"
|
||||
stripe
|
||||
@@ -87,6 +98,7 @@
|
||||
import {
|
||||
create{{.StructName}},
|
||||
delete{{.StructName}},
|
||||
delete{{.StructName}}ByIds,
|
||||
update{{.StructName}},
|
||||
find{{.StructName}},
|
||||
get{{.StructName}}List
|
||||
@@ -103,6 +115,8 @@ export default {
|
||||
dialogFormVisible: false,
|
||||
visible: false,
|
||||
type: "",
|
||||
deleteVisible: false,
|
||||
multipleSelection: [],
|
||||
formData: {
|
||||
{{range .Fields}}{{.FieldJson}}:null,{{ end }}
|
||||
}
|
||||
@@ -136,6 +150,25 @@ export default {
|
||||
} {{ end }} {{ end }}
|
||||
this.getTableData()
|
||||
},
|
||||
handleSelectionChange(val) {
|
||||
this.multipleSelection = val
|
||||
},
|
||||
async onDelete() {
|
||||
const ids = []
|
||||
this.multipleSelection &&
|
||||
this.multipleSelection.map(item => {
|
||||
ids.push(item.ID)
|
||||
})
|
||||
const res = await delete{{.StructName}}ByIds({ ids })
|
||||
if (res.code == 0) {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '删除成功'
|
||||
})
|
||||
this.deleteVisible = false
|
||||
this.getTableData()
|
||||
}
|
||||
},
|
||||
async update{{.StructName}}(row) {
|
||||
const res = await find{{.StructName}}({ ID: row.ID });
|
||||
this.type = "update";
|
||||
|
||||
@@ -48,6 +48,25 @@ func Delete{{.StructName}}(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 批量删除{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete]
|
||||
func Delete{{.StructName}}ByIds(c *gin.Context) {
|
||||
var IDS request.IdsReq
|
||||
_ = c.ShouldBindJSON(&IDS)
|
||||
err := service.Delete{{.StructName}}ByIds(IDS)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 更新{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
type {{.StructName}} struct {
|
||||
gorm.Model {{- range .Fields}}
|
||||
{{- if eq .FieldType "bool" }}
|
||||
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:'{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}'{{- end -}}"`
|
||||
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}}"`
|
||||
{{- else }}
|
||||
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:'{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}'{{- end -}}"`
|
||||
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}}"`
|
||||
{{- end }} {{- end }}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
)
|
||||
|
||||
func Init{{.StructName}}Router(Router *gin.RouterGroup) {
|
||||
{{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
|
||||
{{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()).Use(middleware.OperationRecord())
|
||||
{
|
||||
{{.StructName}}Router.POST("create{{.StructName}}", v1.Create{{.StructName}}) // 新建{{.StructName}}
|
||||
{{.StructName}}Router.DELETE("delete{{.StructName}}", v1.Delete{{.StructName}}) // 删除{{.StructName}}
|
||||
{{.StructName}}Router.DELETE("delete{{.StructName}}ByIds", v1.Delete{{.StructName}}ByIds) // 批量删除{{.StructName}}
|
||||
{{.StructName}}Router.PUT("update{{.StructName}}", v1.Update{{.StructName}}) // 更新{{.StructName}}
|
||||
{{.StructName}}Router.GET("find{{.StructName}}", v1.Find{{.StructName}}) // 根据ID获取{{.StructName}}
|
||||
{{.StructName}}Router.GET("get{{.StructName}}List", v1.Get{{.StructName}}List) // 获取{{.StructName}}列表
|
||||
|
||||
@@ -28,6 +28,17 @@ func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error)
|
||||
return err
|
||||
}
|
||||
|
||||
// @title Delete{{.StructName}}ByIds
|
||||
// @description delete {{.StructName}}s
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param {{.Abbreviation}} model.{{.StructName}}
|
||||
// @return error
|
||||
|
||||
func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
|
||||
err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in (?)",ids.Ids).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// @title Update{{.StructName}}
|
||||
// @description update a {{.StructName}}
|
||||
// @param {{.Abbreviation}} *model.{{.StructName}}
|
||||
|
||||
Reference in New Issue
Block a user