wm-list-add.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view>
  3. <view :animation="animationDataContent" class="animationContent" :style="{'background-color': bgColor }" @click="rotateAndScaleThenTranslate">
  4. <label class="wm-icon wm-icon-gengduo1 moreIcon" v-if="moreFlag" :style="{'color': fontColor }"></label>
  5. <view :animation="animationData" @tap="clickAdd" class="bottom-float" :style="{'background-color': bgColor }">
  6. <label class="wm-icon wm-icon-add addIcon" :style="{'color': fontColor }"></label>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. /**
  13. * wm-list-add 带状态的提交按钮
  14. * @description 一个动效的侧面添加按钮,适用于list场景,避免遮挡用户视线。
  15. * @property {String} bgColor 背景颜色(默认:#5094f2)
  16. * @property {String} fontColor 文字颜色(默认:#ffffff)
  17. * @property {Boolean} isOpen 默认是否关闭动画(默认:否)
  18. * @example
  19. * <wm-list-add ref="add"/>
  20. */
  21. export default {
  22. name: 'wm-list-add',
  23. props: {
  24. // 背景颜色
  25. bgColor: {
  26. type: String,
  27. default: '#5064eb'
  28. },
  29. // 文字颜色
  30. fontColor: {
  31. type: String,
  32. default: '#ffffff'
  33. },
  34. // 是否关闭动画
  35. isOpen: {
  36. type: Boolean,
  37. default: false
  38. },
  39. //列表滑动关闭动画
  40. isClose:{
  41. type: Boolean,
  42. default: false
  43. }
  44. },
  45. created() {
  46. this.init()
  47. },
  48. data() {
  49. return {
  50. animationData: {},
  51. animationDataContent: {},
  52. moreFlag: false,
  53. }
  54. },
  55. methods: {
  56. init() {
  57. if (!this.isOpen) {
  58. this.closeAnimation()
  59. }
  60. },
  61. clickAdd() {
  62. this.$emit('clickAdd');
  63. },
  64. // 关闭右侧添加
  65. closeAnimation() {
  66. if (this.moreFlag) return
  67. const animation1 = uni.createAnimation({
  68. duration: 500,
  69. timingFunction: 'ease',
  70. })
  71. const animation = uni.createAnimation({
  72. duration: 1000,
  73. timingFunction: 'ease',
  74. })
  75. this.animationDataContent = animation1
  76. this.animation = animation
  77. animation1.scale(1, 1).rotate(0).step()
  78. animation.scale(1, 1).rotate(90).step()
  79. this.animationData = animation.export()
  80. this.animationDataContent = animation1.export()
  81. console.log(this.animationData)
  82. setTimeout(function() {
  83. animation1.translate(42).step()
  84. animation.translate(0, -42).step()
  85. this.animationData = animation.export()
  86. this.animationDataContent = animation1.export()
  87. this.moreFlag = true
  88. }.bind(this), 1000)
  89. },
  90. // 打开右侧添加
  91. rotateAndScaleThenTranslate() {
  92. var animation1 = uni.createAnimation({
  93. duration: 500,
  94. timingFunction: 'ease',
  95. })
  96. this.animation1 = animation1
  97. // 先旋转,然后平移
  98. this.animation1.rotate(0).scale(1, 1).step()
  99. this.animation1.translate(0).step()
  100. this.animationDataContent = this.animation1.export()
  101. var animation = uni.createAnimation({
  102. duration: 1000,
  103. timingFunction: 'ease',
  104. })
  105. this.animation = animation
  106. // 先旋转,然后平移
  107. this.animation.rotate(-90).scale(1, 1).step()
  108. this.animation.translate(0, 0).step()
  109. this.animationData = this.animation.export()
  110. this.moreFlag = false
  111. // 5秒自动收回
  112. setTimeout(() => {
  113. this.closeAnimation()
  114. }, 5000)
  115. },
  116. }
  117. }
  118. </script>
  119. <style>
  120. @import url("./css/wm-icon.css");
  121. .animationContent {
  122. position: fixed;
  123. width: 130rpx;
  124. /* background-color: #5094f2; */
  125. height: 100rpx;
  126. bottom: 25%;
  127. right: 0;
  128. z-index: 10;
  129. border-radius: 50rpx 0 0 50rpx;
  130. }
  131. .bottom-float {
  132. position: absolute;
  133. left: 0;
  134. top: 0;
  135. width: 100rpx;
  136. height: 100rpx;
  137. border-radius: 50rpx;
  138. display: flex;
  139. align-items: center;
  140. justify-content: center;
  141. /* background-color: #5094f2; */
  142. box-shadow: 0 0 20px 0px rgba(0, 0, 0, 0.1);
  143. transition: transform 0.4s;
  144. transform: translateX(0) rotate(0deg);
  145. color: #FFFFFF;
  146. }
  147. .moreIcon {
  148. position: absolute;
  149. line-height: 100rpx;
  150. left: 8rpx;
  151. top: 0;
  152. font-size: 40rpx;
  153. }
  154. .addIcon {
  155. font-size: 66rpx;
  156. }
  157. </style>