index.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: interview } = createNamespacedHelpers('interview');
  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', filter: 'input' },
  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. ...interview(['query', 'fetch', 'create', 'update', 'delete']),
  52. async search({ skip = 0, limit = 10, ...info } = {}) {
  53. let res = await this.query({ skip, limit, ...info });
  54. if (this.$checkRes(res)) {
  55. this.$set(this, `list`, res.data);
  56. this.$set(this, `total`, res.total);
  57. }
  58. },
  59. // 修改
  60. toEdit({ data }) {
  61. this.$router.push({ path: '/interview/detail', query: { id: data.id } });
  62. },
  63. // 删除
  64. async toDelete({ data }) {
  65. let res = await this.delete(data.id);
  66. if (this.$checkRes(res)) {
  67. this.$message({
  68. message: '信息删除成功',
  69. type: 'success',
  70. });
  71. this.search();
  72. }
  73. },
  74. // 添加数据
  75. add() {
  76. this.$router.push({ path: '/interview/detail' });
  77. },
  78. },
  79. computed: {
  80. ...mapState(['user']),
  81. },
  82. watch: {},
  83. };
  84. </script>
  85. <style lang="less" scoped>
  86. .main {
  87. .top {
  88. text-align: right;
  89. margin: 0 0 10px 0;
  90. }
  91. }
  92. </style>