代码生成:批量删除

This commit is contained in:
xiangheng
2024-09-12 13:43:18 +08:00
parent 79fb646900
commit 537efc0e50
13 changed files with 360 additions and 203 deletions

View File

@@ -36,11 +36,17 @@ export type type_user_protocol_edit = {
// 用户协议列表 // 用户协议列表
export function user_protocol_list(params?: type_user_protocol_query) { export function user_protocol_list(params?: type_user_protocol_query) {
return request.get<Pages<type_user_protocol>>({ url: '/user_protocol/list', params: clearEmpty(params) }) return request.get<Pages<type_user_protocol>>({
url: '/user_protocol/list',
params: clearEmpty(params)
})
} }
// 用户协议列表-所有 // 用户协议列表-所有
export function user_protocol_list_all(params?: type_user_protocol_query) { export function user_protocol_list_all(params?: type_user_protocol_query) {
return request.get<type_user_protocol[]>({ url: '/user_protocol/listAll', params: clearEmpty(params) }) return request.get<type_user_protocol[]>({
url: '/user_protocol/listAll',
params: clearEmpty(params)
})
} }
// 用户协议详情 // 用户协议详情
@@ -62,11 +68,17 @@ export function user_protocol_edit(data: type_user_protocol_edit) {
export function user_protocol_delete(Id: number | string) { export function user_protocol_delete(Id: number | string) {
return request.post<null>({ url: '/user_protocol/del', data: { Id } }) return request.post<null>({ url: '/user_protocol/del', data: { Id } })
} }
// 用户协议批量删除
export function user_protocol_delete_batch(data: { Ids: string }) {
return request.post<null>({ url: '/user_protocol/delBatch', data })
}
// 用户协议导入 // 用户协议导入
export const user_protocol_import_file = '/user_protocol/ImportFile' export const user_protocol_import_file = '/user_protocol/ImportFile'
// 用户协议导出 // 用户协议导出
export function user_protocol_export_file(params: any) { export function user_protocol_export_file(params: any) {
return (window.location.href =`${config.baseUrl}${config.urlPrefix}/user_protocol/ExportFile?token=${getToken()}&` + queryString.stringify(clearEmpty(params))) return (window.location.href =
`${config.baseUrl}${config.urlPrefix}/user_protocol/ExportFile?token=${getToken()}&` +
queryString.stringify(clearEmpty(params)))
} }

View File

@@ -1,8 +1,14 @@
<template> <template>
<div class="index-lists"> <div class="index-lists">
<el-card class="!border-none" shadow="never"> <el-card class="!border-none" shadow="never">
<el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true" label-width="70px" <el-form
label-position="left"> ref="formRef"
class="mb-[-16px]"
:model="queryParams"
:inline="true"
label-width="70px"
label-position="left"
>
<el-form-item label="标题" prop="Title" class="w-[280px]"> <el-form-item label="标题" prop="Title" class="w-[280px]">
<el-input v-model="queryParams.Title" /> <el-input v-model="queryParams.Title" />
</el-form-item> </el-form-item>
@@ -26,7 +32,11 @@
</el-card> </el-card>
<el-card class="!border-none mt-4" shadow="never"> <el-card class="!border-none mt-4" shadow="never">
<div> <div>
<el-button v-perms="['admin:user_protocol:add']" type="primary" @click="handleAdd()"> <el-button
v-perms="['admin:user_protocol:add']"
type="primary"
@click="handleAdd()"
>
<template #icon> <template #icon>
<icon name="el-icon-Plus" /> <icon name="el-icon-Plus" />
</template> </template>
@@ -53,13 +63,23 @@
</template> </template>
导出 导出
</el-button> </el-button>
<el-button
v-perms="['admin:user_protocol:delBatch']"
type="danger"
@click="deleteBatch"
>
批量删除
</el-button>
</div> </div>
<el-table <el-table
class="mt-4" class="mt-4"
size="large" size="large"
v-loading="pager.loading" v-loading="pager.loading"
:data="pager.lists" :data="pager.lists"
@selection-change="handleSelectionChange"
> >
<el-table-column type="selection" width="55" />
<el-table-column label="标题" prop="Title" min-width="130" /> <el-table-column label="标题" prop="Title" min-width="130" />
<el-table-column label="协议内容" prop="Content" min-width="130" /> <el-table-column label="协议内容" prop="Content" min-width="130" />
<el-table-column label="排序" prop="Sort" min-width="130" /> <el-table-column label="排序" prop="Sort" min-width="130" />
@@ -90,18 +110,18 @@
<pagination v-model="pager" @change="getLists" /> <pagination v-model="pager" @change="getLists" />
</div> </div>
</el-card> </el-card>
<edit-popup <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
v-if="showEdit"
ref="editRef"
@success="getLists"
@close="showEdit = false"
/>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { user_protocol_delete, user_protocol_list,user_protocol_import_file, user_protocol_export_file } from '@/api/user/protocol' import {
import type { type_user_protocol,type_user_protocol_query } from "@/api/user/protocol"; user_protocol_delete,
user_protocol_delete_batch,
user_protocol_list,
user_protocol_import_file,
user_protocol_export_file
} from '@/api/user/protocol'
import type { type_user_protocol, type_user_protocol_query } from '@/api/user/protocol'
import { useDictData, useListAllData } from '@/hooks/useDictOptions' import { useDictData, useListAllData } from '@/hooks/useDictOptions'
import type { type_dict } from '@/hooks/useDictOptions' import type { type_dict } from '@/hooks/useDictOptions'
@@ -110,7 +130,7 @@ import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback' import feedback from '@/utils/feedback'
import EditPopup from './edit.vue' import EditPopup from './edit.vue'
defineOptions({ defineOptions({
name:"user_protocol" name: 'user_protocol'
}) })
const editRef = shallowRef<InstanceType<typeof EditPopup>>() const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false) const showEdit = ref(false)
@@ -121,7 +141,7 @@ const queryParams = reactive<type_user_protocol_query>({
CreateTimeStart: null, CreateTimeStart: null,
CreateTimeEnd: null, CreateTimeEnd: null,
UpdateTimeStart: null, UpdateTimeStart: null,
UpdateTimeEnd: null, UpdateTimeEnd: null
}) })
const { pager, getLists, resetPage, resetParams } = usePaging<type_user_protocol>({ const { pager, getLists, resetPage, resetParams } = usePaging<type_user_protocol>({
@@ -129,7 +149,6 @@ const { pager, getLists, resetPage, resetParams } = usePaging<type_user_protocol
params: queryParams params: queryParams
}) })
const handleAdd = async () => { const handleAdd = async () => {
showEdit.value = true showEdit.value = true
await nextTick() await nextTick()
@@ -142,7 +161,11 @@ const handleEdit = async (data: any) => {
editRef.value?.open('edit') editRef.value?.open('edit')
editRef.value?.getDetail(data) editRef.value?.getDetail(data)
} }
const multipleSelection = ref<type_user_protocol[]>([])
const handleSelectionChange = (val: type_user_protocol[]) => {
console.log(val)
multipleSelection.value = val
}
const handleDelete = async (Id: number) => { const handleDelete = async (Id: number) => {
try { try {
await feedback.confirm('确定要删除?') await feedback.confirm('确定要删除?')
@@ -151,6 +174,21 @@ const handleDelete = async (Id: number) => {
getLists() getLists()
} catch (error) {} } catch (error) {}
} }
// 批量删除
const deleteBatch = async () => {
if (multipleSelection.value.length === 0) {
feedback.msgError('请选择要删除的数据')
return
}
try {
await feedback.confirm('确定要删除?')
await user_protocol_delete_batch({
Ids: multipleSelection.value.map((item) => item.Id).join(',')
})
feedback.msgSuccess('删除成功')
getLists()
} catch (error) {}
}
const exportFile = async () => { const exportFile = async () => {
try { try {
await feedback.confirm('确定要导出?') await feedback.confirm('确定要导出?')

View File

@@ -153,7 +153,26 @@ func (hd *{{{ toUpperCamelCase .ModuleName }}}Handler) Del(c *gin.Context) {
response.CheckAndResp(c, {{{ toUpperCamelCase .EntityName }}}Service.Del(delReq.{{{ toUpperCamelCase .PrimaryKey }}})) response.CheckAndResp(c, {{{ toUpperCamelCase .EntityName }}}Service.Del(delReq.{{{ toUpperCamelCase .PrimaryKey }}}))
} }
// @Summary {{{ .FunctionName }}}删除-批量
// @Tags {{{ .ModuleName }}}-{{{ .FunctionName }}}
// @Produce json
// @Param Token header string true "token"
// @Param Ids body string false "逗号分割的id"
// @Success 200 {object} response.Response "成功"
// @Router /api/admin/{{{ .ModuleName }}}/delBatch [post]
func (hd *UserProtocolHandler) DelBatch(c *gin.Context) {
var delReq {{{ toUpperCamelCase .EntityName }}}DelBatchReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
return
}
if delReq.Ids == "" {
response.FailWithMsg(c, response.SystemError, "请选择要删除的数据")
return
}
var Ids = strings.Split(delReq.Ids, ",")
response.CheckAndResp(c, {{{ toUpperCamelCase .EntityName }}}Service.DelBatch(Ids))
}

View File

@@ -19,6 +19,7 @@ import (
admin:{{{ .ModuleName }}}:add admin:{{{ .ModuleName }}}:add
admin:{{{.ModuleName }}}:edit admin:{{{.ModuleName }}}:edit
admin:{{{.ModuleName }}}:del admin:{{{.ModuleName }}}:del
admin:{{{.ModuleName }}}:delBatch
admin:{{{.ModuleName }}}:list admin:{{{.ModuleName }}}:list
admin:{{{.ModuleName }}}:listAll admin:{{{.ModuleName }}}:listAll
admin:{{{.ModuleName }}}:detail admin:{{{.ModuleName }}}:detail
@@ -32,6 +33,7 @@ INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, paths, component, is
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}添加','admin:{{{ .ModuleName }}}:add', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}添加','admin:{{{ .ModuleName }}}:add', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}编辑','admin:{{{ .ModuleName }}}:edit', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}编辑','admin:{{{ .ModuleName }}}:edit', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}删除','admin:{{{ .ModuleName }}}:del', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}删除','admin:{{{ .ModuleName }}}:del', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}删除-批量','admin:{{{ .ModuleName }}}:delBatch', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}列表','admin:{{{ .ModuleName }}}:list', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}列表','admin:{{{ .ModuleName }}}:list', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}全部列表','admin:{{{ .ModuleName }}}:listAll', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}全部列表','admin:{{{ .ModuleName }}}:listAll', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}详情','admin:{{{ .ModuleName }}}:detail', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}详情','admin:{{{ .ModuleName }}}:detail', 0, 1, 0, now(), now());
@@ -48,9 +50,13 @@ func {{{ toUpperCamelCase .ModuleName }}}Route(rg *gin.RouterGroup) {
r.GET("/{{{ .ModuleName }}}/list", handle.List) r.GET("/{{{ .ModuleName }}}/list", handle.List)
r.GET("/{{{ .ModuleName }}}/listAll", handle.ListAll) r.GET("/{{{ .ModuleName }}}/listAll", handle.ListAll)
r.GET("/{{{ .ModuleName }}}/detail", handle.Detail) r.GET("/{{{ .ModuleName }}}/detail", handle.Detail)
r.POST("/{{{ .ModuleName }}}/add",middleware.RecordLog("{{{ .FunctionName }}}新增"), handle.Add) r.POST("/{{{ .ModuleName }}}/add",middleware.RecordLog("{{{ .FunctionName }}}新增"), handle.Add)
r.POST("/{{{ .ModuleName }}}/edit",middleware.RecordLog("{{{ .FunctionName }}}编辑"), handle.Edit) r.POST("/{{{ .ModuleName }}}/edit",middleware.RecordLog("{{{ .FunctionName }}}编辑"), handle.Edit)
r.POST("/{{{ .ModuleName }}}/del", middleware.RecordLog("{{{ .FunctionName }}}删除"), handle.Del) r.POST("/{{{ .ModuleName }}}/del", middleware.RecordLog("{{{ .FunctionName }}}删除"), handle.Del)
r.POST("/{{{ .ModuleName }}}/delBatch", middleware.RecordLog("{{{ .FunctionName }}}删除-批量"), handle.DelBatch)
r.GET("/{{{ .ModuleName }}}/ExportFile", middleware.RecordLog("{{{ .FunctionName }}}导出"), handle.ExportFile) r.GET("/{{{ .ModuleName }}}/ExportFile", middleware.RecordLog("{{{ .FunctionName }}}导出"), handle.ExportFile)
r.POST("/{{{ .ModuleName }}}/ImportFile", handle.ImportFile) r.POST("/{{{ .ModuleName }}}/ImportFile", handle.ImportFile)
} }

