index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="top">
  6. <el-button type="primary" size="mini" @click="add">添加</el-button>
  7. </el-col>
  8. <el-col :span="24" class="down">
  9. <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @edit="toEdit" @delete="toDelete"></data-table>
  10. </el-col>
  11. </el-col>
  12. </el-row>
  13. </div>
  14. </template>
  15. <script>
  16. import dataTable from '@common/src/components/frame/filter-page-table.vue';
  17. import { mapState, createNamespacedHelpers } from 'vuex';
  18. const { mapActions: mapUniversal } = createNamespacedHelpers('universal');
  19. export default {
  20. metaInfo() {
  21. return { title: this.$route.meta.title };
  22. },
  23. name: 'index',
  24. props: {},
  25. components: { dataTable },
  26. data: function() {
  27. return {
  28. opera: [
  29. {
  30. label: '编辑',
  31. method: 'edit',
  32. },
  33. {
  34. label: '删除',
  35. method: 'delete',
  36. },
  37. ],
  38. fields: [
  39. { label: '信息类型', prop: 'type' },
  40. { label: '信息标题', prop: 'title', filter: 'input' },
  41. { label: '信息来源', prop: 'origin' },
  42. { label: '发布时间', prop: 'create_time' },
  43. ],
  44. list: [],
  45. total: 0,
  46. };
  47. },
  48. async created() {
  49. await this.search();
  50. },
  51. methods: {
  52. ...mapUniversal(['query', 'fetch', 'create', 'update', 'delete']),
  53. async search({ skip = 0, limit = 10, ...info } = {}) {
  54. info.user_id = this.user.id;
  55. let res = await this.query({ skip, limit, ...info });
  56. if (this.$checkRes(res)) {
  57. this.$set(this, `list`, res.data);
  58. this.$set(this, `total`, res.total);
  59. }
  60. },
  61. // 修改
  62. toEdit({ data }) {
  63. this.$router.push({ path: '/universal/detail', query: { id: data.id } });
  64. },
  65. // 删除
  66. async toDelete({ data }) {
  67. let res = await this.delete(data.id);
  68. if (this.$checkRes(res)) {
  69. this.$message({
  70. message: '信息删除成功',
  71. type: 'success',
  72. });
  73. this.search();
  74. }
  75. },
  76. // 添加数据
  77. add() {
  78. this.$router.push({ path: '/universal/detail' });
  79. },
  80. },
  81. computed: {
  82. ...mapState(['user']),
  83. },
  84. watch: {},
  85. };
  86. </script>
  87. <style lang="less" scoped>
  88. .main {
  89. .top {
  90. text-align: right;
  91. margin: 0 0 10px 0;
  92. }
  93. }
  94. </style>