Skip to content

Commit fae2b93

Browse files
committed
feat: add NumberInfo, Ellipsis components
1 parent 1b02e1a commit fae2b93

File tree

7 files changed

+251
-7
lines changed

7 files changed

+251
-7
lines changed

src/components/Ellipsis/Ellipsis.vue

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<script>
2+
import Tooltip from 'ant-design-vue/es/tooltip'
3+
import { cutStrByFullLength, getStrFullLength } from '@/components/_util/StringUtil'
4+
/*
5+
const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;
6+
7+
const TooltipOverlayStyle = {
8+
overflowWrap: 'break-word',
9+
wordWrap: 'break-word',
10+
};
11+
*/
12+
13+
export default {
14+
name: 'Ellipsis',
15+
components: {
16+
Tooltip
17+
},
18+
props: {
19+
prefixCls: {
20+
type: String,
21+
default: 'ant-pro-ellipsis'
22+
},
23+
tooltip: {
24+
type: Boolean
25+
},
26+
length: {
27+
type: Number,
28+
required: true
29+
},
30+
lines: {
31+
type: Number,
32+
default: 1
33+
},
34+
fullWidthRecognition: {
35+
type: Boolean,
36+
default: false
37+
}
38+
},
39+
methods: {
40+
getStrDom (str) {
41+
return (
42+
<span>{ cutStrByFullLength(str, this.length) + '...' }</span>
43+
)
44+
},
45+
getTooltip ( fullStr) {
46+
return (
47+
<Tooltip>
48+
<template slot="title">{ fullStr }</template>
49+
{ this.getStrDom(fullStr) }
50+
</Tooltip>
51+
)
52+
}
53+
},
54+
render () {
55+
const { tooltip, length } = this.$props
56+
let str = this.$slots.default.map(vNode => vNode.text).join("")
57+
const strDom = tooltip && getStrFullLength(str) > length ? this.getTooltip(str) : this.getStrDom(str);
58+
return (
59+
strDom
60+
)
61+
}
62+
}
63+
</script>

src/components/Ellipsis/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Ellipsis from './Ellipsis'
2+
3+
export default Ellipsis
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<template>
2+
<div :class="[prefixCls]">
3+
<slot name="subtitle">
4+
<div :class="[`${prefixCls}-subtitle`]">{{ typeof subTitle === 'string' ? subTitle : subTitle() }}</div>
5+
</slot>
6+
<div class="number-info-value">
7+
<span>{{ total }}</span>
8+
<span class="sub-total">
9+
{{ subTotal }}
10+
<icon :type="`caret-${status}`" />
11+
</span>
12+
</div>
13+
</div>
14+
</template>
15+
16+
<script>
17+
import Icon from 'ant-design-vue/es/icon'
18+
19+
export default {
20+
name: 'NumberInfo',
21+
props: {
22+
prefixCls: {
23+
type: String,
24+
default: 'ant-pro-number-info'
25+
},
26+
total: {
27+
type: Number,
28+
required: true
29+
},
30+
subTotal: {
31+
type: Number,
32+
required: true
33+
},
34+
subTitle: {
35+
type: [String, Function],
36+
default: ''
37+
},
38+
status: {
39+
type: String,
40+
default: 'up'
41+
}
42+
},
43+
components: {
44+
Icon
45+
},
46+
data () {
47+
return {}
48+
}
49+
}
50+
</script>
51+
52+
<style lang="less" scoped>
53+
@import "index";
54+
</style>

src/components/NumberInfo/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import NumberInfo from './NumberInfo'
2+
3+
export default NumberInfo

src/components/NumberInfo/index.less

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@import "../index";
2+
3+
@numberInfo-prefix-cls: ~"@{ant-pro-prefix}-number-info";
4+
5+
.@{numberInfo-prefix-cls} {
6+
7+
.ant-pro-number-info-subtitle {
8+
color: @text-color-secondary;
9+
font-size: @font-size-base;
10+
height: 22px;
11+
line-height: 22px;
12+
overflow: hidden;
13+
text-overflow: ellipsis;
14+
word-break: break-all;
15+
white-space: nowrap;
16+
}
17+
18+
.number-info-value {
19+
margin-top: 4px;
20+
font-size: 0;
21+
overflow: hidden;
22+
text-overflow: ellipsis;
23+
word-break: break-all;
24+
white-space: nowrap;
25+
26+
& > span {
27+
color: @heading-color;
28+
display: inline-block;
29+
line-height: 32px;
30+
height: 32px;
31+
font-size: 24px;
32+
margin-right: 32px;
33+
}
34+
35+
.sub-total {
36+
color: @text-color-secondary;
37+
font-size: @font-size-lg;
38+
vertical-align: top;
39+
margin-right: 0;
40+
i {
41+
font-size: 12px;
42+
transform: scale(0.82);
43+
margin-left: 4px;
44+
}
45+
:global {
46+
.anticon-caret-up {
47+
color: @red-6;
48+
}
49+
.anticon-caret-down {
50+
color: @green-6;
51+
}
52+
}
53+
}
54+
}
55+
}

