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 276 }
277 277  
278 278 // 删除
279   -const deleteData = async (ids: string | number) => {
  279 +const deleteData = async (id: string | number) => {
280 280 const g = unref(xGrid)
281 281 if (!g) {
282 282 return
... ... @@ -288,7 +288,7 @@ const deleteData = async (ids: string | number) => {
288 288 }
289 289 return new Promise(async () => {
290 290 message.delConfirm().then(async () => {
291   - await (options?.deleteApi && options?.deleteApi(ids))
  291 + await (options?.deleteApi && options?.deleteApi(id))
292 292 message.success(t('common.delSuccess'))
293 293 // 刷新列表
294 294 reload()
... ... @@ -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 343 const exportList = async (fileName?: string) => {
301 344 const g = unref(xGrid)
... ... @@ -360,6 +403,7 @@ emit('register', {
360 403 getSearchData,
361 404 setProps,
362 405 deleteData,
  406 + deleteList,
363 407 exportList,
364 408 getCurrentColumn,
365 409 getRadioRecord,
... ...
yudao-ui-admin-vue3/src/components/XTable/src/type.ts
... ... @@ -10,6 +10,7 @@ export type XTableProps<D = any> = VxeGridProps<D> & {
10 10 getListApi?: Function // 获取列表接口
11 11 getAllListApi?: Function // 获取全部数据接口 用于 vxe 导出
12 12 deleteApi?: Function // 删除接口
  13 + deleteListApi?: Function // 批量删除接口
13 14 exportListApi?: Function // 导出接口
14 15 exportName?: string // 导出文件夹名称
15 16 params?: any // 其他查询参数
... ...
yudao-ui-admin-vue3/src/hooks/web/useXTable.ts
... ... @@ -4,7 +4,8 @@ import { XTableProps } from '@/components/XTable/src/type'
4 4 export interface tableMethod {
5 5 reload: () => void // 刷新表格
6 6 setProps: (props: XTableProps) => void
7   - deleteData: (ids: string | number) => void // 删除数据
  7 + deleteData: (id: string | number) => void // 删除数据
  8 + deleteList: () => void // 批量删除
8 9 exportList: (fileName?: string) => void // 导出列表
9 10 getCurrentColumn: () => void // 获取当前列
10 11 getRadioRecord: () => void // 获取当前选中列,redio
... ... @@ -28,7 +29,8 @@ export const useXTable = (props: XTableProps): [Function, tableMethod] => {
28 29 const methods: tableMethod = {
29 30 reload: () => getInstance().reload(),
30 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 34 exportList: (fileName?: string) => getInstance().exportList(fileName),
33 35 getCurrentColumn: () => getInstance().getCheckboxRecords(),
34 36 getRadioRecord: () => getInstance().getRadioRecord(),
... ...