import Vue from 'vue'
import App from './App.vue'
import fetchApi from './services/fetchApi'
import router from './router'    /*引入路由设置*/
import store from './store'    /*引入store  vuex设置*/
import MetaInfo from 'vue-meta-info' /*动态设置meta标签*/
import './assets/icons' // svg图标
import filter from "./filters";
import util from "./utils/util"
import verify from "./utils/verify"
import clickThrottle from "./utils/clickThrottle"
import {Message,Loading} from 'element-ui'
import * as echarts from 'echarts';  /*echarts图表 示例 https://echarts.apache.org/examples/zh/index.html */
import ElementUI from 'element-ui';
import './assets/style/element-ui-variable.scss'
// import 'element-ui/lib/theme-chalk/index.css';
import 'element-ui/lib/theme-chalk/icon.css'
import {TrydoFiles} from "@trydo/files-utils"
// 引入全局通用自定义指令
import '@/assets/js/directive';
import '@/assets/js/directiveVideo';
import stompSocket from "./utils/stompSocket"


Vue.use(ElementUI);

// 全局导入过滤器
Object.keys(filter).forEach(key => Vue.filter(key, filter[key]));

Vue.prototype.$message = Message;
Vue.prototype.$loading = Loading.service;
Vue.prototype.$fetchApi = fetchApi;
Vue.prototype.$util = util;
Vue.prototype.$verify = verify;
Vue.prototype.$clickThrottle = clickThrottle;
Vue.prototype.$echarts = echarts;
Vue.prototype.$TrydoFiles = TrydoFiles;
Vue.prototype.$stompSocket = stompSocket;

// vue使用vue-meta-info来动态设置标题
Vue.use(MetaInfo)

new Vue({
  data(){
    return {
      keyWords:null,//关键字
      description:null,//描述
      sitetitle:null,//标题
      sitetitleinit:null,//
      firstlevelmenu:['/case-management','/mediation-package','/case-package','/payment-receipt','/mediation-management',
        '/system-management/area-management','/system-management/role-permissions-management',
        '/system-management/role-management','/system-management/user-management']
    }
  },
  metaInfo () {
    return {
      title: this.sitetitle,
      meta: [{name: 'keyWords',content: this.keyWords},{name: 'description',content: this.description}]
    }
  },
  router,
  store,
  render: h => h(App),
  watch:{
    '$route': function(to, from) {
      // console.log(to,from,'路由信息')

       // 判断当前登录人是否有该地址的访问权限
      if(this.firstlevelmenu.includes(to.path))
      {
        let interviewFlag = false
        if(JSON.parse(sessionStorage.getItem('userInfo')))
        {
          let resources = JSON.parse(sessionStorage.getItem('userInfo')).resources
          let menuTree = resources[0].children
          
          menuTree.forEach(item =>{
            if(item.url == to.path){ interviewFlag = true}
            if(!interviewFlag)
            {
              item.children.forEach(item =>{
                if(item.url == to.path){ interviewFlag = true}
              })
            }
          })
        }
        if(!interviewFlag)
        {
          // 判断当前登录人角色，如果是普通调解员，则默认展示区域且不可选择
          let identifier = this.$store.state.userinfo.roleIdentifierList
          if(identifier.includes('manager') || identifier.includes('admin'))
          {
            router.push('/workbench')
          }
          else
          {
            router.push('/workbenchcm')
          }
        }
      }
      
      if(to.meta.title!=null&&to.meta.sitetitleinit!=null)
      {
        this.sitetitle=to.meta.title+'-'+this.sitetitleinit;
      }
      if(to.meta.sitetitleinit!=null)
      {
        this.sitetitle=this.sitetitleinit;
      }
      else
      {
        this.sitetitle=to.meta.title;
      }
    }
  }
}).$mount('#app')
