main.js 3.22 KB
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import App from './App.vue';
import router from './router';
import store from './store/index';

import ElementUI from 'element-ui'
import '@styles/element-variables.scss'

Vue.use(ElementUI)
// import enLocale from 'element-ui/lib/locale/lang/en' // lang i18n
// import zhLocale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
// import tcLocale from 'element-ui/lib/locale/lang/zh-TW' // lang i18n
// Vue.use(ElementUI, {
// 	tcLocale
// })

import api from '@/api/api'
import {
	httpGet,
	httpPost
} from '@/api/fetch-api.js';

import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper)

import {
	Loading
} from 'vant';
Vue.use(Loading);

// vant
import {
	Collapse,
	CollapseItem,
	Icon
} from 'vant';
Vue.use(Collapse).use(CollapseItem);
Vue.use(Icon);


import Mock from './mock'
Mock.bootstrap();

// 视频
import VueVideoPlayer from 'vue-video-player'
import 'video.js/dist/video-js.css'
Vue.use(VueVideoPlayer)

// import 'amfe-flexible';
Vue.config.productionTip = false

// Purecss
// import Purecss from 'purecss'
// Vue.use(Purecss);

// 国际化
Vue.use(VueI18n)
const i18n = new VueI18n({
	locale: localStorage.getItem("lang") || 'tc', // 语言标识
	messages: {
		'tc': require('@/common/lang/tc'), // 繁体语言包
		'zh': require('@/common/lang/zh'), // 简体语言包
		'en': require('@/common/lang/en'), // 英文语言包
	}
})

let vueInstance = new Vue({
	i18n,
	router,
	store,
	render: h => h(App),
	mounted: () => {
		document.dispatchEvent(new Event('render-event'));
	},
	data: {
		eventBus: new Vue(),
		queryConfigData: null, // 1.放内存
		// queryConfigData: localStorage.getItem("queryConfig") || null, // 2.放localStorage
	}
}).$mount('#app');
// window.vueInstance = vueInstance; // 实在不满足需要,可以把vue实例挂载到windows上

/**
 * 初始化请求配置
 * 根据需要看放内存还是放localStorage
 *
 * 具体方法访问方法见 首页index.js mounted方法
 */
function initQueryConfig() {

	window.global = {};
	let rsaKey1 = localStorage.getItem("rsaKey");
	let rsaKeyIndex1 = localStorage.getItem("rsaKeyIndex");
	let vhis1 = localStorage.getItem("vhis");
	let policies = localStorage.getItem("policies");

	try {
		policies = policies ? JSON.parse(policies) : null;
	} catch (e) {
		console.error(e);
	}

	window.global = {
		PK: rsaKey1,
		E: rsaKeyIndex1,
		vhis: vhis1,
		policies: policies,
		mockData: process.env.VUE_APP_MOCK_DATA == undefined || !process.env.VUE_APP_MOCK_DATA ? false : true,
		oneAccountCenterOff: process.env.VUE_APP_ONE_ACCOUNT_CENTER_OFF == "true" ? true : false
	};

	httpGet({
		url: api.config
	}).then(res => {
		let rsaKey = res.rsaKey;
		let rsaKeyIndex = res.rsaKeyIndex;
		let vhis = res.vhis;
		let policies = res.policies;

		if (rsaKey) {
			window.global.PK = rsaKey;
			localStorage.setItem("rsaKey", rsaKey);
		}

		if (rsaKeyIndex) {
			window.global.E = rsaKeyIndex;
			localStorage.setItem("rsaKeyIndex", rsaKeyIndex);
		}

		if (vhis) {
			window.global.vhis = vhis;
			localStorage.setItem("vhis", vhis);
		}

		if (policies) {
			window.global.policies = policies;
			localStorage.setItem("policies", JSON.stringify(policies));
		}
	});

}
initQueryConfig();