Commit f4a8dd4d7d019955fa1705643eb1af620c9f7651

Authored by xingyu
1 parent 28ea779f

feat: 添加批量删除功能

yudao-ui-admin-vue3/src/components/XTable/src/XTable.vue
@@ -276,7 +276,7 @@ const reload = () => { @@ -276,7 +276,7 @@ const reload = () => {
276 } 276 }
277 277
278 // 删除 278 // 删除
279 -const deleteData = async (ids: string | number) => { 279 +const deleteData = async (id: string | number) => {
280 const g = unref(xGrid) 280 const g = unref(xGrid)
281 if (!g) { 281 if (!g) {
282 return 282 return
@@ -288,7 +288,7 @@ const deleteData = async (ids: string | number) => { @@ -288,7 +288,7 @@ const deleteData = async (ids: string | number) => {
288 } 288 }
289 return new Promise(async () => { 289 return new Promise(async () => {
290 message.delConfirm().then(async () => { 290 message.delConfirm().then(async () => {
291 - await (options?.deleteApi && options?.deleteApi(ids)) 291 + await (options?.deleteApi && options?.deleteApi(id))
292 message.success(t('common.delSuccess')) 292 message.success(t('common.delSuccess'))
293 // 刷新列表 293 // 刷新列表
294 reload() 294 reload()
@@ -296,6 +296,49 @@ const deleteData = async (ids: string | number) => { @@ -296,6 +296,49 @@ const deleteData = async (ids: string | number) => {
296 }) 296 })
297 } 297 }
298 298
  299 +// 批量删除
  300 +const deleteList = async () => {
  301 + const g = unref(xGrid)
  302 + if (!g) {
  303 + return
  304 + }
  305 + const rows = g.getCheckboxRecords() || g.getRadioRecord()
  306 + let ids: any[] = []
  307 + if (rows.length == 0) {
  308 + message.error('请选择数据')
  309 + return
  310 + } else {
  311 + rows.forEach((row) => {
  312 + ids.push(row.id)
  313 + })
  314 + }
  315 + const options = innerProps.value || props.options
  316 + if (options.deleteListApi) {
  317 + return new Promise(async () => {
  318 + message.delConfirm().then(async () => {
  319 + await (options?.deleteListApi && options?.deleteListApi(ids))
  320 + message.success(t('common.delSuccess'))
  321 + // 刷新列表
  322 + reload()
  323 + })
  324 + })
  325 + } else if (options.deleteApi) {
  326 + return new Promise(async () => {
  327 + message.delConfirm().then(async () => {
  328 + ids.forEach(async (id) => {
  329 + await (options?.deleteApi && options?.deleteApi(id))
  330 + })
  331 + message.success(t('common.delSuccess'))
  332 + // 刷新列表
  333 + reload()
  334 + })
  335 + })
  336 + } else {
  337 + console.error('未传入delListApi')
  338 + return
  339 + }
  340 +}
  341 +
299 // 导出 342 // 导出
300 const exportList = async (fileName?: string) => { 343 const exportList = async (fileName?: string) => {
301 const g = unref(xGrid) 344 const g = unref(xGrid)
@@ -360,6 +403,7 @@ emit('register', { @@ -360,6 +403,7 @@ emit('register', {
360 getSearchData, 403 getSearchData,
361 setProps, 404 setProps,
362 deleteData, 405 deleteData,
  406 + deleteList,
363 exportList, 407 exportList,
364 getCurrentColumn, 408 getCurrentColumn,
365 getRadioRecord, 409 getRadioRecord,
yudao-ui-admin-vue3/src/components/XTable/src/type.ts
@@ -10,6 +10,7 @@ export type XTableProps<D = any> = VxeGridProps<D> & { @@ -10,6 +10,7 @@ export type XTableProps<D = any> = VxeGridProps<D> & {
10 getListApi?: Function // 获取列表接口 10 getListApi?: Function // 获取列表接口
11 getAllListApi?: Function // 获取全部数据接口 用于 vxe 导出 11 getAllListApi?: Function // 获取全部数据接口 用于 vxe 导出
12 deleteApi?: Function // 删除接口 12 deleteApi?: Function // 删除接口
  13 + deleteListApi?: Function // 批量删除接口
13 exportListApi?: Function // 导出接口 14 exportListApi?: Function // 导出接口
14 exportName?: string // 导出文件夹名称 15 exportName?: string // 导出文件夹名称
15 params?: any // 其他查询参数 16 params?: any // 其他查询参数
yudao-ui-admin-vue3/src/hooks/web/useXTable.ts
@@ -4,7 +4,8 @@ import { XTableProps } from '@/components/XTable/src/type' @@ -4,7 +4,8 @@ import { XTableProps } from '@/components/XTable/src/type'
4 export interface tableMethod { 4 export interface tableMethod {
5 reload: () => void // 刷新表格 5 reload: () => void // 刷新表格
6 setProps: (props: XTableProps) => void 6 setProps: (props: XTableProps) => void
7 - deleteData: (ids: string | number) => void // 删除数据 7 + deleteData: (id: string | number) => void // 删除数据
  8 + deleteList: () => void // 批量删除
8 exportList: (fileName?: string) => void // 导出列表 9 exportList: (fileName?: string) => void // 导出列表
9 getCurrentColumn: () => void // 获取当前列 10 getCurrentColumn: () => void // 获取当前列
10 getRadioRecord: () => void // 获取当前选中列,redio 11 getRadioRecord: () => void // 获取当前选中列,redio
@@ -28,7 +29,8 @@ export const useXTable = (props: XTableProps): [Function, tableMethod] => { @@ -28,7 +29,8 @@ export const useXTable = (props: XTableProps): [Function, tableMethod] => {
28 const methods: tableMethod = { 29 const methods: tableMethod = {
29 reload: () => getInstance().reload(), 30 reload: () => getInstance().reload(),
30 setProps: (props) => getInstance().setProps(props), 31 setProps: (props) => getInstance().setProps(props),
31 - deleteData: (ids: string | number) => getInstance().deleteData(ids), 32 + deleteData: (id: string | number) => getInstance().deleteData(id),
  33 + deleteList: () => getInstance().deleteList(),
32 exportList: (fileName?: string) => getInstance().exportList(fileName), 34 exportList: (fileName?: string) => getInstance().exportList(fileName),
33 getCurrentColumn: () => getInstance().getCheckboxRecords(), 35 getCurrentColumn: () => getInstance().getCheckboxRecords(),
34 getRadioRecord: () => getInstance().getRadioRecord(), 36 getRadioRecord: () => getInstance().getRadioRecord(),