cart-para-curve.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view>
  3. <view v-if="cart_icon_data != null && (cart_icon_data.status || 0) == 1" class="cart-para-curve-container pf round" :style="cart_icon_data.style">
  4. <image v-if="(cart_icon_data.icon || null) != null" class="cart-para-curve-icon round br" :src="cart_icon_data.icon"></image>
  5. <view v-else class="cart-para-curve-icon bg-red padding dis-inline-block round br"></view>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. const app = getApp();
  11. export default {
  12. data() {
  13. return {
  14. cart_icon_data: null
  15. };
  16. },
  17. components: {},
  18. props: {
  19. propBtnHeight: {
  20. type: Number,
  21. default: 30
  22. },
  23. propBtnWidth: {
  24. type: Number,
  25. default: 30
  26. },
  27. propCart: {
  28. type: String,
  29. default: ''
  30. },
  31. },
  32. methods: {
  33. // 初始(购物车对象、当前点击对象、图标)
  34. init(cart, pos, icon = '') {
  35. if((pos || null) != null) {
  36. var self = this;
  37. var btn_size = this.propBtnHeight;
  38. var btn_width = this.propBtnWidth;
  39. // 未指定购物车对象则读取tabbar数据自动计算购物车位置
  40. if((cart || null) == null || (cart[0] || null) == null) {
  41. var info = uni.getSystemInfoSync();
  42. var tabbar = app.globalData.data.tabbar_pages;
  43. // 无购物车菜单则结束执行
  44. var tabbar_cart_pos = tabbar.indexOf('/pages/cart/cart');
  45. if(tabbar_cart_pos == -1) {
  46. return false;
  47. }
  48. // 计算购物车菜单位置
  49. var tabbar_count = tabbar.length;
  50. var cart_top = info.screenHeight;
  51. var cart_width = info.screenWidth/tabbar_count;
  52. var cart_left = cart_width*tabbar_cart_pos;
  53. } else {
  54. var temp = cart[0];
  55. var cart_width = temp.width;
  56. var cart_left = temp.left;
  57. var cart_top = temp.top;
  58. }
  59. var left = pos.changedTouches[0].clientX + btn_width/2 - btn_size/2;
  60. var top = pos.changedTouches[0].clientY - btn_size;
  61. var x = cart_left + cart_width/2 - btn_size/2 - left;
  62. var y = cart_top - btn_size - top;
  63. if(self.cart_icon_data == null || (self.cart_icon_data.status || 0) == 0) {
  64. self.setData({cart_icon_data: {
  65. status: 1,
  66. style: `--left:${left}px;--top:${top}px;--x:${x}px;--y:${y}px;`,
  67. icon: icon,
  68. }});
  69. setTimeout(function(){
  70. self.setData({ cart_icon_data: {status: 0}});
  71. }, 495);
  72. }
  73. }
  74. }
  75. }
  76. };
  77. </script>
  78. <style>
  79. @keyframes moveY {
  80. to {
  81. transform: translateY(var(--y));
  82. }
  83. }
  84. @keyframes moveX {
  85. to {
  86. transform: translateX(var(--x));
  87. }
  88. }
  89. .cart-para-curve-container {
  90. width: 60rpx;
  91. height: 60rpx;
  92. z-index: 10;
  93. left: var(--left);
  94. top: var(--top);
  95. --duration: 0.5s;
  96. animation: moveY var(--duration) cubic-bezier(0.5, -0.25, 1, 1);
  97. }
  98. .cart-para-curve-container .cart-para-curve-icon {
  99. max-width: 100%;
  100. max-height: 100%;
  101. animation: moveX var(--duration) linear;
  102. }
  103. </style>