m2pool_web_frontend/mining-pool/src/main.js

94 lines
2.7 KiB
JavaScript
Raw Normal View History

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/index.scss'
import i18n from './i18n/index'
import axios from "axios";
import './assets/icons/iconfont/iconfont.css'
import {$addStorageEvent} from '../src/utils/publicMethods'
import MetaInfo from 'vue-meta-info'
import loadingStateMixin from './utils/loadingStateMixin';
import networkRecoveryMixin from './mixins/networkRecoveryMixin';
import './utils/loadingRecovery';
import errorNotificationManager from '../src/utils/errorNotificationManager';
Vue.use(MetaInfo)
Vue.prototype.$addStorageEvent = $addStorageEvent // 添加storage事件
Vue.config.productionTip = false
Vue.use(ElementUI, {
i18n: (key, value) => i18n.t(key, value)
});
Vue.prototype.$axios = axios
// console.log = ()=>{} //全局关闭打印
// 全局注册混入
Vue.mixin(loadingStateMixin);
Vue.mixin(networkRecoveryMixin);
Vue.prototype.$baseApi = process.env.VUE_APP_BASE_URL //图片base路径
const screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
const isNarrowScreen = screenWidth < 1280;
Vue.prototype.$isMobile = isNarrowScreen
// 在路由守卫中设置
router.beforeEach((to, from, next) => {
// 从路由中获取语言参数
const lang = to.params.lang || (localStorage.getItem('lang') || 'en');
// 设置 HTML 的 lang 属性
document.documentElement.lang = lang;
// 设置i18n语言
if (i18n.locale !== lang) {
i18n.locale = lang;
}
next();
});
// 定期清理过期的错误记录
setInterval(() => {
errorNotificationManager.cleanup();
}, 60000); // 每分钟清理一次
window.vm = new Vue({
router,
store,
i18n,
render: h => h(App),
created() {
this.$watch(
() => this.$i18n.locale,
(newLocale) => {
this.updateMetaAndTitle();
}
);
this.updateMetaAndTitle();
},
mounted () {
document.dispatchEvent(new Event('render-event'))
},
methods: {
updateMetaAndTitle() {
document.title = this.$i18n.t('home.appTitle');
const descriptionMeta = document.querySelector('meta[name="description"]');
// const keywordsMeta = document.querySelector('meta[name="keywords"]');
if (descriptionMeta) {
descriptionMeta.content = this.$i18n.t('home.metaDescription');
}
// if (keywordsMeta) {
// keywordsMeta.content = this.$i18n.t('home.metaKeywords');
// }
}
}
}).$mount('#app')
// 初次加载和DOM加载完成时更新
document.addEventListener('DOMContentLoaded', () => {
window.vm.updateMetaAndTitle();
});