suspen_button.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="suspen-button">
  3. <view
  4. class="px-suspen-button"
  5. :style="{ top: mobileTop, left: mobileLeft }"
  6. @touchmove.stop.prevent="onTouchMove"
  7. @touchend.stop.prevent="ontouchend"
  8. >
  9. <view :class="['center-button', 'px-button', { active: open }]" @click.stop="onOpen">
  10. <slot name="center"> </slot>
  11. </view>
  12. <view :class="['top-button', 'px-button', 'ot-button', open && 'active-top', !first && !open && 'hidden-top']">
  13. <slot name="top"> </slot>
  14. </view>
  15. <view :class="['left-button', 'px-button', 'ot-button', open && 'active-left', !first && !open && 'hidden-left']">
  16. <slot name="bottom"> </slot>
  17. </view>
  18. <view :class="['bottom-button', 'px-button', 'ot-button', open && 'active-bottom', !first && !open && 'hidden-bottom']">
  19. <slot name="left"> </slot>
  20. </view>
  21. <view class="px-suspen-close" @click="closeButtonHandler">
  22. <image class="px-suspen-close-img" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/close-icon.png"></image>
  23. </view>
  24. </view>
  25. <view :class="[open ? 'mask-show' : '']" @click.stop="onOpen"> </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. props: {
  31. show: {},
  32. type: {
  33. type: String,
  34. default: "",
  35. },
  36. showSingInImg: {},
  37. },
  38. data() {
  39. return {
  40. first: true, //样式的一个切换
  41. open: false,
  42. mobileTop: "",
  43. mobileLeft: "",
  44. windowHeight: "",
  45. windowWidth: "",
  46. isLeft: "",
  47. };
  48. },
  49. mounted() {
  50. uni.getSystemInfo({
  51. success: (res) => {
  52. let width = res.windowWidth;
  53. let rate = 750.0 / width;
  54. this.windowHeight = res.windowHeight;
  55. this.windowWidth = width;
  56. },
  57. });
  58. },
  59. methods: {
  60. onOpen() {
  61. this.open = !this.open;
  62. this.first = false;
  63. },
  64. onTouchMove(e) {
  65. let x = e.touches[0].clientX;
  66. let y = e.touches[0].clientY;
  67. if (x < 0) {
  68. x = 0;
  69. } else if (x > this.windowWidth - this.size / this.rate) {
  70. x = this.windowWidth - this.size / this.rate;
  71. }
  72. this.isLeft = x;
  73. this.mobileLeft = x + "px";
  74. this.mobileTop = y + "px";
  75. },
  76. ontouchend() {
  77. if (!this.isLeft) return;
  78. this.mobileLeft = this.windowWidth - 85 + "px";
  79. this.isLeft = "";
  80. },
  81. // 点击了取消的按钮
  82. closeButtonHandler() {
  83. this.$emit("update:show", false);
  84. this.$emit("update:showSingInImg", false);
  85. },
  86. },
  87. };
  88. </script>
  89. <style lang="scss" scoped>
  90. .suspen-button {
  91. width: 100%;
  92. height: 100%;
  93. }
  94. .mask-show {
  95. position: fixed;
  96. top: 0;
  97. left: 0;
  98. right: 0;
  99. bottom: 0;
  100. transition: transform 0.3s;
  101. background-color: rgba(0, 0, 0, 0.6);
  102. z-index: 90;
  103. transition: all 0.3s ease-in-out 0s;
  104. transform: scale(1, 1);
  105. }
  106. .px-suspen-button {
  107. position: fixed;
  108. z-index: 99;
  109. bottom: 320rpx;
  110. right: 180rpx;
  111. }
  112. .px-suspen-close {
  113. position: absolute;
  114. display: flex;
  115. align-items: center;
  116. justify-content: center;
  117. width: 50rpx;
  118. height: 60rpx;
  119. z-index: 99;
  120. top: -38rpx;
  121. left: 108rpx;
  122. .px-suspen-close-img {
  123. width: 35rpx;
  124. height: 35rpx;
  125. }
  126. }
  127. .px-button {
  128. position: absolute;
  129. border-radius: 50%;
  130. top: 0rpx;
  131. left: 0rpx;
  132. height: 120rpx;
  133. width: 120rpx;
  134. display: flex;
  135. flex-direction: column;
  136. justify-content: center;
  137. align-items: center;
  138. z-index: 999;
  139. overflow: hidden;
  140. image {
  141. width: 100%;
  142. height: 100%;
  143. }
  144. &.center-button {
  145. z-index: 1000;
  146. }
  147. &.ot-button {
  148. display: none;
  149. opacity: 0;
  150. &.active-top {
  151. animation: 0.5s ease top forwards;
  152. display: flex;
  153. }
  154. &.hidden-top {
  155. animation: 0.5s ease hidetop forwards;
  156. display: flex;
  157. }
  158. &.active-left {
  159. animation: 0.5s ease left forwards;
  160. display: flex;
  161. }
  162. &.hidden-left {
  163. animation: 0.5s ease hideleft forwards;
  164. display: flex;
  165. }
  166. &.active-bottom {
  167. animation: 0.5s ease bottom forwards;
  168. display: flex;
  169. }
  170. &.hidden-bottom {
  171. animation: 0.5s ease hidebottom forwards;
  172. display: flex;
  173. }
  174. }
  175. }
  176. @keyframes center {
  177. //中间的按钮
  178. 0% {
  179. }
  180. 100% {
  181. transform: rotate(315deg);
  182. opacity: 1;
  183. }
  184. }
  185. @keyframes bottom {
  186. //底部的按钮
  187. 0% {
  188. opacity: 0;
  189. }
  190. 100% {
  191. top: 80rpx;
  192. left: -126rpx;
  193. transform: rotate(360deg);
  194. opacity: 1;
  195. }
  196. }
  197. @keyframes left {
  198. 0% {
  199. opacity: 0;
  200. }
  201. 100% {
  202. top: 0rpx;
  203. left: -180rpx;
  204. transform: rotate(360deg);
  205. opacity: 1;
  206. }
  207. }
  208. @keyframes top {
  209. //头部的按钮
  210. 0% {
  211. opacity: 0;
  212. }
  213. 100% {
  214. top: -90rpx;
  215. left: -126rpx;
  216. transform: rotate(360deg);
  217. opacity: 1;
  218. }
  219. }
  220. @keyframes hideleft {
  221. 0% {
  222. top: 0rpx;
  223. left: -180rpx;
  224. opacity: 1;
  225. }
  226. 100% {
  227. top: 0rpx;
  228. left: 0rpx;
  229. transform: rotate(360deg);
  230. opacity: 0;
  231. }
  232. }
  233. @keyframes hidebottom {
  234. 0% {
  235. top: 100rpx;
  236. left: -120rpx;
  237. opacity: 1;
  238. }
  239. 100% {
  240. top: 0rpx;
  241. left: 0rpx;
  242. transform: rotate(360deg);
  243. opacity: 0;
  244. }
  245. }
  246. @keyframes hidetop {
  247. 0% {
  248. top: -100rpx;
  249. left: -120rpx;
  250. opacity: 1;
  251. }
  252. 100% {
  253. top: 0rpx;
  254. left: 0rpx;
  255. transform: rotate(360deg);
  256. opacity: 0;
  257. }
  258. }
  259. </style>