<template>
  <div :class="needClass?'ab-m-t-16':''">
    <iframe :src="externalUrl" class="iframe-container"></iframe>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router';
import { useRoutesStore } from "@/framework/store/modules/routes";
import { useSettingsStore } from "@/framework/store/modules/settings";
import { removeSlashes } from "@/framework/utils/standard/dataHandleUtil";
import { getToken} from "@/framework/store/modules/user";

const routesStore = useRoutesStore();
const settingsStore = useSettingsStore();

const external=ref(false)
const externalUrl=ref('')
const needClass=ref(false)
const skipHandle = (o: any) => {
  external.value=o.meta.external
  if(o.meta.externalOldERP){
    needClass.value=true
    externalUrl.value="/"+removeSlashes(o.meta.externalOldERPIndex)+'/vindex.html?mUrl='
      +"/"+removeSlashes(o.meta.externalOldERPIndex)+"/"+removeSlashes(o.meta.externalUrl)
  }else{
    externalUrl.value=o.meta.externalUrl
    /**获取token */
    if(settingsStore.extModuleSendToken){
        let cToken=getToken()
        if (null!=cToken) {
          externalUrl.value=externalUrl.value+'?t='+cToken.access_token
        }
    }
  }
}

let router = useRouter()
watch(
  () => router,
  (newValue) => {
    const fullPath = newValue.currentRoute.value.fullPath
    const menuPath = newValue.currentRoute.value.matched[0].path
    const activeRoute = routesStore.routes.find((item: any) => item.path === menuPath)
    if (activeRoute) {
      activeRoute.children.forEach((o: any) => {
        if (fullPath == ( menuPath + '/' + o.path)) {
          skipHandle(o)
        }
      });
    }
  },
  { immediate: true, deep: true }
);
</script>


<style lang="scss" scoped>
.iframe-container {
  width: 100%;
  height: calc(100vh - 88px);
}

</style>