index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <ele-page flex-table>
  3. <!-- Search Bar -->
  4. <div class="bg-white p-4 mb-4 rounded shadow-sm flex items-center justify-between">
  5. <div class="flex items-center space-x-2">
  6. <el-input v-model="searchQuery" placeholder="请输入专题名称" style="width: 240px" clearable />
  7. <el-button type="primary" @click="handleSearch">查询</el-button>
  8. <el-button @click="handleReset">重置</el-button>
  9. </div>
  10. <el-button type="primary" @click="handleAdd">添加专题</el-button>
  11. </div>
  12. <common-table ref="tableRef" :pageConfig="pageConfig" :columns="columns" :tools="false"
  13. :datasource="mockDatasource">
  14. <!-- 状态 -->
  15. <template #status="{ row }">
  16. <span :class="row.status === 'online' ? 'text-green-500' : 'text-gray-500'">
  17. {{ row.status === 'online' ? '已上架' : '已下架' }}
  18. </span>
  19. </template>
  20. <!-- 操作 -->
  21. <template #action="{ row }">
  22. <div class="flex items-center space-x-2">
  23. <el-button v-if="row.status === 'online'" size="small" type="primary" plain
  24. @click="handleStatusToggle(row)">
  25. 下架
  26. </el-button>
  27. <el-button v-else size="small" type="success" plain @click="handleStatusToggle(row)">
  28. 上架
  29. </el-button>
  30. <el-button link type="primary" @click="handleEdit(row)">编辑</el-button>
  31. <el-button link type="primary" @click="handleDetail(row)">详情</el-button>
  32. <el-button link type="danger" @click="handleDelete(row)">删除</el-button>
  33. </div>
  34. </template>
  35. </common-table>
  36. <topics-edit ref="editDialogRef" @success="handleSuccess" />
  37. </ele-page>
  38. </template>
  39. <script setup>
  40. import { ref, reactive } from 'vue';
  41. import CommonTable from '@/components/CommonPage/CommonTable.vue';
  42. import TopicsEdit from './components/topics-edit.vue';
  43. import { EleMessage } from 'ele-admin-plus/es';
  44. defineOptions({ name: 'TopicsList' });
  45. const tableRef = ref(null);
  46. const editDialogRef = ref(null);
  47. const searchQuery = ref('');
  48. const pageConfig = reactive({
  49. pageUrl: '/book/showIndex/queryBindBook',
  50. fileName: '专题列表',
  51. cacheKey: 'topics-list',
  52. params: {
  53. type: 1
  54. }
  55. });
  56. const columns = ref([
  57. { type: 'selection', width: 50, align: 'center' },
  58. { label: '编号', prop: 'code', width: 100, align: 'center' },
  59. { label: '专题名称', prop: 'name', align: 'center' },
  60. { label: '发布时间', prop: 'publishTime', align: 'center', width: 180 },
  61. { label: '专题类型', prop: 'typeLabel', align: 'center' },
  62. { label: '相关单品', prop: 'relatedItems', align: 'center' },
  63. { label: '状态', prop: 'status', slot: 'status', align: 'center' },
  64. { label: '排序', prop: 'sort', align: 'center', width: 80 },
  65. { label: '操作', prop: 'action', slot: 'action', align: 'center', width: 250 }
  66. ]);
  67. const handleSearch = () => {
  68. reload();
  69. };
  70. const handleReset = () => {
  71. searchQuery.value = '';
  72. reload();
  73. };
  74. const reload = () => {
  75. tableRef.value?.reload();
  76. };
  77. const handleAdd = () => {
  78. editDialogRef.value?.handleOpen();
  79. };
  80. const handleEdit = (row) => {
  81. editDialogRef.value?.handleOpen(row);
  82. };
  83. const handleDetail = (row) => {
  84. EleMessage.info(`查看 ${row.name} 详情`);
  85. };
  86. const handleDelete = (row) => {
  87. EleMessage.confirm(`确定要删除 ${row.name} 吗?`)
  88. .then(() => {
  89. // TODO: Call API to delete
  90. // tableRef.value?.operatBatch({ method: 'delete', row, url: '/salesOps/topics/delete' });
  91. EleMessage.success('删除成功');
  92. reload();
  93. })
  94. .catch(() => { });
  95. };
  96. const handleStatusToggle = (row) => {
  97. // TODO: Call API to update status
  98. // tableRef.value?.operatBatch({ method: 'post', row, url: '/salesOps/topics/updateStatus' });
  99. EleMessage.success(`${row.name} 已${row.status === 'online' ? '上架' : '下架'}`);
  100. };
  101. const handleSuccess = () => {
  102. reload();
  103. };
  104. </script>