shikeying
2023-04-07 c192f834c4e092bc7c0f2722c343c25c1be619ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<template>
  <div>
 
    <div class="td-outer-wrapper pop " style="display: block; opacity: 1;">
      <div class="td-mask-common background grey" />
      <div
        class="td-pop-cnt center slide"
        :style="'left:'+left+';top:'+top+';width: 350px; height: 315px; transform: translate(-50%, -50%) scale(1);'"
      >
        <div class="td-pop-slide-area">
          <div class="td-pop-slide-title">
            <div class="td-pop-title">请拖动下方滑块完成拼图
            </div>
          </div>
          <div class="td-pop-center">
            <transition name="el-zoom-in-top">
              <el-alert
                v-show="msg.show"
                :title="msg.text"
                :type="msg.type"
                center
                :closable="false"
                style="position: absolute;z-index: 10;border-radius: unset;"
                show-icon
              />
            </transition>
            <!--背景图-->
            <canvas class="td-bg-img" width="320" height="180" />
            <div v-show="loading" class="refresh-bg">
              <img src="./img/loading.gif" class="loading-icon">
            </div>
<!--            <div class="td-bg-slogan" style="display: block;">
              &lt;!&ndash;<div class="td-logo-transparent-icon td-sprite-icon" />&ndash;&gt;
              <span class="td-logo-transparent-iconfont">智能验证</span>
            </div>-->
            <img
              class="td-pop-slide-identity"
              src=""
              draggable="false"
              style="top: 116px; transform: translate(0px, 0px); opacity: 1;"
            >
          </div>
          <!--滑块-->
          <div class="td-slide-wrap">
            <div class="td-pop-slidebar">
              <div class="td-pop-slidebar-tip">请向右拖动滑块
              </div>
            </div>
            <div
              :class="'td-pop-slidetrigger td-sprite-icon '+mousedown"
              style="transform: translate(0px, 0px);"
              @mousedown="handleMouseDown"
            />
          </div>
          <div class="td-pop-footer">
            <div class="td-icon-set">
              <div class="td-icon-close td-sprite-icon icon" @click="hide">
                <div class="td-icon-tooltip" style="right:-8px;left:auto;">关闭
                </div>
              </div>
              <div class="td-icon-refresh td-sprite-icon icon" @click="getVerify">
                <div class="td-icon-tooltip">刷新
                </div>
              </div>
              <!--<a id="jump2feedback" style="display: block" href="http://static.tongdun.net/captcha/test/index.html?seqId=1561081035175937S365328C48488966,1561081042275149S365328C03293221,1561081058162146S365328C42730006,1561081659566994S35525D734520462,1561082259315562S35525D737834014,1561082859159316S35525D737251353,1561083458396777S365328C43056286,1561086261446326S35525D733771073&amp;partner=tongdun&amp;appName=x_tongdun2_web" target="_blank">-->
              <!--<div class="td-icon-info td-sprite-icon icon">-->
              <!--<div class="td-icon-tooltip">反馈-->
              <!--</div>-->
              <!--</div>-->
              <!--</a>-->
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
import { getVerify, checkVerify } from '@/api/system/verify'
 
