rightView.vue
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<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>