Merge branch 'feat_可同步长江大学的优化_fix'
# Conflicts: # .gitignore
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
<el-table-column label="总分" prop="totalScore" header-align="center"
|
||||
align="center" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column align="center" header-align="center" type="index" :index="indexMethod" label="名次"
|
||||
<el-table-column align="center" header-align="center" prop="rank" label="名次"
|
||||
width="80px"></el-table-column>
|
||||
|
||||
</el-table>
|
||||
@@ -47,7 +47,21 @@ module.exports = {
|
||||
this.tableData = []
|
||||
const {data} = await this.$axios.post(loc() + "/isScoreTopEight", this.Form)
|
||||
const table = data.score.sort(this.compare("totalScore"))
|
||||
this.tableData = table.slice(0, 8)
|
||||
// 按竞赛名次规则取前八:同分并列同名次,并列后名次不跳号(dense rank);
|
||||
// 名次大于 8 的舍弃。不能直接 slice(0, 8),否则同分并列的工会会被切掉。
|
||||
const ranked = []
|
||||
let rank = 0
|
||||
let prevScore = null
|
||||
table.forEach(v => {
|
||||
// 总分带 0.5 折半小数,比较用容差,避免浮点误差误判并列
|
||||
if (prevScore === null || Math.abs(v.totalScore - prevScore) > 0.000001) {
|
||||
// 每遇到一个新的分值,名次 +1;同分者沿用同一名次
|
||||
rank += 1
|
||||
prevScore = v.totalScore
|
||||
}
|
||||
ranked.push(Object.assign({}, v, {rank: rank}))
|
||||
})
|
||||
this.tableData = ranked.filter(v => v.rank <= 8)
|
||||
} catch (e) {
|
||||
this.$message.error(e.msg)
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user