import { initData } from "@/common/methods";
import { getThirdMenuData } from '@/common/setup/table/button';
import { getToken } from "@/services/bus/token";
import { serviceURL } from "@/services/request";
import { ref } from "vue";
import { IfameRouteParam } from "./interface";



export function handleIfameRouter({ code, btnCodeList, tabIndex }: IfameRouteParam) {
    const token = getToken();
    const url = ref<string>('');
    // 获取当前tab页数据
    const list = getThirdMenuData();
    initData(() => {
        let resourcePCMenu = 'resourcepcmenu=';
        // const children = list[0].children;
        // console.log('获取当前tab页数据', children)
        const tabData = list.find((e) => e.code === code);
        if (tabData) {
            const fn = (code: string) => tabData.children.find((e) => e.code === code);
            //  权限按钮
            btnCodeList.forEach(el => {
                const { btnCode, urlCode } = el
                if (btnCode === 'info') {
                    resourcePCMenu += `:${urlCode}`;
                } else if (fn(btnCode)) {
                    resourcePCMenu += `:${urlCode}`;
                }
            });
        }
        url.value = `${serviceURL.pcMangerUrl}${list[0].url}?token=${token}&tabindex=${tabIndex}&${resourcePCMenu}`;
    });
    return { url };
}