scan.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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', // 企业微信企业 ID
  19. agentid: '1000074', // 应用 AgentID
  20. redirect_uri: 'http://asset.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: any) {
  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 lang="scss" scoped>
  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>