index.vue 2.01 KB
Newer Older
Pan's avatar
Pan committed
1 2
<template>
  <div class="app-container">
3 4 5 6 7 8 9 10
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row>
      <el-table-column align="center" label="ID" width="95">
Pan's avatar
Pan committed
11
        <template slot-scope="scope">
12
          {{ scope.$index }}
Pan's avatar
Pan committed
13 14 15
        </template>
      </el-table-column>
      <el-table-column label="Title">
Pan's avatar
Pan committed
16
        <template slot-scope="scope">
17
          {{ scope.row.title }}
Pan's avatar
Pan committed
18 19 20
        </template>
      </el-table-column>
      <el-table-column label="Author" width="110" align="center">
Pan's avatar
Pan committed
21
        <template slot-scope="scope">
22
          <span>{{ scope.row.author }}</span>
Pan's avatar
Pan committed
23 24 25
        </template>
      </el-table-column>
      <el-table-column label="Pageviews" width="110" align="center">
Pan's avatar
Pan committed
26
        <template slot-scope="scope">
27
          {{ scope.row.pageviews }}
Pan's avatar
Pan committed
28 29
        </template>
      </el-table-column>
Pan's avatar
Pan committed
30
      <el-table-column class-name="status-col" label="Status" width="110" align="center">
Pan's avatar
Pan committed
31
        <template slot-scope="scope">
32
          <el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
Pan's avatar
Pan committed
33 34
        </template>
      </el-table-column>
Pan's avatar
Pan committed
35
      <el-table-column align="center" prop="created_at" label="Display_time" width="200">
Pan's avatar
Pan committed
36
        <template slot-scope="scope">
37 38
          <i class="el-icon-time"/>
          <span>{{ scope.row.display_time }}</span>
Pan's avatar
Pan committed
39 40 41 42 43 44 45
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
Pan's avatar
Pan committed
46
import { getList } from '@/api/table'
Pan's avatar
Pan committed
47

Pan's avatar
Pan committed
48
export default {
Pan's avatar
Pan committed
49 50 51 52 53 54 55 56 57 58
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
59 60 61 62 63 64
  data() {
    return {
      list: null,
      listLoading: true
    }
  },
Pan's avatar
Pan committed
65 66 67 68 69 70 71 72 73 74 75 76 77
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getList(this.listQuery).then(response => {
        this.list = response.data.items
        this.listLoading = false
      })
    }
  }
}
Pan's avatar
Pan committed
78
</script>