<template>
  <iframe
    class="sk-zzdlogin-iframe"
    :src="src"
  ></iframe>
</template>

<script lang="ts">

import { defineComponent } from 'vue'

export default defineComponent({
  name: 'SkZzdLogin',
  props: {
    client_id: {
      type: String,
      // default: 'tcqsmzqxt_dingoa',
      default: 'public_login_dingoa',
    },
    redirect_uri: {
      type: String,
      // default: 'https://tdcb.zgj.ningbo.gov.cn/dingservice/getCode',
      default: 'https://www.baidu.com',
    },
    zzd: {
      type: Boolean,
      default: false,
    },
  },
  setup(props, { emit }) {
    let baseUrl = 'https://login-pro.ding.zj.gov.cn'
    if (!props.zzd) {
      baseUrl = 'https://login.dg-work.cn'
    }
    let src = `${baseUrl}/oauth2/auth.htm?response_type=code&client_id=${props.client_id}&redirect_uri=${props.redirect_uri}&scope=get_user_info&authType=QRCODE&embedMode=true`
    window.addEventListener('message', function (event) {
      if (event.data.code){
        emit('success', event.data.code)
      }
    })
    return {
      src,
    }
  },
})
</script>
<style lang="scss" scoped>

</style>
