gui-slide-to-unlock.vue 3.5 KB

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