import Vue from 'vue';
import App from './App.vue';
import store from './store';
import router from './router';
import permission from './utils/permission';
import { MAP_KEY, LICENSE_CODE } from '@/config/setting';
import EleAdmin from 'ele-admin';
import VueClipboard from 'vue-clipboard2';
import i18n from './i18n';
import './styles/index.scss';
import websocket from '@/utils/websocket';

// 初始化事件总线（跨组件通信）
Vue.prototype.$eventBus = new Vue();
window.EventBus = new Vue();
// 应用启动时自动检测 Token 并初始化 WebSocket
websocket.init();

Vue.config.productionTip = false;

Vue.use(EleAdmin, {
  response: {
    dataName: 'list'
  },
  mapKey: MAP_KEY,
  license: LICENSE_CODE,
  i18n: (key, value) => i18n.t(key, value)
});
Vue.use(permission);
Vue.use(VueClipboard);

new Vue({
  router,
  store,
  i18n,
  render: (h) => h(App),
  beforeDestroy() {
    // 应用销毁时关闭连接
    this.$ws.close();
  }
}).$mount('#app');
