|
@@ -6,9 +6,10 @@ export default {
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import router from '@/router'
|
|
|
-import { ElMessage, ElMessageBox, type DialogProps } from 'element-plus'
|
|
|
+import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
+import type { DialogProps, DrawerProps } from 'element-plus'
|
|
|
import type { BasicForm, BasicFormItem, ICRUD, FormSlot } from '@/types/form'
|
|
|
-import type { VXEComponent, VxeToolbarProps, VxeToolbarEventProps } from 'vxe-table'
|
|
|
+import type { VXEComponent, VxeToolbarProps, VxeToolbarEventProps, VxeToolbarPropTypes } from 'vxe-table'
|
|
|
import { buildFormSlots } from '@/utils/utils'
|
|
|
|
|
|
interface CustomTable {
|
|
@@ -24,17 +25,20 @@ interface Props {
|
|
|
pageSize?: number
|
|
|
selection?: boolean
|
|
|
formConfig: BasicForm
|
|
|
- dialogConfig?: DialogProps
|
|
|
+ dialogConfig?: Partial<DialogProps>
|
|
|
+ drawerConfig?: Partial<DrawerProps>
|
|
|
tableConfig?: CustomTable
|
|
|
- toolbarConfig?: VXEComponent<VxeToolbarProps, VxeToolbarEventProps>
|
|
|
+ toolbarConfig?: VxeToolbarProps
|
|
|
showToolbar?: boolean
|
|
|
height?: string
|
|
|
+ formMode?: 'dialog' | 'drawer'
|
|
|
}
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
pageSize: 10,
|
|
|
selection: true,
|
|
|
- showToolbar: true
|
|
|
+ showToolbar: true,
|
|
|
+ formMode: 'dialog'
|
|
|
})
|
|
|
|
|
|
const emits = defineEmits(['click-create', 'click-edit', 'click-view', 'click-reset', 'checkbox-change'])
|
|
@@ -150,7 +154,7 @@ const handleCreate = () => {
|
|
|
} else {
|
|
|
formData.value = {}
|
|
|
props.formConfig.disabled = false
|
|
|
- dialogVisible.value = true
|
|
|
+ formVisible.value = true
|
|
|
}
|
|
|
}
|
|
|
const handleUpdate = (row: any) => {
|
|
@@ -166,7 +170,7 @@ const handleUpdate = (row: any) => {
|
|
|
formData.value = { ...row }
|
|
|
}
|
|
|
props.formConfig.disabled = false
|
|
|
- dialogVisible.value = true
|
|
|
+ formVisible.value = true
|
|
|
}
|
|
|
}
|
|
|
const handleView = (row: any) => {
|
|
@@ -182,7 +186,7 @@ const handleView = (row: any) => {
|
|
|
formData.value = { ...row }
|
|
|
}
|
|
|
props.formConfig.disabled = true
|
|
|
- dialogVisible.value = true
|
|
|
+ formVisible.value = true
|
|
|
}
|
|
|
}
|
|
|
const handleDelete = (id: string | number) => {
|
|
@@ -230,7 +234,7 @@ const handleBatchDelete = () => {
|
|
|
|
|
|
// ============== 表单部分开始 ===============
|
|
|
const formData = ref<any>({})
|
|
|
-const dialogVisible = ref(false)
|
|
|
+const formVisible = ref(false)
|
|
|
const handleFormSuccess = () => {
|
|
|
getTableData()
|
|
|
}
|
|
@@ -245,8 +249,11 @@ defineExpose({
|
|
|
handleDelete,
|
|
|
handleUpdate,
|
|
|
handleView,
|
|
|
+ handleQuery,
|
|
|
+ handleReset,
|
|
|
refresh,
|
|
|
- formData
|
|
|
+ formData,
|
|
|
+ query
|
|
|
})
|
|
|
</script>
|
|
|
|
|
@@ -332,21 +339,40 @@ defineExpose({
|
|
|
</div>
|
|
|
</el-card>
|
|
|
|
|
|
- <dialog-form
|
|
|
- v-model="dialogVisible"
|
|
|
- v-if="dialogVisible"
|
|
|
- :dialogConfig="dialogConfig"
|
|
|
- :formConfig="formConfig"
|
|
|
- :formData="formData"
|
|
|
- :formSlots="formSlots"
|
|
|
- :create="crud.create"
|
|
|
- :update="crud.update"
|
|
|
- @success="handleFormSuccess"
|
|
|
- >
|
|
|
- <template #[slot.alias]="slotProps" v-for="slot in formSlots" :key="slot.alias">
|
|
|
- <slot :name="slot.alias" v-bind="slotProps"></slot>
|
|
|
- </template>
|
|
|
- </dialog-form>
|
|
|
+ <template v-if="formMode === 'dialog'">
|
|
|
+ <dialog-form
|
|
|
+ v-model="formVisible"
|
|
|
+ v-if="formVisible"
|
|
|
+ :dialogConfig="dialogConfig"
|
|
|
+ :formConfig="formConfig"
|
|
|
+ :formData="formData"
|
|
|
+ :formSlots="formSlots"
|
|
|
+ :create="crud.create"
|
|
|
+ :update="crud.update"
|
|
|
+ @success="handleFormSuccess"
|
|
|
+ >
|
|
|
+ <template #[slot.alias]="slotProps" v-for="slot in formSlots" :key="slot.alias">
|
|
|
+ <slot :name="slot.alias" v-bind="slotProps"></slot>
|
|
|
+ </template>
|
|
|
+ </dialog-form>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <drawer-form
|
|
|
+ v-model="formVisible"
|
|
|
+ v-if="formVisible"
|
|
|
+ :drawerConfig="drawerConfig"
|
|
|
+ :formConfig="formConfig"
|
|
|
+ :formData="formData"
|
|
|
+ :formSlots="formSlots"
|
|
|
+ :create="crud.create"
|
|
|
+ :update="crud.update"
|
|
|
+ @success="handleFormSuccess"
|
|
|
+ >
|
|
|
+ <template #[slot.alias]="slotProps" v-for="slot in formSlots" :key="slot.alias">
|
|
|
+ <slot :name="slot.alias" v-bind="slotProps"></slot>
|
|
|
+ </template>
|
|
|
+ </drawer-form>
|
|
|
+ </template>
|
|
|
</div>
|
|
|
</template>
|
|
|
|