index.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <a-drawer v-model:visible="visible"
  3. :title="title"
  4. :width="width"
  5. :destroy-on-close="destroyOnClose"
  6. :placement="placement">
  7. <a-table :rowKey="rowKey"
  8. :columns="columns"
  9. :data-source="source"
  10. :pagination="tablePageOptions"
  11. @change="onPageChange">
  12. <template #operator="{ record }">
  13. <slot :data="record"></slot>
  14. </template>
  15. </a-table>
  16. </a-drawer>
  17. </template>
  18. <script lang="ts">
  19. import { defineComponent, PropType, ref, watchEffect } from "vue";
  20. import usePagination from "@/hooks/usePagination";
  21. import { IMeta, PageOptions } from "@/types/api";
  22. const DrawerWrapper = defineComponent({
  23. props: {
  24. show: {
  25. type: Boolean,
  26. default: false,
  27. },
  28. destroyOnClose: {
  29. type: Boolean,
  30. default: true,
  31. },
  32. width: {
  33. type: [Number, String],
  34. default: "70%",
  35. },
  36. placement: {
  37. type: String,
  38. default: "right",
  39. },
  40. rowKey: {
  41. type: String,
  42. default: "id",
  43. },
  44. title: String,
  45. source: Array,
  46. columns: Array,
  47. meta: {
  48. type: Object as PropType<Partial<IMeta>>,
  49. default: {},
  50. },
  51. },
  52. emits: ["update:show", "pageChange"],
  53. setup(props, { emit }) {
  54. const { meta, tablePageOptions } = usePagination();
  55. let visible = ref(props.show);
  56. watchEffect(() => (meta.value = props.meta));
  57. watchEffect(() => (visible.value = props.show));
  58. watchEffect(() => emit("update:show", visible.value));
  59. const onPageChange = (pagination: PageOptions) => {
  60. emit("pageChange", pagination.current);
  61. };
  62. return { visible, tablePageOptions, onPageChange };
  63. },
  64. });
  65. export default DrawerWrapper;
  66. </script>