Skip to content

Commit c4551a6

Browse files
committed
fix(SPA): 排行榜用户名过长时截断
issue #536
1 parent 9b975fa commit c4551a6

File tree

1 file changed

+39
-53
lines changed

1 file changed

+39
-53
lines changed

resources/spa/src/page/rank/components/RankUsersComponent.vue

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
11
<template>
2-
<div
3-
v-if="show"
4-
:class="prefixCls"
5-
>
6-
<div :class="`${prefixCls}-label`">
2+
<div v-if="show" class="c-rank-users-component">
3+
<div class="label">
74
<h6>{{ title }}</h6>
8-
<div
9-
:class="`${prefixCls}-more`"
10-
@click="to(listUrl)"
11-
>
5+
<div class="label-more" @click="to(listUrl)">
126
<span>全部</span>
137
<svg class="m-style-svg m-svg-small">
148
<use xlink:href="#icon-arrow-right" />
159
</svg>
1610
</div>
1711
</div>
18-
<div :class="`${prefixCls}-label`">
12+
<div class="label">
1913
<div
2014
v-for="user in getShow"
2115
:key="user.id"
22-
:class="`${prefixCls}-user m-aln-st`"
16+
class="user-list m-aln-st"
2317
@click="to(`/users/${user.id}`)"
2418
>
25-
<Avatar
26-
:class="`${prefixCls}-user-avatar`"
27-
:user="user"
28-
/>
29-
<p class="m-flex-grow1 m-flex-shrink1 m-text-cut">{{ user.name }}</p>
19+
<Avatar class="avatar" :user="user" />
20+
<p class="m-text-cut user-name">{{ user.name }}</p>
3021
</div>
3122
</div>
3223
</div>
3324
</template>
3425

3526
<script>
36-
const prefixCls = 'rank-list-item'
3727
export default {
3828
name: 'RankUsersComponent',
3929
props: {
@@ -42,31 +32,19 @@ export default {
4232
title: { type: String, required: true },
4333
name: { type: String, required: true },
4434
},
45-
4635
data () {
4736
return {
48-
prefixCls,
4937
users: [],
5038
}
5139
},
52-
5340
computed: {
54-
/**
55-
* 是否展示该排行模块
56-
* @Author Wayne
57-
* @DateTime 2018-01-04
58-
* @Email qiaobin@zhiyicx.com
59-
* @return Boolean
60-
*/
6141
show () {
6242
return this.users.length > 0
6343
},
6444
/**
6545
* 获取前个要被展示的用户
6646
* @Author Wayne
67-
* @DateTime 2018-01-04
6847
* @Email qiaobin@zhiyicx.com
69-
* @return Array
7048
*/
7149
getShow () {
7250
return this.users.slice(0, 5)
@@ -75,19 +53,15 @@ export default {
7553
activated () {
7654
this.getUsers()
7755
},
78-
7956
methods: {
8057
to (path) {
8158
if (path) {
8259
this.$router.push({ path })
8360
}
8461
},
85-
8662
getUsers () {
8763
this.$http
88-
.get(this.api, {
89-
validateStatus: status => status === 200,
90-
})
64+
.get(this.api, { validateStatus: status => status === 200 })
9165
.then(({ data = [] }) => {
9266
this.users = [...data]
9367
this.$store.commit('SAVE_RANK_DATA', { name: this.name, data })
@@ -99,33 +73,47 @@ export default {
9973
</script>
10074

10175
<style lang="less" scoped>
102-
@rank-list-prefixCls: rank-list-item;
10376
104-
.@{rank-list-prefixCls} {
77+
.c-rank-users-component {
10578
background-color: #fff;
79+
10680
& + & {
10781
margin-top: 8px;
10882
}
109-
&-label {
110-
&:nth-child(2) {
111-
height: 164px;
112-
margin-left: -30px;
113-
justify-content: flex-start;
114-
padding-bottom: 10px;
115-
}
83+
84+
.label {
11685
font-size: 26px;
11786
padding: 0 30px;
11887
height: 70px;
11988
display: flex;
12089
align-items: center;
12190
justify-content: space-between;
12291
92+
&:nth-child(2) {
93+
height: 164px;
94+
margin-left: -30px;
95+
justify-content: flex-start;
96+
padding-bottom: 10px;
97+
}
98+
12399
h6 {
124100
font-size: 30px;
125101
color: #333;
126102
}
103+
104+
.label-more {
105+
display: flex;
106+
align-items: center;
107+
108+
span {
109+
margin: 0 5px;
110+
color: #999;
111+
font-size: 24px;
112+
}
113+
}
127114
}
128-
&-user {
115+
116+
.user-list {
129117
overflow: hidden;
130118
font-size: 24px;
131119
width: calc(~"20% - " 30px);
@@ -135,9 +123,10 @@ export default {
135123
flex-direction: column;
136124
text-align: center;
137125
138-
&-avatar {
126+
.avatar {
139127
width: 100px;
140128
height: 100px;
129+
141130
span {
142131
color: #666;
143132
width: 100%;
@@ -148,14 +137,11 @@ export default {
148137
height: 100px;
149138
}
150139
}
151-
}
152-
&-more {
153-
display: flex;
154-
align-items: center;
155-
span {
156-
margin: 0 5px;
157-
color: #999;
158-
font-size: 24px;
140+
141+
.user-name {
142+
flex: auto;
143+
margin-top: 10px;
144+
max-width: 4em;
159145
}
160146
}
161147

0 commit comments

Comments
 (0)