import Vue from 'vue';

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

import './components';
import './containers';

import 'utils/dialog-helper';
import '@/plugins/viewerjs';

import message from '@/utils/message';

import bus from './utils/bus';

import DICT from '@/const/dictType';
import TABLECOLSIZE from '@/const/tableColSize';

// 时间
import Moment from 'moment';

Vue.prototype.$Bus = bus;
Vue.prototype.$g_emit = (eventName, payload) => {
  bus.$emit(eventName, payload);
};
Vue.prototype.$g_on = (eventName, func) => {
  bus.$on(eventName, func);
};
Vue.prototype.$g_off = (eventName, func) => {
  bus.$off(eventName, func);
};

/**
 * 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, { size: 'small', zIndex: 3000 });

Vue.config.productionTip = false;

// 提示
Vue.prototype.$success = message.success;
Vue.prototype.$error = message.error;
Vue.prototype.$warning = message.warning;

Vue.prototype.$moment = Moment;

// 数据字典搜索关键词
Vue.prototype.$dict = DICT;

// 表格单列宽度
Vue.prototype.$col = TABLECOLSIZE;

Vue.prototype.$upload = url => `${process.env.VUE_APP_BASE_API}${url}`;

window.UEDITOR_CONFIG = `${process.env.VUE_APP_BASE_API}/yxl-back-end/framework/oss/ueditor/ueditor-action`;
window.UEDITOR_SERVER_URL = `${process.env.VUE_APP_BASE_API}/yxl-back-end/framework/oss/ueditor/ueditor-action`;
// window.UEDITOR_CONFIG = `https://ex.by-health.com/baby-institute-back-end/oss/ueditor/ueditor-action`;
// window.UEDITOR_SERVER_URL = `https://ex.by-health.com/baby-institute-back-end/oss/ueditor/ueditor-action`;

Vue.prototype.$filterRichTxt = str => {
  if (!str) return '';
  return str.replace(/<img/g, '<img width="100%"');
};

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