Skip to content

Commit 5faac83

Browse files
committed
Merge branches 'dev' and 'master' of https://github.com/sendya/ant-design-pro-vue
2 parents c6d2892 + 2fae054 commit 5faac83

File tree

20 files changed

+806
-15
lines changed

20 files changed

+806
-15
lines changed

src/components/AvatarList/Item.vue

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<template>
2+
<tooltip v-if="tips !== ''">
3+
<template slot="title">{{ tips }}</template>
4+
<avatar :size="avatarSize" :src="src" />
5+
</tooltip>
6+
<avatar v-else :size="avatarSize" :src="src" />
7+
</template>
8+
9+
<script>
10+
import Avatar from 'ant-design-vue/es/avatar'
11+
import Tooltip from 'ant-design-vue/es/tooltip'
12+
13+
export default {
14+
name: "AvatarItem",
15+
components: {
16+
Avatar,
17+
Tooltip
18+
},
19+
props: {
20+
tips: {
21+
type: String,
22+
default: '',
23+
required: false
24+
},
25+
src: {
26+
type: String,
27+
default: ''
28+
}
29+
},
30+
data () {
31+
return {
32+
size: this.$parent.size
33+
}
34+
},
35+
computed: {
36+
avatarSize () {
37+
return this.size !== 'mini' && this.size || 20
38+
}
39+
},
40+
watch: {
41+
'$parent.size' (val) {
42+
this.size = val
43+
}
44+
}
45+
}
46+
</script>

src/components/AvatarList/List.vue

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<!--
2+
<template>
3+
<div :class="[prefixCls]">
4+
<ul>
5+
<slot></slot>
6+
<template v-for="item in filterEmpty($slots.default).slice(0, 3)"></template>
7+
8+
9+
<template v-if="maxLength > 0 && filterEmpty($slots.default).length > maxLength">
10+
<avatar-item :size="size">
11+
<avatar :size="size !== 'mini' && size || 20" :style="excessItemsStyle">{{ `+${maxLength}` }}</avatar>
12+
</avatar-item>
13+
</template>
14+
</ul>
15+
</div>
16+
</template>
17+
-->
18+
19+
<script>
20+
import Avatar from 'ant-design-vue/es/avatar'
21+
import AvatarItem from './Item'
22+
import { filterEmpty } from '@/components/_util/util'
23+
24+
export default {
25+
AvatarItem,
26+
name: "AvatarList",
27+
components: {
28+
Avatar,
29+
AvatarItem
30+
},
31+
props: {
32+
prefixCls: {
33+
type: String,
34+
default: 'ant-pro-avatar-list'
35+
},
36+
/**
37+
* 头像大小 类型: large、small 、mini, default
38+
* 默认值: default
39+
*/
40+
size: {
41+
type: [String, Number],
42+
default: 'default'
43+
},
44+
/**
45+
* 要显示的最大项目
46+
*/
47+
maxLength: {
48+
type: Number,
49+
default: 0
50+
},
51+
/**
52+
* 多余的项目风格
53+
*/
54+
excessItemsStyle: {
55+
type: Object,
56+
default: () => {
57+
return {
58+
color: '#f56a00',
59+
backgroundColor: '#fde3cf'
60+
}
61+
}
62+
}
63+
},
64+
data () {
65+
return {}
66+
},
67+
methods: {
68+
getItems(items) {
69+
const classString = {
70+
[`${this.prefixCls}-item`]: true,
71+
[`${this.size}`]: true
72+
}
73+
74+
if (this.maxLength > 0) {
75+
items = items.slice(0, this.maxLength)
76+
items.push((<Avatar size={ this.size } style={ this.excessItemsStyle }>{`+${this.maxLength}`}</Avatar>))
77+
}
78+
const itemList = items.map((item) => (
79+
<li class={ classString }>{ item }</li>
80+
))
81+
return itemList
82+
}
83+
},
84+
render () {
85+
const { prefixCls, size } = this.$props
86+
const classString = {
87+
[`${prefixCls}`]: true,
88+
[`${size}`]: true,
89+
}
90+
const items = filterEmpty(this.$slots.default)
91+
const itemsDom = items && items.length ? <ul class={`${prefixCls}-items`}>{ this.getItems(items) }</ul> : null
92+
93+
return (
94+
<div class={ classString }>
95+
{ itemsDom }
96+
</div>
97+
)
98+
}
99+
}
100+
</script>

