import { createApp } from 'vue';
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import locale from 'element-ui/lib/locale/lang/zh-CN'
import '@/request/setupAxios'
import '@/assets/style/public.scss'
import user from '@/state/user'
const app = createApp(App);
app.use(router)
app.use(ElementPlus, { locale })
app.mount('#app')
// 挂在全局方法
app.config.globalProperties.$power = (fun,val) =>{
    let replacelist = {
        'organizationlist':'organization',
    }
    let routeName = router.currentRoute._value.name
    let roleKeyList = user._value.roleKeyList
    let rokeName =  `${replacelist[routeName] || routeName}:${val}`
    if(roleKeyList.includes(rokeName)){
        fun()
    }else{
        console.warn('暂无权限',routeName)
    }
}
app.directive('power',{
    mounted(el,binding) {
        let replacelist = {
            'organizationlist':'organization',
        }
        let routeName = router.currentRoute._value.name
        let roleKeyList = user._value.roleKeyList
        let rokeName =  `${replacelist[routeName] || routeName}:${binding.value}`
        if(!roleKeyList.includes(rokeName)){
                var klses = el.className;
                console.log('klses',klses)
                el.className = klses + ' disable'
                
                // el.onclick=null;
            // el.parentNode&&el.parentNode.removeChild(el);
        }
    }
})