index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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: mappatentnav } = createNamespacedHelpers('patentnav');
  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. label: '是否展示',
  44. prop: 'is_show',
  45. format: item => {
  46. return item === true ? '展示' : '不展示';
  47. },
  48. },
  49. ],
  50. list: [],
  51. total: 0,
  52. };
  53. },
  54. async created() {
  55. await this.search();
  56. },
  57. methods: {
  58. ...mappatentnav(['query', 'fetch', 'create', 'update', 'delete']),
  59. async search({ skip = 0, limit = 10, ...info } = {}) {
  60. info.user_id = this.user.id;
  61. let res = await this.query({ skip, limit, ...info });
  62. if (this.$checkRes(res)) {
  63. this.$set(this, `list`, res.data);
  64. this.$set(this, `total`, res.total);
  65. }
  66. },
  67. // 修改
  68. toEdit({ data }) {
  69. this.$router.push({ path: '/patentnav/detail', query: { id: data.id } });
  70. },
  71. // 删除
  72. async toDelete({ data }) {
  73. let res = await this.delete(data.id);
  74. if (this.$checkRes(res)) {
  75. this.$message({
  76. message: '信息删除成功',
  77. type: 'success',
  78. });
  79. this.search();
  80. }
  81. },
  82. // 添加数据
  83. add() {
  84. this.$router.push({ path: '/dimension/detail' });
  85. },
  86. },
  87. computed: {
  88. ...mapState(['user']),
  89. },
  90. watch: {},
  91. };
  92. </script>
  93. <style lang="less" scoped>
  94. .main {
  95. .top {
  96. text-align: right;
  97. margin: 0 0 10px 0;
  98. }
  99. }
  100. </style>