curd-list-page.vue.hbs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!-- plop(curd-list) 生成:补全 API、searchConfig、contentConfig、表格列与弹窗 -->
  2. <template>
  3. <div class="app-container">
  4. <PageSearch
  5. ref="searchRef"
  6. :search-config="searchConfig"
  7. @query-click="handleQueryClick"
  8. @reset-click="handleResetClick"
  9. />
  10. <PageContent ref="contentRef" :content-config="contentConfig">
  11. <template #toolbar="{ toolbarRight, onToolbar, removeIds, cols }">
  12. <CrudToolbarLeft
  13. :remove-ids="removeIds"
  14. :perm-create="['{{permPrefix}}:create']"
  15. :perm-delete="['{{permPrefix}}:delete']"
  16. :perm-patch="['{{permPrefix}}:patch']"
  17. @add="handleOpenDialog('create')"
  18. @delete="onToolbar('delete')"
  19. @more="handleMoreClick"
  20. />
  21. <div class="data-table__toolbar--right">
  22. <CrudToolbarRight :buttons="toolbarRight" :cols="cols" :on-toolbar="onToolbar" />
  23. </div>
  24. </template>
  25. <template #table="{ data, loading, tableRef, onSelectionChange, pagination }">
  26. <div class="data-table__content">
  27. <el-table
  28. :ref="tableRef as any"
  29. v-loading="loading"
  30. row-key="id"
  31. :data="data"
  32. height="calc(100vh - 350px)"
  33. max-height="calc(100vh - 350px)"
  34. border
  35. stripe
  36. @selection-change="onSelectionChange"
  37. >
  38. <template #empty>
  39. <el-empty :image-size="80" description="暂无数据" />
  40. </template>
  41. <!-- TODO: el-table-column -->
  42. </el-table>
  43. </div>
  44. </template>
  45. </PageContent>
  46. </div>
  47. </template>
  48. <script setup lang="ts">
  49. defineOptions({ name: "{{componentName}}", inheritAttrs: false });
  50. import { reactive } from "vue";
  51. import CrudToolbarLeft from "@/components/CURD/CrudToolbarLeft.vue";
  52. import CrudToolbarRight from "@/components/CURD/CrudToolbarRight.vue";
  53. import PageSearch from "@/components/CURD/PageSearch.vue";
  54. import PageContent from "@/components/CURD/PageContent.vue";
  55. import { useCrudList } from "@/components/CURD/useCrudList";
  56. import type { IContentConfig, ISearchConfig } from "@/components/CURD/types";
  57. const { searchRef, contentRef, handleQueryClick, handleResetClick, refreshList } = useCrudList();
  58. const searchConfig = reactive<ISearchConfig>({
  59. permPrefix: "{{permPrefix}}",
  60. formItems: [],
  61. });
  62. const contentConfig = reactive<IContentConfig>({
  63. permPrefix: "{{permPrefix}}",
  64. toolbar: [],
  65. defaultToolbar: ["refresh", "filter"],
  66. cols: [],
  67. /** TODO: 接入列表 API,返回 { total, list } 供 PageContent 解析 */
  68. indexAction: async () => ({ total: 0, list: [] }),
  69. });
  70. function handleOpenDialog(_type: "create" | "update" | "detail", _id?: string) {
  71. // TODO
  72. }
  73. async function handleMoreClick(_status: string) {
  74. // TODO 批量启用/停用
  75. }
  76. </script>