rightView.vue 2.58 KB
<template>
  <div class="right-view">
    <div class="title">得分TOP10</div>
    <el-table :data="scoreList" border style="width: 100%" size="mini">
      <el-table-column label="排名" prop="rank" width="68" align="center">
        <template slot-scope="scope">
          <!-- {{ scope.row.rank }} -->
          <span v-if="scope.row.num <= 3">
            <img :src="medal(scope.row.num)" class="medal" />
          </span>
          <span v-else>{{ scope.row.num }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="姓名"
        prop="name"
        min-width="154"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span class="name">{{ scope.row.name }}</span>
        </template>
      </el-table-column>

      <el-table-column label="得分" prop="score" width="154" align="center">
        <template slot-scope="scope">
          {{ formatScore(scope.row.score) }}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "RightViewTop10",
  data() {
    return {
      scoreList: []
    }
  },
  props: {
    dataView: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    dataView: {
      handler(newValue, oldValue) {
        this.scoreList = newValue.topPersons
      },
      deep: true,
      immediate: true
    }
  },
  computed: {
    // 渲染数据:排序、截取前10并生成 rank
    // rows() {
    //   const normalized = (this.scoreList || []).map((item) => ({
    //     name: item && item.name != null ? String(item.name) : "",
    //     score: Number(item && item.score != null ? item.score : 0)
    //   }))
    //   return normalized
    //     .sort((a, b) => b.score - a.score)
    //     .slice(0, 10)
    //     .map((item, idx) => ({
    //       rank: idx + 1,
    //       name: item.name,
    //       score: item.score
    //     }))
    // }
  },
  methods: {
    medal(rank) {
      return {
        1: require("./image/champion.png"),
        2: require("./image/runner-up.png"),
        3: require("./image/third.png")
      }[rank]
    },
    formatScore(score) {
      const n = Number(score)
      return Number.isFinite(n) ? n : 0
    }
  }
}
</script>

<style scoped lang="scss">
.right-view {
  .title {
    color: #333333;
    font-size: 14px;
    margin-bottom: 8px;
  }
  ::v-deep .el-table {
    color: #666666;
    font-size: 14px;
    font-weight: 500;
    .name {
      color: #333333 !important;
      font-weight: 400;
    }
    .medal {
      width: 24px;
      height: 24px;
    }
  }
}
</style>