graceSlideToUnlock.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <view class="graceSlideToUnlock" :style="{backgroundColor:bgColor, width:width+'rpx'}">
  3. <view :style="{width:(width - padding* 2) +'rpx', padding:padding+'rpx'}">
  4. <movable-area :style="{backgroundColor:bgColor, width:(width - padding* 2) +'rpx', height:size+'rpx', borderRadius:borderRadius}">
  5. <movable-view class="graceSlideToUnlock-block" direction="horizontal" @change="change" :x="moveX" :disabled="disabled"
  6. :style="{backgroundColor:disabled ? blockActiveColor : blockColor, borderRadius:borderRadius, width:size+'rpx', height:size+'rpx', lineHeight:size+'rpx', color:iconColor, fontSize:iconSize}">
  7. <text class="grace-icons icon-pwd" v-if="!disabled"></text>
  8. <text class="grace-icons icon-right" v-if="disabled"></text>
  9. </movable-view>
  10. <text class="graceSlideToUnlock-text" :style="{width:(width - padding* 2) +'rpx', lineHeight:size+'rpx', color:disabled?blockActiveColor:'#898989'}">{{disabled?msgUnlock:msg}}</text>
  11. </movable-area>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. /*
  17. GraceUI 滑动解锁组件添加于 2020-02-27
  18. 近期发现个别 UI 抄袭 GraceUI,警告:GraceUI 已经申请软著,抄袭也是一种侵权! 我们将举起法律武器维护我们的版权!后果自负 !
  19. */
  20. export default{
  21. props:{
  22. width:{type : Number, default:700},
  23. padding:{type : Number, default:6},
  24. size : {type : Number, default:60},
  25. bgColor : {type : String, default:'#F6F7F8'},
  26. blockColor : {type : String, default:'#3688FF'},
  27. blockActiveColor :{type : String, default:'#1ab16c'},
  28. iconSize : {type : String, default:'30rpx'},
  29. iconColor : {type : String, default:'#FFFFFF'},
  30. borderRadius:{type : String, default:'6rpx'},
  31. msg:{type : String, default:'请向右滑动滑块解锁'},
  32. msgUnlock:{type : String, default:'解锁成功'}
  33. },
  34. data() {
  35. return {
  36. maxWidth:300,
  37. moveX : 0,
  38. disabled:false
  39. }
  40. },
  41. created:function(){
  42. this.maxWidth = uni.upx2px(this.width - this.padding*2 - this.size - 2);
  43. },
  44. methods:{
  45. change:function(e){
  46. if(this.disabled){return ;}
  47. if(e.detail.x >= this.maxWidth){
  48. this.moveX = this.width;
  49. this.disabled = true;
  50. this.$emit('unlock');
  51. }
  52. }
  53. }
  54. }
  55. </script>
  56. <style>
  57. .graceSlideToUnlock{}
  58. .graceSlideToUnlock-block{text-align:center;}
  59. .graceSlideToUnlock-text{text-align:center; color:#898989; font-size:24rpx; display:block;}
  60. </style>