<template>
	<div>
		<iframe style="height:85vh;width:100%" id="iframeLink" name="iframeLink" ref="iframeLink"
			:src="urlLink"></iframe>
	</div>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
		getCurrentInstance
	} from 'vue'

	const {
		proxy
	} = getCurrentInstance()

	import tools from '@/tools'
	const cardBodyStyle = ref(tools.style.card)


	const props = defineProps({
		reportPath: {
			type: String,
			default: () => ''
		}

	})
	onMounted(() => {
		login()
	})



	const urlLink = ref('')
	const urlLogin = ref('')
	const fineReportUserName = ref('jlyypt')
	const fineReportPassWord = ref('jlyypt')
	const fineLinkSrc = ref('')

	import axios from 'axios'
	const login = () => {
		var url = import.meta.env.VITE_FINEREPORT_API +
			'/webroot/decision/login/cross/domain?validity=-1&fine_username=' + encodeURI(
				fineReportUserName.value) + '&fine_password=' + encodeURI(fineReportPassWord.value)
		console.log(url)
		console.log(props.reportPath)
		axios({
			method: 'get',
			changeOrigin: true,
			url,
			timeout: 5000, //超时时间（单位：毫秒）
			dataType: "jsonp", //跨域采用jsonp方式
			jsonp: "callback",
		}).then(response => { 
			if (response.errorCode) {
				ElMessage({
					type: 'error',
					message: '报表登录失败:' + response.errorMsg
				});
			} else {
				urlLink.value = import.meta.env.VITE_FINEREPORT_API +
					"/webroot/decision/view/report?viewlet=" + props.reportPath
					console.log(urlLink.value )
			}
		}).catch(error => {
			ElMessage({
				type: 'error',
				message: '报表登录请求失败！' + error
			});
		})
	}
	const refresh = () => {
		login()
	}

	defineExpose({
		refresh
	})
</script>

<style>
</style>