import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/styles/common.css'
import './assets/styles/globa.less'

import api from '@/api/index.js'

import util from '@/util/index.js'
import moment from 'moment'


Vue.prototype.$api = api;

Vue.prototype.$util = util;
Vue.prototype.$openUrl = (params)=>{
  let {href} = router.resolve(params)
  window.open(href,'_blank')

}
window.moment = moment;

ElementUI.Dialog.props.closeOnClickModal.default = false; // 修改 el-dialog 默认点击遮照为不关闭
Vue.use(ElementUI)

Vue.config.productionTip = false
// 全局混入

Vue.filter('timeResolve', function (value) {
  if (!value) return ''
  return moment(value).format('YYYY-MM-DD HH:mm:SS')
})
Vue.filter('timeResolveD', function (value) {
  if (!value) return ''
  return moment(value).format('YYYY-MM-DD')
})

Vue.filter('StoM',function (value){
  if(!value) return ''
  let minutes = parseInt(value /60);
  let seconds = value % 60;
  if(minutes < 10){
    minutes = '0' + minutes;
  }
  if(seconds < 10){
    seconds = '0' + seconds
  }

  return minutes + ":"+seconds
})


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


//统一在这里做router 和tag的处理
Vue.prototype.$router_ = (params={})=>{
  params.canClose = params.name!=='home'
  store.dispatch('pushMenu',params)
  router.push(params)
}

//首先获取本地的tab组，如果有的话，将tab组初始化
let list = JSON.parse(localStorage.getItem('rx-flq-menuList'))
if(list && list.length){
  store.dispatch('configMenu',list)
}else{
  Vue.prototype.$router_({name:'home',title:'控制台'})
}