src/components/AvatarList/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import AvatarList from './List'
2+
import "./index.less"
3+
4+
export default AvatarList

src/components/AvatarList/index.less

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
@import "../index";
2+
3+
@avatar-list-prefix-cls: ~"@{ant-pro-prefix}-avatar-list";
4+
@avatar-list-item-prefix-cls: ~"@{ant-pro-prefix}-avatar-list-item";
5+
6+
.@{avatar-list-prefix-cls} {
7+
display: inline-block;
8+
9+
ul {
10+
list-style: none;
11+
display: inline-block;
12+
padding: 0;
13+
margin: 0 0 0 8px;
14+
font-size: 0;
15+
}
16+
}
17+
18+
.@{avatar-list-item-prefix-cls} {
19+
display: inline-block;
20+
font-size: @font-size-base;
21+
margin-left: -8px;
22+
width: @avatar-size-base;
23+
height: @avatar-size-base;
24+
25+
:global {
26+
.ant-avatar {
27+
border: 1px solid #fff;
28+
cursor: pointer;
29+
}
30+
}
31+
32+
&.large {
33+
width: @avatar-size-lg;
34+
height: @avatar-size-lg;
35+
}
36+
37+
&.small {
38+
width: @avatar-size-sm;
39+
height: @avatar-size-sm;
40+
}
41+
42+
&.mini {
43+
width: 20px;
44+
height: 20px;
45+
46+
:global {
47+
.ant-avatar {
48+
width: 20px;
49+
height: 20px;
50+
line-height: 20px;
51+
52+
.ant-avatar-string {
53+
font-size: 12px;
54+
line-height: 18px;
55+
}
56+
}
57+
}
58+
}
59+
}
60+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<template>
2+
<span>
3+
{{ lastTime | format }}
4+
</span>
5+
</template>
6+
7+
<script>
8+
9+
function fixedZero(val) {
10+
return val * 1 < 10 ? `0${val}` : val;
11+
}
12+
13+
export default {
14+
name: "CountDown",
15+
props: {
16+
format: {
17+
type: Function,
18+
default: undefined
19+
},
20+
target: {
21+
type: [Date, Number],
22+
required: true,
23+
},
24+
onEnd: {
25+
type: Function,
26+
default: () => {
27+
}
28+
}
29+
},
30+
data() {
31+
return {
32+
dateTime: '0',
33+
originTargetTime: 0,
34+
lastTime: 0,
35+
timer: 0,
36+
interval: 1000
37+
}
38+
},
39+
filters: {
40+
format(time) {
41+
const hours = 60 * 60 * 1000;
42+
const minutes = 60 * 1000;
43+
44+
const h = Math.floor(time / hours);
45+
const m = Math.floor((time - h * hours) / minutes);
46+
const s = Math.floor((time - h * hours - m * minutes) / 1000);
47+
return `${fixedZero(h)}:${fixedZero(m)}:${fixedZero(s)}`
48+
}
49+
},
50+
created() {
51+
this.initTime()
52+
this.tick()
53+
},
54+
methods: {
55+
initTime() {
56+
let lastTime = 0;
57+
let targetTime = 0;
58+
this.originTargetTime = this.target
59+
try {
60+
if (Object.prototype.toString.call(this.target) === '[object Date]') {
61+
targetTime = this.target
62+
} else {
63+
targetTime = new Date(this.target).getTime()
64+
}
65+
} catch (e) {
66+
throw new Error('invalid target prop')
67+
}
68+
69+
lastTime = targetTime - new Date().getTime();
70+
71+
this.lastTime = lastTime < 0 ? 0 : lastTime
72+
},
73+
tick() {
74+
const {onEnd} = this
75+
76+
this.timer = setTimeout(() => {
77+
if (this.lastTime < this.interval) {
78+
clearTimeout(this.timer)
79+
this.lastTime = 0
80+
if (typeof onEnd === 'function') {
81+
onEnd();
82+
}
83+
} else {
84+
this.lastTime -= this.interval
85+
this.tick()
86+
}
87+
}, this.interval)
88+
}
89+
},
90+
beforeUpdate () {
91+
if (this.originTargetTime !== this.target) {
92+
this.initTime()
93+
}
94+
},
95+
beforeDestroy() {
96+
clearTimeout(this.timer)
97+
}
98+
}
99+
</script>
100+
101+
<style scoped>
102+
103+
</style>

src/components/CountDown/index.js

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

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

0 commit comments

Comments
 (0)