import { Icon } from "element-ui"

export default {
    computed: {
        key() {

        
            
            return this.$route.path;
        },
        activePath() {
            // 从完整路径中获取最后一段
            const fullPath = this.$route.path;
            const currentPath = fullPath.split('/').pop();
            console.log('Current Path:', currentPath);
            console.log('Full Path:', fullPath);
            // 如果当前路径存在于菜单列表中，则返回该路径
            if (this.menuList.some(item => item.path === currentPath)) {
                return currentPath;
            }

            // 如果未找到匹配项，返回默认路径
            return 'personalMining';
        }
    },
    data() {
        return {
            menuList: [
                {
                    path: "personalMining",
                    label: 'personal.miningAccount',
                    icon: "iconfont icon-kuanggong1",

                },
                {   //只读页面
                    path: "readOnly",
                    label: 'personal.readOnlyPage',
                    icon: "iconfont icon-yanjing",

                },
                {   //安全设置
                    path: "securitySetting",
                    label: 'personal.securitySetting',
                    icon: "iconfont icon-anquan",

                },
                // {   //个人中心
                //     path:"/personalCenter/personal",
                //     label:'personal.personalCenter',
                //     icon:"iconfont icon-gerenzhongxin",

                // },
                // {   //挖矿报告
                //     path:"/personalCenter/miningReport",
                //     label:'personal.miningReport',
                //     icon:"iconfont icon-baogao",

                // },
                {
                    path: "personalAPI",
                    label: 'personal.API',
                    icon: "iconfont icon-a-fenzhi1",

                },

                // {   
                //     path:"",
                //     label:'U 账户',
                //     icon:"iconfont icon-zhanghuyue",

                // },


            ],
            userEmail: "",
        }
    },



    mounted() {


        if (this.$route.name =="PersonalCenter" && !this.$isMobile) {
            this.$router.go(-1); 
        }


        let userEmail = localStorage.getItem("userEmail")
        this.userEmail = JSON.parse(userEmail)
        window.addEventListener("setItem", () => {
            let userEmail = localStorage.getItem("userEmail")
            this.userEmail = JSON.parse(userEmail)
        });

    
        




    },
    methods: {
        handelMenuItem(path) {
          
            
            const lang = this.$i18n.locale;
            this.$router.push(`/${lang}/personalCenter/${path}`).catch(err => {
                if (err.name !== 'NavigationDuplicated') {
                    console.error('Navigation failed:', err);
                }
            });

            // 可以考虑添加这行代码手动触发重新计算
            this.$nextTick(() => {
                this.$forceUpdate();
            });
        }
    }
}