import Vue from 'vue'//导入vue组件
import dragDialog from './directives/dragdialog'

//重置CSS样式
import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
//import locale from 'element-ui/lib/locale/lang/en' // lang i18n //组件语言包

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
    const { mockXHR } = require('../mock')
    mockXHR()
}

// set ElementUI lang to EN
//Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

Vue.config.productionTip = false

//注册全局自定义事件
//参数1：自定义指令名称
//参数2：配置对象，需要一个inserted钩子函数
Vue.directive("icanvisit", {
    //当指令绑定的标签插入到dom树上时会被调用，同时携带回两个参数回来
    //el参数:当前的dom元素
    //binding参数:指令携带的参数对象
    inserted(el, bindin) {
        let isExist = false
        let btnList = store.state.user.btnPermission//按钮权限

        if (btnList && Array.isArray(btnList) && btnList.length > 0) {
            //遍历按钮权限
            for (let i = 0; i < btnList.length; i++) {
                let item = btnList[i].flag

                //存在该按钮权限
                if (item === bindin.value) {
                    isExist = true
                    break
                }
            }
        }

        //不存在该按钮权限
        if (!isExist) {
            el.remove()
        }
    }
})

//注册全局自定义事件(拖动对话框)
Vue.directive('drag-dialog', dragDialog);

//加载全局组件
//加载组件
import '@/components/install'

new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
})
