|
| 1 | +import mpx, { getMixin } from '@mpxjs/core'; |
| 2 | +let mixin = {}; |
| 3 | +if (__mpx_mode__ === 'ios' || __mpx_mode__ === 'android' || __mpx_mode__ === 'harmony') { |
| 4 | + const DURATION = 2000; |
| 5 | + const NORMAL_COLOR = '#ccc'; |
| 6 | + const SECONDARY_COLOR = 'rgba(204, 204, 204, 0.4)'; |
| 7 | + const ACTIVE_COLOR = '#fff'; |
| 8 | + mixin = { |
| 9 | + data: { |
| 10 | + beforeAnim: {}, |
| 11 | + middleAnim: {}, |
| 12 | + afterAnim: {} |
| 13 | + }, |
| 14 | + lifetimes: { |
| 15 | + ready() { |
| 16 | + this.timer = null; |
| 17 | + this.count = 0; |
| 18 | + this.time = 0; |
| 19 | + this.startAnim(); |
| 20 | + }, |
| 21 | + detached() { |
| 22 | + if (this.timer) { |
| 23 | + clearInterval(this.timer); |
| 24 | + this.timer = null; |
| 25 | + } |
| 26 | + } |
| 27 | + }, |
| 28 | + methods: { |
| 29 | + startAnim() { |
| 30 | + if ((this.count - 1) % 3 === 0 || (this.count - 2) % 3 === 0) { |
| 31 | + this.time = 500; |
| 32 | + } |
| 33 | + else if (this.count !== 0 && this.count % 3 === 0) { |
| 34 | + this.time = 1000; |
| 35 | + } |
| 36 | + this.timer = setTimeout(() => { |
| 37 | + if (this.count % 3 === 0) { |
| 38 | + this.executeAnim('beforeAnim'); |
| 39 | + } |
| 40 | + else if ((this.count - 1) % 3 === 0) { |
| 41 | + this.executeAnim('middleAnim'); |
| 42 | + } |
| 43 | + else if ((this.count - 2) % 3 === 0) { |
| 44 | + this.executeAnim('afterAnim'); |
| 45 | + } |
| 46 | + this.startAnim(); |
| 47 | + }, this.time); |
| 48 | + }, |
| 49 | + executeAnim(animName) { |
| 50 | + this.count++; |
| 51 | + this[animName] = {}; |
| 52 | + this.$nextTick(() => { |
| 53 | + this[animName] = this.createDotAnimation(); |
| 54 | + }); |
| 55 | + }, |
| 56 | + createDotAnimation() { |
| 57 | + const duration = DURATION / 4; |
| 58 | + const animation = mpx.createAnimation({ |
| 59 | + duration: DURATION, |
| 60 | + timingFunction: 'linear' |
| 61 | + }); |
| 62 | + animation.scale(1).backgroundColor(NORMAL_COLOR).step({ duration }); |
| 63 | + animation.scale(1.3).backgroundColor(SECONDARY_COLOR).step({ duration }); |
| 64 | + animation.scale(1).backgroundColor(ACTIVE_COLOR).step({ duration }); |
| 65 | + animation.scale(1).backgroundColor(NORMAL_COLOR).step({ duration }); |
| 66 | + return animation.export(); |
| 67 | + } |
| 68 | + } |
| 69 | + }; |
| 70 | +} |
| 71 | +export default getMixin(mixin); |
0 commit comments