zj-dialog-verification.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <u-popup
  3. mode="center"
  4. :round="10"
  5. :closeable="true"
  6. :show="isShow"
  7. @close="closeDialog">
  8. <view class="code-dialog">
  9. <view class="title">请完成安全验证</view>
  10. <view class="pt">
  11. <view class="pt-verification-box">
  12. <view class="pt-verification-images">
  13. <view class="iconfont refresh" @click="refresh">&#xe64c;</view>
  14. <image mode="widthFix" :src="'data:image/jpeg;base64,'+bgImg" class="bg-img"></image>
  15. <image :src="'data:image/jpeg;base64,'+maskImg" class="drag-img" mode="widthFix" :style="{ left: dragWidth + 'px', top: top + 'px'}"></image>
  16. <view class="mask"></view>
  17. </view>
  18. <view class="pt-dragbar">
  19. <view :class="['pt-drag-area',{fail: isFail,success: isSuccess}]" :style="{ width: dragWidth + 'px'}" v-if="dragWidth"></view>
  20. <movable-area class="pt-dragbar-area">
  21. <movable-view
  22. :class="['pt-dragbar-view',{active: dragWidth > 2,fail: isFail,success: isSuccess}]"
  23. :direction="direction"
  24. @change="dragStart"
  25. @touchend="dragEnd"
  26. :damping="200"
  27. :x="x"
  28. :animation="false"
  29. :disabled="disabled"
  30. :data-dragWidth="dragWidth">
  31. <text class="iconfont">
  32. <block v-if="isSuccess">&#xe687;</block>
  33. <block v-else-if="isFail">&#xe65c;</block>
  34. <block v-else>&#xe62a;</block>
  35. </text>
  36. </movable-view>
  37. <text v-if="dragWidth==0" class="tips">{{tips}}</text>
  38. </movable-area>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </u-popup>
  44. </template>
  45. <script>
  46. export default {
  47. props: {
  48. isShow: {
  49. type: Boolean,
  50. default: false
  51. },
  52. // 背景大图
  53. bgImg: {
  54. type: [String,Number],
  55. default: ''
  56. },
  57. // 块状小图
  58. maskImg: {
  59. type: [String,Number],
  60. default: ''
  61. },
  62. // 坑位的top值
  63. top: {
  64. type: [String,Number],
  65. default: 0
  66. },
  67. // 滑块滑动的方向
  68. direction: {
  69. type: [String,Number],
  70. default: 'horizontal'
  71. },
  72. // 判断是否成功
  73. isSuccess: {
  74. type: Boolean,
  75. default: false,
  76. },
  77. // 判断是否失败
  78. isFail: {
  79. type: Boolean,
  80. default: false,
  81. }
  82. },
  83. data() {
  84. return {
  85. tips: '向右拖动滑块填充拼图',
  86. disabled: false,
  87. dragWidth: 0,
  88. x: 0
  89. };
  90. },
  91. methods: {
  92. closeDialog() {
  93. this.$emit('close');
  94. },
  95. // 开始滑动
  96. dragStart(e){
  97. this.dragWidth = e.detail.x
  98. },
  99. // 停止滑动
  100. dragEnd(e){
  101. this.x = this.dragWidth;
  102. this.$emit('finish', this.dragWidth);
  103. },
  104. refresh(){
  105. console.log(1);
  106. this.dragWidth = 0;
  107. this.isFail = false;
  108. this.isSuccess = false;
  109. this.x = 0;
  110. this.disabled = false;
  111. this.$emit('refresh');
  112. }
  113. }
  114. }
  115. </script>
  116. <style lang="scss">
  117. @font-face {
  118. font-family: 'iconfont'; /* project id 2047533 */
  119. src: url('https://at.alicdn.com/t/font_2047533_o8axbabfs3.ttf') format('truetype')
  120. }
  121. .iconfont {
  122. font-family: iconfont !important;
  123. font-size: 16px;
  124. font-style: normal;
  125. -webkit-font-smoothing: antialiased;
  126. -moz-osx-font-smoothing: grayscale;
  127. }
  128. .code-dialog {
  129. padding: 20px;
  130. border-radius: 10rpx;
  131. display: flex;
  132. flex-direction: column;
  133. align-items: center;
  134. .title {
  135. font-size: 28rpx;
  136. color: #333333;
  137. width: 100%;
  138. text-align: left;
  139. margin-bottom: 10px;
  140. }
  141. }
  142. .pt{
  143. width: 300px;
  144. margin: 0 auto;
  145. &-verification-images{
  146. position: relative;
  147. .refresh{
  148. position: absolute;
  149. right: 20rpx;
  150. top: 20rpx;
  151. z-index: 10;
  152. color: #FFF;
  153. font-weight: bold;
  154. }
  155. .bg-img{
  156. width: 100%;
  157. vertical-align: top;
  158. }
  159. .drag-img{
  160. position: absolute;
  161. width: 112rpx;
  162. height: 91rpx;
  163. top: 0;
  164. left: 0;
  165. z-index: 1;
  166. }
  167. .mask {
  168. position: absolute;
  169. top: 0;
  170. left: 0;
  171. width: 100%;
  172. height: 100%;
  173. background: rgba($color: #000000, $alpha: .2);
  174. }
  175. }
  176. &-dragbar{
  177. position: relative;
  178. height: 80rpx;
  179. background-color: #F7F7F7;
  180. border: solid 2rpx #EEE;
  181. margin-top: 20rpx;
  182. .pt-drag-area{
  183. position: absolute;
  184. height: 80rpx;
  185. border: solid 2rpx $uni-color-primary;
  186. background-color: #D1E9F1;
  187. top: -2rpx;
  188. &.fail{
  189. border-color: $uni-color-error;
  190. background-color: #ffdbdb;
  191. }
  192. &.success{
  193. border-color: $uni-color-success;
  194. background-color: #d7ffe1;
  195. }
  196. }
  197. &-area{
  198. position: absolute;
  199. width: 100%;
  200. height: 100%;
  201. left: 0;
  202. top: 0;
  203. .tips{
  204. font-size: 24rpx;
  205. color: #999;
  206. position: absolute;
  207. left: 50%;
  208. top: 50%;
  209. transform: translate(-50%,-50%);
  210. }
  211. }
  212. &-view{
  213. width: 80rpx;
  214. height: 80rpx;
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. border: solid 2rpx #EEE;
  219. background-color: #FFF;
  220. top: -2rpx;
  221. left: 0;
  222. &.active{
  223. background-color: $uni-color-primary;
  224. border-color: $uni-color-primary;
  225. color: #FFF;
  226. }
  227. &.fail{
  228. background-color: $uni-color-error;
  229. border-color: $uni-color-error;
  230. }
  231. &.success{
  232. border-color: $uni-color-success;
  233. background-color: #00a029;
  234. }
  235. }
  236. }
  237. }
  238. </style>