like.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <cover-view class="div like-wraper">
  3. <cover-view class="div animation" @click="like">
  4. <cover-image v-if="aniUrl.length" mode="widthFix" :src="aniUrl[index]" class="img like-icon" :class="animation ? 'gka-wrap' : ''"/>
  5. </cover-view>
  6. </cover-view>
  7. </template>
  8. <script>
  9. // import aniUrl from '@/static/image/live/like-animation-10.png'
  10. export default {
  11. props: {},
  12. data () {
  13. return {
  14. animation: false,
  15. aniUrl:[],
  16. index:0
  17. }
  18. },
  19. methods: {
  20. like () {
  21. if (!this.animation) {
  22. this.animation = true
  23. const timmer = setInterval(() => {
  24. if(this.index<17){
  25. this.index++
  26. }else{
  27. this.animation = false
  28. this.index=0
  29. clearInterval(timmer)
  30. }
  31. }, 50)
  32. this.$emit('like')
  33. } else {
  34. }
  35. },
  36. getImage(index){
  37. var src=''
  38. if(!index){
  39. src='like'
  40. }else{
  41. src='like-animation-'+index
  42. }
  43. uni.getImageInfo({
  44. src: '/static/image/live/'+src+'.png',
  45. success: (image) => {
  46. this.aniUrl[index] = image.path
  47. this.$forceUpdate()
  48. },fail: (error) => {
  49. }
  50. })
  51. },
  52. },
  53. created() {
  54. for(var i=0;i<18;i++){
  55. this.getImage(i)
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .like-icon {
  62. width: 64rpx;
  63. }
  64. .like-wraper {
  65. position: relative;
  66. bottom: -20rpx;
  67. }
  68. .gka-wrap {
  69. width: 130rpx;
  70. }
  71. .animation {
  72. /* #ifndef APP-PLUS-NVUE */
  73. display: flex;
  74. /* #endif */
  75. /* #ifdef APP-PLUS-NVUE */
  76. flex-direction: row;
  77. /* #endif */
  78. align-items: flex-end;
  79. justify-content: center;
  80. width: 130rpx;
  81. }
  82. </style>