index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. />
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import toolbar from './toolbar';
  19. import mxFilterList from '@/mixins/filterList';
  20. import { getList, delItem } from '@/api/base/info';
  21. export default {
  22. name: 'InfoManagement',
  23. components: { toolbar },
  24. mixins: [
  25. mxFilterList({
  26. fetchList: getList // 在下方data再声明一个 fetchList: iGetList 同等效果
  27. })
  28. ],
  29. data() {
  30. return {
  31. columns: [
  32. {
  33. key: 'title',
  34. name: '标题',
  35. minWidth: '240'
  36. },
  37. {
  38. key: 'author',
  39. name: '作者',
  40. width: '160'
  41. },
  42. {
  43. key: 'createAt',
  44. name: '发布时间',
  45. width: '140'
  46. },
  47. {
  48. key: 'looks',
  49. name: '阅读',
  50. width: '120',
  51. render: (h, { row }) => h('span', row.looks)
  52. },
  53. {
  54. key: 'likes',
  55. name: '点赞',
  56. width: '120',
  57. render: (h, { row }) => h('span', row.likes)
  58. },
  59. {
  60. key: 'collections',
  61. name: '收藏',
  62. width: '120',
  63. render: (h, { row }) => h('span', row.collections)
  64. },
  65. {
  66. key: 'sort',
  67. name: '排序',
  68. width: '80'
  69. },
  70. {
  71. key: 'isShow',
  72. name: '状态',
  73. width: '80',
  74. type: 'tag',
  75. fetchTagType: val => (val ? 'success' : 'info'),
  76. tagName: row => (row.isShow ? '显示' : '隐藏')
  77. },
  78. {
  79. key: 'action',
  80. name: '操作',
  81. width: '120',
  82. render: (h, { row }) => {
  83. const action = [];
  84. action.push(
  85. h(
  86. 'el-button',
  87. {
  88. props: {
  89. type: 'text'
  90. },
  91. on: {
  92. click: () =>
  93. this.$InfoItemModal({
  94. id: row.id
  95. })
  96. }
  97. },
  98. '编辑'
  99. )
  100. );
  101. action.push(
  102. h(
  103. 'BaseBtn',
  104. {
  105. props: {
  106. popip: true,
  107. txt: '删除',
  108. type: 'text'
  109. },
  110. class: 'ml-10',
  111. on: {
  112. ok: () => this.handleDelItem(row)
  113. }
  114. },
  115. '删除'
  116. )
  117. );
  118. return h('div', action);
  119. }
  120. }
  121. ]
  122. };
  123. },
  124. created() {
  125. this.$g_on('base_info_reload', this.reload);
  126. },
  127. beforeDestroy() {
  128. this.$g_off('base_info_reload', this.reload);
  129. },
  130. methods: {
  131. handleAdd() {
  132. this.$InfoItemModal();
  133. },
  134. async handleDelItem(item) {
  135. const { success, msg } = await delItem({
  136. id: item.id
  137. });
  138. if (success) {
  139. this.$success('删除成功!');
  140. this.$g_emit('base_info_reload');
  141. }
  142. }
  143. }
  144. };
  145. </script>
  146. <style type="scss" scoped></style>