index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/carousal/components/CarousalDialog.vue'
  7. import { activeCarousal, getCarousalList, inactiveCarousal } from '@/api/carousal'
  8. const columns: BaseTableColumns = [
  9. {
  10. title: 'ID',
  11. colKey: 'id',
  12. width: 100
  13. },
  14. {
  15. title: '轮播图',
  16. colKey: 'imageUrl',
  17. width: 100
  18. },
  19. {
  20. title: '显示状态',
  21. colKey: 'status',
  22. width: 100,
  23. },
  24. {
  25. title: '操作',
  26. colKey: 'operation',
  27. width: 100
  28. }
  29. ]
  30. const loading = ref(false)
  31. const data = ref([])
  32. const pagination = reactive({
  33. page: 1,
  34. size: 10,
  35. total:0
  36. })
  37. const query = reactive({
  38. page:1,
  39. size:10,
  40. })
  41. const carousalDialogVisible = ref(false)
  42. const isEdit = ref(false)
  43. const currentTableData = ref<{}>({})
  44. const fetchClassifyTableData = async () => {
  45. /* TODO: 获取轮播图表格数据 */
  46. query.page = pagination.page
  47. query.size = pagination.size
  48. const getCarousalListApi = await getCarousalList(query)
  49. data.value = getCarousalListApi.data
  50. pagination.total = getCarousalListApi.pagination.total
  51. }
  52. onMounted(fetchClassifyTableData)
  53. const editClick = (row:object) => {
  54. isEdit.value = true
  55. currentTableData.value = row
  56. carousalDialogVisible.value = true
  57. }
  58. const showClick = async (res:object) => {
  59. if (res.status === 'active'){
  60. await inactiveCarousal({ id: res.id })
  61. } else {
  62. await activeCarousal({ id: res.id })
  63. }
  64. await fetchClassifyTableData()
  65. console.log(res)
  66. }
  67. const onPageChange = () => {
  68. /* TODO: 分页切换 */
  69. }
  70. </script>
  71. <template>
  72. <RegularPage title="轮播图管理">
  73. <template #right-area>
  74. <TButton @click="carousalDialogVisible = true">创建轮播图</TButton>
  75. </template>
  76. <TTable
  77. class="w-full h-full"
  78. row-key="id"
  79. height="92%"
  80. table-layout="auto"
  81. :data="data"
  82. :loading="loading"
  83. :columns="columns"
  84. cell-empty-content="-"
  85. :paginationAffixedBottom="true"
  86. :pagination="{
  87. total: pagination.total,
  88. current: pagination.page,
  89. pageSize: pagination.size,
  90. onChange: onPageChange
  91. }"
  92. >
  93. <template #status="{row}">
  94. <TSpace>
  95. <TTag :theme="row.status === 'active' ? 'success' : 'danger'" variant="light">{{row.status === 'active' ? '显示中' : '已关闭'}}</TTag>
  96. </TSpace>
  97. </template>
  98. <template #roles="{ row }">
  99. <TSpace>
  100. <TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{
  101. role.label
  102. }}</TTag>
  103. </TSpace>
  104. </template>
  105. <template #operation="{ row }">
  106. <TButton variant="text" size="small" theme="primary" @click="editClick(row)">编辑</TButton>
  107. <TButton variant="text" size="small" theme="primary" @click="showClick(row)">{{ row.status === 'active' ? '关闭显示' : '开启显示'}}</TButton>
  108. </template>
  109. </TTable>
  110. <ClassifyDialog
  111. :classify="currentTableData"
  112. v-model:visible="carousalDialogVisible"
  113. :isEdit="isEdit"
  114. headerTitle="轮播图"
  115. ></ClassifyDialog>
  116. </RegularPage>
  117. </template>
  118. <style scoped>
  119. :deep(.t-card__body) {
  120. flex: 1;
  121. min-height: 0;
  122. }
  123. </style>