pull/9/head
tangjinzhou 2017-12-29 16:52:58 +08:00
commit 280af6d07a
5 changed files with 205 additions and 45 deletions

View File

@ -6,15 +6,17 @@
</template> </template>
<template v-else> <template v-else>
<slot></slot> <slot></slot>
<scroll-number <transition appear :name="transitionName">
v-if="!badgeStatus.isHidden" <scroll-number
:prefixCls="scrollNumberPrefixCls" v-if="!badgeStatus.isHidden"
:className="badgeComputedCls.scrollNumberCls" :prefixCls="scrollNumberPrefixCls"
:count="badgeStatus.stateCount" :className="badgeComputedCls.scrollNumberCls"
:titleNumber="count" :count="badgeStatus.stateCount"
:styleNumber="styles" :titleNumber="count"
> :styleNumber="styles"
</scroll-number> >
</scroll-number>
</transition>
<span <span
v-if="!badgeStatus.isHidden && text" v-if="!badgeStatus.isHidden && text"
:class="[prefixCls+'-status-text']"> :class="[prefixCls+'-status-text']">
@ -70,8 +72,11 @@ export default {
}, },
}, },
data () { data () {
const { prefixCls, $slots } = this
const isHasDefaultSlot = $slots && !!$slots.default
return { return {
isHasDefaultSlot: this.$slots && !!this.$slots.default, isHasDefaultSlot,
transitionName: isHasDefaultSlot ? `${prefixCls}-zoom` : '',
} }
}, },
computed: { computed: {
@ -99,7 +104,7 @@ export default {
} }
}, },
badgeStatus () { badgeStatus () {
const { count, overflowCount, showZero, dot, text, status } = this const { count, overflowCount, showZero, dot, text } = this
let stateCount = +count > +overflowCount ? `${overflowCount}+` : count let stateCount = +count > +overflowCount ? `${overflowCount}+` : count
const isDot = dot || text const isDot = dot || text
if (isDot) { if (isDot) {
@ -113,9 +118,6 @@ export default {
isHidden, isHidden,
} }
}, },
},
methods: {
}, },
components: { components: {
Icon, Icon,

View File

@ -1,10 +1,13 @@
<template>
<sup :class="[prefixCls, className]" :title="titleNumber" :style="styleNumber">
<!-- <span v-if="!count || isNaN(count)">{{count}}</span> -->
<span>{{count}}</span>
</sup>
</template>
<script> <script>
import StateMixin from '../_util/StateMixin'
function getNumberArray (num) {
return num
? num.toString()
.split('')
.reverse()
.map(i => Number(i)) : []
}
export default { export default {
name: 'ScrollNumber', name: 'ScrollNumber',
props: { props: {
@ -17,18 +20,108 @@ export default {
default: () => ({}), default: () => ({}),
}, },
}, },
mixins: [StateMixin],
data () { data () {
const { count } = this
return { return {
animateStarted: true,
lastCount: 0,
stateCount: count,
} }
}, },
computed: { watch: {
count (newValue, oldValue) {
//
this.setState({
animateStarted: true,
lastCount: oldValue,
}, () => {
//
//
setTimeout(() => {
this.setState({
animateStarted: false,
stateCount: newValue,
})
}, 30)
})
},
}, },
methods: { methods: {
getPositionByNum (num, i) {
const { animateStarted, lastCount, stateCount } = this
if (animateStarted) {
return 10 + num
}
const currentDigit = getNumberArray(stateCount)[i]
const lastDigit = getNumberArray(lastCount)[i]
//
if (stateCount > lastCount) {
if (currentDigit >= lastDigit) {
return 10 + num
}
return 20 + num
}
if (currentDigit <= lastDigit) {
return 10 + num
}
return num
},
renderNumberList (position) {
const childrenArr = new Array(30).fill(1)
const childrenHtml = childrenArr.map((item, i) => {
const currentClassName = (position === i) ? 'current' : ''
return <p key={i.toString()} class={currentClassName}>{i % 10}</p>
})
return childrenHtml
},
renderCurrentNumber (num, i) {
const { animateStarted, prefixCls } = this
const position = this.getPositionByNum(num, i)
let removeTransition = animateStarted ||
(getNumberArray(this.lastCount)[i] === undefined)
if (!removeTransition) {
removeTransition = ''
}
const styleSpan = {
transition: `${removeTransition}` && 'none',
msTransform: `translateY(${-position * 100}%)`,
WebkitTransform: `translateY(${-position * 100}%)`,
transform: `translateY(${-position * 100}%)`,
}
return (
<span
key={i}
class={`${prefixCls}-only`}
style = {styleSpan}
>
{
this.renderNumberList(position)
}
</span>
)
},
renderNumberElement () {
const { stateCount } = this
if (!stateCount || isNaN(Number(stateCount))) {
return stateCount
}
return getNumberArray(stateCount)
.map((num, i) => this.renderCurrentNumber(num, i)).reverse()
},
}, },
components: { render () {
const { prefixCls, className, titleNumber, styleNumber } = this
return (
<sup
class={[prefixCls, className]}
title={titleNumber}
style={styleNumber}>
{
this.renderNumberElement()
}
</sup>
)
}, },
} }
</script> </script>

View File

@ -1,5 +1,49 @@
<template> <template>
<div> <div>
基本
<div>
<Badge count=5>
<a href="#" class="head-example" />
</Badge>
<Badge count=0 showZero>
<a href="#" class="head-example" />
</Badge>
</div>
<br>
独立使用
<div>
<Badge count=25 />
<Badge count=4 :styles="{backgroundColor: '#fff', color: '#999', boxShadow: '0 0 0 1px #d9d9d9 inset'}" />
<Badge count=109 :styles= "{backgroundColor: '#52c41a'} " />
</div>
<br>
封顶数字
<div style="margin-top: 10px">
<Badge count=99>
<a href="#" class="head-example" />
</Badge>
<Badge count=100>
<a href="#" class="head-example" />
</Badge>
<Badge count=99 overflowCount=10>
<a href="#" class="head-example" />
</Badge>
<Badge count=1000 overflowCount=999>
<a href="#" class="head-example" />
</Badge>
</div>
<br>
讨嫌的小红点
<div style="margin-top: 10px">
<Badge dot>
<Icon type="notification" />
</Badge>
<Badge dot>
<a href="#">Link something</a>
</Badge>
</div>
<br>
状态点
<div> <div>
<Badge status="success" /> <Badge status="success" />
<Badge status="error" /> <Badge status="error" />
@ -19,12 +63,17 @@
<Badge status="warning" text="Warning" /> <Badge status="warning" text="Warning" />
</div> </div>
<br /> <br />
动态
<div> <div>
<Badge :count="count"> <Badge :count="count">
<a href="#" class="head-example" /> <a href="#" class="head-example" />
</Badge> </Badge>
<ant-button @click="changeValue(1)"></ant-button> <ant-button @click="changeMinsValue()">
<ant-button @click="changeValue(-1)"></ant-button> <Icon type="minus" />
</ant-button>
<ant-button @click="changePlusValue(1)">
<Icon type="plus" />
</ant-button>
<br/> <br/>
<Badge :dot="isShow"> <Badge :dot="isShow">
<a href="#" class="head-example" /> <a href="#" class="head-example" />
@ -36,12 +85,13 @@
</template> </template>
<script> <script>
import '../style' import '../style'
import { Badge, Button } from 'antd/index' let i = 0
import { Badge, Button, Icon } from 'antd/index'
export default { export default {
data () { data () {
return { return {
currentStatus: 'warning', currentStatus: 'warning',
count: 98, count: 3,
isShow: true, isShow: true,
} }
}, },
@ -49,8 +99,22 @@ export default {
changeStatus () { changeStatus () {
this.currentStatus = 'processing' this.currentStatus = 'processing'
}, },
changeValue (val) { changeMinsValue () {
this.count = this.count + val i++
console.dir(i)
let count = this.count - 1
if (count < 0) {
count = 0
}
this.count = count
},
changePlusValue () {
setInterval(() => {
const count = this.count + 1
this.count = count
}, 300)
// const count = this.count + 1
// this.count = count
}, },
changeShow () { changeShow () {
this.isShow = !this.isShow this.isShow = !this.isShow
@ -59,6 +123,7 @@ export default {
components: { components: {
Badge, Badge,
AntButton: Button, AntButton: Button,
Icon,
}, },
} }
</script> </script>
@ -70,4 +135,7 @@ export default {
background: #eee; background: #eee;
display: inline-block; display: inline-block;
} }
.ant-badge{
margin-right: 20px;
}
</style> </style>

View File

@ -91,12 +91,12 @@
} }
&-zoom-appear, &-zoom-appear,
&-zoom-enter { &-zoom-enter-active {
animation: antZoomBadgeIn .3s @ease-out-back; animation: antZoomBadgeIn .3s @ease-out-back;
animation-fill-mode: both; animation-fill-mode: both;
} }
&-zoom-leave { &-zoom-leave-active {
animation: antZoomBadgeOut .3s @ease-in-back; animation: antZoomBadgeOut .3s @ease-in-back;
animation-fill-mode: both; animation-fill-mode: both;
} }
@ -135,26 +135,23 @@
@keyframes antZoomBadgeIn { @keyframes antZoomBadgeIn {
0% { 0% {
opacity: 0; opacity: 0;
transform: scale(0) translateX(-50%); transform-origin: 100% 50%;
transform: scale(0) translateX(50%);
} }
100% { 100% {
transform: scale(1) translateX(-50%); transform-origin: 100% 50%;
transform: scale(1) translateX(50%);
} }
} }
@keyframes antZoomBadgeOut { @keyframes antZoomBadgeOut {
0% { 0% {
transform: scale(1) translateX(-50%); transform-origin: 100% 50%;
transform: scale(1) translateX(50%);
} }
100% { 100% {
opacity: 0; opacity: 0;
transform: scale(0) translateX(-50%); transform-origin: 100% 50%;
transform: scale(0) translateX(50%);
} }
} }
.fade-enter-active, .fade-leave-active {
transition: opacity 3s;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}

View File

@ -32,7 +32,7 @@
<Icon type="heart" /> <Icon type="heart" />
</Rate> </Rate>
</br> </br>
<Rate :value="initValue" :allowHalf="allowHalf" character="A"></Rate> <Rate :defaultValue="initValue" :allowHalf="allowHalf" character="A"></Rate>
</br> </br>
<Rate :value="initValue" character="好"></Rate> <Rate :value="initValue" character="好"></Rate>
</div> </div>