Captcha.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div :class="`dx-container${dxStatus ? '' : ' hide'}`">
  3. <div id="dxCaptcha"/>
  4. </div>
  5. </template>
  6. <script>
  7. import { loadSrc } from '~/common/utils.js'
  8. export default {
  9. data() {
  10. return {
  11. dxStatus: false
  12. }
  13. },
  14. computed: {
  15. locale() {
  16. return this.$store.state.locale
  17. }
  18. },
  19. mounted() {
  20. loadSrc(
  21. /*! captcha.js v1.3.37(275) 2019-06-04 10:16:27 */
  22. 'https://cdn.dingxiang-inc.com/ctu-group/captcha-ui/index.js',
  23. 'dxLib',
  24. 'js'
  25. ).then(() => {
  26. this.initDx()
  27. })
  28. },
  29. methods: {
  30. initDx() {
  31. if (!window._dx) return
  32. _dx.hooliCaptcha = _dx.Captcha(document.getElementById('dxCaptcha'), {
  33. appId: '7e86af4ecb92962ec87a38e6616145b6', //appId,在控制台中“应用管理”或“应用配置”模块获取
  34. type: 'basic',
  35. style: 'popup', // 弹出式
  36. language: this.locale || 'cn',
  37. success: token => {
  38. // console.log('dxToken:', token)
  39. // sessionStorage.setItem('hooliDx', { status: 1, token })
  40. _dx.hooliCaptcha.hide()
  41. },
  42. fail: error => {
  43. // console.log('error:', error)
  44. // _dx.hooliCaptcha.reload() // 失败后更换图片
  45. }
  46. })
  47. _dx.hooliCaptcha.on('show', () => {
  48. this.dxStatus = true
  49. })
  50. _dx.hooliCaptcha.on('hide', () => {
  51. this.dxStatus = false
  52. })
  53. // 显示失败
  54. _dx.hooliCaptcha.on('loadFail', () => {
  55. // sessionStorage.setItem('hooliDx', { status: 0, error: 'loadFail' })
  56. })
  57. }
  58. }
  59. }
  60. </script>
  61. <style lang="less">
  62. .dx-container {
  63. position: fixed;
  64. top: 0;
  65. right: 0;
  66. bottom: 0;
  67. left: 0;
  68. z-index: 10;
  69. background: rgba(0, 0, 0, 0.5);
  70. &.hide {
  71. display: none !important;
  72. }
  73. }
  74. .dx_captcha_loading_overlay {
  75. display: none !important;
  76. }
  77. </style>