index.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: mapViewPoint } = createNamespacedHelpers('viewPoint');
  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: 'title' },
  40. { label: '信息来源', prop: 'origin' },
  41. { label: '发布时间', prop: 'publish_time' },
  42. ],
  43. list: [],
  44. total: 0,
  45. };
  46. },
  47. async created() {
  48. await this.search();
  49. },
  50. methods: {
  51. ...mapViewPoint(['query', 'fetch', 'create', 'update', 'delete']),
  52. async search({ skip = 0, limit = 10, ...info } = {}) {
  53. info.user_id = this.user.id;
  54. let res = await this.query({ skip, limit, ...info });
  55. if (this.$checkRes(res)) {
  56. this.$set(this, `list`, res.data);
  57. this.$set(this, `total`, res.total);
  58. }
  59. },
  60. // 修改
  61. toEdit({ data }) {
  62. this.$router.push({ path: '/viewPoint/detail', query: { id: data.id } });
  63. },
  64. // 删除
  65. async toDelete({ data }) {
  66. let res = await this.delete(data.id);
  67. if (this.$checkRes(res)) {
  68. this.$message({
  69. message: '信息删除成功',
  70. type: 'success',
  71. });
  72. this.search();
  73. }
  74. },
  75. // 添加数据
  76. add() {
  77. this.$router.push({ path: '/viewPoint/detail' });
  78. },
  79. },
  80. computed: {
  81. ...mapState(['user']),
  82. },
  83. watch: {},
  84. };
  85. </script>
  86. <style lang="less" scoped>
  87. .main {
  88. .top {
  89. text-align: right;
  90. margin: 0 0 10px 0;
  91. }
  92. }
  93. </style>