scan.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. try {
  38. const res = await WeComLogin(query);
  39. if (res) {
  40. emitter.emit('scan-wecomLogin', { loginInfo: res });
  41. }
  42. } catch (error) {
  43. console.log('error:', error);
  44. }
  45. }
  46. onMounted(() => {
  47. if (props.isScan) {
  48. initWeComQRCode();
  49. }
  50. });
  51. </script>
  52. <template>
  53. <div class="login-scan-container">
  54. <div id="wx_qrcode"></div>
  55. <!--<div class="font12 mt20 login-msg">{{ $t('message.scan.text') }}</div>-->
  56. </div>
  57. </template>
  58. <style lang="scss" scoped>
  59. .login-scan-animation {
  60. opacity: 0;
  61. animation-name: error-num;
  62. animation-duration: 0.5s;
  63. animation-fill-mode: forwards;
  64. }
  65. .login-scan-container {
  66. //padding: 20px;
  67. display: flex;
  68. align-items: center;
  69. flex-direction: column;
  70. text-align: center;
  71. @extend .login-scan-animation;
  72. animation-delay: 0.1s;
  73. :deep(img) {
  74. margin: auto;
  75. }
  76. .login-msg {
  77. color: var(--el-text-color-placeholder);
  78. @extend .login-scan-animation;
  79. animation-delay: 0.2s;
  80. }
  81. }
  82. :deep(#wx_qrcode iframe) {
  83. height: 365px;
  84. }
  85. </style>