index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <script setup lang="ts">
  2. import RegularPage from '@/components/RegularPage.vue'
  3. import { onMounted, ref, reactive } from 'vue'
  4. import type { BaseTableColumns } from 'tdesign-vue-next'
  5. import type { Classify } from '@/model/classify'
  6. import ClassifyDialog from '@/pages/classify/components/ClassifyDialog.vue'
  7. const columns: BaseTableColumns = [
  8. {
  9. title: '分类名称',
  10. colKey: 'name',
  11. width: 100
  12. },
  13. {
  14. title: '分类编号',
  15. colKey: 'numbering',
  16. width: 100
  17. },
  18. {
  19. title: '排序',
  20. colKey: 'sort',
  21. width: 100
  22. },
  23. {
  24. title: '操作',
  25. colKey: 'operation',
  26. width: 100
  27. }
  28. ]
  29. const loading = ref(false)
  30. const data = ref(
  31. Array.from({ length: 1 })
  32. .fill({ id: '1', name: '趣味科普', numbering: 'enjoy', sort: '1' })
  33. .map((item) => item)
  34. )
  35. const pagination = reactive({
  36. total: 1,
  37. page: 1,
  38. size: 10
  39. })
  40. const classifyDialogVisible = ref(false)
  41. const isEdit = ref(false)
  42. const currentTableData = ref<Classify | {}>({})
  43. const fetchClassifyTableData = () => {
  44. /* TODO: 获取分类表格数据 */
  45. }
  46. onMounted(fetchClassifyTableData)
  47. const editClick = (classify: Classify) => {
  48. isEdit.value = true
  49. currentTableData.value = classify
  50. console.log(classify)
  51. classifyDialogVisible.value = true
  52. }
  53. const onPageChange = () => {
  54. /* TODO: 分页切换 */
  55. }
  56. </script>
  57. <template>
  58. <RegularPage title="分类管理">
  59. <template #right-area>
  60. <TButton @click="classifyDialogVisible = true">创建分类</TButton>
  61. </template>
  62. <TTable
  63. class="w-full h-full"
  64. row-key="id"
  65. height="92%"
  66. table-layout="auto"
  67. :data="data"
  68. :loading="loading"
  69. :columns="columns"
  70. cell-empty-content="-"
  71. :paginationAffixedBottom="true"
  72. :pagination="{
  73. total: pagination.total,
  74. current: pagination.page,
  75. pageSize: pagination.size,
  76. onChange: onPageChange
  77. }"
  78. >
  79. <template #roles="{ row }">
  80. <TSpace>
  81. <TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{
  82. role.label
  83. }}</TTag>
  84. </TSpace>
  85. </template>
  86. <template #operation="{ row }">
  87. <TButton variant="text" size="small" theme="primary" @click="editClick(row)">编辑</TButton>
  88. </template>
  89. </TTable>
  90. <ClassifyDialog
  91. :classify="currentTableData"
  92. v-model:visible="classifyDialogVisible"
  93. :isEdit="isEdit"
  94. headerTitle="分类"
  95. ></ClassifyDialog>
  96. </RegularPage>
  97. </template>
  98. <style scoped>
  99. :deep(.t-card__body) {
  100. flex: 1;
  101. min-height: 0;
  102. }
  103. </style>