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

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

Pan's avatar
Pan committed
42 43 44 45 46
export default {
  data() {
    return {
      list: null,
      listLoading: true
Pan's avatar
Pan committed
47
    }
Pan's avatar
Pan committed
48
  },
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]
    }
  },
Pan's avatar
Pan committed
59 60 61 62 63 64 65 66 67 68 69 70 71
  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
72
</script>