list.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="app-container">
  3. <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
  4. <el-table-column align="center" label="ID" width="80">
  5. <template slot-scope="scope">
  6. <span>{{ scope.row.id }}</span>
  7. </template>
  8. </el-table-column>
  9. <el-table-column width="180px" align="center" label="Date">
  10. <template slot-scope="scope">
  11. <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
  12. </template>
  13. </el-table-column>
  14. <el-table-column width="120px" align="center" label="Author">
  15. <template slot-scope="scope">
  16. <span>{{ scope.row.author }}</span>
  17. </template>
  18. </el-table-column>
  19. <el-table-column width="100px" label="Importance">
  20. <template slot-scope="scope">
  21. <svg-icon v-for="n in +scope.row.importance" :key="n" icon-class="star" class="meta-item__icon" />
  22. </template>
  23. </el-table-column>
  24. <el-table-column class-name="status-col" label="Status" width="110">
  25. <template slot-scope="{row}">
  26. <el-tag :type="row.status | statusFilter">
  27. {{ row.status }}
  28. </el-tag>
  29. </template>
  30. </el-table-column>
  31. <el-table-column min-width="300px" label="Title">
  32. <template slot-scope="{row}">
  33. <router-link :to="'/example/edit/'+row.id" class="link-type">
  34. <span>{{ row.title }}</span>
  35. </router-link>
  36. </template>
  37. </el-table-column>
  38. <el-table-column align="center" label="Actions" width="120">
  39. <template slot-scope="scope">
  40. <router-link :to="'/example/edit/'+scope.row.id">
  41. <el-button type="primary" size="small" icon="el-icon-edit">
  42. Edit
  43. </el-button>
  44. </router-link>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  49. </div>
  50. </template>
  51. <script>
  52. import { fetchList } from '@/api/article'
  53. import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  54. export default {
  55. name: 'ArticleList',
  56. components: { Pagination },
  57. filters: {
  58. statusFilter(status) {
  59. const statusMap = {
  60. published: 'success',
  61. draft: 'info',
  62. deleted: 'danger'
  63. }
  64. return statusMap[status]
  65. }
  66. },
  67. data() {
  68. return {
  69. list: null,
  70. total: 0,
  71. listLoading: true,
  72. listQuery: {
  73. page: 1,
  74. limit: 20
  75. }
  76. }
  77. },
  78. created() {
  79. this.getList()
  80. },
  81. methods: {
  82. getList() {
  83. this.listLoading = true
  84. fetchList(this.listQuery).then(response => {
  85. this.list = response.data.items
  86. this.total = response.data.total
  87. this.listLoading = false
  88. })
  89. }
  90. }
  91. }
  92. </script>
  93. <style scoped>
  94. .edit-input {
  95. padding-right: 100px;
  96. }
  97. .cancel-btn {
  98. position: absolute;
  99. right: 15px;
  100. top: 10px;
  101. }
  102. </style>