TreeAnimation.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div
  3. ref="hammer-target"
  4. class="tree-animation"
  5. >
  6. <img
  7. v-for="index of frameNumber"
  8. v-show="((index - 1) === currentFrameIdx) || ((index - 1) === (currentFrameIdx - 1))"
  9. :key="index"
  10. :src="`${$publicPath}tree-grow-frames/初始画面_${(index - 1).toString().padStart(4, '0')}.jpg`"
  11. alt=""
  12. @load="onImgLoad(index - 1)"
  13. @error="onImgError(index - 1)"
  14. >
  15. <SlideTip
  16. v-show="currentFrameIdx === frameNumber - 1"
  17. class="slide-tip"
  18. text="了<br>解<br>详<br>情"
  19. />
  20. <van-loading
  21. v-show="isLoading"
  22. color="#1989fa"
  23. class="loading"
  24. type="spinner"
  25. size="3rem"
  26. vertical
  27. >
  28. <span style="font-size: 1rem;">
  29. {{ frameLoadProgress }}
  30. </span>
  31. </van-loading>
  32. </div>
  33. </template>
  34. <script>
  35. const frameNumber = 927
  36. export default {
  37. data() {
  38. return {
  39. frameNumber,
  40. loadedNumber: 0,
  41. currentFrameIdx: 0,
  42. intervalId: null,
  43. imgStateList: new Array(frameNumber),
  44. loadCountDown: 100,
  45. isLoading: true,
  46. }
  47. },
  48. computed: {
  49. frameLoadProgress() {
  50. return Math.floor(this.loadedNumber / frameNumber * 100) + '%'
  51. }
  52. },
  53. mounted() {
  54. this.intervalId = setInterval(() => {
  55. if (this.frameLoadProgress === '100%') {
  56. // if ((this.loadCountDown === 0) && (this.imgStateList[this.currentFrameIdx + 1] !== undefined)) {
  57. this.isLoading = false
  58. do {
  59. this.currentFrameIdx++
  60. } while (this.imgStateList[this.currentFrameIdx] === false)
  61. if (this.currentFrameIdx >= frameNumber - 1) {
  62. clearInterval(this.intervalId)
  63. let mc = new Hammer(this.$refs['hammer-target'])
  64. mc.get('pan').set({ direction: Hammer.DIRECTION_ALL })
  65. const that = this
  66. mc.on("panup", function me() {
  67. mc.off('panup', me)
  68. that.$router.push({ name: 'TreeSelection' })
  69. })
  70. }
  71. } else {
  72. this.isLoading = true
  73. }
  74. }, 31) // todo
  75. },
  76. unmounted() {
  77. },
  78. methods: {
  79. onImgLoad(idx) {
  80. if (idx < 100) {
  81. this.loadCountDown--
  82. }
  83. this.loadedNumber++
  84. this.imgStateList[idx] = true
  85. },
  86. onImgError(idx) {
  87. if (idx < 100) {
  88. this.loadCountDown--
  89. }
  90. this.loadedNumber++
  91. this.imgStateList[idx] = false
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="less" scoped>
  97. .tree-animation {
  98. width: 100%;
  99. height: 100%;
  100. position: relative;
  101. img {
  102. width: 100%;
  103. height: 100%;
  104. object-fit: contain;
  105. position: absolute;
  106. top: 0;
  107. left: 0;
  108. }
  109. .loading {
  110. position: fixed;
  111. top: 50%;
  112. left: 50%;
  113. transform: translate(-50%, -50%);
  114. }
  115. }
  116. </style>