import { createApp, watch } from 'vue';
import './style.css';
import App from './App.vue';
import { router } from './router'
import { store } from './store';
import Antd from 'ant-design-vue';

import 'ant-design-vue/dist/reset.css';
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css';

import CommonLeftSider from '@/components/common/left-sider.vue';
import ABiaoge from '@/components/biaoge/index.vue';
import AJilian from '@/components/form/jilian.vue';
import AShujilian from '@/components/form/shujilian.vue';
import AXuanze from '@/components/form/xuanze.vue';
import ALogin from '@/components/form/login.vue';
import ImageContainer from '@/components/common/image-container.vue';

import EditButton from '@/components/common/edit-button.vue';
import { routesModuleList } from '@/router/dynamic';
import { routesManageModuleList } from '@/router/manageDynamic';
router.beforeEach((to, from, next) => {
	document.title = `菊城人才网`;
	if (store.state.permissions.permissionList == null) {
		store.commit('getToken', {
			token: sessionStorage.getItem('token') ? sessionStorage.getItem('token') : ''
		})
		store.commit('getRole', {
			role: sessionStorage.getItem('role') ? sessionStorage.getItem('role') : ''
		})
		store.commit('getPageType', {
			pageType: sessionStorage.getItem('pageType') ? sessionStorage.getItem('pageType') : ''
		})
		store.commit('setShowLoginBox', {
			showLoginBox: false
		})
		store.dispatch('permissions/FETCH_PERMISSION').then(() => {
			next({
				path: to.path
			})
		})
	} else {
		next()
	}
})

const app = createApp(App);
app.component('common-left-sider', CommonLeftSider);
app.component('a-biaoge', ABiaoge);
app.component('a-jilian', AJilian);
app.component('a-shujilian', AShujilian);
app.component('a-xuanze', AXuanze);
app.component('a-login', ALogin);
app.component('QuillEditor', QuillEditor)
app.component('image-container', ImageContainer)
app.component('edit-button', EditButton)

app.use(router);
app.use(store);
app.use(Antd);
app.mount('#app');