Pārlūkot izejas kodu

proTable新增before-create属性

tongshangming 2 gadi atpakaļ
vecāks
revīzija
86250aa05a
2 mainītis faili ar 23 papildinājumiem un 3 dzēšanām
  1. 1 2
      .env.development
  2. 22 1
      src/components/core/ProTable.vue

+ 1 - 2
.env.development

@@ -1,5 +1,4 @@
 NODE_ENV = 'development'
 
 VITE_BASE_API = /api
-# VITE_BASE_PATH = http://10.0.0.198:30701
-VITE_BASE_PATH = https://yunji-web.sxidc.com
+VITE_BASE_PATH = http://10.0.0.198:30701

+ 22 - 1
src/components/core/ProTable.vue

@@ -32,6 +32,7 @@ interface Props {
   showToolbar?: boolean
   height?: string
   formMode?: 'dialog' | 'drawer'
+  beforeCreate?: Function
 }
 
 const props = withDefaults(defineProps<Props>(), {
@@ -147,7 +148,8 @@ const handleSelectionChange = () => {
 
 // ============== crud部分开始 ===============
 const formRoute = ref<any>(props.formConfig.route)
-const handleCreate = () => {
+
+const doCreate = () => {
   emits('click-create')
   if (formRoute.value) {
     router.push(formRoute.value)
@@ -157,6 +159,25 @@ const handleCreate = () => {
     formVisible.value = true
   }
 }
+const handleCreate = async () => {
+  if (!props.beforeCreate) {
+    return doCreate()
+  }
+
+  let result = true
+  try {
+    const beforeUploadPromise = props.beforeCreate(formData.value)
+    result = await beforeUploadPromise
+  } catch {
+    result = false
+  }
+  console.log(result)
+  if (result === false) {
+    return
+  }
+  doCreate()
+}
+
 const handleUpdate = (row: any) => {
   emits('click-edit', row)
   if (formRoute.value) {