src/components/_util/StringUtil.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
export const getStrFullLength = (str = '') =>
3+
str.split('').reduce((pre, cur) => {
4+
const charCode = cur.charCodeAt(0)
5+
if (charCode >= 0 && charCode <= 128) {
6+
return pre + 1
7+
}
8+
return pre + 2
9+
}, 0)
10+
11+
export const cutStrByFullLength = (str = '', maxLength) => {
12+
let showLength = 0
13+
return str.split('').reduce((pre, cur) => {
14+
const charCode = cur.charCodeAt(0)
15+
if (charCode >= 0 && charCode <= 128) {
16+
showLength += 1
17+
} else {
18+
showLength += 2
19+
}
20+
if (showLength <= maxLength) {
21+
return pre + cur
22+
}
23+
return pre
24+
}, '')
25+
}

src/views/Home.vue

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="home">
33
<div class="banner">
44
<img alt="Vue logo" style="width: 64px; height: 64px" src="../assets/logo.png">
5-
<h3>Welcome to Your Vue.js App</h3>
5+
<h3 style="margin-top: 1rem">Welcome to Your Vue.js App</h3>
66
</div>
77

88
<br/>
@@ -30,7 +30,7 @@
3030

3131
<a-divider> 颜色反转 </a-divider>
3232

33-
<a-card>
33+
<a-card style="margin-bottom: 3rem">
3434

3535
<trend flag="up" :reverse-color="true" style="margin-right: 16px;">
3636
<span slot="term">工资</span>
@@ -43,9 +43,10 @@
4343

4444
</a-card>
4545

46-
<a-divider> AvatarList </a-divider>
46+
<h2># AvatarList 组件 </h2>
4747

48-
<a-card>
48+
<a-divider> AvatarList </a-divider>
49+
<a-card style="margin-bottom: 3rem">
4950
<avatar-list :max-length="3">
5051
<avatar-list-item tips="Jake" src="https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png" />
5152
<avatar-list-item tips="Andy" src="https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png" />
@@ -66,14 +67,44 @@
6667
</avatar-list>
6768
</a-card>
6869

69-
<a-divider> CountDown </a-divider>
70+
<h2># CountDown 组件 </h2>
7071

71-
<a-card>
72+
<a-divider> CountDown </a-divider>
73+
<a-card style="margin-bottom: 3rem">
7274
<count-down
7375
style="font-size: 2rem"
74-
:target="new Date().getTime() + 3000"
76+
:target="new Date().getTime() + 3000000"
7577
:on-end="onEndHandle">
7678
</count-down>
79+
80+
<a-divider type="vertical" style="margin: 0 16px" />
81+
82+
<count-down
83+
style="font-size: 2rem"
84+
:target="new Date().getTime() + 10000"
85+
:on-end="onEndHandle2">
86+
</count-down>
87+
</a-card>
88+
89+
<h2># Ellipsis 组件 </h2>
90+
91+
<a-divider> Ellipsis </a-divider>
92+
<a-card style="margin-bottom: 3rem">
93+
<ellipsis :length="100" tooltip>
94+
There were injuries alleged in three cases in 2015, and a
95+
fourth incident in September, according to the safety recall report. After meeting with US regulators in October, the firm decided to issue a voluntary recall.
96+
</ellipsis>
97+
</a-card>
98+
99+
<h2># NumberInfo 组件 </h2>
100+
101+
<a-divider> NumberInfo </a-divider>
102+
<a-card>
103+
<number-info
104+
:sub-title="() => { return 'Visits this week' }"
105+
:total="12321"
106+
status="up"
107+
:sub-total="17.1"></number-info>
77108
</a-card>
78109
</div>
79110
</template>
@@ -84,12 +115,16 @@
84115
import Trend from '@/components/Trend'
85116
import AvatarList from '@/components/AvatarList'
86117
import CountDown from '@/components/CountDown/CountDown'
118+
import Ellipsis from '@/components/Ellipsis'
119+
import NumberInfo from '@/components/NumberInfo'
87120
88121
const AvatarListItem = AvatarList.AvatarItem
89122
90123
export default {
91124
name: 'Home',
92125
components: {
126+
NumberInfo,
127+
Ellipsis,
93128
CountDown,
94129
Trend,
95130
AvatarList,
@@ -103,6 +138,12 @@
103138
methods: {
104139
onEndHandle () {
105140
this.$message.success('CountDown callback!!!')
141+
},
142+
onEndHandle2 () {
143+
this.$notification.open({
144+
message: 'Notification Title',
145+
description: 'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
146+
});
106147
}
107148
}
108149
}

0 commit comments

Comments
 (0)