new_file.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view>
  3. <view class="move-path" @touchend="handleOnTouchEnd" @touchstart="start">
  4. <view class="move-content">
  5. <view v-if="vertify" class="success">{{this.tipWords}}</view>
  6. <view v-else>拖动滑块验证</view>
  7. </view>
  8. <movable-area :animation="true">
  9. <movable-view class="move-view" :x="x" direction="horizontal" @change="handleOnMoving" :disabled="vertify"
  10. :class="{'active':vertify}"></movable-view>
  11. </movable-area>
  12. </view>
  13. <!-- <transition name="tips">
  14. <text class="verify-tips" v-if="tipWords" :class="vertify ? 'suc-bg':'err-bg'">{{tipWords}}</text>
  15. </transition> -->
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'move-vertify',
  21. data() {
  22. return {
  23. x: 0,
  24. oldx: 0,
  25. vertify: false,
  26. size: {},
  27. isMove: false,
  28. tipWords: '', // 提示语
  29. startMoveTime: "", //移动开始的时间
  30. endMovetime: '', //移动结束的时间
  31. };
  32. },
  33. mounted() {
  34. this.init()
  35. },
  36. methods: {
  37. //鼠标按下
  38. start: function(e) {
  39. this.startMoveTime = new Date().getTime();
  40. },//开始滑动的时间
  41. //鼠标松开
  42. end: function() {
  43. this.endMovetime = new Date().getTime();
  44. },
  45. init() {
  46. this.getSize(".move-path").then((pathway) => {
  47. this.size.pathway = pathway;
  48. this.getSize(".move-view").then((track) => {
  49. this.size.track = track;
  50. });
  51. })
  52. },
  53. /**
  54. * 获取元素宽度
  55. */
  56. getSize(selector) {
  57. return new Promise((resolve, reject) => {
  58. const view = uni.createSelectorQuery().in(this).select(selector);
  59. view.fields({
  60. size: true,
  61. }, (res) => {
  62. resolve(res.width);
  63. }).exec();
  64. });
  65. },
  66. /**
  67. * 滑动过程
  68. */
  69. handleOnMoving(e) {
  70. this.oldx = e.detail.x;
  71. },
  72. /**
  73. * 滑动结束
  74. */
  75. handleOnTouchEnd() {
  76. this.endMovetime = new Date().getTime();
  77. if (this.vertify || this.oldx < 1) return;
  78. this.x = this.oldx;
  79. if ((this.oldx + 2) > (this.size.pathway - this.size.track)) this.vertify = true;
  80. else {
  81. this.$nextTick(() => {
  82. this.x = 0;
  83. this.oldx = 0;
  84. });
  85. }
  86. setTimeout(() => {
  87. this.$emit("vertify", this.vertify);
  88. }, 1000)
  89. },
  90. }
  91. }
  92. </script>
  93. <style scoped lang="scss">
  94. .verify-tips {
  95. position: absolute;
  96. left: 0px;
  97. bottom: 0px;
  98. width: 100%;
  99. height: 30px;
  100. background-color: rgba(231, 27, 27, .5);
  101. line-height: 30px;
  102. color: #fff;
  103. }
  104. .move-path {
  105. margin: 20rpx auto;
  106. color: #333;
  107. height: 80rpx;
  108. border-radius: 80rpx;
  109. background: linear-gradient(to right, #FEEF3C, #F3CD34);
  110. position: relative;
  111. overflow: hidden;
  112. .move-content {
  113. position: absolute;
  114. top: 0;
  115. left: 0;
  116. width: 100%;
  117. line-height: 80rpx;
  118. text-align: center;
  119. color: #666;
  120. font-size: 32rpx;
  121. z-index: 3;
  122. .success {
  123. color: #fff;
  124. }
  125. }
  126. movable-area {
  127. position: absolute;
  128. top: 0;
  129. left: 0;
  130. height: 100%;
  131. width: 100%;
  132. background: none;
  133. z-index: 5;
  134. }
  135. movable-view {
  136. width: 120rpx;
  137. height: 80rpx;
  138. box-sizing: border-box;
  139. border-radius: 80rpx;
  140. background-color: #fff;
  141. border: #FEEF3C solid 1px;
  142. background-position: center;
  143. background-repeat: no-repeat;
  144. background-size: auto 32rpx;
  145. background-image: url('./arrow.png');
  146. }
  147. movable-view.active {
  148. background-size: 30% 30%;
  149. background-image: url('./success.png');
  150. }
  151. }
  152. </style>