index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <breadcrumb :breadcrumbTitle="this.$route.meta.title"></breadcrumb>
  6. <el-col :span="24" class="container">
  7. <el-col :span="24" class="top">
  8. <el-button type="primary" size="mini" @click="$router.push({ path: '/links/detail' })">添加</el-button>
  9. </el-col>
  10. <el-col :span="24" class="list">
  11. <data-table :fields="fields" :opera="opera" :data="list" :total="total" @edit="toEdit" @delete="toDelete" @query="search"></data-table>
  12. </el-col>
  13. </el-col>
  14. </el-col>
  15. </el-row>
  16. </div>
  17. </template>
  18. <script>
  19. import breadcrumb from '@c/common/breadcrumb.vue';
  20. import dataTable from '@/components/frame/filter-page-table.vue';
  21. import { mapState, createNamespacedHelpers } from 'vuex';
  22. const { mapActions: link } = createNamespacedHelpers('link');
  23. export default {
  24. metaInfo() {
  25. return { title: this.$route.meta.title };
  26. },
  27. name: 'index',
  28. props: {},
  29. components: {
  30. breadcrumb,
  31. dataTable,
  32. },
  33. data: function() {
  34. return {
  35. opera: [
  36. {
  37. label: '修改',
  38. icon: 'el-icon-edit',
  39. method: 'edit',
  40. },
  41. {
  42. label: '删除',
  43. icon: 'el-icon-delete',
  44. method: 'delete',
  45. },
  46. ],
  47. fields: [
  48. { label: '名称', prop: 'name', filter: 'input' },
  49. { label: '相关链接', prop: 'url' },
  50. { label: '图片地址', prop: 'pic' },
  51. ],
  52. list: [],
  53. total: 0,
  54. };
  55. },
  56. created() {
  57. this.search();
  58. },
  59. methods: {
  60. ...link(['query', 'delete']),
  61. // 查询列表
  62. async search({ skip = 0, limit = 10, ...info } = {}) {
  63. const res = await this.query({ skip, limit, ...info });
  64. if (this.$checkRes(res)) {
  65. console.log('asd');
  66. this.$set(this, `list`, res.data);
  67. this.$set(this, `total`, res.total);
  68. }
  69. },
  70. // 修改
  71. toEdit({ data }) {
  72. this.$router.push({ path: '/links/detail', query: { id: data.id } });
  73. },
  74. // 删除
  75. async toDelete({ data }) {
  76. const res = await this.delete(data.id);
  77. if (this.$checkRes(res)) {
  78. this.$message({
  79. message: '刪除成功',
  80. type: 'success',
  81. });
  82. this.search();
  83. }
  84. },
  85. },
  86. computed: {
  87. ...mapState(['user']),
  88. },
  89. };
  90. </script>
  91. <style lang="less" scoped>
  92. .main {
  93. .top {
  94. text-align: right;
  95. margin: 15px 0;
  96. }
  97. }
  98. </style>