export default {
  props: {
    left: {
      type: String,
      default: '70%'
    },
    top: {
      type: String,
      default: '50%'
    }
  },
  data() {
    return {
      loading: false,
      state: 0, // 0松开,1按下
      vSlideLeftpx: 0, // 滑块距离左侧的距离
      mousedown: '',
      msg: {
        show: false,
        type: '',
        text: ''
      },
      token: '',
      startTime: 0,
      endTime: 0
    }
  },
  mounted() {
    this.getVerify()
    const that = this
    document.onmousemove = this.handelMouseMove
    document.onmouseup = this.handleMouseUp
 
    document.querySelector('.td-pop-slidetrigger').addEventListener('touchstart', function(e) {
      that.handleMouseDown(e)
    })
    document.querySelector('.td-pop-slidetrigger').addEventListener('touchmove', function(e) {
      that.handelMouseMove(e)
      e.preventDefault() // 若阻止默认事件,则在长按元素上滑动时,页面是不滚动的,
    })
 
    document.querySelector('.td-pop-slidetrigger').addEventListener('touchend', function(e) {
      // 若手指离开屏幕时,时间小于我们设置的长按时间,则为点击事件,清除定时器,结束长按逻辑
      that.handleMouseUp(e)
    })
  },
  created() {
 
  },
  methods: {
    getVerify() {
      this.loading = true
      this.setLeft(0)
 
      getVerify({}).then(response => {
        // 填充画布
        const c = document.querySelector('.td-bg-img')
        const ctx = c.getContext('2d')
        const img = new Image() // 创建img元素
        img.onload = function() {
          ctx.drawImage(img, 0, 0)
        }
        img.src = response.data.bg
 
        document.querySelector('.td-pop-slide-identity').src = response.data.slider
        document.querySelector('.td-pop-slide-identity').style.top = response.data.y + 'px'
        this.token = response.data.uuid
        this.loading = false
      })
    },
    /*
         * @Author : liu.q [916000612@qq.com]
         * @Date : 2019-06-21 14:09
         * @Description :鼠标点击
         */
    handleMouseDown() {
      this.state = 1
      this.mousedown = 'mousedown'
      // 记录滑块位置
      this.vSlideLeftpx = document.querySelector('.td-pop-slidetrigger').getBoundingClientRect().left
    },
    /*
         * @Author : liu.q [916000612@qq.com]
         * @Date : 2019-06-21 14:09
         * @Description : 鼠标松开
         */
    handleMouseUp() {
      this.state = 0
      this.endTime = new Date().getTime()
      if (this.startTime == 0) {
        return
      }
      const time = this.endTime - this.startTime
 
      const x = document.querySelector('.td-pop-slidetrigger').getBoundingClientRect().left - this.vSlideLeftpx
      checkVerify({ x: x, token: this.token }).then(response => {
        if (response.data.verify != '-1') {
          this.msg.show = true
          const rate = (time / 1000).toFixed(2)
          this.msg.text = '验证通过,' + rate + '秒的速度超过' + this.getRate(rate) + '的用户'
          this.msg.type = 'success'
          setTimeout(() => {
            this.msg.show = false
            this.$emit('success', { verify: response.data.verify, x: response.data.x, uuid: response.data.uuid })
            this.$emit('hide')
          }, 1200)
        } else {
          this.msg.show = true
          this.msg.text = '验证失败,请重试。'
          this.msg.type = 'error'
          setTimeout(() => {
            this.msg.show = false
          }, 1200)
          const timer = setInterval(() => {
            const left = document.querySelector('.td-pop-slidetrigger').getBoundingClientRect().left - this.vSlideLeftpx - 2
            this.setLeft(left)
            if (document.querySelector('.td-pop-slidetrigger').getBoundingClientRect().left - this.vSlideLeftpx <= 0) {
              clearInterval(timer)
              this.setLeft(0)
            }
          }, 1)
          this.getVerify()
        }
      })
    },
    /*
         * @Author : liu.q [916000612@qq.com]
         * @Date : 2019-06-21 14:06
         * @Description : 设置滑块图片左侧偏移
         */
    setLeft(left) {
      if (left == 0) {
        this.mousedown = ''
      }
      document.querySelector('.td-pop-slidetrigger').style.left = left + 'px'
      document.querySelector('.td-pop-slide-identity').style.left = left + 'px'
    },
    /*
         * @Author : liu.q [916000612@qq.com]
         * @Date : 2019-06-21 14:09
         * @Description :鼠标移动
         */
    handelMouseMove(e) {
      if (this.state !== 1) {
        this.startTime = 0
        return
      }
      if (this.startTime == 0) {
        this.startTime = new Date().getTime()
      }
 
      let x
      if (!e.touches) { // 兼容移动端
        x = e.clientX
      } else { // 兼容PC端
        x = e.touches[0].pageX
      }
      if ((x - this.vSlideLeftpx) < 0) {
        this.setLeft(0)
      } else if ((x - this.vSlideLeftpx) > 300) {
        this.setLeft(275)
      } else {
        this.setLeft(x - this.vSlideLeftpx - 20)
      }
    },
    /*
       * @Author : liu.q [916000612@qq.com]
       * @Date : 2019-06-25 14:50
       * @Description :关闭
       */
    hide() {
      this.$emit('hide')
    },
    /*
       * @Author : liu.q [916000612@qq.com]
       * @Date : 2019-06-25 19:41
       * @Description : 超过百分之几的用户
       */
    getRate(rate) {
      if (rate < 0.8) {
        return '99.99%'
      } else if (rate < 1) {
        return '99.96%'
      } else if (rate < 1.1) {
        return '99.38%'
      } else if (rate < 1.2) {
        return '99.24%'
      } else if (rate < 1.3) {
        return '99%'
      } else if (rate < 1.4) {
        return '98.88%'
      } else if (rate < 1.5) {
        return '98%'
      } else if (rate < 1.6) {
        return '96.33%'
      } else if (rate < 1.7) {
        return '96%'
      } else if (rate < 2) {
        return '95.55%'
      } else if (rate < 2.3) {
        return '94%'
      } else if (rate < 2.6) {
        return '91%'
      } else if (rate < 3) {
        return '80%'
      } else if (rate < 4) {
        return '40%'
      } else if (rate < 5) {
        return '1%'
      } else {
        return '0.01%'
      }
    }
  }
}
</script>
 
<style src="./css/index.css"></style>
<style lang="scss">
  .td-outer-wrapper.pop{min-height: 768px;
    .td-pop-cnt.center{left:70%;}
  }
</style>