import '@/assets/styles/reset.less';
import '@/assets/styles/general.scss';
import '@/assets/styles/index.scss';
import ElementUI, { Message } from 'element-ui';
import axios from 'axios';
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import { routes } from './router/routes';
import filters from '@/filters/index.js';
import { subAppAttr } from '@/mixins/subApp.js';
import store from './store/index';
import mkButton from '@/components/mk-button';
import memberInfo from '@/components/member-info';
import elImageView from '@/components/libs/el-image-view';
import itemCode from '@/utils/item-code.js';
import { itemPerm, permission } from '@/utils/permission.js';

import { _throttle } from '@/utils/index';
Vue.use(ElementUI);
axios.defaults.withCredentials = true;
Vue.prototype.axios = axios;
Vue.config.productionTip = false;
Object.keys(filters).map(item => Vue.filter(item, filters[item])); // 全局注册过滤器
Vue.mixin(subAppAttr); // 全局注册mixins
// 全局注册组件
Vue.component('mk-button', mkButton);
Vue.component(elImageView.name, elImageView);
Vue.component('member-info', memberInfo);
// 请求头加isControl参数，否则没有权限
Vue.prototype.axios.interceptors.request.use(config => {
  config.headers['isControl'] = true;
  return config;
});

Vue.prototype.$tips = _throttle(Message, 1500);
Vue.prototype.$itemCode = itemCode;
Vue.prototype.$itemPerm = itemPerm;
// 开启vue devtools.....
/* eslint-disable-next-line */
Vue.config.devtools = process.env.NODE_ENV !== 'production';

// Promise增加finally
window.Promise.prototype.finally = function(callback) {
  let P = this.constructor;
  return this.then(
    value => P.resolve(callback()).then(() => value),
    reason => P.resolve(callback()).then(() => { throw reason; })
  );
};

permission({
  router,
  routes,
  projectPath: '/welfare',
  writeRoute: [ '/index' ],
  menuCode: 'welfare',
  isApp: true,
  createApp() {
    new Vue({
      router,
      store,
      render: h => h(App)
    }).$mount('#app');
  }
});