ソースを参照

protable暴露编辑点击事件

tongshangming 3 年 前
コミット
3eec900c97
1 ファイル変更21 行追加11 行削除
  1. 21 11
      src/components/ProTable.vue

+ 21 - 11
src/components/ProTable.vue

@@ -13,9 +13,9 @@ interface CRUD {
   create: Function
   update: Function
   delete: Function
-  deleteBatch: Function
+  deleteBatch?: Function
   getList: Function
-  getRecord: Function
+  getRecord?: Function
 }
 interface CustomTable {
   showOperate?: boolean
@@ -38,6 +38,8 @@ const props = withDefaults(defineProps<Props>(), {
   showToolbar: true
 })
 
+const emits = defineEmits(['click-edit'])
+
 // ============== 查询部分开始 ===============
 const query = ref<any>({})
 const searchList = ref<any>([])
@@ -119,6 +121,7 @@ const handleCreate = () => {
   }
 }
 const handleUpdate = (row: any) => {
+  emits('click-edit', row)
   if (formRoute.value) {
     router.push(formRoute.value)
   } else {
@@ -148,14 +151,21 @@ const handleBatchDelete = () => {
   ElMessageBox.confirm('您确定要删除吗', '提示', {
     type: 'warning'
   }).then(async () => {
-    await props.crud?.deleteBatch({
-      ids: multipleSelection.value.map(item => item.id).join(',')
-    })
-    getTableData()
-    ElMessage({
-      type: 'success',
-      message: '删除成功'
-    })
+    if (props.crud.deleteBatch) {
+      await props.crud?.deleteBatch({
+        ids: multipleSelection.value.map(item => item.id).join(',')
+      })
+      getTableData()
+      ElMessage({
+        type: 'success',
+        message: '删除成功'
+      })
+    } else {
+      ElMessage({
+        type: 'error',
+        message: '未提供deleteBatch方法'
+      })
+    }
   })
 }
 // ============== crud部分结束 ===============
@@ -206,7 +216,7 @@ defineExpose({
             >
               删除
             </el-button>
-            <slot name="toolbar"></slot>
+            <slot name="toolbar" :selection="multipleSelection"></slot>
           </div>
         </div>
         <el-table