View File

@@ -9,10 +9,10 @@ type {{{ toUpperCamelCase .EntityName }}}ListReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsQuery }}} {{{- if .IsQuery }}}
{{{- if eq .HtmlType "datetime" }}} {{{- if eq .HtmlType "datetime" }}}
{{{ toUpperCamelCase .GoField }}}Start *string `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}}Start *string // {{{ .ColumnComment }}}
{{{ toUpperCamelCase .GoField }}}End *string `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}}End *string // {{{ .ColumnComment }}}
{{{- else }}} {{{- else }}}
{{{ toUpperCamelCase .GoField }}} *{{{.GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} *{{{.GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
@@ -24,7 +24,7 @@ type {{{ toUpperCamelCase .EntityName }}}ListReq struct {
type {{{ toUpperCamelCase .EntityName }}}AddReq struct { type {{{ toUpperCamelCase .EntityName }}}AddReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsInsert }}} {{{- if .IsInsert }}}
{{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
} }
@@ -34,9 +34,9 @@ type {{{ toUpperCamelCase .EntityName }}}EditReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsEdit }}} {{{- if .IsEdit }}}
{{{- if .IsPk }}} {{{- if .IsPk }}}
{{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} // {{{ .ColumnComment }}}
{{{- else }}} {{{- else }}}
{{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{goWithAddEditType .GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
@@ -46,7 +46,7 @@ type {{{ toUpperCamelCase .EntityName }}}EditReq struct {
type {{{ toUpperCamelCase .EntityName }}}DetailReq struct { type {{{ toUpperCamelCase .EntityName }}}DetailReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsPk }}} {{{- if .IsPk }}}
{{{ toUpperCamelCase .GoField }}} {{{.GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{.GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
} }
@@ -55,19 +55,24 @@ type {{{ toUpperCamelCase .EntityName }}}DetailReq struct {
type {{{ toUpperCamelCase .EntityName }}}DelReq struct { type {{{ toUpperCamelCase .EntityName }}}DelReq struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsPk }}} {{{- if .IsPk }}}
{{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{ .GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
} }
//{{{ toUpperCamelCase .EntityName }}}DelReq {{{ .FunctionName }}}批量删除参数
type {{{ toUpperCamelCase .EntityName }}}DelBatchReq struct {
Ids string
}
//{{{ toUpperCamelCase .EntityName }}}Resp {{{ .FunctionName }}}返回信息 //{{{ toUpperCamelCase .EntityName }}}Resp {{{ .FunctionName }}}返回信息
type {{{ toUpperCamelCase .EntityName }}}Resp struct { type {{{ toUpperCamelCase .EntityName }}}Resp struct {
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if or .IsList .IsPk }}} {{{- if or .IsList .IsPk }}}
{{{- if .IsPk }}} {{{- if .IsPk }}}
{{{ toUpperCamelCase .GoField }}} {{{.GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{.GoType }}} // {{{ .ColumnComment }}}
{{{- else }}} {{{- else }}}
{{{ toUpperCamelCase .GoField }}} {{{goWithRespType .GoType }}} `` // {{{ .ColumnComment }}} {{{ toUpperCamelCase .GoField }}} {{{goWithRespType .GoType }}} // {{{ .ColumnComment }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}

View File

@@ -192,6 +192,13 @@ func (service {{{ toCamelCase .EntityName }}}Service) Del({{{ toUpperCamelCase .
return return
} }
// DelBatch 用户协议-批量删除
func (service {{{ toCamelCase .EntityName }}}Service) DelBatch(Ids []string) (e error) {
var obj model.{{{ toUpperCamelCase .EntityName }}}
err := service.db.Where("{{{ $.PrimaryKey }}} in (?)", Ids).Delete(&obj).Error
return err
}
// 获取Excel的列 // 获取Excel的列
func (service {{{ toCamelCase .EntityName }}}Service) GetExcelCol() []excel2.Col { func (service {{{ toCamelCase .EntityName }}}Service) GetExcelCol() []excel2.Col {
var cols = []excel2.Col{ var cols = []excel2.Col{

View File

@@ -61,6 +61,10 @@ export function {{{.ModuleName}}}_edit(data: type_{{{.ModuleName}}}_edit) {
export function {{{.ModuleName}}}_delete({{{toUpperCamelCase .PrimaryKey }}}: number | string) { export function {{{.ModuleName}}}_delete({{{toUpperCamelCase .PrimaryKey }}}: number | string) {
return request.post<null>({ url: '/{{{.ModuleName}}}/del', data: { {{{toUpperCamelCase .PrimaryKey }}} } }) return request.post<null>({ url: '/{{{.ModuleName}}}/del', data: { {{{toUpperCamelCase .PrimaryKey }}} } })
} }
// {{{.FunctionName}}}删除-批量
export function {{{.ModuleName}}}_delete_batch(data: { Ids: string }) {
return request.post<null>({ url: '/{{{.ModuleName}}}/delBatch', data })
}
// {{{.FunctionName}}}导入 // {{{.FunctionName}}}导入
export const {{{.ModuleName}}}_import_file = '/{{{.ModuleName}}}/ImportFile' export const {{{.ModuleName}}}_import_file = '/{{{.ModuleName}}}/ImportFile'

View File

@@ -62,6 +62,7 @@
新增 新增
</el-button> </el-button>
<upload <upload
v-perms="['admin:{{{ .ModuleName }}}:ImportFile']"
class="ml-3 mr-3" class="ml-3 mr-3"
:url="{{{.ModuleName}}}_import_file" :url="{{{.ModuleName}}}_import_file"
:data="{ cid: 0 }" :data="{ cid: 0 }"
@@ -76,19 +77,28 @@
导入 导入
</el-button> </el-button>
</upload> </upload>
<el-button type="primary" @click="exportFile"> <el-button v-perms="['admin:{{{ .ModuleName }}}:ExportFile']" type="primary" @click="exportFile">
<template #icon> <template #icon>
<icon name="el-icon-Download" /> <icon name="el-icon-Download" />
</template> </template>
导出 导出
</el-button> </el-button>
<el-button
v-perms="['admin:{{{ .ModuleName }}}:delBatch']"
type="danger"
@click="deleteBatch"
>
批量删除
</el-button>
</div> </div>
<el-table <el-table
class="mt-4" class="mt-4"
size="large" size="large"
v-loading="pager.loading" v-loading="pager.loading"
:data="pager.lists" :data="pager.lists"
@selection-change="handleSelectionChange"
> >
<el-table-column type="selection" width="55" />
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsList }}} {{{- if .IsList }}}
{{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}} {{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
@@ -162,7 +172,7 @@
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { {{{ .ModuleName }}}_delete, {{{ .ModuleName }}}_list,{{{.ModuleName}}}_import_file, {{{.ModuleName}}}_export_file } from '@/api/{{{nameToPath .ModuleName }}}' import { {{{ .ModuleName }}}_delete,{{{ .ModuleName }}}_delete_batch, {{{ .ModuleName }}}_list,{{{.ModuleName}}}_import_file, {{{.ModuleName}}}_export_file } from '@/api/{{{nameToPath .ModuleName }}}'
import type { type_{{{ .ModuleName }}},type_{{{.ModuleName}}}_query } from "@/api/{{{nameToPath .ModuleName }}}"; import type { type_{{{ .ModuleName }}},type_{{{.ModuleName}}}_query } from "@/api/{{{nameToPath .ModuleName }}}";
@@ -230,6 +240,11 @@ const handleEdit = async (data: any) => {
editRef.value?.open('edit') editRef.value?.open('edit')
editRef.value?.getDetail(data) editRef.value?.getDetail(data)
} }
const multipleSelection = ref<type_{{{ .ModuleName }}}[]>([])
const handleSelectionChange = (val: type_{{{ .ModuleName }}}[]) => {
console.log(val)
multipleSelection.value = val
}
const handleDelete = async ({{{toUpperCamelCase .PrimaryKey }}}: number) => { const handleDelete = async ({{{toUpperCamelCase .PrimaryKey }}}: number) => {
try { try {
@@ -239,6 +254,22 @@ const handleDelete = async ({{{toUpperCamelCase .PrimaryKey }}}: number) => {
getLists() getLists()
} catch (error) {} } catch (error) {}
} }
// 批量删除
const deleteBatch = async () => {
if (multipleSelection.value.length === 0) {
feedback.msgError('请选择要删除的数据')
return
}
try {
await feedback.confirm('确定要删除?')
await {{{ .ModuleName }}}_delete_batch({
Ids: multipleSelection.value.map((item) => item.{{{toUpperCamelCase .PrimaryKey }}}).join(',')
})
feedback.msgSuccess('删除成功')
getLists()
} catch (error) {}
}
const exportFile = async () => { const exportFile = async () => {
try { try {
await feedback.confirm('确定要导出?') await feedback.confirm('确定要导出?')

View File

@@ -3,16 +3,17 @@ package user_protocol
import ( import (
"net/http" "net/http"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/gin-gonic/gin"
"x_admin/core/request" "x_admin/core/request"
"x_admin/core/response" "x_admin/core/response"
"x_admin/util" "x_admin/util"
"x_admin/util/excel2" "x_admin/util/excel2"
"github.com/gin-gonic/gin"
"golang.org/x/sync/singleflight" "golang.org/x/sync/singleflight"
) )
type UserProtocolHandler struct { type UserProtocolHandler struct {
requestGroup singleflight.Group requestGroup singleflight.Group
} }
@@ -30,6 +31,7 @@ type UserProtocolHandler struct {
// @Param CreateTimeEnd query string false "创建时间" // @Param CreateTimeEnd query string false "创建时间"
// @Param UpdateTimeStart query string false "更新时间" // @Param UpdateTimeStart query string false "更新时间"
// @Param UpdateTimeEnd query string false "更新时间" // @Param UpdateTimeEnd query string false "更新时间"
//
// @Success 200 {object} response.Response{ data=response.PageResp{ lists=[]UserProtocolResp}} "成功" // @Success 200 {object} response.Response{ data=response.PageResp{ lists=[]UserProtocolResp}} "成功"
// @Router /api/admin/user_protocol/list [get] // @Router /api/admin/user_protocol/list [get]
func (hd *UserProtocolHandler) List(c *gin.Context) { func (hd *UserProtocolHandler) List(c *gin.Context) {
@@ -86,7 +88,6 @@ func (hd *UserProtocolHandler) Detail(c *gin.Context) {
response.CheckAndRespWithData(c, res, err) response.CheckAndRespWithData(c, res, err)
} }
// @Summary 用户协议新增 // @Summary 用户协议新增
// @Tags user_protocol-用户协议 // @Tags user_protocol-用户协议
// @Produce json // @Produce json
@@ -104,6 +105,7 @@ func (hd *UserProtocolHandler) Add(c *gin.Context) {
createId, e := UserProtocolService.Add(addReq) createId, e := UserProtocolService.Add(addReq)
response.CheckAndRespWithData(c, createId, e) response.CheckAndRespWithData(c, createId, e)
} }
// @Summary 用户协议编辑 // @Summary 用户协议编辑
// @Tags user_protocol-用户协议 // @Tags user_protocol-用户协议
// @Produce json // @Produce json
@@ -121,6 +123,7 @@ func (hd *UserProtocolHandler) Edit(c *gin.Context) {
} }
response.CheckAndRespWithData(c, editReq.Id, UserProtocolService.Edit(editReq)) response.CheckAndRespWithData(c, editReq.Id, UserProtocolService.Edit(editReq))
} }
// @Summary 用户协议删除 // @Summary 用户协议删除
// @Tags user_protocol-用户协议 // @Tags user_protocol-用户协议
// @Produce json // @Produce json
@@ -136,9 +139,28 @@ func (hd *UserProtocolHandler) Del(c *gin.Context) {
response.CheckAndResp(c, UserProtocolService.Del(delReq.Id)) response.CheckAndResp(c, UserProtocolService.Del(delReq.Id))
} }
// @Summary 用户协议批量删除
// @Tags user_protocol-用户协议
// @Produce json
// @Param Token header string true "token"
// @Param Ids body string false "逗号分割的id"
// @Success 200 {object} response.Response "成功"
// @Router /api/admin/user_protocol/delBatch [post]
func (hd *UserProtocolHandler) DelBatch(c *gin.Context) {
var delReq UserProtocolDelBatchReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
return
}
if delReq.Ids == "" {
response.FailWithMsg(c, response.SystemError, "请选择要删除的数据")
return
}
var Ids = strings.Split(delReq.Ids, ",")
// if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
// return
// }
response.CheckAndResp(c, UserProtocolService.DelBatch(Ids))
}
// @Summary 用户协议导出 // @Summary 用户协议导出
// @Tags user_protocol-用户协议 // @Tags user_protocol-用户协议

View File

@@ -1,7 +1,7 @@
package user_protocol package user_protocol
import ( import (
"x_admin/core" "x_admin/core"
) )
// UserProtocolListReq 用户协议列表参数 // UserProtocolListReq 用户协议列表参数
@@ -15,8 +15,6 @@ type UserProtocolListReq struct {
UpdateTimeEnd *string `` // 结束更新时间 UpdateTimeEnd *string `` // 结束更新时间
} }
// UserProtocolAddReq 用户协议新增参数 // UserProtocolAddReq 用户协议新增参数
type UserProtocolAddReq struct { type UserProtocolAddReq struct {
Title *string `` // 标题 Title *string `` // 标题
@@ -41,6 +39,9 @@ type UserProtocolDetailReq struct {
type UserProtocolDelReq struct { type UserProtocolDelReq struct {
Id int `` // Id int `` //
} }
type UserProtocolDelBatchReq struct {
Ids string `` //
}
// UserProtocolResp 用户协议返回信息 // UserProtocolResp 用户协议返回信息
type UserProtocolResp struct { type UserProtocolResp struct {

View File

@@ -5,9 +5,10 @@ import (
"x_admin/core/request" "x_admin/core/request"
"x_admin/core/response" "x_admin/core/response"
"x_admin/model" "x_admin/model"
"gorm.io/gorm"
"x_admin/util" "x_admin/util"
"x_admin/util/excel2" "x_admin/util/excel2"
"gorm.io/gorm"
) )
var UserProtocolService = NewUserProtocolService() var UserProtocolService = NewUserProtocolService()
@@ -29,8 +30,6 @@ type userProtocolService struct {
Name string Name string
} }
// List 用户协议列表 // List 用户协议列表
func (service userProtocolService) GetModel(listReq UserProtocolListReq) *gorm.DB { func (service userProtocolService) GetModel(listReq UserProtocolListReq) *gorm.DB {
// 查询 // 查询
@@ -59,6 +58,7 @@ func (service userProtocolService) GetModel(listReq UserProtocolListReq) *gorm.D
dbModel = dbModel.Where("is_delete = ?", 0) dbModel = dbModel.Where("is_delete = ?", 0)
return dbModel return dbModel
} }
// List 用户协议列表 // List 用户协议列表
func (service userProtocolService) List(page request.PageReq, listReq UserProtocolListReq) (res response.PageResp, e error) { func (service userProtocolService) List(page request.PageReq, listReq UserProtocolListReq) (res response.PageResp, e error) {
// 分页信息 // 分页信息
@@ -86,6 +86,7 @@ func (service userProtocolService) List(page request.PageReq, listReq UserProtoc
Lists: result, Lists: result,
}, nil }, nil
} }
// ListAll 用户协议列表 // ListAll 用户协议列表
func (service userProtocolService) ListAll(listReq UserProtocolListReq) (res []UserProtocolResp, e error) { func (service userProtocolService) ListAll(listReq UserProtocolListReq) (res []UserProtocolResp, e error) {
dbModel := service.GetModel(listReq) dbModel := service.GetModel(listReq)
@@ -175,6 +176,13 @@ func (service userProtocolService) Del(Id int) (e error) {
return return
} }
// DelBatch 用户协议-批量删除
func (service userProtocolService) DelBatch(IdsArr []string) (e error) {
var obj model.UserProtocol
err := service.db.Where("id in (?)", IdsArr).Delete(&obj).Error
return err
}
// 获取Excel的列 // 获取Excel的列
func (service userProtocolService) GetExcelCol() []excel2.Col { func (service userProtocolService) GetExcelCol() []excel2.Col {
var cols = []excel2.Col{ var cols = []excel2.Col{

View File

@@ -1,9 +1,10 @@
package admin package admin
import ( import (
"github.com/gin-gonic/gin"
"x_admin/middleware"
"x_admin/admin/user_protocol" "x_admin/admin/user_protocol"
"x_admin/middleware"
"github.com/gin-gonic/gin"
) )
/** /**
@@ -32,6 +33,7 @@ INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, paths, component, is
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议添加','admin:user_protocol:add', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议添加','admin:user_protocol:add', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议编辑','admin:user_protocol:edit', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议编辑','admin:user_protocol:edit', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议删除','admin:user_protocol:del', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议删除','admin:user_protocol:del', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议批量删除','admin:user_protocol:delBatch', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议列表','admin:user_protocol:list', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议列表','admin:user_protocol:list', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议全部列表','admin:user_protocol:listAll', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议全部列表','admin:user_protocol:listAll', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议详情','admin:user_protocol:detail', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议详情','admin:user_protocol:detail', 0, 1, 0, now(), now());
@@ -39,7 +41,6 @@ INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_sh
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议导入excel','admin:user_protocol:ImportFile', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '用户协议导入excel','admin:user_protocol:ImportFile', 0, 1, 0, now(), now());
*/ */
// UserProtocolRoute(rg) // UserProtocolRoute(rg)
func UserProtocolRoute(rg *gin.RouterGroup) { func UserProtocolRoute(rg *gin.RouterGroup) {
handle := user_protocol.UserProtocolHandler{} handle := user_protocol.UserProtocolHandler{}
@@ -51,6 +52,9 @@ func UserProtocolRoute(rg *gin.RouterGroup) {
r.POST("/user_protocol/add", middleware.RecordLog("用户协议新增"), handle.Add) r.POST("/user_protocol/add", middleware.RecordLog("用户协议新增"), handle.Add)
r.POST("/user_protocol/edit", middleware.RecordLog("用户协议编辑"), handle.Edit) r.POST("/user_protocol/edit", middleware.RecordLog("用户协议编辑"), handle.Edit)
r.POST("/user_protocol/del", middleware.RecordLog("用户协议删除"), handle.Del) r.POST("/user_protocol/del", middleware.RecordLog("用户协议删除"), handle.Del)
r.POST("/user_protocol/delBatch", middleware.RecordLog("用户协议批量删除"), handle.DelBatch)
r.GET("/user_protocol/ExportFile", middleware.RecordLog("用户协议导出"), handle.ExportFile) r.GET("/user_protocol/ExportFile", middleware.RecordLog("用户协议导出"), handle.ExportFile)
r.POST("/user_protocol/ImportFile", handle.ImportFile) r.POST("/user_protocol/ImportFile", handle.ImportFile)
} }

View File

@@ -18,8 +18,8 @@ type Col struct {
Key string Key string
Width int // 宽度 Width int // 宽度
Replace map[string]any //实现值的替换 Replace map[string]any //实现值的替换
Encode func(value any) any //暂未使用 Encode func(value any) any //编码函数-导出先Encode后Replace
Decode func(value any) (any, error) //实现类型、值的替换 Decode func(value any) (any, error) //解码函数-导入先Replace后Decode
} }
// 定义编码接口 // 定义编码接口