tm-verificationImg.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="tm-verificationImg flex-center flex-col">
  3. <view class="flex-shrink rounded overflow relative"
  4. :style="{
  5. width:`${size}rpx`,
  6. height:`${size}rpx`,
  7. }"
  8. >
  9. <view v-if="success" class="tm-verificationImg-success fulled fulled-height rounded absolute flex-center opacity-8" >
  10. <tm-icons name="icon-check" color="white" :size="100"></tm-icons>
  11. </view>
  12. <view :style="{transform: `rotate(${default_value_num}deg)`}">
  13. <tm-images model="aspectFit" :width="size" :height="size" round="rounded" :src="src"></tm-images>
  14. </view>
  15. </view>
  16. <view :style="{width:`${size}rpx`}" class="py-32">
  17. <tm-slider :disabled="disabled" :fllowTheme="fllowTheme" :color="color_tmeme" v-model="default_value_num" :max="360"></tm-slider>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. //https://jx2d.cn/yuwuimages/test.png
  23. //测试图片角度为正120
  24. /**
  25. * 图片安全验证
  26. * @property {String} model = [normal|rotate] 默认:normal,rotate表示图片本身有角度的模式。normal是随机一张正常的图片(图片本身是没有角度的)
  27. * @property {Number} rotate = [] 默认:0,当前model=normal时,应承打乱图片 的角度。当model=rotate,是特指图片本身的角度。
  28. * @property {Number} size = [] 默认:200,大小。
  29. * @property {String} color = [] 默认:primary,主题色。
  30. * @property {String} src = [] 默认:''随机一张图片,图片地址。
  31. * @property {Boolean} disabled = [] 默认:false,是否禁用
  32. * @property {Function} change 旋转的时候触发,返回参数为当前的检验,正确是为true,失败为false
  33. */
  34. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  35. import tmImages from "@/tm-vuetify/components/tm-images/tm-images.vue"
  36. import tmSlider from "@/tm-vuetify/components/tm-slider/tm-slider.vue"
  37. export default {
  38. components:{tmSlider,tmIcons,tmImages},
  39. name:"tm-verificationImg",
  40. props:{
  41. //rotate表示图片本身有角度的模式。normal是随机一张正常的图片(图片本身是没有角度的)
  42. model:{
  43. type:String,
  44. default:'normal' ,//normal|rotate ,
  45. },
  46. //当前model=normal时,应承打乱图片 的角度。当model=rotate,是特指图片本身的角度。
  47. rotate:{
  48. type:Number,
  49. default:0
  50. },
  51. size:{
  52. type:Number|String,
  53. default:200
  54. },
  55. color:{
  56. type:String,
  57. default:'primary'
  58. },
  59. src:{
  60. type:String,
  61. default:'https://picsum.photos/300'
  62. },
  63. // 跟随主题色的改变而改变。
  64. fllowTheme:{
  65. type:Boolean|String,
  66. default:true
  67. },
  68. disabled:Boolean
  69. },
  70. data() {
  71. return {
  72. default_value_num:0,
  73. imgrotate:0,
  74. wucha:5,
  75. success:false
  76. };
  77. },
  78. computed:{
  79. color_tmeme:function(){
  80. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  81. return this.$tm.vx.state().tmVuetify.color;
  82. }
  83. return this.color;
  84. },
  85. },
  86. mounted() {
  87. if(this.model=='normal'){
  88. this.default_value_num = this.rotate
  89. this.imgrotate = 0
  90. }else{
  91. this.default_value_num = 0
  92. this.imgrotate = this.rotate
  93. }
  94. },
  95. watch:{
  96. default_value_num:function(val){
  97. let zque = Math.abs(360-this.imgrotate);
  98. if(this.model=='normal'){
  99. if(val>=360){
  100. this.success=true
  101. }else{
  102. this.success=false
  103. }
  104. }else{
  105. if(val>=zque-5 && val <=zque+5){
  106. this.success=true
  107. }else{
  108. this.success=false
  109. }
  110. }
  111. this.$emit('change',this.success)
  112. }
  113. },
  114. methods: {
  115. name() {
  116. }
  117. },
  118. }
  119. </script>
  120. <style lang="scss">
  121. .tm-verificationImg{
  122. .tm-verificationImg-success{
  123. top: 0;
  124. left: 0;
  125. z-index: 9;
  126. background-color: rgba(0,0,0,0.2);
  127. backdrop-filter: blur(2px);
  128. -webkit-backdrop-filter: blur(2px);
  129. }
  130. }
  131. </style>