index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 { getPage, delItem } from '@/api/base/banner';
  21. import { getList as getDict } from '@/api/dict';
  22. export default {
  23. name: 'BannerManagement',
  24. components: { toolbar },
  25. mixins: [
  26. mxFilterList({
  27. fetchList: getPage // 在下方data再声明一个 fetchList: iGetList 同等效果
  28. })
  29. ],
  30. data() {
  31. return {
  32. columns: [
  33. {
  34. key: 'type',
  35. name: '位置',
  36. minWidth: this.$col.b,
  37. render: (h, { row }) => {
  38. const item = this.options.find(x => x.value === row.type);
  39. if (item) {
  40. return h('span', item.label);
  41. }
  42. return h('span', '-');
  43. }
  44. },
  45. {
  46. key: 'imgUrl',
  47. name: '图片',
  48. width: this.$col.b,
  49. render: (h, { row }) =>
  50. h('img', {
  51. style: {
  52. width: '160px',
  53. height: '90px'
  54. },
  55. class: 'pre-img',
  56. attrs: {
  57. src: row.imgUrl
  58. },
  59. on: {
  60. click: () =>
  61. this.$AdvanceViewImageModal({
  62. items: [{ src: row.imgUrl }]
  63. })
  64. }
  65. })
  66. },
  67. {
  68. key: 'name',
  69. name: '标题',
  70. minWidth: this.$col.s
  71. },
  72. {
  73. key: 'link',
  74. name: '链接',
  75. minWidth: this.$col.m,
  76. showOverflowTooltip: true
  77. },
  78. {
  79. key: 'sort',
  80. name: '排序',
  81. width: this.$col.s
  82. },
  83. {
  84. key: 'createAt',
  85. name: '创建时间',
  86. width: this.$col.b
  87. },
  88. {
  89. key: 'updateAt',
  90. name: '修改时间',
  91. width: this.$col.b
  92. },
  93. {
  94. key: 'isShow',
  95. name: '显示/隐藏',
  96. width: this.$col.s,
  97. type: 'tag',
  98. fetchTagType: val => (val ? 'success' : 'info'),
  99. tagName: row => (row.isShow ? '显示' : '隐藏')
  100. },
  101. {
  102. key: 'action',
  103. name: '操作',
  104. width: '120',
  105. render: (h, { row }) => {
  106. const action = [];
  107. action.push(
  108. h(
  109. 'el-button',
  110. {
  111. props: {
  112. type: 'text'
  113. },
  114. on: {
  115. click: () =>
  116. this.$BannerItemModal({
  117. id: row.id
  118. })
  119. }
  120. },
  121. '编辑'
  122. )
  123. );
  124. action.push(
  125. h(
  126. 'BaseBtn',
  127. {
  128. props: {
  129. popip: true,
  130. txt: '删除',
  131. type: 'text'
  132. },
  133. class: 'ml-10',
  134. on: {
  135. ok: () => this.handleDelItem(row)
  136. }
  137. },
  138. '删除'
  139. )
  140. );
  141. return h('div', action);
  142. }
  143. }
  144. ],
  145. options: []
  146. };
  147. },
  148. created() {
  149. this.$g_on('banner_reload', this.reload);
  150. this.loadDict();
  151. },
  152. beforeDestroy() {
  153. this.$g_off('banner_reload', this.reload);
  154. },
  155. methods: {
  156. async loadDict() {
  157. const { data } = await getDict({
  158. dictCode: this.$dict.BANNER_TYPE
  159. });
  160. this.options = data.map(x => ({
  161. value: x.value,
  162. label: x.name
  163. }));
  164. },
  165. handleAdd() {
  166. this.$BannerItemModal();
  167. },
  168. async handleDelItem(item) {
  169. const { success, msg } = await delItem({
  170. id: item.id
  171. });
  172. if (success) {
  173. this.$success('删除成功!');
  174. this.$g_emit('banner_reload');
  175. }
  176. }
  177. }
  178. };
  179. </script>
  180. <style type="scss" scoped></style>