|
@@ -1,7 +1,5 @@
|
|
|
<template>
|
|
|
- <span :company="after">
|
|
|
- {{icount}}
|
|
|
- </span>
|
|
|
+ <span :company="after">{{icount}}</span>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
@@ -14,8 +12,14 @@ export default {
|
|
|
default: 0,
|
|
|
type: Number
|
|
|
},
|
|
|
- start: {
|
|
|
+ startCount: {
|
|
|
+ default: null
|
|
|
+ },
|
|
|
+ startUp: {
|
|
|
default: true
|
|
|
+ },
|
|
|
+ type: {
|
|
|
+ default: 'up'
|
|
|
}
|
|
|
},
|
|
|
data () {
|
|
@@ -24,30 +28,61 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
mounted () {
|
|
|
- var countStr = this.count.toString()
|
|
|
- var startNum = Number(countStr[0] - 1 + countStr.slice(1))
|
|
|
-
|
|
|
- if (this.count - startNum < 100) {
|
|
|
- startNum = 0
|
|
|
+ if (this.type === 'up') {
|
|
|
+ this.upAttr()
|
|
|
+ } else {
|
|
|
+ this.downAttr()
|
|
|
}
|
|
|
-
|
|
|
- this.endNum = this.icount
|
|
|
- this.icount = startNum
|
|
|
- this.interval = Math.ceil((this.endNum - startNum) / 100)
|
|
|
this.excessive = this.excessive.bind(this)
|
|
|
- this.start && this.excessive()
|
|
|
+ this.startUp && this.excessive()
|
|
|
},
|
|
|
methods: {
|
|
|
+ upAttr () {
|
|
|
+ let startNum
|
|
|
+ if (this.startCount === null) {
|
|
|
+ let countStr = this.count.toString()
|
|
|
+ startNum = Number(countStr[0] - 1 + countStr.slice(1))
|
|
|
+
|
|
|
+ if (this.count - startNum < 100) {
|
|
|
+ startNum = 0
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ startNum = this.startCount
|
|
|
+ }
|
|
|
+
|
|
|
+ this.endNum = this.icount
|
|
|
+ this.icount = startNum
|
|
|
+ this.interval = Math.ceil((this.endNum - startNum) / 100)
|
|
|
+ },
|
|
|
+ downAttr () {
|
|
|
+ let startNum
|
|
|
+ if (this.startCount === null) {
|
|
|
+ let countStr = this.count.toString()
|
|
|
+ startNum = Number(Number(countStr[0]) + 1 + countStr.slice(1))
|
|
|
+
|
|
|
+ if (startNum - this.count < 100) {
|
|
|
+ startNum = this.count + 100
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ startNum = this.startCount
|
|
|
+ }
|
|
|
+
|
|
|
+ this.endNum = this.icount
|
|
|
+ this.icount = startNum
|
|
|
+ this.interval = Math.ceil((this.endNum - startNum) / 100)
|
|
|
+ },
|
|
|
excessive () {
|
|
|
- if (this.icount === this.endNum) {
|
|
|
- return
|
|
|
+ if ((this.interval > 0 && this.icount + this.interval >= this.endNum) ||
|
|
|
+ (this.interval < 0 && this.icount + this.interval <= this.endNum)) {
|
|
|
+ return this.icount = this.endNum
|
|
|
}
|
|
|
+
|
|
|
this.icount += this.interval
|
|
|
requestAnimationFrame(this.excessive)
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
- start (newVal) {
|
|
|
+ startUp (newVal) {
|
|
|
newVal && this.excessive()
|
|
|
}
|
|
|
}
|