index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div class="h-full overflow-hidden">
  3. <n-card title="权限管理" :bordered="false" class="rounded-16px shadow-sm">
  4. <n-data-table :columns="columns" :data="tableData" :pagination="pagination" />
  5. </n-card>
  6. </div>
  7. </template>
  8. <script setup lang="ts">
  9. import { ref } from 'vue';
  10. import type { Ref } from 'vue';
  11. import type { DataTableColumns, PaginationProps } from 'naive-ui';
  12. import { query } from '~/src/service/api/user';
  13. import type { QueryParams } from '~/src/service/api/user';
  14. const tableData = ref<QueryParams[]>([]);
  15. const pagination: PaginationProps = ref({
  16. page: 1,
  17. pageSize: 10,
  18. showSizePicker: true,
  19. pageSizes: [10, 20, 50]
  20. // onChange: (page: number) => {
  21. // // 处理页码变化
  22. // },
  23. // onUpdatePageSize: (pageSize: number) => {
  24. // // 处理每页显示数量变化
  25. // }
  26. }).value;
  27. async function getTableData() {
  28. const pageNum = pagination.page as number; // 页码
  29. const pageSize = pagination.pageSize as number; // 当前所在数
  30. const params: QueryParams = {};
  31. query(pageNum, pageSize, params).then(res => {
  32. tableData.value = res.data as [];
  33. });
  34. }
  35. const columns: Ref<DataTableColumns<QueryParams>> = ref([
  36. {
  37. type: 'selection',
  38. align: 'center'
  39. },
  40. {
  41. key: 'name',
  42. title: '部门名称',
  43. align: 'center'
  44. },
  45. {
  46. key: 'description',
  47. title: '部门地址',
  48. align: 'center'
  49. },
  50. {
  51. key: 'isActive',
  52. title: '是否激活',
  53. align: 'center',
  54. render: (row: QueryParams) => {
  55. return row.isActive ? '是' : '否';
  56. }
  57. },
  58. {
  59. key: 'createTime',
  60. title: '创建时间',
  61. align: 'center'
  62. },
  63. {
  64. key: 'modifyTime',
  65. title: '修改时间',
  66. align: 'center'
  67. },
  68. {
  69. key: 'createUid',
  70. title: '创建用户ID',
  71. align: 'center'
  72. },
  73. {
  74. key: 'disabled',
  75. title: '状态',
  76. align: 'center'
  77. }
  78. ]) as Ref<DataTableColumns<QueryParams>>;
  79. function init() {
  80. getTableData();
  81. }
  82. // 初始化
  83. init();
  84. </script>