feat: 添加批量删除功能
parent
28ea779f83
commit
f4a8dd4d7d
|
@ -276,7 +276,7 @@ const reload = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
const deleteData = async (ids: string | number) => {
|
const deleteData = async (id: string | number) => {
|
||||||
const g = unref(xGrid)
|
const g = unref(xGrid)
|
||||||
if (!g) {
|
if (!g) {
|
||||||
return
|
return
|
||||||
|
@ -288,7 +288,7 @@ const deleteData = async (ids: string | number) => {
|
||||||
}
|
}
|
||||||
return new Promise(async () => {
|
return new Promise(async () => {
|
||||||
message.delConfirm().then(async () => {
|
message.delConfirm().then(async () => {
|
||||||
await (options?.deleteApi && options?.deleteApi(ids))
|
await (options?.deleteApi && options?.deleteApi(id))
|
||||||
message.success(t('common.delSuccess'))
|
message.success(t('common.delSuccess'))
|
||||||
// 刷新列表
|
// 刷新列表
|
||||||
reload()
|
reload()
|
||||||
|
@ -296,6 +296,49 @@ const deleteData = async (ids: string | number) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 批量删除
|
||||||
|
const deleteList = async () => {
|
||||||
|
const g = unref(xGrid)
|
||||||
|
if (!g) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const rows = g.getCheckboxRecords() || g.getRadioRecord()
|
||||||
|
let ids: any[] = []
|
||||||
|
if (rows.length == 0) {
|
||||||
|
message.error('请选择数据')
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
rows.forEach((row) => {
|
||||||
|
ids.push(row.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const options = innerProps.value || props.options
|
||||||
|
if (options.deleteListApi) {
|
||||||
|
return new Promise(async () => {
|
||||||
|
message.delConfirm().then(async () => {
|
||||||
|
await (options?.deleteListApi && options?.deleteListApi(ids))
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
// 刷新列表
|
||||||
|
reload()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else if (options.deleteApi) {
|
||||||
|
return new Promise(async () => {
|
||||||
|
message.delConfirm().then(async () => {
|
||||||
|
ids.forEach(async (id) => {
|
||||||
|
await (options?.deleteApi && options?.deleteApi(id))
|
||||||
|
})
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
// 刷新列表
|
||||||
|
reload()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.error('未传入delListApi')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
const exportList = async (fileName?: string) => {
|
const exportList = async (fileName?: string) => {
|
||||||
const g = unref(xGrid)
|
const g = unref(xGrid)
|
||||||
|
@ -360,6 +403,7 @@ emit('register', {
|
||||||
getSearchData,
|
getSearchData,
|
||||||
setProps,
|
setProps,
|
||||||
deleteData,
|
deleteData,
|
||||||
|
deleteList,
|
||||||
exportList,
|
exportList,
|
||||||
getCurrentColumn,
|
getCurrentColumn,
|
||||||
getRadioRecord,
|
getRadioRecord,
|
||||||
|
|
|
@ -10,6 +10,7 @@ export type XTableProps<D = any> = VxeGridProps<D> & {
|
||||||
getListApi?: Function // 获取列表接口
|
getListApi?: Function // 获取列表接口
|
||||||
getAllListApi?: Function // 获取全部数据接口 用于 vxe 导出
|
getAllListApi?: Function // 获取全部数据接口 用于 vxe 导出
|
||||||
deleteApi?: Function // 删除接口
|
deleteApi?: Function // 删除接口
|
||||||
|
deleteListApi?: Function // 批量删除接口
|
||||||
exportListApi?: Function // 导出接口
|
exportListApi?: Function // 导出接口
|
||||||
exportName?: string // 导出文件夹名称
|
exportName?: string // 导出文件夹名称
|
||||||
params?: any // 其他查询参数
|
params?: any // 其他查询参数
|
||||||
|
|
|
@ -4,7 +4,8 @@ import { XTableProps } from '@/components/XTable/src/type'
|
||||||
export interface tableMethod {
|
export interface tableMethod {
|
||||||
reload: () => void // 刷新表格
|
reload: () => void // 刷新表格
|
||||||
setProps: (props: XTableProps) => void
|
setProps: (props: XTableProps) => void
|
||||||
deleteData: (ids: string | number) => void // 删除数据
|
deleteData: (id: string | number) => void // 删除数据
|
||||||
|
deleteList: () => void // 批量删除
|
||||||
exportList: (fileName?: string) => void // 导出列表
|
exportList: (fileName?: string) => void // 导出列表
|
||||||
getCurrentColumn: () => void // 获取当前列
|
getCurrentColumn: () => void // 获取当前列
|
||||||
getRadioRecord: () => void // 获取当前选中列,redio
|
getRadioRecord: () => void // 获取当前选中列,redio
|
||||||
|
@ -28,7 +29,8 @@ export const useXTable = (props: XTableProps): [Function, tableMethod] => {
|
||||||
const methods: tableMethod = {
|
const methods: tableMethod = {
|
||||||
reload: () => getInstance().reload(),
|
reload: () => getInstance().reload(),
|
||||||
setProps: (props) => getInstance().setProps(props),
|
setProps: (props) => getInstance().setProps(props),
|
||||||
deleteData: (ids: string | number) => getInstance().deleteData(ids),
|
deleteData: (id: string | number) => getInstance().deleteData(id),
|
||||||
|
deleteList: () => getInstance().deleteList(),
|
||||||
exportList: (fileName?: string) => getInstance().exportList(fileName),
|
exportList: (fileName?: string) => getInstance().exportList(fileName),
|
||||||
getCurrentColumn: () => getInstance().getCheckboxRecords(),
|
getCurrentColumn: () => getInstance().getCheckboxRecords(),
|
||||||
getRadioRecord: () => getInstance().getRadioRecord(),
|
getRadioRecord: () => getInstance().getRadioRecord(),
|
||||||
|
|
Loading…
Reference in New Issue