<script setup lang="ts">
import * as ww from '@wecom/jssdk';
import { WeComLogin } from './api';

// const txt = defineModel()

function createWXQRCode() {
  ww.createWWLoginPanel({
    el: '#wx_qrcode',
    params: {
      login_type: 'CorpApp',
      appid: 'ww467ec1685e8262e6',
      agentid: '1000065',
      redirect_uri: 'http://amzads.zositechc.cn/web/',
      state: 'Wechat',
      scope: 'snsapi_privateinfo',
      redirect_type: 'callback',
    },
    onCheckWeComLogin({ isWeComLogin }) {
      console.log(isWeComLogin);
    },
    onLoginSuccess({ code }) {
      // console.log({ code })
      handleWeComLogin({ code: code, state: 'Wechat' });
    },
    onLoginFail(err) {
      console.log(err);
    },
  });
}

async function handleWeComLogin(query) {
  try {
    const res = await WeComLogin(query);
    console.log('res', res);
  } catch (error) {
    console.log('error:', error);
  }
}
</script>

<template>
  <div>
    <el-button type="primary" @click="createWXQRCode" class="m-2.5">发送</el-button>
  </div>
  <div id="wx_qrcode" style="height: 300px; width: 300px"></div>
</template>

<style scoped></style>
