wm-list-add.vue 5.2 KB

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