gui-slide-to-unlock.vue 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view class="graceSlideToUnlock gui-border-box"
  3. :style="{
  4. backgroundColor:bgColor, width:width+'rpx',
  5. padding:padding+'rpx', height:(size+padding*2)+'rpx'
  6. }">
  7. <text class="graceSlideToUnlock-text gui-block-text gui-icons"
  8. :class="[moving?'gui-fade':'']"
  9. :style="{
  10. width:(width - padding* 2) +'rpx',
  11. lineHeight:size+'rpx',
  12. color:disabled?blockActiveColor:'#898989',
  13. top : padding+'rpx'}">{{disabled?msgUnlock:msg}} &#xe601;&#xe601;</text>
  14. <movable-area class="movable-area"
  15. :style="{
  16. width:(width - padding* 2) +'rpx',
  17. height:size+'rpx', borderRadius:borderRadius,
  18. top : padding+'rpx'}">
  19. <movable-view direction="horizontal"
  20. @change="change" :x="moveX" :disabled="disabled"
  21. :style="{width:size+'rpx', height:size+'rpx'}">
  22. <text class="graceSlideToUnlock-block gui-icons gui-block-text gui-color-white"
  23. v-if="!disabled"
  24. :style="{
  25. backgroundColor:disabled ? blockActiveColor : blockColor,
  26. borderRadius:borderRadius, width:size+'rpx', height:size+'rpx',
  27. lineHeight:size+'rpx', color:iconColor, fontSize:iconSize}">&#xe641;</text>
  28. <text class="graceSlideToUnlock-block gui-icons gui-block-text gui-color-white"
  29. v-if="disabled" :style="{
  30. backgroundColor:disabled ? blockActiveColor : blockColor,
  31. borderRadius:borderRadius, width:size+'rpx', height:size+'rpx',
  32. lineHeight:size+'rpx', color:iconColor, fontSize:iconSize}">&#xe86a;</text>
  33. </movable-view>
  34. </movable-area>
  35. </view>
  36. </template>
  37. <script>
  38. export default{
  39. name : "gui-slide-to-unlock",
  40. props : {
  41. width : {type : Number, default:690 },
  42. padding : {type : Number, default:6},
  43. size : {type : Number, default:68},
  44. bgColor : {type : String, default:'#F6F7F8'},
  45. blockColor : {type : String, default:'#008AFF'},
  46. blockActiveColor : {type : String, default:'#39B55A'},
  47. iconSize : {type : String, default:'30rpx'},
  48. iconColor : {type : String, default:'#FFFFFF'},
  49. borderRadius : {type : String, default:'6rpx'},
  50. msg : {type : String, default:'请向右滑动滑块解锁'},
  51. msgUnlock : {type : String, default:'解锁成功'}
  52. },
  53. data() {
  54. return {
  55. maxWidth : 300,
  56. moveX : 0,
  57. disabled : false,
  58. locktimer : null,
  59. moving : false
  60. }
  61. },
  62. created:function(){
  63. this.maxWidth = uni.upx2px(this.width - this.padding * 2 - this.size - 2);
  64. this.moveX = uni.upx2px(this.padding);
  65. },
  66. methods:{
  67. change:function(e){
  68. if(this.disabled){return ;}
  69. this.moving = true;
  70. if(this.locktimer != null){clearTimeout(this.locktimer);}
  71. this.locktimer = setTimeout(() => {
  72. if(e.detail.x >= this.maxWidth){
  73. this.moveX = this.width;
  74. this.disabled = true;
  75. this.moving = false;
  76. this.$emit('unlock');
  77. }else{
  78. this.moveX = uni.upx2px(this.padding) + Math.random();
  79. this.moving = false;
  80. }
  81. }, 300);
  82. }
  83. }
  84. }
  85. </script>
  86. <style scoped>
  87. .graceSlideToUnlock{position:relative;}
  88. .movable-area{position:absolute; left:0; top:0; z-index:2;}
  89. .graceSlideToUnlock-block{text-align:center; opacity:0.88;}
  90. .graceSlideToUnlock-text{text-align:center; color:#FFFFFF; font-size:24rpx; position:absolute; left:0; top:0; z-index:1;}
  91. /* #ifndef APP-NVUE */
  92. @keyframes gui-fade{0%{opacity:1;} 50%{opacity:0;} 100%{opacity:1;}}
  93. .gui-fade{animation:gui-fade 2s ease-in infinite;}
  94. /* #endif */
  95. </style>