scan.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <script lang="ts" setup>
  2. import { onMounted } from 'vue'
  3. import * as ww from '@wecom/jssdk'
  4. import { WeComLogin } from '../api'
  5. import emitter from '/@/utils/emitter'
  6. const props = defineProps({
  7. isScan: {
  8. type: Boolean,
  9. default: false,
  10. },
  11. })
  12. // 初始化企业微信扫码登录
  13. function initWeComQRCode() {
  14. ww.createWWLoginPanel({
  15. el: '#wx_qrcode',
  16. params: {
  17. login_type: 'CorpApp',
  18. appid: 'ww467ec1685e8262e6',
  19. agentid: '1000065',
  20. redirect_uri: 'http://amzads.zositechc.cn/web/',
  21. state: 'Wechat',
  22. scope: 'snsapi_privateinfo',
  23. redirect_type: 'callback',
  24. },
  25. onCheckWeComLogin({ isWeComLogin }) {
  26. // console.log(isWeComLogin)
  27. },
  28. onLoginSuccess({ code }) {
  29. handleWeComLogin({ code: code, state: 'Wechat' })
  30. },
  31. onLoginFail(err) {
  32. // console.log(err)
  33. },
  34. })
  35. }
  36. async function handleWeComLogin(query) {
  37. console.log('扫码成功')
  38. try {
  39. const res = await WeComLogin(query)
  40. if (res) {
  41. emitter.emit('scan-wecomLogin', { loginInfo: res })
  42. console.log('发送跳转')
  43. }
  44. } catch (error) {
  45. console.log('error:', error)
  46. }
  47. }
  48. onMounted(() => {
  49. if (props.isScan) {
  50. initWeComQRCode()
  51. }
  52. })
  53. </script>
  54. <template>
  55. <div class="login-scan-container">
  56. <div id="wx_qrcode"></div>
  57. <!--<div class="font12 mt20 login-msg">{{ $t('message.scan.text') }}</div>-->
  58. </div>
  59. </template>
  60. <style scoped lang="scss">
  61. .login-scan-animation {
  62. opacity: 0;
  63. animation-name: error-num;
  64. animation-duration: 0.5s;
  65. animation-fill-mode: forwards;
  66. }
  67. .login-scan-container {
  68. //padding: 20px;
  69. display: flex;
  70. align-items: center;
  71. flex-direction: column;
  72. text-align: center;
  73. @extend .login-scan-animation;
  74. animation-delay: 0.1s;
  75. :deep(img) {
  76. margin: auto;
  77. }
  78. .login-msg {
  79. color: var(--el-text-color-placeholder);
  80. @extend .login-scan-animation;
  81. animation-delay: 0.2s;
  82. }
  83. }
  84. :deep(#wx_qrcode iframe) {
  85. height: 365px;
  86. }
  87. </style>