SimpleTable.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!-- 编辑弹窗 -->
  2. <template>
  3. <ele-pro-table
  4. ref="tableRef"
  5. :row-key="rowId"
  6. :columns="columns"
  7. :datasource="datasource"
  8. highlight-current-row
  9. :pagination="false"
  10. :tools="false"
  11. v-bind="$attrs"
  12. >
  13. <template v-for="(val, key) in slotArray" v-slot:[key]="{ row }">
  14. <slot :name="key" :row="row"></slot>
  15. </template>
  16. </ele-pro-table>
  17. </template>
  18. <script setup>
  19. import { ref, reactive, nextTick, useSlots } from 'vue';
  20. import request from '@/utils/request';
  21. import { pagePosts } from '@/api/system/post';
  22. const slotArray = useSlots();
  23. const props = defineProps({
  24. columns: {
  25. type: Array,
  26. default() {
  27. return [];
  28. }
  29. },
  30. rowId: {
  31. type: String,
  32. default: 'id'
  33. },
  34. pageUrl: {
  35. type: String
  36. },
  37. otherParams: {
  38. // 额外参数
  39. type: Object,
  40. default() {
  41. return {};
  42. }
  43. }
  44. });
  45. const tableRef = ref(null);
  46. async function queryPage(params) {
  47. if (!props.pageUrl) return Promise.reject(new Error('请配置pageUrl'));
  48. const res = await request.get(props.pageUrl, { params });
  49. if (res.data.code === 200) {
  50. return res.data;
  51. }
  52. return Promise.reject(new Error(res.data.msg));
  53. }
  54. /** 表格数据源 */
  55. const datasource = ({ pages, where, orders }) => {
  56. return queryPage({ ...where, ...orders, ...pages, ...props.otherParams });
  57. };
  58. /** 搜索 */
  59. const reload = (where) => {
  60. tableRef.value?.reload?.({ page: 1, where });
  61. };
  62. defineExpose({
  63. reload
  64. });
  65. </script>