index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div class="">
  3. <toolbar @on-filter="filterData" @on-reset="filterData" />
  4. <div class="m-10 bg-w p-20 br-10">
  5. <el-button type="primary" icon="el-icon-plus" @click="handleAdd"
  6. >新增</el-button
  7. >
  8. <base-table
  9. :columns="columns"
  10. :items="items"
  11. :pagination="pagination"
  12. :page-change="pageChange"
  13. :showPage="false"
  14. />
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import toolbar from './toolbar';
  20. import mxFilterList from '@/mixins/filterList';
  21. import { getList, delItem } from '@/api/base/trend';
  22. export default {
  23. name: 'Trending',
  24. components: { toolbar },
  25. mixins: [
  26. mxFilterList({
  27. fetchList: getList, // 在下方data再声明一个 fetchList: iGetList 同等效果
  28. pagination: {
  29. page: 1,
  30. total: 0,
  31. pageSize: 999999
  32. }
  33. })
  34. ],
  35. data() {
  36. return {
  37. columns: [
  38. {
  39. key: 'name',
  40. name: '标题',
  41. minWidth: '240'
  42. },
  43. {
  44. key: 'sort',
  45. name: '排序',
  46. width: '80'
  47. },
  48. {
  49. key: 'isShow',
  50. name: '状态',
  51. width: '80',
  52. type: 'tag',
  53. fetchTagType: val => (val ? 'success' : 'info'),
  54. tagName: row => (row.isShow ? '显示' : '隐藏')
  55. },
  56. {
  57. key: 'action',
  58. name: '操作',
  59. width: '120',
  60. render: (h, { row }) => {
  61. const action = [];
  62. action.push(
  63. h(
  64. 'el-button',
  65. {
  66. props: {
  67. type: 'text'
  68. },
  69. on: {
  70. click: () =>
  71. this.$TrendItemModal({
  72. id: row.id,
  73. info: {
  74. name: row.name,
  75. sort: row.sort,
  76. isShow: row.isShow
  77. }
  78. })
  79. }
  80. },
  81. '编辑'
  82. )
  83. );
  84. action.push(
  85. h(
  86. 'BaseBtn',
  87. {
  88. props: {
  89. popip: true,
  90. txt: '删除',
  91. type: 'text'
  92. },
  93. class: 'ml-10',
  94. on: {
  95. ok: () => this.handleDelItem(row)
  96. }
  97. },
  98. '删除'
  99. )
  100. );
  101. return h('div', action);
  102. }
  103. }
  104. ]
  105. };
  106. },
  107. created() {
  108. this.$g_on('trend_reload', this.reload);
  109. },
  110. beforeDestroy() {
  111. this.$g_off('trend_reload', this.reload);
  112. },
  113. methods: {
  114. handleAdd() {
  115. this.$TrendItemModal();
  116. },
  117. async handleDelItem(item) {
  118. const { success, msg } = await delItem({
  119. id: item.id
  120. });
  121. if (success) {
  122. this.$success('删除成功!');
  123. this.$g_emit('trend_reload');
  124. }
  125. }
  126. }
  127. };
  128. </script>
  129. <style type="scss" scoped></style>